Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * screen.c: code for displaying on the screen |
| 12 | * |
| 13 | * Output to the screen (console, terminal emulator or GUI window) is minimized |
| 14 | * by remembering what is already on the screen, and only updating the parts |
| 15 | * that changed. |
| 16 | * |
| 17 | * ScreenLines[off] Contains a copy of the whole screen, as it is currently |
| 18 | * displayed (excluding text written by external commands). |
| 19 | * ScreenAttrs[off] Contains the associated attributes. |
| 20 | * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] |
| 21 | * for each line. |
| 22 | * LineWraps[row] Flag for each line whether it wraps to the next line. |
| 23 | * |
| 24 | * For double-byte characters, two consecutive bytes in ScreenLines[] can form |
| 25 | * one character which occupies two display cells. |
| 26 | * For UTF-8 a multi-byte character is converted to Unicode and stored in |
| 27 | * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 28 | * character without composing chars ScreenLinesUC[] will be 0 and |
| 29 | * ScreenLinesC[][] is not used. When the character occupies two display |
| 30 | * cells the next byte in ScreenLines[] is 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 31 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 32 | * (drawn on top of the first character). There is 0 after the last one used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | * ScreenLines2[] is only used for euc-jp to store the second byte if the |
| 34 | * first byte is 0x8e (single-width character). |
| 35 | * |
| 36 | * The screen_*() functions write to the screen and handle updating |
| 37 | * ScreenLines[]. |
| 38 | * |
| 39 | * update_screen() is the function that updates all windows and status lines. |
| 40 | * It is called form the main loop when must_redraw is non-zero. It may be |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 41 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | * |
| 43 | * The part of the buffer that is displayed in a window is set with: |
| 44 | * - w_topline (first buffer line in window) |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 45 | * - w_topfill (filler lines above the first line) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | * - w_leftcol (leftmost window cell in window), |
| 47 | * - w_skipcol (skipped window cells of first line) |
| 48 | * |
| 49 | * Commands that only move the cursor around in a window, do not need to take |
| 50 | * action to update the display. The main loop will check if w_topline is |
| 51 | * valid and update it (scroll the window) when needed. |
| 52 | * |
| 53 | * Commands that scroll a window change w_topline and must call |
| 54 | * check_cursor() to move the cursor into the visible part of the window, and |
| 55 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 56 | * later. |
| 57 | * |
| 58 | * Commands that change text in the buffer must call changed_bytes() or |
| 59 | * changed_lines() to mark the area that changed and will require updating |
| 60 | * later. The main loop will call update_screen(), which will update each |
| 61 | * window that shows the changed buffer. This assumes text above the change |
| 62 | * can remain displayed as it is. Text after the change may need updating for |
| 63 | * scrolling, folding and syntax highlighting. |
| 64 | * |
| 65 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 66 | * invalidate the contents of a window in another way (e.g., change fold |
| 67 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 68 | * redisplayed by update_screen() later. |
| 69 | * |
| 70 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 71 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 72 | * buffer redisplayed by update_screen() later. |
| 73 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 74 | * Commands that change highlighting and possibly cause a scroll too must call |
| 75 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 76 | * to avoid redrawing everything. But the length of displayed lines must not |
| 77 | * change, use NOT_VALID then. |
| 78 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 80 | * TODO: should minimize redrawing by scrolling when possible. |
| 81 | * |
| 82 | * Commands that change everything (e.g., resizing the screen) must call |
| 83 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 84 | * |
| 85 | * Things that are handled indirectly: |
| 86 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 87 | * update_screen() called to redraw. |
| 88 | */ |
| 89 | |
| 90 | #include "vim.h" |
| 91 | |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 92 | #define MB_FILLER_CHAR '<' /* character used when a double-width character |
| 93 | * doesn't fit. */ |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * The attributes that are actually active for writing to the screen. |
| 97 | */ |
| 98 | static int screen_attr = 0; |
| 99 | |
| 100 | /* |
| 101 | * Positioning the cursor is reduced by remembering the last position. |
| 102 | * Mostly used by windgoto() and screen_char(). |
| 103 | */ |
| 104 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 105 | |
| 106 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef FEAT_FOLDING |
| 111 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 112 | static int compute_foldcolumn(win_T *wp, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | /* |
| 116 | * Buffer for one screen line (characters and attributes). |
| 117 | */ |
| 118 | static schar_T *current_ScreenLine; |
| 119 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 120 | static void win_update(win_T *wp); |
| 121 | static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | #ifdef FEAT_FOLDING |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 123 | static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row); |
| 124 | static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum); |
| 125 | static void copy_text_attr(int off, char_u *buf, int len, int attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 127 | static int win_line(win_T *, linenr_T, int, int, int nochange); |
| 128 | static int char_needs_redraw(int off_from, int off_to, int cols); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 129 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 130 | static void screen_line(int row, int coloff, int endcol, int clear_width, int rlflag); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 132 | #else |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 133 | static void screen_line(int row, int coloff, int endcol, int clear_width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 135 | #endif |
Bram Moolenaar | 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 |
| 419 | redraw_after_callback() |
| 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(); |
| 425 | else if ((State & NORMAL) || (State & INSERT)) |
| 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 | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 435 | /* Don't update the cursor while it is blinking, it will get |
| 436 | * updated soon and this avoids interrupting the blinking. */ |
| 437 | if (!gui_mch_is_blinking()) |
| 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 | /* |
| 489 | * update_screen() |
| 490 | * |
| 491 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 492 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 493 | */ |
| 494 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 495 | update_screen(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 496 | { |
| 497 | win_T *wp; |
| 498 | static int did_intro = FALSE; |
| 499 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 500 | int did_one; |
| 501 | #endif |
| 502 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 503 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 504 | if (!screen_valid(TRUE)) |
| 505 | return; |
| 506 | |
| 507 | if (must_redraw) |
| 508 | { |
| 509 | if (type < must_redraw) /* use maximal type */ |
| 510 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 511 | |
| 512 | /* must_redraw is reset here, so that when we run into some weird |
| 513 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 514 | * scrolling), or update_topline() in win_update() will cause a |
| 515 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 516 | must_redraw = 0; |
| 517 | } |
| 518 | |
| 519 | /* Need to update w_lines[]. */ |
| 520 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 521 | type = NOT_VALID; |
| 522 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 523 | /* Postpone the redrawing when it's not needed and when being called |
| 524 | * recursively. */ |
| 525 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 526 | { |
| 527 | redraw_later(type); /* remember type for next time */ |
| 528 | must_redraw = type; |
| 529 | if (type > INVERTED_ALL) |
| 530 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | updating_screen = TRUE; |
| 535 | #ifdef FEAT_SYN_HL |
| 536 | ++display_tick; /* let syntax code know we're in a next round of |
| 537 | * display updating */ |
| 538 | #endif |
| 539 | |
| 540 | /* |
| 541 | * if the screen was scrolled up when displaying a message, scroll it down |
| 542 | */ |
| 543 | if (msg_scrolled) |
| 544 | { |
| 545 | clear_cmdline = TRUE; |
| 546 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 547 | type = CLEAR; |
| 548 | else if (type != CLEAR) |
| 549 | { |
| 550 | check_for_delay(FALSE); |
| 551 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 552 | type = CLEAR; |
| 553 | FOR_ALL_WINDOWS(wp) |
| 554 | { |
| 555 | if (W_WINROW(wp) < msg_scrolled) |
| 556 | { |
| 557 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 558 | && wp->w_redr_type < REDRAW_TOP |
| 559 | && wp->w_lines_valid > 0 |
| 560 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 561 | { |
| 562 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 563 | wp->w_redr_type = REDRAW_TOP; |
| 564 | } |
| 565 | else |
| 566 | { |
| 567 | wp->w_redr_type = NOT_VALID; |
| 568 | #ifdef FEAT_WINDOWS |
| 569 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 570 | <= msg_scrolled) |
| 571 | wp->w_redr_status = TRUE; |
| 572 | #endif |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 577 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 578 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 579 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 580 | } |
| 581 | msg_scrolled = 0; |
| 582 | need_wait_return = FALSE; |
| 583 | } |
| 584 | |
| 585 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 586 | compute_cmdrow(); |
| 587 | |
| 588 | /* Check for changed highlighting */ |
| 589 | if (need_highlight_changed) |
| 590 | highlight_changed(); |
| 591 | |
| 592 | if (type == CLEAR) /* first clear screen */ |
| 593 | { |
| 594 | screenclear(); /* will reset clear_cmdline */ |
| 595 | type = NOT_VALID; |
| 596 | } |
| 597 | |
| 598 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 599 | check_for_delay(FALSE); |
| 600 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 601 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 602 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 603 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 604 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 605 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 606 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 607 | curwin->w_redr_type = NOT_VALID; |
| 608 | #endif |
| 609 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 610 | /* |
| 611 | * Only start redrawing if there is really something to do. |
| 612 | */ |
| 613 | if (type == INVERTED) |
| 614 | update_curswant(); |
| 615 | if (curwin->w_redr_type < type |
| 616 | && !((type == VALID |
| 617 | && curwin->w_lines[0].wl_valid |
| 618 | #ifdef FEAT_DIFF |
| 619 | && curwin->w_topfill == curwin->w_old_topfill |
| 620 | && curwin->w_botfill == curwin->w_old_botfill |
| 621 | #endif |
| 622 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 623 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 624 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 625 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 626 | && curwin->w_old_visual_mode == VIsual_mode |
| 627 | && (curwin->w_valid & VALID_VIRTCOL) |
| 628 | && curwin->w_old_curswant == curwin->w_curswant) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 629 | )) |
| 630 | curwin->w_redr_type = type; |
| 631 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 632 | #ifdef FEAT_WINDOWS |
| 633 | /* Redraw the tab pages line if needed. */ |
| 634 | if (redraw_tabline || type >= NOT_VALID) |
| 635 | draw_tabline(); |
| 636 | #endif |
| 637 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 638 | #ifdef FEAT_SYN_HL |
| 639 | /* |
| 640 | * Correct stored syntax highlighting info for changes in each displayed |
| 641 | * buffer. Each buffer must only be done once. |
| 642 | */ |
| 643 | FOR_ALL_WINDOWS(wp) |
| 644 | { |
| 645 | if (wp->w_buffer->b_mod_set) |
| 646 | { |
| 647 | # ifdef FEAT_WINDOWS |
| 648 | win_T *wwp; |
| 649 | |
| 650 | /* Check if we already did this buffer. */ |
| 651 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 652 | if (wwp->w_buffer == wp->w_buffer) |
| 653 | break; |
| 654 | # endif |
| 655 | if ( |
| 656 | # ifdef FEAT_WINDOWS |
| 657 | wwp == wp && |
| 658 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 659 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 660 | syn_stack_apply_changes(wp->w_buffer); |
| 661 | } |
| 662 | } |
| 663 | #endif |
| 664 | |
| 665 | /* |
| 666 | * Go from top to bottom through the windows, redrawing the ones that need |
| 667 | * it. |
| 668 | */ |
| 669 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 670 | did_one = FALSE; |
| 671 | #endif |
| 672 | #ifdef FEAT_SEARCH_EXTRA |
| 673 | search_hl.rm.regprog = NULL; |
| 674 | #endif |
| 675 | FOR_ALL_WINDOWS(wp) |
| 676 | { |
| 677 | if (wp->w_redr_type != 0) |
| 678 | { |
| 679 | cursor_off(); |
| 680 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 681 | if (!did_one) |
| 682 | { |
| 683 | did_one = TRUE; |
| 684 | # ifdef FEAT_SEARCH_EXTRA |
| 685 | start_search_hl(); |
| 686 | # endif |
| 687 | # ifdef FEAT_CLIPBOARD |
| 688 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 689 | if (clip_star.available && clip_isautosel_star()) |
| 690 | clip_update_selection(&clip_star); |
| 691 | if (clip_plus.available && clip_isautosel_plus()) |
| 692 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 693 | # endif |
| 694 | #ifdef FEAT_GUI |
| 695 | /* Remove the cursor before starting to do anything, because |
| 696 | * scrolling may make it difficult to redraw the text under |
| 697 | * it. */ |
| 698 | if (gui.in_use) |
| 699 | gui_undraw_cursor(); |
| 700 | #endif |
| 701 | } |
| 702 | #endif |
| 703 | win_update(wp); |
| 704 | } |
| 705 | |
| 706 | #ifdef FEAT_WINDOWS |
| 707 | /* redraw status line after the window to minimize cursor movement */ |
| 708 | if (wp->w_redr_status) |
| 709 | { |
| 710 | cursor_off(); |
| 711 | win_redr_status(wp); |
| 712 | } |
| 713 | #endif |
| 714 | } |
| 715 | #if defined(FEAT_SEARCH_EXTRA) |
| 716 | end_search_hl(); |
| 717 | #endif |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 718 | #ifdef FEAT_INS_EXPAND |
| 719 | /* May need to redraw the popup menu. */ |
| 720 | if (pum_visible()) |
| 721 | pum_redraw(); |
| 722 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 723 | |
| 724 | #ifdef FEAT_WINDOWS |
| 725 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 726 | * than going through all buffers (there could be many buffers). */ |
| 727 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 728 | wp->w_buffer->b_mod_set = FALSE; |
| 729 | #else |
| 730 | curbuf->b_mod_set = FALSE; |
| 731 | #endif |
| 732 | |
| 733 | updating_screen = FALSE; |
| 734 | #ifdef FEAT_GUI |
| 735 | gui_may_resize_shell(); |
| 736 | #endif |
| 737 | |
| 738 | /* Clear or redraw the command line. Done last, because scrolling may |
| 739 | * mess up the command line. */ |
| 740 | if (clear_cmdline || redraw_cmdline) |
| 741 | showmode(); |
| 742 | |
| 743 | /* May put up an introductory message when not editing a file */ |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 744 | if (!did_intro) |
| 745 | maybe_intro_message(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 746 | did_intro = TRUE; |
| 747 | |
| 748 | #ifdef FEAT_GUI |
| 749 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 750 | * done. */ |
| 751 | if (gui.in_use) |
| 752 | { |
| 753 | out_flush(); /* required before updating the cursor */ |
| 754 | if (did_one) |
| 755 | gui_update_cursor(FALSE, FALSE); |
| 756 | gui_update_scrollbars(FALSE); |
| 757 | } |
| 758 | #endif |
| 759 | } |
| 760 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 761 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 762 | /* |
| 763 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 764 | * to the 'concealcursor' option. |
| 765 | */ |
| 766 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 767 | conceal_cursor_line(win_T *wp) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 768 | { |
| 769 | int c; |
| 770 | |
| 771 | if (*wp->w_p_cocu == NUL) |
| 772 | return FALSE; |
| 773 | if (get_real_state() & VISUAL) |
| 774 | c = 'v'; |
| 775 | else if (State & INSERT) |
| 776 | c = 'i'; |
| 777 | else if (State & NORMAL) |
| 778 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 779 | else if (State & CMDLINE) |
| 780 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 781 | else |
| 782 | return FALSE; |
| 783 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 788 | */ |
| 789 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 790 | conceal_check_cursur_line(void) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 791 | { |
| 792 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 793 | { |
| 794 | need_cursor_line_redraw = TRUE; |
| 795 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 796 | * without concealing. */ |
| 797 | curs_columns(TRUE); |
| 798 | } |
| 799 | } |
| 800 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 801 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 802 | update_single_line(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 803 | { |
| 804 | int row; |
| 805 | int j; |
| 806 | |
Bram Moolenaar | 908be43 | 2016-05-24 10:51:30 +0200 | [diff] [blame] | 807 | /* Don't do anything if the screen structures are (not yet) valid. */ |
| 808 | if (!screen_valid(TRUE)) |
| 809 | return; |
| 810 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 811 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 812 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 813 | { |
| 814 | # ifdef FEAT_GUI |
| 815 | /* Remove the cursor before starting to do anything, because scrolling |
| 816 | * may make it difficult to redraw the text under it. */ |
| 817 | if (gui.in_use) |
| 818 | gui_undraw_cursor(); |
| 819 | # endif |
| 820 | row = 0; |
| 821 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 822 | { |
| 823 | if (lnum == wp->w_lines[j].wl_lnum) |
| 824 | { |
| 825 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 826 | # ifdef FEAT_SEARCH_EXTRA |
| 827 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 828 | start_search_hl(); |
| 829 | prepare_search_hl(wp, lnum); |
| 830 | # endif |
| 831 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 832 | # if defined(FEAT_SEARCH_EXTRA) |
| 833 | end_search_hl(); |
| 834 | # endif |
| 835 | break; |
| 836 | } |
| 837 | row += wp->w_lines[j].wl_size; |
| 838 | } |
| 839 | # ifdef FEAT_GUI |
| 840 | /* Redraw the cursor */ |
| 841 | if (gui.in_use) |
| 842 | { |
| 843 | out_flush(); /* required before updating the cursor */ |
| 844 | gui_update_cursor(FALSE, FALSE); |
| 845 | } |
| 846 | # endif |
| 847 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 848 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 849 | } |
| 850 | #endif |
| 851 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 852 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 853 | static void update_prepare(void); |
| 854 | static void update_finish(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 855 | |
| 856 | /* |
| 857 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 858 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 859 | */ |
| 860 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 861 | update_prepare(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 862 | { |
| 863 | cursor_off(); |
| 864 | updating_screen = TRUE; |
| 865 | #ifdef FEAT_GUI |
| 866 | /* Remove the cursor before starting to do anything, because scrolling may |
| 867 | * make it difficult to redraw the text under it. */ |
| 868 | if (gui.in_use) |
| 869 | gui_undraw_cursor(); |
| 870 | #endif |
| 871 | #ifdef FEAT_SEARCH_EXTRA |
| 872 | start_search_hl(); |
| 873 | #endif |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | * Finish updating one or more windows. |
| 878 | */ |
| 879 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 880 | update_finish(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 881 | { |
| 882 | if (redraw_cmdline) |
| 883 | showmode(); |
| 884 | |
| 885 | # ifdef FEAT_SEARCH_EXTRA |
| 886 | end_search_hl(); |
| 887 | # endif |
| 888 | |
| 889 | updating_screen = FALSE; |
| 890 | |
| 891 | # ifdef FEAT_GUI |
| 892 | gui_may_resize_shell(); |
| 893 | |
| 894 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 895 | * done. */ |
| 896 | if (gui.in_use) |
| 897 | { |
| 898 | out_flush(); /* required before updating the cursor */ |
| 899 | gui_update_cursor(FALSE, FALSE); |
| 900 | gui_update_scrollbars(FALSE); |
| 901 | } |
| 902 | # endif |
| 903 | } |
| 904 | #endif |
| 905 | |
| 906 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 907 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 908 | update_debug_sign(buf_T *buf, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 909 | { |
| 910 | win_T *wp; |
| 911 | int doit = FALSE; |
| 912 | |
| 913 | # ifdef FEAT_FOLDING |
| 914 | win_foldinfo.fi_level = 0; |
| 915 | # endif |
| 916 | |
| 917 | /* update/delete a specific mark */ |
| 918 | FOR_ALL_WINDOWS(wp) |
| 919 | { |
| 920 | if (buf != NULL && lnum > 0) |
| 921 | { |
| 922 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 923 | && lnum < wp->w_botline) |
| 924 | { |
| 925 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 926 | wp->w_redraw_top = lnum; |
| 927 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 928 | wp->w_redraw_bot = lnum; |
| 929 | redraw_win_later(wp, VALID); |
| 930 | } |
| 931 | } |
| 932 | else |
| 933 | redraw_win_later(wp, VALID); |
| 934 | if (wp->w_redr_type != 0) |
| 935 | doit = TRUE; |
| 936 | } |
| 937 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 938 | /* Return when there is nothing to do, screen updating is already |
| 939 | * happening (recursive call) or still starting up. */ |
| 940 | if (!doit || updating_screen |
| 941 | #ifdef FEAT_GUI |
| 942 | || gui.starting |
| 943 | #endif |
| 944 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 945 | return; |
| 946 | |
| 947 | /* update all windows that need updating */ |
| 948 | update_prepare(); |
| 949 | |
| 950 | # ifdef FEAT_WINDOWS |
| 951 | for (wp = firstwin; wp; wp = wp->w_next) |
| 952 | { |
| 953 | if (wp->w_redr_type != 0) |
| 954 | win_update(wp); |
| 955 | if (wp->w_redr_status) |
| 956 | win_redr_status(wp); |
| 957 | } |
| 958 | # else |
| 959 | if (curwin->w_redr_type != 0) |
| 960 | win_update(curwin); |
| 961 | # endif |
| 962 | |
| 963 | update_finish(); |
| 964 | } |
| 965 | #endif |
| 966 | |
| 967 | |
| 968 | #if defined(FEAT_GUI) || defined(PROTO) |
| 969 | /* |
| 970 | * Update a single window, its status line and maybe the command line msg. |
| 971 | * Used for the GUI scrollbar. |
| 972 | */ |
| 973 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 974 | updateWindow(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 975 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 976 | /* return if already busy updating */ |
| 977 | if (updating_screen) |
| 978 | return; |
| 979 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 980 | update_prepare(); |
| 981 | |
| 982 | #ifdef FEAT_CLIPBOARD |
| 983 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 984 | if (clip_star.available && clip_isautosel_star()) |
| 985 | clip_update_selection(&clip_star); |
| 986 | if (clip_plus.available && clip_isautosel_plus()) |
| 987 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 988 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 989 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 990 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 991 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 992 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 993 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 994 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 995 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 996 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 997 | if (wp->w_redr_status |
| 998 | # ifdef FEAT_CMDL_INFO |
| 999 | || p_ru |
| 1000 | # endif |
| 1001 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 1002 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1003 | # endif |
| 1004 | ) |
| 1005 | win_redr_status(wp); |
| 1006 | #endif |
| 1007 | |
| 1008 | update_finish(); |
| 1009 | } |
| 1010 | #endif |
| 1011 | |
| 1012 | /* |
| 1013 | * Update a single window. |
| 1014 | * |
| 1015 | * This may cause the windows below it also to be redrawn (when clearing the |
| 1016 | * screen or scrolling lines). |
| 1017 | * |
| 1018 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 1019 | * implies the one below it. |
| 1020 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1021 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1022 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 1023 | * INVERTED redraw the changed part of the Visual area |
| 1024 | * INVERTED_ALL redraw the whole Visual area |
| 1025 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 1026 | * 2. update lines at the top when scrolled down |
| 1027 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 1028 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1029 | * b_mod_top and b_mod_bot. |
| 1030 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 1031 | * wp->w_redraw_top and wp->w_redr_bot. |
| 1032 | * - continue redrawing when syntax status is invalid. |
| 1033 | * 4. if scrolled up, update lines at the bottom. |
| 1034 | * This results in three areas that may need updating: |
| 1035 | * top: from first row to top_end (when scrolled down) |
| 1036 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1037 | * bot: from bot_start to last row (when scrolled up) |
| 1038 | */ |
| 1039 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 1040 | win_update(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1041 | { |
| 1042 | buf_T *buf = wp->w_buffer; |
| 1043 | int type; |
| 1044 | int top_end = 0; /* Below last row of the top area that needs |
| 1045 | updating. 0 when no top area updating. */ |
| 1046 | int mid_start = 999;/* first row of the mid area that needs |
| 1047 | updating. 999 when no mid area updating. */ |
| 1048 | int mid_end = 0; /* Below last row of the mid area that needs |
| 1049 | updating. 0 when no mid area updating. */ |
| 1050 | int bot_start = 999;/* first row of the bot area that needs |
| 1051 | updating. 999 when no bot area updating */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1052 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 1053 | w_topline got smaller a bit */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1054 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1055 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1056 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 1057 | #endif |
| 1058 | |
| 1059 | int row; /* current window row to display */ |
| 1060 | linenr_T lnum; /* current buffer lnum to display */ |
| 1061 | int idx; /* current index in w_lines[] */ |
| 1062 | int srow; /* starting row of the current line */ |
| 1063 | |
| 1064 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 1065 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 1066 | int i; |
| 1067 | long j; |
| 1068 | static int recursive = FALSE; /* being called recursively */ |
| 1069 | int old_botline = wp->w_botline; |
| 1070 | #ifdef FEAT_FOLDING |
| 1071 | long fold_count; |
| 1072 | #endif |
| 1073 | #ifdef FEAT_SYN_HL |
| 1074 | /* remember what happened to the previous line, to know if |
| 1075 | * check_visual_highlight() can be used */ |
| 1076 | #define DID_NONE 1 /* didn't update a line */ |
| 1077 | #define DID_LINE 2 /* updated a normal line */ |
| 1078 | #define DID_FOLD 3 /* updated a folded line */ |
| 1079 | int did_update = DID_NONE; |
| 1080 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 1081 | #endif |
| 1082 | linenr_T mod_top = 0; |
| 1083 | linenr_T mod_bot = 0; |
| 1084 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1085 | int save_got_int; |
| 1086 | #endif |
| 1087 | |
| 1088 | type = wp->w_redr_type; |
| 1089 | |
| 1090 | if (type == NOT_VALID) |
| 1091 | { |
| 1092 | #ifdef FEAT_WINDOWS |
| 1093 | wp->w_redr_status = TRUE; |
| 1094 | #endif |
| 1095 | wp->w_lines_valid = 0; |
| 1096 | } |
| 1097 | |
| 1098 | /* Window is zero-height: nothing to draw. */ |
| 1099 | if (wp->w_height == 0) |
| 1100 | { |
| 1101 | wp->w_redr_type = 0; |
| 1102 | return; |
| 1103 | } |
| 1104 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 1105 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1106 | /* Window is zero-width: Only need to draw the separator. */ |
| 1107 | if (wp->w_width == 0) |
| 1108 | { |
| 1109 | /* draw the vertical separator right of this window */ |
| 1110 | draw_vsep_win(wp, 0); |
| 1111 | wp->w_redr_type = 0; |
| 1112 | return; |
| 1113 | } |
| 1114 | #endif |
| 1115 | |
| 1116 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 1117 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1118 | #endif |
| 1119 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1120 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 1121 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 1122 | * changes. */ |
| 1123 | 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] | 1124 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1125 | { |
| 1126 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1127 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1128 | } |
| 1129 | else |
| 1130 | #endif |
| 1131 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1132 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 1133 | { |
| 1134 | /* |
| 1135 | * When there are both inserted/deleted lines and specific lines to be |
| 1136 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 1137 | * everything (only happens when redrawing is off for while). |
| 1138 | */ |
| 1139 | type = NOT_VALID; |
| 1140 | } |
| 1141 | else |
| 1142 | { |
| 1143 | /* |
| 1144 | * Set mod_top to the first line that needs displaying because of |
| 1145 | * changes. Set mod_bot to the first line after the changes. |
| 1146 | */ |
| 1147 | mod_top = wp->w_redraw_top; |
| 1148 | if (wp->w_redraw_bot != 0) |
| 1149 | mod_bot = wp->w_redraw_bot + 1; |
| 1150 | else |
| 1151 | mod_bot = 0; |
| 1152 | wp->w_redraw_top = 0; /* reset for next time */ |
| 1153 | wp->w_redraw_bot = 0; |
| 1154 | if (buf->b_mod_set) |
| 1155 | { |
| 1156 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1157 | { |
| 1158 | mod_top = buf->b_mod_top; |
| 1159 | #ifdef FEAT_SYN_HL |
| 1160 | /* Need to redraw lines above the change that may be included |
| 1161 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1162 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1163 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1164 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1165 | if (mod_top < 1) |
| 1166 | mod_top = 1; |
| 1167 | } |
| 1168 | #endif |
| 1169 | } |
| 1170 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1171 | mod_bot = buf->b_mod_bot; |
| 1172 | |
| 1173 | #ifdef FEAT_SEARCH_EXTRA |
| 1174 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1175 | * change in one line may make the Search highlighting in a |
| 1176 | * previous line invalid. Simple solution: redraw all visible |
| 1177 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1178 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1179 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1180 | if (search_hl.rm.regprog != NULL |
| 1181 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1182 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1183 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1184 | { |
| 1185 | cur = wp->w_match_head; |
| 1186 | while (cur != NULL) |
| 1187 | { |
| 1188 | if (cur->match.regprog != NULL |
| 1189 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1190 | { |
| 1191 | top_to_mod = TRUE; |
| 1192 | break; |
| 1193 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1194 | cur = cur->next; |
| 1195 | } |
| 1196 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1197 | #endif |
| 1198 | } |
| 1199 | #ifdef FEAT_FOLDING |
| 1200 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1201 | { |
| 1202 | linenr_T lnumt, lnumb; |
| 1203 | |
| 1204 | /* |
| 1205 | * A change in a line can cause lines above it to become folded or |
| 1206 | * unfolded. Find the top most buffer line that may be affected. |
| 1207 | * If the line was previously folded and displayed, get the first |
| 1208 | * line of that fold. If the line is folded now, get the first |
| 1209 | * folded line. Use the minimum of these two. |
| 1210 | */ |
| 1211 | |
| 1212 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1213 | * the line below it. If there is no valid entry, use w_topline. |
| 1214 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1215 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1216 | lnumt = wp->w_topline; |
| 1217 | lnumb = MAXLNUM; |
| 1218 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1219 | if (wp->w_lines[i].wl_valid) |
| 1220 | { |
| 1221 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1222 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1223 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1224 | { |
| 1225 | lnumb = wp->w_lines[i].wl_lnum; |
| 1226 | /* When there is a fold column it might need updating |
| 1227 | * in the next line ("J" just above an open fold). */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 1228 | if (compute_foldcolumn(wp, 0) > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1229 | ++lnumb; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1234 | if (mod_top > lnumt) |
| 1235 | mod_top = lnumt; |
| 1236 | |
| 1237 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1238 | --mod_bot; |
| 1239 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1240 | ++mod_bot; |
| 1241 | if (mod_bot < lnumb) |
| 1242 | mod_bot = lnumb; |
| 1243 | } |
| 1244 | #endif |
| 1245 | |
| 1246 | /* When a change starts above w_topline and the end is below |
| 1247 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1248 | * If the end of the change is above w_topline: do like no change was |
| 1249 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1251 | { |
| 1252 | if (mod_bot > wp->w_topline) |
| 1253 | mod_top = wp->w_topline; |
| 1254 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1255 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1256 | top_end = 1; |
| 1257 | #endif |
| 1258 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1259 | |
| 1260 | /* When line numbers are displayed need to redraw all lines below |
| 1261 | * inserted/deleted lines. */ |
| 1262 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1263 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * When only displaying the lines at the top, set top_end. Used when |
| 1268 | * window has scrolled down for msg_scrolled. |
| 1269 | */ |
| 1270 | if (type == REDRAW_TOP) |
| 1271 | { |
| 1272 | j = 0; |
| 1273 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1274 | { |
| 1275 | j += wp->w_lines[i].wl_size; |
| 1276 | if (j >= wp->w_upd_rows) |
| 1277 | { |
| 1278 | top_end = j; |
| 1279 | break; |
| 1280 | } |
| 1281 | } |
| 1282 | if (top_end == 0) |
| 1283 | /* not found (cannot happen?): redraw everything */ |
| 1284 | type = NOT_VALID; |
| 1285 | else |
| 1286 | /* top area defined, the rest is VALID */ |
| 1287 | type = VALID; |
| 1288 | } |
| 1289 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1290 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1291 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1292 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1293 | * called. */ |
| 1294 | if (screen_cleared) |
| 1295 | screen_cleared = MAYBE; |
| 1296 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1297 | /* |
| 1298 | * If there are no changes on the screen that require a complete redraw, |
| 1299 | * handle three cases: |
| 1300 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1301 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1302 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1303 | * w_lines[] that needs updating. |
| 1304 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1305 | if ((type == VALID || type == SOME_VALID |
| 1306 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1307 | #ifdef FEAT_DIFF |
| 1308 | && !wp->w_botfill && !wp->w_old_botfill |
| 1309 | #endif |
| 1310 | ) |
| 1311 | { |
| 1312 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1313 | { |
| 1314 | /* |
| 1315 | * w_topline is the first changed line, the scrolling will be done |
| 1316 | * further down. |
| 1317 | */ |
| 1318 | } |
| 1319 | else if (wp->w_lines[0].wl_valid |
| 1320 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1321 | #ifdef FEAT_DIFF |
| 1322 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1323 | && wp->w_topfill > wp->w_old_topfill) |
| 1324 | #endif |
| 1325 | )) |
| 1326 | { |
| 1327 | /* |
| 1328 | * New topline is above old topline: May scroll down. |
| 1329 | */ |
| 1330 | #ifdef FEAT_FOLDING |
| 1331 | if (hasAnyFolding(wp)) |
| 1332 | { |
| 1333 | linenr_T ln; |
| 1334 | |
| 1335 | /* count the number of lines we are off, counting a sequence |
| 1336 | * of folded lines as one */ |
| 1337 | j = 0; |
| 1338 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1339 | { |
| 1340 | ++j; |
| 1341 | if (j >= wp->w_height - 2) |
| 1342 | break; |
| 1343 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1344 | } |
| 1345 | } |
| 1346 | else |
| 1347 | #endif |
| 1348 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1349 | if (j < wp->w_height - 2) /* not too far off */ |
| 1350 | { |
| 1351 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1352 | #ifdef FEAT_DIFF |
| 1353 | /* insert extra lines for previously invisible filler lines */ |
| 1354 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1355 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1356 | - wp->w_old_topfill; |
| 1357 | #endif |
| 1358 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1359 | { |
| 1360 | /* |
| 1361 | * Try to insert the correct number of lines. |
| 1362 | * If not the last window, delete the lines at the bottom. |
| 1363 | * win_ins_lines may fail when the terminal can't do it. |
| 1364 | */ |
| 1365 | if (i > 0) |
| 1366 | check_for_delay(FALSE); |
| 1367 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1368 | { |
| 1369 | if (wp->w_lines_valid != 0) |
| 1370 | { |
| 1371 | /* Need to update rows that are new, stop at the |
| 1372 | * first one that scrolled down. */ |
| 1373 | top_end = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1374 | scrolled_down = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1375 | |
| 1376 | /* Move the entries that were scrolled, disable |
| 1377 | * the entries for the lines to be redrawn. */ |
| 1378 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1379 | wp->w_lines_valid = wp->w_height; |
| 1380 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1381 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1382 | while (idx >= 0) |
| 1383 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1384 | } |
| 1385 | } |
| 1386 | else |
| 1387 | mid_start = 0; /* redraw all lines */ |
| 1388 | } |
| 1389 | else |
| 1390 | mid_start = 0; /* redraw all lines */ |
| 1391 | } |
| 1392 | else |
| 1393 | mid_start = 0; /* redraw all lines */ |
| 1394 | } |
| 1395 | else |
| 1396 | { |
| 1397 | /* |
| 1398 | * New topline is at or below old topline: May scroll up. |
| 1399 | * When topline didn't change, find first entry in w_lines[] that |
| 1400 | * needs updating. |
| 1401 | */ |
| 1402 | |
| 1403 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1404 | j = -1; |
| 1405 | row = 0; |
| 1406 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1407 | { |
| 1408 | if (wp->w_lines[i].wl_valid |
| 1409 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1410 | { |
| 1411 | j = i; |
| 1412 | break; |
| 1413 | } |
| 1414 | row += wp->w_lines[i].wl_size; |
| 1415 | } |
| 1416 | if (j == -1) |
| 1417 | { |
| 1418 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1419 | * lines */ |
| 1420 | mid_start = 0; |
| 1421 | } |
| 1422 | else |
| 1423 | { |
| 1424 | /* |
| 1425 | * Try to delete the correct number of lines. |
| 1426 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1427 | */ |
| 1428 | #ifdef FEAT_DIFF |
| 1429 | /* If the topline didn't change, delete old filler lines, |
| 1430 | * otherwise delete filler lines of the new topline... */ |
| 1431 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1432 | row += wp->w_old_topfill; |
| 1433 | else |
| 1434 | row += diff_check_fill(wp, wp->w_topline); |
| 1435 | /* ... but don't delete new filler lines. */ |
| 1436 | row -= wp->w_topfill; |
| 1437 | #endif |
| 1438 | if (row > 0) |
| 1439 | { |
| 1440 | check_for_delay(FALSE); |
| 1441 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1442 | bot_start = wp->w_height - row; |
| 1443 | else |
| 1444 | mid_start = 0; /* redraw all lines */ |
| 1445 | } |
| 1446 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1447 | { |
| 1448 | /* |
| 1449 | * Skip the lines (below the deleted lines) that are still |
| 1450 | * valid and don't need redrawing. Copy their info |
| 1451 | * upwards, to compensate for the deleted lines. Set |
| 1452 | * bot_start to the first row that needs redrawing. |
| 1453 | */ |
| 1454 | bot_start = 0; |
| 1455 | idx = 0; |
| 1456 | for (;;) |
| 1457 | { |
| 1458 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1459 | /* stop at line that didn't fit, unless it is still |
| 1460 | * valid (no lines deleted) */ |
| 1461 | if (row > 0 && bot_start + row |
| 1462 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1463 | { |
| 1464 | wp->w_lines_valid = idx + 1; |
| 1465 | break; |
| 1466 | } |
| 1467 | bot_start += wp->w_lines[idx++].wl_size; |
| 1468 | |
| 1469 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1470 | if (++j >= wp->w_lines_valid) |
| 1471 | { |
| 1472 | wp->w_lines_valid = idx; |
| 1473 | break; |
| 1474 | } |
| 1475 | } |
| 1476 | #ifdef FEAT_DIFF |
| 1477 | /* Correct the first entry for filler lines at the top |
| 1478 | * when it won't get updated below. */ |
| 1479 | if (wp->w_p_diff && bot_start > 0) |
| 1480 | wp->w_lines[0].wl_size = |
| 1481 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1482 | + wp->w_topfill; |
| 1483 | #endif |
| 1484 | } |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | /* When starting redraw in the first line, redraw all lines. When |
| 1489 | * there is only one window it's probably faster to clear the screen |
| 1490 | * first. */ |
| 1491 | if (mid_start == 0) |
| 1492 | { |
| 1493 | mid_end = wp->w_height; |
| 1494 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1495 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1496 | /* Clear the screen when it was not done by win_del_lines() or |
| 1497 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1498 | * then. */ |
| 1499 | if (screen_cleared != TRUE) |
| 1500 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1501 | #ifdef FEAT_WINDOWS |
| 1502 | /* The screen was cleared, redraw the tab pages line. */ |
| 1503 | if (redraw_tabline) |
| 1504 | draw_tabline(); |
| 1505 | #endif |
| 1506 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1507 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1508 | |
| 1509 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1510 | * cleared (only happens for the first window) or when screenclear() |
| 1511 | * was called directly above, "must_redraw" will have been set to |
| 1512 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1513 | if (screen_cleared == TRUE) |
| 1514 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1515 | } |
| 1516 | else |
| 1517 | { |
| 1518 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1519 | mid_start = 0; |
| 1520 | mid_end = wp->w_height; |
| 1521 | } |
| 1522 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1523 | if (type == SOME_VALID) |
| 1524 | { |
| 1525 | /* SOME_VALID: redraw all lines. */ |
| 1526 | mid_start = 0; |
| 1527 | mid_end = wp->w_height; |
| 1528 | type = NOT_VALID; |
| 1529 | } |
| 1530 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1531 | /* check if we are updating or removing the inverted part */ |
| 1532 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1533 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1534 | { |
| 1535 | linenr_T from, to; |
| 1536 | |
| 1537 | if (VIsual_active) |
| 1538 | { |
| 1539 | if (VIsual_active |
| 1540 | && (VIsual_mode != wp->w_old_visual_mode |
| 1541 | || type == INVERTED_ALL)) |
| 1542 | { |
| 1543 | /* |
| 1544 | * If the type of Visual selection changed, redraw the whole |
| 1545 | * selection. Also when the ownership of the X selection is |
| 1546 | * gained or lost. |
| 1547 | */ |
| 1548 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1549 | { |
| 1550 | from = curwin->w_cursor.lnum; |
| 1551 | to = VIsual.lnum; |
| 1552 | } |
| 1553 | else |
| 1554 | { |
| 1555 | from = VIsual.lnum; |
| 1556 | to = curwin->w_cursor.lnum; |
| 1557 | } |
| 1558 | /* redraw more when the cursor moved as well */ |
| 1559 | if (wp->w_old_cursor_lnum < from) |
| 1560 | from = wp->w_old_cursor_lnum; |
| 1561 | if (wp->w_old_cursor_lnum > to) |
| 1562 | to = wp->w_old_cursor_lnum; |
| 1563 | if (wp->w_old_visual_lnum < from) |
| 1564 | from = wp->w_old_visual_lnum; |
| 1565 | if (wp->w_old_visual_lnum > to) |
| 1566 | to = wp->w_old_visual_lnum; |
| 1567 | } |
| 1568 | else |
| 1569 | { |
| 1570 | /* |
| 1571 | * Find the line numbers that need to be updated: The lines |
| 1572 | * between the old cursor position and the current cursor |
| 1573 | * position. Also check if the Visual position changed. |
| 1574 | */ |
| 1575 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1576 | { |
| 1577 | from = curwin->w_cursor.lnum; |
| 1578 | to = wp->w_old_cursor_lnum; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
| 1582 | from = wp->w_old_cursor_lnum; |
| 1583 | to = curwin->w_cursor.lnum; |
| 1584 | if (from == 0) /* Visual mode just started */ |
| 1585 | from = to; |
| 1586 | } |
| 1587 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1588 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1589 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1590 | { |
| 1591 | if (wp->w_old_visual_lnum < from |
| 1592 | && wp->w_old_visual_lnum != 0) |
| 1593 | from = wp->w_old_visual_lnum; |
| 1594 | if (wp->w_old_visual_lnum > to) |
| 1595 | to = wp->w_old_visual_lnum; |
| 1596 | if (VIsual.lnum < from) |
| 1597 | from = VIsual.lnum; |
| 1598 | if (VIsual.lnum > to) |
| 1599 | to = VIsual.lnum; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | /* |
| 1604 | * If in block mode and changed column or curwin->w_curswant: |
| 1605 | * update all lines. |
| 1606 | * First compute the actual start and end column. |
| 1607 | */ |
| 1608 | if (VIsual_mode == Ctrl_V) |
| 1609 | { |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1610 | colnr_T fromc, toc; |
| 1611 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1612 | int save_ve_flags = ve_flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1613 | |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1614 | if (curwin->w_p_lbr) |
| 1615 | ve_flags = VE_ALL; |
| 1616 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1617 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1618 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1619 | ve_flags = save_ve_flags; |
| 1620 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1621 | ++toc; |
| 1622 | if (curwin->w_curswant == MAXCOL) |
| 1623 | toc = MAXCOL; |
| 1624 | |
| 1625 | if (fromc != wp->w_old_cursor_fcol |
| 1626 | || toc != wp->w_old_cursor_lcol) |
| 1627 | { |
| 1628 | if (from > VIsual.lnum) |
| 1629 | from = VIsual.lnum; |
| 1630 | if (to < VIsual.lnum) |
| 1631 | to = VIsual.lnum; |
| 1632 | } |
| 1633 | wp->w_old_cursor_fcol = fromc; |
| 1634 | wp->w_old_cursor_lcol = toc; |
| 1635 | } |
| 1636 | } |
| 1637 | else |
| 1638 | { |
| 1639 | /* Use the line numbers of the old Visual area. */ |
| 1640 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1641 | { |
| 1642 | from = wp->w_old_cursor_lnum; |
| 1643 | to = wp->w_old_visual_lnum; |
| 1644 | } |
| 1645 | else |
| 1646 | { |
| 1647 | from = wp->w_old_visual_lnum; |
| 1648 | to = wp->w_old_cursor_lnum; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | /* |
| 1653 | * There is no need to update lines above the top of the window. |
| 1654 | */ |
| 1655 | if (from < wp->w_topline) |
| 1656 | from = wp->w_topline; |
| 1657 | |
| 1658 | /* |
| 1659 | * If we know the value of w_botline, use it to restrict the update to |
| 1660 | * the lines that are visible in the window. |
| 1661 | */ |
| 1662 | if (wp->w_valid & VALID_BOTLINE) |
| 1663 | { |
| 1664 | if (from >= wp->w_botline) |
| 1665 | from = wp->w_botline - 1; |
| 1666 | if (to >= wp->w_botline) |
| 1667 | to = wp->w_botline - 1; |
| 1668 | } |
| 1669 | |
| 1670 | /* |
| 1671 | * Find the minimal part to be updated. |
| 1672 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1673 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1674 | * top_end; need to redraw from top_end to the "to" line. |
| 1675 | * A middle mouse click with a Visual selection may change the text |
| 1676 | * above the Visual area and reset wl_valid, do count these for |
| 1677 | * mid_end (in srow). |
| 1678 | */ |
| 1679 | if (mid_start > 0) |
| 1680 | { |
| 1681 | lnum = wp->w_topline; |
| 1682 | idx = 0; |
| 1683 | srow = 0; |
| 1684 | if (scrolled_down) |
| 1685 | mid_start = top_end; |
| 1686 | else |
| 1687 | mid_start = 0; |
| 1688 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1689 | { |
| 1690 | if (wp->w_lines[idx].wl_valid) |
| 1691 | mid_start += wp->w_lines[idx].wl_size; |
| 1692 | else if (!scrolled_down) |
| 1693 | srow += wp->w_lines[idx].wl_size; |
| 1694 | ++idx; |
| 1695 | # ifdef FEAT_FOLDING |
| 1696 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1697 | lnum = wp->w_lines[idx].wl_lnum; |
| 1698 | else |
| 1699 | # endif |
| 1700 | ++lnum; |
| 1701 | } |
| 1702 | srow += mid_start; |
| 1703 | mid_end = wp->w_height; |
| 1704 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1705 | { |
| 1706 | if (wp->w_lines[idx].wl_valid |
| 1707 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1708 | { |
| 1709 | /* Only update until first row of this line */ |
| 1710 | mid_end = srow; |
| 1711 | break; |
| 1712 | } |
| 1713 | srow += wp->w_lines[idx].wl_size; |
| 1714 | } |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | if (VIsual_active && buf == curwin->w_buffer) |
| 1719 | { |
| 1720 | wp->w_old_visual_mode = VIsual_mode; |
| 1721 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1722 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1723 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1724 | wp->w_old_curswant = curwin->w_curswant; |
| 1725 | } |
| 1726 | else |
| 1727 | { |
| 1728 | wp->w_old_visual_mode = 0; |
| 1729 | wp->w_old_cursor_lnum = 0; |
| 1730 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1731 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1732 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1733 | |
| 1734 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1735 | /* reset got_int, otherwise regexp won't work */ |
| 1736 | save_got_int = got_int; |
| 1737 | got_int = 0; |
| 1738 | #endif |
| 1739 | #ifdef FEAT_FOLDING |
| 1740 | win_foldinfo.fi_level = 0; |
| 1741 | #endif |
| 1742 | |
| 1743 | /* |
| 1744 | * Update all the window rows. |
| 1745 | */ |
| 1746 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1747 | row = 0; |
| 1748 | srow = 0; |
| 1749 | lnum = wp->w_topline; /* first line shown in window */ |
| 1750 | for (;;) |
| 1751 | { |
| 1752 | /* stop updating when reached the end of the window (check for _past_ |
| 1753 | * the end of the window is at the end of the loop) */ |
| 1754 | if (row == wp->w_height) |
| 1755 | { |
| 1756 | didline = TRUE; |
| 1757 | break; |
| 1758 | } |
| 1759 | |
| 1760 | /* stop updating when hit the end of the file */ |
| 1761 | if (lnum > buf->b_ml.ml_line_count) |
| 1762 | { |
| 1763 | eof = TRUE; |
| 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | /* Remember the starting row of the line that is going to be dealt |
| 1768 | * with. It is used further down when the line doesn't fit. */ |
| 1769 | srow = row; |
| 1770 | |
| 1771 | /* |
| 1772 | * Update a line when it is in an area that needs updating, when it |
| 1773 | * has changes or w_lines[idx] is invalid. |
| 1774 | * bot_start may be halfway a wrapped line after using |
| 1775 | * win_del_lines(), check if the current line includes it. |
| 1776 | * When syntax folding is being used, the saved syntax states will |
| 1777 | * already have been updated, we can't see where the syntax state is |
| 1778 | * the same again, just update until the end of the window. |
| 1779 | */ |
| 1780 | if (row < top_end |
| 1781 | || (row >= mid_start && row < mid_end) |
| 1782 | #ifdef FEAT_SEARCH_EXTRA |
| 1783 | || top_to_mod |
| 1784 | #endif |
| 1785 | || idx >= wp->w_lines_valid |
| 1786 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1787 | || (mod_top != 0 |
| 1788 | && (lnum == mod_top |
| 1789 | || (lnum >= mod_top |
| 1790 | && (lnum < mod_bot |
| 1791 | #ifdef FEAT_SYN_HL |
| 1792 | || did_update == DID_FOLD |
| 1793 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1794 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1795 | && ( |
| 1796 | # ifdef FEAT_FOLDING |
| 1797 | (foldmethodIsSyntax(wp) |
| 1798 | && hasAnyFolding(wp)) || |
| 1799 | # endif |
| 1800 | syntax_check_changed(lnum))) |
| 1801 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1802 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | dab70c6 | 2014-07-02 17:16:58 +0200 | [diff] [blame] | 1803 | /* match in fixed position might need redraw |
| 1804 | * if lines were inserted or deleted */ |
| 1805 | || (wp->w_match_head != NULL |
| 1806 | && buf->b_mod_xlines != 0) |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1807 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1808 | ))))) |
| 1809 | { |
| 1810 | #ifdef FEAT_SEARCH_EXTRA |
| 1811 | if (lnum == mod_top) |
| 1812 | top_to_mod = FALSE; |
| 1813 | #endif |
| 1814 | |
| 1815 | /* |
| 1816 | * When at start of changed lines: May scroll following lines |
| 1817 | * up or down to minimize redrawing. |
| 1818 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1819 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1820 | */ |
| 1821 | if (lnum == mod_top |
| 1822 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1823 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1824 | { |
| 1825 | int old_rows = 0; |
| 1826 | int new_rows = 0; |
| 1827 | int xtra_rows; |
| 1828 | linenr_T l; |
| 1829 | |
| 1830 | /* Count the old number of window rows, using w_lines[], which |
| 1831 | * should still contain the sizes for the lines as they are |
| 1832 | * currently displayed. */ |
| 1833 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1834 | { |
| 1835 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1836 | * lines are part of the changed area. */ |
| 1837 | if (wp->w_lines[i].wl_valid |
| 1838 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1839 | break; |
| 1840 | old_rows += wp->w_lines[i].wl_size; |
| 1841 | #ifdef FEAT_FOLDING |
| 1842 | if (wp->w_lines[i].wl_valid |
| 1843 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1844 | { |
| 1845 | /* Must have found the last valid entry above mod_bot. |
| 1846 | * Add following invalid entries. */ |
| 1847 | ++i; |
| 1848 | while (i < wp->w_lines_valid |
| 1849 | && !wp->w_lines[i].wl_valid) |
| 1850 | old_rows += wp->w_lines[i++].wl_size; |
| 1851 | break; |
| 1852 | } |
| 1853 | #endif |
| 1854 | } |
| 1855 | |
| 1856 | if (i >= wp->w_lines_valid) |
| 1857 | { |
| 1858 | /* We can't find a valid line below the changed lines, |
| 1859 | * need to redraw until the end of the window. |
| 1860 | * Inserting/deleting lines has no use. */ |
| 1861 | bot_start = 0; |
| 1862 | } |
| 1863 | else |
| 1864 | { |
| 1865 | /* Able to count old number of rows: Count new window |
| 1866 | * rows, and may insert/delete lines */ |
| 1867 | j = idx; |
| 1868 | for (l = lnum; l < mod_bot; ++l) |
| 1869 | { |
| 1870 | #ifdef FEAT_FOLDING |
| 1871 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1872 | ++new_rows; |
| 1873 | else |
| 1874 | #endif |
| 1875 | #ifdef FEAT_DIFF |
| 1876 | if (l == wp->w_topline) |
| 1877 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1878 | + wp->w_topfill; |
| 1879 | else |
| 1880 | #endif |
| 1881 | new_rows += plines_win(wp, l, TRUE); |
| 1882 | ++j; |
| 1883 | if (new_rows > wp->w_height - row - 2) |
| 1884 | { |
| 1885 | /* it's getting too much, must redraw the rest */ |
| 1886 | new_rows = 9999; |
| 1887 | break; |
| 1888 | } |
| 1889 | } |
| 1890 | xtra_rows = new_rows - old_rows; |
| 1891 | if (xtra_rows < 0) |
| 1892 | { |
| 1893 | /* May scroll text up. If there is not enough |
| 1894 | * remaining text or scrolling fails, must redraw the |
| 1895 | * rest. If scrolling works, must redraw the text |
| 1896 | * below the scrolled text. */ |
| 1897 | if (row - xtra_rows >= wp->w_height - 2) |
| 1898 | mod_bot = MAXLNUM; |
| 1899 | else |
| 1900 | { |
| 1901 | check_for_delay(FALSE); |
| 1902 | if (win_del_lines(wp, row, |
| 1903 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1904 | mod_bot = MAXLNUM; |
| 1905 | else |
| 1906 | bot_start = wp->w_height + xtra_rows; |
| 1907 | } |
| 1908 | } |
| 1909 | else if (xtra_rows > 0) |
| 1910 | { |
| 1911 | /* May scroll text down. If there is not enough |
| 1912 | * remaining text of scrolling fails, must redraw the |
| 1913 | * rest. */ |
| 1914 | if (row + xtra_rows >= wp->w_height - 2) |
| 1915 | mod_bot = MAXLNUM; |
| 1916 | else |
| 1917 | { |
| 1918 | check_for_delay(FALSE); |
| 1919 | if (win_ins_lines(wp, row + old_rows, |
| 1920 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1921 | mod_bot = MAXLNUM; |
| 1922 | else if (top_end > row + old_rows) |
| 1923 | /* Scrolled the part at the top that requires |
| 1924 | * updating down. */ |
| 1925 | top_end += xtra_rows; |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | /* When not updating the rest, may need to move w_lines[] |
| 1930 | * entries. */ |
| 1931 | if (mod_bot != MAXLNUM && i != j) |
| 1932 | { |
| 1933 | if (j < i) |
| 1934 | { |
| 1935 | int x = row + new_rows; |
| 1936 | |
| 1937 | /* move entries in w_lines[] upwards */ |
| 1938 | for (;;) |
| 1939 | { |
| 1940 | /* stop at last valid entry in w_lines[] */ |
| 1941 | if (i >= wp->w_lines_valid) |
| 1942 | { |
| 1943 | wp->w_lines_valid = j; |
| 1944 | break; |
| 1945 | } |
| 1946 | wp->w_lines[j] = wp->w_lines[i]; |
| 1947 | /* stop at a line that won't fit */ |
| 1948 | if (x + (int)wp->w_lines[j].wl_size |
| 1949 | > wp->w_height) |
| 1950 | { |
| 1951 | wp->w_lines_valid = j + 1; |
| 1952 | break; |
| 1953 | } |
| 1954 | x += wp->w_lines[j++].wl_size; |
| 1955 | ++i; |
| 1956 | } |
| 1957 | if (bot_start > x) |
| 1958 | bot_start = x; |
| 1959 | } |
| 1960 | else /* j > i */ |
| 1961 | { |
| 1962 | /* move entries in w_lines[] downwards */ |
| 1963 | j -= i; |
| 1964 | wp->w_lines_valid += j; |
| 1965 | if (wp->w_lines_valid > wp->w_height) |
| 1966 | wp->w_lines_valid = wp->w_height; |
| 1967 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1968 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1969 | |
| 1970 | /* The w_lines[] entries for inserted lines are |
| 1971 | * now invalid, but wl_size may be used above. |
| 1972 | * Reset to zero. */ |
| 1973 | while (i >= idx) |
| 1974 | { |
| 1975 | wp->w_lines[i].wl_size = 0; |
| 1976 | wp->w_lines[i--].wl_valid = FALSE; |
| 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | #ifdef FEAT_FOLDING |
| 1984 | /* |
| 1985 | * When lines are folded, display one line for all of them. |
| 1986 | * Otherwise, display normally (can be several display lines when |
| 1987 | * 'wrap' is on). |
| 1988 | */ |
| 1989 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1990 | if (fold_count != 0) |
| 1991 | { |
| 1992 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1993 | ++row; |
| 1994 | --fold_count; |
| 1995 | wp->w_lines[idx].wl_folded = TRUE; |
| 1996 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1997 | # ifdef FEAT_SYN_HL |
| 1998 | did_update = DID_FOLD; |
| 1999 | # endif |
| 2000 | } |
| 2001 | else |
| 2002 | #endif |
| 2003 | if (idx < wp->w_lines_valid |
| 2004 | && wp->w_lines[idx].wl_valid |
| 2005 | && wp->w_lines[idx].wl_lnum == lnum |
| 2006 | && lnum > wp->w_topline |
| 2007 | && !(dy_flags & DY_LASTLINE) |
| 2008 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 2009 | #ifdef FEAT_DIFF |
| 2010 | && diff_check_fill(wp, lnum) == 0 |
| 2011 | #endif |
| 2012 | ) |
| 2013 | { |
| 2014 | /* This line is not going to fit. Don't draw anything here, |
| 2015 | * will draw "@ " lines below. */ |
| 2016 | row = wp->w_height + 1; |
| 2017 | } |
| 2018 | else |
| 2019 | { |
| 2020 | #ifdef FEAT_SEARCH_EXTRA |
| 2021 | prepare_search_hl(wp, lnum); |
| 2022 | #endif |
| 2023 | #ifdef FEAT_SYN_HL |
| 2024 | /* Let the syntax stuff know we skipped a few lines. */ |
| 2025 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2026 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2027 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2028 | #endif |
| 2029 | |
| 2030 | /* |
| 2031 | * Display one line. |
| 2032 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2033 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2034 | |
| 2035 | #ifdef FEAT_FOLDING |
| 2036 | wp->w_lines[idx].wl_folded = FALSE; |
| 2037 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2038 | #endif |
| 2039 | #ifdef FEAT_SYN_HL |
| 2040 | did_update = DID_LINE; |
| 2041 | syntax_last_parsed = lnum; |
| 2042 | #endif |
| 2043 | } |
| 2044 | |
| 2045 | wp->w_lines[idx].wl_lnum = lnum; |
| 2046 | wp->w_lines[idx].wl_valid = TRUE; |
| 2047 | if (row > wp->w_height) /* past end of screen */ |
| 2048 | { |
| 2049 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2050 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2051 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2052 | ++idx; |
| 2053 | break; |
| 2054 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2055 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2056 | wp->w_lines[idx].wl_size = row - srow; |
| 2057 | ++idx; |
| 2058 | #ifdef FEAT_FOLDING |
| 2059 | lnum += fold_count + 1; |
| 2060 | #else |
| 2061 | ++lnum; |
| 2062 | #endif |
| 2063 | } |
| 2064 | else |
| 2065 | { |
| 2066 | /* This line does not need updating, advance to the next one */ |
| 2067 | row += wp->w_lines[idx++].wl_size; |
| 2068 | if (row > wp->w_height) /* past end of screen */ |
| 2069 | break; |
| 2070 | #ifdef FEAT_FOLDING |
| 2071 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2072 | #else |
| 2073 | ++lnum; |
| 2074 | #endif |
| 2075 | #ifdef FEAT_SYN_HL |
| 2076 | did_update = DID_NONE; |
| 2077 | #endif |
| 2078 | } |
| 2079 | |
| 2080 | if (lnum > buf->b_ml.ml_line_count) |
| 2081 | { |
| 2082 | eof = TRUE; |
| 2083 | break; |
| 2084 | } |
| 2085 | } |
| 2086 | /* |
| 2087 | * End of loop over all window lines. |
| 2088 | */ |
| 2089 | |
| 2090 | |
| 2091 | if (idx > wp->w_lines_valid) |
| 2092 | wp->w_lines_valid = idx; |
| 2093 | |
| 2094 | #ifdef FEAT_SYN_HL |
| 2095 | /* |
| 2096 | * Let the syntax stuff know we stop parsing here. |
| 2097 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2098 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2099 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2100 | #endif |
| 2101 | |
| 2102 | /* |
| 2103 | * If we didn't hit the end of the file, and we didn't finish the last |
| 2104 | * line we were working on, then the line didn't fit. |
| 2105 | */ |
| 2106 | wp->w_empty_rows = 0; |
| 2107 | #ifdef FEAT_DIFF |
| 2108 | wp->w_filler_rows = 0; |
| 2109 | #endif |
| 2110 | if (!eof && !didline) |
| 2111 | { |
| 2112 | if (lnum == wp->w_topline) |
| 2113 | { |
| 2114 | /* |
| 2115 | * Single line that does not fit! |
| 2116 | * Don't overwrite it, it can be edited. |
| 2117 | */ |
| 2118 | wp->w_botline = lnum + 1; |
| 2119 | } |
| 2120 | #ifdef FEAT_DIFF |
| 2121 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2122 | { |
| 2123 | /* Window ends in filler lines. */ |
| 2124 | wp->w_botline = lnum; |
| 2125 | wp->w_filler_rows = wp->w_height - srow; |
| 2126 | } |
| 2127 | #endif |
| 2128 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 2129 | { |
| 2130 | /* |
| 2131 | * Last line isn't finished: Display "@@@" at the end. |
| 2132 | */ |
| 2133 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2134 | W_WINROW(wp) + wp->w_height, |
| 2135 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 2136 | '@', '@', hl_attr(HLF_AT)); |
| 2137 | set_empty_rows(wp, srow); |
| 2138 | wp->w_botline = lnum; |
| 2139 | } |
| 2140 | else |
| 2141 | { |
| 2142 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 2143 | wp->w_botline = lnum; |
| 2144 | } |
| 2145 | } |
| 2146 | else |
| 2147 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 2148 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2149 | draw_vsep_win(wp, row); |
| 2150 | #endif |
| 2151 | if (eof) /* we hit the end of the file */ |
| 2152 | { |
| 2153 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2154 | #ifdef FEAT_DIFF |
| 2155 | j = diff_check_fill(wp, wp->w_botline); |
| 2156 | if (j > 0 && !wp->w_botfill) |
| 2157 | { |
| 2158 | /* |
| 2159 | * Display filler lines at the end of the file |
| 2160 | */ |
| 2161 | if (char2cells(fill_diff) > 1) |
| 2162 | i = '-'; |
| 2163 | else |
| 2164 | i = fill_diff; |
| 2165 | if (row + j > wp->w_height) |
| 2166 | j = wp->w_height - row; |
| 2167 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2168 | row += j; |
| 2169 | } |
| 2170 | #endif |
| 2171 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2172 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2173 | wp->w_botline = lnum; |
| 2174 | |
| 2175 | /* make sure the rest of the screen is blank */ |
| 2176 | /* put '~'s on rows that aren't part of the file. */ |
| 2177 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 2178 | } |
| 2179 | |
| 2180 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2181 | wp->w_redr_type = 0; |
| 2182 | #ifdef FEAT_DIFF |
| 2183 | wp->w_old_topfill = wp->w_topfill; |
| 2184 | wp->w_old_botfill = wp->w_botfill; |
| 2185 | #endif |
| 2186 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2187 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2188 | { |
| 2189 | /* |
| 2190 | * There is a trick with w_botline. If we invalidate it on each |
| 2191 | * change that might modify it, this will cause a lot of expensive |
| 2192 | * calls to plines() in update_topline() each time. Therefore the |
| 2193 | * value of w_botline is often approximated, and this value is used to |
| 2194 | * compute the value of w_topline. If the value of w_botline was |
| 2195 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2196 | * the visible part of the text). If it's not, we need to redraw |
| 2197 | * again. Mostly this just means scrolling up a few lines, so it |
| 2198 | * doesn't look too bad. Only do this for the current window (where |
| 2199 | * changes are relevant). |
| 2200 | */ |
| 2201 | wp->w_valid |= VALID_BOTLINE; |
| 2202 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2203 | { |
| 2204 | recursive = TRUE; |
| 2205 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2206 | update_topline(); /* may invalidate w_botline again */ |
| 2207 | if (must_redraw != 0) |
| 2208 | { |
| 2209 | /* Don't update for changes in buffer again. */ |
| 2210 | i = curbuf->b_mod_set; |
| 2211 | curbuf->b_mod_set = FALSE; |
| 2212 | win_update(curwin); |
| 2213 | must_redraw = 0; |
| 2214 | curbuf->b_mod_set = i; |
| 2215 | } |
| 2216 | recursive = FALSE; |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2221 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2222 | if (!got_int) |
| 2223 | got_int = save_got_int; |
| 2224 | #endif |
| 2225 | } |
| 2226 | |
| 2227 | #ifdef FEAT_SIGNS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2228 | static int draw_signcolumn(win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2229 | |
| 2230 | /* |
| 2231 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2232 | */ |
| 2233 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2234 | draw_signcolumn(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2235 | { |
| 2236 | return (wp->w_buffer->b_signlist != NULL |
| 2237 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | 3b7b836 | 2015-03-20 18:11:48 +0100 | [diff] [blame] | 2238 | || wp->w_buffer->b_has_sign_column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2239 | # endif |
| 2240 | ); |
| 2241 | } |
| 2242 | #endif |
| 2243 | |
| 2244 | /* |
| 2245 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2246 | * as the filler character. |
| 2247 | */ |
| 2248 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2249 | win_draw_end( |
| 2250 | win_T *wp, |
| 2251 | int c1, |
| 2252 | int c2, |
| 2253 | int row, |
| 2254 | int endrow, |
| 2255 | hlf_T hl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2256 | { |
| 2257 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2258 | int n = 0; |
| 2259 | # define FDC_OFF n |
| 2260 | #else |
| 2261 | # define FDC_OFF 0 |
| 2262 | #endif |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2263 | #ifdef FEAT_FOLDING |
| 2264 | int fdc = compute_foldcolumn(wp, 0); |
| 2265 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2266 | |
| 2267 | #ifdef FEAT_RIGHTLEFT |
| 2268 | if (wp->w_p_rl) |
| 2269 | { |
| 2270 | /* No check for cmdline window: should never be right-left. */ |
| 2271 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2272 | n = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2273 | |
| 2274 | if (n > 0) |
| 2275 | { |
| 2276 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2277 | if (n > W_WIDTH(wp)) |
| 2278 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2279 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2280 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2281 | ' ', ' ', hl_attr(HLF_FC)); |
| 2282 | } |
| 2283 | # endif |
| 2284 | # ifdef FEAT_SIGNS |
| 2285 | if (draw_signcolumn(wp)) |
| 2286 | { |
| 2287 | int nn = n + 2; |
| 2288 | |
| 2289 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2290 | if (nn > W_WIDTH(wp)) |
| 2291 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2292 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2293 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2294 | ' ', ' ', hl_attr(HLF_SC)); |
| 2295 | n = nn; |
| 2296 | } |
| 2297 | # endif |
| 2298 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2299 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2300 | c2, c2, hl_attr(hl)); |
| 2301 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2302 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2303 | c1, c2, hl_attr(hl)); |
| 2304 | } |
| 2305 | else |
| 2306 | #endif |
| 2307 | { |
| 2308 | #ifdef FEAT_CMDWIN |
| 2309 | if (cmdwin_type != 0 && wp == curwin) |
| 2310 | { |
| 2311 | /* draw the cmdline character in the leftmost column */ |
| 2312 | n = 1; |
| 2313 | if (n > wp->w_width) |
| 2314 | n = wp->w_width; |
| 2315 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2316 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2317 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2318 | } |
| 2319 | #endif |
| 2320 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2321 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2322 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2323 | int nn = n + fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2324 | |
| 2325 | /* draw the fold column at the left */ |
| 2326 | if (nn > W_WIDTH(wp)) |
| 2327 | nn = W_WIDTH(wp); |
| 2328 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2329 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2330 | ' ', ' ', hl_attr(HLF_FC)); |
| 2331 | n = nn; |
| 2332 | } |
| 2333 | #endif |
| 2334 | #ifdef FEAT_SIGNS |
| 2335 | if (draw_signcolumn(wp)) |
| 2336 | { |
| 2337 | int nn = n + 2; |
| 2338 | |
| 2339 | /* draw the sign column after the fold column */ |
| 2340 | if (nn > W_WIDTH(wp)) |
| 2341 | nn = W_WIDTH(wp); |
| 2342 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2343 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2344 | ' ', ' ', hl_attr(HLF_SC)); |
| 2345 | n = nn; |
| 2346 | } |
| 2347 | #endif |
| 2348 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2349 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2350 | c1, c2, hl_attr(hl)); |
| 2351 | } |
| 2352 | set_empty_rows(wp, row); |
| 2353 | } |
| 2354 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2355 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2356 | static int advance_color_col(int vcol, int **color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2357 | |
| 2358 | /* |
| 2359 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2360 | */ |
| 2361 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2362 | advance_color_col(int vcol, int **color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2363 | { |
| 2364 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2365 | ++*color_cols; |
| 2366 | return (**color_cols >= 0); |
| 2367 | } |
| 2368 | #endif |
| 2369 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2370 | #ifdef FEAT_FOLDING |
| 2371 | /* |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2372 | * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much |
| 2373 | * space is available for window "wp", minus "col". |
| 2374 | */ |
| 2375 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2376 | compute_foldcolumn(win_T *wp, int col) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2377 | { |
| 2378 | int fdc = wp->w_p_fdc; |
| 2379 | int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; |
| 2380 | int wwidth = W_WIDTH(wp); |
| 2381 | |
| 2382 | if (fdc > wwidth - (col + wmw)) |
| 2383 | fdc = wwidth - (col + wmw); |
| 2384 | return fdc; |
| 2385 | } |
| 2386 | |
| 2387 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2388 | * Display one folded line. |
| 2389 | */ |
| 2390 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2391 | fold_line( |
| 2392 | win_T *wp, |
| 2393 | long fold_count, |
| 2394 | foldinfo_T *foldinfo, |
| 2395 | linenr_T lnum, |
| 2396 | int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2397 | { |
| 2398 | char_u buf[51]; |
| 2399 | pos_T *top, *bot; |
| 2400 | linenr_T lnume = lnum + fold_count - 1; |
| 2401 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2402 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2403 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2404 | int col; |
| 2405 | int txtcol; |
| 2406 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2407 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2408 | |
| 2409 | /* Build the fold line: |
| 2410 | * 1. Add the cmdwin_type for the command-line window |
| 2411 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2412 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2413 | * 4. Compose the text |
| 2414 | * 5. Add the text |
| 2415 | * 6. set highlighting for the Visual area an other text |
| 2416 | */ |
| 2417 | col = 0; |
| 2418 | |
| 2419 | /* |
| 2420 | * 1. Add the cmdwin_type for the command-line window |
| 2421 | * Ignores 'rightleft', this window is never right-left. |
| 2422 | */ |
| 2423 | #ifdef FEAT_CMDWIN |
| 2424 | if (cmdwin_type != 0 && wp == curwin) |
| 2425 | { |
| 2426 | ScreenLines[off] = cmdwin_type; |
| 2427 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2428 | #ifdef FEAT_MBYTE |
| 2429 | if (enc_utf8) |
| 2430 | ScreenLinesUC[off] = 0; |
| 2431 | #endif |
| 2432 | ++col; |
| 2433 | } |
| 2434 | #endif |
| 2435 | |
| 2436 | /* |
| 2437 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2438 | * Reduce the width when there is not enough space. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2439 | */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2440 | fdc = compute_foldcolumn(wp, col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2441 | if (fdc > 0) |
| 2442 | { |
| 2443 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2444 | #ifdef FEAT_RIGHTLEFT |
| 2445 | if (wp->w_p_rl) |
| 2446 | { |
| 2447 | int i; |
| 2448 | |
| 2449 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2450 | hl_attr(HLF_FC)); |
| 2451 | /* reverse the fold column */ |
| 2452 | for (i = 0; i < fdc; ++i) |
| 2453 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2454 | } |
| 2455 | else |
| 2456 | #endif |
| 2457 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2458 | col += fdc; |
| 2459 | } |
| 2460 | |
| 2461 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2462 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2463 | for (ri = 0; ri < l; ++ri) \ |
| 2464 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2465 | else \ |
| 2466 | for (ri = 0; ri < l; ++ri) \ |
| 2467 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2468 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2469 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2470 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2471 | #endif |
| 2472 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2473 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2474 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2475 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2476 | |
| 2477 | #ifdef FEAT_SIGNS |
| 2478 | /* If signs are being displayed, add two spaces. */ |
| 2479 | if (draw_signcolumn(wp)) |
| 2480 | { |
| 2481 | len = W_WIDTH(wp) - col; |
| 2482 | if (len > 0) |
| 2483 | { |
| 2484 | if (len > 2) |
| 2485 | len = 2; |
| 2486 | # ifdef FEAT_RIGHTLEFT |
| 2487 | if (wp->w_p_rl) |
| 2488 | /* the line number isn't reversed */ |
| 2489 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2490 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2491 | else |
| 2492 | # endif |
| 2493 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2494 | col += len; |
| 2495 | } |
| 2496 | } |
| 2497 | #endif |
| 2498 | |
| 2499 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2500 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2501 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2502 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2503 | { |
| 2504 | len = W_WIDTH(wp) - col; |
| 2505 | if (len > 0) |
| 2506 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2507 | int w = number_width(wp); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2508 | long num; |
| 2509 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2510 | |
| 2511 | if (len > w + 1) |
| 2512 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2513 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2514 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2515 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2516 | num = (long)lnum; |
| 2517 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2518 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2519 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2520 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2521 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2522 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2523 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2524 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2525 | num = lnum; |
| 2526 | fmt = "%-*ld "; |
| 2527 | } |
| 2528 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2529 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2530 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2531 | #ifdef FEAT_RIGHTLEFT |
| 2532 | if (wp->w_p_rl) |
| 2533 | /* the line number isn't reversed */ |
| 2534 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2535 | hl_attr(HLF_FL)); |
| 2536 | else |
| 2537 | #endif |
| 2538 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2539 | col += len; |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | /* |
| 2544 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2545 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2546 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2547 | |
| 2548 | txtcol = col; /* remember where text starts */ |
| 2549 | |
| 2550 | /* |
| 2551 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2552 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2553 | * in columns number-col - window-width. |
| 2554 | */ |
| 2555 | #ifdef FEAT_MBYTE |
| 2556 | if (has_mbyte) |
| 2557 | { |
| 2558 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2559 | int u8c, u8cc[MAX_MCO]; |
| 2560 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2561 | int idx; |
| 2562 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2563 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2564 | # ifdef FEAT_ARABIC |
| 2565 | int prev_c = 0; /* previous Arabic character */ |
| 2566 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2567 | # endif |
| 2568 | |
| 2569 | # ifdef FEAT_RIGHTLEFT |
| 2570 | if (wp->w_p_rl) |
| 2571 | idx = off; |
| 2572 | else |
| 2573 | # endif |
| 2574 | idx = off + col; |
| 2575 | |
| 2576 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2577 | for (p = text; *p != NUL; ) |
| 2578 | { |
| 2579 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2580 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2581 | if (col + cells > W_WIDTH(wp) |
| 2582 | # ifdef FEAT_RIGHTLEFT |
| 2583 | - (wp->w_p_rl ? col : 0) |
| 2584 | # endif |
| 2585 | ) |
| 2586 | break; |
| 2587 | ScreenLines[idx] = *p; |
| 2588 | if (enc_utf8) |
| 2589 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2590 | u8c = utfc_ptr2char(p, u8cc); |
| 2591 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2592 | { |
| 2593 | ScreenLinesUC[idx] = 0; |
| 2594 | #ifdef FEAT_ARABIC |
| 2595 | prev_c = u8c; |
| 2596 | #endif |
| 2597 | } |
| 2598 | else |
| 2599 | { |
| 2600 | #ifdef FEAT_ARABIC |
| 2601 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2602 | { |
| 2603 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2604 | int pc, pc1, nc; |
| 2605 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2606 | int firstbyte = *p; |
| 2607 | |
| 2608 | /* The idea of what is the previous and next |
| 2609 | * character depends on 'rightleft'. */ |
| 2610 | if (wp->w_p_rl) |
| 2611 | { |
| 2612 | pc = prev_c; |
| 2613 | pc1 = prev_c1; |
| 2614 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2615 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2616 | } |
| 2617 | else |
| 2618 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2619 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2620 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2621 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2622 | } |
| 2623 | prev_c = u8c; |
| 2624 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2625 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2626 | pc, pc1, nc); |
| 2627 | ScreenLines[idx] = firstbyte; |
| 2628 | } |
| 2629 | else |
| 2630 | prev_c = u8c; |
| 2631 | #endif |
| 2632 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2633 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2634 | if (u8c >= 0x10000) |
| 2635 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2636 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2637 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2638 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2639 | for (i = 0; i < Screen_mco; ++i) |
| 2640 | { |
| 2641 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2642 | if (u8cc[i] == 0) |
| 2643 | break; |
| 2644 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2645 | } |
| 2646 | if (cells > 1) |
| 2647 | ScreenLines[idx + 1] = 0; |
| 2648 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2649 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2650 | /* double-byte single width character */ |
| 2651 | ScreenLines2[idx] = p[1]; |
| 2652 | else if (cells > 1) |
| 2653 | /* double-width character */ |
| 2654 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2655 | col += cells; |
| 2656 | idx += cells; |
| 2657 | p += c_len; |
| 2658 | } |
| 2659 | } |
| 2660 | else |
| 2661 | #endif |
| 2662 | { |
| 2663 | len = (int)STRLEN(text); |
| 2664 | if (len > W_WIDTH(wp) - col) |
| 2665 | len = W_WIDTH(wp) - col; |
| 2666 | if (len > 0) |
| 2667 | { |
| 2668 | #ifdef FEAT_RIGHTLEFT |
| 2669 | if (wp->w_p_rl) |
| 2670 | STRNCPY(current_ScreenLine, text, len); |
| 2671 | else |
| 2672 | #endif |
| 2673 | STRNCPY(current_ScreenLine + col, text, len); |
| 2674 | col += len; |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /* Fill the rest of the line with the fold filler */ |
| 2679 | #ifdef FEAT_RIGHTLEFT |
| 2680 | if (wp->w_p_rl) |
| 2681 | col -= txtcol; |
| 2682 | #endif |
| 2683 | while (col < W_WIDTH(wp) |
| 2684 | #ifdef FEAT_RIGHTLEFT |
| 2685 | - (wp->w_p_rl ? txtcol : 0) |
| 2686 | #endif |
| 2687 | ) |
| 2688 | { |
| 2689 | #ifdef FEAT_MBYTE |
| 2690 | if (enc_utf8) |
| 2691 | { |
| 2692 | if (fill_fold >= 0x80) |
| 2693 | { |
| 2694 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2695 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2696 | } |
| 2697 | else |
| 2698 | ScreenLinesUC[off + col] = 0; |
| 2699 | } |
| 2700 | #endif |
| 2701 | ScreenLines[off + col++] = fill_fold; |
| 2702 | } |
| 2703 | |
| 2704 | if (text != buf) |
| 2705 | vim_free(text); |
| 2706 | |
| 2707 | /* |
| 2708 | * 6. set highlighting for the Visual area an other text. |
| 2709 | * If all folded lines are in the Visual area, highlight the line. |
| 2710 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2711 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2712 | { |
| 2713 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2714 | { |
| 2715 | /* Visual is after curwin->w_cursor */ |
| 2716 | top = &curwin->w_cursor; |
| 2717 | bot = &VIsual; |
| 2718 | } |
| 2719 | else |
| 2720 | { |
| 2721 | /* Visual is before curwin->w_cursor */ |
| 2722 | top = &VIsual; |
| 2723 | bot = &curwin->w_cursor; |
| 2724 | } |
| 2725 | if (lnum >= top->lnum |
| 2726 | && lnume <= bot->lnum |
| 2727 | && (VIsual_mode != 'v' |
| 2728 | || ((lnum > top->lnum |
| 2729 | || (lnum == top->lnum |
| 2730 | && top->col == 0)) |
| 2731 | && (lnume < bot->lnum |
| 2732 | || (lnume == bot->lnum |
| 2733 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2734 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2735 | { |
| 2736 | if (VIsual_mode == Ctrl_V) |
| 2737 | { |
| 2738 | /* Visual block mode: highlight the chars part of the block */ |
| 2739 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2740 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2741 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2742 | && wp->w_old_cursor_lcol + txtcol |
| 2743 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2744 | len = wp->w_old_cursor_lcol; |
| 2745 | else |
| 2746 | len = W_WIDTH(wp) - txtcol; |
| 2747 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2748 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2749 | } |
| 2750 | } |
| 2751 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2752 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2753 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2754 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2755 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2756 | } |
| 2757 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2758 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2759 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | fbc25b2 | 2015-03-20 17:16:27 +0100 | [diff] [blame] | 2760 | /* Show colorcolumn in the fold line, but let cursorcolumn override it. */ |
| 2761 | if (wp->w_p_cc_cols) |
| 2762 | { |
| 2763 | int i = 0; |
| 2764 | int j = wp->w_p_cc_cols[i]; |
| 2765 | int old_txtcol = txtcol; |
| 2766 | |
| 2767 | while (j > -1) |
| 2768 | { |
| 2769 | txtcol += j; |
| 2770 | if (wp->w_p_wrap) |
| 2771 | txtcol -= wp->w_skipcol; |
| 2772 | else |
| 2773 | txtcol -= wp->w_leftcol; |
| 2774 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2775 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2776 | ScreenAttrs[off + txtcol], hl_attr(HLF_MC)); |
| 2777 | txtcol = old_txtcol; |
| 2778 | j = wp->w_p_cc_cols[++i]; |
| 2779 | } |
| 2780 | } |
| 2781 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2782 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2783 | if (wp->w_p_cuc) |
| 2784 | { |
| 2785 | txtcol += wp->w_virtcol; |
| 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_CUC)); |
| 2793 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2794 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2795 | |
| 2796 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2797 | (int)W_WIDTH(wp), FALSE); |
| 2798 | |
| 2799 | /* |
| 2800 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2801 | * updated (saves a call to plines() later). |
| 2802 | */ |
| 2803 | if (wp == curwin |
| 2804 | && lnum <= curwin->w_cursor.lnum |
| 2805 | && lnume >= curwin->w_cursor.lnum) |
| 2806 | { |
| 2807 | curwin->w_cline_row = row; |
| 2808 | curwin->w_cline_height = 1; |
| 2809 | curwin->w_cline_folded = TRUE; |
| 2810 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | /* |
| 2815 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2816 | */ |
| 2817 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2818 | copy_text_attr( |
| 2819 | int off, |
| 2820 | char_u *buf, |
| 2821 | int len, |
| 2822 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2823 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2824 | int i; |
| 2825 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2826 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2827 | # ifdef FEAT_MBYTE |
| 2828 | if (enc_utf8) |
| 2829 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2830 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2831 | for (i = 0; i < len; ++i) |
| 2832 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | /* |
| 2836 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2837 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2838 | */ |
| 2839 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2840 | fill_foldcolumn( |
| 2841 | char_u *p, |
| 2842 | win_T *wp, |
| 2843 | int closed, /* TRUE of FALSE */ |
| 2844 | linenr_T lnum) /* current line number */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2845 | { |
| 2846 | int i = 0; |
| 2847 | int level; |
| 2848 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2849 | int empty; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2850 | int fdc = compute_foldcolumn(wp, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2851 | |
| 2852 | /* Init to all spaces. */ |
Bram Moolenaar | 2536d4f | 2015-07-17 13:22:51 +0200 | [diff] [blame] | 2853 | vim_memset(p, ' ', (size_t)fdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2854 | |
| 2855 | level = win_foldinfo.fi_level; |
| 2856 | if (level > 0) |
| 2857 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2858 | /* If there is only one column put more info in it. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2859 | empty = (fdc == 1) ? 0 : 1; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2860 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2861 | /* If the column is too narrow, we start at the lowest level that |
| 2862 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2863 | first_level = level - fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2864 | if (first_level < 1) |
| 2865 | first_level = 1; |
| 2866 | |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2867 | for (i = 0; i + empty < fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2868 | { |
| 2869 | if (win_foldinfo.fi_lnum == lnum |
| 2870 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2871 | p[i] = '-'; |
| 2872 | else if (first_level == 1) |
| 2873 | p[i] = '|'; |
| 2874 | else if (first_level + i <= 9) |
| 2875 | p[i] = '0' + first_level + i; |
| 2876 | else |
| 2877 | p[i] = '>'; |
| 2878 | if (first_level + i == level) |
| 2879 | break; |
| 2880 | } |
| 2881 | } |
| 2882 | if (closed) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2883 | p[i >= fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2884 | } |
| 2885 | #endif /* FEAT_FOLDING */ |
| 2886 | |
| 2887 | /* |
| 2888 | * Display line "lnum" of window 'wp' on the screen. |
| 2889 | * Start at row "startrow", stop when "endrow" is reached. |
| 2890 | * wp->w_virtcol needs to be valid. |
| 2891 | * |
| 2892 | * Return the number of last row the line occupies. |
| 2893 | */ |
| 2894 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2895 | win_line( |
| 2896 | win_T *wp, |
| 2897 | linenr_T lnum, |
| 2898 | int startrow, |
| 2899 | int endrow, |
| 2900 | int nochange UNUSED) /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2901 | { |
| 2902 | int col; /* visual column on screen */ |
| 2903 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2904 | int c = 0; /* init for GCC */ |
| 2905 | long vcol = 0; /* virtual column (for tabs) */ |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 2906 | #ifdef FEAT_LINEBREAK |
| 2907 | long vcol_sbr = -1; /* virtual column after showbreak */ |
| 2908 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2909 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2910 | char_u *line; /* current line */ |
| 2911 | char_u *ptr; /* current position in "line" */ |
| 2912 | int row; /* row in the window, excl w_winrow */ |
| 2913 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2914 | |
| 2915 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2916 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2917 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 2918 | char_u *p_extra_free = NULL; /* p_extra needs to be freed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2919 | int c_extra = NUL; /* extra chars, all the same */ |
| 2920 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2921 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2922 | displaying lcs_eol at end-of-line */ |
| 2923 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2924 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2925 | |
| 2926 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2927 | int saved_n_extra = 0; |
| 2928 | char_u *saved_p_extra = NULL; |
| 2929 | int saved_c_extra = 0; |
| 2930 | int saved_char_attr = 0; |
| 2931 | |
| 2932 | int n_attr = 0; /* chars with special attr */ |
| 2933 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2934 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2935 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2936 | |
| 2937 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2938 | |
| 2939 | int fromcol, tocol; /* start/end of inverting */ |
| 2940 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2941 | int noinvcur = FALSE; /* don't invert the cursor */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2942 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2943 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2944 | pos_T pos; |
| 2945 | long v; |
| 2946 | |
| 2947 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2948 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2949 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2950 | in this line */ |
| 2951 | int attr = 0; /* attributes for area highlighting */ |
| 2952 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2953 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2954 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2955 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2956 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2957 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2958 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2959 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2960 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2961 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2962 | #endif |
| 2963 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2964 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2965 | # define SPWORDLEN 150 |
| 2966 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2967 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2968 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2969 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2970 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2971 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2972 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2973 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2974 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2975 | static int cap_col = -1; /* column to check for Cap word */ |
| 2976 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2977 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2978 | #endif |
| 2979 | int extra_check; /* has syntax or linebreak */ |
| 2980 | #ifdef FEAT_MBYTE |
| 2981 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2982 | int mb_l = 1; /* multi-byte byte length */ |
| 2983 | int mb_c = 0; /* decoded multi-byte character */ |
| 2984 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2985 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2986 | #endif |
| 2987 | #ifdef FEAT_DIFF |
| 2988 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2989 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2990 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2991 | int change_start = MAXCOL; /* first col of changed area */ |
| 2992 | int change_end = -1; /* last col of changed area */ |
| 2993 | #endif |
| 2994 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2995 | #ifdef FEAT_LINEBREAK |
| 2996 | int need_showbreak = FALSE; |
| 2997 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2998 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2999 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3000 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3001 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3002 | #endif |
| 3003 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3004 | matchitem_T *cur; /* points to the match list */ |
| 3005 | match_T *shl; /* points to search_hl or a match */ |
| 3006 | int shl_flag; /* flag to indicate whether search_hl |
| 3007 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3008 | int pos_inprogress; /* marks that position match search is |
| 3009 | in progress */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3010 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 3011 | equals startcol of search_hl or one |
| 3012 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3013 | #endif |
| 3014 | #ifdef FEAT_ARABIC |
| 3015 | int prev_c = 0; /* previous Arabic character */ |
| 3016 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 3017 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3018 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 3019 | int did_line_attr = 0; |
| 3020 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3021 | |
| 3022 | /* draw_state: items that are drawn in sequence: */ |
| 3023 | #define WL_START 0 /* nothing done yet */ |
| 3024 | #ifdef FEAT_CMDWIN |
| 3025 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 3026 | #else |
| 3027 | # define WL_CMDLINE WL_START |
| 3028 | #endif |
| 3029 | #ifdef FEAT_FOLDING |
| 3030 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 3031 | #else |
| 3032 | # define WL_FOLD WL_CMDLINE |
| 3033 | #endif |
| 3034 | #ifdef FEAT_SIGNS |
| 3035 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 3036 | #else |
| 3037 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 3038 | #endif |
| 3039 | #define WL_NR WL_SIGN + 1 /* line number */ |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3040 | #ifdef FEAT_LINEBREAK |
| 3041 | # define WL_BRI WL_NR + 1 /* 'breakindent' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3042 | #else |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3043 | # define WL_BRI WL_NR |
| 3044 | #endif |
| 3045 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3046 | # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */ |
| 3047 | #else |
| 3048 | # define WL_SBR WL_BRI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3049 | #endif |
| 3050 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 3051 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 3052 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3053 | int feedback_col = 0; |
| 3054 | int feedback_old_attr = -1; |
| 3055 | #endif |
| 3056 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3057 | #ifdef FEAT_CONCEAL |
| 3058 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 3059 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 3060 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3061 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3062 | int is_concealing = FALSE; |
| 3063 | int boguscols = 0; /* nonexistent columns added to force |
| 3064 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3065 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3066 | int did_wcol = FALSE; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3067 | int match_conc = 0; /* cchar for match functions */ |
| 3068 | int has_match_conc = 0; /* match wants to conceal */ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3069 | int old_boguscols = 0; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3070 | # define VCOL_HLC (vcol - vcol_off) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3071 | # define FIX_FOR_BOGUSCOLS \ |
| 3072 | { \ |
| 3073 | n_extra += vcol_off; \ |
| 3074 | vcol -= vcol_off; \ |
| 3075 | vcol_off = 0; \ |
| 3076 | col -= boguscols; \ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3077 | old_boguscols = boguscols; \ |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3078 | boguscols = 0; \ |
| 3079 | } |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3080 | #else |
| 3081 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3082 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3083 | |
| 3084 | if (startrow > endrow) /* past the end already! */ |
| 3085 | return startrow; |
| 3086 | |
| 3087 | row = startrow; |
| 3088 | screen_row = row + W_WINROW(wp); |
| 3089 | |
| 3090 | /* |
| 3091 | * To speed up the loop below, set extra_check when there is linebreak, |
| 3092 | * trailing white space and/or syntax processing to be done. |
| 3093 | */ |
| 3094 | #ifdef FEAT_LINEBREAK |
| 3095 | extra_check = wp->w_p_lbr; |
| 3096 | #else |
| 3097 | extra_check = 0; |
| 3098 | #endif |
| 3099 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3100 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3101 | { |
| 3102 | /* Prepare for syntax highlighting in this line. When there is an |
| 3103 | * error, stop syntax highlighting. */ |
| 3104 | save_did_emsg = did_emsg; |
| 3105 | did_emsg = FALSE; |
| 3106 | syntax_start(wp, lnum); |
| 3107 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3108 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3109 | else |
| 3110 | { |
| 3111 | did_emsg = save_did_emsg; |
| 3112 | has_syntax = TRUE; |
| 3113 | extra_check = TRUE; |
| 3114 | } |
| 3115 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3116 | |
| 3117 | /* Check for columns to display for 'colorcolumn'. */ |
| 3118 | color_cols = wp->w_p_cc_cols; |
| 3119 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3120 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3121 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3122 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3123 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3124 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3125 | && *wp->w_s->b_p_spl != NUL |
| 3126 | && wp->w_s->b_langp.ga_len > 0 |
| 3127 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3128 | { |
| 3129 | /* Prepare for spell checking. */ |
| 3130 | has_spell = TRUE; |
| 3131 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3132 | |
| 3133 | /* Get the start of the next line, so that words that wrap to the next |
| 3134 | * line are found too: "et<line-break>al.". |
| 3135 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 3136 | nextline[SPWORDLEN] = NUL; |
| 3137 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 3138 | { |
| 3139 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 3140 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 3141 | } |
| 3142 | |
| 3143 | /* When a word wrapped from the previous line the start of the current |
| 3144 | * line is valid. */ |
| 3145 | if (lnum == checked_lnum) |
| 3146 | cur_checked_col = checked_col; |
| 3147 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3148 | |
| 3149 | /* When there was a sentence end in the previous line may require a |
| 3150 | * word starting with capital in this line. In line 1 always check |
| 3151 | * the first word. */ |
| 3152 | if (lnum != capcol_lnum) |
| 3153 | cap_col = -1; |
| 3154 | if (lnum == 1) |
| 3155 | cap_col = 0; |
| 3156 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3157 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3158 | #endif |
| 3159 | |
| 3160 | /* |
| 3161 | * handle visual active in this window |
| 3162 | */ |
| 3163 | fromcol = -10; |
| 3164 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3165 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3166 | { |
| 3167 | /* Visual is after curwin->w_cursor */ |
| 3168 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 3169 | { |
| 3170 | top = &curwin->w_cursor; |
| 3171 | bot = &VIsual; |
| 3172 | } |
| 3173 | else /* Visual is before curwin->w_cursor */ |
| 3174 | { |
| 3175 | top = &VIsual; |
| 3176 | bot = &curwin->w_cursor; |
| 3177 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3178 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3179 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 3180 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3181 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3182 | { |
| 3183 | fromcol = wp->w_old_cursor_fcol; |
| 3184 | tocol = wp->w_old_cursor_lcol; |
| 3185 | } |
| 3186 | } |
| 3187 | else /* non-block mode */ |
| 3188 | { |
| 3189 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 3190 | fromcol = 0; |
| 3191 | else if (lnum == top->lnum) |
| 3192 | { |
| 3193 | if (VIsual_mode == 'V') /* linewise */ |
| 3194 | fromcol = 0; |
| 3195 | else |
| 3196 | { |
| 3197 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 3198 | if (gchar_pos(top) == NUL) |
| 3199 | tocol = fromcol + 1; |
| 3200 | } |
| 3201 | } |
| 3202 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 3203 | { |
| 3204 | if (*p_sel == 'e' && bot->col == 0 |
| 3205 | #ifdef FEAT_VIRTUALEDIT |
| 3206 | && bot->coladd == 0 |
| 3207 | #endif |
| 3208 | ) |
| 3209 | { |
| 3210 | fromcol = -10; |
| 3211 | tocol = MAXCOL; |
| 3212 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3213 | else if (bot->col == MAXCOL) |
| 3214 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3215 | else |
| 3216 | { |
| 3217 | pos = *bot; |
| 3218 | if (*p_sel == 'e') |
| 3219 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3220 | else |
| 3221 | { |
| 3222 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3223 | ++tocol; |
| 3224 | } |
| 3225 | } |
| 3226 | } |
| 3227 | } |
| 3228 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3229 | /* Check if the character under the cursor should not be inverted */ |
| 3230 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3231 | #ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3232 | && !gui.in_use |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3233 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3234 | ) |
| 3235 | noinvcur = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3236 | |
| 3237 | /* if inverting in this line set area_highlighting */ |
| 3238 | if (fromcol >= 0) |
| 3239 | { |
| 3240 | area_highlighting = TRUE; |
| 3241 | attr = hl_attr(HLF_V); |
| 3242 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3243 | if ((clip_star.available && !clip_star.owned |
| 3244 | && clip_isautosel_star()) |
| 3245 | || (clip_plus.available && !clip_plus.owned |
| 3246 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3247 | attr = hl_attr(HLF_VNC); |
| 3248 | #endif |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3253 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3254 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3255 | else if (highlight_match |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3256 | && wp == curwin |
| 3257 | && lnum >= curwin->w_cursor.lnum |
| 3258 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3259 | { |
| 3260 | if (lnum == curwin->w_cursor.lnum) |
| 3261 | getvcol(curwin, &(curwin->w_cursor), |
| 3262 | (colnr_T *)&fromcol, NULL, NULL); |
| 3263 | else |
| 3264 | fromcol = 0; |
| 3265 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3266 | { |
| 3267 | pos.lnum = lnum; |
| 3268 | pos.col = search_match_endcol; |
| 3269 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3270 | } |
| 3271 | else |
| 3272 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3273 | /* do at least one character; happens when past end of line */ |
| 3274 | if (fromcol == tocol) |
| 3275 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3276 | area_highlighting = TRUE; |
| 3277 | attr = hl_attr(HLF_I); |
| 3278 | } |
| 3279 | |
| 3280 | #ifdef FEAT_DIFF |
| 3281 | filler_lines = diff_check(wp, lnum); |
| 3282 | if (filler_lines < 0) |
| 3283 | { |
| 3284 | if (filler_lines == -1) |
| 3285 | { |
| 3286 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3287 | diff_hlf = HLF_ADD; /* added line */ |
| 3288 | else if (change_start == 0) |
| 3289 | diff_hlf = HLF_TXD; /* changed text */ |
| 3290 | else |
| 3291 | diff_hlf = HLF_CHD; /* changed line */ |
| 3292 | } |
| 3293 | else |
| 3294 | diff_hlf = HLF_ADD; /* added line */ |
| 3295 | filler_lines = 0; |
| 3296 | area_highlighting = TRUE; |
| 3297 | } |
| 3298 | if (lnum == wp->w_topline) |
| 3299 | filler_lines = wp->w_topfill; |
| 3300 | filler_todo = filler_lines; |
| 3301 | #endif |
| 3302 | |
| 3303 | #ifdef LINE_ATTR |
| 3304 | # ifdef FEAT_SIGNS |
| 3305 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3306 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3307 | if (v != 0) |
| 3308 | line_attr = sign_get_attr((int)v, TRUE); |
| 3309 | # endif |
| 3310 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3311 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3312 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3313 | line_attr = hl_attr(HLF_L); |
| 3314 | # endif |
| 3315 | if (line_attr != 0) |
| 3316 | area_highlighting = TRUE; |
| 3317 | #endif |
| 3318 | |
| 3319 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3320 | ptr = line; |
| 3321 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3322 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3323 | if (has_spell) |
| 3324 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3325 | /* For checking first word with a capital skip white space. */ |
| 3326 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3327 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3328 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3329 | /* To be able to spell-check over line boundaries copy the end of the |
| 3330 | * current line into nextline[]. Above the start of the next line was |
| 3331 | * copied to nextline[SPWORDLEN]. */ |
| 3332 | if (nextline[SPWORDLEN] == NUL) |
| 3333 | { |
| 3334 | /* No next line or it is empty. */ |
| 3335 | nextlinecol = MAXCOL; |
| 3336 | nextline_idx = 0; |
| 3337 | } |
| 3338 | else |
| 3339 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3340 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3341 | if (v < SPWORDLEN) |
| 3342 | { |
| 3343 | /* Short line, use it completely and append the start of the |
| 3344 | * next line. */ |
| 3345 | nextlinecol = 0; |
| 3346 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3347 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3348 | nextline_idx = v + 1; |
| 3349 | } |
| 3350 | else |
| 3351 | { |
| 3352 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3353 | nextlinecol = v - SPWORDLEN; |
| 3354 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3355 | nextline_idx = SPWORDLEN + 1; |
| 3356 | } |
| 3357 | } |
| 3358 | } |
| 3359 | #endif |
| 3360 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3361 | if (wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3362 | { |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3363 | if (lcs_space || lcs_trail) |
| 3364 | extra_check = TRUE; |
| 3365 | /* find start of trailing whitespace */ |
| 3366 | if (lcs_trail) |
| 3367 | { |
| 3368 | trailcol = (colnr_T)STRLEN(ptr); |
| 3369 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3370 | --trailcol; |
| 3371 | trailcol += (colnr_T) (ptr - line); |
| 3372 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | /* |
| 3376 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3377 | * first character to be displayed. |
| 3378 | */ |
| 3379 | if (wp->w_p_wrap) |
| 3380 | v = wp->w_skipcol; |
| 3381 | else |
| 3382 | v = wp->w_leftcol; |
| 3383 | if (v > 0) |
| 3384 | { |
| 3385 | #ifdef FEAT_MBYTE |
| 3386 | char_u *prev_ptr = ptr; |
| 3387 | #endif |
| 3388 | while (vcol < v && *ptr != NUL) |
| 3389 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3390 | c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3391 | vcol += c; |
| 3392 | #ifdef FEAT_MBYTE |
| 3393 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3394 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3395 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3398 | /* When: |
| 3399 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3400 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3401 | * - 'virtualedit' is set, or |
| 3402 | * - the visual mode is active, |
| 3403 | * the end of the line may be before the start of the displayed part. |
| 3404 | */ |
| 3405 | if (vcol < v && ( |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3406 | #ifdef FEAT_SYN_HL |
| 3407 | wp->w_p_cuc || draw_color_col || |
| 3408 | #endif |
| 3409 | #ifdef FEAT_VIRTUALEDIT |
| 3410 | virtual_active() || |
| 3411 | #endif |
| 3412 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3413 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3414 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3415 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3416 | |
| 3417 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3418 | * that character but skip the first few screen characters. */ |
| 3419 | if (vcol > v) |
| 3420 | { |
| 3421 | vcol -= c; |
| 3422 | #ifdef FEAT_MBYTE |
| 3423 | ptr = prev_ptr; |
| 3424 | #else |
| 3425 | --ptr; |
| 3426 | #endif |
| 3427 | n_skip = v - vcol; |
| 3428 | } |
| 3429 | |
| 3430 | /* |
| 3431 | * Adjust for when the inverted text is before the screen, |
| 3432 | * and when the start of the inverted text is before the screen. |
| 3433 | */ |
| 3434 | if (tocol <= vcol) |
| 3435 | fromcol = 0; |
| 3436 | else if (fromcol >= 0 && fromcol < vcol) |
| 3437 | fromcol = vcol; |
| 3438 | |
| 3439 | #ifdef FEAT_LINEBREAK |
| 3440 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3441 | if (wp->w_p_wrap) |
| 3442 | need_showbreak = TRUE; |
| 3443 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3444 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3445 | /* When spell checking a word we need to figure out the start of the |
| 3446 | * word and if it's badly spelled or not. */ |
| 3447 | if (has_spell) |
| 3448 | { |
| 3449 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3450 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3451 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3452 | |
| 3453 | pos = wp->w_cursor; |
| 3454 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3455 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3456 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3457 | |
| 3458 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3459 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3460 | ptr = line + linecol; |
| 3461 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3462 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3463 | { |
| 3464 | /* no bad word found at line start, don't check until end of a |
| 3465 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3466 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3467 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3468 | } |
| 3469 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3470 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3471 | /* bad word found, use attributes until end of word */ |
| 3472 | word_end = wp->w_cursor.col + len + 1; |
| 3473 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3474 | /* Turn index into actual attributes. */ |
| 3475 | if (spell_hlf != HLF_COUNT) |
| 3476 | spell_attr = highlight_attr[spell_hlf]; |
| 3477 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3478 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3479 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3480 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3481 | /* Need to restart syntax highlighting for this line. */ |
| 3482 | if (has_syntax) |
| 3483 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3484 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3485 | } |
| 3486 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | /* |
| 3490 | * Correct highlighting for cursor that can't be disabled. |
| 3491 | * Avoids having to check this for each character. |
| 3492 | */ |
| 3493 | if (fromcol >= 0) |
| 3494 | { |
| 3495 | if (noinvcur) |
| 3496 | { |
| 3497 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3498 | { |
| 3499 | /* highlighting starts at cursor, let it start just after the |
| 3500 | * cursor */ |
| 3501 | fromcol_prev = fromcol; |
| 3502 | fromcol = -1; |
| 3503 | } |
| 3504 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3505 | /* restart highlighting after the cursor */ |
| 3506 | fromcol_prev = wp->w_virtcol; |
| 3507 | } |
| 3508 | if (fromcol >= tocol) |
| 3509 | fromcol = -1; |
| 3510 | } |
| 3511 | |
| 3512 | #ifdef FEAT_SEARCH_EXTRA |
| 3513 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3514 | * Handle highlighting the last used search pattern and matches. |
| 3515 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3516 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3517 | cur = wp->w_match_head; |
| 3518 | shl_flag = FALSE; |
| 3519 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3520 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3521 | if (shl_flag == FALSE) |
| 3522 | { |
| 3523 | shl = &search_hl; |
| 3524 | shl_flag = TRUE; |
| 3525 | } |
| 3526 | else |
| 3527 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3528 | shl->startcol = MAXCOL; |
| 3529 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3530 | shl->attr_cur = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3531 | v = (long)(ptr - line); |
| 3532 | if (cur != NULL) |
| 3533 | cur->pos.cur = 0; |
| 3534 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3535 | |
| 3536 | /* Need to get the line again, a multi-line regexp may have made it |
| 3537 | * invalid. */ |
| 3538 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3539 | ptr = line + v; |
| 3540 | |
| 3541 | if (shl->lnum != 0 && shl->lnum <= lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3542 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3543 | if (shl->lnum == lnum) |
| 3544 | shl->startcol = shl->rm.startpos[0].col; |
| 3545 | else |
| 3546 | shl->startcol = 0; |
| 3547 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3548 | - shl->rm.startpos[0].lnum) |
| 3549 | shl->endcol = shl->rm.endpos[0].col; |
| 3550 | else |
| 3551 | shl->endcol = MAXCOL; |
| 3552 | /* Highlight one character for an empty match. */ |
| 3553 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3554 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3555 | #ifdef FEAT_MBYTE |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3556 | if (has_mbyte && line[shl->endcol] != NUL) |
| 3557 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
| 3558 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3559 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3560 | ++shl->endcol; |
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 ((long)shl->startcol < v) /* match at leftcol */ |
| 3563 | { |
| 3564 | shl->attr_cur = shl->attr; |
| 3565 | search_attr = shl->attr; |
| 3566 | } |
| 3567 | area_highlighting = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3568 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3569 | if (shl != &search_hl && cur != NULL) |
| 3570 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3571 | } |
| 3572 | #endif |
| 3573 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3574 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3575 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3576 | * when Visual mode is active, because it's not clear what is selected |
| 3577 | * then. */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3578 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3579 | && !(wp == curwin && VIsual_active)) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3580 | { |
| 3581 | line_attr = hl_attr(HLF_CUL); |
| 3582 | area_highlighting = TRUE; |
| 3583 | } |
| 3584 | #endif |
| 3585 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3586 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3587 | col = 0; |
| 3588 | #ifdef FEAT_RIGHTLEFT |
| 3589 | if (wp->w_p_rl) |
| 3590 | { |
| 3591 | /* Rightleft window: process the text in the normal direction, but put |
| 3592 | * it in current_ScreenLine[] from right to left. Start at the |
| 3593 | * rightmost column of the window. */ |
| 3594 | col = W_WIDTH(wp) - 1; |
| 3595 | off += col; |
| 3596 | } |
| 3597 | #endif |
| 3598 | |
| 3599 | /* |
| 3600 | * Repeat for the whole displayed line. |
| 3601 | */ |
| 3602 | for (;;) |
| 3603 | { |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3604 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3605 | has_match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3606 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3607 | /* Skip this quickly when working on the text. */ |
| 3608 | if (draw_state != WL_LINE) |
| 3609 | { |
| 3610 | #ifdef FEAT_CMDWIN |
| 3611 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3612 | { |
| 3613 | draw_state = WL_CMDLINE; |
| 3614 | if (cmdwin_type != 0 && wp == curwin) |
| 3615 | { |
| 3616 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3617 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3618 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3619 | char_attr = hl_attr(HLF_AT); |
| 3620 | } |
| 3621 | } |
| 3622 | #endif |
| 3623 | |
| 3624 | #ifdef FEAT_FOLDING |
| 3625 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3626 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3627 | int fdc = compute_foldcolumn(wp, 0); |
| 3628 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3629 | draw_state = WL_FOLD; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3630 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3631 | { |
| 3632 | /* Draw the 'foldcolumn'. */ |
| 3633 | fill_foldcolumn(extra, wp, FALSE, lnum); |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3634 | n_extra = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3635 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3636 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3637 | c_extra = NUL; |
| 3638 | char_attr = hl_attr(HLF_FC); |
| 3639 | } |
| 3640 | } |
| 3641 | #endif |
| 3642 | |
| 3643 | #ifdef FEAT_SIGNS |
| 3644 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3645 | { |
| 3646 | draw_state = WL_SIGN; |
| 3647 | /* Show the sign column when there are any signs in this |
| 3648 | * buffer or when using Netbeans. */ |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3649 | if (draw_signcolumn(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3650 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3651 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3652 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3653 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3654 | # endif |
| 3655 | |
| 3656 | /* Draw two cells with the sign value or blank. */ |
| 3657 | c_extra = ' '; |
| 3658 | char_attr = hl_attr(HLF_SC); |
| 3659 | n_extra = 2; |
| 3660 | |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3661 | if (row == startrow |
| 3662 | #ifdef FEAT_DIFF |
| 3663 | + filler_lines && filler_todo <= 0 |
| 3664 | #endif |
| 3665 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3666 | { |
| 3667 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3668 | SIGN_TEXT); |
| 3669 | # ifdef FEAT_SIGN_ICONS |
| 3670 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3671 | SIGN_ICON); |
| 3672 | if (gui.in_use && icon_sign != 0) |
| 3673 | { |
| 3674 | /* Use the image in this position. */ |
| 3675 | c_extra = SIGN_BYTE; |
| 3676 | # ifdef FEAT_NETBEANS_INTG |
| 3677 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3678 | c_extra = MULTISIGN_BYTE; |
| 3679 | # endif |
| 3680 | char_attr = icon_sign; |
| 3681 | } |
| 3682 | else |
| 3683 | # endif |
| 3684 | if (text_sign != 0) |
| 3685 | { |
| 3686 | p_extra = sign_get_text(text_sign); |
| 3687 | if (p_extra != NULL) |
| 3688 | { |
| 3689 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3690 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3691 | } |
| 3692 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3693 | } |
| 3694 | } |
| 3695 | } |
| 3696 | } |
| 3697 | #endif |
| 3698 | |
| 3699 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3700 | { |
| 3701 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3702 | /* Display the absolute or relative line number. After the |
| 3703 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3704 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3705 | && (row == startrow |
| 3706 | #ifdef FEAT_DIFF |
| 3707 | + filler_lines |
| 3708 | #endif |
| 3709 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3710 | { |
| 3711 | /* Draw the line number (empty space after wrapping). */ |
| 3712 | if (row == startrow |
| 3713 | #ifdef FEAT_DIFF |
| 3714 | + filler_lines |
| 3715 | #endif |
| 3716 | ) |
| 3717 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3718 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3719 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3720 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3721 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3722 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3723 | num = (long)lnum; |
| 3724 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3725 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3726 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3727 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3728 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3729 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3730 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3731 | num = lnum; |
| 3732 | fmt = "%-*ld "; |
| 3733 | } |
| 3734 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3735 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3736 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3737 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3738 | if (wp->w_skipcol > 0) |
| 3739 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3740 | *p_extra = '-'; |
| 3741 | #ifdef FEAT_RIGHTLEFT |
| 3742 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3743 | rl_mirror(extra); |
| 3744 | #endif |
| 3745 | p_extra = extra; |
| 3746 | c_extra = NUL; |
| 3747 | } |
| 3748 | else |
| 3749 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3750 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3751 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3752 | #ifdef FEAT_SYN_HL |
| 3753 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3754 | * the current line differently. |
| 3755 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3756 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3757 | if ((wp->w_p_cul || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3758 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3759 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3760 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3761 | } |
| 3762 | } |
| 3763 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3764 | #ifdef FEAT_LINEBREAK |
| 3765 | if (wp->w_p_brisbr && draw_state == WL_BRI - 1 |
| 3766 | && n_extra == 0 && *p_sbr != NUL) |
| 3767 | /* draw indent after showbreak value */ |
| 3768 | draw_state = WL_BRI; |
| 3769 | else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) |
| 3770 | /* After the showbreak, draw the breakindent */ |
| 3771 | draw_state = WL_BRI - 1; |
| 3772 | |
| 3773 | /* draw 'breakindent': indent wrapped text accordingly */ |
| 3774 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 3775 | { |
| 3776 | draw_state = WL_BRI; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3777 | if (wp->w_p_bri && n_extra == 0 && row != startrow |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3778 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3779 | && filler_lines == 0 |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3780 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3781 | ) |
| 3782 | { |
| 3783 | char_attr = 0; /* was: hl_attr(HLF_AT); */ |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3784 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3785 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3786 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3787 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3788 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3789 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3790 | char_attr = hl_combine_attr(char_attr, |
| 3791 | hl_attr(HLF_CUL)); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3792 | # endif |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3793 | } |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3794 | # endif |
Bram Moolenaar | b8b5746 | 2014-07-03 22:54:08 +0200 | [diff] [blame] | 3795 | p_extra = NULL; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3796 | c_extra = ' '; |
| 3797 | n_extra = get_breakindent_win(wp, |
| 3798 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 3799 | /* Correct end of highlighted area for 'breakindent', |
| 3800 | * required when 'linebreak' is also set. */ |
| 3801 | if (tocol == vcol) |
| 3802 | tocol += n_extra; |
| 3803 | } |
| 3804 | } |
| 3805 | #endif |
| 3806 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3807 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3808 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3809 | { |
| 3810 | draw_state = WL_SBR; |
| 3811 | # ifdef FEAT_DIFF |
| 3812 | if (filler_todo > 0) |
| 3813 | { |
| 3814 | /* Draw "deleted" diff line(s). */ |
| 3815 | if (char2cells(fill_diff) > 1) |
| 3816 | c_extra = '-'; |
| 3817 | else |
| 3818 | c_extra = fill_diff; |
| 3819 | # ifdef FEAT_RIGHTLEFT |
| 3820 | if (wp->w_p_rl) |
| 3821 | n_extra = col + 1; |
| 3822 | else |
| 3823 | # endif |
| 3824 | n_extra = W_WIDTH(wp) - col; |
| 3825 | char_attr = hl_attr(HLF_DED); |
| 3826 | } |
| 3827 | # endif |
| 3828 | # ifdef FEAT_LINEBREAK |
| 3829 | if (*p_sbr != NUL && need_showbreak) |
| 3830 | { |
| 3831 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3832 | p_extra = p_sbr; |
| 3833 | c_extra = NUL; |
| 3834 | n_extra = (int)STRLEN(p_sbr); |
| 3835 | char_attr = hl_attr(HLF_AT); |
| 3836 | need_showbreak = FALSE; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 3837 | vcol_sbr = vcol + MB_CHARLEN(p_sbr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3838 | /* Correct end of highlighted area for 'showbreak', |
| 3839 | * required when 'linebreak' is also set. */ |
| 3840 | if (tocol == vcol) |
| 3841 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3842 | #ifdef FEAT_SYN_HL |
| 3843 | /* combine 'showbreak' with 'cursorline' */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3844 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3845 | char_attr = hl_combine_attr(char_attr, |
| 3846 | hl_attr(HLF_CUL)); |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3847 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3848 | } |
| 3849 | # endif |
| 3850 | } |
| 3851 | #endif |
| 3852 | |
| 3853 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3854 | { |
| 3855 | draw_state = WL_LINE; |
| 3856 | if (saved_n_extra) |
| 3857 | { |
| 3858 | /* Continue item from end of wrapped line. */ |
| 3859 | n_extra = saved_n_extra; |
| 3860 | c_extra = saved_c_extra; |
| 3861 | p_extra = saved_p_extra; |
| 3862 | char_attr = saved_char_attr; |
| 3863 | } |
| 3864 | else |
| 3865 | char_attr = 0; |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3870 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3871 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3872 | #ifdef FEAT_DIFF |
| 3873 | && filler_todo <= 0 |
| 3874 | #endif |
| 3875 | ) |
| 3876 | { |
| 3877 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3878 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3879 | /* Pretend we have finished updating the window. Except when |
| 3880 | * 'cursorcolumn' is set. */ |
| 3881 | #ifdef FEAT_SYN_HL |
| 3882 | if (wp->w_p_cuc) |
| 3883 | row = wp->w_cline_row + wp->w_cline_height; |
| 3884 | else |
| 3885 | #endif |
| 3886 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3887 | break; |
| 3888 | } |
| 3889 | |
| 3890 | if (draw_state == WL_LINE && area_highlighting) |
| 3891 | { |
| 3892 | /* handle Visual or match highlighting in this line */ |
| 3893 | if (vcol == fromcol |
| 3894 | #ifdef FEAT_MBYTE |
| 3895 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3896 | && (*mb_ptr2cells)(ptr) > 1) |
| 3897 | #endif |
| 3898 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3899 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3900 | && vcol < tocol)) |
| 3901 | area_attr = attr; /* start highlighting */ |
| 3902 | else if (area_attr != 0 |
| 3903 | && (vcol == tocol |
| 3904 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3905 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3906 | |
| 3907 | #ifdef FEAT_SEARCH_EXTRA |
| 3908 | if (!n_extra) |
| 3909 | { |
| 3910 | /* |
| 3911 | * Check for start/end of search pattern match. |
| 3912 | * After end, check for start/end of next match. |
| 3913 | * When another match, have to check for start again. |
| 3914 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3915 | * Do this for 'search_hl' and the match list (ordered by |
| 3916 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3917 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3918 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3919 | cur = wp->w_match_head; |
| 3920 | shl_flag = FALSE; |
| 3921 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3922 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3923 | if (shl_flag == FALSE |
| 3924 | && ((cur != NULL |
| 3925 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3926 | || cur == NULL)) |
| 3927 | { |
| 3928 | shl = &search_hl; |
| 3929 | shl_flag = TRUE; |
| 3930 | } |
| 3931 | else |
| 3932 | shl = &cur->hl; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3933 | if (cur != NULL) |
| 3934 | cur->pos.cur = 0; |
| 3935 | pos_inprogress = TRUE; |
| 3936 | while (shl->rm.regprog != NULL |
| 3937 | || (cur != NULL && pos_inprogress)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3938 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3939 | if (shl->startcol != MAXCOL |
| 3940 | && v >= (long)shl->startcol |
| 3941 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3942 | { |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3943 | #ifdef FEAT_MBYTE |
| 3944 | int tmp_col = v + MB_PTR2LEN(ptr); |
| 3945 | |
| 3946 | if (shl->endcol < tmp_col) |
| 3947 | shl->endcol = tmp_col; |
| 3948 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3949 | shl->attr_cur = shl->attr; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3950 | #ifdef FEAT_CONCEAL |
| 3951 | if (cur != NULL && syn_name2id((char_u *)"Conceal") |
| 3952 | == cur->hlg_id) |
| 3953 | { |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3954 | has_match_conc = |
| 3955 | v == (long)shl->startcol ? 2 : 1; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3956 | match_conc = cur->conceal_char; |
| 3957 | } |
| 3958 | else |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3959 | has_match_conc = match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3960 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3961 | } |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3962 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3963 | { |
| 3964 | shl->attr_cur = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3965 | #ifdef FEAT_CONCEAL |
| 3966 | prev_syntax_id = 0; |
| 3967 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3968 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3969 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3970 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3971 | |
| 3972 | /* Need to get the line again, a multi-line regexp |
| 3973 | * may have made it invalid. */ |
| 3974 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3975 | ptr = line + v; |
| 3976 | |
| 3977 | if (shl->lnum == lnum) |
| 3978 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3979 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3980 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3981 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3982 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3983 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3984 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3985 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3986 | { |
| 3987 | /* highlight empty match, try again after |
| 3988 | * it */ |
| 3989 | #ifdef FEAT_MBYTE |
| 3990 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3991 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3992 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3993 | else |
| 3994 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3995 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | /* Loop to check if the match starts at the |
| 3999 | * current position */ |
| 4000 | continue; |
| 4001 | } |
| 4002 | } |
| 4003 | break; |
| 4004 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4005 | if (shl != &search_hl && cur != NULL) |
| 4006 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4007 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4008 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4009 | /* Use attributes from match with highest priority among |
| 4010 | * 'search_hl' and the match list. */ |
| 4011 | search_attr = search_hl.attr_cur; |
| 4012 | cur = wp->w_match_head; |
| 4013 | shl_flag = FALSE; |
| 4014 | while (cur != NULL || shl_flag == FALSE) |
| 4015 | { |
| 4016 | if (shl_flag == FALSE |
| 4017 | && ((cur != NULL |
| 4018 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4019 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4020 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4021 | shl = &search_hl; |
| 4022 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4023 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4024 | else |
| 4025 | shl = &cur->hl; |
| 4026 | if (shl->attr_cur != 0) |
| 4027 | search_attr = shl->attr_cur; |
| 4028 | if (shl != &search_hl && cur != NULL) |
| 4029 | cur = cur->next; |
| 4030 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4031 | } |
| 4032 | #endif |
| 4033 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4034 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4035 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4036 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4037 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 4038 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4039 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4040 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 4041 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4042 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4043 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4044 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4045 | line_attr = hl_combine_attr(line_attr, hl_attr(HLF_CUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4046 | } |
| 4047 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4048 | |
| 4049 | /* Decide which of the highlight attributes to use. */ |
| 4050 | attr_pri = TRUE; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4051 | #ifdef LINE_ATTR |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4052 | if (area_attr != 0) |
| 4053 | char_attr = hl_combine_attr(line_attr, area_attr); |
| 4054 | else if (search_attr != 0) |
| 4055 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4056 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 4057 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 4058 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 4059 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 4060 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4061 | char_attr = line_attr; |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4062 | #else |
| 4063 | if (area_attr != 0) |
| 4064 | char_attr = area_attr; |
| 4065 | else if (search_attr != 0) |
| 4066 | char_attr = search_attr; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4067 | #endif |
| 4068 | else |
| 4069 | { |
| 4070 | attr_pri = FALSE; |
| 4071 | #ifdef FEAT_SYN_HL |
| 4072 | if (has_syntax) |
| 4073 | char_attr = syntax_attr; |
| 4074 | else |
| 4075 | #endif |
| 4076 | char_attr = 0; |
| 4077 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | /* |
| 4081 | * Get the next character to put on the screen. |
| 4082 | */ |
| 4083 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 4084 | * The "p_extra" points to the extra stuff that is inserted to |
| 4085 | * represent special characters (non-printable stuff) and other |
| 4086 | * things. When all characters are the same, c_extra is used. |
| 4087 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 4088 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4089 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 4090 | */ |
| 4091 | if (n_extra > 0) |
| 4092 | { |
| 4093 | if (c_extra != NUL) |
| 4094 | { |
| 4095 | c = c_extra; |
| 4096 | #ifdef FEAT_MBYTE |
| 4097 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 4098 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4099 | { |
| 4100 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4101 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4102 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4103 | } |
| 4104 | else |
| 4105 | mb_utf8 = FALSE; |
| 4106 | #endif |
| 4107 | } |
| 4108 | else |
| 4109 | { |
| 4110 | c = *p_extra; |
| 4111 | #ifdef FEAT_MBYTE |
| 4112 | if (has_mbyte) |
| 4113 | { |
| 4114 | mb_c = c; |
| 4115 | if (enc_utf8) |
| 4116 | { |
| 4117 | /* If the UTF-8 character is more than one byte: |
| 4118 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4119 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4120 | mb_utf8 = FALSE; |
| 4121 | if (mb_l > n_extra) |
| 4122 | mb_l = 1; |
| 4123 | else if (mb_l > 1) |
| 4124 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4125 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4126 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4127 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4128 | } |
| 4129 | } |
| 4130 | else |
| 4131 | { |
| 4132 | /* if this is a DBCS character, put it in "mb_c" */ |
| 4133 | mb_l = MB_BYTE2LEN(c); |
| 4134 | if (mb_l >= n_extra) |
| 4135 | mb_l = 1; |
| 4136 | else if (mb_l > 1) |
| 4137 | mb_c = (c << 8) + p_extra[1]; |
| 4138 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4139 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4140 | mb_l = 1; |
| 4141 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4142 | /* If a double-width char doesn't fit display a '>' in the |
| 4143 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4144 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4145 | # ifdef FEAT_RIGHTLEFT |
| 4146 | wp->w_p_rl ? (col <= 0) : |
| 4147 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4148 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4149 | && (*mb_char2cells)(mb_c) == 2) |
| 4150 | { |
| 4151 | c = '>'; |
| 4152 | mb_c = c; |
| 4153 | mb_l = 1; |
| 4154 | mb_utf8 = FALSE; |
| 4155 | multi_attr = hl_attr(HLF_AT); |
| 4156 | /* put the pointer back to output the double-width |
| 4157 | * character at the start of the next line. */ |
| 4158 | ++n_extra; |
| 4159 | --p_extra; |
| 4160 | } |
| 4161 | else |
| 4162 | { |
| 4163 | n_extra -= mb_l - 1; |
| 4164 | p_extra += mb_l - 1; |
| 4165 | } |
| 4166 | } |
| 4167 | #endif |
| 4168 | ++p_extra; |
| 4169 | } |
| 4170 | --n_extra; |
| 4171 | } |
| 4172 | else |
| 4173 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4174 | if (p_extra_free != NULL) |
| 4175 | { |
| 4176 | vim_free(p_extra_free); |
| 4177 | p_extra_free = NULL; |
| 4178 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4179 | /* |
| 4180 | * Get a character from the line itself. |
| 4181 | */ |
| 4182 | c = *ptr; |
| 4183 | #ifdef FEAT_MBYTE |
| 4184 | if (has_mbyte) |
| 4185 | { |
| 4186 | mb_c = c; |
| 4187 | if (enc_utf8) |
| 4188 | { |
| 4189 | /* If the UTF-8 character is more than one byte: Decode it |
| 4190 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4191 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4192 | mb_utf8 = FALSE; |
| 4193 | if (mb_l > 1) |
| 4194 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4195 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4196 | /* Overlong encoded ASCII or ASCII with composing char |
| 4197 | * is displayed normally, except a NUL. */ |
| 4198 | if (mb_c < 0x80) |
| 4199 | c = mb_c; |
| 4200 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4201 | |
| 4202 | /* At start of the line we can have a composing char. |
| 4203 | * Draw it as a space with a composing char. */ |
| 4204 | if (utf_iscomposing(mb_c)) |
| 4205 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4206 | int i; |
| 4207 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4208 | for (i = Screen_mco - 1; i > 0; --i) |
| 4209 | u8cc[i] = u8cc[i - 1]; |
| 4210 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4211 | mb_c = ' '; |
| 4212 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | if ((mb_l == 1 && c >= 0x80) |
| 4216 | || (mb_l >= 1 && mb_c == 0) |
| 4217 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4218 | # ifdef UNICODE16 |
| 4219 | || mb_c >= 0x10000 |
| 4220 | # endif |
| 4221 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4222 | { |
| 4223 | /* |
| 4224 | * Illegal UTF-8 byte: display as <xx>. |
| 4225 | * Non-BMP character : display as ? or fullwidth ?. |
| 4226 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4227 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4228 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4229 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4230 | { |
| 4231 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4232 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4233 | if (wp->w_p_rl) /* reverse */ |
| 4234 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4235 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4236 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4237 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4238 | else if (utf_char2cells(mb_c) != 2) |
| 4239 | STRCPY(extra, "?"); |
| 4240 | else |
| 4241 | /* 0xff1f in UTF-8: full-width '?' */ |
| 4242 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4243 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4244 | |
| 4245 | p_extra = extra; |
| 4246 | c = *p_extra; |
| 4247 | mb_c = mb_ptr2char_adv(&p_extra); |
| 4248 | mb_utf8 = (c >= 0x80); |
| 4249 | n_extra = (int)STRLEN(p_extra); |
| 4250 | c_extra = NUL; |
| 4251 | if (area_attr == 0 && search_attr == 0) |
| 4252 | { |
| 4253 | n_attr = n_extra + 1; |
| 4254 | extra_attr = hl_attr(HLF_8); |
| 4255 | saved_attr2 = char_attr; /* save current attr */ |
| 4256 | } |
| 4257 | } |
| 4258 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4259 | mb_l = 1; |
| 4260 | #ifdef FEAT_ARABIC |
| 4261 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 4262 | { |
| 4263 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4264 | int pc, pc1, nc; |
| 4265 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4266 | |
| 4267 | /* The idea of what is the previous and next |
| 4268 | * character depends on 'rightleft'. */ |
| 4269 | if (wp->w_p_rl) |
| 4270 | { |
| 4271 | pc = prev_c; |
| 4272 | pc1 = prev_c1; |
| 4273 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4274 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4275 | } |
| 4276 | else |
| 4277 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4278 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4279 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4280 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4281 | } |
| 4282 | prev_c = mb_c; |
| 4283 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4284 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4285 | } |
| 4286 | else |
| 4287 | prev_c = mb_c; |
| 4288 | #endif |
| 4289 | } |
| 4290 | else /* enc_dbcs */ |
| 4291 | { |
| 4292 | mb_l = MB_BYTE2LEN(c); |
| 4293 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4294 | mb_l = 1; |
| 4295 | else if (mb_l > 1) |
| 4296 | { |
| 4297 | /* We assume a second byte below 32 is illegal. |
| 4298 | * Hopefully this is OK for all double-byte encodings! |
| 4299 | */ |
| 4300 | if (ptr[1] >= 32) |
| 4301 | mb_c = (c << 8) + ptr[1]; |
| 4302 | else |
| 4303 | { |
| 4304 | if (ptr[1] == NUL) |
| 4305 | { |
| 4306 | /* head byte at end of line */ |
| 4307 | mb_l = 1; |
| 4308 | transchar_nonprint(extra, c); |
| 4309 | } |
| 4310 | else |
| 4311 | { |
| 4312 | /* illegal tail byte */ |
| 4313 | mb_l = 2; |
| 4314 | STRCPY(extra, "XX"); |
| 4315 | } |
| 4316 | p_extra = extra; |
| 4317 | n_extra = (int)STRLEN(extra) - 1; |
| 4318 | c_extra = NUL; |
| 4319 | c = *p_extra++; |
| 4320 | if (area_attr == 0 && search_attr == 0) |
| 4321 | { |
| 4322 | n_attr = n_extra + 1; |
| 4323 | extra_attr = hl_attr(HLF_8); |
| 4324 | saved_attr2 = char_attr; /* save current attr */ |
| 4325 | } |
| 4326 | mb_c = c; |
| 4327 | } |
| 4328 | } |
| 4329 | } |
| 4330 | /* If a double-width char doesn't fit display a '>' in the |
| 4331 | * last column; the character is displayed at the start of the |
| 4332 | * next line. */ |
| 4333 | if (( |
| 4334 | # ifdef FEAT_RIGHTLEFT |
| 4335 | wp->w_p_rl ? (col <= 0) : |
| 4336 | # endif |
| 4337 | (col >= W_WIDTH(wp) - 1)) |
| 4338 | && (*mb_char2cells)(mb_c) == 2) |
| 4339 | { |
| 4340 | c = '>'; |
| 4341 | mb_c = c; |
| 4342 | mb_utf8 = FALSE; |
| 4343 | mb_l = 1; |
| 4344 | multi_attr = hl_attr(HLF_AT); |
| 4345 | /* Put pointer back so that the character will be |
| 4346 | * displayed at the start of the next line. */ |
| 4347 | --ptr; |
| 4348 | } |
| 4349 | else if (*ptr != NUL) |
| 4350 | ptr += mb_l - 1; |
| 4351 | |
| 4352 | /* 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] | 4353 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4354 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4355 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4356 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4357 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4358 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4359 | c = ' '; |
| 4360 | if (area_attr == 0 && search_attr == 0) |
| 4361 | { |
| 4362 | n_attr = n_extra + 1; |
| 4363 | extra_attr = hl_attr(HLF_AT); |
| 4364 | saved_attr2 = char_attr; /* save current attr */ |
| 4365 | } |
| 4366 | mb_c = c; |
| 4367 | mb_utf8 = FALSE; |
| 4368 | mb_l = 1; |
| 4369 | } |
| 4370 | |
| 4371 | } |
| 4372 | #endif |
| 4373 | ++ptr; |
| 4374 | |
| 4375 | if (extra_check) |
| 4376 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4377 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4378 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4379 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4380 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4381 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4382 | /* Get syntax attribute, unless still at the start of the line |
| 4383 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4384 | v = (long)(ptr - line); |
| 4385 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4386 | { |
| 4387 | /* Get the syntax attribute for the character. If there |
| 4388 | * is an error, disable syntax highlighting. */ |
| 4389 | save_did_emsg = did_emsg; |
| 4390 | did_emsg = FALSE; |
| 4391 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4392 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4393 | # ifdef FEAT_SPELL |
| 4394 | has_spell ? &can_spell : |
| 4395 | # endif |
| 4396 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4397 | |
| 4398 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4399 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4400 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4401 | has_syntax = FALSE; |
| 4402 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4403 | else |
| 4404 | did_emsg = save_did_emsg; |
| 4405 | |
| 4406 | /* Need to get the line again, a multi-line regexp may |
| 4407 | * have made it invalid. */ |
| 4408 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4409 | ptr = line + v; |
| 4410 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4411 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4412 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4413 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4414 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4415 | # ifdef FEAT_CONCEAL |
| 4416 | /* no concealing past the end of the line, it interferes |
| 4417 | * with line highlighting */ |
| 4418 | if (c == NUL) |
| 4419 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4420 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4421 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4422 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4423 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4424 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4425 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4426 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4427 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4428 | * Only do this when there is no syntax highlighting, the |
| 4429 | * @Spell cluster is not used or the current syntax item |
| 4430 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4431 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4432 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4433 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4434 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4435 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4436 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4437 | # endif |
| 4438 | if (c != 0 && ( |
| 4439 | # ifdef FEAT_SYN_HL |
| 4440 | !has_syntax || |
| 4441 | # endif |
| 4442 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4443 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4444 | char_u *prev_ptr, *p; |
| 4445 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4446 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4447 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4448 | if (has_mbyte) |
| 4449 | { |
| 4450 | prev_ptr = ptr - mb_l; |
| 4451 | v -= mb_l - 1; |
| 4452 | } |
| 4453 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4454 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4455 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4456 | |
| 4457 | /* Use nextline[] if possible, it has the start of the |
| 4458 | * next line concatenated. */ |
| 4459 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4460 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4461 | else |
| 4462 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4463 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4464 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4465 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4466 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4467 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4468 | /* In Insert mode only highlight a word that |
| 4469 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4470 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4471 | && (State & INSERT) != 0 |
| 4472 | && wp->w_cursor.lnum == lnum |
| 4473 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4474 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4475 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4476 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4477 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4478 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4479 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4480 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4481 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4482 | && (p - nextline) + len > nextline_idx) |
| 4483 | { |
| 4484 | /* Remember that the good word continues at the |
| 4485 | * start of the next line. */ |
| 4486 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4487 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4488 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4489 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4490 | /* Turn index into actual attributes. */ |
| 4491 | if (spell_hlf != HLF_COUNT) |
| 4492 | spell_attr = highlight_attr[spell_hlf]; |
| 4493 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4494 | if (cap_col > 0) |
| 4495 | { |
| 4496 | if (p != prev_ptr |
| 4497 | && (p - nextline) + cap_col >= nextline_idx) |
| 4498 | { |
| 4499 | /* Remember that the word in the next line |
| 4500 | * must start with a capital. */ |
| 4501 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4502 | cap_col = (int)((p - nextline) + cap_col |
| 4503 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4504 | } |
| 4505 | else |
| 4506 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4507 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4508 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4509 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4510 | } |
| 4511 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4512 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4513 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4514 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4515 | else |
| 4516 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4517 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4518 | #endif |
| 4519 | #ifdef FEAT_LINEBREAK |
| 4520 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4521 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4522 | */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4523 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4524 | { |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4525 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4526 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4527 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4528 | char_u *p = ptr - ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4529 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4530 | mb_off + |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4531 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4532 | 1); |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4533 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4534 | /* TODO: is passing p for start of the line OK? */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4535 | n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4536 | NULL) - 1; |
Bram Moolenaar | a365091 | 2014-11-19 13:21:57 +0100 | [diff] [blame] | 4537 | if (c == TAB && n_extra + col > W_WIDTH(wp)) |
| 4538 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4539 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4540 | |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4541 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4542 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4543 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4544 | c_extra = ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4545 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4546 | if (vim_iswhite(c)) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4547 | { |
| 4548 | #ifdef FEAT_CONCEAL |
| 4549 | if (c == TAB) |
| 4550 | /* See "Tab alignment" below. */ |
| 4551 | FIX_FOR_BOGUSCOLS; |
| 4552 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4553 | if (!wp->w_p_list) |
| 4554 | c = ' '; |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4555 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4556 | } |
| 4557 | #endif |
| 4558 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 4559 | /* 'list': change char 160 to lcs_nbsp and space to lcs_space. |
| 4560 | */ |
| 4561 | if (wp->w_p_list |
| 4562 | && (((c == 160 |
| 4563 | #ifdef FEAT_MBYTE |
| 4564 | || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)) |
| 4565 | #endif |
| 4566 | ) && lcs_nbsp) |
| 4567 | || (c == ' ' && lcs_space && ptr - line <= trailcol))) |
| 4568 | { |
| 4569 | c = (c == ' ') ? lcs_space : lcs_nbsp; |
| 4570 | if (area_attr == 0 && search_attr == 0) |
| 4571 | { |
| 4572 | n_attr = 1; |
| 4573 | extra_attr = hl_attr(HLF_8); |
| 4574 | saved_attr2 = char_attr; /* save current attr */ |
| 4575 | } |
| 4576 | #ifdef FEAT_MBYTE |
| 4577 | mb_c = c; |
| 4578 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4579 | { |
| 4580 | mb_utf8 = TRUE; |
| 4581 | u8cc[0] = 0; |
| 4582 | c = 0xc0; |
| 4583 | } |
| 4584 | else |
| 4585 | mb_utf8 = FALSE; |
| 4586 | #endif |
| 4587 | } |
| 4588 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4589 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4590 | { |
| 4591 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4592 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4593 | { |
| 4594 | n_attr = 1; |
| 4595 | extra_attr = hl_attr(HLF_8); |
| 4596 | saved_attr2 = char_attr; /* save current attr */ |
| 4597 | } |
| 4598 | #ifdef FEAT_MBYTE |
| 4599 | mb_c = c; |
| 4600 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4601 | { |
| 4602 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4603 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4604 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4605 | } |
| 4606 | else |
| 4607 | mb_utf8 = FALSE; |
| 4608 | #endif |
| 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | /* |
| 4613 | * Handling of non-printable characters. |
| 4614 | */ |
Bram Moolenaar | 88e8f9f | 2016-01-20 22:48:02 +0100 | [diff] [blame] | 4615 | if (!vim_isprintc(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4616 | { |
| 4617 | /* |
| 4618 | * when getting a character from the file, we may have to |
| 4619 | * turn it into something else on the way to putting it |
| 4620 | * into "ScreenLines". |
| 4621 | */ |
| 4622 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4623 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4624 | int tab_len = 0; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4625 | long vcol_adjusted = vcol; /* removed showbreak length */ |
| 4626 | #ifdef FEAT_LINEBREAK |
| 4627 | /* only adjust the tab_len, when at the first column |
| 4628 | * after the showbreak value was drawn */ |
| 4629 | if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 4630 | vcol_adjusted = vcol - MB_CHARLEN(p_sbr); |
| 4631 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4632 | /* tab amount depends on current column */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4633 | tab_len = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4634 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 4635 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4636 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81c85d | 2014-07-30 16:44:22 +0200 | [diff] [blame] | 4637 | if (!wp->w_p_lbr || !wp->w_p_list) |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4638 | #endif |
| 4639 | /* tab amount depends on current column */ |
| 4640 | n_extra = tab_len; |
| 4641 | #ifdef FEAT_LINEBREAK |
| 4642 | else |
| 4643 | { |
| 4644 | char_u *p; |
| 4645 | int len = n_extra; |
| 4646 | int i; |
| 4647 | int saved_nextra = n_extra; |
| 4648 | |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4649 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4650 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4651 | /* there are characters to conceal */ |
| 4652 | tab_len += vcol_off; |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4653 | /* boguscols before FIX_FOR_BOGUSCOLS macro from above |
| 4654 | */ |
| 4655 | if (wp->w_p_list && lcs_tab1 && old_boguscols > 0 |
| 4656 | && n_extra > tab_len) |
| 4657 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4658 | #endif |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4659 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4660 | /* if n_extra > 0, it gives the number of chars, to |
| 4661 | * use for a tab, else we need to calculate the width |
| 4662 | * for a tab */ |
| 4663 | #ifdef FEAT_MBYTE |
| 4664 | len = (tab_len * mb_char2len(lcs_tab2)); |
| 4665 | if (n_extra > 0) |
| 4666 | len += n_extra - tab_len; |
| 4667 | #endif |
| 4668 | c = lcs_tab1; |
| 4669 | p = alloc((unsigned)(len + 1)); |
| 4670 | vim_memset(p, ' ', len); |
| 4671 | p[len] = NUL; |
| 4672 | p_extra_free = p; |
| 4673 | for (i = 0; i < tab_len; i++) |
| 4674 | { |
| 4675 | #ifdef FEAT_MBYTE |
| 4676 | mb_char2bytes(lcs_tab2, p); |
| 4677 | p += mb_char2len(lcs_tab2); |
| 4678 | n_extra += mb_char2len(lcs_tab2) |
| 4679 | - (saved_nextra > 0 ? 1 : 0); |
| 4680 | #else |
| 4681 | p[i] = lcs_tab2; |
| 4682 | #endif |
| 4683 | } |
| 4684 | p_extra = p_extra_free; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4685 | #ifdef FEAT_CONCEAL |
| 4686 | /* n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 4687 | * macro below, so need to adjust for that here */ |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4688 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4689 | n_extra -= vcol_off; |
| 4690 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4691 | } |
| 4692 | #endif |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4693 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4694 | { |
| 4695 | int vc_saved = vcol_off; |
| 4696 | |
| 4697 | /* Tab alignment should be identical regardless of |
| 4698 | * 'conceallevel' value. So tab compensates of all |
| 4699 | * previous concealed characters, and thus resets |
| 4700 | * vcol_off and boguscols accumulated so far in the |
| 4701 | * line. Note that the tab can be longer than |
| 4702 | * 'tabstop' when there are concealed characters. */ |
| 4703 | FIX_FOR_BOGUSCOLS; |
| 4704 | |
| 4705 | /* Make sure, the highlighting for the tab char will be |
| 4706 | * correctly set further below (effectively reverts the |
| 4707 | * FIX_FOR_BOGSUCOLS macro */ |
| 4708 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4709 | && lcs_tab1) |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4710 | tab_len += vc_saved; |
| 4711 | } |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4712 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4713 | #ifdef FEAT_MBYTE |
| 4714 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4715 | #endif |
| 4716 | if (wp->w_p_list) |
| 4717 | { |
| 4718 | c = lcs_tab1; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4719 | #ifdef FEAT_LINEBREAK |
| 4720 | if (wp->w_p_lbr) |
| 4721 | c_extra = NUL; /* using p_extra from above */ |
| 4722 | else |
| 4723 | #endif |
| 4724 | c_extra = lcs_tab2; |
| 4725 | n_attr = tab_len + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4726 | extra_attr = hl_attr(HLF_8); |
| 4727 | saved_attr2 = char_attr; /* save current attr */ |
| 4728 | #ifdef FEAT_MBYTE |
| 4729 | mb_c = c; |
| 4730 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4731 | { |
| 4732 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4733 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4734 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4735 | } |
| 4736 | #endif |
| 4737 | } |
| 4738 | else |
| 4739 | { |
| 4740 | c_extra = ' '; |
| 4741 | c = ' '; |
| 4742 | } |
| 4743 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4744 | else if (c == NUL |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4745 | && (wp->w_p_list |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4746 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4747 | && tocol > vcol |
| 4748 | && VIsual_mode != Ctrl_V |
| 4749 | && ( |
| 4750 | # ifdef FEAT_RIGHTLEFT |
| 4751 | wp->w_p_rl ? (col >= 0) : |
| 4752 | # endif |
| 4753 | (col < W_WIDTH(wp))) |
| 4754 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4755 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4756 | && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 0481fee | 2015-05-14 05:56:09 +0200 | [diff] [blame] | 4757 | && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4758 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4759 | /* Display a '$' after the line or highlight an extra |
| 4760 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4761 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4762 | /* For a diff line the highlighting continues after the |
| 4763 | * "$". */ |
| 4764 | if ( |
| 4765 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4766 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4767 | # ifdef LINE_ATTR |
| 4768 | && |
| 4769 | # endif |
| 4770 | # endif |
| 4771 | # ifdef LINE_ATTR |
| 4772 | line_attr == 0 |
| 4773 | # endif |
| 4774 | ) |
| 4775 | #endif |
| 4776 | { |
| 4777 | #ifdef FEAT_VIRTUALEDIT |
| 4778 | /* In virtualedit, visual selections may extend |
| 4779 | * beyond end of line. */ |
| 4780 | if (area_highlighting && virtual_active() |
| 4781 | && tocol != MAXCOL && vcol < tocol) |
| 4782 | n_extra = 0; |
| 4783 | else |
| 4784 | #endif |
| 4785 | { |
| 4786 | p_extra = at_end_str; |
| 4787 | n_extra = 1; |
| 4788 | c_extra = NUL; |
| 4789 | } |
| 4790 | } |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4791 | if (wp->w_p_list && lcs_eol > 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4792 | c = lcs_eol; |
| 4793 | else |
| 4794 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4795 | lcs_eol_one = -1; |
| 4796 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4797 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4798 | { |
| 4799 | extra_attr = hl_attr(HLF_AT); |
| 4800 | n_attr = 1; |
| 4801 | } |
| 4802 | #ifdef FEAT_MBYTE |
| 4803 | mb_c = c; |
| 4804 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4805 | { |
| 4806 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4807 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4808 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4809 | } |
| 4810 | else |
| 4811 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4812 | #endif |
| 4813 | } |
| 4814 | else if (c != NUL) |
| 4815 | { |
| 4816 | p_extra = transchar(c); |
Bram Moolenaar | 5524aeb | 2014-07-16 17:29:51 +0200 | [diff] [blame] | 4817 | if (n_extra == 0) |
| 4818 | n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4819 | #ifdef FEAT_RIGHTLEFT |
| 4820 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4821 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4822 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4823 | c_extra = NUL; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4824 | #ifdef FEAT_LINEBREAK |
| 4825 | if (wp->w_p_lbr) |
| 4826 | { |
| 4827 | char_u *p; |
| 4828 | |
| 4829 | c = *p_extra; |
| 4830 | p = alloc((unsigned)n_extra + 1); |
| 4831 | vim_memset(p, ' ', n_extra); |
| 4832 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 4833 | p[n_extra] = NUL; |
| 4834 | p_extra_free = p_extra = p; |
| 4835 | } |
| 4836 | else |
| 4837 | #endif |
| 4838 | { |
| 4839 | n_extra = byte2cells(c) - 1; |
| 4840 | c = *p_extra++; |
| 4841 | } |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4842 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4843 | { |
| 4844 | n_attr = n_extra + 1; |
| 4845 | extra_attr = hl_attr(HLF_8); |
| 4846 | saved_attr2 = char_attr; /* save current attr */ |
| 4847 | } |
| 4848 | #ifdef FEAT_MBYTE |
| 4849 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4850 | #endif |
| 4851 | } |
| 4852 | #ifdef FEAT_VIRTUALEDIT |
| 4853 | else if (VIsual_active |
| 4854 | && (VIsual_mode == Ctrl_V |
| 4855 | || VIsual_mode == 'v') |
| 4856 | && virtual_active() |
| 4857 | && tocol != MAXCOL |
| 4858 | && vcol < tocol |
| 4859 | && ( |
| 4860 | # ifdef FEAT_RIGHTLEFT |
| 4861 | wp->w_p_rl ? (col >= 0) : |
| 4862 | # endif |
| 4863 | (col < W_WIDTH(wp)))) |
| 4864 | { |
| 4865 | c = ' '; |
| 4866 | --ptr; /* put it back at the NUL */ |
| 4867 | } |
| 4868 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4869 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4870 | else if (( |
| 4871 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4872 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4873 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4874 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4875 | ) && ( |
| 4876 | # ifdef FEAT_RIGHTLEFT |
| 4877 | wp->w_p_rl ? (col >= 0) : |
| 4878 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4879 | (col |
| 4880 | # ifdef FEAT_CONCEAL |
| 4881 | - boguscols |
| 4882 | # endif |
| 4883 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4884 | { |
| 4885 | /* Highlight until the right side of the window */ |
| 4886 | c = ' '; |
| 4887 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4888 | |
| 4889 | /* Remember we do the char for line highlighting. */ |
| 4890 | ++did_line_attr; |
| 4891 | |
| 4892 | /* don't do search HL for the rest of the line */ |
| 4893 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4894 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4895 | # ifdef FEAT_DIFF |
| 4896 | if (diff_hlf == HLF_TXD) |
| 4897 | { |
| 4898 | diff_hlf = HLF_CHD; |
| 4899 | if (attr == 0 || char_attr != attr) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4900 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4901 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4902 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4903 | char_attr = hl_combine_attr(char_attr, |
| 4904 | hl_attr(HLF_CUL)); |
| 4905 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4906 | } |
| 4907 | # endif |
| 4908 | } |
| 4909 | #endif |
| 4910 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4911 | |
| 4912 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4913 | if ( wp->w_p_cole > 0 |
| 4914 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4915 | conceal_cursor_line(wp) ) |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4916 | && ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4917 | && !(lnum_in_visual_area |
| 4918 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4919 | { |
| 4920 | char_attr = conceal_attr; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4921 | if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1) |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4922 | && (syn_get_sub_char() != NUL || match_conc |
| 4923 | || wp->w_p_cole == 1) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4924 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4925 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4926 | /* First time at this concealed item: display one |
| 4927 | * character. */ |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4928 | if (match_conc) |
| 4929 | c = match_conc; |
| 4930 | else if (syn_get_sub_char() != NUL) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4931 | c = syn_get_sub_char(); |
| 4932 | else if (lcs_conceal != NUL) |
| 4933 | c = lcs_conceal; |
| 4934 | else |
| 4935 | c = ' '; |
| 4936 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4937 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4938 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4939 | if (n_extra > 0) |
| 4940 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4941 | vcol += n_extra; |
| 4942 | if (wp->w_p_wrap && n_extra > 0) |
| 4943 | { |
| 4944 | # ifdef FEAT_RIGHTLEFT |
| 4945 | if (wp->w_p_rl) |
| 4946 | { |
| 4947 | col -= n_extra; |
| 4948 | boguscols -= n_extra; |
| 4949 | } |
| 4950 | else |
| 4951 | # endif |
| 4952 | { |
| 4953 | boguscols += n_extra; |
| 4954 | col += n_extra; |
| 4955 | } |
| 4956 | } |
| 4957 | n_extra = 0; |
| 4958 | n_attr = 0; |
| 4959 | } |
| 4960 | else if (n_skip == 0) |
| 4961 | { |
| 4962 | is_concealing = TRUE; |
| 4963 | n_skip = 1; |
| 4964 | } |
| 4965 | # ifdef FEAT_MBYTE |
| 4966 | mb_c = c; |
| 4967 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4968 | { |
| 4969 | mb_utf8 = TRUE; |
| 4970 | u8cc[0] = 0; |
| 4971 | c = 0xc0; |
| 4972 | } |
| 4973 | else |
| 4974 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4975 | # endif |
| 4976 | } |
| 4977 | else |
| 4978 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4979 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4980 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4981 | } |
| 4982 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4983 | } |
| 4984 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4985 | #ifdef FEAT_CONCEAL |
| 4986 | /* In the cursor line and we may be concealing characters: correct |
| 4987 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 4988 | if (!did_wcol && draw_state == WL_LINE |
| 4989 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4990 | && conceal_cursor_line(wp) |
| 4991 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 4992 | { |
Bram Moolenaar | e39b3d9 | 2016-01-15 22:52:22 +0100 | [diff] [blame] | 4993 | # ifdef FEAT_RIGHTLEFT |
| 4994 | if (wp->w_p_rl) |
| 4995 | wp->w_wcol = W_WIDTH(wp) - col + boguscols - 1; |
| 4996 | else |
| 4997 | # endif |
| 4998 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 4999 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5000 | did_wcol = TRUE; |
| 5001 | } |
| 5002 | #endif |
| 5003 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5004 | /* Don't override visual selection highlighting. */ |
| 5005 | if (n_attr > 0 |
| 5006 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5007 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5008 | char_attr = extra_attr; |
| 5009 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5010 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5011 | /* XIM don't send preedit_start and preedit_end, but they send |
| 5012 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 5013 | * im_is_preediting() here. */ |
| 5014 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5015 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5016 | && (State & INSERT) |
| 5017 | && !p_imdisable |
| 5018 | && im_is_preediting() |
| 5019 | && draw_state == WL_LINE) |
| 5020 | { |
| 5021 | colnr_T tcol; |
| 5022 | |
| 5023 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5024 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5025 | else |
| 5026 | tcol = preedit_end_col; |
| 5027 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 5028 | { |
| 5029 | if (feedback_old_attr < 0) |
| 5030 | { |
| 5031 | feedback_col = 0; |
| 5032 | feedback_old_attr = char_attr; |
| 5033 | } |
| 5034 | char_attr = im_get_feedback_attr(feedback_col); |
| 5035 | if (char_attr < 0) |
| 5036 | char_attr = feedback_old_attr; |
| 5037 | feedback_col++; |
| 5038 | } |
| 5039 | else if (feedback_old_attr >= 0) |
| 5040 | { |
| 5041 | char_attr = feedback_old_attr; |
| 5042 | feedback_old_attr = -1; |
| 5043 | feedback_col = 0; |
| 5044 | } |
| 5045 | } |
| 5046 | #endif |
| 5047 | /* |
| 5048 | * Handle the case where we are in column 0 but not on the first |
| 5049 | * character of the line and the user wants us to show us a |
| 5050 | * special character (via 'listchars' option "precedes:<char>". |
| 5051 | */ |
| 5052 | if (lcs_prec_todo != NUL |
Bram Moolenaar | 7425b93 | 2014-10-10 15:28:46 +0200 | [diff] [blame] | 5053 | && wp->w_p_list |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5054 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 5055 | #ifdef FEAT_DIFF |
| 5056 | && filler_todo <= 0 |
| 5057 | #endif |
| 5058 | && draw_state > WL_NR |
| 5059 | && c != NUL) |
| 5060 | { |
| 5061 | c = lcs_prec; |
| 5062 | lcs_prec_todo = NUL; |
| 5063 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 5064 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5065 | { |
| 5066 | /* Double-width character being overwritten by the "precedes" |
| 5067 | * character, need to fill up half the character. */ |
| 5068 | c_extra = MB_FILLER_CHAR; |
| 5069 | n_extra = 1; |
| 5070 | n_attr = 2; |
| 5071 | extra_attr = hl_attr(HLF_AT); |
| 5072 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5073 | mb_c = c; |
| 5074 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5075 | { |
| 5076 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5077 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5078 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5079 | } |
| 5080 | else |
| 5081 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5082 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5083 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5084 | { |
| 5085 | saved_attr3 = char_attr; /* save current attr */ |
| 5086 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 5087 | n_attr3 = 1; |
| 5088 | } |
| 5089 | } |
| 5090 | |
| 5091 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5092 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5093 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5094 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5095 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5096 | || did_line_attr == 1 |
| 5097 | #endif |
| 5098 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5099 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5100 | #ifdef FEAT_SEARCH_EXTRA |
| 5101 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5102 | |
| 5103 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 5104 | 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] | 5105 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5106 | #endif |
| 5107 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5108 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5109 | * highlight match at end of line. If it's beyond the last |
| 5110 | * char on the screen, just overwrite that one (tricky!) Not |
| 5111 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5112 | #ifdef FEAT_SEARCH_EXTRA |
| 5113 | prevcol_hl_flag = FALSE; |
| 5114 | if (prevcol == (long)search_hl.startcol) |
| 5115 | prevcol_hl_flag = TRUE; |
| 5116 | else |
| 5117 | { |
| 5118 | cur = wp->w_match_head; |
| 5119 | while (cur != NULL) |
| 5120 | { |
| 5121 | if (prevcol == (long)cur->hl.startcol) |
| 5122 | { |
| 5123 | prevcol_hl_flag = TRUE; |
| 5124 | break; |
| 5125 | } |
| 5126 | cur = cur->next; |
| 5127 | } |
| 5128 | } |
| 5129 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5130 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5131 | && ((area_attr != 0 && vcol == fromcol |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5132 | && (VIsual_mode != Ctrl_V |
| 5133 | || lnum == VIsual.lnum |
| 5134 | || lnum == curwin->w_cursor.lnum) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5135 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5136 | #ifdef FEAT_SEARCH_EXTRA |
| 5137 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5138 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5139 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5140 | && did_line_attr <= 1 |
| 5141 | # endif |
| 5142 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5143 | #endif |
| 5144 | )) |
| 5145 | { |
| 5146 | int n = 0; |
| 5147 | |
| 5148 | #ifdef FEAT_RIGHTLEFT |
| 5149 | if (wp->w_p_rl) |
| 5150 | { |
| 5151 | if (col < 0) |
| 5152 | n = 1; |
| 5153 | } |
| 5154 | else |
| 5155 | #endif |
| 5156 | { |
| 5157 | if (col >= W_WIDTH(wp)) |
| 5158 | n = -1; |
| 5159 | } |
| 5160 | if (n != 0) |
| 5161 | { |
| 5162 | /* At the window boundary, highlight the last character |
| 5163 | * instead (better than nothing). */ |
| 5164 | off += n; |
| 5165 | col += n; |
| 5166 | } |
| 5167 | else |
| 5168 | { |
| 5169 | /* Add a blank character to highlight. */ |
| 5170 | ScreenLines[off] = ' '; |
| 5171 | #ifdef FEAT_MBYTE |
| 5172 | if (enc_utf8) |
| 5173 | ScreenLinesUC[off] = 0; |
| 5174 | #endif |
| 5175 | } |
| 5176 | #ifdef FEAT_SEARCH_EXTRA |
| 5177 | if (area_attr == 0) |
| 5178 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5179 | /* Use attributes from match with highest priority among |
| 5180 | * 'search_hl' and the match list. */ |
| 5181 | char_attr = search_hl.attr; |
| 5182 | cur = wp->w_match_head; |
| 5183 | shl_flag = FALSE; |
| 5184 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5185 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5186 | if (shl_flag == FALSE |
| 5187 | && ((cur != NULL |
| 5188 | && cur->priority > SEARCH_HL_PRIORITY) |
| 5189 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5190 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5191 | shl = &search_hl; |
| 5192 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5193 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5194 | else |
| 5195 | shl = &cur->hl; |
| 5196 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 5197 | char_attr = shl->attr; |
| 5198 | if (shl != &search_hl && cur != NULL) |
| 5199 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5200 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5201 | } |
| 5202 | #endif |
| 5203 | ScreenAttrs[off] = char_attr; |
| 5204 | #ifdef FEAT_RIGHTLEFT |
| 5205 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5206 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5207 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5208 | --off; |
| 5209 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5210 | else |
| 5211 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5212 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5213 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5214 | ++off; |
| 5215 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5216 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5217 | #ifdef FEAT_SYN_HL |
| 5218 | eol_hl_off = 1; |
| 5219 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5220 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5221 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5222 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5223 | /* |
| 5224 | * At end of the text line. |
| 5225 | */ |
| 5226 | if (c == NUL) |
| 5227 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5228 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5229 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 5230 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5231 | { |
| 5232 | /* highlight last char after line */ |
| 5233 | --col; |
| 5234 | --off; |
| 5235 | --vcol; |
| 5236 | } |
| 5237 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5238 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 5239 | if (wp->w_p_wrap) |
| 5240 | v = wp->w_skipcol; |
| 5241 | else |
| 5242 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5243 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5244 | /* check if line ends before left margin */ |
| 5245 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5246 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5247 | #ifdef FEAT_CONCEAL |
| 5248 | /* Get rid of the boguscols now, we want to draw until the right |
| 5249 | * edge for 'cursorcolumn'. */ |
| 5250 | col -= boguscols; |
| 5251 | boguscols = 0; |
| 5252 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5253 | |
| 5254 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5255 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5256 | |
| 5257 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5258 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 5259 | && (int)wp->w_virtcol < |
| 5260 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5261 | && lnum != wp->w_cursor.lnum) |
| 5262 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5263 | # ifdef FEAT_RIGHTLEFT |
| 5264 | && !wp->w_p_rl |
| 5265 | # endif |
| 5266 | ) |
| 5267 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5268 | int rightmost_vcol = 0; |
| 5269 | int i; |
| 5270 | |
| 5271 | if (wp->w_p_cuc) |
| 5272 | rightmost_vcol = wp->w_virtcol; |
| 5273 | if (draw_color_col) |
| 5274 | /* determine rightmost colorcolumn to possibly draw */ |
| 5275 | for (i = 0; color_cols[i] >= 0; ++i) |
| 5276 | if (rightmost_vcol < color_cols[i]) |
| 5277 | rightmost_vcol = color_cols[i]; |
| 5278 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5279 | while (col < W_WIDTH(wp)) |
| 5280 | { |
| 5281 | ScreenLines[off] = ' '; |
| 5282 | #ifdef FEAT_MBYTE |
| 5283 | if (enc_utf8) |
| 5284 | ScreenLinesUC[off] = 0; |
| 5285 | #endif |
| 5286 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 5287 | if (draw_color_col) |
| 5288 | draw_color_col = advance_color_col(VCOL_HLC, |
| 5289 | &color_cols); |
| 5290 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5291 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5292 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5293 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5294 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 5295 | else |
| 5296 | ScreenAttrs[off++] = 0; |
| 5297 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5298 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5299 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5300 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5301 | ++vcol; |
| 5302 | } |
| 5303 | } |
| 5304 | #endif |
| 5305 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5306 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5307 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5308 | row++; |
| 5309 | |
| 5310 | /* |
| 5311 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 5312 | * updated (saves a call to plines() later). |
| 5313 | */ |
| 5314 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 5315 | { |
| 5316 | curwin->w_cline_row = startrow; |
| 5317 | curwin->w_cline_height = row - startrow; |
| 5318 | #ifdef FEAT_FOLDING |
| 5319 | curwin->w_cline_folded = FALSE; |
| 5320 | #endif |
| 5321 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 5322 | } |
| 5323 | |
| 5324 | break; |
| 5325 | } |
| 5326 | |
| 5327 | /* line continues beyond line end */ |
| 5328 | if (lcs_ext |
| 5329 | && !wp->w_p_wrap |
| 5330 | #ifdef FEAT_DIFF |
| 5331 | && filler_todo <= 0 |
| 5332 | #endif |
| 5333 | && ( |
| 5334 | #ifdef FEAT_RIGHTLEFT |
| 5335 | wp->w_p_rl ? col == 0 : |
| 5336 | #endif |
| 5337 | col == W_WIDTH(wp) - 1) |
| 5338 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 5339 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5340 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 5341 | { |
| 5342 | c = lcs_ext; |
| 5343 | char_attr = hl_attr(HLF_AT); |
| 5344 | #ifdef FEAT_MBYTE |
| 5345 | mb_c = c; |
| 5346 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5347 | { |
| 5348 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5349 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5350 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5351 | } |
| 5352 | else |
| 5353 | mb_utf8 = FALSE; |
| 5354 | #endif |
| 5355 | } |
| 5356 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5357 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5358 | /* advance to the next 'colorcolumn' */ |
| 5359 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5360 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5361 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5362 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5363 | * highlight the cursor position itself. |
| 5364 | * Also highlight the 'colorcolumn' if it is different than |
| 5365 | * 'cursorcolumn' */ |
| 5366 | vcol_save_attr = -1; |
| 5367 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5368 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5369 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5370 | && lnum != wp->w_cursor.lnum) |
| 5371 | { |
| 5372 | vcol_save_attr = char_attr; |
| 5373 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 5374 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 5375 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5376 | { |
| 5377 | vcol_save_attr = char_attr; |
| 5378 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 5379 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5380 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5381 | #endif |
| 5382 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5383 | /* |
| 5384 | * Store character to be displayed. |
| 5385 | * Skip characters that are left of the screen for 'nowrap'. |
| 5386 | */ |
| 5387 | vcol_prev = vcol; |
| 5388 | if (draw_state < WL_LINE || n_skip <= 0) |
| 5389 | { |
| 5390 | /* |
| 5391 | * Store the character. |
| 5392 | */ |
| 5393 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 5394 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 5395 | { |
| 5396 | /* A double-wide character is: put first halve in left cell. */ |
| 5397 | --off; |
| 5398 | --col; |
| 5399 | } |
| 5400 | #endif |
| 5401 | ScreenLines[off] = c; |
| 5402 | #ifdef FEAT_MBYTE |
| 5403 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5404 | { |
| 5405 | if ((mb_c & 0xff00) == 0x8e00) |
| 5406 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5407 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5408 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5409 | else if (enc_utf8) |
| 5410 | { |
| 5411 | if (mb_utf8) |
| 5412 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5413 | int i; |
| 5414 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5415 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5416 | if ((c & 0xff) == 0) |
| 5417 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5418 | for (i = 0; i < Screen_mco; ++i) |
| 5419 | { |
| 5420 | ScreenLinesC[i][off] = u8cc[i]; |
| 5421 | if (u8cc[i] == 0) |
| 5422 | break; |
| 5423 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5424 | } |
| 5425 | else |
| 5426 | ScreenLinesUC[off] = 0; |
| 5427 | } |
| 5428 | if (multi_attr) |
| 5429 | { |
| 5430 | ScreenAttrs[off] = multi_attr; |
| 5431 | multi_attr = 0; |
| 5432 | } |
| 5433 | else |
| 5434 | #endif |
| 5435 | ScreenAttrs[off] = char_attr; |
| 5436 | |
| 5437 | #ifdef FEAT_MBYTE |
| 5438 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5439 | { |
| 5440 | /* Need to fill two screen columns. */ |
| 5441 | ++off; |
| 5442 | ++col; |
| 5443 | if (enc_utf8) |
| 5444 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5445 | ScreenLines[off] = 0; |
| 5446 | else |
| 5447 | /* DBCS: Put second byte in the second screen char. */ |
| 5448 | ScreenLines[off] = mb_c & 0xff; |
Bram Moolenaar | 32a214e | 2015-12-03 14:29:02 +0100 | [diff] [blame] | 5449 | if (draw_state > WL_NR |
| 5450 | #ifdef FEAT_DIFF |
| 5451 | && filler_todo <= 0 |
| 5452 | #endif |
| 5453 | ) |
| 5454 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5455 | /* When "tocol" is halfway a character, set it to the end of |
| 5456 | * the character, otherwise highlighting won't stop. */ |
| 5457 | if (tocol == vcol) |
| 5458 | ++tocol; |
| 5459 | #ifdef FEAT_RIGHTLEFT |
| 5460 | if (wp->w_p_rl) |
| 5461 | { |
| 5462 | /* now it's time to backup one cell */ |
| 5463 | --off; |
| 5464 | --col; |
| 5465 | } |
| 5466 | #endif |
| 5467 | } |
| 5468 | #endif |
| 5469 | #ifdef FEAT_RIGHTLEFT |
| 5470 | if (wp->w_p_rl) |
| 5471 | { |
| 5472 | --off; |
| 5473 | --col; |
| 5474 | } |
| 5475 | else |
| 5476 | #endif |
| 5477 | { |
| 5478 | ++off; |
| 5479 | ++col; |
| 5480 | } |
| 5481 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5482 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5483 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5484 | { |
| 5485 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5486 | ++vcol_off; |
| 5487 | if (n_extra > 0) |
| 5488 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5489 | if (wp->w_p_wrap) |
| 5490 | { |
| 5491 | /* |
| 5492 | * Special voodoo required if 'wrap' is on. |
| 5493 | * |
| 5494 | * Advance the column indicator to force the line |
| 5495 | * drawing to wrap early. This will make the line |
| 5496 | * take up the same screen space when parts are concealed, |
| 5497 | * so that cursor line computations aren't messed up. |
| 5498 | * |
| 5499 | * To avoid the fictitious advance of 'col' causing |
| 5500 | * trailing junk to be written out of the screen line |
| 5501 | * we are building, 'boguscols' keeps track of the number |
| 5502 | * of bad columns we have advanced. |
| 5503 | */ |
| 5504 | if (n_extra > 0) |
| 5505 | { |
| 5506 | vcol += n_extra; |
| 5507 | # ifdef FEAT_RIGHTLEFT |
| 5508 | if (wp->w_p_rl) |
| 5509 | { |
| 5510 | col -= n_extra; |
| 5511 | boguscols -= n_extra; |
| 5512 | } |
| 5513 | else |
| 5514 | # endif |
| 5515 | { |
| 5516 | col += n_extra; |
| 5517 | boguscols += n_extra; |
| 5518 | } |
| 5519 | n_extra = 0; |
| 5520 | n_attr = 0; |
| 5521 | } |
| 5522 | |
| 5523 | |
| 5524 | # ifdef FEAT_MBYTE |
| 5525 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5526 | { |
| 5527 | /* Need to fill two screen columns. */ |
| 5528 | # ifdef FEAT_RIGHTLEFT |
| 5529 | if (wp->w_p_rl) |
| 5530 | { |
| 5531 | --boguscols; |
| 5532 | --col; |
| 5533 | } |
| 5534 | else |
| 5535 | # endif |
| 5536 | { |
| 5537 | ++boguscols; |
| 5538 | ++col; |
| 5539 | } |
| 5540 | } |
| 5541 | # endif |
| 5542 | |
| 5543 | # ifdef FEAT_RIGHTLEFT |
| 5544 | if (wp->w_p_rl) |
| 5545 | { |
| 5546 | --boguscols; |
| 5547 | --col; |
| 5548 | } |
| 5549 | else |
| 5550 | # endif |
| 5551 | { |
| 5552 | ++boguscols; |
| 5553 | ++col; |
| 5554 | } |
| 5555 | } |
| 5556 | else |
| 5557 | { |
| 5558 | if (n_extra > 0) |
| 5559 | { |
| 5560 | vcol += n_extra; |
| 5561 | n_extra = 0; |
| 5562 | n_attr = 0; |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | } |
| 5567 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5568 | else |
| 5569 | --n_skip; |
| 5570 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5571 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5572 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5573 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5574 | #ifdef FEAT_DIFF |
| 5575 | && filler_todo <= 0 |
| 5576 | #endif |
| 5577 | ) |
| 5578 | ++vcol; |
| 5579 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5580 | #ifdef FEAT_SYN_HL |
| 5581 | if (vcol_save_attr >= 0) |
| 5582 | char_attr = vcol_save_attr; |
| 5583 | #endif |
| 5584 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5585 | /* restore attributes after "predeces" in 'listchars' */ |
| 5586 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5587 | char_attr = saved_attr3; |
| 5588 | |
| 5589 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5590 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5591 | char_attr = saved_attr2; |
| 5592 | |
| 5593 | /* |
| 5594 | * 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] | 5595 | * 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] | 5596 | */ |
| 5597 | if (( |
| 5598 | #ifdef FEAT_RIGHTLEFT |
| 5599 | wp->w_p_rl ? (col < 0) : |
| 5600 | #endif |
| 5601 | (col >= W_WIDTH(wp))) |
| 5602 | && (*ptr != NUL |
| 5603 | #ifdef FEAT_DIFF |
| 5604 | || filler_todo > 0 |
| 5605 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5606 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5607 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5608 | ) |
| 5609 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5610 | #ifdef FEAT_CONCEAL |
| 5611 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5612 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5613 | boguscols = 0; |
| 5614 | #else |
| 5615 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5616 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5617 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5618 | ++row; |
| 5619 | ++screen_row; |
| 5620 | |
| 5621 | /* When not wrapping and finished diff lines, or when displayed |
| 5622 | * '$' and highlighting until last column, break here. */ |
| 5623 | if ((!wp->w_p_wrap |
| 5624 | #ifdef FEAT_DIFF |
| 5625 | && filler_todo <= 0 |
| 5626 | #endif |
| 5627 | ) || lcs_eol_one == -1) |
| 5628 | break; |
| 5629 | |
| 5630 | /* When the window is too narrow draw all "@" lines. */ |
| 5631 | if (draw_state != WL_LINE |
| 5632 | #ifdef FEAT_DIFF |
| 5633 | && filler_todo <= 0 |
| 5634 | #endif |
| 5635 | ) |
| 5636 | { |
| 5637 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5638 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5639 | draw_vsep_win(wp, row); |
| 5640 | #endif |
| 5641 | row = endrow; |
| 5642 | } |
| 5643 | |
| 5644 | /* When line got too long for screen break here. */ |
| 5645 | if (row == endrow) |
| 5646 | { |
| 5647 | ++row; |
| 5648 | break; |
| 5649 | } |
| 5650 | |
| 5651 | if (screen_cur_row == screen_row - 1 |
| 5652 | #ifdef FEAT_DIFF |
| 5653 | && filler_todo <= 0 |
| 5654 | #endif |
| 5655 | && W_WIDTH(wp) == Columns) |
| 5656 | { |
| 5657 | /* Remember that the line wraps, used for modeless copy. */ |
| 5658 | LineWraps[screen_row - 1] = TRUE; |
| 5659 | |
| 5660 | /* |
| 5661 | * Special trick to make copy/paste of wrapped lines work with |
| 5662 | * xterm/screen: write an extra character beyond the end of |
| 5663 | * the line. This will work with all terminal types |
| 5664 | * (regardless of the xn,am settings). |
| 5665 | * Only do this on a fast tty. |
| 5666 | * Only do this if the cursor is on the current line |
| 5667 | * (something has been written in it). |
| 5668 | * Don't do this for the GUI. |
| 5669 | * Don't do this for double-width characters. |
| 5670 | * Don't do this for a window not at the right screen border. |
| 5671 | */ |
| 5672 | if (p_tf |
| 5673 | #ifdef FEAT_GUI |
| 5674 | && !gui.in_use |
| 5675 | #endif |
| 5676 | #ifdef FEAT_MBYTE |
| 5677 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5678 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5679 | LineOffset[screen_row] + screen_Columns) |
| 5680 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5681 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5682 | + (int)Columns - 2, |
| 5683 | LineOffset[screen_row] + screen_Columns) |
| 5684 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5685 | #endif |
| 5686 | ) |
| 5687 | { |
| 5688 | /* First make sure we are at the end of the screen line, |
| 5689 | * then output the same character again to let the |
| 5690 | * terminal know about the wrap. If the terminal doesn't |
| 5691 | * auto-wrap, we overwrite the character. */ |
| 5692 | if (screen_cur_col != W_WIDTH(wp)) |
| 5693 | screen_char(LineOffset[screen_row - 1] |
| 5694 | + (unsigned)Columns - 1, |
| 5695 | screen_row - 1, (int)(Columns - 1)); |
| 5696 | |
| 5697 | #ifdef FEAT_MBYTE |
| 5698 | /* When there is a multi-byte character, just output a |
| 5699 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5700 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5701 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5702 | out_char(' '); |
| 5703 | else |
| 5704 | #endif |
| 5705 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5706 | + (Columns - 1)]); |
| 5707 | /* force a redraw of the first char on the next line */ |
| 5708 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5709 | screen_start(); /* don't know where cursor is now */ |
| 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | col = 0; |
| 5714 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5715 | #ifdef FEAT_RIGHTLEFT |
| 5716 | if (wp->w_p_rl) |
| 5717 | { |
| 5718 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5719 | off += col; |
| 5720 | } |
| 5721 | #endif |
| 5722 | |
| 5723 | /* reset the drawing state for the start of a wrapped line */ |
| 5724 | draw_state = WL_START; |
| 5725 | saved_n_extra = n_extra; |
| 5726 | saved_p_extra = p_extra; |
| 5727 | saved_c_extra = c_extra; |
| 5728 | saved_char_attr = char_attr; |
| 5729 | n_extra = 0; |
| 5730 | lcs_prec_todo = lcs_prec; |
| 5731 | #ifdef FEAT_LINEBREAK |
| 5732 | # ifdef FEAT_DIFF |
| 5733 | if (filler_todo <= 0) |
| 5734 | # endif |
| 5735 | need_showbreak = TRUE; |
| 5736 | #endif |
| 5737 | #ifdef FEAT_DIFF |
| 5738 | --filler_todo; |
| 5739 | /* When the filler lines are actually below the last line of the |
| 5740 | * file, don't draw the line itself, break here. */ |
| 5741 | if (filler_todo == 0 && wp->w_botfill) |
| 5742 | break; |
| 5743 | #endif |
| 5744 | } |
| 5745 | |
| 5746 | } /* for every character in the line */ |
| 5747 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5748 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5749 | /* After an empty line check first word for capital. */ |
| 5750 | if (*skipwhite(line) == NUL) |
| 5751 | { |
| 5752 | capcol_lnum = lnum + 1; |
| 5753 | cap_col = 0; |
| 5754 | } |
| 5755 | #endif |
| 5756 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5757 | return row; |
| 5758 | } |
| 5759 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5760 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 5761 | static int comp_char_differs(int, int); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5762 | |
| 5763 | /* |
| 5764 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5765 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5766 | */ |
| 5767 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5768 | comp_char_differs(int off_from, int off_to) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5769 | { |
| 5770 | int i; |
| 5771 | |
| 5772 | for (i = 0; i < Screen_mco; ++i) |
| 5773 | { |
| 5774 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5775 | return TRUE; |
| 5776 | if (ScreenLinesC[i][off_from] == 0) |
| 5777 | break; |
| 5778 | } |
| 5779 | return FALSE; |
| 5780 | } |
| 5781 | #endif |
| 5782 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5783 | /* |
| 5784 | * Check whether the given character needs redrawing: |
| 5785 | * - the (first byte of the) character is different |
| 5786 | * - the attributes are different |
| 5787 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5788 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5789 | */ |
| 5790 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5791 | char_needs_redraw(int off_from, int off_to, int cols) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5792 | { |
| 5793 | if (cols > 0 |
| 5794 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5795 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5796 | |
| 5797 | #ifdef FEAT_MBYTE |
| 5798 | || (enc_dbcs != 0 |
| 5799 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5800 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5801 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5802 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5803 | != ScreenLines[off_to + 1]))) |
| 5804 | || (enc_utf8 |
| 5805 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5806 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5807 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5808 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5809 | && ScreenLines[off_from + 1] |
| 5810 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5811 | #endif |
| 5812 | )) |
| 5813 | return TRUE; |
| 5814 | return FALSE; |
| 5815 | } |
| 5816 | |
| 5817 | /* |
| 5818 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5819 | * have actually changed. Handle insert/delete character. |
| 5820 | * "coloff" gives the first column on the screen for this line. |
| 5821 | * "endcol" gives the columns where valid characters are. |
| 5822 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5823 | * needs to be cleared, negative otherwise. |
| 5824 | * "rlflag" is TRUE in a rightleft window: |
| 5825 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5826 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5827 | */ |
| 5828 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5829 | screen_line( |
| 5830 | int row, |
| 5831 | int coloff, |
| 5832 | int endcol, |
| 5833 | int clear_width |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5834 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5835 | , int rlflag |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5836 | #endif |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5837 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5838 | { |
| 5839 | unsigned off_from; |
| 5840 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5841 | #ifdef FEAT_MBYTE |
| 5842 | unsigned max_off_from; |
| 5843 | unsigned max_off_to; |
| 5844 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5845 | int col = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5846 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5847 | int hl; |
| 5848 | #endif |
| 5849 | int force = FALSE; /* force update rest of the line */ |
| 5850 | int redraw_this /* bool: does character need redraw? */ |
| 5851 | #ifdef FEAT_GUI |
| 5852 | = TRUE /* For GUI when while-loop empty */ |
| 5853 | #endif |
| 5854 | ; |
| 5855 | int redraw_next; /* redraw_this for next character */ |
| 5856 | #ifdef FEAT_MBYTE |
| 5857 | int clear_next = FALSE; |
| 5858 | int char_cells; /* 1: normal char */ |
| 5859 | /* 2: occupies two display cells */ |
| 5860 | # define CHAR_CELLS char_cells |
| 5861 | #else |
| 5862 | # define CHAR_CELLS 1 |
| 5863 | #endif |
| 5864 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5865 | /* Check for illegal row and col, just in case. */ |
| 5866 | if (row >= Rows) |
| 5867 | row = Rows - 1; |
| 5868 | if (endcol > Columns) |
| 5869 | endcol = Columns; |
| 5870 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5871 | # ifdef FEAT_CLIPBOARD |
| 5872 | clip_may_clear_selection(row, row); |
| 5873 | # endif |
| 5874 | |
| 5875 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5876 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5877 | #ifdef FEAT_MBYTE |
| 5878 | max_off_from = off_from + screen_Columns; |
| 5879 | max_off_to = LineOffset[row] + screen_Columns; |
| 5880 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5881 | |
| 5882 | #ifdef FEAT_RIGHTLEFT |
| 5883 | if (rlflag) |
| 5884 | { |
| 5885 | /* Clear rest first, because it's left of the text. */ |
| 5886 | if (clear_width > 0) |
| 5887 | { |
| 5888 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5889 | && ScreenAttrs[off_to] == 0 |
| 5890 | # ifdef FEAT_MBYTE |
| 5891 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5892 | # endif |
| 5893 | ) |
| 5894 | { |
| 5895 | ++off_to; |
| 5896 | ++col; |
| 5897 | } |
| 5898 | if (col <= endcol) |
| 5899 | screen_fill(row, row + 1, col + coloff, |
| 5900 | endcol + coloff + 1, ' ', ' ', 0); |
| 5901 | } |
| 5902 | col = endcol + 1; |
| 5903 | off_to = LineOffset[row] + col + coloff; |
| 5904 | off_from += col; |
| 5905 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5906 | } |
| 5907 | #endif /* FEAT_RIGHTLEFT */ |
| 5908 | |
| 5909 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5910 | |
| 5911 | while (col < endcol) |
| 5912 | { |
| 5913 | #ifdef FEAT_MBYTE |
| 5914 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5915 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5916 | else |
| 5917 | char_cells = 1; |
| 5918 | #endif |
| 5919 | |
| 5920 | redraw_this = redraw_next; |
| 5921 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5922 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5923 | |
| 5924 | #ifdef FEAT_GUI |
| 5925 | /* If the next character was bold, then redraw the current character to |
| 5926 | * remove any pixels that might have spilt over into us. This only |
| 5927 | * happens in the GUI. |
| 5928 | */ |
| 5929 | if (redraw_next && gui.in_use) |
| 5930 | { |
| 5931 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5932 | if (hl > HL_ALL) |
| 5933 | hl = syn_attr2attr(hl); |
| 5934 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5935 | redraw_this = TRUE; |
| 5936 | } |
| 5937 | #endif |
| 5938 | |
| 5939 | if (redraw_this) |
| 5940 | { |
| 5941 | /* |
| 5942 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5943 | * Attributes for characters are stored at the position where the |
| 5944 | * cursor is when writing the highlighting code. The |
| 5945 | * start-highlighting code must be written with the cursor on the |
| 5946 | * first highlighted character. The stop-highlighting code must |
| 5947 | * be written with the cursor just after the last highlighted |
| 5948 | * character. |
| 5949 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5950 | * to clear the rest of the line, and force redrawing it |
| 5951 | * completely. |
| 5952 | */ |
| 5953 | if ( p_wiv |
| 5954 | && !force |
| 5955 | #ifdef FEAT_GUI |
| 5956 | && !gui.in_use |
| 5957 | #endif |
| 5958 | && ScreenAttrs[off_to] != 0 |
| 5959 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5960 | { |
| 5961 | /* |
| 5962 | * Need to remove highlighting attributes here. |
| 5963 | */ |
| 5964 | windgoto(row, col + coloff); |
| 5965 | out_str(T_CE); /* clear rest of this screen line */ |
| 5966 | screen_start(); /* don't know where cursor is now */ |
| 5967 | force = TRUE; /* force redraw of rest of the line */ |
| 5968 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5969 | |
| 5970 | /* |
| 5971 | * If the previous character was highlighted, need to stop |
| 5972 | * highlighting at this character. |
| 5973 | */ |
| 5974 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5975 | { |
| 5976 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5977 | term_windgoto(row, col + coloff); |
| 5978 | screen_stop_highlight(); |
| 5979 | } |
| 5980 | else |
| 5981 | screen_attr = 0; /* highlighting has stopped */ |
| 5982 | } |
| 5983 | #ifdef FEAT_MBYTE |
| 5984 | if (enc_dbcs != 0) |
| 5985 | { |
| 5986 | /* Check if overwriting a double-byte with a single-byte or |
| 5987 | * the other way around requires another character to be |
| 5988 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5989 | * ScreenLinesUC[] is sufficient. */ |
| 5990 | if (char_cells == 1 |
| 5991 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5992 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5993 | { |
| 5994 | /* Writing a single-cell character over a double-cell |
| 5995 | * character: need to redraw the next cell. */ |
| 5996 | ScreenLines[off_to + 1] = 0; |
| 5997 | redraw_next = TRUE; |
| 5998 | } |
| 5999 | else if (char_cells == 2 |
| 6000 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6001 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6002 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6003 | { |
| 6004 | /* Writing the second half of a double-cell character over |
| 6005 | * a double-cell character: need to redraw the second |
| 6006 | * cell. */ |
| 6007 | ScreenLines[off_to + 2] = 0; |
| 6008 | redraw_next = TRUE; |
| 6009 | } |
| 6010 | |
| 6011 | if (enc_dbcs == DBCS_JPNU) |
| 6012 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 6013 | } |
| 6014 | /* When writing a single-width character over a double-width |
| 6015 | * character and at the end of the redrawn text, need to clear out |
| 6016 | * the right halve of the old character. |
| 6017 | * Also required when writing the right halve of a double-width |
| 6018 | * char over the left halve of an existing one. */ |
| 6019 | if (has_mbyte && col + char_cells == endcol |
| 6020 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6021 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6022 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6023 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6024 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6025 | clear_next = TRUE; |
| 6026 | #endif |
| 6027 | |
| 6028 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 6029 | #ifdef FEAT_MBYTE |
| 6030 | if (enc_utf8) |
| 6031 | { |
| 6032 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 6033 | if (ScreenLinesUC[off_from] != 0) |
| 6034 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6035 | int i; |
| 6036 | |
| 6037 | for (i = 0; i < Screen_mco; ++i) |
| 6038 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | if (char_cells == 2) |
| 6042 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 6043 | #endif |
| 6044 | |
| 6045 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6046 | /* The bold trick makes a single column of pixels appear in the |
| 6047 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6048 | * character should be redrawn too. This happens for our own GUI |
| 6049 | * and for some xterms. */ |
| 6050 | if ( |
| 6051 | # ifdef FEAT_GUI |
| 6052 | gui.in_use |
| 6053 | # endif |
| 6054 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6055 | || |
| 6056 | # endif |
| 6057 | # ifdef UNIX |
| 6058 | term_is_xterm |
| 6059 | # endif |
| 6060 | ) |
| 6061 | { |
| 6062 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 6063 | if (hl > HL_ALL) |
| 6064 | hl = syn_attr2attr(hl); |
| 6065 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6066 | redraw_next = TRUE; |
| 6067 | } |
| 6068 | #endif |
| 6069 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 6070 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6071 | /* For simplicity set the attributes of second half of a |
| 6072 | * double-wide character equal to the first half. */ |
| 6073 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6074 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6075 | |
| 6076 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6077 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6078 | else |
| 6079 | #endif |
| 6080 | screen_char(off_to, row, col + coloff); |
| 6081 | } |
| 6082 | else if ( p_wiv |
| 6083 | #ifdef FEAT_GUI |
| 6084 | && !gui.in_use |
| 6085 | #endif |
| 6086 | && col + coloff > 0) |
| 6087 | { |
| 6088 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 6089 | { |
| 6090 | /* |
| 6091 | * Don't output stop-highlight when moving the cursor, it will |
| 6092 | * stop the highlighting when it should continue. |
| 6093 | */ |
| 6094 | screen_attr = 0; |
| 6095 | } |
| 6096 | else if (screen_attr != 0) |
| 6097 | screen_stop_highlight(); |
| 6098 | } |
| 6099 | |
| 6100 | off_to += CHAR_CELLS; |
| 6101 | off_from += CHAR_CELLS; |
| 6102 | col += CHAR_CELLS; |
| 6103 | } |
| 6104 | |
| 6105 | #ifdef FEAT_MBYTE |
| 6106 | if (clear_next) |
| 6107 | { |
| 6108 | /* Clear the second half of a double-wide character of which the left |
| 6109 | * half was overwritten with a single-wide character. */ |
| 6110 | ScreenLines[off_to] = ' '; |
| 6111 | if (enc_utf8) |
| 6112 | ScreenLinesUC[off_to] = 0; |
| 6113 | screen_char(off_to, row, col + coloff); |
| 6114 | } |
| 6115 | #endif |
| 6116 | |
| 6117 | if (clear_width > 0 |
| 6118 | #ifdef FEAT_RIGHTLEFT |
| 6119 | && !rlflag |
| 6120 | #endif |
| 6121 | ) |
| 6122 | { |
| 6123 | #ifdef FEAT_GUI |
| 6124 | int startCol = col; |
| 6125 | #endif |
| 6126 | |
| 6127 | /* blank out the rest of the line */ |
| 6128 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 6129 | && ScreenAttrs[off_to] == 0 |
| 6130 | #ifdef FEAT_MBYTE |
| 6131 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 6132 | #endif |
| 6133 | ) |
| 6134 | { |
| 6135 | ++off_to; |
| 6136 | ++col; |
| 6137 | } |
| 6138 | if (col < clear_width) |
| 6139 | { |
| 6140 | #ifdef FEAT_GUI |
| 6141 | /* |
| 6142 | * In the GUI, clearing the rest of the line may leave pixels |
| 6143 | * behind if the first character cleared was bold. Some bold |
| 6144 | * fonts spill over the left. In this case we redraw the previous |
| 6145 | * character too. If we didn't skip any blanks above, then we |
| 6146 | * only redraw if the character wasn't already redrawn anyway. |
| 6147 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6148 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6149 | { |
| 6150 | hl = ScreenAttrs[off_to]; |
| 6151 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6152 | { |
| 6153 | int prev_cells = 1; |
| 6154 | # ifdef FEAT_MBYTE |
| 6155 | if (enc_utf8) |
| 6156 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 6157 | * that its width is 2. */ |
| 6158 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 6159 | else if (enc_dbcs != 0) |
| 6160 | { |
| 6161 | /* find previous character by counting from first |
| 6162 | * column and get its width. */ |
| 6163 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6164 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6165 | |
| 6166 | while (off < off_to) |
| 6167 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6168 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6169 | off += prev_cells; |
| 6170 | } |
| 6171 | } |
| 6172 | |
| 6173 | if (enc_dbcs != 0 && prev_cells > 1) |
| 6174 | screen_char_2(off_to - prev_cells, row, |
| 6175 | col + coloff - prev_cells); |
| 6176 | else |
| 6177 | # endif |
| 6178 | screen_char(off_to - prev_cells, row, |
| 6179 | col + coloff - prev_cells); |
| 6180 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6181 | } |
| 6182 | #endif |
| 6183 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 6184 | ' ', ' ', 0); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6185 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6186 | off_to += clear_width - col; |
| 6187 | col = clear_width; |
| 6188 | #endif |
| 6189 | } |
| 6190 | } |
| 6191 | |
| 6192 | if (clear_width > 0) |
| 6193 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6194 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6195 | /* For a window that's left of another, draw the separator char. */ |
| 6196 | if (col + coloff < Columns) |
| 6197 | { |
| 6198 | int c; |
| 6199 | |
| 6200 | c = fillchar_vsep(&hl); |
Bram Moolenaar | c60c4f6 | 2015-01-07 19:04:28 +0100 | [diff] [blame] | 6201 | if (ScreenLines[off_to] != (schar_T)c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6202 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6203 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 6204 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6205 | # endif |
| 6206 | || ScreenAttrs[off_to] != hl) |
| 6207 | { |
| 6208 | ScreenLines[off_to] = c; |
| 6209 | ScreenAttrs[off_to] = hl; |
| 6210 | # ifdef FEAT_MBYTE |
| 6211 | if (enc_utf8) |
| 6212 | { |
| 6213 | if (c >= 0x80) |
| 6214 | { |
| 6215 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6216 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6217 | } |
| 6218 | else |
| 6219 | ScreenLinesUC[off_to] = 0; |
| 6220 | } |
| 6221 | # endif |
| 6222 | screen_char(off_to, row, col + coloff); |
| 6223 | } |
| 6224 | } |
| 6225 | else |
| 6226 | #endif |
| 6227 | LineWraps[row] = FALSE; |
| 6228 | } |
| 6229 | } |
| 6230 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6231 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6232 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6233 | * Mirror text "str" for right-left displaying. |
| 6234 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6235 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6236 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6237 | rl_mirror(char_u *str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6238 | { |
| 6239 | char_u *p1, *p2; |
| 6240 | int t; |
| 6241 | |
| 6242 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 6243 | { |
| 6244 | t = *p1; |
| 6245 | *p1 = *p2; |
| 6246 | *p2 = t; |
| 6247 | } |
| 6248 | } |
| 6249 | #endif |
| 6250 | |
| 6251 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6252 | /* |
| 6253 | * mark all status lines for redraw; used after first :cd |
| 6254 | */ |
| 6255 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6256 | status_redraw_all(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6257 | { |
| 6258 | win_T *wp; |
| 6259 | |
| 6260 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6261 | if (wp->w_status_height) |
| 6262 | { |
| 6263 | wp->w_redr_status = TRUE; |
| 6264 | redraw_later(VALID); |
| 6265 | } |
| 6266 | } |
| 6267 | |
| 6268 | /* |
| 6269 | * mark all status lines of the current buffer for redraw |
| 6270 | */ |
| 6271 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6272 | status_redraw_curbuf(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6273 | { |
| 6274 | win_T *wp; |
| 6275 | |
| 6276 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6277 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 6278 | { |
| 6279 | wp->w_redr_status = TRUE; |
| 6280 | redraw_later(VALID); |
| 6281 | } |
| 6282 | } |
| 6283 | |
| 6284 | /* |
| 6285 | * Redraw all status lines that need to be redrawn. |
| 6286 | */ |
| 6287 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6288 | redraw_statuslines(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6289 | { |
| 6290 | win_T *wp; |
| 6291 | |
| 6292 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6293 | if (wp->w_redr_status) |
| 6294 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 6295 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6296 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6297 | } |
| 6298 | #endif |
| 6299 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6300 | #if (defined(FEAT_WILDMENU) && defined(FEAT_WINDOWS)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6301 | /* |
| 6302 | * Redraw all status lines at the bottom of frame "frp". |
| 6303 | */ |
| 6304 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6305 | win_redraw_last_status(frame_T *frp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6306 | { |
| 6307 | if (frp->fr_layout == FR_LEAF) |
| 6308 | frp->fr_win->w_redr_status = TRUE; |
| 6309 | else if (frp->fr_layout == FR_ROW) |
| 6310 | { |
| 6311 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 6312 | win_redraw_last_status(frp); |
| 6313 | } |
| 6314 | else /* frp->fr_layout == FR_COL */ |
| 6315 | { |
| 6316 | frp = frp->fr_child; |
| 6317 | while (frp->fr_next != NULL) |
| 6318 | frp = frp->fr_next; |
| 6319 | win_redraw_last_status(frp); |
| 6320 | } |
| 6321 | } |
| 6322 | #endif |
| 6323 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6324 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6325 | /* |
| 6326 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 6327 | */ |
| 6328 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6329 | draw_vsep_win(win_T *wp, int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6330 | { |
| 6331 | int hl; |
| 6332 | int c; |
| 6333 | |
| 6334 | if (wp->w_vsep_width) |
| 6335 | { |
| 6336 | /* draw the vertical separator right of this window */ |
| 6337 | c = fillchar_vsep(&hl); |
| 6338 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 6339 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 6340 | c, ' ', hl); |
| 6341 | } |
| 6342 | } |
| 6343 | #endif |
| 6344 | |
| 6345 | #ifdef FEAT_WILDMENU |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 6346 | static int status_match_len(expand_T *xp, char_u *s); |
| 6347 | static int skip_status_match_char(expand_T *xp, char_u *s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6348 | |
| 6349 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6350 | * 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] | 6351 | */ |
| 6352 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6353 | status_match_len(expand_T *xp, char_u *s) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6354 | { |
| 6355 | int len = 0; |
| 6356 | |
| 6357 | #ifdef FEAT_MENU |
| 6358 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 6359 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6360 | |
| 6361 | /* Check for menu separators - replace with '|'. */ |
| 6362 | if (emenu && menu_is_separator(s)) |
| 6363 | return 1; |
| 6364 | #endif |
| 6365 | |
| 6366 | while (*s != NUL) |
| 6367 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6368 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 6369 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6370 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | return len; |
| 6374 | } |
| 6375 | |
| 6376 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6377 | * Return the number of characters that should be skipped in a status match. |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6378 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 6379 | */ |
| 6380 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6381 | skip_status_match_char(expand_T *xp, char_u *s) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6382 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6383 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6384 | #ifdef FEAT_MENU |
| 6385 | || ((xp->xp_context == EXPAND_MENUS |
| 6386 | || xp->xp_context == EXPAND_MENUNAMES) |
| 6387 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 6388 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6389 | ) |
| 6390 | { |
| 6391 | #ifndef BACKSLASH_IN_FILENAME |
| 6392 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 6393 | return 2; |
| 6394 | #endif |
| 6395 | return 1; |
| 6396 | } |
| 6397 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6401 | * Show wildchar matches in the status line. |
| 6402 | * Show at least the "match" item. |
| 6403 | * We start at item 'first_match' in the list and show all matches that fit. |
| 6404 | * |
| 6405 | * If inversion is possible we use it. Else '=' characters are used. |
| 6406 | */ |
| 6407 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6408 | win_redr_status_matches( |
| 6409 | expand_T *xp, |
| 6410 | int num_matches, |
| 6411 | char_u **matches, /* list of matches */ |
| 6412 | int match, |
| 6413 | int showtail) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6414 | { |
| 6415 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6416 | int row; |
| 6417 | char_u *buf; |
| 6418 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6419 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6420 | int fillchar; |
| 6421 | int attr; |
| 6422 | int i; |
| 6423 | int highlight = TRUE; |
| 6424 | char_u *selstart = NULL; |
| 6425 | int selstart_col = 0; |
| 6426 | char_u *selend = NULL; |
| 6427 | static int first_match = 0; |
| 6428 | int add_left = FALSE; |
| 6429 | char_u *s; |
| 6430 | #ifdef FEAT_MENU |
| 6431 | int emenu; |
| 6432 | #endif |
| 6433 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6434 | int l; |
| 6435 | #endif |
| 6436 | |
| 6437 | if (matches == NULL) /* interrupted completion? */ |
| 6438 | return; |
| 6439 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6440 | #ifdef FEAT_MBYTE |
| 6441 | if (has_mbyte) |
| 6442 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6443 | else |
| 6444 | #endif |
| 6445 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6446 | if (buf == NULL) |
| 6447 | return; |
| 6448 | |
| 6449 | if (match == -1) /* don't show match but original text */ |
| 6450 | { |
| 6451 | match = 0; |
| 6452 | highlight = FALSE; |
| 6453 | } |
| 6454 | /* count 1 for the ending ">" */ |
| 6455 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6456 | if (match == 0) |
| 6457 | first_match = 0; |
| 6458 | else if (match < first_match) |
| 6459 | { |
| 6460 | /* jumping left, as far as we can go */ |
| 6461 | first_match = match; |
| 6462 | add_left = TRUE; |
| 6463 | } |
| 6464 | else |
| 6465 | { |
| 6466 | /* check if match fits on the screen */ |
| 6467 | for (i = first_match; i < match; ++i) |
| 6468 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6469 | if (first_match > 0) |
| 6470 | clen += 2; |
| 6471 | /* jumping right, put match at the left */ |
| 6472 | if ((long)clen > Columns) |
| 6473 | { |
| 6474 | first_match = match; |
| 6475 | /* if showing the last match, we can add some on the left */ |
| 6476 | clen = 2; |
| 6477 | for (i = match; i < num_matches; ++i) |
| 6478 | { |
| 6479 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6480 | if ((long)clen >= Columns) |
| 6481 | break; |
| 6482 | } |
| 6483 | if (i == num_matches) |
| 6484 | add_left = TRUE; |
| 6485 | } |
| 6486 | } |
| 6487 | if (add_left) |
| 6488 | while (first_match > 0) |
| 6489 | { |
| 6490 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6491 | if ((long)clen >= Columns) |
| 6492 | break; |
| 6493 | --first_match; |
| 6494 | } |
| 6495 | |
| 6496 | fillchar = fillchar_status(&attr, TRUE); |
| 6497 | |
| 6498 | if (first_match == 0) |
| 6499 | { |
| 6500 | *buf = NUL; |
| 6501 | len = 0; |
| 6502 | } |
| 6503 | else |
| 6504 | { |
| 6505 | STRCPY(buf, "< "); |
| 6506 | len = 2; |
| 6507 | } |
| 6508 | clen = len; |
| 6509 | |
| 6510 | i = first_match; |
| 6511 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6512 | { |
| 6513 | if (i == match) |
| 6514 | { |
| 6515 | selstart = buf + len; |
| 6516 | selstart_col = clen; |
| 6517 | } |
| 6518 | |
| 6519 | s = L_MATCH(i); |
| 6520 | /* Check for menu separators - replace with '|' */ |
| 6521 | #ifdef FEAT_MENU |
| 6522 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6523 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6524 | if (emenu && menu_is_separator(s)) |
| 6525 | { |
| 6526 | STRCPY(buf + len, transchar('|')); |
| 6527 | l = (int)STRLEN(buf + len); |
| 6528 | len += l; |
| 6529 | clen += l; |
| 6530 | } |
| 6531 | else |
| 6532 | #endif |
| 6533 | for ( ; *s != NUL; ++s) |
| 6534 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6535 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6536 | clen += ptr2cells(s); |
| 6537 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6538 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6539 | { |
| 6540 | STRNCPY(buf + len, s, l); |
| 6541 | s += l - 1; |
| 6542 | len += l; |
| 6543 | } |
| 6544 | else |
| 6545 | #endif |
| 6546 | { |
| 6547 | STRCPY(buf + len, transchar_byte(*s)); |
| 6548 | len += (int)STRLEN(buf + len); |
| 6549 | } |
| 6550 | } |
| 6551 | if (i == match) |
| 6552 | selend = buf + len; |
| 6553 | |
| 6554 | *(buf + len++) = ' '; |
| 6555 | *(buf + len++) = ' '; |
| 6556 | clen += 2; |
| 6557 | if (++i == num_matches) |
| 6558 | break; |
| 6559 | } |
| 6560 | |
| 6561 | if (i != num_matches) |
| 6562 | { |
| 6563 | *(buf + len++) = '>'; |
| 6564 | ++clen; |
| 6565 | } |
| 6566 | |
| 6567 | buf[len] = NUL; |
| 6568 | |
| 6569 | row = cmdline_row - 1; |
| 6570 | if (row >= 0) |
| 6571 | { |
| 6572 | if (wild_menu_showing == 0) |
| 6573 | { |
| 6574 | if (msg_scrolled > 0) |
| 6575 | { |
| 6576 | /* Put the wildmenu just above the command line. If there is |
| 6577 | * no room, scroll the screen one line up. */ |
| 6578 | if (cmdline_row == Rows - 1) |
| 6579 | { |
| 6580 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6581 | ++msg_scrolled; |
| 6582 | } |
| 6583 | else |
| 6584 | { |
| 6585 | ++cmdline_row; |
| 6586 | ++row; |
| 6587 | } |
| 6588 | wild_menu_showing = WM_SCROLLED; |
| 6589 | } |
| 6590 | else |
| 6591 | { |
| 6592 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6593 | * Set 'winminheight' to zero to avoid that the window is |
| 6594 | * resized. */ |
| 6595 | if (lastwin->w_status_height == 0) |
| 6596 | { |
| 6597 | save_p_ls = p_ls; |
| 6598 | save_p_wmh = p_wmh; |
| 6599 | p_ls = 2; |
| 6600 | p_wmh = 0; |
| 6601 | last_status(FALSE); |
| 6602 | } |
| 6603 | wild_menu_showing = WM_SHOWN; |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | screen_puts(buf, row, 0, attr); |
| 6608 | if (selstart != NULL && highlight) |
| 6609 | { |
| 6610 | *selend = NUL; |
| 6611 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6612 | } |
| 6613 | |
| 6614 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6615 | } |
| 6616 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6617 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6618 | win_redraw_last_status(topframe); |
| 6619 | #else |
| 6620 | lastwin->w_redr_status = TRUE; |
| 6621 | #endif |
| 6622 | vim_free(buf); |
| 6623 | } |
| 6624 | #endif |
| 6625 | |
| 6626 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6627 | /* |
| 6628 | * Redraw the status line of window wp. |
| 6629 | * |
| 6630 | * If inversion is possible we use it. Else '=' characters are used. |
| 6631 | */ |
| 6632 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6633 | win_redr_status(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6634 | { |
| 6635 | int row; |
| 6636 | char_u *p; |
| 6637 | int len; |
| 6638 | int fillchar; |
| 6639 | int attr; |
| 6640 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6641 | static int busy = FALSE; |
| 6642 | |
| 6643 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6644 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6645 | if (busy) |
| 6646 | return; |
| 6647 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6648 | |
| 6649 | wp->w_redr_status = FALSE; |
| 6650 | if (wp->w_status_height == 0) |
| 6651 | { |
| 6652 | /* no status line, can only be last window */ |
| 6653 | redraw_cmdline = TRUE; |
| 6654 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6655 | else if (!redrawing() |
| 6656 | #ifdef FEAT_INS_EXPAND |
| 6657 | /* don't update status line when popup menu is visible and may be |
| 6658 | * drawn over it */ |
| 6659 | || pum_visible() |
| 6660 | #endif |
| 6661 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6662 | { |
| 6663 | /* Don't redraw right now, do it later. */ |
| 6664 | wp->w_redr_status = TRUE; |
| 6665 | } |
| 6666 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6667 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6668 | { |
| 6669 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6670 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6671 | } |
| 6672 | #endif |
| 6673 | else |
| 6674 | { |
| 6675 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6676 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6677 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6678 | p = NameBuff; |
| 6679 | len = (int)STRLEN(p); |
| 6680 | |
| 6681 | if (wp->w_buffer->b_help |
| 6682 | #ifdef FEAT_QUICKFIX |
| 6683 | || wp->w_p_pvw |
| 6684 | #endif |
| 6685 | || bufIsChanged(wp->w_buffer) |
| 6686 | || wp->w_buffer->b_p_ro) |
| 6687 | *(p + len++) = ' '; |
| 6688 | if (wp->w_buffer->b_help) |
| 6689 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6690 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6691 | len += (int)STRLEN(p + len); |
| 6692 | } |
| 6693 | #ifdef FEAT_QUICKFIX |
| 6694 | if (wp->w_p_pvw) |
| 6695 | { |
| 6696 | STRCPY(p + len, _("[Preview]")); |
| 6697 | len += (int)STRLEN(p + len); |
| 6698 | } |
| 6699 | #endif |
| 6700 | if (bufIsChanged(wp->w_buffer)) |
| 6701 | { |
| 6702 | STRCPY(p + len, "[+]"); |
| 6703 | len += 3; |
| 6704 | } |
| 6705 | if (wp->w_buffer->b_p_ro) |
| 6706 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6707 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6708 | len += 4; |
| 6709 | } |
| 6710 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6711 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6712 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6713 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6714 | if (this_ru_col <= 1) |
| 6715 | { |
| 6716 | p = (char_u *)"<"; /* No room for file name! */ |
| 6717 | len = 1; |
| 6718 | } |
| 6719 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6720 | #ifdef FEAT_MBYTE |
| 6721 | if (has_mbyte) |
| 6722 | { |
| 6723 | int clen = 0, i; |
| 6724 | |
| 6725 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6726 | clen = mb_string2cells(p, -1); |
| 6727 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6728 | /* Find first character that will fit. |
| 6729 | * Going from start to end is much faster for DBCS. */ |
| 6730 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6731 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6732 | clen -= (*mb_ptr2cells)(p + i); |
| 6733 | len = clen; |
| 6734 | if (i > 0) |
| 6735 | { |
| 6736 | p = p + i - 1; |
| 6737 | *p = '<'; |
| 6738 | ++len; |
| 6739 | } |
| 6740 | |
| 6741 | } |
| 6742 | else |
| 6743 | #endif |
| 6744 | if (len > this_ru_col - 1) |
| 6745 | { |
| 6746 | p += len - (this_ru_col - 1); |
| 6747 | *p = '<'; |
| 6748 | len = this_ru_col - 1; |
| 6749 | } |
| 6750 | |
| 6751 | row = W_WINROW(wp) + wp->w_height; |
| 6752 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6753 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6754 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6755 | |
| 6756 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 6757 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6758 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6759 | - 1 + W_WINCOL(wp)), attr); |
| 6760 | |
| 6761 | #ifdef FEAT_CMDL_INFO |
| 6762 | win_redr_ruler(wp, TRUE); |
| 6763 | #endif |
| 6764 | } |
| 6765 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6766 | /* |
| 6767 | * May need to draw the character below the vertical separator. |
| 6768 | */ |
| 6769 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6770 | { |
| 6771 | if (stl_connected(wp)) |
| 6772 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6773 | else |
| 6774 | fillchar = fillchar_vsep(&attr); |
| 6775 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6776 | attr); |
| 6777 | } |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6778 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6781 | #ifdef FEAT_STL_OPT |
| 6782 | /* |
| 6783 | * Redraw the status line according to 'statusline' and take care of any |
| 6784 | * errors encountered. |
| 6785 | */ |
| 6786 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6787 | redraw_custom_statusline(win_T *wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6788 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6789 | static int entered = FALSE; |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6790 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6791 | |
| 6792 | /* When called recursively return. This can happen when the statusline |
| 6793 | * contains an expression that triggers a redraw. */ |
| 6794 | if (entered) |
| 6795 | return; |
| 6796 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6797 | |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6798 | did_emsg = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6799 | win_redr_custom(wp, FALSE); |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6800 | if (did_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6801 | { |
| 6802 | /* When there is an error disable the statusline, otherwise the |
| 6803 | * display is messed up with errors and a redraw triggers the problem |
| 6804 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6805 | set_string_option_direct((char_u *)"statusline", -1, |
| 6806 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6807 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6808 | } |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6809 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6810 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6811 | } |
| 6812 | #endif |
| 6813 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6814 | /* |
| 6815 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6816 | * line of the window right of it. If not, then it's a vertical separator. |
| 6817 | * Only call if (wp->w_vsep_width != 0). |
| 6818 | */ |
| 6819 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6820 | stl_connected(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6821 | { |
| 6822 | frame_T *fr; |
| 6823 | |
| 6824 | fr = wp->w_frame; |
| 6825 | while (fr->fr_parent != NULL) |
| 6826 | { |
| 6827 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6828 | { |
| 6829 | if (fr->fr_next != NULL) |
| 6830 | break; |
| 6831 | } |
| 6832 | else |
| 6833 | { |
| 6834 | if (fr->fr_next != NULL) |
| 6835 | return TRUE; |
| 6836 | } |
| 6837 | fr = fr->fr_parent; |
| 6838 | } |
| 6839 | return FALSE; |
| 6840 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6841 | |
| 6842 | #endif /* FEAT_WINDOWS */ |
| 6843 | |
| 6844 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6845 | /* |
| 6846 | * Get the value to show for the language mappings, active 'keymap'. |
| 6847 | */ |
| 6848 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6849 | get_keymap_str( |
| 6850 | win_T *wp, |
| 6851 | char_u *buf, /* buffer for the result */ |
| 6852 | int len) /* length of buffer */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6853 | { |
| 6854 | char_u *p; |
| 6855 | |
| 6856 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6857 | return FALSE; |
| 6858 | |
| 6859 | { |
| 6860 | #ifdef FEAT_EVAL |
| 6861 | buf_T *old_curbuf = curbuf; |
| 6862 | win_T *old_curwin = curwin; |
| 6863 | char_u *s; |
| 6864 | |
| 6865 | curbuf = wp->w_buffer; |
| 6866 | curwin = wp; |
| 6867 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6868 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6869 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6870 | --emsg_skip; |
| 6871 | curbuf = old_curbuf; |
| 6872 | curwin = old_curwin; |
| 6873 | if (p == NULL || *p == NUL) |
| 6874 | #endif |
| 6875 | { |
| 6876 | #ifdef FEAT_KEYMAP |
| 6877 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6878 | p = wp->w_buffer->b_p_keymap; |
| 6879 | else |
| 6880 | #endif |
| 6881 | p = (char_u *)"lang"; |
| 6882 | } |
| 6883 | if ((int)(STRLEN(p) + 3) < len) |
| 6884 | sprintf((char *)buf, "<%s>", p); |
| 6885 | else |
| 6886 | buf[0] = NUL; |
| 6887 | #ifdef FEAT_EVAL |
| 6888 | vim_free(s); |
| 6889 | #endif |
| 6890 | } |
| 6891 | return buf[0] != NUL; |
| 6892 | } |
| 6893 | #endif |
| 6894 | |
| 6895 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6896 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6897 | * Redraw the status line or ruler of window "wp". |
| 6898 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6899 | */ |
| 6900 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6901 | win_redr_custom( |
| 6902 | win_T *wp, |
| 6903 | int draw_ruler) /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6904 | { |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6905 | static int entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6906 | int attr; |
| 6907 | int curattr; |
| 6908 | int row; |
| 6909 | int col = 0; |
| 6910 | int maxwidth; |
| 6911 | int width; |
| 6912 | int n; |
| 6913 | int len; |
| 6914 | int fillchar; |
| 6915 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6916 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6917 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6918 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6919 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6920 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6921 | win_T *ewp; |
| 6922 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6923 | |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6924 | /* There is a tiny chance that this gets called recursively: When |
| 6925 | * redrawing a status line triggers redrawing the ruler or tabline. |
| 6926 | * Avoid trouble by not allowing recursion. */ |
| 6927 | if (entered) |
| 6928 | return; |
| 6929 | entered = TRUE; |
| 6930 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6931 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6932 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6933 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6934 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6935 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6936 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6937 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6938 | attr = hl_attr(HLF_TPF); |
| 6939 | maxwidth = Columns; |
| 6940 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6941 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6942 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6943 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6944 | else |
| 6945 | { |
| 6946 | row = W_WINROW(wp) + wp->w_height; |
| 6947 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6948 | maxwidth = W_WIDTH(wp); |
| 6949 | |
| 6950 | if (draw_ruler) |
| 6951 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6952 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6953 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6954 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6955 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6956 | if (*++stl == '-') |
| 6957 | stl++; |
| 6958 | if (atoi((char *)stl)) |
| 6959 | while (VIM_ISDIGIT(*stl)) |
| 6960 | stl++; |
| 6961 | if (*stl++ != '(') |
| 6962 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6963 | } |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6964 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6965 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6966 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6967 | col = (W_WIDTH(wp) + 1) / 2; |
| 6968 | #else |
| 6969 | col = ru_col; |
| 6970 | if (col > (Columns + 1) / 2) |
| 6971 | col = (Columns + 1) / 2; |
| 6972 | #endif |
| 6973 | maxwidth = W_WIDTH(wp) - col; |
| 6974 | #ifdef FEAT_WINDOWS |
| 6975 | if (!wp->w_status_height) |
| 6976 | #endif |
| 6977 | { |
| 6978 | row = Rows - 1; |
| 6979 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6980 | fillchar = ' '; |
| 6981 | attr = 0; |
| 6982 | } |
| 6983 | |
| 6984 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6985 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6986 | # endif |
| 6987 | } |
| 6988 | else |
| 6989 | { |
| 6990 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6991 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6992 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6993 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6994 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6995 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 6996 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6997 | # endif |
| 6998 | } |
| 6999 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 7000 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7001 | col += W_WINCOL(wp); |
| 7002 | #endif |
| 7003 | } |
| 7004 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7005 | if (maxwidth <= 0) |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7006 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7007 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7008 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 7009 | * the cursor away and back. */ |
| 7010 | ewp = wp == NULL ? curwin : wp; |
| 7011 | p_crb_save = ewp->w_p_crb; |
| 7012 | ewp->w_p_crb = FALSE; |
| 7013 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7014 | /* Make a copy, because the statusline may include a function call that |
| 7015 | * might change the option value and free the memory. */ |
| 7016 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7017 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7018 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7019 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7020 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7021 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7022 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 7023 | /* Make all characters printable. */ |
| 7024 | p = transstr(buf); |
| 7025 | if (p != NULL) |
| 7026 | { |
| 7027 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 7028 | vim_free(p); |
| 7029 | } |
| 7030 | |
| 7031 | /* fill up with "fillchar" */ |
| 7032 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 7033 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7034 | { |
| 7035 | #ifdef FEAT_MBYTE |
| 7036 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 7037 | #else |
| 7038 | buf[len++] = fillchar; |
| 7039 | #endif |
| 7040 | ++width; |
| 7041 | } |
| 7042 | buf[len] = NUL; |
| 7043 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7044 | /* |
| 7045 | * Draw each snippet with the specified highlighting. |
| 7046 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7047 | curattr = attr; |
| 7048 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7049 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7050 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7051 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7052 | screen_puts_len(p, len, row, col, curattr); |
| 7053 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7054 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7055 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7056 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7057 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7058 | else if (hltab[n].userhl < 0) |
| 7059 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7060 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 7061 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7062 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7063 | #endif |
| 7064 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7065 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7066 | } |
| 7067 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7068 | |
| 7069 | if (wp == NULL) |
| 7070 | { |
| 7071 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 7072 | col = 0; |
| 7073 | len = 0; |
| 7074 | p = buf; |
| 7075 | fillchar = 0; |
| 7076 | for (n = 0; tabtab[n].start != NULL; n++) |
| 7077 | { |
| 7078 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 7079 | while (col < len) |
| 7080 | TabPageIdxs[col++] = fillchar; |
| 7081 | p = tabtab[n].start; |
| 7082 | fillchar = tabtab[n].userhl; |
| 7083 | } |
| 7084 | while (col < Columns) |
| 7085 | TabPageIdxs[col++] = fillchar; |
| 7086 | } |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7087 | |
| 7088 | theend: |
| 7089 | entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | #endif /* FEAT_STL_OPT */ |
| 7093 | |
| 7094 | /* |
| 7095 | * Output a single character directly to the screen and update ScreenLines. |
| 7096 | */ |
| 7097 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7098 | screen_putchar(int c, int row, int col, int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7099 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7100 | char_u buf[MB_MAXBYTES + 1]; |
| 7101 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7102 | #ifdef FEAT_MBYTE |
| 7103 | if (has_mbyte) |
| 7104 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 7105 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7106 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7107 | { |
| 7108 | buf[0] = c; |
| 7109 | buf[1] = NUL; |
| 7110 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7111 | screen_puts(buf, row, col, attr); |
| 7112 | } |
| 7113 | |
| 7114 | /* |
| 7115 | * Get a single character directly from ScreenLines into "bytes[]". |
| 7116 | * Also return its attribute in *attrp; |
| 7117 | */ |
| 7118 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7119 | screen_getbytes(int row, int col, char_u *bytes, int *attrp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7120 | { |
| 7121 | unsigned off; |
| 7122 | |
| 7123 | /* safety check */ |
| 7124 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 7125 | { |
| 7126 | off = LineOffset[row] + col; |
| 7127 | *attrp = ScreenAttrs[off]; |
| 7128 | bytes[0] = ScreenLines[off]; |
| 7129 | bytes[1] = NUL; |
| 7130 | |
| 7131 | #ifdef FEAT_MBYTE |
| 7132 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7133 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 7134 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7135 | { |
| 7136 | bytes[0] = ScreenLines[off]; |
| 7137 | bytes[1] = ScreenLines2[off]; |
| 7138 | bytes[2] = NUL; |
| 7139 | } |
| 7140 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 7141 | { |
| 7142 | bytes[1] = ScreenLines[off + 1]; |
| 7143 | bytes[2] = NUL; |
| 7144 | } |
| 7145 | #endif |
| 7146 | } |
| 7147 | } |
| 7148 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7149 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 7150 | static int screen_comp_differs(int, int*); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7151 | |
| 7152 | /* |
| 7153 | * Return TRUE if composing characters for screen posn "off" differs from |
| 7154 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7155 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7156 | */ |
| 7157 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7158 | screen_comp_differs(int off, int *u8cc) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7159 | { |
| 7160 | int i; |
| 7161 | |
| 7162 | for (i = 0; i < Screen_mco; ++i) |
| 7163 | { |
| 7164 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 7165 | return TRUE; |
| 7166 | if (u8cc[i] == 0) |
| 7167 | break; |
| 7168 | } |
| 7169 | return FALSE; |
| 7170 | } |
| 7171 | #endif |
| 7172 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7173 | /* |
| 7174 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 7175 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 7176 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 7177 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 7178 | */ |
| 7179 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7180 | screen_puts( |
| 7181 | char_u *text, |
| 7182 | int row, |
| 7183 | int col, |
| 7184 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7185 | { |
| 7186 | screen_puts_len(text, -1, row, col, attr); |
| 7187 | } |
| 7188 | |
| 7189 | /* |
| 7190 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 7191 | * a NUL. |
| 7192 | */ |
| 7193 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7194 | screen_puts_len( |
| 7195 | char_u *text, |
| 7196 | int textlen, |
| 7197 | int row, |
| 7198 | int col, |
| 7199 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7200 | { |
| 7201 | unsigned off; |
| 7202 | char_u *ptr = text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7203 | int len = textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7204 | int c; |
| 7205 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7206 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7207 | int mbyte_blen = 1; |
| 7208 | int mbyte_cells = 1; |
| 7209 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7210 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7211 | int clear_next_cell = FALSE; |
| 7212 | # ifdef FEAT_ARABIC |
| 7213 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7214 | int pc, nc, nc1; |
| 7215 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7216 | # endif |
| 7217 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7218 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7219 | int force_redraw_this; |
| 7220 | int force_redraw_next = FALSE; |
| 7221 | #endif |
| 7222 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7223 | |
| 7224 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 7225 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7226 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7227 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7228 | #ifdef FEAT_MBYTE |
| 7229 | /* When drawing over the right halve of a double-wide char clear out the |
| 7230 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7231 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7232 | # ifdef FEAT_GUI |
| 7233 | && !gui.in_use |
| 7234 | # endif |
| 7235 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7236 | { |
| 7237 | ScreenLines[off - 1] = ' '; |
| 7238 | ScreenAttrs[off - 1] = 0; |
| 7239 | if (enc_utf8) |
| 7240 | { |
| 7241 | ScreenLinesUC[off - 1] = 0; |
| 7242 | ScreenLinesC[0][off - 1] = 0; |
| 7243 | } |
| 7244 | /* redraw the previous cell, make it empty */ |
| 7245 | screen_char(off - 1, row, col - 1); |
| 7246 | /* force the cell at "col" to be redrawn */ |
| 7247 | force_redraw_next = TRUE; |
| 7248 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7249 | #endif |
| 7250 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7251 | #ifdef FEAT_MBYTE |
| 7252 | max_off = LineOffset[row] + screen_Columns; |
| 7253 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 7254 | while (col < screen_Columns |
| 7255 | && (len < 0 || (int)(ptr - text) < len) |
| 7256 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7257 | { |
| 7258 | c = *ptr; |
| 7259 | #ifdef FEAT_MBYTE |
| 7260 | /* check if this is the first byte of a multibyte */ |
| 7261 | if (has_mbyte) |
| 7262 | { |
| 7263 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7264 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7265 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7266 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7267 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7268 | mbyte_cells = 1; |
| 7269 | else if (enc_dbcs != 0) |
| 7270 | mbyte_cells = mbyte_blen; |
| 7271 | else /* enc_utf8 */ |
| 7272 | { |
| 7273 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7274 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7275 | (int)((text + len) - ptr)); |
| 7276 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7277 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7278 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7279 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7280 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 7281 | if (u8c >= 0x10000) |
| 7282 | { |
| 7283 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 7284 | if (attr == 0) |
| 7285 | attr = hl_attr(HLF_8); |
| 7286 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7287 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | # ifdef FEAT_ARABIC |
| 7289 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 7290 | { |
| 7291 | /* Do Arabic shaping. */ |
| 7292 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 7293 | { |
| 7294 | /* Past end of string to be displayed. */ |
| 7295 | nc = NUL; |
| 7296 | nc1 = NUL; |
| 7297 | } |
| 7298 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7299 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 7300 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 7301 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7302 | nc1 = pcc[0]; |
| 7303 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7304 | pc = prev_c; |
| 7305 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7306 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7307 | } |
| 7308 | else |
| 7309 | prev_c = u8c; |
| 7310 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 7311 | if (col + mbyte_cells > screen_Columns) |
| 7312 | { |
| 7313 | /* Only 1 cell left, but character requires 2 cells: |
| 7314 | * display a '>' in the last column to avoid wrapping. */ |
| 7315 | c = '>'; |
| 7316 | mbyte_cells = 1; |
| 7317 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7318 | } |
| 7319 | } |
| 7320 | #endif |
| 7321 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7322 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7323 | force_redraw_this = force_redraw_next; |
| 7324 | force_redraw_next = FALSE; |
| 7325 | #endif |
| 7326 | |
| 7327 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7328 | #ifdef FEAT_MBYTE |
| 7329 | || (mbyte_cells == 2 |
| 7330 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 7331 | || (enc_dbcs == DBCS_JPNU |
| 7332 | && c == 0x8e |
| 7333 | && ScreenLines2[off] != ptr[1]) |
| 7334 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7335 | && (ScreenLinesUC[off] != |
| 7336 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 7337 | || (ScreenLinesUC[off] != 0 |
| 7338 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7339 | #endif |
| 7340 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7341 | || exmode_active; |
| 7342 | |
| 7343 | if (need_redraw |
| 7344 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7345 | || force_redraw_this |
| 7346 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7347 | ) |
| 7348 | { |
| 7349 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7350 | /* The bold trick makes a single row of pixels appear in the next |
| 7351 | * character. When a bold character is removed, the next |
| 7352 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7353 | * and for some xterms. */ |
| 7354 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7355 | # ifdef FEAT_GUI |
| 7356 | gui.in_use |
| 7357 | # endif |
| 7358 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7359 | || |
| 7360 | # endif |
| 7361 | # ifdef UNIX |
| 7362 | term_is_xterm |
| 7363 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7364 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7365 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7366 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7367 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7368 | if (n > HL_ALL) |
| 7369 | n = syn_attr2attr(n); |
| 7370 | if (n & HL_BOLD) |
| 7371 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7372 | } |
| 7373 | #endif |
| 7374 | #ifdef FEAT_MBYTE |
| 7375 | /* When at the end of the text and overwriting a two-cell |
| 7376 | * character with a one-cell character, need to clear the next |
| 7377 | * cell. Also when overwriting the left halve of a two-cell char |
| 7378 | * with the right halve of a two-cell char. Do this only once |
| 7379 | * (mb_off2cells() may return 2 on the right halve). */ |
| 7380 | if (clear_next_cell) |
| 7381 | clear_next_cell = FALSE; |
| 7382 | else if (has_mbyte |
| 7383 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 7384 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7385 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7386 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7387 | && (*mb_off2cells)(off, max_off) == 1 |
| 7388 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7389 | clear_next_cell = TRUE; |
| 7390 | |
| 7391 | /* Make sure we never leave a second byte of a double-byte behind, |
| 7392 | * it confuses mb_off2cells(). */ |
| 7393 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7394 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7395 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7396 | && (*mb_off2cells)(off, max_off) == 1 |
| 7397 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7398 | ScreenLines[off + mbyte_blen] = 0; |
| 7399 | #endif |
| 7400 | ScreenLines[off] = c; |
| 7401 | ScreenAttrs[off] = attr; |
| 7402 | #ifdef FEAT_MBYTE |
| 7403 | if (enc_utf8) |
| 7404 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7405 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7406 | ScreenLinesUC[off] = 0; |
| 7407 | else |
| 7408 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7409 | int i; |
| 7410 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7411 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7412 | for (i = 0; i < Screen_mco; ++i) |
| 7413 | { |
| 7414 | ScreenLinesC[i][off] = u8cc[i]; |
| 7415 | if (u8cc[i] == 0) |
| 7416 | break; |
| 7417 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7418 | } |
| 7419 | if (mbyte_cells == 2) |
| 7420 | { |
| 7421 | ScreenLines[off + 1] = 0; |
| 7422 | ScreenAttrs[off + 1] = attr; |
| 7423 | } |
| 7424 | screen_char(off, row, col); |
| 7425 | } |
| 7426 | else if (mbyte_cells == 2) |
| 7427 | { |
| 7428 | ScreenLines[off + 1] = ptr[1]; |
| 7429 | ScreenAttrs[off + 1] = attr; |
| 7430 | screen_char_2(off, row, col); |
| 7431 | } |
| 7432 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7433 | { |
| 7434 | ScreenLines2[off] = ptr[1]; |
| 7435 | screen_char(off, row, col); |
| 7436 | } |
| 7437 | else |
| 7438 | #endif |
| 7439 | screen_char(off, row, col); |
| 7440 | } |
| 7441 | #ifdef FEAT_MBYTE |
| 7442 | if (has_mbyte) |
| 7443 | { |
| 7444 | off += mbyte_cells; |
| 7445 | col += mbyte_cells; |
| 7446 | ptr += mbyte_blen; |
| 7447 | if (clear_next_cell) |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7448 | { |
| 7449 | /* This only happens at the end, display one space next. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7450 | ptr = (char_u *)" "; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7451 | len = -1; |
| 7452 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7453 | } |
| 7454 | else |
| 7455 | #endif |
| 7456 | { |
| 7457 | ++off; |
| 7458 | ++col; |
| 7459 | ++ptr; |
| 7460 | } |
| 7461 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7462 | |
| 7463 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7464 | /* If we detected the next character needs to be redrawn, but the text |
| 7465 | * doesn't extend up to there, update the character here. */ |
| 7466 | if (force_redraw_next && col < screen_Columns) |
| 7467 | { |
| 7468 | # ifdef FEAT_MBYTE |
| 7469 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7470 | screen_char_2(off, row, col); |
| 7471 | else |
| 7472 | # endif |
| 7473 | screen_char(off, row, col); |
| 7474 | } |
| 7475 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | #ifdef FEAT_SEARCH_EXTRA |
| 7479 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7480 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7481 | */ |
| 7482 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7483 | start_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7484 | { |
| 7485 | if (p_hls && !no_hlsearch) |
| 7486 | { |
| 7487 | last_pat_prog(&search_hl.rm); |
| 7488 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7489 | # ifdef FEAT_RELTIME |
| 7490 | /* Set the time limit to 'redrawtime'. */ |
| 7491 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7492 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7493 | } |
| 7494 | } |
| 7495 | |
| 7496 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7497 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7498 | */ |
| 7499 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7500 | end_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7501 | { |
| 7502 | if (search_hl.rm.regprog != NULL) |
| 7503 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7504 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7505 | search_hl.rm.regprog = NULL; |
| 7506 | } |
| 7507 | } |
| 7508 | |
| 7509 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7510 | * Init for calling prepare_search_hl(). |
| 7511 | */ |
| 7512 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7513 | init_search_hl(win_T *wp) |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7514 | { |
| 7515 | matchitem_T *cur; |
| 7516 | |
| 7517 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7518 | * match */ |
| 7519 | cur = wp->w_match_head; |
| 7520 | while (cur != NULL) |
| 7521 | { |
| 7522 | cur->hl.rm = cur->match; |
| 7523 | if (cur->hlg_id == 0) |
| 7524 | cur->hl.attr = 0; |
| 7525 | else |
| 7526 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7527 | cur->hl.buf = wp->w_buffer; |
| 7528 | cur->hl.lnum = 0; |
| 7529 | cur->hl.first_lnum = 0; |
| 7530 | # ifdef FEAT_RELTIME |
| 7531 | /* Set the time limit to 'redrawtime'. */ |
| 7532 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7533 | # endif |
| 7534 | cur = cur->next; |
| 7535 | } |
| 7536 | search_hl.buf = wp->w_buffer; |
| 7537 | search_hl.lnum = 0; |
| 7538 | search_hl.first_lnum = 0; |
| 7539 | /* time limit is set at the toplevel, for all windows */ |
| 7540 | } |
| 7541 | |
| 7542 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7543 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7544 | */ |
| 7545 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7546 | prepare_search_hl(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7547 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7548 | matchitem_T *cur; /* points to the match list */ |
| 7549 | match_T *shl; /* points to search_hl or a match */ |
| 7550 | int shl_flag; /* flag to indicate whether search_hl |
| 7551 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7552 | int pos_inprogress; /* marks that position match search is |
| 7553 | in progress */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7554 | int n; |
| 7555 | |
| 7556 | /* |
| 7557 | * When using a multi-line pattern, start searching at the top |
| 7558 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7559 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7560 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7561 | cur = wp->w_match_head; |
| 7562 | shl_flag = FALSE; |
| 7563 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7564 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7565 | if (shl_flag == FALSE) |
| 7566 | { |
| 7567 | shl = &search_hl; |
| 7568 | shl_flag = TRUE; |
| 7569 | } |
| 7570 | else |
| 7571 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7572 | if (shl->rm.regprog != NULL |
| 7573 | && shl->lnum == 0 |
| 7574 | && re_multiline(shl->rm.regprog)) |
| 7575 | { |
| 7576 | if (shl->first_lnum == 0) |
| 7577 | { |
| 7578 | # ifdef FEAT_FOLDING |
| 7579 | for (shl->first_lnum = lnum; |
| 7580 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7581 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7582 | NULL, NULL, TRUE, NULL)) |
| 7583 | break; |
| 7584 | # else |
| 7585 | shl->first_lnum = wp->w_topline; |
| 7586 | # endif |
| 7587 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7588 | if (cur != NULL) |
| 7589 | cur->pos.cur = 0; |
| 7590 | pos_inprogress = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7591 | n = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7592 | while (shl->first_lnum < lnum && (shl->rm.regprog != NULL |
| 7593 | || (cur != NULL && pos_inprogress))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7594 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7595 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, cur); |
| 7596 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
| 7597 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7598 | if (shl->lnum != 0) |
| 7599 | { |
| 7600 | shl->first_lnum = shl->lnum |
| 7601 | + shl->rm.endpos[0].lnum |
| 7602 | - shl->rm.startpos[0].lnum; |
| 7603 | n = shl->rm.endpos[0].col; |
| 7604 | } |
| 7605 | else |
| 7606 | { |
| 7607 | ++shl->first_lnum; |
| 7608 | n = 0; |
| 7609 | } |
| 7610 | } |
| 7611 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7612 | if (shl != &search_hl && cur != NULL) |
| 7613 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7614 | } |
| 7615 | } |
| 7616 | |
| 7617 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7618 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7619 | * Uses shl->buf. |
| 7620 | * Sets shl->lnum and shl->rm contents. |
| 7621 | * Note: Assumes a previous match is always before "lnum", unless |
| 7622 | * shl->lnum is zero. |
| 7623 | * Careful: Any pointers for buffer lines will become invalid. |
| 7624 | */ |
| 7625 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7626 | next_search_hl( |
| 7627 | win_T *win, |
| 7628 | match_T *shl, /* points to search_hl or a match */ |
| 7629 | linenr_T lnum, |
| 7630 | colnr_T mincol, /* minimal column for a match */ |
| 7631 | matchitem_T *cur) /* to retrieve match positions if any */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7632 | { |
| 7633 | linenr_T l; |
| 7634 | colnr_T matchcol; |
| 7635 | long nmatched; |
| 7636 | |
| 7637 | if (shl->lnum != 0) |
| 7638 | { |
| 7639 | /* Check for three situations: |
| 7640 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7641 | * 2. If the previous match includes "mincol", use it. |
| 7642 | * 3. Continue after the previous match. |
| 7643 | */ |
| 7644 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7645 | if (lnum > l) |
| 7646 | shl->lnum = 0; |
| 7647 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7648 | return; |
| 7649 | } |
| 7650 | |
| 7651 | /* |
| 7652 | * Repeat searching for a match until one is found that includes "mincol" |
| 7653 | * or none is found in this line. |
| 7654 | */ |
| 7655 | called_emsg = FALSE; |
| 7656 | for (;;) |
| 7657 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7658 | #ifdef FEAT_RELTIME |
| 7659 | /* Stop searching after passing the time limit. */ |
| 7660 | if (profile_passed_limit(&(shl->tm))) |
| 7661 | { |
| 7662 | shl->lnum = 0; /* no match found in time */ |
| 7663 | break; |
| 7664 | } |
| 7665 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7666 | /* Three situations: |
| 7667 | * 1. No useful previous match: search from start of line. |
| 7668 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7669 | * Break the loop if this is beyond the end of the line. |
| 7670 | * 3. Vi compatible searching: continue at end of previous match. |
| 7671 | */ |
| 7672 | if (shl->lnum == 0) |
| 7673 | matchcol = 0; |
| 7674 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7675 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7676 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7677 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7678 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7679 | |
| 7680 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7681 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7682 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7683 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7684 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7685 | shl->lnum = 0; |
| 7686 | break; |
| 7687 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7688 | #ifdef FEAT_MBYTE |
| 7689 | if (has_mbyte) |
| 7690 | matchcol += mb_ptr2len(ml); |
| 7691 | else |
| 7692 | #endif |
| 7693 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7694 | } |
| 7695 | else |
| 7696 | matchcol = shl->rm.endpos[0].col; |
| 7697 | |
| 7698 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7699 | if (shl->rm.regprog != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7700 | { |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7701 | /* Remember whether shl->rm is using a copy of the regprog in |
| 7702 | * cur->match. */ |
| 7703 | int regprog_is_copy = (shl != &search_hl && cur != NULL |
| 7704 | && shl == &cur->hl |
| 7705 | && cur->match.regprog == cur->hl.rm.regprog); |
| 7706 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7707 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, |
| 7708 | matchcol, |
| 7709 | #ifdef FEAT_RELTIME |
| 7710 | &(shl->tm) |
| 7711 | #else |
| 7712 | NULL |
| 7713 | #endif |
| 7714 | ); |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7715 | /* Copy the regprog, in case it got freed and recompiled. */ |
| 7716 | if (regprog_is_copy) |
| 7717 | cur->match.regprog = cur->hl.rm.regprog; |
| 7718 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7719 | if (called_emsg || got_int) |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7720 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7721 | /* Error while handling regexp: stop using this regexp. */ |
| 7722 | if (shl == &search_hl) |
| 7723 | { |
| 7724 | /* don't free regprog in the match list, it's a copy */ |
| 7725 | vim_regfree(shl->rm.regprog); |
| 7726 | SET_NO_HLSEARCH(TRUE); |
| 7727 | } |
| 7728 | shl->rm.regprog = NULL; |
| 7729 | shl->lnum = 0; |
| 7730 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" |
| 7731 | message */ |
| 7732 | break; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7733 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7734 | } |
| 7735 | else if (cur != NULL) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7736 | nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol); |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7737 | else |
| 7738 | nmatched = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7739 | if (nmatched == 0) |
| 7740 | { |
| 7741 | shl->lnum = 0; /* no match found */ |
| 7742 | break; |
| 7743 | } |
| 7744 | if (shl->rm.startpos[0].lnum > 0 |
| 7745 | || shl->rm.startpos[0].col >= mincol |
| 7746 | || nmatched > 1 |
| 7747 | || shl->rm.endpos[0].col > mincol) |
| 7748 | { |
| 7749 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7750 | break; /* useful match found */ |
| 7751 | } |
| 7752 | } |
| 7753 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7754 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7755 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7756 | next_search_hl_pos( |
| 7757 | match_T *shl, /* points to a match */ |
| 7758 | linenr_T lnum, |
| 7759 | posmatch_T *posmatch, /* match positions */ |
| 7760 | colnr_T mincol) /* minimal column for a match */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7761 | { |
| 7762 | int i; |
Bram Moolenaar | b6da44a | 2014-06-25 18:15:22 +0200 | [diff] [blame] | 7763 | int bot = -1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7764 | |
| 7765 | shl->lnum = 0; |
| 7766 | for (i = posmatch->cur; i < MAXPOSMATCH; i++) |
| 7767 | { |
| 7768 | if (posmatch->pos[i].lnum == 0) |
| 7769 | break; |
| 7770 | if (posmatch->pos[i].col < mincol) |
| 7771 | continue; |
| 7772 | if (posmatch->pos[i].lnum == lnum) |
| 7773 | { |
| 7774 | if (shl->lnum == lnum) |
| 7775 | { |
| 7776 | /* partially sort positions by column numbers |
| 7777 | * on the same line */ |
| 7778 | if (posmatch->pos[i].col < posmatch->pos[bot].col) |
| 7779 | { |
| 7780 | llpos_T tmp = posmatch->pos[i]; |
| 7781 | |
| 7782 | posmatch->pos[i] = posmatch->pos[bot]; |
| 7783 | posmatch->pos[bot] = tmp; |
| 7784 | } |
| 7785 | } |
| 7786 | else |
| 7787 | { |
| 7788 | bot = i; |
| 7789 | shl->lnum = lnum; |
| 7790 | } |
| 7791 | } |
| 7792 | } |
| 7793 | posmatch->cur = 0; |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 7794 | if (shl->lnum == lnum && bot >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7795 | { |
| 7796 | colnr_T start = posmatch->pos[bot].col == 0 |
| 7797 | ? 0 : posmatch->pos[bot].col - 1; |
| 7798 | colnr_T end = posmatch->pos[bot].col == 0 |
| 7799 | ? MAXCOL : start + posmatch->pos[bot].len; |
| 7800 | |
| 7801 | shl->rm.startpos[0].lnum = 0; |
| 7802 | shl->rm.startpos[0].col = start; |
| 7803 | shl->rm.endpos[0].lnum = 0; |
| 7804 | shl->rm.endpos[0].col = end; |
| 7805 | posmatch->cur = bot + 1; |
| 7806 | return TRUE; |
| 7807 | } |
| 7808 | return FALSE; |
| 7809 | } |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 7810 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7811 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7812 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7813 | screen_start_highlight(int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7814 | { |
| 7815 | attrentry_T *aep = NULL; |
| 7816 | |
| 7817 | screen_attr = attr; |
| 7818 | if (full_screen |
| 7819 | #ifdef WIN3264 |
| 7820 | && termcap_active |
| 7821 | #endif |
| 7822 | ) |
| 7823 | { |
| 7824 | #ifdef FEAT_GUI |
| 7825 | if (gui.in_use) |
| 7826 | { |
| 7827 | char buf[20]; |
| 7828 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7829 | /* The GUI handles this internally. */ |
| 7830 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7831 | OUT_STR(buf); |
| 7832 | } |
| 7833 | else |
| 7834 | #endif |
| 7835 | { |
| 7836 | if (attr > HL_ALL) /* special HL attr. */ |
| 7837 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7838 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7839 | aep = syn_cterm_attr2entry(attr); |
| 7840 | else |
| 7841 | aep = syn_term_attr2entry(attr); |
| 7842 | if (aep == NULL) /* did ":syntax clear" */ |
| 7843 | attr = 0; |
| 7844 | else |
| 7845 | attr = aep->ae_attr; |
| 7846 | } |
| 7847 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7848 | out_str(T_MD); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7849 | else if (aep != NULL && cterm_normal_fg_bold && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7850 | #ifdef FEAT_TERMGUICOLORS |
| 7851 | (p_tgc ? |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7852 | (aep->ae_u.cterm.fg_rgb != (long_u)INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7853 | #endif |
| 7854 | (t_colors > 1 && aep->ae_u.cterm.fg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7855 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7856 | ) |
| 7857 | #endif |
| 7858 | ) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7859 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7860 | * has a FG color defined, clear BOLD. */ |
| 7861 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7862 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7863 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7864 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7865 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7866 | out_str(T_US); |
| 7867 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7868 | out_str(T_CZH); |
| 7869 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7870 | out_str(T_MR); |
| 7871 | |
| 7872 | /* |
| 7873 | * Output the color or start string after bold etc., in case the |
| 7874 | * bold etc. override the color setting. |
| 7875 | */ |
| 7876 | if (aep != NULL) |
| 7877 | { |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7878 | #ifdef FEAT_TERMGUICOLORS |
| 7879 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7880 | { |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7881 | if (aep->ae_u.cterm.fg_rgb != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7882 | term_fg_rgb_color(aep->ae_u.cterm.fg_rgb); |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7883 | if (aep->ae_u.cterm.bg_rgb != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7884 | term_bg_rgb_color(aep->ae_u.cterm.bg_rgb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7885 | } |
| 7886 | else |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7887 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7888 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7889 | if (t_colors > 1) |
| 7890 | { |
| 7891 | if (aep->ae_u.cterm.fg_color) |
| 7892 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7893 | if (aep->ae_u.cterm.bg_color) |
| 7894 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7895 | } |
| 7896 | else |
| 7897 | { |
| 7898 | if (aep->ae_u.term.start != NULL) |
| 7899 | out_str(aep->ae_u.term.start); |
| 7900 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7901 | } |
| 7902 | } |
| 7903 | } |
| 7904 | } |
| 7905 | } |
| 7906 | |
| 7907 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7908 | screen_stop_highlight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7909 | { |
| 7910 | int do_ME = FALSE; /* output T_ME code */ |
| 7911 | |
| 7912 | if (screen_attr != 0 |
| 7913 | #ifdef WIN3264 |
| 7914 | && termcap_active |
| 7915 | #endif |
| 7916 | ) |
| 7917 | { |
| 7918 | #ifdef FEAT_GUI |
| 7919 | if (gui.in_use) |
| 7920 | { |
| 7921 | char buf[20]; |
| 7922 | |
| 7923 | /* use internal GUI code */ |
| 7924 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7925 | OUT_STR(buf); |
| 7926 | } |
| 7927 | else |
| 7928 | #endif |
| 7929 | { |
| 7930 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7931 | { |
| 7932 | attrentry_T *aep; |
| 7933 | |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7934 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7935 | { |
| 7936 | /* |
| 7937 | * Assume that t_me restores the original colors! |
| 7938 | */ |
| 7939 | aep = syn_cterm_attr2entry(screen_attr); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7940 | if (aep != NULL && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7941 | #ifdef FEAT_TERMGUICOLORS |
| 7942 | (p_tgc ? |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7943 | (aep->ae_u.cterm.fg_rgb != (long_u)INVALCOLOR || |
| 7944 | aep->ae_u.cterm.bg_rgb != (long_u)INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7945 | #endif |
| 7946 | (aep->ae_u.cterm.fg_color || aep->ae_u.cterm.bg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7947 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7948 | ) |
| 7949 | #endif |
| 7950 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7951 | do_ME = TRUE; |
| 7952 | } |
| 7953 | else |
| 7954 | { |
| 7955 | aep = syn_term_attr2entry(screen_attr); |
| 7956 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7957 | { |
| 7958 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7959 | do_ME = TRUE; |
| 7960 | else |
| 7961 | out_str(aep->ae_u.term.stop); |
| 7962 | } |
| 7963 | } |
| 7964 | if (aep == NULL) /* did ":syntax clear" */ |
| 7965 | screen_attr = 0; |
| 7966 | else |
| 7967 | screen_attr = aep->ae_attr; |
| 7968 | } |
| 7969 | |
| 7970 | /* |
| 7971 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7972 | * same sequence several times. |
| 7973 | */ |
| 7974 | if (screen_attr & HL_STANDOUT) |
| 7975 | { |
| 7976 | if (STRCMP(T_SE, T_ME) == 0) |
| 7977 | do_ME = TRUE; |
| 7978 | else |
| 7979 | out_str(T_SE); |
| 7980 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7981 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7982 | { |
| 7983 | if (STRCMP(T_UE, T_ME) == 0) |
| 7984 | do_ME = TRUE; |
| 7985 | else |
| 7986 | out_str(T_UE); |
| 7987 | } |
| 7988 | if (screen_attr & HL_ITALIC) |
| 7989 | { |
| 7990 | if (STRCMP(T_CZR, T_ME) == 0) |
| 7991 | do_ME = TRUE; |
| 7992 | else |
| 7993 | out_str(T_CZR); |
| 7994 | } |
| 7995 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 7996 | out_str(T_ME); |
| 7997 | |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7998 | #ifdef FEAT_TERMGUICOLORS |
| 7999 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8000 | { |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 8001 | if (cterm_normal_fg_gui_color != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8002 | term_fg_rgb_color(cterm_normal_fg_gui_color); |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 8003 | if (cterm_normal_bg_gui_color != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8004 | term_bg_rgb_color(cterm_normal_bg_gui_color); |
| 8005 | } |
| 8006 | else |
| 8007 | #endif |
| 8008 | { |
| 8009 | if (t_colors > 1) |
| 8010 | { |
| 8011 | /* set Normal cterm colors */ |
| 8012 | if (cterm_normal_fg_color != 0) |
| 8013 | term_fg_color(cterm_normal_fg_color - 1); |
| 8014 | if (cterm_normal_bg_color != 0) |
| 8015 | term_bg_color(cterm_normal_bg_color - 1); |
| 8016 | if (cterm_normal_fg_bold) |
| 8017 | out_str(T_MD); |
| 8018 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8019 | } |
| 8020 | } |
| 8021 | } |
| 8022 | screen_attr = 0; |
| 8023 | } |
| 8024 | |
| 8025 | /* |
| 8026 | * Reset the colors for a cterm. Used when leaving Vim. |
| 8027 | * The machine specific code may override this again. |
| 8028 | */ |
| 8029 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8030 | reset_cterm_colors(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8031 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8032 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8033 | { |
| 8034 | /* set Normal cterm colors */ |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8035 | #ifdef FEAT_TERMGUICOLORS |
| 8036 | if (p_tgc ? |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 8037 | (cterm_normal_fg_gui_color != (long_u)INVALCOLOR |
| 8038 | || cterm_normal_bg_gui_color != (long_u)INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8039 | (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)) |
| 8040 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8041 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8042 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8043 | { |
| 8044 | out_str(T_OP); |
| 8045 | screen_attr = -1; |
| 8046 | } |
| 8047 | if (cterm_normal_fg_bold) |
| 8048 | { |
| 8049 | out_str(T_ME); |
| 8050 | screen_attr = -1; |
| 8051 | } |
| 8052 | } |
| 8053 | } |
| 8054 | |
| 8055 | /* |
| 8056 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 8057 | * using the attributes from ScreenAttrs["off"]. |
| 8058 | */ |
| 8059 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8060 | screen_char(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8061 | { |
| 8062 | int attr; |
| 8063 | |
| 8064 | /* Check for illegal values, just in case (could happen just after |
| 8065 | * resizing). */ |
| 8066 | if (row >= screen_Rows || col >= screen_Columns) |
| 8067 | return; |
| 8068 | |
Bram Moolenaar | 494838a | 2015-02-10 19:20:37 +0100 | [diff] [blame] | 8069 | /* Outputting a character in the last cell on the screen may scroll the |
| 8070 | * screen up. Only do it when the "xn" termcap property is set, otherwise |
| 8071 | * mark the character invalid (update it when scrolled up). */ |
| 8072 | if (*T_XN == NUL |
| 8073 | && row == screen_Rows - 1 && col == screen_Columns - 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8074 | #ifdef FEAT_RIGHTLEFT |
| 8075 | /* account for first command-line character in rightleft mode */ |
| 8076 | && !cmdmsg_rl |
| 8077 | #endif |
| 8078 | ) |
| 8079 | { |
| 8080 | ScreenAttrs[off] = (sattr_T)-1; |
| 8081 | return; |
| 8082 | } |
| 8083 | |
| 8084 | /* |
| 8085 | * Stop highlighting first, so it's easier to move the cursor. |
| 8086 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8087 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8088 | if (screen_char_attr != 0) |
| 8089 | attr = screen_char_attr; |
| 8090 | else |
| 8091 | #endif |
| 8092 | attr = ScreenAttrs[off]; |
| 8093 | if (screen_attr != attr) |
| 8094 | screen_stop_highlight(); |
| 8095 | |
| 8096 | windgoto(row, col); |
| 8097 | |
| 8098 | if (screen_attr != attr) |
| 8099 | screen_start_highlight(attr); |
| 8100 | |
| 8101 | #ifdef FEAT_MBYTE |
| 8102 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 8103 | { |
| 8104 | char_u buf[MB_MAXBYTES + 1]; |
| 8105 | |
| 8106 | /* Convert UTF-8 character to bytes and write it. */ |
| 8107 | |
| 8108 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 8109 | |
| 8110 | out_str(buf); |
Bram Moolenaar | cb07008 | 2016-04-02 22:14:51 +0200 | [diff] [blame] | 8111 | if (utf_ambiguous_width(ScreenLinesUC[off])) |
| 8112 | screen_cur_col = 9999; |
| 8113 | else if (utf_char2cells(ScreenLinesUC[off]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8114 | ++screen_cur_col; |
| 8115 | } |
| 8116 | else |
| 8117 | #endif |
| 8118 | { |
| 8119 | #ifdef FEAT_MBYTE |
| 8120 | out_flush_check(); |
| 8121 | #endif |
| 8122 | out_char(ScreenLines[off]); |
| 8123 | #ifdef FEAT_MBYTE |
| 8124 | /* double-byte character in single-width cell */ |
| 8125 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 8126 | out_char(ScreenLines2[off]); |
| 8127 | #endif |
| 8128 | } |
| 8129 | |
| 8130 | screen_cur_col++; |
| 8131 | } |
| 8132 | |
| 8133 | #ifdef FEAT_MBYTE |
| 8134 | |
| 8135 | /* |
| 8136 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 8137 | * on the screen at position 'row' and 'col'. |
| 8138 | * The attributes of the first byte is used for all. This is required to |
| 8139 | * output the two bytes of a double-byte character with nothing in between. |
| 8140 | */ |
| 8141 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8142 | screen_char_2(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8143 | { |
| 8144 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 8145 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 8146 | return; |
| 8147 | |
| 8148 | /* Outputting the last character on the screen may scrollup the screen. |
| 8149 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 8150 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 8151 | { |
| 8152 | ScreenAttrs[off] = (sattr_T)-1; |
| 8153 | return; |
| 8154 | } |
| 8155 | |
| 8156 | /* Output the first byte normally (positions the cursor), then write the |
| 8157 | * second byte directly. */ |
| 8158 | screen_char(off, row, col); |
| 8159 | out_char(ScreenLines[off + 1]); |
| 8160 | ++screen_cur_col; |
| 8161 | } |
| 8162 | #endif |
| 8163 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8164 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8165 | /* |
| 8166 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 8167 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 8168 | */ |
| 8169 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8170 | screen_draw_rectangle( |
| 8171 | int row, |
| 8172 | int col, |
| 8173 | int height, |
| 8174 | int width, |
| 8175 | int invert) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8176 | { |
| 8177 | int r, c; |
| 8178 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8179 | #ifdef FEAT_MBYTE |
| 8180 | int max_off; |
| 8181 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8182 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8183 | /* Can't use ScreenLines unless initialized */ |
| 8184 | if (ScreenLines == NULL) |
| 8185 | return; |
| 8186 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8187 | if (invert) |
| 8188 | screen_char_attr = HL_INVERSE; |
| 8189 | for (r = row; r < row + height; ++r) |
| 8190 | { |
| 8191 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8192 | #ifdef FEAT_MBYTE |
| 8193 | max_off = off + screen_Columns; |
| 8194 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8195 | for (c = col; c < col + width; ++c) |
| 8196 | { |
| 8197 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8198 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8199 | { |
| 8200 | screen_char_2(off + c, r, c); |
| 8201 | ++c; |
| 8202 | } |
| 8203 | else |
| 8204 | #endif |
| 8205 | { |
| 8206 | screen_char(off + c, r, c); |
| 8207 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8208 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8209 | ++c; |
| 8210 | #endif |
| 8211 | } |
| 8212 | } |
| 8213 | } |
| 8214 | screen_char_attr = 0; |
| 8215 | } |
| 8216 | #endif |
| 8217 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8218 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8219 | /* |
| 8220 | * Redraw the characters for a vertically split window. |
| 8221 | */ |
| 8222 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8223 | redraw_block(int row, int end, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8224 | { |
| 8225 | int col; |
| 8226 | int width; |
| 8227 | |
| 8228 | # ifdef FEAT_CLIPBOARD |
| 8229 | clip_may_clear_selection(row, end - 1); |
| 8230 | # endif |
| 8231 | |
| 8232 | if (wp == NULL) |
| 8233 | { |
| 8234 | col = 0; |
| 8235 | width = Columns; |
| 8236 | } |
| 8237 | else |
| 8238 | { |
| 8239 | col = wp->w_wincol; |
| 8240 | width = wp->w_width; |
| 8241 | } |
| 8242 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 8243 | } |
| 8244 | #endif |
| 8245 | |
| 8246 | /* |
| 8247 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 8248 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 8249 | * Use attributes 'attr'. |
| 8250 | */ |
| 8251 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8252 | screen_fill( |
| 8253 | int start_row, |
| 8254 | int end_row, |
| 8255 | int start_col, |
| 8256 | int end_col, |
| 8257 | int c1, |
| 8258 | int c2, |
| 8259 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8260 | { |
| 8261 | int row; |
| 8262 | int col; |
| 8263 | int off; |
| 8264 | int end_off; |
| 8265 | int did_delete; |
| 8266 | int c; |
| 8267 | int norm_term; |
| 8268 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8269 | int force_next = FALSE; |
| 8270 | #endif |
| 8271 | |
| 8272 | if (end_row > screen_Rows) /* safety check */ |
| 8273 | end_row = screen_Rows; |
| 8274 | if (end_col > screen_Columns) /* safety check */ |
| 8275 | end_col = screen_Columns; |
| 8276 | if (ScreenLines == NULL |
| 8277 | || start_row >= end_row |
| 8278 | || start_col >= end_col) /* nothing to do */ |
| 8279 | return; |
| 8280 | |
| 8281 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 8282 | norm_term = ( |
| 8283 | #ifdef FEAT_GUI |
| 8284 | !gui.in_use && |
| 8285 | #endif |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8286 | !IS_CTERM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8287 | for (row = start_row; row < end_row; ++row) |
| 8288 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8289 | #ifdef FEAT_MBYTE |
| 8290 | if (has_mbyte |
| 8291 | # ifdef FEAT_GUI |
| 8292 | && !gui.in_use |
| 8293 | # endif |
| 8294 | ) |
| 8295 | { |
| 8296 | /* When drawing over the right halve of a double-wide char clear |
| 8297 | * out the left halve. When drawing over the left halve of a |
| 8298 | * double wide-char clear out the right halve. Only needed in a |
| 8299 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 8300 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8301 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 8302 | 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] | 8303 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8304 | } |
| 8305 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8306 | /* |
| 8307 | * Try to use delete-line termcap code, when no attributes or in a |
| 8308 | * "normal" terminal, where a bold/italic space is just a |
| 8309 | * space. |
| 8310 | */ |
| 8311 | did_delete = FALSE; |
| 8312 | if (c2 == ' ' |
| 8313 | && end_col == Columns |
| 8314 | && can_clear(T_CE) |
| 8315 | && (attr == 0 |
| 8316 | || (norm_term |
| 8317 | && attr <= HL_ALL |
| 8318 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 8319 | { |
| 8320 | /* |
| 8321 | * check if we really need to clear something |
| 8322 | */ |
| 8323 | col = start_col; |
| 8324 | if (c1 != ' ') /* don't clear first char */ |
| 8325 | ++col; |
| 8326 | |
| 8327 | off = LineOffset[row] + col; |
| 8328 | end_off = LineOffset[row] + end_col; |
| 8329 | |
| 8330 | /* skip blanks (used often, keep it fast!) */ |
| 8331 | #ifdef FEAT_MBYTE |
| 8332 | if (enc_utf8) |
| 8333 | while (off < end_off && ScreenLines[off] == ' ' |
| 8334 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 8335 | ++off; |
| 8336 | else |
| 8337 | #endif |
| 8338 | while (off < end_off && ScreenLines[off] == ' ' |
| 8339 | && ScreenAttrs[off] == 0) |
| 8340 | ++off; |
| 8341 | if (off < end_off) /* something to be cleared */ |
| 8342 | { |
| 8343 | col = off - LineOffset[row]; |
| 8344 | screen_stop_highlight(); |
| 8345 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 8346 | out_str(T_CE); |
| 8347 | screen_start(); /* don't know where cursor is now */ |
| 8348 | col = end_col - col; |
| 8349 | while (col--) /* clear chars in ScreenLines */ |
| 8350 | { |
| 8351 | ScreenLines[off] = ' '; |
| 8352 | #ifdef FEAT_MBYTE |
| 8353 | if (enc_utf8) |
| 8354 | ScreenLinesUC[off] = 0; |
| 8355 | #endif |
| 8356 | ScreenAttrs[off] = 0; |
| 8357 | ++off; |
| 8358 | } |
| 8359 | } |
| 8360 | did_delete = TRUE; /* the chars are cleared now */ |
| 8361 | } |
| 8362 | |
| 8363 | off = LineOffset[row] + start_col; |
| 8364 | c = c1; |
| 8365 | for (col = start_col; col < end_col; ++col) |
| 8366 | { |
| 8367 | if (ScreenLines[off] != c |
| 8368 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8369 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 8370 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8371 | #endif |
| 8372 | || ScreenAttrs[off] != attr |
| 8373 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8374 | || force_next |
| 8375 | #endif |
| 8376 | ) |
| 8377 | { |
| 8378 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8379 | /* The bold trick may make a single row of pixels appear in |
| 8380 | * the next character. When a bold character is removed, the |
| 8381 | * next character should be redrawn too. This happens for our |
| 8382 | * own GUI and for some xterms. */ |
| 8383 | if ( |
| 8384 | # ifdef FEAT_GUI |
| 8385 | gui.in_use |
| 8386 | # endif |
| 8387 | # if defined(FEAT_GUI) && defined(UNIX) |
| 8388 | || |
| 8389 | # endif |
| 8390 | # ifdef UNIX |
| 8391 | term_is_xterm |
| 8392 | # endif |
| 8393 | ) |
| 8394 | { |
| 8395 | if (ScreenLines[off] != ' ' |
| 8396 | && (ScreenAttrs[off] > HL_ALL |
| 8397 | || ScreenAttrs[off] & HL_BOLD)) |
| 8398 | force_next = TRUE; |
| 8399 | else |
| 8400 | force_next = FALSE; |
| 8401 | } |
| 8402 | #endif |
| 8403 | ScreenLines[off] = c; |
| 8404 | #ifdef FEAT_MBYTE |
| 8405 | if (enc_utf8) |
| 8406 | { |
| 8407 | if (c >= 0x80) |
| 8408 | { |
| 8409 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8410 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8411 | } |
| 8412 | else |
| 8413 | ScreenLinesUC[off] = 0; |
| 8414 | } |
| 8415 | #endif |
| 8416 | ScreenAttrs[off] = attr; |
| 8417 | if (!did_delete || c != ' ') |
| 8418 | screen_char(off, row, col); |
| 8419 | } |
| 8420 | ++off; |
| 8421 | if (col == start_col) |
| 8422 | { |
| 8423 | if (did_delete) |
| 8424 | break; |
| 8425 | c = c2; |
| 8426 | } |
| 8427 | } |
| 8428 | if (end_col == Columns) |
| 8429 | LineWraps[row] = FALSE; |
| 8430 | if (row == Rows - 1) /* overwritten the command line */ |
| 8431 | { |
| 8432 | redraw_cmdline = TRUE; |
| 8433 | if (c1 == ' ' && c2 == ' ') |
| 8434 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8435 | if (start_col == 0) |
| 8436 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8437 | } |
| 8438 | } |
| 8439 | } |
| 8440 | |
| 8441 | /* |
| 8442 | * Check if there should be a delay. Used before clearing or redrawing the |
| 8443 | * screen or the command line. |
| 8444 | */ |
| 8445 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8446 | check_for_delay(int check_msg_scroll) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8447 | { |
| 8448 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 8449 | && !did_wait_return |
| 8450 | && emsg_silent == 0) |
| 8451 | { |
| 8452 | out_flush(); |
| 8453 | ui_delay(1000L, TRUE); |
| 8454 | emsg_on_display = FALSE; |
| 8455 | if (check_msg_scroll) |
| 8456 | msg_scroll = FALSE; |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | /* |
| 8461 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8462 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8463 | * Returns TRUE if there is a valid screen to write to. |
| 8464 | * Returns FALSE when starting up and screen not initialized yet. |
| 8465 | */ |
| 8466 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8467 | screen_valid(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8468 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8469 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8470 | return (ScreenLines != NULL); |
| 8471 | } |
| 8472 | |
| 8473 | /* |
| 8474 | * Resize the shell to Rows and Columns. |
| 8475 | * Allocate ScreenLines[] and associated items. |
| 8476 | * |
| 8477 | * There may be some time between setting Rows and Columns and (re)allocating |
| 8478 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 8479 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 8480 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 8481 | * final size of the shell is needed. |
| 8482 | */ |
| 8483 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8484 | screenalloc(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8485 | { |
| 8486 | int new_row, old_row; |
| 8487 | #ifdef FEAT_GUI |
| 8488 | int old_Rows; |
| 8489 | #endif |
| 8490 | win_T *wp; |
| 8491 | int outofmem = FALSE; |
| 8492 | int len; |
| 8493 | schar_T *new_ScreenLines; |
| 8494 | #ifdef FEAT_MBYTE |
| 8495 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8496 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8497 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8498 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8499 | #endif |
| 8500 | sattr_T *new_ScreenAttrs; |
| 8501 | unsigned *new_LineOffset; |
| 8502 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8503 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8504 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8505 | tabpage_T *tp; |
| 8506 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8507 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8508 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8509 | #ifdef FEAT_AUTOCMD |
| 8510 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8511 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8512 | retry: |
| 8513 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8514 | /* |
| 8515 | * Allocation of the screen buffers is done only when the size changes and |
| 8516 | * when Rows and Columns have been set and we have started doing full |
| 8517 | * screen stuff. |
| 8518 | */ |
| 8519 | if ((ScreenLines != NULL |
| 8520 | && Rows == screen_Rows |
| 8521 | && Columns == screen_Columns |
| 8522 | #ifdef FEAT_MBYTE |
| 8523 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 8524 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8525 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8526 | #endif |
| 8527 | ) |
| 8528 | || Rows == 0 |
| 8529 | || Columns == 0 |
| 8530 | || (!full_screen && ScreenLines == NULL)) |
| 8531 | return; |
| 8532 | |
| 8533 | /* |
| 8534 | * It's possible that we produce an out-of-memory message below, which |
| 8535 | * will cause this function to be called again. To break the loop, just |
| 8536 | * return here. |
| 8537 | */ |
| 8538 | if (entered) |
| 8539 | return; |
| 8540 | entered = TRUE; |
| 8541 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8542 | /* |
| 8543 | * Note that the window sizes are updated before reallocating the arrays, |
| 8544 | * thus we must not redraw here! |
| 8545 | */ |
| 8546 | ++RedrawingDisabled; |
| 8547 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8548 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8549 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8550 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8551 | |
| 8552 | /* |
| 8553 | * We're changing the size of the screen. |
| 8554 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8555 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8556 | * lines (unless the screen is going to be cleared). |
| 8557 | * - Free the old arrays. |
| 8558 | * |
| 8559 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8560 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8561 | * size is wrong. |
| 8562 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8563 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8564 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8565 | #ifdef FEAT_AUTOCMD |
| 8566 | if (aucmd_win != NULL) |
| 8567 | win_free_lsize(aucmd_win); |
| 8568 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8569 | |
| 8570 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8571 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8572 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8573 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8574 | if (enc_utf8) |
| 8575 | { |
| 8576 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8577 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8578 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8579 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8580 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8581 | } |
| 8582 | if (enc_dbcs == DBCS_JPNU) |
| 8583 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8584 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8585 | #endif |
| 8586 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8587 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8588 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8589 | Rows * sizeof(unsigned)), FALSE); |
| 8590 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8591 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8592 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8593 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8594 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8595 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8596 | { |
| 8597 | if (win_alloc_lines(wp) == FAIL) |
| 8598 | { |
| 8599 | outofmem = TRUE; |
| 8600 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8601 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8602 | #endif |
| 8603 | } |
| 8604 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8605 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8606 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8607 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8608 | outofmem = TRUE; |
| 8609 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8610 | #ifdef FEAT_WINDOWS |
| 8611 | give_up: |
| 8612 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8613 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8614 | #ifdef FEAT_MBYTE |
| 8615 | for (i = 0; i < p_mco; ++i) |
| 8616 | if (new_ScreenLinesC[i] == NULL) |
| 8617 | break; |
| 8618 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8619 | if (new_ScreenLines == NULL |
| 8620 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8621 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8622 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8623 | #endif |
| 8624 | || new_ScreenAttrs == NULL |
| 8625 | || new_LineOffset == NULL |
| 8626 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8627 | #ifdef FEAT_WINDOWS |
| 8628 | || new_TabPageIdxs == NULL |
| 8629 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8630 | || outofmem) |
| 8631 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8632 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8633 | { |
| 8634 | /* guess the size */ |
| 8635 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8636 | |
| 8637 | /* Remember we did this to avoid getting outofmem messages over |
| 8638 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8639 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8640 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8641 | vim_free(new_ScreenLines); |
| 8642 | new_ScreenLines = NULL; |
| 8643 | #ifdef FEAT_MBYTE |
| 8644 | vim_free(new_ScreenLinesUC); |
| 8645 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8646 | for (i = 0; i < p_mco; ++i) |
| 8647 | { |
| 8648 | vim_free(new_ScreenLinesC[i]); |
| 8649 | new_ScreenLinesC[i] = NULL; |
| 8650 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8651 | vim_free(new_ScreenLines2); |
| 8652 | new_ScreenLines2 = NULL; |
| 8653 | #endif |
| 8654 | vim_free(new_ScreenAttrs); |
| 8655 | new_ScreenAttrs = NULL; |
| 8656 | vim_free(new_LineOffset); |
| 8657 | new_LineOffset = NULL; |
| 8658 | vim_free(new_LineWraps); |
| 8659 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8660 | #ifdef FEAT_WINDOWS |
| 8661 | vim_free(new_TabPageIdxs); |
| 8662 | new_TabPageIdxs = NULL; |
| 8663 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8664 | } |
| 8665 | else |
| 8666 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8667 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8668 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8669 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8670 | { |
| 8671 | new_LineOffset[new_row] = new_row * Columns; |
| 8672 | new_LineWraps[new_row] = FALSE; |
| 8673 | |
| 8674 | /* |
| 8675 | * If the screen is not going to be cleared, copy as much as |
| 8676 | * possible from the old screen to the new one and clear the rest |
| 8677 | * (used when resizing the window at the "--more--" prompt or when |
| 8678 | * executing an external command, for the GUI). |
| 8679 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8680 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8681 | { |
| 8682 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8683 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8684 | #ifdef FEAT_MBYTE |
| 8685 | if (enc_utf8) |
| 8686 | { |
| 8687 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8688 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8689 | for (i = 0; i < p_mco; ++i) |
| 8690 | (void)vim_memset(new_ScreenLinesC[i] |
| 8691 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8692 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8693 | } |
| 8694 | if (enc_dbcs == DBCS_JPNU) |
| 8695 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8696 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8697 | #endif |
| 8698 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8699 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8700 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8701 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8702 | { |
| 8703 | if (screen_Columns < Columns) |
| 8704 | len = screen_Columns; |
| 8705 | else |
| 8706 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8707 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8708 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8709 | * may be invalid now. Also when p_mco changes. */ |
| 8710 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8711 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8712 | #endif |
| 8713 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8714 | ScreenLines + LineOffset[old_row], |
| 8715 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8716 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8717 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8718 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8719 | { |
| 8720 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8721 | ScreenLinesUC + LineOffset[old_row], |
| 8722 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8723 | for (i = 0; i < p_mco; ++i) |
| 8724 | mch_memmove(new_ScreenLinesC[i] |
| 8725 | + new_LineOffset[new_row], |
| 8726 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8727 | (size_t)len * sizeof(u8char_T)); |
| 8728 | } |
| 8729 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8730 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8731 | ScreenLines2 + LineOffset[old_row], |
| 8732 | (size_t)len * sizeof(schar_T)); |
| 8733 | #endif |
| 8734 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8735 | ScreenAttrs + LineOffset[old_row], |
| 8736 | (size_t)len * sizeof(sattr_T)); |
| 8737 | } |
| 8738 | } |
| 8739 | } |
| 8740 | /* Use the last line of the screen for the current line. */ |
| 8741 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8742 | } |
| 8743 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8744 | free_screenlines(); |
| 8745 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8746 | ScreenLines = new_ScreenLines; |
| 8747 | #ifdef FEAT_MBYTE |
| 8748 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8749 | for (i = 0; i < p_mco; ++i) |
| 8750 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8751 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8752 | ScreenLines2 = new_ScreenLines2; |
| 8753 | #endif |
| 8754 | ScreenAttrs = new_ScreenAttrs; |
| 8755 | LineOffset = new_LineOffset; |
| 8756 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8757 | #ifdef FEAT_WINDOWS |
| 8758 | TabPageIdxs = new_TabPageIdxs; |
| 8759 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8760 | |
| 8761 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8762 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8763 | #ifdef FEAT_GUI |
| 8764 | old_Rows = screen_Rows; |
| 8765 | #endif |
| 8766 | screen_Rows = Rows; |
| 8767 | screen_Columns = Columns; |
| 8768 | |
| 8769 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8770 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8771 | screenclear2(); |
| 8772 | |
| 8773 | #ifdef FEAT_GUI |
| 8774 | else if (gui.in_use |
| 8775 | && !gui.starting |
| 8776 | && ScreenLines != NULL |
| 8777 | && old_Rows != Rows) |
| 8778 | { |
| 8779 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8780 | /* |
| 8781 | * Adjust the position of the cursor, for when executing an external |
| 8782 | * command. |
| 8783 | */ |
| 8784 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8785 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8786 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8787 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8788 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8789 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8790 | } |
| 8791 | #endif |
| 8792 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8793 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8794 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8795 | |
| 8796 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8797 | /* |
| 8798 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8799 | * in case applying autocommands always changes Rows or Columns. |
| 8800 | */ |
| 8801 | if (starting == 0 && ++retry_count <= 3) |
| 8802 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8803 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8804 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8805 | * jump back to check if we need to allocate the screen again. */ |
| 8806 | goto retry; |
| 8807 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8808 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8809 | } |
| 8810 | |
| 8811 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8812 | free_screenlines(void) |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8813 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8814 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8815 | int i; |
| 8816 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8817 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8818 | for (i = 0; i < Screen_mco; ++i) |
| 8819 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8820 | vim_free(ScreenLines2); |
| 8821 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8822 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8823 | vim_free(ScreenAttrs); |
| 8824 | vim_free(LineOffset); |
| 8825 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8826 | #ifdef FEAT_WINDOWS |
| 8827 | vim_free(TabPageIdxs); |
| 8828 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8829 | } |
| 8830 | |
| 8831 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8832 | screenclear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8833 | { |
| 8834 | check_for_delay(FALSE); |
| 8835 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8836 | screenclear2(); /* clear the screen */ |
| 8837 | } |
| 8838 | |
| 8839 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8840 | screenclear2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8841 | { |
| 8842 | int i; |
| 8843 | |
| 8844 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8845 | #ifdef FEAT_GUI |
| 8846 | || (gui.in_use && gui.starting) |
| 8847 | #endif |
| 8848 | ) |
| 8849 | return; |
| 8850 | |
| 8851 | #ifdef FEAT_GUI |
| 8852 | if (!gui.in_use) |
| 8853 | #endif |
| 8854 | screen_attr = -1; /* force setting the Normal colors */ |
| 8855 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8856 | |
| 8857 | #ifdef FEAT_CLIPBOARD |
| 8858 | /* disable selection without redrawing it */ |
| 8859 | clip_scroll_selection(9999); |
| 8860 | #endif |
| 8861 | |
| 8862 | /* blank out ScreenLines */ |
| 8863 | for (i = 0; i < Rows; ++i) |
| 8864 | { |
| 8865 | lineclear(LineOffset[i], (int)Columns); |
| 8866 | LineWraps[i] = FALSE; |
| 8867 | } |
| 8868 | |
| 8869 | if (can_clear(T_CL)) |
| 8870 | { |
| 8871 | out_str(T_CL); /* clear the display */ |
| 8872 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8873 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8874 | } |
| 8875 | else |
| 8876 | { |
| 8877 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8878 | for (i = 0; i < Rows; ++i) |
| 8879 | lineinvalid(LineOffset[i], (int)Columns); |
| 8880 | clear_cmdline = TRUE; |
| 8881 | } |
| 8882 | |
| 8883 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8884 | |
| 8885 | win_rest_invalid(firstwin); |
| 8886 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8887 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8888 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8889 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8890 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8891 | must_redraw = NOT_VALID; |
| 8892 | compute_cmdrow(); |
| 8893 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8894 | msg_col = 0; |
| 8895 | screen_start(); /* don't know where cursor is now */ |
| 8896 | msg_scrolled = 0; /* can't scroll back */ |
| 8897 | msg_didany = FALSE; |
| 8898 | msg_didout = FALSE; |
| 8899 | } |
| 8900 | |
| 8901 | /* |
| 8902 | * Clear one line in ScreenLines. |
| 8903 | */ |
| 8904 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8905 | lineclear(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8906 | { |
| 8907 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8908 | #ifdef FEAT_MBYTE |
| 8909 | if (enc_utf8) |
| 8910 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8911 | (size_t)width * sizeof(u8char_T)); |
| 8912 | #endif |
| 8913 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8914 | } |
| 8915 | |
| 8916 | /* |
| 8917 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8918 | * invalid value. |
| 8919 | */ |
| 8920 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8921 | lineinvalid(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8922 | { |
| 8923 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8924 | } |
| 8925 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8926 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8927 | /* |
| 8928 | * Copy part of a Screenline for vertically split window "wp". |
| 8929 | */ |
| 8930 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8931 | linecopy(int to, int from, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8932 | { |
| 8933 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8934 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8935 | |
| 8936 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8937 | wp->w_width * sizeof(schar_T)); |
| 8938 | # ifdef FEAT_MBYTE |
| 8939 | if (enc_utf8) |
| 8940 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8941 | int i; |
| 8942 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8943 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8944 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8945 | for (i = 0; i < p_mco; ++i) |
| 8946 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8947 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8948 | } |
| 8949 | if (enc_dbcs == DBCS_JPNU) |
| 8950 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8951 | wp->w_width * sizeof(schar_T)); |
| 8952 | # endif |
| 8953 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8954 | wp->w_width * sizeof(sattr_T)); |
| 8955 | } |
| 8956 | #endif |
| 8957 | |
| 8958 | /* |
| 8959 | * Return TRUE if clearing with term string "p" would work. |
| 8960 | * It can't work when the string is empty or it won't set the right background. |
| 8961 | */ |
| 8962 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8963 | can_clear(char_u *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8964 | { |
| 8965 | return (*p != NUL && (t_colors <= 1 |
| 8966 | #ifdef FEAT_GUI |
| 8967 | || gui.in_use |
| 8968 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8969 | #ifdef FEAT_TERMGUICOLORS |
| 8970 | || (p_tgc && cterm_normal_bg_gui_color != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8971 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8972 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 8973 | } |
| 8974 | |
| 8975 | /* |
| 8976 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8977 | * something directly to the screen (shell commands) or a terminal control |
| 8978 | * code. |
| 8979 | */ |
| 8980 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8981 | screen_start(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8982 | { |
| 8983 | screen_cur_row = screen_cur_col = 9999; |
| 8984 | } |
| 8985 | |
| 8986 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8987 | * Move the cursor to position "row","col" in the screen. |
| 8988 | * This tries to find the most efficient way to move, minimizing the number of |
| 8989 | * characters sent to the terminal. |
| 8990 | */ |
| 8991 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8992 | windgoto(int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8993 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8994 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8995 | int i; |
| 8996 | int plan; |
| 8997 | int cost; |
| 8998 | int wouldbe_col; |
| 8999 | int noinvcurs; |
| 9000 | char_u *bs; |
| 9001 | int goto_cost; |
| 9002 | int attr; |
| 9003 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9004 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9005 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 9006 | |
| 9007 | #define PLAN_LE 1 |
| 9008 | #define PLAN_CR 2 |
| 9009 | #define PLAN_NL 3 |
| 9010 | #define PLAN_WRITE 4 |
| 9011 | /* Can't use ScreenLines unless initialized */ |
| 9012 | if (ScreenLines == NULL) |
| 9013 | return; |
| 9014 | |
| 9015 | if (col != screen_cur_col || row != screen_cur_row) |
| 9016 | { |
| 9017 | /* Check for valid position. */ |
| 9018 | if (row < 0) /* window without text lines? */ |
| 9019 | row = 0; |
| 9020 | if (row >= screen_Rows) |
| 9021 | row = screen_Rows - 1; |
| 9022 | if (col >= screen_Columns) |
| 9023 | col = screen_Columns - 1; |
| 9024 | |
| 9025 | /* check if no cursor movement is allowed in highlight mode */ |
| 9026 | if (screen_attr && *T_MS == NUL) |
| 9027 | noinvcurs = HIGHL_COST; |
| 9028 | else |
| 9029 | noinvcurs = 0; |
| 9030 | goto_cost = GOTO_COST + noinvcurs; |
| 9031 | |
| 9032 | /* |
| 9033 | * Plan how to do the positioning: |
| 9034 | * 1. Use CR to move it to column 0, same row. |
| 9035 | * 2. Use T_LE to move it a few columns to the left. |
| 9036 | * 3. Use NL to move a few lines down, column 0. |
| 9037 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 9038 | * |
| 9039 | * Don't do this if the cursor went beyond the last column, the cursor |
| 9040 | * position is unknown then (some terminals wrap, some don't ) |
| 9041 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9042 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9043 | * characters to move the cursor to the right. |
| 9044 | */ |
| 9045 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 9046 | { |
| 9047 | /* |
| 9048 | * If the cursor is in the same row, bigger col, we can use CR |
| 9049 | * or T_LE. |
| 9050 | */ |
| 9051 | bs = NULL; /* init for GCC */ |
| 9052 | attr = screen_attr; |
| 9053 | if (row == screen_cur_row && col < screen_cur_col) |
| 9054 | { |
| 9055 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 9056 | if (*T_LE) |
| 9057 | bs = T_LE; /* "cursor left" */ |
| 9058 | else |
| 9059 | bs = T_BC; /* "backspace character (old) */ |
| 9060 | if (*bs) |
| 9061 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 9062 | else |
| 9063 | cost = 999; |
| 9064 | if (col + 1 < cost) /* using CR is less characters */ |
| 9065 | { |
| 9066 | plan = PLAN_CR; |
| 9067 | wouldbe_col = 0; |
| 9068 | cost = 1; /* CR is just one character */ |
| 9069 | } |
| 9070 | else |
| 9071 | { |
| 9072 | plan = PLAN_LE; |
| 9073 | wouldbe_col = col; |
| 9074 | } |
| 9075 | if (noinvcurs) /* will stop highlighting */ |
| 9076 | { |
| 9077 | cost += noinvcurs; |
| 9078 | attr = 0; |
| 9079 | } |
| 9080 | } |
| 9081 | |
| 9082 | /* |
| 9083 | * If the cursor is above where we want to be, we can use CR LF. |
| 9084 | */ |
| 9085 | else if (row > screen_cur_row) |
| 9086 | { |
| 9087 | plan = PLAN_NL; |
| 9088 | wouldbe_col = 0; |
| 9089 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 9090 | if (noinvcurs) /* will stop highlighting */ |
| 9091 | { |
| 9092 | cost += noinvcurs; |
| 9093 | attr = 0; |
| 9094 | } |
| 9095 | } |
| 9096 | |
| 9097 | /* |
| 9098 | * If the cursor is in the same row, smaller col, just use write. |
| 9099 | */ |
| 9100 | else |
| 9101 | { |
| 9102 | plan = PLAN_WRITE; |
| 9103 | wouldbe_col = screen_cur_col; |
| 9104 | cost = 0; |
| 9105 | } |
| 9106 | |
| 9107 | /* |
| 9108 | * Check if any characters that need to be written have the |
| 9109 | * correct attributes. Also avoid UTF-8 characters. |
| 9110 | */ |
| 9111 | i = col - wouldbe_col; |
| 9112 | if (i > 0) |
| 9113 | cost += i; |
| 9114 | if (cost < goto_cost && i > 0) |
| 9115 | { |
| 9116 | /* |
| 9117 | * Check if the attributes are correct without additionally |
| 9118 | * stopping highlighting. |
| 9119 | */ |
| 9120 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 9121 | while (i && *p++ == attr) |
| 9122 | --i; |
| 9123 | if (i != 0) |
| 9124 | { |
| 9125 | /* |
| 9126 | * Try if it works when highlighting is stopped here. |
| 9127 | */ |
| 9128 | if (*--p == 0) |
| 9129 | { |
| 9130 | cost += noinvcurs; |
| 9131 | while (i && *p++ == 0) |
| 9132 | --i; |
| 9133 | } |
| 9134 | if (i != 0) |
| 9135 | cost = 999; /* different attributes, don't do it */ |
| 9136 | } |
| 9137 | #ifdef FEAT_MBYTE |
| 9138 | if (enc_utf8) |
| 9139 | { |
| 9140 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 9141 | for (i = wouldbe_col; i < col; ++i) |
| 9142 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 9143 | { |
| 9144 | cost = 999; |
| 9145 | break; |
| 9146 | } |
| 9147 | } |
| 9148 | #endif |
| 9149 | } |
| 9150 | |
| 9151 | /* |
| 9152 | * We can do it without term_windgoto()! |
| 9153 | */ |
| 9154 | if (cost < goto_cost) |
| 9155 | { |
| 9156 | if (plan == PLAN_LE) |
| 9157 | { |
| 9158 | if (noinvcurs) |
| 9159 | screen_stop_highlight(); |
| 9160 | while (screen_cur_col > col) |
| 9161 | { |
| 9162 | out_str(bs); |
| 9163 | --screen_cur_col; |
| 9164 | } |
| 9165 | } |
| 9166 | else if (plan == PLAN_CR) |
| 9167 | { |
| 9168 | if (noinvcurs) |
| 9169 | screen_stop_highlight(); |
| 9170 | out_char('\r'); |
| 9171 | screen_cur_col = 0; |
| 9172 | } |
| 9173 | else if (plan == PLAN_NL) |
| 9174 | { |
| 9175 | if (noinvcurs) |
| 9176 | screen_stop_highlight(); |
| 9177 | while (screen_cur_row < row) |
| 9178 | { |
| 9179 | out_char('\n'); |
| 9180 | ++screen_cur_row; |
| 9181 | } |
| 9182 | screen_cur_col = 0; |
| 9183 | } |
| 9184 | |
| 9185 | i = col - screen_cur_col; |
| 9186 | if (i > 0) |
| 9187 | { |
| 9188 | /* |
| 9189 | * Use cursor-right if it's one character only. Avoids |
| 9190 | * removing a line of pixels from the last bold char, when |
| 9191 | * using the bold trick in the GUI. |
| 9192 | */ |
| 9193 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 9194 | { |
| 9195 | while (i-- > 0) |
| 9196 | out_char(*T_ND); |
| 9197 | } |
| 9198 | else |
| 9199 | { |
| 9200 | int off; |
| 9201 | |
| 9202 | off = LineOffset[row] + screen_cur_col; |
| 9203 | while (i-- > 0) |
| 9204 | { |
| 9205 | if (ScreenAttrs[off] != screen_attr) |
| 9206 | screen_stop_highlight(); |
| 9207 | #ifdef FEAT_MBYTE |
| 9208 | out_flush_check(); |
| 9209 | #endif |
| 9210 | out_char(ScreenLines[off]); |
| 9211 | #ifdef FEAT_MBYTE |
| 9212 | if (enc_dbcs == DBCS_JPNU |
| 9213 | && ScreenLines[off] == 0x8e) |
| 9214 | out_char(ScreenLines2[off]); |
| 9215 | #endif |
| 9216 | ++off; |
| 9217 | } |
| 9218 | } |
| 9219 | } |
| 9220 | } |
| 9221 | } |
| 9222 | else |
| 9223 | cost = 999; |
| 9224 | |
| 9225 | if (cost >= goto_cost) |
| 9226 | { |
| 9227 | if (noinvcurs) |
| 9228 | screen_stop_highlight(); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 9229 | if (row == screen_cur_row && (col > screen_cur_col) |
| 9230 | && *T_CRI != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9231 | term_cursor_right(col - screen_cur_col); |
| 9232 | else |
| 9233 | term_windgoto(row, col); |
| 9234 | } |
| 9235 | screen_cur_row = row; |
| 9236 | screen_cur_col = col; |
| 9237 | } |
| 9238 | } |
| 9239 | |
| 9240 | /* |
| 9241 | * Set cursor to its position in the current window. |
| 9242 | */ |
| 9243 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9244 | setcursor(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9245 | { |
| 9246 | if (redrawing()) |
| 9247 | { |
| 9248 | validate_cursor(); |
| 9249 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 9250 | W_WINCOL(curwin) + ( |
| 9251 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9252 | /* With 'rightleft' set and the cursor on a double-wide |
| 9253 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9254 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 9255 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9256 | (has_mbyte |
| 9257 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 9258 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9259 | # endif |
| 9260 | 1)) : |
| 9261 | #endif |
| 9262 | curwin->w_wcol)); |
| 9263 | } |
| 9264 | } |
| 9265 | |
| 9266 | |
| 9267 | /* |
| 9268 | * insert 'line_count' lines at 'row' in window 'wp' |
| 9269 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 9270 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 9271 | * scrolling. |
| 9272 | * Returns FAIL if the lines are not inserted, OK for success. |
| 9273 | */ |
| 9274 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9275 | win_ins_lines( |
| 9276 | win_T *wp, |
| 9277 | int row, |
| 9278 | int line_count, |
| 9279 | int invalid, |
| 9280 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9281 | { |
| 9282 | int did_delete; |
| 9283 | int nextrow; |
| 9284 | int lastrow; |
| 9285 | int retval; |
| 9286 | |
| 9287 | if (invalid) |
| 9288 | wp->w_lines_valid = 0; |
| 9289 | |
| 9290 | if (wp->w_height < 5) |
| 9291 | return FAIL; |
| 9292 | |
| 9293 | if (line_count > wp->w_height - row) |
| 9294 | line_count = wp->w_height - row; |
| 9295 | |
| 9296 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 9297 | if (retval != MAYBE) |
| 9298 | return retval; |
| 9299 | |
| 9300 | /* |
| 9301 | * If there is a next window or a status line, we first try to delete the |
| 9302 | * lines at the bottom to avoid messing what is after the window. |
| 9303 | * If this fails and there are following windows, don't do anything to avoid |
| 9304 | * messing up those windows, better just redraw. |
| 9305 | */ |
| 9306 | did_delete = FALSE; |
| 9307 | #ifdef FEAT_WINDOWS |
| 9308 | if (wp->w_next != NULL || wp->w_status_height) |
| 9309 | { |
| 9310 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9311 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 9312 | did_delete = TRUE; |
| 9313 | else if (wp->w_next) |
| 9314 | return FAIL; |
| 9315 | } |
| 9316 | #endif |
| 9317 | /* |
| 9318 | * if no lines deleted, blank the lines that will end up below the window |
| 9319 | */ |
| 9320 | if (!did_delete) |
| 9321 | { |
| 9322 | #ifdef FEAT_WINDOWS |
| 9323 | wp->w_redr_status = TRUE; |
| 9324 | #endif |
| 9325 | redraw_cmdline = TRUE; |
| 9326 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 9327 | lastrow = nextrow + line_count; |
| 9328 | if (lastrow > Rows) |
| 9329 | lastrow = Rows; |
| 9330 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 9331 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9332 | ' ', ' ', 0); |
| 9333 | } |
| 9334 | |
| 9335 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 9336 | == FAIL) |
| 9337 | { |
| 9338 | /* deletion will have messed up other windows */ |
| 9339 | if (did_delete) |
| 9340 | { |
| 9341 | #ifdef FEAT_WINDOWS |
| 9342 | wp->w_redr_status = TRUE; |
| 9343 | #endif |
| 9344 | win_rest_invalid(W_NEXT(wp)); |
| 9345 | } |
| 9346 | return FAIL; |
| 9347 | } |
| 9348 | |
| 9349 | return OK; |
| 9350 | } |
| 9351 | |
| 9352 | /* |
| 9353 | * delete "line_count" window lines at "row" in window "wp" |
| 9354 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 9355 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 9356 | * scrolling |
| 9357 | * Return OK for success, FAIL if the lines are not deleted. |
| 9358 | */ |
| 9359 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9360 | win_del_lines( |
| 9361 | win_T *wp, |
| 9362 | int row, |
| 9363 | int line_count, |
| 9364 | int invalid, |
| 9365 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9366 | { |
| 9367 | int retval; |
| 9368 | |
| 9369 | if (invalid) |
| 9370 | wp->w_lines_valid = 0; |
| 9371 | |
| 9372 | if (line_count > wp->w_height - row) |
| 9373 | line_count = wp->w_height - row; |
| 9374 | |
| 9375 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 9376 | if (retval != MAYBE) |
| 9377 | return retval; |
| 9378 | |
| 9379 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 9380 | (int)Rows, FALSE, NULL) == FAIL) |
| 9381 | return FAIL; |
| 9382 | |
| 9383 | #ifdef FEAT_WINDOWS |
| 9384 | /* |
| 9385 | * If there are windows or status lines below, try to put them at the |
| 9386 | * correct place. If we can't do that, they have to be redrawn. |
| 9387 | */ |
| 9388 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 9389 | { |
| 9390 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9391 | line_count, (int)Rows, NULL) == FAIL) |
| 9392 | { |
| 9393 | wp->w_redr_status = TRUE; |
| 9394 | win_rest_invalid(wp->w_next); |
| 9395 | } |
| 9396 | } |
| 9397 | /* |
| 9398 | * If this is the last window and there is no status line, redraw the |
| 9399 | * command line later. |
| 9400 | */ |
| 9401 | else |
| 9402 | #endif |
| 9403 | redraw_cmdline = TRUE; |
| 9404 | return OK; |
| 9405 | } |
| 9406 | |
| 9407 | /* |
| 9408 | * Common code for win_ins_lines() and win_del_lines(). |
| 9409 | * Returns OK or FAIL when the work has been done. |
| 9410 | * Returns MAYBE when not finished yet. |
| 9411 | */ |
| 9412 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9413 | win_do_lines( |
| 9414 | win_T *wp, |
| 9415 | int row, |
| 9416 | int line_count, |
| 9417 | int mayclear, |
| 9418 | int del) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9419 | { |
| 9420 | int retval; |
| 9421 | |
| 9422 | if (!redrawing() || line_count <= 0) |
| 9423 | return FAIL; |
| 9424 | |
| 9425 | /* only a few lines left: redraw is faster */ |
| 9426 | if (mayclear && Rows - line_count < 5 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9427 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9428 | && wp->w_width == Columns |
| 9429 | #endif |
| 9430 | ) |
| 9431 | { |
| 9432 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 9433 | return FAIL; |
| 9434 | } |
| 9435 | |
| 9436 | /* |
| 9437 | * Delete all remaining lines |
| 9438 | */ |
| 9439 | if (row + line_count >= wp->w_height) |
| 9440 | { |
| 9441 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 9442 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9443 | ' ', ' ', 0); |
| 9444 | return OK; |
| 9445 | } |
| 9446 | |
| 9447 | /* |
| 9448 | * when scrolling, the message on the command line should be cleared, |
| 9449 | * otherwise it will stay there forever. |
| 9450 | */ |
| 9451 | clear_cmdline = TRUE; |
| 9452 | |
| 9453 | /* |
| 9454 | * If the terminal can set a scroll region, use that. |
| 9455 | * Always do this in a vertically split window. This will redraw from |
| 9456 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 9457 | * win_line(). |
| 9458 | * 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] | 9459 | * a character in the lower right corner of the scroll region may cause a |
| 9460 | * scroll-up . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9461 | */ |
| 9462 | if (scroll_region |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9463 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9464 | || W_WIDTH(wp) != Columns |
| 9465 | #endif |
| 9466 | ) |
| 9467 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9468 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9469 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9470 | #endif |
| 9471 | scroll_region_set(wp, row); |
| 9472 | if (del) |
| 9473 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 9474 | wp->w_height - row, FALSE, wp); |
| 9475 | else |
| 9476 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 9477 | wp->w_height - row, wp); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9478 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9479 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9480 | #endif |
| 9481 | scroll_region_reset(); |
| 9482 | return retval; |
| 9483 | } |
| 9484 | |
| 9485 | #ifdef FEAT_WINDOWS |
| 9486 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 9487 | return FAIL; |
| 9488 | #endif |
| 9489 | |
| 9490 | return MAYBE; |
| 9491 | } |
| 9492 | |
| 9493 | /* |
| 9494 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 9495 | */ |
| 9496 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9497 | win_rest_invalid(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9498 | { |
| 9499 | #ifdef FEAT_WINDOWS |
| 9500 | while (wp != NULL) |
| 9501 | #else |
| 9502 | if (wp != NULL) |
| 9503 | #endif |
| 9504 | { |
| 9505 | redraw_win_later(wp, NOT_VALID); |
| 9506 | #ifdef FEAT_WINDOWS |
| 9507 | wp->w_redr_status = TRUE; |
| 9508 | wp = wp->w_next; |
| 9509 | #endif |
| 9510 | } |
| 9511 | redraw_cmdline = TRUE; |
| 9512 | } |
| 9513 | |
| 9514 | /* |
| 9515 | * The rest of the routines in this file perform screen manipulations. The |
| 9516 | * given operation is performed physically on the screen. The corresponding |
| 9517 | * change is also made to the internal screen image. In this way, the editor |
| 9518 | * anticipates the effect of editing changes on the appearance of the screen. |
| 9519 | * That way, when we call screenupdate a complete redraw isn't usually |
| 9520 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 9521 | * screen changes, and in the meantime, everything still works. |
| 9522 | */ |
| 9523 | |
| 9524 | /* |
| 9525 | * types for inserting or deleting lines |
| 9526 | */ |
| 9527 | #define USE_T_CAL 1 |
| 9528 | #define USE_T_CDL 2 |
| 9529 | #define USE_T_AL 3 |
| 9530 | #define USE_T_CE 4 |
| 9531 | #define USE_T_DL 5 |
| 9532 | #define USE_T_SR 6 |
| 9533 | #define USE_NL 7 |
| 9534 | #define USE_T_CD 8 |
| 9535 | #define USE_REDRAW 9 |
| 9536 | |
| 9537 | /* |
| 9538 | * insert lines on the screen and update ScreenLines[] |
| 9539 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9540 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9541 | * 'row' and 'end' are relative to the start of the region. |
| 9542 | * |
| 9543 | * return FAIL for failure, OK for success. |
| 9544 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9545 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9546 | screen_ins_lines( |
| 9547 | int off, |
| 9548 | int row, |
| 9549 | int line_count, |
| 9550 | int end, |
| 9551 | win_T *wp) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9552 | { |
| 9553 | int i; |
| 9554 | int j; |
| 9555 | unsigned temp; |
| 9556 | int cursor_row; |
| 9557 | int type; |
| 9558 | int result_empty; |
| 9559 | int can_ce = can_clear(T_CE); |
| 9560 | |
| 9561 | /* |
| 9562 | * FAIL if |
| 9563 | * - there is no valid screen |
| 9564 | * - the screen has to be redrawn completely |
| 9565 | * - the line count is less than one |
| 9566 | * - the line count is more than 'ttyscroll' |
| 9567 | */ |
| 9568 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9569 | return FAIL; |
| 9570 | |
| 9571 | /* |
| 9572 | * There are seven ways to insert lines: |
| 9573 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9574 | * characters from ScreenLines[]. |
| 9575 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9576 | * the insert is just empty lines |
| 9577 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9578 | * present or line_count > 1. It looks better if we do all the inserts |
| 9579 | * at once. |
| 9580 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9581 | * insert is just empty lines and T_CE is not present or line_count > |
| 9582 | * 1. |
| 9583 | * 4. Use T_AL (insert line) if it exists. |
| 9584 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9585 | * just empty lines. |
| 9586 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9587 | * just empty lines. |
| 9588 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9589 | * the 'da' flag is not set or we have clear line capability. |
| 9590 | * 8. redraw the characters from ScreenLines[]. |
| 9591 | * |
| 9592 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9593 | * the scrollbar for the window. It does have insert line, use that if it |
| 9594 | * exists. |
| 9595 | */ |
| 9596 | result_empty = (row + line_count >= end); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9597 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9598 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9599 | type = USE_REDRAW; |
| 9600 | else |
| 9601 | #endif |
| 9602 | if (can_clear(T_CD) && result_empty) |
| 9603 | type = USE_T_CD; |
| 9604 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9605 | type = USE_T_CAL; |
| 9606 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9607 | type = USE_T_CDL; |
| 9608 | else if (*T_AL != NUL) |
| 9609 | type = USE_T_AL; |
| 9610 | else if (can_ce && result_empty) |
| 9611 | type = USE_T_CE; |
| 9612 | else if (*T_DL != NUL && result_empty) |
| 9613 | type = USE_T_DL; |
| 9614 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9615 | type = USE_T_SR; |
| 9616 | else |
| 9617 | return FAIL; |
| 9618 | |
| 9619 | /* |
| 9620 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9621 | * care of t_db if necessary. |
| 9622 | */ |
| 9623 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9624 | type == USE_T_CE || type == USE_T_DL) |
| 9625 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9626 | |
| 9627 | /* |
| 9628 | * If text is retained below the screen, first clear or delete as many |
| 9629 | * lines at the bottom of the window as are about to be inserted so that |
| 9630 | * the deleted lines won't later surface during a screen_del_lines. |
| 9631 | */ |
| 9632 | if (*T_DB) |
| 9633 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9634 | |
| 9635 | #ifdef FEAT_CLIPBOARD |
| 9636 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9637 | * or not the full width of the screen. */ |
| 9638 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9639 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9640 | || (wp != NULL && wp->w_width != Columns) |
| 9641 | # endif |
| 9642 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9643 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9644 | else |
| 9645 | clip_scroll_selection(-line_count); |
| 9646 | #endif |
| 9647 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9648 | #ifdef FEAT_GUI |
| 9649 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9650 | * scrolling is actually carried out. */ |
| 9651 | gui_dont_update_cursor(); |
| 9652 | #endif |
| 9653 | |
| 9654 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9655 | cursor_row = row; |
| 9656 | else |
| 9657 | cursor_row = row + off; |
| 9658 | |
| 9659 | /* |
| 9660 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9661 | * Clear the inserted lines in ScreenLines[]. |
| 9662 | */ |
| 9663 | row += off; |
| 9664 | end += off; |
| 9665 | for (i = 0; i < line_count; ++i) |
| 9666 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9667 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9668 | if (wp != NULL && wp->w_width != Columns) |
| 9669 | { |
| 9670 | /* need to copy part of a line */ |
| 9671 | j = end - 1 - i; |
| 9672 | while ((j -= line_count) >= row) |
| 9673 | linecopy(j + line_count, j, wp); |
| 9674 | j += line_count; |
| 9675 | if (can_clear((char_u *)" ")) |
| 9676 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9677 | else |
| 9678 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9679 | LineWraps[j] = FALSE; |
| 9680 | } |
| 9681 | else |
| 9682 | #endif |
| 9683 | { |
| 9684 | j = end - 1 - i; |
| 9685 | temp = LineOffset[j]; |
| 9686 | while ((j -= line_count) >= row) |
| 9687 | { |
| 9688 | LineOffset[j + line_count] = LineOffset[j]; |
| 9689 | LineWraps[j + line_count] = LineWraps[j]; |
| 9690 | } |
| 9691 | LineOffset[j + line_count] = temp; |
| 9692 | LineWraps[j + line_count] = FALSE; |
| 9693 | if (can_clear((char_u *)" ")) |
| 9694 | lineclear(temp, (int)Columns); |
| 9695 | else |
| 9696 | lineinvalid(temp, (int)Columns); |
| 9697 | } |
| 9698 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9699 | |
| 9700 | screen_stop_highlight(); |
| 9701 | windgoto(cursor_row, 0); |
| 9702 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9703 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9704 | /* redraw the characters */ |
| 9705 | if (type == USE_REDRAW) |
| 9706 | redraw_block(row, end, wp); |
| 9707 | else |
| 9708 | #endif |
| 9709 | if (type == USE_T_CAL) |
| 9710 | { |
| 9711 | term_append_lines(line_count); |
| 9712 | screen_start(); /* don't know where cursor is now */ |
| 9713 | } |
| 9714 | else |
| 9715 | { |
| 9716 | for (i = 0; i < line_count; i++) |
| 9717 | { |
| 9718 | if (type == USE_T_AL) |
| 9719 | { |
| 9720 | if (i && cursor_row != 0) |
| 9721 | windgoto(cursor_row, 0); |
| 9722 | out_str(T_AL); |
| 9723 | } |
| 9724 | else /* type == USE_T_SR */ |
| 9725 | out_str(T_SR); |
| 9726 | screen_start(); /* don't know where cursor is now */ |
| 9727 | } |
| 9728 | } |
| 9729 | |
| 9730 | /* |
| 9731 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9732 | * have been scrolled down into the region. |
| 9733 | */ |
| 9734 | if (type == USE_T_SR && *T_DA) |
| 9735 | { |
| 9736 | for (i = 0; i < line_count; ++i) |
| 9737 | { |
| 9738 | windgoto(off + i, 0); |
| 9739 | out_str(T_CE); |
| 9740 | screen_start(); /* don't know where cursor is now */ |
| 9741 | } |
| 9742 | } |
| 9743 | |
| 9744 | #ifdef FEAT_GUI |
| 9745 | gui_can_update_cursor(); |
| 9746 | if (gui.in_use) |
| 9747 | out_flush(); /* always flush after a scroll */ |
| 9748 | #endif |
| 9749 | return OK; |
| 9750 | } |
| 9751 | |
| 9752 | /* |
| 9753 | * delete lines on the screen and update ScreenLines[] |
| 9754 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9755 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9756 | * 'row' and 'end' are relative to the start of the region. |
| 9757 | * |
| 9758 | * Return OK for success, FAIL if the lines are not deleted. |
| 9759 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9760 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9761 | screen_del_lines( |
| 9762 | int off, |
| 9763 | int row, |
| 9764 | int line_count, |
| 9765 | int end, |
| 9766 | int force, /* even when line_count > p_ttyscroll */ |
| 9767 | win_T *wp UNUSED) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9768 | { |
| 9769 | int j; |
| 9770 | int i; |
| 9771 | unsigned temp; |
| 9772 | int cursor_row; |
| 9773 | int cursor_end; |
| 9774 | int result_empty; /* result is empty until end of region */ |
| 9775 | int can_delete; /* deleting line codes can be used */ |
| 9776 | int type; |
| 9777 | |
| 9778 | /* |
| 9779 | * FAIL if |
| 9780 | * - there is no valid screen |
| 9781 | * - the screen has to be redrawn completely |
| 9782 | * - the line count is less than one |
| 9783 | * - the line count is more than 'ttyscroll' |
| 9784 | */ |
| 9785 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9786 | (!force && line_count > p_ttyscroll)) |
| 9787 | return FAIL; |
| 9788 | |
| 9789 | /* |
| 9790 | * Check if the rest of the current region will become empty. |
| 9791 | */ |
| 9792 | result_empty = row + line_count >= end; |
| 9793 | |
| 9794 | /* |
| 9795 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9796 | * available. |
| 9797 | */ |
| 9798 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9799 | |
| 9800 | /* |
| 9801 | * There are six ways to delete lines: |
| 9802 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9803 | * characters from ScreenLines[]. |
| 9804 | * 1. Use T_CD if it exists and the result is empty. |
| 9805 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9806 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9807 | * none of the other ways work. |
| 9808 | * 4. Use T_CE (erase line) if the result is empty. |
| 9809 | * 5. Use T_DL (delete line) if it exists. |
| 9810 | * 6. redraw the characters from ScreenLines[]. |
| 9811 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9812 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9813 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9814 | type = USE_REDRAW; |
| 9815 | else |
| 9816 | #endif |
| 9817 | if (can_clear(T_CD) && result_empty) |
| 9818 | type = USE_T_CD; |
| 9819 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9820 | /* |
| 9821 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9822 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9823 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9824 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9825 | * the trick... |
| 9826 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9827 | * (Olaf Seibert) |
| 9828 | */ |
| 9829 | else if (row == 0 && T_DB == empty_option |
| 9830 | && (line_count == 1 || *T_CDL == NUL)) |
| 9831 | #else |
| 9832 | else if (row == 0 && ( |
| 9833 | #ifndef AMIGA |
| 9834 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9835 | * up, so use delete-line command */ |
| 9836 | line_count == 1 || |
| 9837 | #endif |
| 9838 | *T_CDL == NUL)) |
| 9839 | #endif |
| 9840 | type = USE_NL; |
| 9841 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9842 | type = USE_T_CDL; |
| 9843 | else if (can_clear(T_CE) && result_empty |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9844 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9845 | && (wp == NULL || wp->w_width == Columns) |
| 9846 | #endif |
| 9847 | ) |
| 9848 | type = USE_T_CE; |
| 9849 | else if (*T_DL != NUL && can_delete) |
| 9850 | type = USE_T_DL; |
| 9851 | else if (*T_CDL != NUL && can_delete) |
| 9852 | type = USE_T_CDL; |
| 9853 | else |
| 9854 | return FAIL; |
| 9855 | |
| 9856 | #ifdef FEAT_CLIPBOARD |
| 9857 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9858 | * not the full width of the screen. */ |
| 9859 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9860 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9861 | || (wp != NULL && wp->w_width != Columns) |
| 9862 | # endif |
| 9863 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9864 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9865 | else |
| 9866 | clip_scroll_selection(line_count); |
| 9867 | #endif |
| 9868 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9869 | #ifdef FEAT_GUI |
| 9870 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9871 | * scrolling is actually carried out. */ |
| 9872 | gui_dont_update_cursor(); |
| 9873 | #endif |
| 9874 | |
| 9875 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9876 | { |
| 9877 | cursor_row = row; |
| 9878 | cursor_end = end; |
| 9879 | } |
| 9880 | else |
| 9881 | { |
| 9882 | cursor_row = row + off; |
| 9883 | cursor_end = end + off; |
| 9884 | } |
| 9885 | |
| 9886 | /* |
| 9887 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9888 | * Clear the inserted lines in ScreenLines[]. |
| 9889 | */ |
| 9890 | row += off; |
| 9891 | end += off; |
| 9892 | for (i = 0; i < line_count; ++i) |
| 9893 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9894 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9895 | if (wp != NULL && wp->w_width != Columns) |
| 9896 | { |
| 9897 | /* need to copy part of a line */ |
| 9898 | j = row + i; |
| 9899 | while ((j += line_count) <= end - 1) |
| 9900 | linecopy(j - line_count, j, wp); |
| 9901 | j -= line_count; |
| 9902 | if (can_clear((char_u *)" ")) |
| 9903 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9904 | else |
| 9905 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9906 | LineWraps[j] = FALSE; |
| 9907 | } |
| 9908 | else |
| 9909 | #endif |
| 9910 | { |
| 9911 | /* whole width, moving the line pointers is faster */ |
| 9912 | j = row + i; |
| 9913 | temp = LineOffset[j]; |
| 9914 | while ((j += line_count) <= end - 1) |
| 9915 | { |
| 9916 | LineOffset[j - line_count] = LineOffset[j]; |
| 9917 | LineWraps[j - line_count] = LineWraps[j]; |
| 9918 | } |
| 9919 | LineOffset[j - line_count] = temp; |
| 9920 | LineWraps[j - line_count] = FALSE; |
| 9921 | if (can_clear((char_u *)" ")) |
| 9922 | lineclear(temp, (int)Columns); |
| 9923 | else |
| 9924 | lineinvalid(temp, (int)Columns); |
| 9925 | } |
| 9926 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9927 | |
| 9928 | screen_stop_highlight(); |
| 9929 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9930 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9931 | /* redraw the characters */ |
| 9932 | if (type == USE_REDRAW) |
| 9933 | redraw_block(row, end, wp); |
| 9934 | else |
| 9935 | #endif |
| 9936 | if (type == USE_T_CD) /* delete the lines */ |
| 9937 | { |
| 9938 | windgoto(cursor_row, 0); |
| 9939 | out_str(T_CD); |
| 9940 | screen_start(); /* don't know where cursor is now */ |
| 9941 | } |
| 9942 | else if (type == USE_T_CDL) |
| 9943 | { |
| 9944 | windgoto(cursor_row, 0); |
| 9945 | term_delete_lines(line_count); |
| 9946 | screen_start(); /* don't know where cursor is now */ |
| 9947 | } |
| 9948 | /* |
| 9949 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9950 | * the whole screen (scroll region) up by outputting newlines on the |
| 9951 | * last line. |
| 9952 | */ |
| 9953 | else if (type == USE_NL) |
| 9954 | { |
| 9955 | windgoto(cursor_end - 1, 0); |
| 9956 | for (i = line_count; --i >= 0; ) |
| 9957 | out_char('\n'); /* cursor will remain on same line */ |
| 9958 | } |
| 9959 | else |
| 9960 | { |
| 9961 | for (i = line_count; --i >= 0; ) |
| 9962 | { |
| 9963 | if (type == USE_T_DL) |
| 9964 | { |
| 9965 | windgoto(cursor_row, 0); |
| 9966 | out_str(T_DL); /* delete a line */ |
| 9967 | } |
| 9968 | else /* type == USE_T_CE */ |
| 9969 | { |
| 9970 | windgoto(cursor_row + i, 0); |
| 9971 | out_str(T_CE); /* erase a line */ |
| 9972 | } |
| 9973 | screen_start(); /* don't know where cursor is now */ |
| 9974 | } |
| 9975 | } |
| 9976 | |
| 9977 | /* |
| 9978 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9979 | * scrolled up at the bottom of the region. |
| 9980 | */ |
| 9981 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9982 | { |
| 9983 | for (i = line_count; i > 0; --i) |
| 9984 | { |
| 9985 | windgoto(cursor_end - i, 0); |
| 9986 | out_str(T_CE); /* erase a line */ |
| 9987 | screen_start(); /* don't know where cursor is now */ |
| 9988 | } |
| 9989 | } |
| 9990 | |
| 9991 | #ifdef FEAT_GUI |
| 9992 | gui_can_update_cursor(); |
| 9993 | if (gui.in_use) |
| 9994 | out_flush(); /* always flush after a scroll */ |
| 9995 | #endif |
| 9996 | |
| 9997 | return OK; |
| 9998 | } |
| 9999 | |
| 10000 | /* |
| 10001 | * show the current mode and ruler |
| 10002 | * |
| 10003 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 10004 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 10005 | * cleared only if a mode is shown. |
| 10006 | * Return the length of the message (0 if no message). |
| 10007 | */ |
| 10008 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10009 | showmode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10010 | { |
| 10011 | int need_clear; |
| 10012 | int length = 0; |
| 10013 | int do_mode; |
| 10014 | int attr; |
| 10015 | int nwr_save; |
| 10016 | #ifdef FEAT_INS_EXPAND |
| 10017 | int sub_attr; |
| 10018 | #endif |
| 10019 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 10020 | do_mode = ((p_smd && msg_silent == 0) |
| 10021 | && ((State & INSERT) |
| 10022 | || restart_edit |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 10023 | || VIsual_active)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10024 | if (do_mode || Recording) |
| 10025 | { |
| 10026 | /* |
| 10027 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 10028 | * Call char_avail() only when we are going to show something, because |
| 10029 | * it takes a bit of time. |
| 10030 | */ |
| 10031 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 10032 | { |
| 10033 | redraw_cmdline = TRUE; /* show mode later */ |
| 10034 | return 0; |
| 10035 | } |
| 10036 | |
| 10037 | nwr_save = need_wait_return; |
| 10038 | |
| 10039 | /* wait a bit before overwriting an important message */ |
| 10040 | check_for_delay(FALSE); |
| 10041 | |
| 10042 | /* if the cmdline is more than one line high, erase top lines */ |
| 10043 | need_clear = clear_cmdline; |
| 10044 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 10045 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 10046 | |
| 10047 | /* Position on the last line in the window, column 0 */ |
| 10048 | msg_pos_mode(); |
| 10049 | cursor_off(); |
| 10050 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 10051 | if (do_mode) |
| 10052 | { |
| 10053 | MSG_PUTS_ATTR("--", attr); |
| 10054 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10055 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10056 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10057 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10058 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10059 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10060 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10061 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 10062 | # 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] | 10063 | MSG_PUTS_ATTR(" IM", attr); |
| 10064 | # else |
| 10065 | MSG_PUTS_ATTR(" XIM", attr); |
| 10066 | # endif |
| 10067 | #endif |
| 10068 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 10069 | if (gui.in_use) |
| 10070 | { |
| 10071 | if (hangul_input_state_get()) |
Bram Moolenaar | 72f4cc4 | 2015-11-10 14:35:18 +0100 | [diff] [blame] | 10072 | { |
| 10073 | /* HANGUL */ |
| 10074 | if (enc_utf8) |
| 10075 | MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr); |
| 10076 | else |
| 10077 | MSG_PUTS_ATTR(" \307\321\261\333", attr); |
| 10078 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10079 | } |
| 10080 | #endif |
| 10081 | #ifdef FEAT_INS_EXPAND |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 10082 | /* CTRL-X in Insert mode */ |
| 10083 | if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10084 | { |
| 10085 | /* These messages can get long, avoid a wrap in a narrow |
| 10086 | * window. Prefer showing edit_submode_extra. */ |
| 10087 | length = (Rows - msg_row) * Columns - 3; |
| 10088 | if (edit_submode_extra != NULL) |
| 10089 | length -= vim_strsize(edit_submode_extra); |
| 10090 | if (length > 0) |
| 10091 | { |
| 10092 | if (edit_submode_pre != NULL) |
| 10093 | length -= vim_strsize(edit_submode_pre); |
| 10094 | if (length - vim_strsize(edit_submode) > 0) |
| 10095 | { |
| 10096 | if (edit_submode_pre != NULL) |
| 10097 | msg_puts_attr(edit_submode_pre, attr); |
| 10098 | msg_puts_attr(edit_submode, attr); |
| 10099 | } |
| 10100 | if (edit_submode_extra != NULL) |
| 10101 | { |
| 10102 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 10103 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 10104 | sub_attr = hl_attr(edit_submode_highl); |
| 10105 | else |
| 10106 | sub_attr = attr; |
| 10107 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 10108 | } |
| 10109 | } |
| 10110 | length = 0; |
| 10111 | } |
| 10112 | else |
| 10113 | #endif |
| 10114 | { |
| 10115 | #ifdef FEAT_VREPLACE |
| 10116 | if (State & VREPLACE_FLAG) |
| 10117 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 10118 | else |
| 10119 | #endif |
| 10120 | if (State & REPLACE_FLAG) |
| 10121 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 10122 | else if (State & INSERT) |
| 10123 | { |
| 10124 | #ifdef FEAT_RIGHTLEFT |
| 10125 | if (p_ri) |
| 10126 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 10127 | #endif |
| 10128 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 10129 | } |
| 10130 | else if (restart_edit == 'I') |
| 10131 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 10132 | else if (restart_edit == 'R') |
| 10133 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 10134 | else if (restart_edit == 'V') |
| 10135 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 10136 | #ifdef FEAT_RIGHTLEFT |
| 10137 | if (p_hkmap) |
| 10138 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 10139 | # ifdef FEAT_FKMAP |
| 10140 | if (p_fkmap) |
| 10141 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 10142 | # endif |
| 10143 | #endif |
| 10144 | #ifdef FEAT_KEYMAP |
| 10145 | if (State & LANGMAP) |
| 10146 | { |
| 10147 | # ifdef FEAT_ARABIC |
| 10148 | if (curwin->w_p_arab) |
| 10149 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 10150 | else |
| 10151 | # endif |
| 10152 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 10153 | } |
| 10154 | #endif |
| 10155 | if ((State & INSERT) && p_paste) |
| 10156 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 10157 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10158 | if (VIsual_active) |
| 10159 | { |
| 10160 | char *p; |
| 10161 | |
| 10162 | /* Don't concatenate separate words to avoid translation |
| 10163 | * problems. */ |
| 10164 | switch ((VIsual_select ? 4 : 0) |
| 10165 | + (VIsual_mode == Ctrl_V) * 2 |
| 10166 | + (VIsual_mode == 'V')) |
| 10167 | { |
| 10168 | case 0: p = N_(" VISUAL"); break; |
| 10169 | case 1: p = N_(" VISUAL LINE"); break; |
| 10170 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 10171 | case 4: p = N_(" SELECT"); break; |
| 10172 | case 5: p = N_(" SELECT LINE"); break; |
| 10173 | default: p = N_(" SELECT BLOCK"); break; |
| 10174 | } |
| 10175 | MSG_PUTS_ATTR(_(p), attr); |
| 10176 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10177 | MSG_PUTS_ATTR(" --", attr); |
| 10178 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10179 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10180 | need_clear = TRUE; |
| 10181 | } |
| 10182 | if (Recording |
| 10183 | #ifdef FEAT_INS_EXPAND |
| 10184 | && edit_submode == NULL /* otherwise it gets too long */ |
| 10185 | #endif |
| 10186 | ) |
| 10187 | { |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10188 | recording_mode(attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10189 | need_clear = TRUE; |
| 10190 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10191 | |
| 10192 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10193 | if (need_clear || clear_cmdline) |
| 10194 | msg_clr_eos(); |
| 10195 | msg_didout = FALSE; /* overwrite this message */ |
| 10196 | length = msg_col; |
| 10197 | msg_col = 0; |
| 10198 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 10199 | } |
| 10200 | else if (clear_cmdline && msg_silent == 0) |
| 10201 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 10202 | msg_clr_cmdline(); |
| 10203 | |
| 10204 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10205 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 10206 | if (VIsual_active) |
| 10207 | clear_showcmd(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10208 | |
| 10209 | /* If the last window has no status line, the ruler is after the mode |
| 10210 | * message and must be redrawn */ |
| 10211 | if (redrawing() |
| 10212 | # ifdef FEAT_WINDOWS |
| 10213 | && lastwin->w_status_height == 0 |
| 10214 | # endif |
| 10215 | ) |
| 10216 | win_redr_ruler(lastwin, TRUE); |
| 10217 | #endif |
| 10218 | redraw_cmdline = FALSE; |
| 10219 | clear_cmdline = FALSE; |
| 10220 | |
| 10221 | return length; |
| 10222 | } |
| 10223 | |
| 10224 | /* |
| 10225 | * Position for a mode message. |
| 10226 | */ |
| 10227 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10228 | msg_pos_mode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10229 | { |
| 10230 | msg_col = 0; |
| 10231 | msg_row = Rows - 1; |
| 10232 | } |
| 10233 | |
| 10234 | /* |
| 10235 | * Delete mode message. Used when ESC is typed which is expected to end |
| 10236 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10237 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10238 | */ |
| 10239 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10240 | unshowmode(int force) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10241 | { |
| 10242 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 10243 | * 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] | 10244 | */ |
| 10245 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 10246 | redraw_cmdline = TRUE; /* delete mode later */ |
| 10247 | else |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10248 | clearmode(); |
| 10249 | } |
| 10250 | |
| 10251 | /* |
| 10252 | * Clear the mode message. |
| 10253 | */ |
| 10254 | void |
| 10255 | clearmode() |
| 10256 | { |
| 10257 | msg_pos_mode(); |
| 10258 | if (Recording) |
| 10259 | recording_mode(hl_attr(HLF_CM)); |
| 10260 | msg_clr_eos(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10261 | } |
| 10262 | |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10263 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10264 | recording_mode(int attr) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10265 | { |
| 10266 | MSG_PUTS_ATTR(_("recording"), attr); |
| 10267 | if (!shortmess(SHM_RECORDING)) |
| 10268 | { |
| 10269 | char_u s[4]; |
| 10270 | sprintf((char *)s, " @%c", Recording); |
| 10271 | MSG_PUTS_ATTR(s, attr); |
| 10272 | } |
| 10273 | } |
| 10274 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10275 | #if defined(FEAT_WINDOWS) |
| 10276 | /* |
| 10277 | * Draw the tab pages line at the top of the Vim window. |
| 10278 | */ |
| 10279 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10280 | draw_tabline(void) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10281 | { |
| 10282 | int tabcount = 0; |
| 10283 | tabpage_T *tp; |
| 10284 | int tabwidth; |
| 10285 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10286 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10287 | int attr; |
| 10288 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10289 | win_T *cwp; |
| 10290 | int wincount; |
| 10291 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10292 | int c; |
| 10293 | int len; |
| 10294 | int attr_sel = hl_attr(HLF_TPS); |
| 10295 | int attr_nosel = hl_attr(HLF_TP); |
| 10296 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10297 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10298 | int room; |
| 10299 | int use_sep_chars = (t_colors < 8 |
| 10300 | #ifdef FEAT_GUI |
| 10301 | && !gui.in_use |
| 10302 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 10303 | #ifdef FEAT_TERMGUICOLORS |
| 10304 | && !p_tgc |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 10305 | #endif |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10306 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10307 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10308 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10309 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10310 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 10311 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10312 | if (gui_use_tabline()) |
| 10313 | { |
| 10314 | gui_update_tabline(); |
| 10315 | return; |
| 10316 | } |
| 10317 | #endif |
| 10318 | |
| 10319 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10320 | return; |
| 10321 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10322 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10323 | |
| 10324 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 10325 | for (scol = 0; scol < Columns; ++scol) |
| 10326 | TabPageIdxs[scol] = 0; |
| 10327 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10328 | /* Use the 'tabline' option if it's set. */ |
| 10329 | if (*p_tal != NUL) |
| 10330 | { |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10331 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10332 | |
| 10333 | /* Check for an error. If there is one we would loop in redrawing the |
| 10334 | * screen. Avoid that by making 'tabline' empty. */ |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10335 | did_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10336 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10337 | if (did_emsg) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10338 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10339 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10340 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10341 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10342 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10343 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10344 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10345 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 10346 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10347 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10348 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 10349 | if (tabwidth < 6) |
| 10350 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10351 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10352 | attr = attr_nosel; |
| 10353 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10354 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10355 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 10356 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10357 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10358 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10359 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10360 | if (tp->tp_topframe == topframe) |
| 10361 | attr = attr_sel; |
| 10362 | if (use_sep_chars && col > 0) |
| 10363 | screen_putchar('|', 0, col++, attr); |
| 10364 | |
| 10365 | if (tp->tp_topframe != topframe) |
| 10366 | attr = attr_nosel; |
| 10367 | |
| 10368 | screen_putchar(' ', 0, col++, attr); |
| 10369 | |
| 10370 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10371 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10372 | cwp = curwin; |
| 10373 | wp = firstwin; |
| 10374 | } |
| 10375 | else |
| 10376 | { |
| 10377 | cwp = tp->tp_curwin; |
| 10378 | wp = tp->tp_firstwin; |
| 10379 | } |
| 10380 | |
| 10381 | modified = FALSE; |
| 10382 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 10383 | if (bufIsChanged(wp->w_buffer)) |
| 10384 | modified = TRUE; |
| 10385 | if (modified || wincount > 1) |
| 10386 | { |
| 10387 | if (wincount > 1) |
| 10388 | { |
| 10389 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10390 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10391 | if (col + len >= Columns - 3) |
| 10392 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10393 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10394 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10395 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10396 | #else |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10397 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10398 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10399 | ); |
| 10400 | col += len; |
| 10401 | } |
| 10402 | if (modified) |
| 10403 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 10404 | screen_putchar(' ', 0, col++, attr); |
| 10405 | } |
| 10406 | |
| 10407 | room = scol - col + tabwidth - 1; |
| 10408 | if (room > 0) |
| 10409 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10410 | /* Get buffer name in NameBuff[] */ |
| 10411 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 10412 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10413 | len = vim_strsize(NameBuff); |
| 10414 | p = NameBuff; |
| 10415 | #ifdef FEAT_MBYTE |
| 10416 | if (has_mbyte) |
| 10417 | while (len > room) |
| 10418 | { |
| 10419 | len -= ptr2cells(p); |
| 10420 | mb_ptr_adv(p); |
| 10421 | } |
| 10422 | else |
| 10423 | #endif |
| 10424 | if (len > room) |
| 10425 | { |
| 10426 | p += len - room; |
| 10427 | len = room; |
| 10428 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10429 | if (len > Columns - col - 1) |
| 10430 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10431 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10432 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10433 | col += len; |
| 10434 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10435 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10436 | |
| 10437 | /* Store the tab page number in TabPageIdxs[], so that |
| 10438 | * jump_to_mouse() knows where each one is. */ |
| 10439 | ++tabcount; |
| 10440 | while (scol < col) |
| 10441 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10442 | } |
| 10443 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10444 | if (use_sep_chars) |
| 10445 | c = '_'; |
| 10446 | else |
| 10447 | c = ' '; |
| 10448 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10449 | |
| 10450 | /* Put an "X" for closing the current tab if there are several. */ |
| 10451 | if (first_tabpage->tp_next != NULL) |
| 10452 | { |
| 10453 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 10454 | TabPageIdxs[Columns - 1] = -999; |
| 10455 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10456 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 10457 | |
| 10458 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 10459 | * set. */ |
| 10460 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10461 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10462 | |
| 10463 | /* |
| 10464 | * Get buffer name for "buf" into NameBuff[]. |
| 10465 | * Takes care of special buffer names and translates special characters. |
| 10466 | */ |
| 10467 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10468 | get_trans_bufname(buf_T *buf) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10469 | { |
| 10470 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 10471 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10472 | else |
| 10473 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 10474 | trans_characters(NameBuff, MAXPATHL); |
| 10475 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10476 | #endif |
| 10477 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10478 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 10479 | /* |
| 10480 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 10481 | */ |
| 10482 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10483 | fillchar_status(int *attr, int is_curwin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10484 | { |
| 10485 | int fill; |
| 10486 | if (is_curwin) |
| 10487 | { |
| 10488 | *attr = hl_attr(HLF_S); |
| 10489 | fill = fill_stl; |
| 10490 | } |
| 10491 | else |
| 10492 | { |
| 10493 | *attr = hl_attr(HLF_SNC); |
| 10494 | fill = fill_stlnc; |
| 10495 | } |
| 10496 | /* Use fill when there is highlighting, and highlighting of current |
| 10497 | * window differs, or the fillchars differ, or this is not the |
| 10498 | * current window */ |
| 10499 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 10500 | || !is_curwin || firstwin == lastwin) |
| 10501 | || (fill_stl != fill_stlnc))) |
| 10502 | return fill; |
| 10503 | if (is_curwin) |
| 10504 | return '^'; |
| 10505 | return '='; |
| 10506 | } |
| 10507 | #endif |
| 10508 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10509 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10510 | /* |
| 10511 | * Get the character to use in a separator between vertically split windows. |
| 10512 | * Get its attributes in "*attr". |
| 10513 | */ |
| 10514 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10515 | fillchar_vsep(int *attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10516 | { |
| 10517 | *attr = hl_attr(HLF_C); |
| 10518 | if (*attr == 0 && fill_vert == ' ') |
| 10519 | return '|'; |
| 10520 | else |
| 10521 | return fill_vert; |
| 10522 | } |
| 10523 | #endif |
| 10524 | |
| 10525 | /* |
| 10526 | * Return TRUE if redrawing should currently be done. |
| 10527 | */ |
| 10528 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10529 | redrawing(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10530 | { |
| 10531 | return (!RedrawingDisabled |
| 10532 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 10533 | } |
| 10534 | |
| 10535 | /* |
| 10536 | * Return TRUE if printing messages should currently be done. |
| 10537 | */ |
| 10538 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10539 | messaging(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10540 | { |
| 10541 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10542 | } |
| 10543 | |
| 10544 | /* |
| 10545 | * Show current status info in ruler and various other places |
| 10546 | * If always is FALSE, only show ruler if position has changed. |
| 10547 | */ |
| 10548 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10549 | showruler(int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10550 | { |
| 10551 | if (!always && !redrawing()) |
| 10552 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10553 | #ifdef FEAT_INS_EXPAND |
| 10554 | if (pum_visible()) |
| 10555 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10556 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10557 | /* Don't redraw right now, do it later. */ |
| 10558 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10559 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10560 | return; |
| 10561 | } |
| 10562 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10563 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10564 | 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] | 10565 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10566 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10567 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10568 | else |
| 10569 | #endif |
| 10570 | #ifdef FEAT_CMDL_INFO |
| 10571 | win_redr_ruler(curwin, always); |
| 10572 | #endif |
| 10573 | |
| 10574 | #ifdef FEAT_TITLE |
| 10575 | if (need_maketitle |
| 10576 | # ifdef FEAT_STL_OPT |
| 10577 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10578 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10579 | # endif |
| 10580 | ) |
| 10581 | maketitle(); |
| 10582 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10583 | #ifdef FEAT_WINDOWS |
| 10584 | /* Redraw the tab pages line if needed. */ |
| 10585 | if (redraw_tabline) |
| 10586 | draw_tabline(); |
| 10587 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10588 | } |
| 10589 | |
| 10590 | #ifdef FEAT_CMDL_INFO |
| 10591 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10592 | win_redr_ruler(win_T *wp, int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10593 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10594 | #define RULER_BUF_LEN 70 |
| 10595 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10596 | int row; |
| 10597 | int fillchar; |
| 10598 | int attr; |
| 10599 | int empty_line = FALSE; |
| 10600 | colnr_T virtcol; |
| 10601 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10602 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10603 | int o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10604 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10605 | int this_ru_col; |
| 10606 | int off = 0; |
| 10607 | int width = Columns; |
| 10608 | # define WITH_OFF(x) x |
| 10609 | # define WITH_WIDTH(x) x |
| 10610 | #else |
| 10611 | # define WITH_OFF(x) 0 |
| 10612 | # define WITH_WIDTH(x) Columns |
| 10613 | # define this_ru_col ru_col |
| 10614 | #endif |
| 10615 | |
| 10616 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10617 | if (!p_ru) |
| 10618 | return; |
| 10619 | |
| 10620 | /* |
| 10621 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10622 | * after deleting lines, before cursor.lnum is corrected. |
| 10623 | */ |
| 10624 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10625 | return; |
| 10626 | |
| 10627 | #ifdef FEAT_INS_EXPAND |
| 10628 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10629 | * the (long) mode message. */ |
| 10630 | # ifdef FEAT_WINDOWS |
| 10631 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10632 | # endif |
| 10633 | if (edit_submode != NULL) |
| 10634 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10635 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10636 | if (pum_visible()) |
| 10637 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10638 | #endif |
| 10639 | |
| 10640 | #ifdef FEAT_STL_OPT |
| 10641 | if (*p_ruf) |
| 10642 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10643 | int save_called_emsg = called_emsg; |
| 10644 | |
| 10645 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10646 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10647 | if (called_emsg) |
| 10648 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10649 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10650 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10651 | return; |
| 10652 | } |
| 10653 | #endif |
| 10654 | |
| 10655 | /* |
| 10656 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10657 | */ |
| 10658 | if (!(State & INSERT) |
| 10659 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10660 | empty_line = TRUE; |
| 10661 | |
| 10662 | /* |
| 10663 | * Only draw the ruler when something changed. |
| 10664 | */ |
| 10665 | validate_virtcol_win(wp); |
| 10666 | if ( redraw_cmdline |
| 10667 | || always |
| 10668 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10669 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10670 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10671 | #ifdef FEAT_VIRTUALEDIT |
| 10672 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10673 | #endif |
| 10674 | || wp->w_topline != wp->w_ru_topline |
| 10675 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10676 | #ifdef FEAT_DIFF |
| 10677 | || wp->w_topfill != wp->w_ru_topfill |
| 10678 | #endif |
| 10679 | || empty_line != wp->w_ru_empty) |
| 10680 | { |
| 10681 | cursor_off(); |
| 10682 | #ifdef FEAT_WINDOWS |
| 10683 | if (wp->w_status_height) |
| 10684 | { |
| 10685 | row = W_WINROW(wp) + wp->w_height; |
| 10686 | fillchar = fillchar_status(&attr, wp == curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10687 | off = W_WINCOL(wp); |
| 10688 | width = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10689 | } |
| 10690 | else |
| 10691 | #endif |
| 10692 | { |
| 10693 | row = Rows - 1; |
| 10694 | fillchar = ' '; |
| 10695 | attr = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10696 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10697 | width = Columns; |
| 10698 | off = 0; |
| 10699 | #endif |
| 10700 | } |
| 10701 | |
| 10702 | /* In list mode virtcol needs to be recomputed */ |
| 10703 | virtcol = wp->w_virtcol; |
| 10704 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10705 | { |
| 10706 | wp->w_p_list = FALSE; |
| 10707 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10708 | wp->w_p_list = TRUE; |
| 10709 | } |
| 10710 | |
| 10711 | /* |
| 10712 | * Some sprintfs return the length, some return a pointer. |
| 10713 | * To avoid portability problems we use strlen() here. |
| 10714 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10715 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10716 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10717 | ? 0L |
| 10718 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10719 | len = STRLEN(buffer); |
| 10720 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10721 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10722 | (int)virtcol + 1); |
| 10723 | |
| 10724 | /* |
| 10725 | * Add a "50%" if there is room for it. |
| 10726 | * On the last line, don't print in the last column (scrolls the |
| 10727 | * screen up on some terminals). |
| 10728 | */ |
| 10729 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10730 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10731 | o = i + vim_strsize(buffer + i + 1); |
| 10732 | #ifdef FEAT_WINDOWS |
| 10733 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10734 | #endif |
| 10735 | ++o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10736 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10737 | this_ru_col = ru_col - (Columns - width); |
| 10738 | if (this_ru_col < 0) |
| 10739 | this_ru_col = 0; |
| 10740 | #endif |
| 10741 | /* Never use more than half the window/screen width, leave the other |
| 10742 | * half for the filename. */ |
| 10743 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10744 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10745 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10746 | { |
Bram Moolenaar | 0027c21 | 2015-01-07 13:31:52 +0100 | [diff] [blame] | 10747 | /* need at least 3 chars left for get_rel_pos() + NUL */ |
| 10748 | 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] | 10749 | { |
| 10750 | #ifdef FEAT_MBYTE |
| 10751 | if (has_mbyte) |
| 10752 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10753 | else |
| 10754 | #endif |
| 10755 | buffer[i++] = fillchar; |
| 10756 | ++o; |
| 10757 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10758 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10759 | } |
| 10760 | /* Truncate at window boundary. */ |
| 10761 | #ifdef FEAT_MBYTE |
| 10762 | if (has_mbyte) |
| 10763 | { |
| 10764 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10765 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10766 | { |
| 10767 | o += (*mb_ptr2cells)(buffer + i); |
| 10768 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10769 | { |
| 10770 | buffer[i] = NUL; |
| 10771 | break; |
| 10772 | } |
| 10773 | } |
| 10774 | } |
| 10775 | else |
| 10776 | #endif |
| 10777 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10778 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10779 | |
| 10780 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10781 | i = redraw_cmdline; |
| 10782 | screen_fill(row, row + 1, |
| 10783 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10784 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10785 | fillchar, fillchar, attr); |
| 10786 | /* don't redraw the cmdline because of showing the ruler */ |
| 10787 | redraw_cmdline = i; |
| 10788 | wp->w_ru_cursor = wp->w_cursor; |
| 10789 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10790 | wp->w_ru_empty = empty_line; |
| 10791 | wp->w_ru_topline = wp->w_topline; |
| 10792 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10793 | #ifdef FEAT_DIFF |
| 10794 | wp->w_ru_topfill = wp->w_topfill; |
| 10795 | #endif |
| 10796 | } |
| 10797 | } |
| 10798 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10799 | |
| 10800 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10801 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10802 | * Return the width of the 'number' and 'relativenumber' column. |
| 10803 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10804 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10805 | */ |
| 10806 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10807 | number_width(win_T *wp) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10808 | { |
| 10809 | int n; |
| 10810 | linenr_T lnum; |
| 10811 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10812 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10813 | /* cursor line shows "0" */ |
| 10814 | lnum = wp->w_height; |
| 10815 | else |
| 10816 | /* cursor line shows absolute line number */ |
| 10817 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10818 | |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10819 | 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] | 10820 | return wp->w_nrwidth_width; |
| 10821 | wp->w_nrwidth_line_count = lnum; |
| 10822 | |
| 10823 | n = 0; |
| 10824 | do |
| 10825 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10826 | lnum /= 10; |
| 10827 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10828 | } while (lnum > 0); |
| 10829 | |
| 10830 | /* 'numberwidth' gives the minimal width plus one */ |
| 10831 | if (n < wp->w_p_nuw - 1) |
| 10832 | n = wp->w_p_nuw - 1; |
| 10833 | |
| 10834 | wp->w_nrwidth_width = n; |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10835 | wp->w_nuw_cached = wp->w_p_nuw; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10836 | return n; |
| 10837 | } |
| 10838 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10839 | |
| 10840 | /* |
| 10841 | * Return the current cursor column. This is the actual position on the |
| 10842 | * screen. First column is 0. |
| 10843 | */ |
| 10844 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10845 | screen_screencol(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10846 | { |
| 10847 | return screen_cur_col; |
| 10848 | } |
| 10849 | |
| 10850 | /* |
| 10851 | * Return the current cursor row. This is the actual position on the screen. |
| 10852 | * First row is 0. |
| 10853 | */ |
| 10854 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10855 | screen_screenrow(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10856 | { |
| 10857 | return screen_cur_row; |
| 10858 | } |