Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * screen.c: code for displaying on the screen |
| 12 | * |
| 13 | * Output to the screen (console, terminal emulator or GUI window) is minimized |
| 14 | * by remembering what is already on the screen, and only updating the parts |
| 15 | * that changed. |
| 16 | * |
| 17 | * ScreenLines[off] Contains a copy of the whole screen, as it is currently |
| 18 | * displayed (excluding text written by external commands). |
| 19 | * ScreenAttrs[off] Contains the associated attributes. |
| 20 | * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] |
| 21 | * for each line. |
| 22 | * LineWraps[row] Flag for each line whether it wraps to the next line. |
| 23 | * |
| 24 | * For double-byte characters, two consecutive bytes in ScreenLines[] can form |
| 25 | * one character which occupies two display cells. |
| 26 | * For UTF-8 a multi-byte character is converted to Unicode and stored in |
| 27 | * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 28 | * character without composing chars ScreenLinesUC[] will be 0 and |
| 29 | * ScreenLinesC[][] is not used. When the character occupies two display |
| 30 | * cells the next byte in ScreenLines[] is 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 31 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 32 | * (drawn on top of the first character). There is 0 after the last one used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | * ScreenLines2[] is only used for euc-jp to store the second byte if the |
| 34 | * first byte is 0x8e (single-width character). |
| 35 | * |
| 36 | * The screen_*() functions write to the screen and handle updating |
| 37 | * ScreenLines[]. |
| 38 | * |
| 39 | * update_screen() is the function that updates all windows and status lines. |
| 40 | * It is called form the main loop when must_redraw is non-zero. It may be |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 41 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | * |
| 43 | * The part of the buffer that is displayed in a window is set with: |
| 44 | * - w_topline (first buffer line in window) |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 45 | * - w_topfill (filler lines above the first line) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | * - w_leftcol (leftmost window cell in window), |
| 47 | * - w_skipcol (skipped window cells of first line) |
| 48 | * |
| 49 | * Commands that only move the cursor around in a window, do not need to take |
| 50 | * action to update the display. The main loop will check if w_topline is |
| 51 | * valid and update it (scroll the window) when needed. |
| 52 | * |
| 53 | * Commands that scroll a window change w_topline and must call |
| 54 | * check_cursor() to move the cursor into the visible part of the window, and |
| 55 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 56 | * later. |
| 57 | * |
| 58 | * Commands that change text in the buffer must call changed_bytes() or |
| 59 | * changed_lines() to mark the area that changed and will require updating |
| 60 | * later. The main loop will call update_screen(), which will update each |
| 61 | * window that shows the changed buffer. This assumes text above the change |
| 62 | * can remain displayed as it is. Text after the change may need updating for |
| 63 | * scrolling, folding and syntax highlighting. |
| 64 | * |
| 65 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 66 | * invalidate the contents of a window in another way (e.g., change fold |
| 67 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 68 | * redisplayed by update_screen() later. |
| 69 | * |
| 70 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 71 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 72 | * buffer redisplayed by update_screen() later. |
| 73 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 74 | * Commands that change highlighting and possibly cause a scroll too must call |
| 75 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 76 | * to avoid redrawing everything. But the length of displayed lines must not |
| 77 | * change, use NOT_VALID then. |
| 78 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 80 | * TODO: should minimize redrawing by scrolling when possible. |
| 81 | * |
| 82 | * Commands that change everything (e.g., resizing the screen) must call |
| 83 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 84 | * |
| 85 | * Things that are handled indirectly: |
| 86 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 87 | * update_screen() called to redraw. |
| 88 | */ |
| 89 | |
| 90 | #include "vim.h" |
| 91 | |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 92 | #define MB_FILLER_CHAR '<' /* character used when a double-width character |
| 93 | * doesn't fit. */ |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * The attributes that are actually active for writing to the screen. |
| 97 | */ |
| 98 | static int screen_attr = 0; |
| 99 | |
| 100 | /* |
| 101 | * Positioning the cursor is reduced by remembering the last position. |
| 102 | * Mostly used by windgoto() and screen_char(). |
| 103 | */ |
| 104 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 105 | |
| 106 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef FEAT_FOLDING |
| 111 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 112 | static int compute_foldcolumn(win_T *wp, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | /* |
| 116 | * Buffer for one screen line (characters and attributes). |
| 117 | */ |
| 118 | static schar_T *current_ScreenLine; |
| 119 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 120 | static void win_update(win_T *wp); |
| 121 | static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | #ifdef FEAT_FOLDING |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 123 | static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row); |
| 124 | static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum); |
| 125 | static void copy_text_attr(int off, char_u *buf, int len, int attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 127 | static int win_line(win_T *, linenr_T, int, int, int nochange); |
| 128 | static int char_needs_redraw(int off_from, int off_to, int cols); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 129 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 130 | static void screen_line(int row, int coloff, int endcol, int clear_width, int rlflag); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 132 | #else |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 133 | static void screen_line(int row, int coloff, int endcol, int clear_width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 135 | #endif |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 136 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 137 | static void draw_vsep_win(win_T *wp, int row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 139 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 140 | static void redraw_custom_statusline(win_T *wp); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 141 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 142 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 143 | # define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 144 | static void start_search_hl(void); |
| 145 | static void end_search_hl(void); |
| 146 | static void init_search_hl(win_T *wp); |
| 147 | static void prepare_search_hl(win_T *wp, linenr_T lnum); |
| 148 | static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur); |
| 149 | static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 150 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 151 | static void screen_start_highlight(int attr); |
| 152 | static void screen_char(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 154 | static void screen_char_2(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 155 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 156 | static void screenclear2(void); |
| 157 | static void lineclear(unsigned off, int width); |
| 158 | static void lineinvalid(unsigned off, int width); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 159 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 160 | static void linecopy(int to, int from, win_T *wp); |
| 161 | static void redraw_block(int row, int end, win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 163 | static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del); |
| 164 | static void win_rest_invalid(win_T *wp); |
| 165 | static void msg_pos_mode(void); |
| 166 | static void recording_mode(int attr); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 167 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 168 | static void draw_tabline(void); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 169 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 171 | static int fillchar_status(int *attr, int is_curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | #endif |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 173 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 174 | static int fillchar_vsep(int *attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | #endif |
| 176 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 177 | static void win_redr_custom(win_T *wp, int draw_ruler); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 178 | #endif |
| 179 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 180 | static void win_redr_ruler(win_T *wp, int always); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 183 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | /* Ugly global: overrule attribute used by screen_char() */ |
| 185 | static int screen_char_attr = 0; |
| 186 | #endif |
| 187 | |
| 188 | /* |
| 189 | * Redraw the current window later, with update_screen(type). |
| 190 | * Set must_redraw only if not already set to a higher value. |
| 191 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 192 | */ |
| 193 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 194 | redraw_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 195 | { |
| 196 | redraw_win_later(curwin, type); |
| 197 | } |
| 198 | |
| 199 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 200 | redraw_win_later( |
| 201 | win_T *wp, |
| 202 | int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 203 | { |
| 204 | if (wp->w_redr_type < type) |
| 205 | { |
| 206 | wp->w_redr_type = type; |
| 207 | if (type >= NOT_VALID) |
| 208 | wp->w_lines_valid = 0; |
| 209 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 210 | must_redraw = type; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 216 | * after executing a shell command that messes up the screen. |
| 217 | */ |
| 218 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 219 | redraw_later_clear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 220 | { |
| 221 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 222 | #ifdef FEAT_GUI |
| 223 | if (gui.in_use) |
| 224 | /* Use a code that will reset gui.highlight_mask in |
| 225 | * gui_stop_highlight(). */ |
| 226 | screen_attr = HL_ALL + 1; |
| 227 | else |
| 228 | #endif |
| 229 | /* Use attributes that is very unlikely to appear in text. */ |
| 230 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Mark all windows to be redrawn later. |
| 235 | */ |
| 236 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 237 | redraw_all_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | { |
| 239 | win_T *wp; |
| 240 | |
| 241 | FOR_ALL_WINDOWS(wp) |
| 242 | { |
| 243 | redraw_win_later(wp, type); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 248 | * Mark all windows that are editing the current buffer to be updated later. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 249 | */ |
| 250 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 251 | redraw_curbuf_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 252 | { |
| 253 | redraw_buf_later(curbuf, type); |
| 254 | } |
| 255 | |
| 256 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 257 | redraw_buf_later(buf_T *buf, int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 258 | { |
| 259 | win_T *wp; |
| 260 | |
| 261 | FOR_ALL_WINDOWS(wp) |
| 262 | { |
| 263 | if (wp->w_buffer == buf) |
| 264 | redraw_win_later(wp, type); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /* |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 269 | * Redraw as soon as possible. When the command line is not scrolled redraw |
| 270 | * right away and restore what was on the command line. |
| 271 | * Return a code indicating what happened. |
| 272 | */ |
| 273 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 274 | redraw_asap(int type) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 275 | { |
| 276 | int rows; |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 277 | int cols = screen_Columns; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 278 | int r; |
| 279 | int ret = 0; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 280 | schar_T *screenline; /* copy from ScreenLines[] */ |
| 281 | sattr_T *screenattr; /* copy from ScreenAttrs[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 282 | #ifdef FEAT_MBYTE |
| 283 | int i; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 284 | u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 285 | u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */ |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 286 | schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 287 | #endif |
| 288 | |
| 289 | redraw_later(type); |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 290 | if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 291 | return ret; |
| 292 | |
| 293 | /* Allocate space to save the text displayed in the command line area. */ |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 294 | rows = screen_Rows - cmdline_row; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 295 | screenline = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 296 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 297 | screenattr = (sattr_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 298 | (long_u)(rows * cols * sizeof(sattr_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 299 | if (screenline == NULL || screenattr == NULL) |
| 300 | ret = 2; |
| 301 | #ifdef FEAT_MBYTE |
| 302 | if (enc_utf8) |
| 303 | { |
| 304 | screenlineUC = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 305 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 306 | if (screenlineUC == NULL) |
| 307 | ret = 2; |
| 308 | for (i = 0; i < p_mco; ++i) |
| 309 | { |
| 310 | screenlineC[i] = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 311 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 312 | if (screenlineC[i] == NULL) |
| 313 | ret = 2; |
| 314 | } |
| 315 | } |
| 316 | if (enc_dbcs == DBCS_JPNU) |
| 317 | { |
| 318 | screenline2 = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 319 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 320 | if (screenline2 == NULL) |
| 321 | ret = 2; |
| 322 | } |
| 323 | #endif |
| 324 | |
| 325 | if (ret != 2) |
| 326 | { |
| 327 | /* Save the text displayed in the command line area. */ |
| 328 | for (r = 0; r < rows; ++r) |
| 329 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 330 | mch_memmove(screenline + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 331 | ScreenLines + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 332 | (size_t)cols * sizeof(schar_T)); |
| 333 | mch_memmove(screenattr + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 334 | ScreenAttrs + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 335 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 336 | #ifdef FEAT_MBYTE |
| 337 | if (enc_utf8) |
| 338 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 339 | mch_memmove(screenlineUC + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 340 | ScreenLinesUC + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 341 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 342 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 343 | mch_memmove(screenlineC[i] + r * cols, |
| 344 | ScreenLinesC[i] + LineOffset[cmdline_row + r], |
| 345 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 346 | } |
| 347 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 348 | mch_memmove(screenline2 + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 349 | ScreenLines2 + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 350 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 351 | #endif |
| 352 | } |
| 353 | |
| 354 | update_screen(0); |
| 355 | ret = 3; |
| 356 | |
| 357 | if (must_redraw == 0) |
| 358 | { |
| 359 | int off = (int)(current_ScreenLine - ScreenLines); |
| 360 | |
| 361 | /* Restore the text displayed in the command line area. */ |
| 362 | for (r = 0; r < rows; ++r) |
| 363 | { |
| 364 | mch_memmove(current_ScreenLine, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 365 | screenline + r * cols, |
| 366 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 367 | mch_memmove(ScreenAttrs + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 368 | screenattr + r * cols, |
| 369 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 370 | #ifdef FEAT_MBYTE |
| 371 | if (enc_utf8) |
| 372 | { |
| 373 | mch_memmove(ScreenLinesUC + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 374 | screenlineUC + r * cols, |
| 375 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 376 | for (i = 0; i < p_mco; ++i) |
| 377 | mch_memmove(ScreenLinesC[i] + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 378 | screenlineC[i] + r * cols, |
| 379 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 380 | } |
| 381 | if (enc_dbcs == DBCS_JPNU) |
| 382 | mch_memmove(ScreenLines2 + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 383 | screenline2 + r * cols, |
| 384 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 385 | #endif |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 386 | SCREEN_LINE(cmdline_row + r, 0, cols, cols, FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 387 | } |
| 388 | ret = 4; |
| 389 | } |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | vim_free(screenline); |
| 393 | vim_free(screenattr); |
| 394 | #ifdef FEAT_MBYTE |
| 395 | if (enc_utf8) |
| 396 | { |
| 397 | vim_free(screenlineUC); |
| 398 | for (i = 0; i < p_mco; ++i) |
| 399 | vim_free(screenlineC[i]); |
| 400 | } |
| 401 | if (enc_dbcs == DBCS_JPNU) |
| 402 | vim_free(screenline2); |
| 403 | #endif |
| 404 | |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 405 | /* Show the intro message when appropriate. */ |
| 406 | maybe_intro_message(); |
| 407 | |
| 408 | setcursor(); |
| 409 | |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | /* |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 414 | * Invoked after an asynchronous callback is called. |
| 415 | * If an echo command was used the cursor needs to be put back where |
| 416 | * it belongs. If highlighting was changed a redraw is needed. |
| 417 | */ |
| 418 | void |
Bram Moolenaar | cf08946 | 2016-06-12 21:18:43 +0200 | [diff] [blame] | 419 | redraw_after_callback(void) |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 420 | { |
Bram Moolenaar | bfb96c0 | 2016-03-19 17:05:20 +0100 | [diff] [blame] | 421 | if (State == HITRETURN || State == ASKMORE) |
| 422 | ; /* do nothing */ |
| 423 | else if (State & CMDLINE) |
| 424 | redrawcmdline(); |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 425 | else if (State & (NORMAL | INSERT)) |
Bram Moolenaar | bfb96c0 | 2016-03-19 17:05:20 +0100 | [diff] [blame] | 426 | { |
| 427 | update_screen(0); |
| 428 | setcursor(); |
| 429 | } |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 430 | cursor_on(); |
| 431 | out_flush(); |
| 432 | #ifdef FEAT_GUI |
| 433 | if (gui.in_use) |
| 434 | { |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 435 | /* Don't update the cursor when it is blinking and off to avoid |
| 436 | * flicker. */ |
| 437 | if (!gui_mch_is_blink_off()) |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 438 | gui_update_cursor(FALSE, FALSE); |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 439 | gui_mch_flush(); |
| 440 | } |
| 441 | #endif |
| 442 | } |
| 443 | |
| 444 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 445 | * Changed something in the current window, at buffer line "lnum", that |
| 446 | * requires that line and possibly other lines to be redrawn. |
| 447 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 448 | * Used to remove the "$" from a change command. |
| 449 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 450 | * may become invalid and the whole window will have to be redrawn. |
| 451 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 452 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 453 | redrawWinline( |
| 454 | linenr_T lnum, |
| 455 | int invalid UNUSED) /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 456 | { |
| 457 | #ifdef FEAT_FOLDING |
| 458 | int i; |
| 459 | #endif |
| 460 | |
| 461 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 462 | curwin->w_redraw_top = lnum; |
| 463 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 464 | curwin->w_redraw_bot = lnum; |
| 465 | redraw_later(VALID); |
| 466 | |
| 467 | #ifdef FEAT_FOLDING |
| 468 | if (invalid) |
| 469 | { |
| 470 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 471 | i = find_wl_entry(curwin, lnum); |
| 472 | if (i >= 0) |
| 473 | curwin->w_lines[i].wl_valid = FALSE; |
| 474 | } |
| 475 | #endif |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * update all windows that are editing the current buffer |
| 480 | */ |
| 481 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 482 | update_curbuf(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 483 | { |
| 484 | redraw_curbuf_later(type); |
| 485 | update_screen(type); |
| 486 | } |
| 487 | |
| 488 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 489 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 490 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 491 | */ |
| 492 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 493 | update_screen(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 494 | { |
| 495 | win_T *wp; |
| 496 | static int did_intro = FALSE; |
| 497 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 498 | int did_one; |
| 499 | #endif |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 500 | #ifdef FEAT_GUI |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 501 | int did_undraw = FALSE; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 502 | int gui_cursor_col; |
| 503 | int gui_cursor_row; |
| 504 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 505 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 506 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 507 | if (!screen_valid(TRUE)) |
| 508 | return; |
| 509 | |
| 510 | if (must_redraw) |
| 511 | { |
| 512 | if (type < must_redraw) /* use maximal type */ |
| 513 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 514 | |
| 515 | /* must_redraw is reset here, so that when we run into some weird |
| 516 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 517 | * scrolling), or update_topline() in win_update() will cause a |
| 518 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 519 | must_redraw = 0; |
| 520 | } |
| 521 | |
| 522 | /* Need to update w_lines[]. */ |
| 523 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 524 | type = NOT_VALID; |
| 525 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 526 | /* Postpone the redrawing when it's not needed and when being called |
| 527 | * recursively. */ |
| 528 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 529 | { |
| 530 | redraw_later(type); /* remember type for next time */ |
| 531 | must_redraw = type; |
| 532 | if (type > INVERTED_ALL) |
| 533 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | updating_screen = TRUE; |
| 538 | #ifdef FEAT_SYN_HL |
| 539 | ++display_tick; /* let syntax code know we're in a next round of |
| 540 | * display updating */ |
| 541 | #endif |
| 542 | |
| 543 | /* |
| 544 | * if the screen was scrolled up when displaying a message, scroll it down |
| 545 | */ |
| 546 | if (msg_scrolled) |
| 547 | { |
| 548 | clear_cmdline = TRUE; |
| 549 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 550 | type = CLEAR; |
| 551 | else if (type != CLEAR) |
| 552 | { |
| 553 | check_for_delay(FALSE); |
| 554 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 555 | type = CLEAR; |
| 556 | FOR_ALL_WINDOWS(wp) |
| 557 | { |
| 558 | if (W_WINROW(wp) < msg_scrolled) |
| 559 | { |
| 560 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 561 | && wp->w_redr_type < REDRAW_TOP |
| 562 | && wp->w_lines_valid > 0 |
| 563 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 564 | { |
| 565 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 566 | wp->w_redr_type = REDRAW_TOP; |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | wp->w_redr_type = NOT_VALID; |
| 571 | #ifdef FEAT_WINDOWS |
| 572 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 573 | <= msg_scrolled) |
| 574 | wp->w_redr_status = TRUE; |
| 575 | #endif |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 580 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 581 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 582 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 583 | } |
| 584 | msg_scrolled = 0; |
| 585 | need_wait_return = FALSE; |
| 586 | } |
| 587 | |
| 588 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 589 | compute_cmdrow(); |
| 590 | |
| 591 | /* Check for changed highlighting */ |
| 592 | if (need_highlight_changed) |
| 593 | highlight_changed(); |
| 594 | |
| 595 | if (type == CLEAR) /* first clear screen */ |
| 596 | { |
| 597 | screenclear(); /* will reset clear_cmdline */ |
| 598 | type = NOT_VALID; |
| 599 | } |
| 600 | |
| 601 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 602 | check_for_delay(FALSE); |
| 603 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 604 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 605 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 606 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 607 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 608 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 609 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 610 | curwin->w_redr_type = NOT_VALID; |
| 611 | #endif |
| 612 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 613 | /* |
| 614 | * Only start redrawing if there is really something to do. |
| 615 | */ |
| 616 | if (type == INVERTED) |
| 617 | update_curswant(); |
| 618 | if (curwin->w_redr_type < type |
| 619 | && !((type == VALID |
| 620 | && curwin->w_lines[0].wl_valid |
| 621 | #ifdef FEAT_DIFF |
| 622 | && curwin->w_topfill == curwin->w_old_topfill |
| 623 | && curwin->w_botfill == curwin->w_old_botfill |
| 624 | #endif |
| 625 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 626 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 627 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 628 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 629 | && curwin->w_old_visual_mode == VIsual_mode |
| 630 | && (curwin->w_valid & VALID_VIRTCOL) |
| 631 | && curwin->w_old_curswant == curwin->w_curswant) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 632 | )) |
| 633 | curwin->w_redr_type = type; |
| 634 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 635 | #ifdef FEAT_WINDOWS |
| 636 | /* Redraw the tab pages line if needed. */ |
| 637 | if (redraw_tabline || type >= NOT_VALID) |
| 638 | draw_tabline(); |
| 639 | #endif |
| 640 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 641 | #ifdef FEAT_SYN_HL |
| 642 | /* |
| 643 | * Correct stored syntax highlighting info for changes in each displayed |
| 644 | * buffer. Each buffer must only be done once. |
| 645 | */ |
| 646 | FOR_ALL_WINDOWS(wp) |
| 647 | { |
| 648 | if (wp->w_buffer->b_mod_set) |
| 649 | { |
| 650 | # ifdef FEAT_WINDOWS |
| 651 | win_T *wwp; |
| 652 | |
| 653 | /* Check if we already did this buffer. */ |
| 654 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 655 | if (wwp->w_buffer == wp->w_buffer) |
| 656 | break; |
| 657 | # endif |
| 658 | if ( |
| 659 | # ifdef FEAT_WINDOWS |
| 660 | wwp == wp && |
| 661 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 662 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 663 | syn_stack_apply_changes(wp->w_buffer); |
| 664 | } |
| 665 | } |
| 666 | #endif |
| 667 | |
| 668 | /* |
| 669 | * Go from top to bottom through the windows, redrawing the ones that need |
| 670 | * it. |
| 671 | */ |
| 672 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 673 | did_one = FALSE; |
| 674 | #endif |
| 675 | #ifdef FEAT_SEARCH_EXTRA |
| 676 | search_hl.rm.regprog = NULL; |
| 677 | #endif |
| 678 | FOR_ALL_WINDOWS(wp) |
| 679 | { |
| 680 | if (wp->w_redr_type != 0) |
| 681 | { |
| 682 | cursor_off(); |
| 683 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 684 | if (!did_one) |
| 685 | { |
| 686 | did_one = TRUE; |
| 687 | # ifdef FEAT_SEARCH_EXTRA |
| 688 | start_search_hl(); |
| 689 | # endif |
| 690 | # ifdef FEAT_CLIPBOARD |
| 691 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 692 | if (clip_star.available && clip_isautosel_star()) |
| 693 | clip_update_selection(&clip_star); |
| 694 | if (clip_plus.available && clip_isautosel_plus()) |
| 695 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 696 | # endif |
| 697 | #ifdef FEAT_GUI |
| 698 | /* Remove the cursor before starting to do anything, because |
| 699 | * scrolling may make it difficult to redraw the text under |
| 700 | * it. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 701 | if (gui.in_use && wp == curwin) |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 702 | { |
| 703 | gui_cursor_col = gui.cursor_col; |
| 704 | gui_cursor_row = gui.cursor_row; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 705 | gui_undraw_cursor(); |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 706 | did_undraw = TRUE; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 707 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 708 | #endif |
| 709 | } |
| 710 | #endif |
| 711 | win_update(wp); |
| 712 | } |
| 713 | |
| 714 | #ifdef FEAT_WINDOWS |
| 715 | /* redraw status line after the window to minimize cursor movement */ |
| 716 | if (wp->w_redr_status) |
| 717 | { |
| 718 | cursor_off(); |
| 719 | win_redr_status(wp); |
| 720 | } |
| 721 | #endif |
| 722 | } |
| 723 | #if defined(FEAT_SEARCH_EXTRA) |
| 724 | end_search_hl(); |
| 725 | #endif |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 726 | #ifdef FEAT_INS_EXPAND |
| 727 | /* May need to redraw the popup menu. */ |
| 728 | if (pum_visible()) |
| 729 | pum_redraw(); |
| 730 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 731 | |
| 732 | #ifdef FEAT_WINDOWS |
| 733 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 734 | * than going through all buffers (there could be many buffers). */ |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 735 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 736 | wp->w_buffer->b_mod_set = FALSE; |
| 737 | #else |
| 738 | curbuf->b_mod_set = FALSE; |
| 739 | #endif |
| 740 | |
| 741 | updating_screen = FALSE; |
| 742 | #ifdef FEAT_GUI |
| 743 | gui_may_resize_shell(); |
| 744 | #endif |
| 745 | |
| 746 | /* Clear or redraw the command line. Done last, because scrolling may |
| 747 | * mess up the command line. */ |
| 748 | if (clear_cmdline || redraw_cmdline) |
| 749 | showmode(); |
| 750 | |
| 751 | /* May put up an introductory message when not editing a file */ |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 752 | if (!did_intro) |
| 753 | maybe_intro_message(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | did_intro = TRUE; |
| 755 | |
| 756 | #ifdef FEAT_GUI |
| 757 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 758 | * done. */ |
| 759 | if (gui.in_use) |
| 760 | { |
| 761 | out_flush(); /* required before updating the cursor */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 762 | if (did_undraw && !gui_mch_is_blink_off()) |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 763 | { |
| 764 | /* Put the GUI position where the cursor was, gui_update_cursor() |
| 765 | * uses that. */ |
| 766 | gui.col = gui_cursor_col; |
| 767 | gui.row = gui_cursor_row; |
Bram Moolenaar | 84dbd49 | 2016-10-02 23:09:31 +0200 | [diff] [blame] | 768 | # ifdef FEAT_MBYTE |
| 769 | gui.col = mb_fix_col(gui.col, gui.row); |
| 770 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 771 | gui_update_cursor(FALSE, FALSE); |
Bram Moolenaar | 65549bd | 2016-07-08 22:52:37 +0200 | [diff] [blame] | 772 | screen_cur_col = gui.col; |
| 773 | screen_cur_row = gui.row; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 774 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 775 | gui_update_scrollbars(FALSE); |
| 776 | } |
| 777 | #endif |
| 778 | } |
| 779 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 780 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 781 | /* |
| 782 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 783 | * to the 'concealcursor' option. |
| 784 | */ |
| 785 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 786 | conceal_cursor_line(win_T *wp) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 787 | { |
| 788 | int c; |
| 789 | |
| 790 | if (*wp->w_p_cocu == NUL) |
| 791 | return FALSE; |
| 792 | if (get_real_state() & VISUAL) |
| 793 | c = 'v'; |
| 794 | else if (State & INSERT) |
| 795 | c = 'i'; |
| 796 | else if (State & NORMAL) |
| 797 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 798 | else if (State & CMDLINE) |
| 799 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 800 | else |
| 801 | return FALSE; |
| 802 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 807 | */ |
| 808 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 809 | conceal_check_cursur_line(void) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 810 | { |
| 811 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 812 | { |
| 813 | need_cursor_line_redraw = TRUE; |
| 814 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 815 | * without concealing. */ |
| 816 | curs_columns(TRUE); |
| 817 | } |
| 818 | } |
| 819 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 820 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 821 | update_single_line(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 822 | { |
| 823 | int row; |
| 824 | int j; |
| 825 | |
Bram Moolenaar | 908be43 | 2016-05-24 10:51:30 +0200 | [diff] [blame] | 826 | /* Don't do anything if the screen structures are (not yet) valid. */ |
| 827 | if (!screen_valid(TRUE)) |
| 828 | return; |
| 829 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 830 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 831 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 832 | { |
| 833 | # ifdef FEAT_GUI |
| 834 | /* Remove the cursor before starting to do anything, because scrolling |
| 835 | * may make it difficult to redraw the text under it. */ |
| 836 | if (gui.in_use) |
| 837 | gui_undraw_cursor(); |
| 838 | # endif |
| 839 | row = 0; |
| 840 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 841 | { |
| 842 | if (lnum == wp->w_lines[j].wl_lnum) |
| 843 | { |
| 844 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 845 | # ifdef FEAT_SEARCH_EXTRA |
| 846 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 847 | start_search_hl(); |
| 848 | prepare_search_hl(wp, lnum); |
| 849 | # endif |
| 850 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 851 | # if defined(FEAT_SEARCH_EXTRA) |
| 852 | end_search_hl(); |
| 853 | # endif |
| 854 | break; |
| 855 | } |
| 856 | row += wp->w_lines[j].wl_size; |
| 857 | } |
| 858 | # ifdef FEAT_GUI |
| 859 | /* Redraw the cursor */ |
| 860 | if (gui.in_use) |
| 861 | { |
| 862 | out_flush(); /* required before updating the cursor */ |
| 863 | gui_update_cursor(FALSE, FALSE); |
| 864 | } |
| 865 | # endif |
| 866 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 867 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 868 | } |
| 869 | #endif |
| 870 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 871 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 872 | static void update_prepare(void); |
| 873 | static void update_finish(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 874 | |
| 875 | /* |
| 876 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 877 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 878 | */ |
| 879 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 880 | update_prepare(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 881 | { |
| 882 | cursor_off(); |
| 883 | updating_screen = TRUE; |
| 884 | #ifdef FEAT_GUI |
| 885 | /* Remove the cursor before starting to do anything, because scrolling may |
| 886 | * make it difficult to redraw the text under it. */ |
| 887 | if (gui.in_use) |
| 888 | gui_undraw_cursor(); |
| 889 | #endif |
| 890 | #ifdef FEAT_SEARCH_EXTRA |
| 891 | start_search_hl(); |
| 892 | #endif |
| 893 | } |
| 894 | |
| 895 | /* |
| 896 | * Finish updating one or more windows. |
| 897 | */ |
| 898 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 899 | update_finish(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 900 | { |
| 901 | if (redraw_cmdline) |
| 902 | showmode(); |
| 903 | |
| 904 | # ifdef FEAT_SEARCH_EXTRA |
| 905 | end_search_hl(); |
| 906 | # endif |
| 907 | |
| 908 | updating_screen = FALSE; |
| 909 | |
| 910 | # ifdef FEAT_GUI |
| 911 | gui_may_resize_shell(); |
| 912 | |
| 913 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 914 | * done. */ |
| 915 | if (gui.in_use) |
| 916 | { |
| 917 | out_flush(); /* required before updating the cursor */ |
| 918 | gui_update_cursor(FALSE, FALSE); |
| 919 | gui_update_scrollbars(FALSE); |
| 920 | } |
| 921 | # endif |
| 922 | } |
| 923 | #endif |
| 924 | |
| 925 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 926 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 927 | update_debug_sign(buf_T *buf, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 928 | { |
| 929 | win_T *wp; |
| 930 | int doit = FALSE; |
| 931 | |
| 932 | # ifdef FEAT_FOLDING |
| 933 | win_foldinfo.fi_level = 0; |
| 934 | # endif |
| 935 | |
| 936 | /* update/delete a specific mark */ |
| 937 | FOR_ALL_WINDOWS(wp) |
| 938 | { |
| 939 | if (buf != NULL && lnum > 0) |
| 940 | { |
| 941 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 942 | && lnum < wp->w_botline) |
| 943 | { |
| 944 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 945 | wp->w_redraw_top = lnum; |
| 946 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 947 | wp->w_redraw_bot = lnum; |
| 948 | redraw_win_later(wp, VALID); |
| 949 | } |
| 950 | } |
| 951 | else |
| 952 | redraw_win_later(wp, VALID); |
| 953 | if (wp->w_redr_type != 0) |
| 954 | doit = TRUE; |
| 955 | } |
| 956 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 957 | /* Return when there is nothing to do, screen updating is already |
| 958 | * happening (recursive call) or still starting up. */ |
| 959 | if (!doit || updating_screen |
| 960 | #ifdef FEAT_GUI |
| 961 | || gui.starting |
| 962 | #endif |
| 963 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 964 | return; |
| 965 | |
| 966 | /* update all windows that need updating */ |
| 967 | update_prepare(); |
| 968 | |
| 969 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 970 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 971 | { |
| 972 | if (wp->w_redr_type != 0) |
| 973 | win_update(wp); |
| 974 | if (wp->w_redr_status) |
| 975 | win_redr_status(wp); |
| 976 | } |
| 977 | # else |
| 978 | if (curwin->w_redr_type != 0) |
| 979 | win_update(curwin); |
| 980 | # endif |
| 981 | |
| 982 | update_finish(); |
| 983 | } |
| 984 | #endif |
| 985 | |
| 986 | |
| 987 | #if defined(FEAT_GUI) || defined(PROTO) |
| 988 | /* |
| 989 | * Update a single window, its status line and maybe the command line msg. |
| 990 | * Used for the GUI scrollbar. |
| 991 | */ |
| 992 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 993 | updateWindow(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 994 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 995 | /* return if already busy updating */ |
| 996 | if (updating_screen) |
| 997 | return; |
| 998 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 999 | update_prepare(); |
| 1000 | |
| 1001 | #ifdef FEAT_CLIPBOARD |
| 1002 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 1003 | if (clip_star.available && clip_isautosel_star()) |
| 1004 | clip_update_selection(&clip_star); |
| 1005 | if (clip_plus.available && clip_isautosel_plus()) |
| 1006 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1007 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1008 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1009 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1010 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1011 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1012 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 1013 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1014 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1015 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1016 | if (wp->w_redr_status |
| 1017 | # ifdef FEAT_CMDL_INFO |
| 1018 | || p_ru |
| 1019 | # endif |
| 1020 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 1021 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1022 | # endif |
| 1023 | ) |
| 1024 | win_redr_status(wp); |
| 1025 | #endif |
| 1026 | |
| 1027 | update_finish(); |
| 1028 | } |
| 1029 | #endif |
| 1030 | |
| 1031 | /* |
| 1032 | * Update a single window. |
| 1033 | * |
| 1034 | * This may cause the windows below it also to be redrawn (when clearing the |
| 1035 | * screen or scrolling lines). |
| 1036 | * |
| 1037 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 1038 | * implies the one below it. |
| 1039 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1040 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1041 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 1042 | * INVERTED redraw the changed part of the Visual area |
| 1043 | * INVERTED_ALL redraw the whole Visual area |
| 1044 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 1045 | * 2. update lines at the top when scrolled down |
| 1046 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 1047 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1048 | * b_mod_top and b_mod_bot. |
| 1049 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 1050 | * wp->w_redraw_top and wp->w_redr_bot. |
| 1051 | * - continue redrawing when syntax status is invalid. |
| 1052 | * 4. if scrolled up, update lines at the bottom. |
| 1053 | * This results in three areas that may need updating: |
| 1054 | * top: from first row to top_end (when scrolled down) |
| 1055 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1056 | * bot: from bot_start to last row (when scrolled up) |
| 1057 | */ |
| 1058 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 1059 | win_update(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1060 | { |
| 1061 | buf_T *buf = wp->w_buffer; |
| 1062 | int type; |
| 1063 | int top_end = 0; /* Below last row of the top area that needs |
| 1064 | updating. 0 when no top area updating. */ |
| 1065 | int mid_start = 999;/* first row of the mid area that needs |
| 1066 | updating. 999 when no mid area updating. */ |
| 1067 | int mid_end = 0; /* Below last row of the mid area that needs |
| 1068 | updating. 0 when no mid area updating. */ |
| 1069 | int bot_start = 999;/* first row of the bot area that needs |
| 1070 | updating. 999 when no bot area updating */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1071 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 1072 | w_topline got smaller a bit */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1073 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1074 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1075 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 1076 | #endif |
| 1077 | |
| 1078 | int row; /* current window row to display */ |
| 1079 | linenr_T lnum; /* current buffer lnum to display */ |
| 1080 | int idx; /* current index in w_lines[] */ |
| 1081 | int srow; /* starting row of the current line */ |
| 1082 | |
| 1083 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 1084 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 1085 | int i; |
| 1086 | long j; |
| 1087 | static int recursive = FALSE; /* being called recursively */ |
| 1088 | int old_botline = wp->w_botline; |
| 1089 | #ifdef FEAT_FOLDING |
| 1090 | long fold_count; |
| 1091 | #endif |
| 1092 | #ifdef FEAT_SYN_HL |
| 1093 | /* remember what happened to the previous line, to know if |
| 1094 | * check_visual_highlight() can be used */ |
| 1095 | #define DID_NONE 1 /* didn't update a line */ |
| 1096 | #define DID_LINE 2 /* updated a normal line */ |
| 1097 | #define DID_FOLD 3 /* updated a folded line */ |
| 1098 | int did_update = DID_NONE; |
| 1099 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 1100 | #endif |
| 1101 | linenr_T mod_top = 0; |
| 1102 | linenr_T mod_bot = 0; |
| 1103 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1104 | int save_got_int; |
| 1105 | #endif |
| 1106 | |
| 1107 | type = wp->w_redr_type; |
| 1108 | |
| 1109 | if (type == NOT_VALID) |
| 1110 | { |
| 1111 | #ifdef FEAT_WINDOWS |
| 1112 | wp->w_redr_status = TRUE; |
| 1113 | #endif |
| 1114 | wp->w_lines_valid = 0; |
| 1115 | } |
| 1116 | |
| 1117 | /* Window is zero-height: nothing to draw. */ |
| 1118 | if (wp->w_height == 0) |
| 1119 | { |
| 1120 | wp->w_redr_type = 0; |
| 1121 | return; |
| 1122 | } |
| 1123 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 1124 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1125 | /* Window is zero-width: Only need to draw the separator. */ |
| 1126 | if (wp->w_width == 0) |
| 1127 | { |
| 1128 | /* draw the vertical separator right of this window */ |
| 1129 | draw_vsep_win(wp, 0); |
| 1130 | wp->w_redr_type = 0; |
| 1131 | return; |
| 1132 | } |
| 1133 | #endif |
| 1134 | |
| 1135 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 1136 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1137 | #endif |
| 1138 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1139 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 1140 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 1141 | * changes. */ |
| 1142 | 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] | 1143 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1144 | { |
| 1145 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1146 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1147 | } |
| 1148 | else |
| 1149 | #endif |
| 1150 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1151 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 1152 | { |
| 1153 | /* |
| 1154 | * When there are both inserted/deleted lines and specific lines to be |
| 1155 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 1156 | * everything (only happens when redrawing is off for while). |
| 1157 | */ |
| 1158 | type = NOT_VALID; |
| 1159 | } |
| 1160 | else |
| 1161 | { |
| 1162 | /* |
| 1163 | * Set mod_top to the first line that needs displaying because of |
| 1164 | * changes. Set mod_bot to the first line after the changes. |
| 1165 | */ |
| 1166 | mod_top = wp->w_redraw_top; |
| 1167 | if (wp->w_redraw_bot != 0) |
| 1168 | mod_bot = wp->w_redraw_bot + 1; |
| 1169 | else |
| 1170 | mod_bot = 0; |
| 1171 | wp->w_redraw_top = 0; /* reset for next time */ |
| 1172 | wp->w_redraw_bot = 0; |
| 1173 | if (buf->b_mod_set) |
| 1174 | { |
| 1175 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1176 | { |
| 1177 | mod_top = buf->b_mod_top; |
| 1178 | #ifdef FEAT_SYN_HL |
| 1179 | /* Need to redraw lines above the change that may be included |
| 1180 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1181 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1182 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1183 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1184 | if (mod_top < 1) |
| 1185 | mod_top = 1; |
| 1186 | } |
| 1187 | #endif |
| 1188 | } |
| 1189 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1190 | mod_bot = buf->b_mod_bot; |
| 1191 | |
| 1192 | #ifdef FEAT_SEARCH_EXTRA |
| 1193 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1194 | * change in one line may make the Search highlighting in a |
| 1195 | * previous line invalid. Simple solution: redraw all visible |
| 1196 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1197 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1198 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1199 | if (search_hl.rm.regprog != NULL |
| 1200 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1201 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1202 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1203 | { |
| 1204 | cur = wp->w_match_head; |
| 1205 | while (cur != NULL) |
| 1206 | { |
| 1207 | if (cur->match.regprog != NULL |
| 1208 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1209 | { |
| 1210 | top_to_mod = TRUE; |
| 1211 | break; |
| 1212 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1213 | cur = cur->next; |
| 1214 | } |
| 1215 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1216 | #endif |
| 1217 | } |
| 1218 | #ifdef FEAT_FOLDING |
| 1219 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1220 | { |
| 1221 | linenr_T lnumt, lnumb; |
| 1222 | |
| 1223 | /* |
| 1224 | * A change in a line can cause lines above it to become folded or |
| 1225 | * unfolded. Find the top most buffer line that may be affected. |
| 1226 | * If the line was previously folded and displayed, get the first |
| 1227 | * line of that fold. If the line is folded now, get the first |
| 1228 | * folded line. Use the minimum of these two. |
| 1229 | */ |
| 1230 | |
| 1231 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1232 | * the line below it. If there is no valid entry, use w_topline. |
| 1233 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1234 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1235 | lnumt = wp->w_topline; |
| 1236 | lnumb = MAXLNUM; |
| 1237 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1238 | if (wp->w_lines[i].wl_valid) |
| 1239 | { |
| 1240 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1241 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1242 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1243 | { |
| 1244 | lnumb = wp->w_lines[i].wl_lnum; |
| 1245 | /* When there is a fold column it might need updating |
| 1246 | * in the next line ("J" just above an open fold). */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 1247 | if (compute_foldcolumn(wp, 0) > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1248 | ++lnumb; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1253 | if (mod_top > lnumt) |
| 1254 | mod_top = lnumt; |
| 1255 | |
| 1256 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1257 | --mod_bot; |
| 1258 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1259 | ++mod_bot; |
| 1260 | if (mod_bot < lnumb) |
| 1261 | mod_bot = lnumb; |
| 1262 | } |
| 1263 | #endif |
| 1264 | |
| 1265 | /* When a change starts above w_topline and the end is below |
| 1266 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1267 | * If the end of the change is above w_topline: do like no change was |
| 1268 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1269 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1270 | { |
| 1271 | if (mod_bot > wp->w_topline) |
| 1272 | mod_top = wp->w_topline; |
| 1273 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1274 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | top_end = 1; |
| 1276 | #endif |
| 1277 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1278 | |
| 1279 | /* When line numbers are displayed need to redraw all lines below |
| 1280 | * inserted/deleted lines. */ |
| 1281 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1282 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | /* |
| 1286 | * When only displaying the lines at the top, set top_end. Used when |
| 1287 | * window has scrolled down for msg_scrolled. |
| 1288 | */ |
| 1289 | if (type == REDRAW_TOP) |
| 1290 | { |
| 1291 | j = 0; |
| 1292 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1293 | { |
| 1294 | j += wp->w_lines[i].wl_size; |
| 1295 | if (j >= wp->w_upd_rows) |
| 1296 | { |
| 1297 | top_end = j; |
| 1298 | break; |
| 1299 | } |
| 1300 | } |
| 1301 | if (top_end == 0) |
| 1302 | /* not found (cannot happen?): redraw everything */ |
| 1303 | type = NOT_VALID; |
| 1304 | else |
| 1305 | /* top area defined, the rest is VALID */ |
| 1306 | type = VALID; |
| 1307 | } |
| 1308 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1309 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1310 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1311 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1312 | * called. */ |
| 1313 | if (screen_cleared) |
| 1314 | screen_cleared = MAYBE; |
| 1315 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1316 | /* |
| 1317 | * If there are no changes on the screen that require a complete redraw, |
| 1318 | * handle three cases: |
| 1319 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1320 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1321 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1322 | * w_lines[] that needs updating. |
| 1323 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1324 | if ((type == VALID || type == SOME_VALID |
| 1325 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1326 | #ifdef FEAT_DIFF |
| 1327 | && !wp->w_botfill && !wp->w_old_botfill |
| 1328 | #endif |
| 1329 | ) |
| 1330 | { |
| 1331 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1332 | { |
| 1333 | /* |
| 1334 | * w_topline is the first changed line, the scrolling will be done |
| 1335 | * further down. |
| 1336 | */ |
| 1337 | } |
| 1338 | else if (wp->w_lines[0].wl_valid |
| 1339 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1340 | #ifdef FEAT_DIFF |
| 1341 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1342 | && wp->w_topfill > wp->w_old_topfill) |
| 1343 | #endif |
| 1344 | )) |
| 1345 | { |
| 1346 | /* |
| 1347 | * New topline is above old topline: May scroll down. |
| 1348 | */ |
| 1349 | #ifdef FEAT_FOLDING |
| 1350 | if (hasAnyFolding(wp)) |
| 1351 | { |
| 1352 | linenr_T ln; |
| 1353 | |
| 1354 | /* count the number of lines we are off, counting a sequence |
| 1355 | * of folded lines as one */ |
| 1356 | j = 0; |
| 1357 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1358 | { |
| 1359 | ++j; |
| 1360 | if (j >= wp->w_height - 2) |
| 1361 | break; |
| 1362 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1363 | } |
| 1364 | } |
| 1365 | else |
| 1366 | #endif |
| 1367 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1368 | if (j < wp->w_height - 2) /* not too far off */ |
| 1369 | { |
| 1370 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1371 | #ifdef FEAT_DIFF |
| 1372 | /* insert extra lines for previously invisible filler lines */ |
| 1373 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1374 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1375 | - wp->w_old_topfill; |
| 1376 | #endif |
| 1377 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1378 | { |
| 1379 | /* |
| 1380 | * Try to insert the correct number of lines. |
| 1381 | * If not the last window, delete the lines at the bottom. |
| 1382 | * win_ins_lines may fail when the terminal can't do it. |
| 1383 | */ |
| 1384 | if (i > 0) |
| 1385 | check_for_delay(FALSE); |
| 1386 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1387 | { |
| 1388 | if (wp->w_lines_valid != 0) |
| 1389 | { |
| 1390 | /* Need to update rows that are new, stop at the |
| 1391 | * first one that scrolled down. */ |
| 1392 | top_end = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1393 | scrolled_down = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1394 | |
| 1395 | /* Move the entries that were scrolled, disable |
| 1396 | * the entries for the lines to be redrawn. */ |
| 1397 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1398 | wp->w_lines_valid = wp->w_height; |
| 1399 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1400 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1401 | while (idx >= 0) |
| 1402 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1403 | } |
| 1404 | } |
| 1405 | else |
| 1406 | mid_start = 0; /* redraw all lines */ |
| 1407 | } |
| 1408 | else |
| 1409 | mid_start = 0; /* redraw all lines */ |
| 1410 | } |
| 1411 | else |
| 1412 | mid_start = 0; /* redraw all lines */ |
| 1413 | } |
| 1414 | else |
| 1415 | { |
| 1416 | /* |
| 1417 | * New topline is at or below old topline: May scroll up. |
| 1418 | * When topline didn't change, find first entry in w_lines[] that |
| 1419 | * needs updating. |
| 1420 | */ |
| 1421 | |
| 1422 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1423 | j = -1; |
| 1424 | row = 0; |
| 1425 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1426 | { |
| 1427 | if (wp->w_lines[i].wl_valid |
| 1428 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1429 | { |
| 1430 | j = i; |
| 1431 | break; |
| 1432 | } |
| 1433 | row += wp->w_lines[i].wl_size; |
| 1434 | } |
| 1435 | if (j == -1) |
| 1436 | { |
| 1437 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1438 | * lines */ |
| 1439 | mid_start = 0; |
| 1440 | } |
| 1441 | else |
| 1442 | { |
| 1443 | /* |
| 1444 | * Try to delete the correct number of lines. |
| 1445 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1446 | */ |
| 1447 | #ifdef FEAT_DIFF |
| 1448 | /* If the topline didn't change, delete old filler lines, |
| 1449 | * otherwise delete filler lines of the new topline... */ |
| 1450 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1451 | row += wp->w_old_topfill; |
| 1452 | else |
| 1453 | row += diff_check_fill(wp, wp->w_topline); |
| 1454 | /* ... but don't delete new filler lines. */ |
| 1455 | row -= wp->w_topfill; |
| 1456 | #endif |
| 1457 | if (row > 0) |
| 1458 | { |
| 1459 | check_for_delay(FALSE); |
| 1460 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1461 | bot_start = wp->w_height - row; |
| 1462 | else |
| 1463 | mid_start = 0; /* redraw all lines */ |
| 1464 | } |
| 1465 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1466 | { |
| 1467 | /* |
| 1468 | * Skip the lines (below the deleted lines) that are still |
| 1469 | * valid and don't need redrawing. Copy their info |
| 1470 | * upwards, to compensate for the deleted lines. Set |
| 1471 | * bot_start to the first row that needs redrawing. |
| 1472 | */ |
| 1473 | bot_start = 0; |
| 1474 | idx = 0; |
| 1475 | for (;;) |
| 1476 | { |
| 1477 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1478 | /* stop at line that didn't fit, unless it is still |
| 1479 | * valid (no lines deleted) */ |
| 1480 | if (row > 0 && bot_start + row |
| 1481 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1482 | { |
| 1483 | wp->w_lines_valid = idx + 1; |
| 1484 | break; |
| 1485 | } |
| 1486 | bot_start += wp->w_lines[idx++].wl_size; |
| 1487 | |
| 1488 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1489 | if (++j >= wp->w_lines_valid) |
| 1490 | { |
| 1491 | wp->w_lines_valid = idx; |
| 1492 | break; |
| 1493 | } |
| 1494 | } |
| 1495 | #ifdef FEAT_DIFF |
| 1496 | /* Correct the first entry for filler lines at the top |
| 1497 | * when it won't get updated below. */ |
| 1498 | if (wp->w_p_diff && bot_start > 0) |
| 1499 | wp->w_lines[0].wl_size = |
| 1500 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1501 | + wp->w_topfill; |
| 1502 | #endif |
| 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | /* When starting redraw in the first line, redraw all lines. When |
| 1508 | * there is only one window it's probably faster to clear the screen |
| 1509 | * first. */ |
| 1510 | if (mid_start == 0) |
| 1511 | { |
| 1512 | mid_end = wp->w_height; |
Bram Moolenaar | a1f4cb9 | 2016-11-06 15:25:42 +0100 | [diff] [blame] | 1513 | if (ONE_WINDOW) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1514 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1515 | /* Clear the screen when it was not done by win_del_lines() or |
| 1516 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1517 | * then. */ |
| 1518 | if (screen_cleared != TRUE) |
| 1519 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1520 | #ifdef FEAT_WINDOWS |
| 1521 | /* The screen was cleared, redraw the tab pages line. */ |
| 1522 | if (redraw_tabline) |
| 1523 | draw_tabline(); |
| 1524 | #endif |
| 1525 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1526 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1527 | |
| 1528 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1529 | * cleared (only happens for the first window) or when screenclear() |
| 1530 | * was called directly above, "must_redraw" will have been set to |
| 1531 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1532 | if (screen_cleared == TRUE) |
| 1533 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1538 | mid_start = 0; |
| 1539 | mid_end = wp->w_height; |
| 1540 | } |
| 1541 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1542 | if (type == SOME_VALID) |
| 1543 | { |
| 1544 | /* SOME_VALID: redraw all lines. */ |
| 1545 | mid_start = 0; |
| 1546 | mid_end = wp->w_height; |
| 1547 | type = NOT_VALID; |
| 1548 | } |
| 1549 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1550 | /* check if we are updating or removing the inverted part */ |
| 1551 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1552 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1553 | { |
| 1554 | linenr_T from, to; |
| 1555 | |
| 1556 | if (VIsual_active) |
| 1557 | { |
| 1558 | if (VIsual_active |
| 1559 | && (VIsual_mode != wp->w_old_visual_mode |
| 1560 | || type == INVERTED_ALL)) |
| 1561 | { |
| 1562 | /* |
| 1563 | * If the type of Visual selection changed, redraw the whole |
| 1564 | * selection. Also when the ownership of the X selection is |
| 1565 | * gained or lost. |
| 1566 | */ |
| 1567 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1568 | { |
| 1569 | from = curwin->w_cursor.lnum; |
| 1570 | to = VIsual.lnum; |
| 1571 | } |
| 1572 | else |
| 1573 | { |
| 1574 | from = VIsual.lnum; |
| 1575 | to = curwin->w_cursor.lnum; |
| 1576 | } |
| 1577 | /* redraw more when the cursor moved as well */ |
| 1578 | if (wp->w_old_cursor_lnum < from) |
| 1579 | from = wp->w_old_cursor_lnum; |
| 1580 | if (wp->w_old_cursor_lnum > to) |
| 1581 | to = wp->w_old_cursor_lnum; |
| 1582 | if (wp->w_old_visual_lnum < from) |
| 1583 | from = wp->w_old_visual_lnum; |
| 1584 | if (wp->w_old_visual_lnum > to) |
| 1585 | to = wp->w_old_visual_lnum; |
| 1586 | } |
| 1587 | else |
| 1588 | { |
| 1589 | /* |
| 1590 | * Find the line numbers that need to be updated: The lines |
| 1591 | * between the old cursor position and the current cursor |
| 1592 | * position. Also check if the Visual position changed. |
| 1593 | */ |
| 1594 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1595 | { |
| 1596 | from = curwin->w_cursor.lnum; |
| 1597 | to = wp->w_old_cursor_lnum; |
| 1598 | } |
| 1599 | else |
| 1600 | { |
| 1601 | from = wp->w_old_cursor_lnum; |
| 1602 | to = curwin->w_cursor.lnum; |
| 1603 | if (from == 0) /* Visual mode just started */ |
| 1604 | from = to; |
| 1605 | } |
| 1606 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1607 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1608 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1609 | { |
| 1610 | if (wp->w_old_visual_lnum < from |
| 1611 | && wp->w_old_visual_lnum != 0) |
| 1612 | from = wp->w_old_visual_lnum; |
| 1613 | if (wp->w_old_visual_lnum > to) |
| 1614 | to = wp->w_old_visual_lnum; |
| 1615 | if (VIsual.lnum < from) |
| 1616 | from = VIsual.lnum; |
| 1617 | if (VIsual.lnum > to) |
| 1618 | to = VIsual.lnum; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | /* |
| 1623 | * If in block mode and changed column or curwin->w_curswant: |
| 1624 | * update all lines. |
| 1625 | * First compute the actual start and end column. |
| 1626 | */ |
| 1627 | if (VIsual_mode == Ctrl_V) |
| 1628 | { |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1629 | colnr_T fromc, toc; |
| 1630 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1631 | int save_ve_flags = ve_flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1632 | |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1633 | if (curwin->w_p_lbr) |
| 1634 | ve_flags = VE_ALL; |
| 1635 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1636 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1637 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1638 | ve_flags = save_ve_flags; |
| 1639 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1640 | ++toc; |
| 1641 | if (curwin->w_curswant == MAXCOL) |
| 1642 | toc = MAXCOL; |
| 1643 | |
| 1644 | if (fromc != wp->w_old_cursor_fcol |
| 1645 | || toc != wp->w_old_cursor_lcol) |
| 1646 | { |
| 1647 | if (from > VIsual.lnum) |
| 1648 | from = VIsual.lnum; |
| 1649 | if (to < VIsual.lnum) |
| 1650 | to = VIsual.lnum; |
| 1651 | } |
| 1652 | wp->w_old_cursor_fcol = fromc; |
| 1653 | wp->w_old_cursor_lcol = toc; |
| 1654 | } |
| 1655 | } |
| 1656 | else |
| 1657 | { |
| 1658 | /* Use the line numbers of the old Visual area. */ |
| 1659 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1660 | { |
| 1661 | from = wp->w_old_cursor_lnum; |
| 1662 | to = wp->w_old_visual_lnum; |
| 1663 | } |
| 1664 | else |
| 1665 | { |
| 1666 | from = wp->w_old_visual_lnum; |
| 1667 | to = wp->w_old_cursor_lnum; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | /* |
| 1672 | * There is no need to update lines above the top of the window. |
| 1673 | */ |
| 1674 | if (from < wp->w_topline) |
| 1675 | from = wp->w_topline; |
| 1676 | |
| 1677 | /* |
| 1678 | * If we know the value of w_botline, use it to restrict the update to |
| 1679 | * the lines that are visible in the window. |
| 1680 | */ |
| 1681 | if (wp->w_valid & VALID_BOTLINE) |
| 1682 | { |
| 1683 | if (from >= wp->w_botline) |
| 1684 | from = wp->w_botline - 1; |
| 1685 | if (to >= wp->w_botline) |
| 1686 | to = wp->w_botline - 1; |
| 1687 | } |
| 1688 | |
| 1689 | /* |
| 1690 | * Find the minimal part to be updated. |
| 1691 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1692 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1693 | * top_end; need to redraw from top_end to the "to" line. |
| 1694 | * A middle mouse click with a Visual selection may change the text |
| 1695 | * above the Visual area and reset wl_valid, do count these for |
| 1696 | * mid_end (in srow). |
| 1697 | */ |
| 1698 | if (mid_start > 0) |
| 1699 | { |
| 1700 | lnum = wp->w_topline; |
| 1701 | idx = 0; |
| 1702 | srow = 0; |
| 1703 | if (scrolled_down) |
| 1704 | mid_start = top_end; |
| 1705 | else |
| 1706 | mid_start = 0; |
| 1707 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1708 | { |
| 1709 | if (wp->w_lines[idx].wl_valid) |
| 1710 | mid_start += wp->w_lines[idx].wl_size; |
| 1711 | else if (!scrolled_down) |
| 1712 | srow += wp->w_lines[idx].wl_size; |
| 1713 | ++idx; |
| 1714 | # ifdef FEAT_FOLDING |
| 1715 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1716 | lnum = wp->w_lines[idx].wl_lnum; |
| 1717 | else |
| 1718 | # endif |
| 1719 | ++lnum; |
| 1720 | } |
| 1721 | srow += mid_start; |
| 1722 | mid_end = wp->w_height; |
| 1723 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1724 | { |
| 1725 | if (wp->w_lines[idx].wl_valid |
| 1726 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1727 | { |
| 1728 | /* Only update until first row of this line */ |
| 1729 | mid_end = srow; |
| 1730 | break; |
| 1731 | } |
| 1732 | srow += wp->w_lines[idx].wl_size; |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | if (VIsual_active && buf == curwin->w_buffer) |
| 1738 | { |
| 1739 | wp->w_old_visual_mode = VIsual_mode; |
| 1740 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1741 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1742 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1743 | wp->w_old_curswant = curwin->w_curswant; |
| 1744 | } |
| 1745 | else |
| 1746 | { |
| 1747 | wp->w_old_visual_mode = 0; |
| 1748 | wp->w_old_cursor_lnum = 0; |
| 1749 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1750 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1751 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1752 | |
| 1753 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1754 | /* reset got_int, otherwise regexp won't work */ |
| 1755 | save_got_int = got_int; |
| 1756 | got_int = 0; |
| 1757 | #endif |
| 1758 | #ifdef FEAT_FOLDING |
| 1759 | win_foldinfo.fi_level = 0; |
| 1760 | #endif |
| 1761 | |
| 1762 | /* |
| 1763 | * Update all the window rows. |
| 1764 | */ |
| 1765 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1766 | row = 0; |
| 1767 | srow = 0; |
| 1768 | lnum = wp->w_topline; /* first line shown in window */ |
| 1769 | for (;;) |
| 1770 | { |
| 1771 | /* stop updating when reached the end of the window (check for _past_ |
| 1772 | * the end of the window is at the end of the loop) */ |
| 1773 | if (row == wp->w_height) |
| 1774 | { |
| 1775 | didline = TRUE; |
| 1776 | break; |
| 1777 | } |
| 1778 | |
| 1779 | /* stop updating when hit the end of the file */ |
| 1780 | if (lnum > buf->b_ml.ml_line_count) |
| 1781 | { |
| 1782 | eof = TRUE; |
| 1783 | break; |
| 1784 | } |
| 1785 | |
| 1786 | /* Remember the starting row of the line that is going to be dealt |
| 1787 | * with. It is used further down when the line doesn't fit. */ |
| 1788 | srow = row; |
| 1789 | |
| 1790 | /* |
| 1791 | * Update a line when it is in an area that needs updating, when it |
| 1792 | * has changes or w_lines[idx] is invalid. |
| 1793 | * bot_start may be halfway a wrapped line after using |
| 1794 | * win_del_lines(), check if the current line includes it. |
| 1795 | * When syntax folding is being used, the saved syntax states will |
| 1796 | * already have been updated, we can't see where the syntax state is |
| 1797 | * the same again, just update until the end of the window. |
| 1798 | */ |
| 1799 | if (row < top_end |
| 1800 | || (row >= mid_start && row < mid_end) |
| 1801 | #ifdef FEAT_SEARCH_EXTRA |
| 1802 | || top_to_mod |
| 1803 | #endif |
| 1804 | || idx >= wp->w_lines_valid |
| 1805 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1806 | || (mod_top != 0 |
| 1807 | && (lnum == mod_top |
| 1808 | || (lnum >= mod_top |
| 1809 | && (lnum < mod_bot |
| 1810 | #ifdef FEAT_SYN_HL |
| 1811 | || did_update == DID_FOLD |
| 1812 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1813 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1814 | && ( |
| 1815 | # ifdef FEAT_FOLDING |
| 1816 | (foldmethodIsSyntax(wp) |
| 1817 | && hasAnyFolding(wp)) || |
| 1818 | # endif |
| 1819 | syntax_check_changed(lnum))) |
| 1820 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1821 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | dab70c6 | 2014-07-02 17:16:58 +0200 | [diff] [blame] | 1822 | /* match in fixed position might need redraw |
| 1823 | * if lines were inserted or deleted */ |
| 1824 | || (wp->w_match_head != NULL |
| 1825 | && buf->b_mod_xlines != 0) |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1826 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1827 | ))))) |
| 1828 | { |
| 1829 | #ifdef FEAT_SEARCH_EXTRA |
| 1830 | if (lnum == mod_top) |
| 1831 | top_to_mod = FALSE; |
| 1832 | #endif |
| 1833 | |
| 1834 | /* |
| 1835 | * When at start of changed lines: May scroll following lines |
| 1836 | * up or down to minimize redrawing. |
| 1837 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1838 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1839 | */ |
| 1840 | if (lnum == mod_top |
| 1841 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1842 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1843 | { |
| 1844 | int old_rows = 0; |
| 1845 | int new_rows = 0; |
| 1846 | int xtra_rows; |
| 1847 | linenr_T l; |
| 1848 | |
| 1849 | /* Count the old number of window rows, using w_lines[], which |
| 1850 | * should still contain the sizes for the lines as they are |
| 1851 | * currently displayed. */ |
| 1852 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1853 | { |
| 1854 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1855 | * lines are part of the changed area. */ |
| 1856 | if (wp->w_lines[i].wl_valid |
| 1857 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1858 | break; |
| 1859 | old_rows += wp->w_lines[i].wl_size; |
| 1860 | #ifdef FEAT_FOLDING |
| 1861 | if (wp->w_lines[i].wl_valid |
| 1862 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1863 | { |
| 1864 | /* Must have found the last valid entry above mod_bot. |
| 1865 | * Add following invalid entries. */ |
| 1866 | ++i; |
| 1867 | while (i < wp->w_lines_valid |
| 1868 | && !wp->w_lines[i].wl_valid) |
| 1869 | old_rows += wp->w_lines[i++].wl_size; |
| 1870 | break; |
| 1871 | } |
| 1872 | #endif |
| 1873 | } |
| 1874 | |
| 1875 | if (i >= wp->w_lines_valid) |
| 1876 | { |
| 1877 | /* We can't find a valid line below the changed lines, |
| 1878 | * need to redraw until the end of the window. |
| 1879 | * Inserting/deleting lines has no use. */ |
| 1880 | bot_start = 0; |
| 1881 | } |
| 1882 | else |
| 1883 | { |
| 1884 | /* Able to count old number of rows: Count new window |
| 1885 | * rows, and may insert/delete lines */ |
| 1886 | j = idx; |
| 1887 | for (l = lnum; l < mod_bot; ++l) |
| 1888 | { |
| 1889 | #ifdef FEAT_FOLDING |
| 1890 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1891 | ++new_rows; |
| 1892 | else |
| 1893 | #endif |
| 1894 | #ifdef FEAT_DIFF |
| 1895 | if (l == wp->w_topline) |
| 1896 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1897 | + wp->w_topfill; |
| 1898 | else |
| 1899 | #endif |
| 1900 | new_rows += plines_win(wp, l, TRUE); |
| 1901 | ++j; |
| 1902 | if (new_rows > wp->w_height - row - 2) |
| 1903 | { |
| 1904 | /* it's getting too much, must redraw the rest */ |
| 1905 | new_rows = 9999; |
| 1906 | break; |
| 1907 | } |
| 1908 | } |
| 1909 | xtra_rows = new_rows - old_rows; |
| 1910 | if (xtra_rows < 0) |
| 1911 | { |
| 1912 | /* May scroll text up. If there is not enough |
| 1913 | * remaining text or scrolling fails, must redraw the |
| 1914 | * rest. If scrolling works, must redraw the text |
| 1915 | * below the scrolled text. */ |
| 1916 | if (row - xtra_rows >= wp->w_height - 2) |
| 1917 | mod_bot = MAXLNUM; |
| 1918 | else |
| 1919 | { |
| 1920 | check_for_delay(FALSE); |
| 1921 | if (win_del_lines(wp, row, |
| 1922 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1923 | mod_bot = MAXLNUM; |
| 1924 | else |
| 1925 | bot_start = wp->w_height + xtra_rows; |
| 1926 | } |
| 1927 | } |
| 1928 | else if (xtra_rows > 0) |
| 1929 | { |
| 1930 | /* May scroll text down. If there is not enough |
| 1931 | * remaining text of scrolling fails, must redraw the |
| 1932 | * rest. */ |
| 1933 | if (row + xtra_rows >= wp->w_height - 2) |
| 1934 | mod_bot = MAXLNUM; |
| 1935 | else |
| 1936 | { |
| 1937 | check_for_delay(FALSE); |
| 1938 | if (win_ins_lines(wp, row + old_rows, |
| 1939 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1940 | mod_bot = MAXLNUM; |
| 1941 | else if (top_end > row + old_rows) |
| 1942 | /* Scrolled the part at the top that requires |
| 1943 | * updating down. */ |
| 1944 | top_end += xtra_rows; |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | /* When not updating the rest, may need to move w_lines[] |
| 1949 | * entries. */ |
| 1950 | if (mod_bot != MAXLNUM && i != j) |
| 1951 | { |
| 1952 | if (j < i) |
| 1953 | { |
| 1954 | int x = row + new_rows; |
| 1955 | |
| 1956 | /* move entries in w_lines[] upwards */ |
| 1957 | for (;;) |
| 1958 | { |
| 1959 | /* stop at last valid entry in w_lines[] */ |
| 1960 | if (i >= wp->w_lines_valid) |
| 1961 | { |
| 1962 | wp->w_lines_valid = j; |
| 1963 | break; |
| 1964 | } |
| 1965 | wp->w_lines[j] = wp->w_lines[i]; |
| 1966 | /* stop at a line that won't fit */ |
| 1967 | if (x + (int)wp->w_lines[j].wl_size |
| 1968 | > wp->w_height) |
| 1969 | { |
| 1970 | wp->w_lines_valid = j + 1; |
| 1971 | break; |
| 1972 | } |
| 1973 | x += wp->w_lines[j++].wl_size; |
| 1974 | ++i; |
| 1975 | } |
| 1976 | if (bot_start > x) |
| 1977 | bot_start = x; |
| 1978 | } |
| 1979 | else /* j > i */ |
| 1980 | { |
| 1981 | /* move entries in w_lines[] downwards */ |
| 1982 | j -= i; |
| 1983 | wp->w_lines_valid += j; |
| 1984 | if (wp->w_lines_valid > wp->w_height) |
| 1985 | wp->w_lines_valid = wp->w_height; |
| 1986 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1987 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1988 | |
| 1989 | /* The w_lines[] entries for inserted lines are |
| 1990 | * now invalid, but wl_size may be used above. |
| 1991 | * Reset to zero. */ |
| 1992 | while (i >= idx) |
| 1993 | { |
| 1994 | wp->w_lines[i].wl_size = 0; |
| 1995 | wp->w_lines[i--].wl_valid = FALSE; |
| 1996 | } |
| 1997 | } |
| 1998 | } |
| 1999 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | #ifdef FEAT_FOLDING |
| 2003 | /* |
| 2004 | * When lines are folded, display one line for all of them. |
| 2005 | * Otherwise, display normally (can be several display lines when |
| 2006 | * 'wrap' is on). |
| 2007 | */ |
| 2008 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 2009 | if (fold_count != 0) |
| 2010 | { |
| 2011 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 2012 | ++row; |
| 2013 | --fold_count; |
| 2014 | wp->w_lines[idx].wl_folded = TRUE; |
| 2015 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 2016 | # ifdef FEAT_SYN_HL |
| 2017 | did_update = DID_FOLD; |
| 2018 | # endif |
| 2019 | } |
| 2020 | else |
| 2021 | #endif |
| 2022 | if (idx < wp->w_lines_valid |
| 2023 | && wp->w_lines[idx].wl_valid |
| 2024 | && wp->w_lines[idx].wl_lnum == lnum |
| 2025 | && lnum > wp->w_topline |
Bram Moolenaar | ad9c2a0 | 2016-07-27 23:26:04 +0200 | [diff] [blame] | 2026 | && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2027 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 2028 | #ifdef FEAT_DIFF |
| 2029 | && diff_check_fill(wp, lnum) == 0 |
| 2030 | #endif |
| 2031 | ) |
| 2032 | { |
| 2033 | /* This line is not going to fit. Don't draw anything here, |
| 2034 | * will draw "@ " lines below. */ |
| 2035 | row = wp->w_height + 1; |
| 2036 | } |
| 2037 | else |
| 2038 | { |
| 2039 | #ifdef FEAT_SEARCH_EXTRA |
| 2040 | prepare_search_hl(wp, lnum); |
| 2041 | #endif |
| 2042 | #ifdef FEAT_SYN_HL |
| 2043 | /* Let the syntax stuff know we skipped a few lines. */ |
| 2044 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2045 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2046 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2047 | #endif |
| 2048 | |
| 2049 | /* |
| 2050 | * Display one line. |
| 2051 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2052 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2053 | |
| 2054 | #ifdef FEAT_FOLDING |
| 2055 | wp->w_lines[idx].wl_folded = FALSE; |
| 2056 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2057 | #endif |
| 2058 | #ifdef FEAT_SYN_HL |
| 2059 | did_update = DID_LINE; |
| 2060 | syntax_last_parsed = lnum; |
| 2061 | #endif |
| 2062 | } |
| 2063 | |
| 2064 | wp->w_lines[idx].wl_lnum = lnum; |
| 2065 | wp->w_lines[idx].wl_valid = TRUE; |
| 2066 | if (row > wp->w_height) /* past end of screen */ |
| 2067 | { |
| 2068 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2069 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2070 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2071 | ++idx; |
| 2072 | break; |
| 2073 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2074 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2075 | wp->w_lines[idx].wl_size = row - srow; |
| 2076 | ++idx; |
| 2077 | #ifdef FEAT_FOLDING |
| 2078 | lnum += fold_count + 1; |
| 2079 | #else |
| 2080 | ++lnum; |
| 2081 | #endif |
| 2082 | } |
| 2083 | else |
| 2084 | { |
| 2085 | /* This line does not need updating, advance to the next one */ |
| 2086 | row += wp->w_lines[idx++].wl_size; |
| 2087 | if (row > wp->w_height) /* past end of screen */ |
| 2088 | break; |
| 2089 | #ifdef FEAT_FOLDING |
| 2090 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2091 | #else |
| 2092 | ++lnum; |
| 2093 | #endif |
| 2094 | #ifdef FEAT_SYN_HL |
| 2095 | did_update = DID_NONE; |
| 2096 | #endif |
| 2097 | } |
| 2098 | |
| 2099 | if (lnum > buf->b_ml.ml_line_count) |
| 2100 | { |
| 2101 | eof = TRUE; |
| 2102 | break; |
| 2103 | } |
| 2104 | } |
| 2105 | /* |
| 2106 | * End of loop over all window lines. |
| 2107 | */ |
| 2108 | |
| 2109 | |
| 2110 | if (idx > wp->w_lines_valid) |
| 2111 | wp->w_lines_valid = idx; |
| 2112 | |
| 2113 | #ifdef FEAT_SYN_HL |
| 2114 | /* |
| 2115 | * Let the syntax stuff know we stop parsing here. |
| 2116 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2117 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2118 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2119 | #endif |
| 2120 | |
| 2121 | /* |
| 2122 | * If we didn't hit the end of the file, and we didn't finish the last |
| 2123 | * line we were working on, then the line didn't fit. |
| 2124 | */ |
| 2125 | wp->w_empty_rows = 0; |
| 2126 | #ifdef FEAT_DIFF |
| 2127 | wp->w_filler_rows = 0; |
| 2128 | #endif |
| 2129 | if (!eof && !didline) |
| 2130 | { |
| 2131 | if (lnum == wp->w_topline) |
| 2132 | { |
| 2133 | /* |
| 2134 | * Single line that does not fit! |
| 2135 | * Don't overwrite it, it can be edited. |
| 2136 | */ |
| 2137 | wp->w_botline = lnum + 1; |
| 2138 | } |
| 2139 | #ifdef FEAT_DIFF |
| 2140 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2141 | { |
| 2142 | /* Window ends in filler lines. */ |
| 2143 | wp->w_botline = lnum; |
| 2144 | wp->w_filler_rows = wp->w_height - srow; |
| 2145 | } |
| 2146 | #endif |
Bram Moolenaar | ad9c2a0 | 2016-07-27 23:26:04 +0200 | [diff] [blame] | 2147 | else if (dy_flags & DY_TRUNCATE) /* 'display' has "truncate" */ |
| 2148 | { |
| 2149 | int scr_row = W_WINROW(wp) + wp->w_height - 1; |
| 2150 | |
| 2151 | /* |
| 2152 | * Last line isn't finished: Display "@@@" in the last screen line. |
| 2153 | */ |
| 2154 | screen_puts_len((char_u *)"@@", 2, scr_row, W_WINCOL(wp), |
| 2155 | hl_attr(HLF_AT)); |
| 2156 | screen_fill(scr_row, scr_row + 1, |
| 2157 | (int)W_WINCOL(wp) + 2, (int)W_ENDCOL(wp), |
| 2158 | '@', ' ', hl_attr(HLF_AT)); |
| 2159 | set_empty_rows(wp, srow); |
| 2160 | wp->w_botline = lnum; |
| 2161 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2162 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 2163 | { |
| 2164 | /* |
| 2165 | * Last line isn't finished: Display "@@@" at the end. |
| 2166 | */ |
| 2167 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2168 | W_WINROW(wp) + wp->w_height, |
| 2169 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 2170 | '@', '@', hl_attr(HLF_AT)); |
| 2171 | set_empty_rows(wp, srow); |
| 2172 | wp->w_botline = lnum; |
| 2173 | } |
| 2174 | else |
| 2175 | { |
| 2176 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 2177 | wp->w_botline = lnum; |
| 2178 | } |
| 2179 | } |
| 2180 | else |
| 2181 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 2182 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2183 | draw_vsep_win(wp, row); |
| 2184 | #endif |
| 2185 | if (eof) /* we hit the end of the file */ |
| 2186 | { |
| 2187 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2188 | #ifdef FEAT_DIFF |
| 2189 | j = diff_check_fill(wp, wp->w_botline); |
| 2190 | if (j > 0 && !wp->w_botfill) |
| 2191 | { |
| 2192 | /* |
| 2193 | * Display filler lines at the end of the file |
| 2194 | */ |
| 2195 | if (char2cells(fill_diff) > 1) |
| 2196 | i = '-'; |
| 2197 | else |
| 2198 | i = fill_diff; |
| 2199 | if (row + j > wp->w_height) |
| 2200 | j = wp->w_height - row; |
| 2201 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2202 | row += j; |
| 2203 | } |
| 2204 | #endif |
| 2205 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2206 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2207 | wp->w_botline = lnum; |
| 2208 | |
| 2209 | /* make sure the rest of the screen is blank */ |
| 2210 | /* put '~'s on rows that aren't part of the file. */ |
Bram Moolenaar | 58b8534 | 2016-08-14 19:54:54 +0200 | [diff] [blame] | 2211 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_EOB); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2215 | wp->w_redr_type = 0; |
| 2216 | #ifdef FEAT_DIFF |
| 2217 | wp->w_old_topfill = wp->w_topfill; |
| 2218 | wp->w_old_botfill = wp->w_botfill; |
| 2219 | #endif |
| 2220 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2221 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2222 | { |
| 2223 | /* |
| 2224 | * There is a trick with w_botline. If we invalidate it on each |
| 2225 | * change that might modify it, this will cause a lot of expensive |
| 2226 | * calls to plines() in update_topline() each time. Therefore the |
| 2227 | * value of w_botline is often approximated, and this value is used to |
| 2228 | * compute the value of w_topline. If the value of w_botline was |
| 2229 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2230 | * the visible part of the text). If it's not, we need to redraw |
| 2231 | * again. Mostly this just means scrolling up a few lines, so it |
| 2232 | * doesn't look too bad. Only do this for the current window (where |
| 2233 | * changes are relevant). |
| 2234 | */ |
| 2235 | wp->w_valid |= VALID_BOTLINE; |
| 2236 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2237 | { |
| 2238 | recursive = TRUE; |
| 2239 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2240 | update_topline(); /* may invalidate w_botline again */ |
| 2241 | if (must_redraw != 0) |
| 2242 | { |
| 2243 | /* Don't update for changes in buffer again. */ |
| 2244 | i = curbuf->b_mod_set; |
| 2245 | curbuf->b_mod_set = FALSE; |
| 2246 | win_update(curwin); |
| 2247 | must_redraw = 0; |
| 2248 | curbuf->b_mod_set = i; |
| 2249 | } |
| 2250 | recursive = FALSE; |
| 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2255 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2256 | if (!got_int) |
| 2257 | got_int = save_got_int; |
| 2258 | #endif |
| 2259 | } |
| 2260 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2261 | /* |
| 2262 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2263 | * as the filler character. |
| 2264 | */ |
| 2265 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2266 | win_draw_end( |
| 2267 | win_T *wp, |
| 2268 | int c1, |
| 2269 | int c2, |
| 2270 | int row, |
| 2271 | int endrow, |
| 2272 | hlf_T hl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2273 | { |
| 2274 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2275 | int n = 0; |
| 2276 | # define FDC_OFF n |
| 2277 | #else |
| 2278 | # define FDC_OFF 0 |
| 2279 | #endif |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2280 | #ifdef FEAT_FOLDING |
| 2281 | int fdc = compute_foldcolumn(wp, 0); |
| 2282 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2283 | |
| 2284 | #ifdef FEAT_RIGHTLEFT |
| 2285 | if (wp->w_p_rl) |
| 2286 | { |
| 2287 | /* No check for cmdline window: should never be right-left. */ |
| 2288 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2289 | n = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2290 | |
| 2291 | if (n > 0) |
| 2292 | { |
| 2293 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2294 | if (n > W_WIDTH(wp)) |
| 2295 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2296 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2297 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2298 | ' ', ' ', hl_attr(HLF_FC)); |
| 2299 | } |
| 2300 | # endif |
| 2301 | # ifdef FEAT_SIGNS |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 2302 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2303 | { |
| 2304 | int nn = n + 2; |
| 2305 | |
| 2306 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2307 | if (nn > W_WIDTH(wp)) |
| 2308 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2309 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2310 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2311 | ' ', ' ', hl_attr(HLF_SC)); |
| 2312 | n = nn; |
| 2313 | } |
| 2314 | # endif |
| 2315 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2316 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2317 | c2, c2, hl_attr(hl)); |
| 2318 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2319 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2320 | c1, c2, hl_attr(hl)); |
| 2321 | } |
| 2322 | else |
| 2323 | #endif |
| 2324 | { |
| 2325 | #ifdef FEAT_CMDWIN |
| 2326 | if (cmdwin_type != 0 && wp == curwin) |
| 2327 | { |
| 2328 | /* draw the cmdline character in the leftmost column */ |
| 2329 | n = 1; |
| 2330 | if (n > wp->w_width) |
| 2331 | n = wp->w_width; |
| 2332 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2333 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2334 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2335 | } |
| 2336 | #endif |
| 2337 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2338 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2339 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2340 | int nn = n + fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2341 | |
| 2342 | /* draw the fold column at the left */ |
| 2343 | if (nn > W_WIDTH(wp)) |
| 2344 | nn = W_WIDTH(wp); |
| 2345 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2346 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2347 | ' ', ' ', hl_attr(HLF_FC)); |
| 2348 | n = nn; |
| 2349 | } |
| 2350 | #endif |
| 2351 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 2352 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2353 | { |
| 2354 | int nn = n + 2; |
| 2355 | |
| 2356 | /* draw the sign column after the fold column */ |
| 2357 | if (nn > W_WIDTH(wp)) |
| 2358 | nn = W_WIDTH(wp); |
| 2359 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2360 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2361 | ' ', ' ', hl_attr(HLF_SC)); |
| 2362 | n = nn; |
| 2363 | } |
| 2364 | #endif |
| 2365 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2366 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2367 | c1, c2, hl_attr(hl)); |
| 2368 | } |
| 2369 | set_empty_rows(wp, row); |
| 2370 | } |
| 2371 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2372 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2373 | static int advance_color_col(int vcol, int **color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2374 | |
| 2375 | /* |
| 2376 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2377 | */ |
| 2378 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2379 | advance_color_col(int vcol, int **color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2380 | { |
| 2381 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2382 | ++*color_cols; |
| 2383 | return (**color_cols >= 0); |
| 2384 | } |
| 2385 | #endif |
| 2386 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2387 | #ifdef FEAT_FOLDING |
| 2388 | /* |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2389 | * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much |
| 2390 | * space is available for window "wp", minus "col". |
| 2391 | */ |
| 2392 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2393 | compute_foldcolumn(win_T *wp, int col) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2394 | { |
| 2395 | int fdc = wp->w_p_fdc; |
| 2396 | int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; |
| 2397 | int wwidth = W_WIDTH(wp); |
| 2398 | |
| 2399 | if (fdc > wwidth - (col + wmw)) |
| 2400 | fdc = wwidth - (col + wmw); |
| 2401 | return fdc; |
| 2402 | } |
| 2403 | |
| 2404 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2405 | * Display one folded line. |
| 2406 | */ |
| 2407 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2408 | fold_line( |
| 2409 | win_T *wp, |
| 2410 | long fold_count, |
| 2411 | foldinfo_T *foldinfo, |
| 2412 | linenr_T lnum, |
| 2413 | int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2414 | { |
Bram Moolenaar | ee695f7 | 2016-08-03 22:08:45 +0200 | [diff] [blame] | 2415 | char_u buf[FOLD_TEXT_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2416 | pos_T *top, *bot; |
| 2417 | linenr_T lnume = lnum + fold_count - 1; |
| 2418 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2419 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2420 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2421 | int col; |
| 2422 | int txtcol; |
| 2423 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2424 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2425 | |
| 2426 | /* Build the fold line: |
| 2427 | * 1. Add the cmdwin_type for the command-line window |
| 2428 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2429 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2430 | * 4. Compose the text |
| 2431 | * 5. Add the text |
| 2432 | * 6. set highlighting for the Visual area an other text |
| 2433 | */ |
| 2434 | col = 0; |
| 2435 | |
| 2436 | /* |
| 2437 | * 1. Add the cmdwin_type for the command-line window |
| 2438 | * Ignores 'rightleft', this window is never right-left. |
| 2439 | */ |
| 2440 | #ifdef FEAT_CMDWIN |
| 2441 | if (cmdwin_type != 0 && wp == curwin) |
| 2442 | { |
| 2443 | ScreenLines[off] = cmdwin_type; |
| 2444 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2445 | #ifdef FEAT_MBYTE |
| 2446 | if (enc_utf8) |
| 2447 | ScreenLinesUC[off] = 0; |
| 2448 | #endif |
| 2449 | ++col; |
| 2450 | } |
| 2451 | #endif |
| 2452 | |
| 2453 | /* |
| 2454 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2455 | * Reduce the width when there is not enough space. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2456 | */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2457 | fdc = compute_foldcolumn(wp, col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2458 | if (fdc > 0) |
| 2459 | { |
| 2460 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2461 | #ifdef FEAT_RIGHTLEFT |
| 2462 | if (wp->w_p_rl) |
| 2463 | { |
| 2464 | int i; |
| 2465 | |
| 2466 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2467 | hl_attr(HLF_FC)); |
| 2468 | /* reverse the fold column */ |
| 2469 | for (i = 0; i < fdc; ++i) |
| 2470 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2471 | } |
| 2472 | else |
| 2473 | #endif |
| 2474 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2475 | col += fdc; |
| 2476 | } |
| 2477 | |
| 2478 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2479 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2480 | for (ri = 0; ri < l; ++ri) \ |
| 2481 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2482 | else \ |
| 2483 | for (ri = 0; ri < l; ++ri) \ |
| 2484 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2485 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2486 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2487 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2488 | #endif |
| 2489 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2490 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2491 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2492 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2493 | |
| 2494 | #ifdef FEAT_SIGNS |
| 2495 | /* If signs are being displayed, add two spaces. */ |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 2496 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2497 | { |
| 2498 | len = W_WIDTH(wp) - col; |
| 2499 | if (len > 0) |
| 2500 | { |
| 2501 | if (len > 2) |
| 2502 | len = 2; |
| 2503 | # ifdef FEAT_RIGHTLEFT |
| 2504 | if (wp->w_p_rl) |
| 2505 | /* the line number isn't reversed */ |
| 2506 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2507 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2508 | else |
| 2509 | # endif |
| 2510 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2511 | col += len; |
| 2512 | } |
| 2513 | } |
| 2514 | #endif |
| 2515 | |
| 2516 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2517 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2518 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2519 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2520 | { |
| 2521 | len = W_WIDTH(wp) - col; |
| 2522 | if (len > 0) |
| 2523 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2524 | int w = number_width(wp); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2525 | long num; |
| 2526 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2527 | |
| 2528 | if (len > w + 1) |
| 2529 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2530 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2531 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2532 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2533 | num = (long)lnum; |
| 2534 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2535 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2536 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2537 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2538 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2539 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2540 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2541 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2542 | num = lnum; |
| 2543 | fmt = "%-*ld "; |
| 2544 | } |
| 2545 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2546 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2547 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2548 | #ifdef FEAT_RIGHTLEFT |
| 2549 | if (wp->w_p_rl) |
| 2550 | /* the line number isn't reversed */ |
| 2551 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2552 | hl_attr(HLF_FL)); |
| 2553 | else |
| 2554 | #endif |
| 2555 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2556 | col += len; |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | /* |
| 2561 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2562 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2563 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2564 | |
| 2565 | txtcol = col; /* remember where text starts */ |
| 2566 | |
| 2567 | /* |
| 2568 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2569 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2570 | * in columns number-col - window-width. |
| 2571 | */ |
| 2572 | #ifdef FEAT_MBYTE |
| 2573 | if (has_mbyte) |
| 2574 | { |
| 2575 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2576 | int u8c, u8cc[MAX_MCO]; |
| 2577 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2578 | int idx; |
| 2579 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2580 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2581 | # ifdef FEAT_ARABIC |
| 2582 | int prev_c = 0; /* previous Arabic character */ |
| 2583 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2584 | # endif |
| 2585 | |
| 2586 | # ifdef FEAT_RIGHTLEFT |
| 2587 | if (wp->w_p_rl) |
| 2588 | idx = off; |
| 2589 | else |
| 2590 | # endif |
| 2591 | idx = off + col; |
| 2592 | |
| 2593 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2594 | for (p = text; *p != NUL; ) |
| 2595 | { |
| 2596 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2597 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2598 | if (col + cells > W_WIDTH(wp) |
| 2599 | # ifdef FEAT_RIGHTLEFT |
| 2600 | - (wp->w_p_rl ? col : 0) |
| 2601 | # endif |
| 2602 | ) |
| 2603 | break; |
| 2604 | ScreenLines[idx] = *p; |
| 2605 | if (enc_utf8) |
| 2606 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2607 | u8c = utfc_ptr2char(p, u8cc); |
| 2608 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2609 | { |
| 2610 | ScreenLinesUC[idx] = 0; |
| 2611 | #ifdef FEAT_ARABIC |
| 2612 | prev_c = u8c; |
| 2613 | #endif |
| 2614 | } |
| 2615 | else |
| 2616 | { |
| 2617 | #ifdef FEAT_ARABIC |
| 2618 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2619 | { |
| 2620 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2621 | int pc, pc1, nc; |
| 2622 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2623 | int firstbyte = *p; |
| 2624 | |
| 2625 | /* The idea of what is the previous and next |
| 2626 | * character depends on 'rightleft'. */ |
| 2627 | if (wp->w_p_rl) |
| 2628 | { |
| 2629 | pc = prev_c; |
| 2630 | pc1 = prev_c1; |
| 2631 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2632 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2633 | } |
| 2634 | else |
| 2635 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2636 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2637 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2638 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2639 | } |
| 2640 | prev_c = u8c; |
| 2641 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2642 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2643 | pc, pc1, nc); |
| 2644 | ScreenLines[idx] = firstbyte; |
| 2645 | } |
| 2646 | else |
| 2647 | prev_c = u8c; |
| 2648 | #endif |
| 2649 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2650 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2651 | if (u8c >= 0x10000) |
| 2652 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2653 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2654 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2655 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2656 | for (i = 0; i < Screen_mco; ++i) |
| 2657 | { |
| 2658 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2659 | if (u8cc[i] == 0) |
| 2660 | break; |
| 2661 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2662 | } |
| 2663 | if (cells > 1) |
| 2664 | ScreenLines[idx + 1] = 0; |
| 2665 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2666 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2667 | /* double-byte single width character */ |
| 2668 | ScreenLines2[idx] = p[1]; |
| 2669 | else if (cells > 1) |
| 2670 | /* double-width character */ |
| 2671 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2672 | col += cells; |
| 2673 | idx += cells; |
| 2674 | p += c_len; |
| 2675 | } |
| 2676 | } |
| 2677 | else |
| 2678 | #endif |
| 2679 | { |
| 2680 | len = (int)STRLEN(text); |
| 2681 | if (len > W_WIDTH(wp) - col) |
| 2682 | len = W_WIDTH(wp) - col; |
| 2683 | if (len > 0) |
| 2684 | { |
| 2685 | #ifdef FEAT_RIGHTLEFT |
| 2686 | if (wp->w_p_rl) |
| 2687 | STRNCPY(current_ScreenLine, text, len); |
| 2688 | else |
| 2689 | #endif |
| 2690 | STRNCPY(current_ScreenLine + col, text, len); |
| 2691 | col += len; |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | /* Fill the rest of the line with the fold filler */ |
| 2696 | #ifdef FEAT_RIGHTLEFT |
| 2697 | if (wp->w_p_rl) |
| 2698 | col -= txtcol; |
| 2699 | #endif |
| 2700 | while (col < W_WIDTH(wp) |
| 2701 | #ifdef FEAT_RIGHTLEFT |
| 2702 | - (wp->w_p_rl ? txtcol : 0) |
| 2703 | #endif |
| 2704 | ) |
| 2705 | { |
| 2706 | #ifdef FEAT_MBYTE |
| 2707 | if (enc_utf8) |
| 2708 | { |
| 2709 | if (fill_fold >= 0x80) |
| 2710 | { |
| 2711 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2712 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2713 | } |
| 2714 | else |
| 2715 | ScreenLinesUC[off + col] = 0; |
| 2716 | } |
| 2717 | #endif |
| 2718 | ScreenLines[off + col++] = fill_fold; |
| 2719 | } |
| 2720 | |
| 2721 | if (text != buf) |
| 2722 | vim_free(text); |
| 2723 | |
| 2724 | /* |
| 2725 | * 6. set highlighting for the Visual area an other text. |
| 2726 | * If all folded lines are in the Visual area, highlight the line. |
| 2727 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2728 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2729 | { |
| 2730 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2731 | { |
| 2732 | /* Visual is after curwin->w_cursor */ |
| 2733 | top = &curwin->w_cursor; |
| 2734 | bot = &VIsual; |
| 2735 | } |
| 2736 | else |
| 2737 | { |
| 2738 | /* Visual is before curwin->w_cursor */ |
| 2739 | top = &VIsual; |
| 2740 | bot = &curwin->w_cursor; |
| 2741 | } |
| 2742 | if (lnum >= top->lnum |
| 2743 | && lnume <= bot->lnum |
| 2744 | && (VIsual_mode != 'v' |
| 2745 | || ((lnum > top->lnum |
| 2746 | || (lnum == top->lnum |
| 2747 | && top->col == 0)) |
| 2748 | && (lnume < bot->lnum |
| 2749 | || (lnume == bot->lnum |
| 2750 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2751 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2752 | { |
| 2753 | if (VIsual_mode == Ctrl_V) |
| 2754 | { |
| 2755 | /* Visual block mode: highlight the chars part of the block */ |
| 2756 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2757 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2758 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2759 | && wp->w_old_cursor_lcol + txtcol |
| 2760 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2761 | len = wp->w_old_cursor_lcol; |
| 2762 | else |
| 2763 | len = W_WIDTH(wp) - txtcol; |
| 2764 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2765 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2766 | } |
| 2767 | } |
| 2768 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2769 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2770 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2771 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2772 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2773 | } |
| 2774 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2775 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2776 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | fbc25b2 | 2015-03-20 17:16:27 +0100 | [diff] [blame] | 2777 | /* Show colorcolumn in the fold line, but let cursorcolumn override it. */ |
| 2778 | if (wp->w_p_cc_cols) |
| 2779 | { |
| 2780 | int i = 0; |
| 2781 | int j = wp->w_p_cc_cols[i]; |
| 2782 | int old_txtcol = txtcol; |
| 2783 | |
| 2784 | while (j > -1) |
| 2785 | { |
| 2786 | txtcol += j; |
| 2787 | if (wp->w_p_wrap) |
| 2788 | txtcol -= wp->w_skipcol; |
| 2789 | else |
| 2790 | txtcol -= wp->w_leftcol; |
| 2791 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2792 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2793 | ScreenAttrs[off + txtcol], hl_attr(HLF_MC)); |
| 2794 | txtcol = old_txtcol; |
| 2795 | j = wp->w_p_cc_cols[++i]; |
| 2796 | } |
| 2797 | } |
| 2798 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2799 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2800 | if (wp->w_p_cuc) |
| 2801 | { |
| 2802 | txtcol += wp->w_virtcol; |
| 2803 | if (wp->w_p_wrap) |
| 2804 | txtcol -= wp->w_skipcol; |
| 2805 | else |
| 2806 | txtcol -= wp->w_leftcol; |
| 2807 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2808 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2809 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2810 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2811 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2812 | |
| 2813 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2814 | (int)W_WIDTH(wp), FALSE); |
| 2815 | |
| 2816 | /* |
| 2817 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2818 | * updated (saves a call to plines() later). |
| 2819 | */ |
| 2820 | if (wp == curwin |
| 2821 | && lnum <= curwin->w_cursor.lnum |
| 2822 | && lnume >= curwin->w_cursor.lnum) |
| 2823 | { |
| 2824 | curwin->w_cline_row = row; |
| 2825 | curwin->w_cline_height = 1; |
| 2826 | curwin->w_cline_folded = TRUE; |
| 2827 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | /* |
| 2832 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2833 | */ |
| 2834 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2835 | copy_text_attr( |
| 2836 | int off, |
| 2837 | char_u *buf, |
| 2838 | int len, |
| 2839 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2840 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2841 | int i; |
| 2842 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2843 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2844 | # ifdef FEAT_MBYTE |
| 2845 | if (enc_utf8) |
| 2846 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2847 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2848 | for (i = 0; i < len; ++i) |
| 2849 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | /* |
| 2853 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2854 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2855 | */ |
| 2856 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2857 | fill_foldcolumn( |
| 2858 | char_u *p, |
| 2859 | win_T *wp, |
| 2860 | int closed, /* TRUE of FALSE */ |
| 2861 | linenr_T lnum) /* current line number */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2862 | { |
| 2863 | int i = 0; |
| 2864 | int level; |
| 2865 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2866 | int empty; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2867 | int fdc = compute_foldcolumn(wp, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2868 | |
| 2869 | /* Init to all spaces. */ |
Bram Moolenaar | 2536d4f | 2015-07-17 13:22:51 +0200 | [diff] [blame] | 2870 | vim_memset(p, ' ', (size_t)fdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2871 | |
| 2872 | level = win_foldinfo.fi_level; |
| 2873 | if (level > 0) |
| 2874 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2875 | /* If there is only one column put more info in it. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2876 | empty = (fdc == 1) ? 0 : 1; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2877 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2878 | /* If the column is too narrow, we start at the lowest level that |
| 2879 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2880 | first_level = level - fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2881 | if (first_level < 1) |
| 2882 | first_level = 1; |
| 2883 | |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2884 | for (i = 0; i + empty < fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2885 | { |
| 2886 | if (win_foldinfo.fi_lnum == lnum |
| 2887 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2888 | p[i] = '-'; |
| 2889 | else if (first_level == 1) |
| 2890 | p[i] = '|'; |
| 2891 | else if (first_level + i <= 9) |
| 2892 | p[i] = '0' + first_level + i; |
| 2893 | else |
| 2894 | p[i] = '>'; |
| 2895 | if (first_level + i == level) |
| 2896 | break; |
| 2897 | } |
| 2898 | } |
| 2899 | if (closed) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2900 | p[i >= fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2901 | } |
| 2902 | #endif /* FEAT_FOLDING */ |
| 2903 | |
| 2904 | /* |
| 2905 | * Display line "lnum" of window 'wp' on the screen. |
| 2906 | * Start at row "startrow", stop when "endrow" is reached. |
| 2907 | * wp->w_virtcol needs to be valid. |
| 2908 | * |
| 2909 | * Return the number of last row the line occupies. |
| 2910 | */ |
| 2911 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2912 | win_line( |
| 2913 | win_T *wp, |
| 2914 | linenr_T lnum, |
| 2915 | int startrow, |
| 2916 | int endrow, |
| 2917 | int nochange UNUSED) /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2918 | { |
| 2919 | int col; /* visual column on screen */ |
| 2920 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2921 | int c = 0; /* init for GCC */ |
| 2922 | long vcol = 0; /* virtual column (for tabs) */ |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 2923 | #ifdef FEAT_LINEBREAK |
| 2924 | long vcol_sbr = -1; /* virtual column after showbreak */ |
| 2925 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2926 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2927 | char_u *line; /* current line */ |
| 2928 | char_u *ptr; /* current position in "line" */ |
| 2929 | int row; /* row in the window, excl w_winrow */ |
| 2930 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2931 | |
| 2932 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2933 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2934 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 2935 | char_u *p_extra_free = NULL; /* p_extra needs to be freed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2936 | int c_extra = NUL; /* extra chars, all the same */ |
| 2937 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2938 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2939 | displaying lcs_eol at end-of-line */ |
| 2940 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2941 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2942 | |
| 2943 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2944 | int saved_n_extra = 0; |
| 2945 | char_u *saved_p_extra = NULL; |
| 2946 | int saved_c_extra = 0; |
| 2947 | int saved_char_attr = 0; |
| 2948 | |
| 2949 | int n_attr = 0; /* chars with special attr */ |
| 2950 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2951 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2952 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2953 | |
| 2954 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2955 | |
| 2956 | int fromcol, tocol; /* start/end of inverting */ |
| 2957 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2958 | int noinvcur = FALSE; /* don't invert the cursor */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2959 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2960 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2961 | pos_T pos; |
| 2962 | long v; |
| 2963 | |
| 2964 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2965 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2966 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2967 | in this line */ |
| 2968 | int attr = 0; /* attributes for area highlighting */ |
| 2969 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2970 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2971 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2972 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2973 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2974 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2975 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2976 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2977 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2978 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2979 | #endif |
| 2980 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2981 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2982 | # define SPWORDLEN 150 |
| 2983 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2984 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2985 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2986 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2987 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2988 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2989 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2990 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2991 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2992 | static int cap_col = -1; /* column to check for Cap word */ |
| 2993 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2994 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2995 | #endif |
| 2996 | int extra_check; /* has syntax or linebreak */ |
| 2997 | #ifdef FEAT_MBYTE |
| 2998 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2999 | int mb_l = 1; /* multi-byte byte length */ |
| 3000 | int mb_c = 0; /* decoded multi-byte character */ |
| 3001 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3002 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3003 | #endif |
| 3004 | #ifdef FEAT_DIFF |
| 3005 | int filler_lines; /* nr of filler lines to be drawn */ |
| 3006 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3007 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3008 | int change_start = MAXCOL; /* first col of changed area */ |
| 3009 | int change_end = -1; /* last col of changed area */ |
| 3010 | #endif |
| 3011 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 3012 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 3013 | int need_showbreak = FALSE; /* overlong line, skipping first x |
| 3014 | chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3015 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3016 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 3017 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3018 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3019 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3020 | #endif |
| 3021 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3022 | matchitem_T *cur; /* points to the match list */ |
| 3023 | match_T *shl; /* points to search_hl or a match */ |
| 3024 | int shl_flag; /* flag to indicate whether search_hl |
| 3025 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3026 | int pos_inprogress; /* marks that position match search is |
| 3027 | in progress */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3028 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 3029 | equals startcol of search_hl or one |
| 3030 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3031 | #endif |
| 3032 | #ifdef FEAT_ARABIC |
| 3033 | int prev_c = 0; /* previous Arabic character */ |
| 3034 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 3035 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3036 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 3037 | int did_line_attr = 0; |
| 3038 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3039 | |
| 3040 | /* draw_state: items that are drawn in sequence: */ |
| 3041 | #define WL_START 0 /* nothing done yet */ |
| 3042 | #ifdef FEAT_CMDWIN |
| 3043 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 3044 | #else |
| 3045 | # define WL_CMDLINE WL_START |
| 3046 | #endif |
| 3047 | #ifdef FEAT_FOLDING |
| 3048 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 3049 | #else |
| 3050 | # define WL_FOLD WL_CMDLINE |
| 3051 | #endif |
| 3052 | #ifdef FEAT_SIGNS |
| 3053 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 3054 | #else |
| 3055 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 3056 | #endif |
| 3057 | #define WL_NR WL_SIGN + 1 /* line number */ |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3058 | #ifdef FEAT_LINEBREAK |
| 3059 | # define WL_BRI WL_NR + 1 /* 'breakindent' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3060 | #else |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3061 | # define WL_BRI WL_NR |
| 3062 | #endif |
| 3063 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3064 | # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */ |
| 3065 | #else |
| 3066 | # define WL_SBR WL_BRI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3067 | #endif |
| 3068 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 3069 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 3070 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3071 | int feedback_col = 0; |
| 3072 | int feedback_old_attr = -1; |
| 3073 | #endif |
| 3074 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3075 | #ifdef FEAT_CONCEAL |
| 3076 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 3077 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 3078 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3079 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3080 | int is_concealing = FALSE; |
| 3081 | int boguscols = 0; /* nonexistent columns added to force |
| 3082 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3083 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3084 | int did_wcol = FALSE; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3085 | int match_conc = 0; /* cchar for match functions */ |
| 3086 | int has_match_conc = 0; /* match wants to conceal */ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3087 | int old_boguscols = 0; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3088 | # define VCOL_HLC (vcol - vcol_off) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3089 | # define FIX_FOR_BOGUSCOLS \ |
| 3090 | { \ |
| 3091 | n_extra += vcol_off; \ |
| 3092 | vcol -= vcol_off; \ |
| 3093 | vcol_off = 0; \ |
| 3094 | col -= boguscols; \ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3095 | old_boguscols = boguscols; \ |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3096 | boguscols = 0; \ |
| 3097 | } |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3098 | #else |
| 3099 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3100 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3101 | |
| 3102 | if (startrow > endrow) /* past the end already! */ |
| 3103 | return startrow; |
| 3104 | |
| 3105 | row = startrow; |
| 3106 | screen_row = row + W_WINROW(wp); |
| 3107 | |
| 3108 | /* |
| 3109 | * To speed up the loop below, set extra_check when there is linebreak, |
| 3110 | * trailing white space and/or syntax processing to be done. |
| 3111 | */ |
| 3112 | #ifdef FEAT_LINEBREAK |
| 3113 | extra_check = wp->w_p_lbr; |
| 3114 | #else |
| 3115 | extra_check = 0; |
| 3116 | #endif |
| 3117 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3118 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3119 | { |
| 3120 | /* Prepare for syntax highlighting in this line. When there is an |
| 3121 | * error, stop syntax highlighting. */ |
| 3122 | save_did_emsg = did_emsg; |
| 3123 | did_emsg = FALSE; |
| 3124 | syntax_start(wp, lnum); |
| 3125 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3126 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3127 | else |
| 3128 | { |
| 3129 | did_emsg = save_did_emsg; |
| 3130 | has_syntax = TRUE; |
| 3131 | extra_check = TRUE; |
| 3132 | } |
| 3133 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3134 | |
| 3135 | /* Check for columns to display for 'colorcolumn'. */ |
| 3136 | color_cols = wp->w_p_cc_cols; |
| 3137 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3138 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3139 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3140 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3141 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3142 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3143 | && *wp->w_s->b_p_spl != NUL |
| 3144 | && wp->w_s->b_langp.ga_len > 0 |
| 3145 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3146 | { |
| 3147 | /* Prepare for spell checking. */ |
| 3148 | has_spell = TRUE; |
| 3149 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3150 | |
| 3151 | /* Get the start of the next line, so that words that wrap to the next |
| 3152 | * line are found too: "et<line-break>al.". |
| 3153 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 3154 | nextline[SPWORDLEN] = NUL; |
| 3155 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 3156 | { |
| 3157 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 3158 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 3159 | } |
| 3160 | |
| 3161 | /* When a word wrapped from the previous line the start of the current |
| 3162 | * line is valid. */ |
| 3163 | if (lnum == checked_lnum) |
| 3164 | cur_checked_col = checked_col; |
| 3165 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3166 | |
| 3167 | /* When there was a sentence end in the previous line may require a |
| 3168 | * word starting with capital in this line. In line 1 always check |
| 3169 | * the first word. */ |
| 3170 | if (lnum != capcol_lnum) |
| 3171 | cap_col = -1; |
| 3172 | if (lnum == 1) |
| 3173 | cap_col = 0; |
| 3174 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3175 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3176 | #endif |
| 3177 | |
| 3178 | /* |
| 3179 | * handle visual active in this window |
| 3180 | */ |
| 3181 | fromcol = -10; |
| 3182 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3183 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3184 | { |
| 3185 | /* Visual is after curwin->w_cursor */ |
| 3186 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 3187 | { |
| 3188 | top = &curwin->w_cursor; |
| 3189 | bot = &VIsual; |
| 3190 | } |
| 3191 | else /* Visual is before curwin->w_cursor */ |
| 3192 | { |
| 3193 | top = &VIsual; |
| 3194 | bot = &curwin->w_cursor; |
| 3195 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3196 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3197 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 3198 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3199 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3200 | { |
| 3201 | fromcol = wp->w_old_cursor_fcol; |
| 3202 | tocol = wp->w_old_cursor_lcol; |
| 3203 | } |
| 3204 | } |
| 3205 | else /* non-block mode */ |
| 3206 | { |
| 3207 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 3208 | fromcol = 0; |
| 3209 | else if (lnum == top->lnum) |
| 3210 | { |
| 3211 | if (VIsual_mode == 'V') /* linewise */ |
| 3212 | fromcol = 0; |
| 3213 | else |
| 3214 | { |
| 3215 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 3216 | if (gchar_pos(top) == NUL) |
| 3217 | tocol = fromcol + 1; |
| 3218 | } |
| 3219 | } |
| 3220 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 3221 | { |
| 3222 | if (*p_sel == 'e' && bot->col == 0 |
| 3223 | #ifdef FEAT_VIRTUALEDIT |
| 3224 | && bot->coladd == 0 |
| 3225 | #endif |
| 3226 | ) |
| 3227 | { |
| 3228 | fromcol = -10; |
| 3229 | tocol = MAXCOL; |
| 3230 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3231 | else if (bot->col == MAXCOL) |
| 3232 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3233 | else |
| 3234 | { |
| 3235 | pos = *bot; |
| 3236 | if (*p_sel == 'e') |
| 3237 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3238 | else |
| 3239 | { |
| 3240 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3241 | ++tocol; |
| 3242 | } |
| 3243 | } |
| 3244 | } |
| 3245 | } |
| 3246 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3247 | /* Check if the character under the cursor should not be inverted */ |
| 3248 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3249 | #ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3250 | && !gui.in_use |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3251 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3252 | ) |
| 3253 | noinvcur = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3254 | |
| 3255 | /* if inverting in this line set area_highlighting */ |
| 3256 | if (fromcol >= 0) |
| 3257 | { |
| 3258 | area_highlighting = TRUE; |
| 3259 | attr = hl_attr(HLF_V); |
| 3260 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3261 | if ((clip_star.available && !clip_star.owned |
| 3262 | && clip_isautosel_star()) |
| 3263 | || (clip_plus.available && !clip_plus.owned |
| 3264 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3265 | attr = hl_attr(HLF_VNC); |
| 3266 | #endif |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3271 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3272 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3273 | else if (highlight_match |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3274 | && wp == curwin |
| 3275 | && lnum >= curwin->w_cursor.lnum |
| 3276 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3277 | { |
| 3278 | if (lnum == curwin->w_cursor.lnum) |
| 3279 | getvcol(curwin, &(curwin->w_cursor), |
| 3280 | (colnr_T *)&fromcol, NULL, NULL); |
| 3281 | else |
| 3282 | fromcol = 0; |
| 3283 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3284 | { |
| 3285 | pos.lnum = lnum; |
| 3286 | pos.col = search_match_endcol; |
| 3287 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3288 | } |
| 3289 | else |
| 3290 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3291 | /* do at least one character; happens when past end of line */ |
| 3292 | if (fromcol == tocol) |
| 3293 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3294 | area_highlighting = TRUE; |
| 3295 | attr = hl_attr(HLF_I); |
| 3296 | } |
| 3297 | |
| 3298 | #ifdef FEAT_DIFF |
| 3299 | filler_lines = diff_check(wp, lnum); |
| 3300 | if (filler_lines < 0) |
| 3301 | { |
| 3302 | if (filler_lines == -1) |
| 3303 | { |
| 3304 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3305 | diff_hlf = HLF_ADD; /* added line */ |
| 3306 | else if (change_start == 0) |
| 3307 | diff_hlf = HLF_TXD; /* changed text */ |
| 3308 | else |
| 3309 | diff_hlf = HLF_CHD; /* changed line */ |
| 3310 | } |
| 3311 | else |
| 3312 | diff_hlf = HLF_ADD; /* added line */ |
| 3313 | filler_lines = 0; |
| 3314 | area_highlighting = TRUE; |
| 3315 | } |
| 3316 | if (lnum == wp->w_topline) |
| 3317 | filler_lines = wp->w_topfill; |
| 3318 | filler_todo = filler_lines; |
| 3319 | #endif |
| 3320 | |
| 3321 | #ifdef LINE_ATTR |
| 3322 | # ifdef FEAT_SIGNS |
| 3323 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3324 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3325 | if (v != 0) |
| 3326 | line_attr = sign_get_attr((int)v, TRUE); |
| 3327 | # endif |
| 3328 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3329 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3330 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3331 | line_attr = hl_attr(HLF_L); |
| 3332 | # endif |
| 3333 | if (line_attr != 0) |
| 3334 | area_highlighting = TRUE; |
| 3335 | #endif |
| 3336 | |
| 3337 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3338 | ptr = line; |
| 3339 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3340 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3341 | if (has_spell) |
| 3342 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3343 | /* For checking first word with a capital skip white space. */ |
| 3344 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3345 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3346 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3347 | /* To be able to spell-check over line boundaries copy the end of the |
| 3348 | * current line into nextline[]. Above the start of the next line was |
| 3349 | * copied to nextline[SPWORDLEN]. */ |
| 3350 | if (nextline[SPWORDLEN] == NUL) |
| 3351 | { |
| 3352 | /* No next line or it is empty. */ |
| 3353 | nextlinecol = MAXCOL; |
| 3354 | nextline_idx = 0; |
| 3355 | } |
| 3356 | else |
| 3357 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3358 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3359 | if (v < SPWORDLEN) |
| 3360 | { |
| 3361 | /* Short line, use it completely and append the start of the |
| 3362 | * next line. */ |
| 3363 | nextlinecol = 0; |
| 3364 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3365 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3366 | nextline_idx = v + 1; |
| 3367 | } |
| 3368 | else |
| 3369 | { |
| 3370 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3371 | nextlinecol = v - SPWORDLEN; |
| 3372 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3373 | nextline_idx = SPWORDLEN + 1; |
| 3374 | } |
| 3375 | } |
| 3376 | } |
| 3377 | #endif |
| 3378 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3379 | if (wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3380 | { |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3381 | if (lcs_space || lcs_trail) |
| 3382 | extra_check = TRUE; |
| 3383 | /* find start of trailing whitespace */ |
| 3384 | if (lcs_trail) |
| 3385 | { |
| 3386 | trailcol = (colnr_T)STRLEN(ptr); |
| 3387 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3388 | --trailcol; |
| 3389 | trailcol += (colnr_T) (ptr - line); |
| 3390 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | /* |
| 3394 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3395 | * first character to be displayed. |
| 3396 | */ |
| 3397 | if (wp->w_p_wrap) |
| 3398 | v = wp->w_skipcol; |
| 3399 | else |
| 3400 | v = wp->w_leftcol; |
| 3401 | if (v > 0) |
| 3402 | { |
| 3403 | #ifdef FEAT_MBYTE |
| 3404 | char_u *prev_ptr = ptr; |
| 3405 | #endif |
| 3406 | while (vcol < v && *ptr != NUL) |
| 3407 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3408 | c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3409 | vcol += c; |
| 3410 | #ifdef FEAT_MBYTE |
| 3411 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3412 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3413 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3416 | /* When: |
| 3417 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3418 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3419 | * - 'virtualedit' is set, or |
| 3420 | * - the visual mode is active, |
| 3421 | * the end of the line may be before the start of the displayed part. |
| 3422 | */ |
| 3423 | if (vcol < v && ( |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3424 | #ifdef FEAT_SYN_HL |
| 3425 | wp->w_p_cuc || draw_color_col || |
| 3426 | #endif |
| 3427 | #ifdef FEAT_VIRTUALEDIT |
| 3428 | virtual_active() || |
| 3429 | #endif |
| 3430 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3431 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3432 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3433 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3434 | |
| 3435 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3436 | * that character but skip the first few screen characters. */ |
| 3437 | if (vcol > v) |
| 3438 | { |
| 3439 | vcol -= c; |
| 3440 | #ifdef FEAT_MBYTE |
| 3441 | ptr = prev_ptr; |
| 3442 | #else |
| 3443 | --ptr; |
| 3444 | #endif |
| 3445 | n_skip = v - vcol; |
| 3446 | } |
| 3447 | |
| 3448 | /* |
| 3449 | * Adjust for when the inverted text is before the screen, |
| 3450 | * and when the start of the inverted text is before the screen. |
| 3451 | */ |
| 3452 | if (tocol <= vcol) |
| 3453 | fromcol = 0; |
| 3454 | else if (fromcol >= 0 && fromcol < vcol) |
| 3455 | fromcol = vcol; |
| 3456 | |
| 3457 | #ifdef FEAT_LINEBREAK |
| 3458 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3459 | if (wp->w_p_wrap) |
| 3460 | need_showbreak = TRUE; |
| 3461 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3462 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3463 | /* When spell checking a word we need to figure out the start of the |
| 3464 | * word and if it's badly spelled or not. */ |
| 3465 | if (has_spell) |
| 3466 | { |
| 3467 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3468 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3469 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3470 | |
| 3471 | pos = wp->w_cursor; |
| 3472 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3473 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3474 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3475 | |
| 3476 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3477 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3478 | ptr = line + linecol; |
| 3479 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3480 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3481 | { |
| 3482 | /* no bad word found at line start, don't check until end of a |
| 3483 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3484 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3485 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3486 | } |
| 3487 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3488 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3489 | /* bad word found, use attributes until end of word */ |
| 3490 | word_end = wp->w_cursor.col + len + 1; |
| 3491 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3492 | /* Turn index into actual attributes. */ |
| 3493 | if (spell_hlf != HLF_COUNT) |
| 3494 | spell_attr = highlight_attr[spell_hlf]; |
| 3495 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3496 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3497 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3498 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3499 | /* Need to restart syntax highlighting for this line. */ |
| 3500 | if (has_syntax) |
| 3501 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3502 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3503 | } |
| 3504 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | /* |
| 3508 | * Correct highlighting for cursor that can't be disabled. |
| 3509 | * Avoids having to check this for each character. |
| 3510 | */ |
| 3511 | if (fromcol >= 0) |
| 3512 | { |
| 3513 | if (noinvcur) |
| 3514 | { |
| 3515 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3516 | { |
| 3517 | /* highlighting starts at cursor, let it start just after the |
| 3518 | * cursor */ |
| 3519 | fromcol_prev = fromcol; |
| 3520 | fromcol = -1; |
| 3521 | } |
| 3522 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3523 | /* restart highlighting after the cursor */ |
| 3524 | fromcol_prev = wp->w_virtcol; |
| 3525 | } |
| 3526 | if (fromcol >= tocol) |
| 3527 | fromcol = -1; |
| 3528 | } |
| 3529 | |
| 3530 | #ifdef FEAT_SEARCH_EXTRA |
| 3531 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3532 | * Handle highlighting the last used search pattern and matches. |
| 3533 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3534 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3535 | cur = wp->w_match_head; |
| 3536 | shl_flag = FALSE; |
| 3537 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3538 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3539 | if (shl_flag == FALSE) |
| 3540 | { |
| 3541 | shl = &search_hl; |
| 3542 | shl_flag = TRUE; |
| 3543 | } |
| 3544 | else |
| 3545 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3546 | shl->startcol = MAXCOL; |
| 3547 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3548 | shl->attr_cur = 0; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 3549 | shl->is_addpos = FALSE; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3550 | v = (long)(ptr - line); |
| 3551 | if (cur != NULL) |
| 3552 | cur->pos.cur = 0; |
Bram Moolenaar | e17bdff | 2016-08-27 18:34:29 +0200 | [diff] [blame] | 3553 | next_search_hl(wp, shl, lnum, (colnr_T)v, |
| 3554 | shl == &search_hl ? NULL : cur); |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3555 | |
| 3556 | /* Need to get the line again, a multi-line regexp may have made it |
| 3557 | * invalid. */ |
| 3558 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3559 | ptr = line + v; |
| 3560 | |
| 3561 | if (shl->lnum != 0 && shl->lnum <= lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3562 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3563 | if (shl->lnum == lnum) |
| 3564 | shl->startcol = shl->rm.startpos[0].col; |
| 3565 | else |
| 3566 | shl->startcol = 0; |
| 3567 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3568 | - shl->rm.startpos[0].lnum) |
| 3569 | shl->endcol = shl->rm.endpos[0].col; |
| 3570 | else |
| 3571 | shl->endcol = MAXCOL; |
| 3572 | /* Highlight one character for an empty match. */ |
| 3573 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3574 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3575 | #ifdef FEAT_MBYTE |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3576 | if (has_mbyte && line[shl->endcol] != NUL) |
| 3577 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
| 3578 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3579 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3580 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3581 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3582 | if ((long)shl->startcol < v) /* match at leftcol */ |
| 3583 | { |
| 3584 | shl->attr_cur = shl->attr; |
| 3585 | search_attr = shl->attr; |
| 3586 | } |
| 3587 | area_highlighting = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3588 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3589 | if (shl != &search_hl && cur != NULL) |
| 3590 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3591 | } |
| 3592 | #endif |
| 3593 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3594 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3595 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3596 | * when Visual mode is active, because it's not clear what is selected |
| 3597 | * then. */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3598 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3599 | && !(wp == curwin && VIsual_active)) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3600 | { |
| 3601 | line_attr = hl_attr(HLF_CUL); |
| 3602 | area_highlighting = TRUE; |
| 3603 | } |
| 3604 | #endif |
| 3605 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3606 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3607 | col = 0; |
| 3608 | #ifdef FEAT_RIGHTLEFT |
| 3609 | if (wp->w_p_rl) |
| 3610 | { |
| 3611 | /* Rightleft window: process the text in the normal direction, but put |
| 3612 | * it in current_ScreenLine[] from right to left. Start at the |
| 3613 | * rightmost column of the window. */ |
| 3614 | col = W_WIDTH(wp) - 1; |
| 3615 | off += col; |
| 3616 | } |
| 3617 | #endif |
| 3618 | |
| 3619 | /* |
| 3620 | * Repeat for the whole displayed line. |
| 3621 | */ |
| 3622 | for (;;) |
| 3623 | { |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3624 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3625 | has_match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3626 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3627 | /* Skip this quickly when working on the text. */ |
| 3628 | if (draw_state != WL_LINE) |
| 3629 | { |
| 3630 | #ifdef FEAT_CMDWIN |
| 3631 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3632 | { |
| 3633 | draw_state = WL_CMDLINE; |
| 3634 | if (cmdwin_type != 0 && wp == curwin) |
| 3635 | { |
| 3636 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3637 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3638 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3639 | char_attr = hl_attr(HLF_AT); |
| 3640 | } |
| 3641 | } |
| 3642 | #endif |
| 3643 | |
| 3644 | #ifdef FEAT_FOLDING |
| 3645 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3646 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3647 | int fdc = compute_foldcolumn(wp, 0); |
| 3648 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3649 | draw_state = WL_FOLD; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3650 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3651 | { |
| 3652 | /* Draw the 'foldcolumn'. */ |
| 3653 | fill_foldcolumn(extra, wp, FALSE, lnum); |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3654 | n_extra = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3655 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3656 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3657 | c_extra = NUL; |
| 3658 | char_attr = hl_attr(HLF_FC); |
| 3659 | } |
| 3660 | } |
| 3661 | #endif |
| 3662 | |
| 3663 | #ifdef FEAT_SIGNS |
| 3664 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3665 | { |
| 3666 | draw_state = WL_SIGN; |
| 3667 | /* Show the sign column when there are any signs in this |
| 3668 | * buffer or when using Netbeans. */ |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 3669 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3670 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3671 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3672 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3673 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3674 | # endif |
| 3675 | |
| 3676 | /* Draw two cells with the sign value or blank. */ |
| 3677 | c_extra = ' '; |
| 3678 | char_attr = hl_attr(HLF_SC); |
| 3679 | n_extra = 2; |
| 3680 | |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3681 | if (row == startrow |
| 3682 | #ifdef FEAT_DIFF |
| 3683 | + filler_lines && filler_todo <= 0 |
| 3684 | #endif |
| 3685 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3686 | { |
| 3687 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3688 | SIGN_TEXT); |
| 3689 | # ifdef FEAT_SIGN_ICONS |
| 3690 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3691 | SIGN_ICON); |
| 3692 | if (gui.in_use && icon_sign != 0) |
| 3693 | { |
| 3694 | /* Use the image in this position. */ |
| 3695 | c_extra = SIGN_BYTE; |
| 3696 | # ifdef FEAT_NETBEANS_INTG |
| 3697 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3698 | c_extra = MULTISIGN_BYTE; |
| 3699 | # endif |
| 3700 | char_attr = icon_sign; |
| 3701 | } |
| 3702 | else |
| 3703 | # endif |
| 3704 | if (text_sign != 0) |
| 3705 | { |
| 3706 | p_extra = sign_get_text(text_sign); |
| 3707 | if (p_extra != NULL) |
| 3708 | { |
| 3709 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3710 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3711 | } |
| 3712 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3713 | } |
| 3714 | } |
| 3715 | } |
| 3716 | } |
| 3717 | #endif |
| 3718 | |
| 3719 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3720 | { |
| 3721 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3722 | /* Display the absolute or relative line number. After the |
| 3723 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3724 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3725 | && (row == startrow |
| 3726 | #ifdef FEAT_DIFF |
| 3727 | + filler_lines |
| 3728 | #endif |
| 3729 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3730 | { |
| 3731 | /* Draw the line number (empty space after wrapping). */ |
| 3732 | if (row == startrow |
| 3733 | #ifdef FEAT_DIFF |
| 3734 | + filler_lines |
| 3735 | #endif |
| 3736 | ) |
| 3737 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3738 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3739 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3740 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3741 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3742 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3743 | num = (long)lnum; |
| 3744 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3745 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3746 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3747 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3748 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3749 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3750 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3751 | num = lnum; |
| 3752 | fmt = "%-*ld "; |
| 3753 | } |
| 3754 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3755 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3756 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3757 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3758 | if (wp->w_skipcol > 0) |
| 3759 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3760 | *p_extra = '-'; |
| 3761 | #ifdef FEAT_RIGHTLEFT |
| 3762 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3763 | rl_mirror(extra); |
| 3764 | #endif |
| 3765 | p_extra = extra; |
| 3766 | c_extra = NUL; |
| 3767 | } |
| 3768 | else |
| 3769 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3770 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3771 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3772 | #ifdef FEAT_SYN_HL |
| 3773 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3774 | * the current line differently. |
| 3775 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3776 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3777 | if ((wp->w_p_cul || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3778 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3779 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3780 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3784 | #ifdef FEAT_LINEBREAK |
| 3785 | if (wp->w_p_brisbr && draw_state == WL_BRI - 1 |
| 3786 | && n_extra == 0 && *p_sbr != NUL) |
| 3787 | /* draw indent after showbreak value */ |
| 3788 | draw_state = WL_BRI; |
| 3789 | else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) |
| 3790 | /* After the showbreak, draw the breakindent */ |
| 3791 | draw_state = WL_BRI - 1; |
| 3792 | |
| 3793 | /* draw 'breakindent': indent wrapped text accordingly */ |
| 3794 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 3795 | { |
| 3796 | draw_state = WL_BRI; |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 3797 | /* if need_showbreak is set, breakindent also applies */ |
| 3798 | if (wp->w_p_bri && n_extra == 0 |
| 3799 | && (row != startrow || need_showbreak) |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3800 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3801 | && filler_lines == 0 |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3802 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3803 | ) |
| 3804 | { |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 3805 | char_attr = 0; |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3806 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3807 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3808 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3809 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3810 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3811 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3812 | char_attr = hl_combine_attr(char_attr, |
| 3813 | hl_attr(HLF_CUL)); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3814 | # endif |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3815 | } |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3816 | # endif |
Bram Moolenaar | b8b5746 | 2014-07-03 22:54:08 +0200 | [diff] [blame] | 3817 | p_extra = NULL; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3818 | c_extra = ' '; |
| 3819 | n_extra = get_breakindent_win(wp, |
| 3820 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 3821 | /* Correct end of highlighted area for 'breakindent', |
| 3822 | * required when 'linebreak' is also set. */ |
| 3823 | if (tocol == vcol) |
| 3824 | tocol += n_extra; |
| 3825 | } |
| 3826 | } |
| 3827 | #endif |
| 3828 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3829 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3830 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3831 | { |
| 3832 | draw_state = WL_SBR; |
| 3833 | # ifdef FEAT_DIFF |
| 3834 | if (filler_todo > 0) |
| 3835 | { |
| 3836 | /* Draw "deleted" diff line(s). */ |
| 3837 | if (char2cells(fill_diff) > 1) |
| 3838 | c_extra = '-'; |
| 3839 | else |
| 3840 | c_extra = fill_diff; |
| 3841 | # ifdef FEAT_RIGHTLEFT |
| 3842 | if (wp->w_p_rl) |
| 3843 | n_extra = col + 1; |
| 3844 | else |
| 3845 | # endif |
| 3846 | n_extra = W_WIDTH(wp) - col; |
| 3847 | char_attr = hl_attr(HLF_DED); |
| 3848 | } |
| 3849 | # endif |
| 3850 | # ifdef FEAT_LINEBREAK |
| 3851 | if (*p_sbr != NUL && need_showbreak) |
| 3852 | { |
| 3853 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3854 | p_extra = p_sbr; |
| 3855 | c_extra = NUL; |
| 3856 | n_extra = (int)STRLEN(p_sbr); |
| 3857 | char_attr = hl_attr(HLF_AT); |
| 3858 | need_showbreak = FALSE; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 3859 | vcol_sbr = vcol + MB_CHARLEN(p_sbr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3860 | /* Correct end of highlighted area for 'showbreak', |
| 3861 | * required when 'linebreak' is also set. */ |
| 3862 | if (tocol == vcol) |
| 3863 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3864 | #ifdef FEAT_SYN_HL |
| 3865 | /* combine 'showbreak' with 'cursorline' */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3866 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3867 | char_attr = hl_combine_attr(char_attr, |
| 3868 | hl_attr(HLF_CUL)); |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3869 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3870 | } |
| 3871 | # endif |
| 3872 | } |
| 3873 | #endif |
| 3874 | |
| 3875 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3876 | { |
| 3877 | draw_state = WL_LINE; |
| 3878 | if (saved_n_extra) |
| 3879 | { |
| 3880 | /* Continue item from end of wrapped line. */ |
| 3881 | n_extra = saved_n_extra; |
| 3882 | c_extra = saved_c_extra; |
| 3883 | p_extra = saved_p_extra; |
| 3884 | char_attr = saved_char_attr; |
| 3885 | } |
| 3886 | else |
| 3887 | char_attr = 0; |
| 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3892 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3893 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3894 | #ifdef FEAT_DIFF |
| 3895 | && filler_todo <= 0 |
| 3896 | #endif |
| 3897 | ) |
| 3898 | { |
| 3899 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3900 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3901 | /* Pretend we have finished updating the window. Except when |
| 3902 | * 'cursorcolumn' is set. */ |
| 3903 | #ifdef FEAT_SYN_HL |
| 3904 | if (wp->w_p_cuc) |
| 3905 | row = wp->w_cline_row + wp->w_cline_height; |
| 3906 | else |
| 3907 | #endif |
| 3908 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3909 | break; |
| 3910 | } |
| 3911 | |
| 3912 | if (draw_state == WL_LINE && area_highlighting) |
| 3913 | { |
| 3914 | /* handle Visual or match highlighting in this line */ |
| 3915 | if (vcol == fromcol |
| 3916 | #ifdef FEAT_MBYTE |
| 3917 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3918 | && (*mb_ptr2cells)(ptr) > 1) |
| 3919 | #endif |
| 3920 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3921 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3922 | && vcol < tocol)) |
| 3923 | area_attr = attr; /* start highlighting */ |
| 3924 | else if (area_attr != 0 |
| 3925 | && (vcol == tocol |
| 3926 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3927 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3928 | |
| 3929 | #ifdef FEAT_SEARCH_EXTRA |
| 3930 | if (!n_extra) |
| 3931 | { |
| 3932 | /* |
| 3933 | * Check for start/end of search pattern match. |
| 3934 | * After end, check for start/end of next match. |
| 3935 | * When another match, have to check for start again. |
| 3936 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3937 | * Do this for 'search_hl' and the match list (ordered by |
| 3938 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3939 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3940 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3941 | cur = wp->w_match_head; |
| 3942 | shl_flag = FALSE; |
| 3943 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3944 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3945 | if (shl_flag == FALSE |
| 3946 | && ((cur != NULL |
| 3947 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3948 | || cur == NULL)) |
| 3949 | { |
| 3950 | shl = &search_hl; |
| 3951 | shl_flag = TRUE; |
| 3952 | } |
| 3953 | else |
| 3954 | shl = &cur->hl; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3955 | if (cur != NULL) |
| 3956 | cur->pos.cur = 0; |
| 3957 | pos_inprogress = TRUE; |
| 3958 | while (shl->rm.regprog != NULL |
| 3959 | || (cur != NULL && pos_inprogress)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3960 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3961 | if (shl->startcol != MAXCOL |
| 3962 | && v >= (long)shl->startcol |
| 3963 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3964 | { |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3965 | #ifdef FEAT_MBYTE |
| 3966 | int tmp_col = v + MB_PTR2LEN(ptr); |
| 3967 | |
| 3968 | if (shl->endcol < tmp_col) |
| 3969 | shl->endcol = tmp_col; |
| 3970 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3971 | shl->attr_cur = shl->attr; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3972 | #ifdef FEAT_CONCEAL |
| 3973 | if (cur != NULL && syn_name2id((char_u *)"Conceal") |
| 3974 | == cur->hlg_id) |
| 3975 | { |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3976 | has_match_conc = |
| 3977 | v == (long)shl->startcol ? 2 : 1; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3978 | match_conc = cur->conceal_char; |
| 3979 | } |
| 3980 | else |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3981 | has_match_conc = match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3982 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3983 | } |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3984 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3985 | { |
| 3986 | shl->attr_cur = 0; |
Bram Moolenaar | e17bdff | 2016-08-27 18:34:29 +0200 | [diff] [blame] | 3987 | next_search_hl(wp, shl, lnum, (colnr_T)v, |
| 3988 | shl == &search_hl ? NULL : cur); |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3989 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3990 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3991 | |
| 3992 | /* Need to get the line again, a multi-line regexp |
| 3993 | * may have made it invalid. */ |
| 3994 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3995 | ptr = line + v; |
| 3996 | |
| 3997 | if (shl->lnum == lnum) |
| 3998 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3999 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4000 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4001 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4002 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4003 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4004 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4005 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4006 | { |
| 4007 | /* highlight empty match, try again after |
| 4008 | * it */ |
| 4009 | #ifdef FEAT_MBYTE |
| 4010 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4011 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4012 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4013 | else |
| 4014 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4015 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | /* Loop to check if the match starts at the |
| 4019 | * current position */ |
| 4020 | continue; |
| 4021 | } |
| 4022 | } |
| 4023 | break; |
| 4024 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4025 | if (shl != &search_hl && cur != NULL) |
| 4026 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4027 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4028 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4029 | /* Use attributes from match with highest priority among |
| 4030 | * 'search_hl' and the match list. */ |
| 4031 | search_attr = search_hl.attr_cur; |
| 4032 | cur = wp->w_match_head; |
| 4033 | shl_flag = FALSE; |
| 4034 | while (cur != NULL || shl_flag == FALSE) |
| 4035 | { |
| 4036 | if (shl_flag == FALSE |
| 4037 | && ((cur != NULL |
| 4038 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4039 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4040 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4041 | shl = &search_hl; |
| 4042 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4043 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4044 | else |
| 4045 | shl = &cur->hl; |
| 4046 | if (shl->attr_cur != 0) |
| 4047 | search_attr = shl->attr_cur; |
| 4048 | if (shl != &search_hl && cur != NULL) |
| 4049 | cur = cur->next; |
| 4050 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4051 | } |
| 4052 | #endif |
| 4053 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4054 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4055 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4056 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4057 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 4058 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4059 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4060 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 4061 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4062 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4063 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4064 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4065 | line_attr = hl_combine_attr(line_attr, hl_attr(HLF_CUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4066 | } |
| 4067 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4068 | |
| 4069 | /* Decide which of the highlight attributes to use. */ |
| 4070 | attr_pri = TRUE; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4071 | #ifdef LINE_ATTR |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4072 | if (area_attr != 0) |
| 4073 | char_attr = hl_combine_attr(line_attr, area_attr); |
| 4074 | else if (search_attr != 0) |
| 4075 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4076 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 4077 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 4078 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 4079 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 4080 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4081 | char_attr = line_attr; |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4082 | #else |
| 4083 | if (area_attr != 0) |
| 4084 | char_attr = area_attr; |
| 4085 | else if (search_attr != 0) |
| 4086 | char_attr = search_attr; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4087 | #endif |
| 4088 | else |
| 4089 | { |
| 4090 | attr_pri = FALSE; |
| 4091 | #ifdef FEAT_SYN_HL |
| 4092 | if (has_syntax) |
| 4093 | char_attr = syntax_attr; |
| 4094 | else |
| 4095 | #endif |
| 4096 | char_attr = 0; |
| 4097 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /* |
| 4101 | * Get the next character to put on the screen. |
| 4102 | */ |
| 4103 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 4104 | * The "p_extra" points to the extra stuff that is inserted to |
| 4105 | * represent special characters (non-printable stuff) and other |
| 4106 | * things. When all characters are the same, c_extra is used. |
| 4107 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 4108 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4109 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 4110 | */ |
| 4111 | if (n_extra > 0) |
| 4112 | { |
| 4113 | if (c_extra != NUL) |
| 4114 | { |
| 4115 | c = c_extra; |
| 4116 | #ifdef FEAT_MBYTE |
| 4117 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 4118 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4119 | { |
| 4120 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4121 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4122 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4123 | } |
| 4124 | else |
| 4125 | mb_utf8 = FALSE; |
| 4126 | #endif |
| 4127 | } |
| 4128 | else |
| 4129 | { |
| 4130 | c = *p_extra; |
| 4131 | #ifdef FEAT_MBYTE |
| 4132 | if (has_mbyte) |
| 4133 | { |
| 4134 | mb_c = c; |
| 4135 | if (enc_utf8) |
| 4136 | { |
| 4137 | /* If the UTF-8 character is more than one byte: |
| 4138 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4139 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4140 | mb_utf8 = FALSE; |
| 4141 | if (mb_l > n_extra) |
| 4142 | mb_l = 1; |
| 4143 | else if (mb_l > 1) |
| 4144 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4145 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4146 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4147 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4148 | } |
| 4149 | } |
| 4150 | else |
| 4151 | { |
| 4152 | /* if this is a DBCS character, put it in "mb_c" */ |
| 4153 | mb_l = MB_BYTE2LEN(c); |
| 4154 | if (mb_l >= n_extra) |
| 4155 | mb_l = 1; |
| 4156 | else if (mb_l > 1) |
| 4157 | mb_c = (c << 8) + p_extra[1]; |
| 4158 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4159 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4160 | mb_l = 1; |
| 4161 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4162 | /* If a double-width char doesn't fit display a '>' in the |
| 4163 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4164 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4165 | # ifdef FEAT_RIGHTLEFT |
| 4166 | wp->w_p_rl ? (col <= 0) : |
| 4167 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4168 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4169 | && (*mb_char2cells)(mb_c) == 2) |
| 4170 | { |
| 4171 | c = '>'; |
| 4172 | mb_c = c; |
| 4173 | mb_l = 1; |
| 4174 | mb_utf8 = FALSE; |
| 4175 | multi_attr = hl_attr(HLF_AT); |
| 4176 | /* put the pointer back to output the double-width |
| 4177 | * character at the start of the next line. */ |
| 4178 | ++n_extra; |
| 4179 | --p_extra; |
| 4180 | } |
| 4181 | else |
| 4182 | { |
| 4183 | n_extra -= mb_l - 1; |
| 4184 | p_extra += mb_l - 1; |
| 4185 | } |
| 4186 | } |
| 4187 | #endif |
| 4188 | ++p_extra; |
| 4189 | } |
| 4190 | --n_extra; |
| 4191 | } |
| 4192 | else |
| 4193 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4194 | if (p_extra_free != NULL) |
| 4195 | { |
| 4196 | vim_free(p_extra_free); |
| 4197 | p_extra_free = NULL; |
| 4198 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4199 | /* |
| 4200 | * Get a character from the line itself. |
| 4201 | */ |
| 4202 | c = *ptr; |
| 4203 | #ifdef FEAT_MBYTE |
| 4204 | if (has_mbyte) |
| 4205 | { |
| 4206 | mb_c = c; |
| 4207 | if (enc_utf8) |
| 4208 | { |
| 4209 | /* If the UTF-8 character is more than one byte: Decode it |
| 4210 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4211 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4212 | mb_utf8 = FALSE; |
| 4213 | if (mb_l > 1) |
| 4214 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4215 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4216 | /* Overlong encoded ASCII or ASCII with composing char |
| 4217 | * is displayed normally, except a NUL. */ |
| 4218 | if (mb_c < 0x80) |
| 4219 | c = mb_c; |
| 4220 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4221 | |
| 4222 | /* At start of the line we can have a composing char. |
| 4223 | * Draw it as a space with a composing char. */ |
| 4224 | if (utf_iscomposing(mb_c)) |
| 4225 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4226 | int i; |
| 4227 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4228 | for (i = Screen_mco - 1; i > 0; --i) |
| 4229 | u8cc[i] = u8cc[i - 1]; |
| 4230 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4231 | mb_c = ' '; |
| 4232 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | if ((mb_l == 1 && c >= 0x80) |
| 4236 | || (mb_l >= 1 && mb_c == 0) |
| 4237 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4238 | # ifdef UNICODE16 |
| 4239 | || mb_c >= 0x10000 |
| 4240 | # endif |
| 4241 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4242 | { |
| 4243 | /* |
| 4244 | * Illegal UTF-8 byte: display as <xx>. |
| 4245 | * Non-BMP character : display as ? or fullwidth ?. |
| 4246 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4247 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4248 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4249 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4250 | { |
| 4251 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4252 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4253 | if (wp->w_p_rl) /* reverse */ |
| 4254 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4255 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4256 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4257 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4258 | else if (utf_char2cells(mb_c) != 2) |
| 4259 | STRCPY(extra, "?"); |
| 4260 | else |
| 4261 | /* 0xff1f in UTF-8: full-width '?' */ |
| 4262 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4263 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4264 | |
| 4265 | p_extra = extra; |
| 4266 | c = *p_extra; |
| 4267 | mb_c = mb_ptr2char_adv(&p_extra); |
| 4268 | mb_utf8 = (c >= 0x80); |
| 4269 | n_extra = (int)STRLEN(p_extra); |
| 4270 | c_extra = NUL; |
| 4271 | if (area_attr == 0 && search_attr == 0) |
| 4272 | { |
| 4273 | n_attr = n_extra + 1; |
| 4274 | extra_attr = hl_attr(HLF_8); |
| 4275 | saved_attr2 = char_attr; /* save current attr */ |
| 4276 | } |
| 4277 | } |
| 4278 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4279 | mb_l = 1; |
| 4280 | #ifdef FEAT_ARABIC |
| 4281 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 4282 | { |
| 4283 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4284 | int pc, pc1, nc; |
| 4285 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4286 | |
| 4287 | /* The idea of what is the previous and next |
| 4288 | * character depends on 'rightleft'. */ |
| 4289 | if (wp->w_p_rl) |
| 4290 | { |
| 4291 | pc = prev_c; |
| 4292 | pc1 = prev_c1; |
| 4293 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4294 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4295 | } |
| 4296 | else |
| 4297 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4298 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4299 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4300 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4301 | } |
| 4302 | prev_c = mb_c; |
| 4303 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4304 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4305 | } |
| 4306 | else |
| 4307 | prev_c = mb_c; |
| 4308 | #endif |
| 4309 | } |
| 4310 | else /* enc_dbcs */ |
| 4311 | { |
| 4312 | mb_l = MB_BYTE2LEN(c); |
| 4313 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4314 | mb_l = 1; |
| 4315 | else if (mb_l > 1) |
| 4316 | { |
| 4317 | /* We assume a second byte below 32 is illegal. |
| 4318 | * Hopefully this is OK for all double-byte encodings! |
| 4319 | */ |
| 4320 | if (ptr[1] >= 32) |
| 4321 | mb_c = (c << 8) + ptr[1]; |
| 4322 | else |
| 4323 | { |
| 4324 | if (ptr[1] == NUL) |
| 4325 | { |
| 4326 | /* head byte at end of line */ |
| 4327 | mb_l = 1; |
| 4328 | transchar_nonprint(extra, c); |
| 4329 | } |
| 4330 | else |
| 4331 | { |
| 4332 | /* illegal tail byte */ |
| 4333 | mb_l = 2; |
| 4334 | STRCPY(extra, "XX"); |
| 4335 | } |
| 4336 | p_extra = extra; |
| 4337 | n_extra = (int)STRLEN(extra) - 1; |
| 4338 | c_extra = NUL; |
| 4339 | c = *p_extra++; |
| 4340 | if (area_attr == 0 && search_attr == 0) |
| 4341 | { |
| 4342 | n_attr = n_extra + 1; |
| 4343 | extra_attr = hl_attr(HLF_8); |
| 4344 | saved_attr2 = char_attr; /* save current attr */ |
| 4345 | } |
| 4346 | mb_c = c; |
| 4347 | } |
| 4348 | } |
| 4349 | } |
| 4350 | /* If a double-width char doesn't fit display a '>' in the |
| 4351 | * last column; the character is displayed at the start of the |
| 4352 | * next line. */ |
| 4353 | if (( |
| 4354 | # ifdef FEAT_RIGHTLEFT |
| 4355 | wp->w_p_rl ? (col <= 0) : |
| 4356 | # endif |
| 4357 | (col >= W_WIDTH(wp) - 1)) |
| 4358 | && (*mb_char2cells)(mb_c) == 2) |
| 4359 | { |
| 4360 | c = '>'; |
| 4361 | mb_c = c; |
| 4362 | mb_utf8 = FALSE; |
| 4363 | mb_l = 1; |
| 4364 | multi_attr = hl_attr(HLF_AT); |
| 4365 | /* Put pointer back so that the character will be |
| 4366 | * displayed at the start of the next line. */ |
| 4367 | --ptr; |
| 4368 | } |
| 4369 | else if (*ptr != NUL) |
| 4370 | ptr += mb_l - 1; |
| 4371 | |
| 4372 | /* 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] | 4373 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4374 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4375 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4376 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4377 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4378 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4379 | c = ' '; |
| 4380 | if (area_attr == 0 && search_attr == 0) |
| 4381 | { |
| 4382 | n_attr = n_extra + 1; |
| 4383 | extra_attr = hl_attr(HLF_AT); |
| 4384 | saved_attr2 = char_attr; /* save current attr */ |
| 4385 | } |
| 4386 | mb_c = c; |
| 4387 | mb_utf8 = FALSE; |
| 4388 | mb_l = 1; |
| 4389 | } |
| 4390 | |
| 4391 | } |
| 4392 | #endif |
| 4393 | ++ptr; |
| 4394 | |
| 4395 | if (extra_check) |
| 4396 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4397 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4398 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4399 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4400 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4401 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4402 | /* Get syntax attribute, unless still at the start of the line |
| 4403 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4404 | v = (long)(ptr - line); |
| 4405 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4406 | { |
| 4407 | /* Get the syntax attribute for the character. If there |
| 4408 | * is an error, disable syntax highlighting. */ |
| 4409 | save_did_emsg = did_emsg; |
| 4410 | did_emsg = FALSE; |
| 4411 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4412 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4413 | # ifdef FEAT_SPELL |
| 4414 | has_spell ? &can_spell : |
| 4415 | # endif |
| 4416 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4417 | |
| 4418 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4419 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4420 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4421 | has_syntax = FALSE; |
| 4422 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4423 | else |
| 4424 | did_emsg = save_did_emsg; |
| 4425 | |
| 4426 | /* Need to get the line again, a multi-line regexp may |
| 4427 | * have made it invalid. */ |
| 4428 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4429 | ptr = line + v; |
| 4430 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4431 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4432 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4433 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4434 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4435 | # ifdef FEAT_CONCEAL |
| 4436 | /* no concealing past the end of the line, it interferes |
| 4437 | * with line highlighting */ |
| 4438 | if (c == NUL) |
| 4439 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4440 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4441 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4442 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4443 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4444 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4445 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4446 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4447 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4448 | * Only do this when there is no syntax highlighting, the |
| 4449 | * @Spell cluster is not used or the current syntax item |
| 4450 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4451 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4452 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4453 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4454 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4455 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4456 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4457 | # endif |
| 4458 | if (c != 0 && ( |
| 4459 | # ifdef FEAT_SYN_HL |
| 4460 | !has_syntax || |
| 4461 | # endif |
| 4462 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4463 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4464 | char_u *prev_ptr, *p; |
| 4465 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4466 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4467 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4468 | if (has_mbyte) |
| 4469 | { |
| 4470 | prev_ptr = ptr - mb_l; |
| 4471 | v -= mb_l - 1; |
| 4472 | } |
| 4473 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4474 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4475 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4476 | |
| 4477 | /* Use nextline[] if possible, it has the start of the |
| 4478 | * next line concatenated. */ |
| 4479 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4480 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4481 | else |
| 4482 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4483 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4484 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4485 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4486 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4487 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4488 | /* In Insert mode only highlight a word that |
| 4489 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4490 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4491 | && (State & INSERT) != 0 |
| 4492 | && wp->w_cursor.lnum == lnum |
| 4493 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4494 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4495 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4496 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4497 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4498 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4499 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4500 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4501 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4502 | && (p - nextline) + len > nextline_idx) |
| 4503 | { |
| 4504 | /* Remember that the good word continues at the |
| 4505 | * start of the next line. */ |
| 4506 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4507 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4508 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4509 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4510 | /* Turn index into actual attributes. */ |
| 4511 | if (spell_hlf != HLF_COUNT) |
| 4512 | spell_attr = highlight_attr[spell_hlf]; |
| 4513 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4514 | if (cap_col > 0) |
| 4515 | { |
| 4516 | if (p != prev_ptr |
| 4517 | && (p - nextline) + cap_col >= nextline_idx) |
| 4518 | { |
| 4519 | /* Remember that the word in the next line |
| 4520 | * must start with a capital. */ |
| 4521 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4522 | cap_col = (int)((p - nextline) + cap_col |
| 4523 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4524 | } |
| 4525 | else |
| 4526 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4527 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4528 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4529 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4530 | } |
| 4531 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4532 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4533 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4534 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4535 | else |
| 4536 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4537 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4538 | #endif |
| 4539 | #ifdef FEAT_LINEBREAK |
| 4540 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4541 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4542 | */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4543 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4544 | { |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4545 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4546 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4547 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4548 | char_u *p = ptr - ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4549 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4550 | mb_off + |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4551 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4552 | 1); |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4553 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4554 | /* TODO: is passing p for start of the line OK? */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4555 | n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4556 | NULL) - 1; |
Bram Moolenaar | a365091 | 2014-11-19 13:21:57 +0100 | [diff] [blame] | 4557 | if (c == TAB && n_extra + col > W_WIDTH(wp)) |
| 4558 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4559 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4560 | |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4561 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4562 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4563 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4564 | c_extra = ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4565 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4566 | if (vim_iswhite(c)) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4567 | { |
| 4568 | #ifdef FEAT_CONCEAL |
| 4569 | if (c == TAB) |
| 4570 | /* See "Tab alignment" below. */ |
| 4571 | FIX_FOR_BOGUSCOLS; |
| 4572 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4573 | if (!wp->w_p_list) |
| 4574 | c = ' '; |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4575 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4576 | } |
| 4577 | #endif |
| 4578 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 4579 | /* 'list': change char 160 to lcs_nbsp and space to lcs_space. |
| 4580 | */ |
| 4581 | if (wp->w_p_list |
| 4582 | && (((c == 160 |
| 4583 | #ifdef FEAT_MBYTE |
| 4584 | || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)) |
| 4585 | #endif |
| 4586 | ) && lcs_nbsp) |
| 4587 | || (c == ' ' && lcs_space && ptr - line <= trailcol))) |
| 4588 | { |
| 4589 | c = (c == ' ') ? lcs_space : lcs_nbsp; |
| 4590 | if (area_attr == 0 && search_attr == 0) |
| 4591 | { |
| 4592 | n_attr = 1; |
| 4593 | extra_attr = hl_attr(HLF_8); |
| 4594 | saved_attr2 = char_attr; /* save current attr */ |
| 4595 | } |
| 4596 | #ifdef FEAT_MBYTE |
| 4597 | mb_c = c; |
| 4598 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4599 | { |
| 4600 | mb_utf8 = TRUE; |
| 4601 | u8cc[0] = 0; |
| 4602 | c = 0xc0; |
| 4603 | } |
| 4604 | else |
| 4605 | mb_utf8 = FALSE; |
| 4606 | #endif |
| 4607 | } |
| 4608 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4609 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4610 | { |
| 4611 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4612 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4613 | { |
| 4614 | n_attr = 1; |
| 4615 | extra_attr = hl_attr(HLF_8); |
| 4616 | saved_attr2 = char_attr; /* save current attr */ |
| 4617 | } |
| 4618 | #ifdef FEAT_MBYTE |
| 4619 | mb_c = c; |
| 4620 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4621 | { |
| 4622 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4623 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4624 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4625 | } |
| 4626 | else |
| 4627 | mb_utf8 = FALSE; |
| 4628 | #endif |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | /* |
| 4633 | * Handling of non-printable characters. |
| 4634 | */ |
Bram Moolenaar | 88e8f9f | 2016-01-20 22:48:02 +0100 | [diff] [blame] | 4635 | if (!vim_isprintc(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4636 | { |
| 4637 | /* |
| 4638 | * when getting a character from the file, we may have to |
| 4639 | * turn it into something else on the way to putting it |
| 4640 | * into "ScreenLines". |
| 4641 | */ |
| 4642 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4643 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4644 | int tab_len = 0; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4645 | long vcol_adjusted = vcol; /* removed showbreak length */ |
| 4646 | #ifdef FEAT_LINEBREAK |
| 4647 | /* only adjust the tab_len, when at the first column |
| 4648 | * after the showbreak value was drawn */ |
| 4649 | if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 4650 | vcol_adjusted = vcol - MB_CHARLEN(p_sbr); |
| 4651 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4652 | /* tab amount depends on current column */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4653 | tab_len = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4654 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 4655 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4656 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81c85d | 2014-07-30 16:44:22 +0200 | [diff] [blame] | 4657 | if (!wp->w_p_lbr || !wp->w_p_list) |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4658 | #endif |
| 4659 | /* tab amount depends on current column */ |
| 4660 | n_extra = tab_len; |
| 4661 | #ifdef FEAT_LINEBREAK |
| 4662 | else |
| 4663 | { |
| 4664 | char_u *p; |
| 4665 | int len = n_extra; |
| 4666 | int i; |
| 4667 | int saved_nextra = n_extra; |
| 4668 | |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4669 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4670 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4671 | /* there are characters to conceal */ |
| 4672 | tab_len += vcol_off; |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4673 | /* boguscols before FIX_FOR_BOGUSCOLS macro from above |
| 4674 | */ |
| 4675 | if (wp->w_p_list && lcs_tab1 && old_boguscols > 0 |
| 4676 | && n_extra > tab_len) |
| 4677 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4678 | #endif |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4679 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4680 | /* if n_extra > 0, it gives the number of chars, to |
| 4681 | * use for a tab, else we need to calculate the width |
| 4682 | * for a tab */ |
| 4683 | #ifdef FEAT_MBYTE |
| 4684 | len = (tab_len * mb_char2len(lcs_tab2)); |
| 4685 | if (n_extra > 0) |
| 4686 | len += n_extra - tab_len; |
| 4687 | #endif |
| 4688 | c = lcs_tab1; |
| 4689 | p = alloc((unsigned)(len + 1)); |
| 4690 | vim_memset(p, ' ', len); |
| 4691 | p[len] = NUL; |
| 4692 | p_extra_free = p; |
| 4693 | for (i = 0; i < tab_len; i++) |
| 4694 | { |
| 4695 | #ifdef FEAT_MBYTE |
| 4696 | mb_char2bytes(lcs_tab2, p); |
| 4697 | p += mb_char2len(lcs_tab2); |
| 4698 | n_extra += mb_char2len(lcs_tab2) |
| 4699 | - (saved_nextra > 0 ? 1 : 0); |
| 4700 | #else |
| 4701 | p[i] = lcs_tab2; |
| 4702 | #endif |
| 4703 | } |
| 4704 | p_extra = p_extra_free; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4705 | #ifdef FEAT_CONCEAL |
| 4706 | /* n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 4707 | * macro below, so need to adjust for that here */ |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4708 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4709 | n_extra -= vcol_off; |
| 4710 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4711 | } |
| 4712 | #endif |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4713 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4714 | { |
| 4715 | int vc_saved = vcol_off; |
| 4716 | |
| 4717 | /* Tab alignment should be identical regardless of |
| 4718 | * 'conceallevel' value. So tab compensates of all |
| 4719 | * previous concealed characters, and thus resets |
| 4720 | * vcol_off and boguscols accumulated so far in the |
| 4721 | * line. Note that the tab can be longer than |
| 4722 | * 'tabstop' when there are concealed characters. */ |
| 4723 | FIX_FOR_BOGUSCOLS; |
| 4724 | |
| 4725 | /* Make sure, the highlighting for the tab char will be |
| 4726 | * correctly set further below (effectively reverts the |
| 4727 | * FIX_FOR_BOGSUCOLS macro */ |
| 4728 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4729 | && lcs_tab1) |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4730 | tab_len += vc_saved; |
| 4731 | } |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4732 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4733 | #ifdef FEAT_MBYTE |
| 4734 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4735 | #endif |
| 4736 | if (wp->w_p_list) |
| 4737 | { |
| 4738 | c = lcs_tab1; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4739 | #ifdef FEAT_LINEBREAK |
| 4740 | if (wp->w_p_lbr) |
| 4741 | c_extra = NUL; /* using p_extra from above */ |
| 4742 | else |
| 4743 | #endif |
| 4744 | c_extra = lcs_tab2; |
| 4745 | n_attr = tab_len + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4746 | extra_attr = hl_attr(HLF_8); |
| 4747 | saved_attr2 = char_attr; /* save current attr */ |
| 4748 | #ifdef FEAT_MBYTE |
| 4749 | mb_c = c; |
| 4750 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4751 | { |
| 4752 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4753 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4754 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4755 | } |
| 4756 | #endif |
| 4757 | } |
| 4758 | else |
| 4759 | { |
| 4760 | c_extra = ' '; |
| 4761 | c = ' '; |
| 4762 | } |
| 4763 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4764 | else if (c == NUL |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4765 | && (wp->w_p_list |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4766 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4767 | && tocol > vcol |
| 4768 | && VIsual_mode != Ctrl_V |
| 4769 | && ( |
| 4770 | # ifdef FEAT_RIGHTLEFT |
| 4771 | wp->w_p_rl ? (col >= 0) : |
| 4772 | # endif |
| 4773 | (col < W_WIDTH(wp))) |
| 4774 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4775 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4776 | && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 0481fee | 2015-05-14 05:56:09 +0200 | [diff] [blame] | 4777 | && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4778 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4779 | /* Display a '$' after the line or highlight an extra |
| 4780 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4781 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4782 | /* For a diff line the highlighting continues after the |
| 4783 | * "$". */ |
| 4784 | if ( |
| 4785 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4786 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4787 | # ifdef LINE_ATTR |
| 4788 | && |
| 4789 | # endif |
| 4790 | # endif |
| 4791 | # ifdef LINE_ATTR |
| 4792 | line_attr == 0 |
| 4793 | # endif |
| 4794 | ) |
| 4795 | #endif |
| 4796 | { |
| 4797 | #ifdef FEAT_VIRTUALEDIT |
| 4798 | /* In virtualedit, visual selections may extend |
| 4799 | * beyond end of line. */ |
| 4800 | if (area_highlighting && virtual_active() |
| 4801 | && tocol != MAXCOL && vcol < tocol) |
| 4802 | n_extra = 0; |
| 4803 | else |
| 4804 | #endif |
| 4805 | { |
| 4806 | p_extra = at_end_str; |
| 4807 | n_extra = 1; |
| 4808 | c_extra = NUL; |
| 4809 | } |
| 4810 | } |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4811 | if (wp->w_p_list && lcs_eol > 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4812 | c = lcs_eol; |
| 4813 | else |
| 4814 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4815 | lcs_eol_one = -1; |
| 4816 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4817 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4818 | { |
| 4819 | extra_attr = hl_attr(HLF_AT); |
| 4820 | n_attr = 1; |
| 4821 | } |
| 4822 | #ifdef FEAT_MBYTE |
| 4823 | mb_c = c; |
| 4824 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4825 | { |
| 4826 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4827 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4828 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4829 | } |
| 4830 | else |
| 4831 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4832 | #endif |
| 4833 | } |
| 4834 | else if (c != NUL) |
| 4835 | { |
| 4836 | p_extra = transchar(c); |
Bram Moolenaar | 5524aeb | 2014-07-16 17:29:51 +0200 | [diff] [blame] | 4837 | if (n_extra == 0) |
| 4838 | n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4839 | #ifdef FEAT_RIGHTLEFT |
| 4840 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4841 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4842 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4843 | c_extra = NUL; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4844 | #ifdef FEAT_LINEBREAK |
| 4845 | if (wp->w_p_lbr) |
| 4846 | { |
| 4847 | char_u *p; |
| 4848 | |
| 4849 | c = *p_extra; |
| 4850 | p = alloc((unsigned)n_extra + 1); |
| 4851 | vim_memset(p, ' ', n_extra); |
| 4852 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 4853 | p[n_extra] = NUL; |
| 4854 | p_extra_free = p_extra = p; |
| 4855 | } |
| 4856 | else |
| 4857 | #endif |
| 4858 | { |
| 4859 | n_extra = byte2cells(c) - 1; |
| 4860 | c = *p_extra++; |
| 4861 | } |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4862 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4863 | { |
| 4864 | n_attr = n_extra + 1; |
| 4865 | extra_attr = hl_attr(HLF_8); |
| 4866 | saved_attr2 = char_attr; /* save current attr */ |
| 4867 | } |
| 4868 | #ifdef FEAT_MBYTE |
| 4869 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4870 | #endif |
| 4871 | } |
| 4872 | #ifdef FEAT_VIRTUALEDIT |
| 4873 | else if (VIsual_active |
| 4874 | && (VIsual_mode == Ctrl_V |
| 4875 | || VIsual_mode == 'v') |
| 4876 | && virtual_active() |
| 4877 | && tocol != MAXCOL |
| 4878 | && vcol < tocol |
| 4879 | && ( |
| 4880 | # ifdef FEAT_RIGHTLEFT |
| 4881 | wp->w_p_rl ? (col >= 0) : |
| 4882 | # endif |
| 4883 | (col < W_WIDTH(wp)))) |
| 4884 | { |
| 4885 | c = ' '; |
| 4886 | --ptr; /* put it back at the NUL */ |
| 4887 | } |
| 4888 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4889 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4890 | else if (( |
| 4891 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4892 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4893 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4894 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4895 | ) && ( |
| 4896 | # ifdef FEAT_RIGHTLEFT |
| 4897 | wp->w_p_rl ? (col >= 0) : |
| 4898 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4899 | (col |
| 4900 | # ifdef FEAT_CONCEAL |
| 4901 | - boguscols |
| 4902 | # endif |
| 4903 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4904 | { |
| 4905 | /* Highlight until the right side of the window */ |
| 4906 | c = ' '; |
| 4907 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4908 | |
| 4909 | /* Remember we do the char for line highlighting. */ |
| 4910 | ++did_line_attr; |
| 4911 | |
| 4912 | /* don't do search HL for the rest of the line */ |
| 4913 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4914 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4915 | # ifdef FEAT_DIFF |
| 4916 | if (diff_hlf == HLF_TXD) |
| 4917 | { |
| 4918 | diff_hlf = HLF_CHD; |
| 4919 | if (attr == 0 || char_attr != attr) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4920 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4921 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4922 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4923 | char_attr = hl_combine_attr(char_attr, |
| 4924 | hl_attr(HLF_CUL)); |
| 4925 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4926 | } |
| 4927 | # endif |
| 4928 | } |
| 4929 | #endif |
| 4930 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4931 | |
| 4932 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4933 | if ( wp->w_p_cole > 0 |
| 4934 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4935 | conceal_cursor_line(wp) ) |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4936 | && ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4937 | && !(lnum_in_visual_area |
| 4938 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4939 | { |
| 4940 | char_attr = conceal_attr; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4941 | if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1) |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4942 | && (syn_get_sub_char() != NUL || match_conc |
| 4943 | || wp->w_p_cole == 1) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4944 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4945 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4946 | /* First time at this concealed item: display one |
| 4947 | * character. */ |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4948 | if (match_conc) |
| 4949 | c = match_conc; |
| 4950 | else if (syn_get_sub_char() != NUL) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4951 | c = syn_get_sub_char(); |
| 4952 | else if (lcs_conceal != NUL) |
| 4953 | c = lcs_conceal; |
| 4954 | else |
| 4955 | c = ' '; |
| 4956 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4957 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4958 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4959 | if (n_extra > 0) |
| 4960 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4961 | vcol += n_extra; |
| 4962 | if (wp->w_p_wrap && n_extra > 0) |
| 4963 | { |
| 4964 | # ifdef FEAT_RIGHTLEFT |
| 4965 | if (wp->w_p_rl) |
| 4966 | { |
| 4967 | col -= n_extra; |
| 4968 | boguscols -= n_extra; |
| 4969 | } |
| 4970 | else |
| 4971 | # endif |
| 4972 | { |
| 4973 | boguscols += n_extra; |
| 4974 | col += n_extra; |
| 4975 | } |
| 4976 | } |
| 4977 | n_extra = 0; |
| 4978 | n_attr = 0; |
| 4979 | } |
| 4980 | else if (n_skip == 0) |
| 4981 | { |
| 4982 | is_concealing = TRUE; |
| 4983 | n_skip = 1; |
| 4984 | } |
| 4985 | # ifdef FEAT_MBYTE |
| 4986 | mb_c = c; |
| 4987 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4988 | { |
| 4989 | mb_utf8 = TRUE; |
| 4990 | u8cc[0] = 0; |
| 4991 | c = 0xc0; |
| 4992 | } |
| 4993 | else |
| 4994 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4995 | # endif |
| 4996 | } |
| 4997 | else |
| 4998 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4999 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 5000 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5001 | } |
| 5002 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5005 | #ifdef FEAT_CONCEAL |
| 5006 | /* In the cursor line and we may be concealing characters: correct |
| 5007 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 5008 | if (!did_wcol && draw_state == WL_LINE |
| 5009 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5010 | && conceal_cursor_line(wp) |
| 5011 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 5012 | { |
Bram Moolenaar | e39b3d9 | 2016-01-15 22:52:22 +0100 | [diff] [blame] | 5013 | # ifdef FEAT_RIGHTLEFT |
| 5014 | if (wp->w_p_rl) |
| 5015 | wp->w_wcol = W_WIDTH(wp) - col + boguscols - 1; |
| 5016 | else |
| 5017 | # endif |
| 5018 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 5019 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5020 | did_wcol = TRUE; |
| 5021 | } |
| 5022 | #endif |
| 5023 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5024 | /* Don't override visual selection highlighting. */ |
| 5025 | if (n_attr > 0 |
| 5026 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5027 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5028 | char_attr = extra_attr; |
| 5029 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5030 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5031 | /* XIM don't send preedit_start and preedit_end, but they send |
| 5032 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 5033 | * im_is_preediting() here. */ |
| 5034 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5035 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5036 | && (State & INSERT) |
| 5037 | && !p_imdisable |
| 5038 | && im_is_preediting() |
| 5039 | && draw_state == WL_LINE) |
| 5040 | { |
| 5041 | colnr_T tcol; |
| 5042 | |
| 5043 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5044 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5045 | else |
| 5046 | tcol = preedit_end_col; |
| 5047 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 5048 | { |
| 5049 | if (feedback_old_attr < 0) |
| 5050 | { |
| 5051 | feedback_col = 0; |
| 5052 | feedback_old_attr = char_attr; |
| 5053 | } |
| 5054 | char_attr = im_get_feedback_attr(feedback_col); |
| 5055 | if (char_attr < 0) |
| 5056 | char_attr = feedback_old_attr; |
| 5057 | feedback_col++; |
| 5058 | } |
| 5059 | else if (feedback_old_attr >= 0) |
| 5060 | { |
| 5061 | char_attr = feedback_old_attr; |
| 5062 | feedback_old_attr = -1; |
| 5063 | feedback_col = 0; |
| 5064 | } |
| 5065 | } |
| 5066 | #endif |
| 5067 | /* |
| 5068 | * Handle the case where we are in column 0 but not on the first |
| 5069 | * character of the line and the user wants us to show us a |
| 5070 | * special character (via 'listchars' option "precedes:<char>". |
| 5071 | */ |
| 5072 | if (lcs_prec_todo != NUL |
Bram Moolenaar | 7425b93 | 2014-10-10 15:28:46 +0200 | [diff] [blame] | 5073 | && wp->w_p_list |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5074 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 5075 | #ifdef FEAT_DIFF |
| 5076 | && filler_todo <= 0 |
| 5077 | #endif |
| 5078 | && draw_state > WL_NR |
| 5079 | && c != NUL) |
| 5080 | { |
| 5081 | c = lcs_prec; |
| 5082 | lcs_prec_todo = NUL; |
| 5083 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 5084 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5085 | { |
| 5086 | /* Double-width character being overwritten by the "precedes" |
| 5087 | * character, need to fill up half the character. */ |
| 5088 | c_extra = MB_FILLER_CHAR; |
| 5089 | n_extra = 1; |
| 5090 | n_attr = 2; |
| 5091 | extra_attr = hl_attr(HLF_AT); |
| 5092 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5093 | mb_c = c; |
| 5094 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5095 | { |
| 5096 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5097 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5098 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5099 | } |
| 5100 | else |
| 5101 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5102 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5103 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5104 | { |
| 5105 | saved_attr3 = char_attr; /* save current attr */ |
| 5106 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 5107 | n_attr3 = 1; |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5112 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5113 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5114 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5115 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5116 | || did_line_attr == 1 |
| 5117 | #endif |
| 5118 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5119 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5120 | #ifdef FEAT_SEARCH_EXTRA |
| 5121 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5122 | |
| 5123 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 5124 | 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] | 5125 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5126 | #endif |
| 5127 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5128 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5129 | * highlight match at end of line. If it's beyond the last |
| 5130 | * char on the screen, just overwrite that one (tricky!) Not |
| 5131 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5132 | #ifdef FEAT_SEARCH_EXTRA |
| 5133 | prevcol_hl_flag = FALSE; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 5134 | if (!search_hl.is_addpos && prevcol == (long)search_hl.startcol) |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5135 | prevcol_hl_flag = TRUE; |
| 5136 | else |
| 5137 | { |
| 5138 | cur = wp->w_match_head; |
| 5139 | while (cur != NULL) |
| 5140 | { |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 5141 | if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol) |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5142 | { |
| 5143 | prevcol_hl_flag = TRUE; |
| 5144 | break; |
| 5145 | } |
| 5146 | cur = cur->next; |
| 5147 | } |
| 5148 | } |
| 5149 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5150 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5151 | && ((area_attr != 0 && vcol == fromcol |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5152 | && (VIsual_mode != Ctrl_V |
| 5153 | || lnum == VIsual.lnum |
| 5154 | || lnum == curwin->w_cursor.lnum) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5155 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5156 | #ifdef FEAT_SEARCH_EXTRA |
| 5157 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5158 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5159 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5160 | && did_line_attr <= 1 |
| 5161 | # endif |
| 5162 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5163 | #endif |
| 5164 | )) |
| 5165 | { |
| 5166 | int n = 0; |
| 5167 | |
| 5168 | #ifdef FEAT_RIGHTLEFT |
| 5169 | if (wp->w_p_rl) |
| 5170 | { |
| 5171 | if (col < 0) |
| 5172 | n = 1; |
| 5173 | } |
| 5174 | else |
| 5175 | #endif |
| 5176 | { |
| 5177 | if (col >= W_WIDTH(wp)) |
| 5178 | n = -1; |
| 5179 | } |
| 5180 | if (n != 0) |
| 5181 | { |
| 5182 | /* At the window boundary, highlight the last character |
| 5183 | * instead (better than nothing). */ |
| 5184 | off += n; |
| 5185 | col += n; |
| 5186 | } |
| 5187 | else |
| 5188 | { |
| 5189 | /* Add a blank character to highlight. */ |
| 5190 | ScreenLines[off] = ' '; |
| 5191 | #ifdef FEAT_MBYTE |
| 5192 | if (enc_utf8) |
| 5193 | ScreenLinesUC[off] = 0; |
| 5194 | #endif |
| 5195 | } |
| 5196 | #ifdef FEAT_SEARCH_EXTRA |
| 5197 | if (area_attr == 0) |
| 5198 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5199 | /* Use attributes from match with highest priority among |
| 5200 | * 'search_hl' and the match list. */ |
| 5201 | char_attr = search_hl.attr; |
| 5202 | cur = wp->w_match_head; |
| 5203 | shl_flag = FALSE; |
| 5204 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5205 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5206 | if (shl_flag == FALSE |
| 5207 | && ((cur != NULL |
| 5208 | && cur->priority > SEARCH_HL_PRIORITY) |
| 5209 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5210 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5211 | shl = &search_hl; |
| 5212 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5213 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5214 | else |
| 5215 | shl = &cur->hl; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 5216 | if ((ptr - line) - 1 == (long)shl->startcol |
| 5217 | && (shl == &search_hl || !shl->is_addpos)) |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5218 | char_attr = shl->attr; |
| 5219 | if (shl != &search_hl && cur != NULL) |
| 5220 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5221 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5222 | } |
| 5223 | #endif |
| 5224 | ScreenAttrs[off] = char_attr; |
| 5225 | #ifdef FEAT_RIGHTLEFT |
| 5226 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5227 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5228 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5229 | --off; |
| 5230 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5231 | else |
| 5232 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5233 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5234 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5235 | ++off; |
| 5236 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5237 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5238 | #ifdef FEAT_SYN_HL |
| 5239 | eol_hl_off = 1; |
| 5240 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5241 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5242 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5243 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5244 | /* |
| 5245 | * At end of the text line. |
| 5246 | */ |
| 5247 | if (c == NUL) |
| 5248 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5249 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5250 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 5251 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5252 | { |
| 5253 | /* highlight last char after line */ |
| 5254 | --col; |
| 5255 | --off; |
| 5256 | --vcol; |
| 5257 | } |
| 5258 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5259 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 5260 | if (wp->w_p_wrap) |
| 5261 | v = wp->w_skipcol; |
| 5262 | else |
| 5263 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5264 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5265 | /* check if line ends before left margin */ |
| 5266 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5267 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5268 | #ifdef FEAT_CONCEAL |
| 5269 | /* Get rid of the boguscols now, we want to draw until the right |
| 5270 | * edge for 'cursorcolumn'. */ |
| 5271 | col -= boguscols; |
| 5272 | boguscols = 0; |
| 5273 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5274 | |
| 5275 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5276 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5277 | |
| 5278 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5279 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 5280 | && (int)wp->w_virtcol < |
| 5281 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5282 | && lnum != wp->w_cursor.lnum) |
| 5283 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5284 | # ifdef FEAT_RIGHTLEFT |
| 5285 | && !wp->w_p_rl |
| 5286 | # endif |
| 5287 | ) |
| 5288 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5289 | int rightmost_vcol = 0; |
| 5290 | int i; |
| 5291 | |
| 5292 | if (wp->w_p_cuc) |
| 5293 | rightmost_vcol = wp->w_virtcol; |
| 5294 | if (draw_color_col) |
| 5295 | /* determine rightmost colorcolumn to possibly draw */ |
| 5296 | for (i = 0; color_cols[i] >= 0; ++i) |
| 5297 | if (rightmost_vcol < color_cols[i]) |
| 5298 | rightmost_vcol = color_cols[i]; |
| 5299 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5300 | while (col < W_WIDTH(wp)) |
| 5301 | { |
| 5302 | ScreenLines[off] = ' '; |
| 5303 | #ifdef FEAT_MBYTE |
| 5304 | if (enc_utf8) |
| 5305 | ScreenLinesUC[off] = 0; |
| 5306 | #endif |
| 5307 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 5308 | if (draw_color_col) |
| 5309 | draw_color_col = advance_color_col(VCOL_HLC, |
| 5310 | &color_cols); |
| 5311 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5312 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5313 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5314 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5315 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 5316 | else |
| 5317 | ScreenAttrs[off++] = 0; |
| 5318 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5319 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5320 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5321 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5322 | ++vcol; |
| 5323 | } |
| 5324 | } |
| 5325 | #endif |
| 5326 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5327 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5328 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5329 | row++; |
| 5330 | |
| 5331 | /* |
| 5332 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 5333 | * updated (saves a call to plines() later). |
| 5334 | */ |
| 5335 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 5336 | { |
| 5337 | curwin->w_cline_row = startrow; |
| 5338 | curwin->w_cline_height = row - startrow; |
| 5339 | #ifdef FEAT_FOLDING |
| 5340 | curwin->w_cline_folded = FALSE; |
| 5341 | #endif |
| 5342 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 5343 | } |
| 5344 | |
| 5345 | break; |
| 5346 | } |
| 5347 | |
| 5348 | /* line continues beyond line end */ |
| 5349 | if (lcs_ext |
| 5350 | && !wp->w_p_wrap |
| 5351 | #ifdef FEAT_DIFF |
| 5352 | && filler_todo <= 0 |
| 5353 | #endif |
| 5354 | && ( |
| 5355 | #ifdef FEAT_RIGHTLEFT |
| 5356 | wp->w_p_rl ? col == 0 : |
| 5357 | #endif |
| 5358 | col == W_WIDTH(wp) - 1) |
| 5359 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 5360 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5361 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 5362 | { |
| 5363 | c = lcs_ext; |
| 5364 | char_attr = hl_attr(HLF_AT); |
| 5365 | #ifdef FEAT_MBYTE |
| 5366 | mb_c = c; |
| 5367 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5368 | { |
| 5369 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5370 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5371 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5372 | } |
| 5373 | else |
| 5374 | mb_utf8 = FALSE; |
| 5375 | #endif |
| 5376 | } |
| 5377 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5378 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5379 | /* advance to the next 'colorcolumn' */ |
| 5380 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5381 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5382 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5383 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5384 | * highlight the cursor position itself. |
| 5385 | * Also highlight the 'colorcolumn' if it is different than |
| 5386 | * 'cursorcolumn' */ |
| 5387 | vcol_save_attr = -1; |
| 5388 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5389 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5390 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5391 | && lnum != wp->w_cursor.lnum) |
| 5392 | { |
| 5393 | vcol_save_attr = char_attr; |
| 5394 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 5395 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 5396 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5397 | { |
| 5398 | vcol_save_attr = char_attr; |
| 5399 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 5400 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5401 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5402 | #endif |
| 5403 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5404 | /* |
| 5405 | * Store character to be displayed. |
| 5406 | * Skip characters that are left of the screen for 'nowrap'. |
| 5407 | */ |
| 5408 | vcol_prev = vcol; |
| 5409 | if (draw_state < WL_LINE || n_skip <= 0) |
| 5410 | { |
| 5411 | /* |
| 5412 | * Store the character. |
| 5413 | */ |
| 5414 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 5415 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 5416 | { |
| 5417 | /* A double-wide character is: put first halve in left cell. */ |
| 5418 | --off; |
| 5419 | --col; |
| 5420 | } |
| 5421 | #endif |
| 5422 | ScreenLines[off] = c; |
| 5423 | #ifdef FEAT_MBYTE |
| 5424 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5425 | { |
| 5426 | if ((mb_c & 0xff00) == 0x8e00) |
| 5427 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5428 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5429 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5430 | else if (enc_utf8) |
| 5431 | { |
| 5432 | if (mb_utf8) |
| 5433 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5434 | int i; |
| 5435 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5436 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5437 | if ((c & 0xff) == 0) |
| 5438 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5439 | for (i = 0; i < Screen_mco; ++i) |
| 5440 | { |
| 5441 | ScreenLinesC[i][off] = u8cc[i]; |
| 5442 | if (u8cc[i] == 0) |
| 5443 | break; |
| 5444 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5445 | } |
| 5446 | else |
| 5447 | ScreenLinesUC[off] = 0; |
| 5448 | } |
| 5449 | if (multi_attr) |
| 5450 | { |
| 5451 | ScreenAttrs[off] = multi_attr; |
| 5452 | multi_attr = 0; |
| 5453 | } |
| 5454 | else |
| 5455 | #endif |
| 5456 | ScreenAttrs[off] = char_attr; |
| 5457 | |
| 5458 | #ifdef FEAT_MBYTE |
| 5459 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5460 | { |
| 5461 | /* Need to fill two screen columns. */ |
| 5462 | ++off; |
| 5463 | ++col; |
| 5464 | if (enc_utf8) |
| 5465 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5466 | ScreenLines[off] = 0; |
| 5467 | else |
| 5468 | /* DBCS: Put second byte in the second screen char. */ |
| 5469 | ScreenLines[off] = mb_c & 0xff; |
Bram Moolenaar | 32a214e | 2015-12-03 14:29:02 +0100 | [diff] [blame] | 5470 | if (draw_state > WL_NR |
| 5471 | #ifdef FEAT_DIFF |
| 5472 | && filler_todo <= 0 |
| 5473 | #endif |
| 5474 | ) |
| 5475 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5476 | /* When "tocol" is halfway a character, set it to the end of |
| 5477 | * the character, otherwise highlighting won't stop. */ |
| 5478 | if (tocol == vcol) |
| 5479 | ++tocol; |
| 5480 | #ifdef FEAT_RIGHTLEFT |
| 5481 | if (wp->w_p_rl) |
| 5482 | { |
| 5483 | /* now it's time to backup one cell */ |
| 5484 | --off; |
| 5485 | --col; |
| 5486 | } |
| 5487 | #endif |
| 5488 | } |
| 5489 | #endif |
| 5490 | #ifdef FEAT_RIGHTLEFT |
| 5491 | if (wp->w_p_rl) |
| 5492 | { |
| 5493 | --off; |
| 5494 | --col; |
| 5495 | } |
| 5496 | else |
| 5497 | #endif |
| 5498 | { |
| 5499 | ++off; |
| 5500 | ++col; |
| 5501 | } |
| 5502 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5503 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5504 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5505 | { |
| 5506 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5507 | ++vcol_off; |
| 5508 | if (n_extra > 0) |
| 5509 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5510 | if (wp->w_p_wrap) |
| 5511 | { |
| 5512 | /* |
| 5513 | * Special voodoo required if 'wrap' is on. |
| 5514 | * |
| 5515 | * Advance the column indicator to force the line |
| 5516 | * drawing to wrap early. This will make the line |
| 5517 | * take up the same screen space when parts are concealed, |
| 5518 | * so that cursor line computations aren't messed up. |
| 5519 | * |
| 5520 | * To avoid the fictitious advance of 'col' causing |
| 5521 | * trailing junk to be written out of the screen line |
| 5522 | * we are building, 'boguscols' keeps track of the number |
| 5523 | * of bad columns we have advanced. |
| 5524 | */ |
| 5525 | if (n_extra > 0) |
| 5526 | { |
| 5527 | vcol += n_extra; |
| 5528 | # ifdef FEAT_RIGHTLEFT |
| 5529 | if (wp->w_p_rl) |
| 5530 | { |
| 5531 | col -= n_extra; |
| 5532 | boguscols -= n_extra; |
| 5533 | } |
| 5534 | else |
| 5535 | # endif |
| 5536 | { |
| 5537 | col += n_extra; |
| 5538 | boguscols += n_extra; |
| 5539 | } |
| 5540 | n_extra = 0; |
| 5541 | n_attr = 0; |
| 5542 | } |
| 5543 | |
| 5544 | |
| 5545 | # ifdef FEAT_MBYTE |
| 5546 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5547 | { |
| 5548 | /* Need to fill two screen columns. */ |
| 5549 | # ifdef FEAT_RIGHTLEFT |
| 5550 | if (wp->w_p_rl) |
| 5551 | { |
| 5552 | --boguscols; |
| 5553 | --col; |
| 5554 | } |
| 5555 | else |
| 5556 | # endif |
| 5557 | { |
| 5558 | ++boguscols; |
| 5559 | ++col; |
| 5560 | } |
| 5561 | } |
| 5562 | # endif |
| 5563 | |
| 5564 | # ifdef FEAT_RIGHTLEFT |
| 5565 | if (wp->w_p_rl) |
| 5566 | { |
| 5567 | --boguscols; |
| 5568 | --col; |
| 5569 | } |
| 5570 | else |
| 5571 | # endif |
| 5572 | { |
| 5573 | ++boguscols; |
| 5574 | ++col; |
| 5575 | } |
| 5576 | } |
| 5577 | else |
| 5578 | { |
| 5579 | if (n_extra > 0) |
| 5580 | { |
| 5581 | vcol += n_extra; |
| 5582 | n_extra = 0; |
| 5583 | n_attr = 0; |
| 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | } |
| 5588 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5589 | else |
| 5590 | --n_skip; |
| 5591 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5592 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5593 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5594 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5595 | #ifdef FEAT_DIFF |
| 5596 | && filler_todo <= 0 |
| 5597 | #endif |
| 5598 | ) |
| 5599 | ++vcol; |
| 5600 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5601 | #ifdef FEAT_SYN_HL |
| 5602 | if (vcol_save_attr >= 0) |
| 5603 | char_attr = vcol_save_attr; |
| 5604 | #endif |
| 5605 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5606 | /* restore attributes after "predeces" in 'listchars' */ |
| 5607 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5608 | char_attr = saved_attr3; |
| 5609 | |
| 5610 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5611 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5612 | char_attr = saved_attr2; |
| 5613 | |
| 5614 | /* |
| 5615 | * 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] | 5616 | * 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] | 5617 | */ |
| 5618 | if (( |
| 5619 | #ifdef FEAT_RIGHTLEFT |
| 5620 | wp->w_p_rl ? (col < 0) : |
| 5621 | #endif |
| 5622 | (col >= W_WIDTH(wp))) |
| 5623 | && (*ptr != NUL |
| 5624 | #ifdef FEAT_DIFF |
| 5625 | || filler_todo > 0 |
| 5626 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5627 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5628 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5629 | ) |
| 5630 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5631 | #ifdef FEAT_CONCEAL |
| 5632 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5633 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5634 | boguscols = 0; |
| 5635 | #else |
| 5636 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5637 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5638 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5639 | ++row; |
| 5640 | ++screen_row; |
| 5641 | |
| 5642 | /* When not wrapping and finished diff lines, or when displayed |
| 5643 | * '$' and highlighting until last column, break here. */ |
| 5644 | if ((!wp->w_p_wrap |
| 5645 | #ifdef FEAT_DIFF |
| 5646 | && filler_todo <= 0 |
| 5647 | #endif |
| 5648 | ) || lcs_eol_one == -1) |
| 5649 | break; |
| 5650 | |
| 5651 | /* When the window is too narrow draw all "@" lines. */ |
| 5652 | if (draw_state != WL_LINE |
| 5653 | #ifdef FEAT_DIFF |
| 5654 | && filler_todo <= 0 |
| 5655 | #endif |
| 5656 | ) |
| 5657 | { |
| 5658 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5659 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5660 | draw_vsep_win(wp, row); |
| 5661 | #endif |
| 5662 | row = endrow; |
| 5663 | } |
| 5664 | |
| 5665 | /* When line got too long for screen break here. */ |
| 5666 | if (row == endrow) |
| 5667 | { |
| 5668 | ++row; |
| 5669 | break; |
| 5670 | } |
| 5671 | |
| 5672 | if (screen_cur_row == screen_row - 1 |
| 5673 | #ifdef FEAT_DIFF |
| 5674 | && filler_todo <= 0 |
| 5675 | #endif |
Bram Moolenaar | a1f4cb9 | 2016-11-06 15:25:42 +0100 | [diff] [blame] | 5676 | #ifdef FEAT_WINDOWS |
| 5677 | && W_WIDTH(wp) == Columns |
| 5678 | #endif |
| 5679 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5680 | { |
| 5681 | /* Remember that the line wraps, used for modeless copy. */ |
| 5682 | LineWraps[screen_row - 1] = TRUE; |
| 5683 | |
| 5684 | /* |
| 5685 | * Special trick to make copy/paste of wrapped lines work with |
| 5686 | * xterm/screen: write an extra character beyond the end of |
| 5687 | * the line. This will work with all terminal types |
| 5688 | * (regardless of the xn,am settings). |
| 5689 | * Only do this on a fast tty. |
| 5690 | * Only do this if the cursor is on the current line |
| 5691 | * (something has been written in it). |
| 5692 | * Don't do this for the GUI. |
| 5693 | * Don't do this for double-width characters. |
| 5694 | * Don't do this for a window not at the right screen border. |
| 5695 | */ |
| 5696 | if (p_tf |
| 5697 | #ifdef FEAT_GUI |
| 5698 | && !gui.in_use |
| 5699 | #endif |
| 5700 | #ifdef FEAT_MBYTE |
| 5701 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5702 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5703 | LineOffset[screen_row] + screen_Columns) |
| 5704 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5705 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5706 | + (int)Columns - 2, |
| 5707 | LineOffset[screen_row] + screen_Columns) |
| 5708 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5709 | #endif |
| 5710 | ) |
| 5711 | { |
| 5712 | /* First make sure we are at the end of the screen line, |
| 5713 | * then output the same character again to let the |
| 5714 | * terminal know about the wrap. If the terminal doesn't |
| 5715 | * auto-wrap, we overwrite the character. */ |
| 5716 | if (screen_cur_col != W_WIDTH(wp)) |
| 5717 | screen_char(LineOffset[screen_row - 1] |
| 5718 | + (unsigned)Columns - 1, |
| 5719 | screen_row - 1, (int)(Columns - 1)); |
| 5720 | |
| 5721 | #ifdef FEAT_MBYTE |
| 5722 | /* When there is a multi-byte character, just output a |
| 5723 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5724 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5725 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5726 | out_char(' '); |
| 5727 | else |
| 5728 | #endif |
| 5729 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5730 | + (Columns - 1)]); |
| 5731 | /* force a redraw of the first char on the next line */ |
| 5732 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5733 | screen_start(); /* don't know where cursor is now */ |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | col = 0; |
| 5738 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5739 | #ifdef FEAT_RIGHTLEFT |
| 5740 | if (wp->w_p_rl) |
| 5741 | { |
| 5742 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5743 | off += col; |
| 5744 | } |
| 5745 | #endif |
| 5746 | |
| 5747 | /* reset the drawing state for the start of a wrapped line */ |
| 5748 | draw_state = WL_START; |
| 5749 | saved_n_extra = n_extra; |
| 5750 | saved_p_extra = p_extra; |
| 5751 | saved_c_extra = c_extra; |
| 5752 | saved_char_attr = char_attr; |
| 5753 | n_extra = 0; |
| 5754 | lcs_prec_todo = lcs_prec; |
| 5755 | #ifdef FEAT_LINEBREAK |
| 5756 | # ifdef FEAT_DIFF |
| 5757 | if (filler_todo <= 0) |
| 5758 | # endif |
| 5759 | need_showbreak = TRUE; |
| 5760 | #endif |
| 5761 | #ifdef FEAT_DIFF |
| 5762 | --filler_todo; |
| 5763 | /* When the filler lines are actually below the last line of the |
| 5764 | * file, don't draw the line itself, break here. */ |
| 5765 | if (filler_todo == 0 && wp->w_botfill) |
| 5766 | break; |
| 5767 | #endif |
| 5768 | } |
| 5769 | |
| 5770 | } /* for every character in the line */ |
| 5771 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5772 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5773 | /* After an empty line check first word for capital. */ |
| 5774 | if (*skipwhite(line) == NUL) |
| 5775 | { |
| 5776 | capcol_lnum = lnum + 1; |
| 5777 | cap_col = 0; |
| 5778 | } |
| 5779 | #endif |
| 5780 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5781 | return row; |
| 5782 | } |
| 5783 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5784 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 5785 | static int comp_char_differs(int, int); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5786 | |
| 5787 | /* |
| 5788 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5789 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5790 | */ |
| 5791 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5792 | comp_char_differs(int off_from, int off_to) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5793 | { |
| 5794 | int i; |
| 5795 | |
| 5796 | for (i = 0; i < Screen_mco; ++i) |
| 5797 | { |
| 5798 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5799 | return TRUE; |
| 5800 | if (ScreenLinesC[i][off_from] == 0) |
| 5801 | break; |
| 5802 | } |
| 5803 | return FALSE; |
| 5804 | } |
| 5805 | #endif |
| 5806 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5807 | /* |
| 5808 | * Check whether the given character needs redrawing: |
| 5809 | * - the (first byte of the) character is different |
| 5810 | * - the attributes are different |
| 5811 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5812 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5813 | */ |
| 5814 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5815 | char_needs_redraw(int off_from, int off_to, int cols) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5816 | { |
| 5817 | if (cols > 0 |
| 5818 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5819 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5820 | |
| 5821 | #ifdef FEAT_MBYTE |
| 5822 | || (enc_dbcs != 0 |
| 5823 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5824 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5825 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5826 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5827 | != ScreenLines[off_to + 1]))) |
| 5828 | || (enc_utf8 |
| 5829 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5830 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5831 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5832 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5833 | && ScreenLines[off_from + 1] |
| 5834 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5835 | #endif |
| 5836 | )) |
| 5837 | return TRUE; |
| 5838 | return FALSE; |
| 5839 | } |
| 5840 | |
| 5841 | /* |
| 5842 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5843 | * have actually changed. Handle insert/delete character. |
| 5844 | * "coloff" gives the first column on the screen for this line. |
| 5845 | * "endcol" gives the columns where valid characters are. |
| 5846 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5847 | * needs to be cleared, negative otherwise. |
| 5848 | * "rlflag" is TRUE in a rightleft window: |
| 5849 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5850 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5851 | */ |
| 5852 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5853 | screen_line( |
| 5854 | int row, |
| 5855 | int coloff, |
| 5856 | int endcol, |
| 5857 | int clear_width |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5858 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5859 | , int rlflag |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5860 | #endif |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5861 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5862 | { |
| 5863 | unsigned off_from; |
| 5864 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5865 | #ifdef FEAT_MBYTE |
| 5866 | unsigned max_off_from; |
| 5867 | unsigned max_off_to; |
| 5868 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5869 | int col = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5870 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5871 | int hl; |
| 5872 | #endif |
| 5873 | int force = FALSE; /* force update rest of the line */ |
| 5874 | int redraw_this /* bool: does character need redraw? */ |
| 5875 | #ifdef FEAT_GUI |
| 5876 | = TRUE /* For GUI when while-loop empty */ |
| 5877 | #endif |
| 5878 | ; |
| 5879 | int redraw_next; /* redraw_this for next character */ |
| 5880 | #ifdef FEAT_MBYTE |
| 5881 | int clear_next = FALSE; |
| 5882 | int char_cells; /* 1: normal char */ |
| 5883 | /* 2: occupies two display cells */ |
| 5884 | # define CHAR_CELLS char_cells |
| 5885 | #else |
| 5886 | # define CHAR_CELLS 1 |
| 5887 | #endif |
| 5888 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5889 | /* Check for illegal row and col, just in case. */ |
| 5890 | if (row >= Rows) |
| 5891 | row = Rows - 1; |
| 5892 | if (endcol > Columns) |
| 5893 | endcol = Columns; |
| 5894 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5895 | # ifdef FEAT_CLIPBOARD |
| 5896 | clip_may_clear_selection(row, row); |
| 5897 | # endif |
| 5898 | |
| 5899 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5900 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5901 | #ifdef FEAT_MBYTE |
| 5902 | max_off_from = off_from + screen_Columns; |
| 5903 | max_off_to = LineOffset[row] + screen_Columns; |
| 5904 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5905 | |
| 5906 | #ifdef FEAT_RIGHTLEFT |
| 5907 | if (rlflag) |
| 5908 | { |
| 5909 | /* Clear rest first, because it's left of the text. */ |
| 5910 | if (clear_width > 0) |
| 5911 | { |
| 5912 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5913 | && ScreenAttrs[off_to] == 0 |
| 5914 | # ifdef FEAT_MBYTE |
| 5915 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5916 | # endif |
| 5917 | ) |
| 5918 | { |
| 5919 | ++off_to; |
| 5920 | ++col; |
| 5921 | } |
| 5922 | if (col <= endcol) |
| 5923 | screen_fill(row, row + 1, col + coloff, |
| 5924 | endcol + coloff + 1, ' ', ' ', 0); |
| 5925 | } |
| 5926 | col = endcol + 1; |
| 5927 | off_to = LineOffset[row] + col + coloff; |
| 5928 | off_from += col; |
| 5929 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5930 | } |
| 5931 | #endif /* FEAT_RIGHTLEFT */ |
| 5932 | |
| 5933 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5934 | |
| 5935 | while (col < endcol) |
| 5936 | { |
| 5937 | #ifdef FEAT_MBYTE |
| 5938 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5939 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5940 | else |
| 5941 | char_cells = 1; |
| 5942 | #endif |
| 5943 | |
| 5944 | redraw_this = redraw_next; |
| 5945 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5946 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5947 | |
| 5948 | #ifdef FEAT_GUI |
| 5949 | /* If the next character was bold, then redraw the current character to |
| 5950 | * remove any pixels that might have spilt over into us. This only |
| 5951 | * happens in the GUI. |
| 5952 | */ |
| 5953 | if (redraw_next && gui.in_use) |
| 5954 | { |
| 5955 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5956 | if (hl > HL_ALL) |
| 5957 | hl = syn_attr2attr(hl); |
| 5958 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5959 | redraw_this = TRUE; |
| 5960 | } |
| 5961 | #endif |
| 5962 | |
| 5963 | if (redraw_this) |
| 5964 | { |
| 5965 | /* |
| 5966 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5967 | * Attributes for characters are stored at the position where the |
| 5968 | * cursor is when writing the highlighting code. The |
| 5969 | * start-highlighting code must be written with the cursor on the |
| 5970 | * first highlighted character. The stop-highlighting code must |
| 5971 | * be written with the cursor just after the last highlighted |
| 5972 | * character. |
| 5973 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5974 | * to clear the rest of the line, and force redrawing it |
| 5975 | * completely. |
| 5976 | */ |
| 5977 | if ( p_wiv |
| 5978 | && !force |
| 5979 | #ifdef FEAT_GUI |
| 5980 | && !gui.in_use |
| 5981 | #endif |
| 5982 | && ScreenAttrs[off_to] != 0 |
| 5983 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5984 | { |
| 5985 | /* |
| 5986 | * Need to remove highlighting attributes here. |
| 5987 | */ |
| 5988 | windgoto(row, col + coloff); |
| 5989 | out_str(T_CE); /* clear rest of this screen line */ |
| 5990 | screen_start(); /* don't know where cursor is now */ |
| 5991 | force = TRUE; /* force redraw of rest of the line */ |
| 5992 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5993 | |
| 5994 | /* |
| 5995 | * If the previous character was highlighted, need to stop |
| 5996 | * highlighting at this character. |
| 5997 | */ |
| 5998 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5999 | { |
| 6000 | screen_attr = ScreenAttrs[off_to - 1]; |
| 6001 | term_windgoto(row, col + coloff); |
| 6002 | screen_stop_highlight(); |
| 6003 | } |
| 6004 | else |
| 6005 | screen_attr = 0; /* highlighting has stopped */ |
| 6006 | } |
| 6007 | #ifdef FEAT_MBYTE |
| 6008 | if (enc_dbcs != 0) |
| 6009 | { |
| 6010 | /* Check if overwriting a double-byte with a single-byte or |
| 6011 | * the other way around requires another character to be |
| 6012 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 6013 | * ScreenLinesUC[] is sufficient. */ |
| 6014 | if (char_cells == 1 |
| 6015 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6016 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6017 | { |
| 6018 | /* Writing a single-cell character over a double-cell |
| 6019 | * character: need to redraw the next cell. */ |
| 6020 | ScreenLines[off_to + 1] = 0; |
| 6021 | redraw_next = TRUE; |
| 6022 | } |
| 6023 | else if (char_cells == 2 |
| 6024 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6025 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6026 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6027 | { |
| 6028 | /* Writing the second half of a double-cell character over |
| 6029 | * a double-cell character: need to redraw the second |
| 6030 | * cell. */ |
| 6031 | ScreenLines[off_to + 2] = 0; |
| 6032 | redraw_next = TRUE; |
| 6033 | } |
| 6034 | |
| 6035 | if (enc_dbcs == DBCS_JPNU) |
| 6036 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 6037 | } |
| 6038 | /* When writing a single-width character over a double-width |
| 6039 | * character and at the end of the redrawn text, need to clear out |
| 6040 | * the right halve of the old character. |
| 6041 | * Also required when writing the right halve of a double-width |
| 6042 | * char over the left halve of an existing one. */ |
| 6043 | if (has_mbyte && col + char_cells == endcol |
| 6044 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6045 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6046 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6047 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6048 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6049 | clear_next = TRUE; |
| 6050 | #endif |
| 6051 | |
| 6052 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 6053 | #ifdef FEAT_MBYTE |
| 6054 | if (enc_utf8) |
| 6055 | { |
| 6056 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 6057 | if (ScreenLinesUC[off_from] != 0) |
| 6058 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6059 | int i; |
| 6060 | |
| 6061 | for (i = 0; i < Screen_mco; ++i) |
| 6062 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6063 | } |
| 6064 | } |
| 6065 | if (char_cells == 2) |
| 6066 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 6067 | #endif |
| 6068 | |
| 6069 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6070 | /* The bold trick makes a single column of pixels appear in the |
| 6071 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6072 | * character should be redrawn too. This happens for our own GUI |
| 6073 | * and for some xterms. */ |
| 6074 | if ( |
| 6075 | # ifdef FEAT_GUI |
| 6076 | gui.in_use |
| 6077 | # endif |
| 6078 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6079 | || |
| 6080 | # endif |
| 6081 | # ifdef UNIX |
| 6082 | term_is_xterm |
| 6083 | # endif |
| 6084 | ) |
| 6085 | { |
| 6086 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 6087 | if (hl > HL_ALL) |
| 6088 | hl = syn_attr2attr(hl); |
| 6089 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6090 | redraw_next = TRUE; |
| 6091 | } |
| 6092 | #endif |
| 6093 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 6094 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6095 | /* For simplicity set the attributes of second half of a |
| 6096 | * double-wide character equal to the first half. */ |
| 6097 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6098 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6099 | |
| 6100 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6101 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6102 | else |
| 6103 | #endif |
| 6104 | screen_char(off_to, row, col + coloff); |
| 6105 | } |
| 6106 | else if ( p_wiv |
| 6107 | #ifdef FEAT_GUI |
| 6108 | && !gui.in_use |
| 6109 | #endif |
| 6110 | && col + coloff > 0) |
| 6111 | { |
| 6112 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 6113 | { |
| 6114 | /* |
| 6115 | * Don't output stop-highlight when moving the cursor, it will |
| 6116 | * stop the highlighting when it should continue. |
| 6117 | */ |
| 6118 | screen_attr = 0; |
| 6119 | } |
| 6120 | else if (screen_attr != 0) |
| 6121 | screen_stop_highlight(); |
| 6122 | } |
| 6123 | |
| 6124 | off_to += CHAR_CELLS; |
| 6125 | off_from += CHAR_CELLS; |
| 6126 | col += CHAR_CELLS; |
| 6127 | } |
| 6128 | |
| 6129 | #ifdef FEAT_MBYTE |
| 6130 | if (clear_next) |
| 6131 | { |
| 6132 | /* Clear the second half of a double-wide character of which the left |
| 6133 | * half was overwritten with a single-wide character. */ |
| 6134 | ScreenLines[off_to] = ' '; |
| 6135 | if (enc_utf8) |
| 6136 | ScreenLinesUC[off_to] = 0; |
| 6137 | screen_char(off_to, row, col + coloff); |
| 6138 | } |
| 6139 | #endif |
| 6140 | |
| 6141 | if (clear_width > 0 |
| 6142 | #ifdef FEAT_RIGHTLEFT |
| 6143 | && !rlflag |
| 6144 | #endif |
| 6145 | ) |
| 6146 | { |
| 6147 | #ifdef FEAT_GUI |
| 6148 | int startCol = col; |
| 6149 | #endif |
| 6150 | |
| 6151 | /* blank out the rest of the line */ |
| 6152 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 6153 | && ScreenAttrs[off_to] == 0 |
| 6154 | #ifdef FEAT_MBYTE |
| 6155 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 6156 | #endif |
| 6157 | ) |
| 6158 | { |
| 6159 | ++off_to; |
| 6160 | ++col; |
| 6161 | } |
| 6162 | if (col < clear_width) |
| 6163 | { |
| 6164 | #ifdef FEAT_GUI |
| 6165 | /* |
| 6166 | * In the GUI, clearing the rest of the line may leave pixels |
| 6167 | * behind if the first character cleared was bold. Some bold |
| 6168 | * fonts spill over the left. In this case we redraw the previous |
| 6169 | * character too. If we didn't skip any blanks above, then we |
| 6170 | * only redraw if the character wasn't already redrawn anyway. |
| 6171 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6172 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6173 | { |
| 6174 | hl = ScreenAttrs[off_to]; |
| 6175 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6176 | { |
| 6177 | int prev_cells = 1; |
| 6178 | # ifdef FEAT_MBYTE |
| 6179 | if (enc_utf8) |
| 6180 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 6181 | * that its width is 2. */ |
| 6182 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 6183 | else if (enc_dbcs != 0) |
| 6184 | { |
| 6185 | /* find previous character by counting from first |
| 6186 | * column and get its width. */ |
| 6187 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6188 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6189 | |
| 6190 | while (off < off_to) |
| 6191 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6192 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6193 | off += prev_cells; |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | if (enc_dbcs != 0 && prev_cells > 1) |
| 6198 | screen_char_2(off_to - prev_cells, row, |
| 6199 | col + coloff - prev_cells); |
| 6200 | else |
| 6201 | # endif |
| 6202 | screen_char(off_to - prev_cells, row, |
| 6203 | col + coloff - prev_cells); |
| 6204 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6205 | } |
| 6206 | #endif |
| 6207 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 6208 | ' ', ' ', 0); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6209 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6210 | off_to += clear_width - col; |
| 6211 | col = clear_width; |
| 6212 | #endif |
| 6213 | } |
| 6214 | } |
| 6215 | |
| 6216 | if (clear_width > 0) |
| 6217 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6218 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6219 | /* For a window that's left of another, draw the separator char. */ |
| 6220 | if (col + coloff < Columns) |
| 6221 | { |
| 6222 | int c; |
| 6223 | |
| 6224 | c = fillchar_vsep(&hl); |
Bram Moolenaar | c60c4f6 | 2015-01-07 19:04:28 +0100 | [diff] [blame] | 6225 | if (ScreenLines[off_to] != (schar_T)c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6226 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6227 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 6228 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6229 | # endif |
| 6230 | || ScreenAttrs[off_to] != hl) |
| 6231 | { |
| 6232 | ScreenLines[off_to] = c; |
| 6233 | ScreenAttrs[off_to] = hl; |
| 6234 | # ifdef FEAT_MBYTE |
| 6235 | if (enc_utf8) |
| 6236 | { |
| 6237 | if (c >= 0x80) |
| 6238 | { |
| 6239 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6240 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6241 | } |
| 6242 | else |
| 6243 | ScreenLinesUC[off_to] = 0; |
| 6244 | } |
| 6245 | # endif |
| 6246 | screen_char(off_to, row, col + coloff); |
| 6247 | } |
| 6248 | } |
| 6249 | else |
| 6250 | #endif |
| 6251 | LineWraps[row] = FALSE; |
| 6252 | } |
| 6253 | } |
| 6254 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6255 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6256 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6257 | * Mirror text "str" for right-left displaying. |
| 6258 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6259 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6260 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6261 | rl_mirror(char_u *str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6262 | { |
| 6263 | char_u *p1, *p2; |
| 6264 | int t; |
| 6265 | |
| 6266 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 6267 | { |
| 6268 | t = *p1; |
| 6269 | *p1 = *p2; |
| 6270 | *p2 = t; |
| 6271 | } |
| 6272 | } |
| 6273 | #endif |
| 6274 | |
| 6275 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6276 | /* |
| 6277 | * mark all status lines for redraw; used after first :cd |
| 6278 | */ |
| 6279 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6280 | status_redraw_all(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6281 | { |
| 6282 | win_T *wp; |
| 6283 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6284 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6285 | if (wp->w_status_height) |
| 6286 | { |
| 6287 | wp->w_redr_status = TRUE; |
| 6288 | redraw_later(VALID); |
| 6289 | } |
| 6290 | } |
| 6291 | |
| 6292 | /* |
| 6293 | * mark all status lines of the current buffer for redraw |
| 6294 | */ |
| 6295 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6296 | status_redraw_curbuf(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6297 | { |
| 6298 | win_T *wp; |
| 6299 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6300 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6301 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 6302 | { |
| 6303 | wp->w_redr_status = TRUE; |
| 6304 | redraw_later(VALID); |
| 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | /* |
| 6309 | * Redraw all status lines that need to be redrawn. |
| 6310 | */ |
| 6311 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6312 | redraw_statuslines(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6313 | { |
| 6314 | win_T *wp; |
| 6315 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6316 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6317 | if (wp->w_redr_status) |
| 6318 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 6319 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6320 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6321 | } |
| 6322 | #endif |
| 6323 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6324 | #if (defined(FEAT_WILDMENU) && defined(FEAT_WINDOWS)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6325 | /* |
| 6326 | * Redraw all status lines at the bottom of frame "frp". |
| 6327 | */ |
| 6328 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6329 | win_redraw_last_status(frame_T *frp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6330 | { |
| 6331 | if (frp->fr_layout == FR_LEAF) |
| 6332 | frp->fr_win->w_redr_status = TRUE; |
| 6333 | else if (frp->fr_layout == FR_ROW) |
| 6334 | { |
| 6335 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 6336 | win_redraw_last_status(frp); |
| 6337 | } |
| 6338 | else /* frp->fr_layout == FR_COL */ |
| 6339 | { |
| 6340 | frp = frp->fr_child; |
| 6341 | while (frp->fr_next != NULL) |
| 6342 | frp = frp->fr_next; |
| 6343 | win_redraw_last_status(frp); |
| 6344 | } |
| 6345 | } |
| 6346 | #endif |
| 6347 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6348 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6349 | /* |
| 6350 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 6351 | */ |
| 6352 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6353 | draw_vsep_win(win_T *wp, int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6354 | { |
| 6355 | int hl; |
| 6356 | int c; |
| 6357 | |
| 6358 | if (wp->w_vsep_width) |
| 6359 | { |
| 6360 | /* draw the vertical separator right of this window */ |
| 6361 | c = fillchar_vsep(&hl); |
| 6362 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 6363 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 6364 | c, ' ', hl); |
| 6365 | } |
| 6366 | } |
| 6367 | #endif |
| 6368 | |
| 6369 | #ifdef FEAT_WILDMENU |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 6370 | static int status_match_len(expand_T *xp, char_u *s); |
| 6371 | static int skip_status_match_char(expand_T *xp, char_u *s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6372 | |
| 6373 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6374 | * 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] | 6375 | */ |
| 6376 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6377 | status_match_len(expand_T *xp, char_u *s) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6378 | { |
| 6379 | int len = 0; |
| 6380 | |
| 6381 | #ifdef FEAT_MENU |
| 6382 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 6383 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6384 | |
| 6385 | /* Check for menu separators - replace with '|'. */ |
| 6386 | if (emenu && menu_is_separator(s)) |
| 6387 | return 1; |
| 6388 | #endif |
| 6389 | |
| 6390 | while (*s != NUL) |
| 6391 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6392 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 6393 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6394 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | return len; |
| 6398 | } |
| 6399 | |
| 6400 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6401 | * 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] | 6402 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 6403 | */ |
| 6404 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6405 | skip_status_match_char(expand_T *xp, char_u *s) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6406 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6407 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6408 | #ifdef FEAT_MENU |
| 6409 | || ((xp->xp_context == EXPAND_MENUS |
| 6410 | || xp->xp_context == EXPAND_MENUNAMES) |
| 6411 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 6412 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6413 | ) |
| 6414 | { |
| 6415 | #ifndef BACKSLASH_IN_FILENAME |
| 6416 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 6417 | return 2; |
| 6418 | #endif |
| 6419 | return 1; |
| 6420 | } |
| 6421 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6425 | * Show wildchar matches in the status line. |
| 6426 | * Show at least the "match" item. |
| 6427 | * We start at item 'first_match' in the list and show all matches that fit. |
| 6428 | * |
| 6429 | * If inversion is possible we use it. Else '=' characters are used. |
| 6430 | */ |
| 6431 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6432 | win_redr_status_matches( |
| 6433 | expand_T *xp, |
| 6434 | int num_matches, |
| 6435 | char_u **matches, /* list of matches */ |
| 6436 | int match, |
| 6437 | int showtail) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6438 | { |
| 6439 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6440 | int row; |
| 6441 | char_u *buf; |
| 6442 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6443 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6444 | int fillchar; |
| 6445 | int attr; |
| 6446 | int i; |
| 6447 | int highlight = TRUE; |
| 6448 | char_u *selstart = NULL; |
| 6449 | int selstart_col = 0; |
| 6450 | char_u *selend = NULL; |
| 6451 | static int first_match = 0; |
| 6452 | int add_left = FALSE; |
| 6453 | char_u *s; |
| 6454 | #ifdef FEAT_MENU |
| 6455 | int emenu; |
| 6456 | #endif |
| 6457 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6458 | int l; |
| 6459 | #endif |
| 6460 | |
| 6461 | if (matches == NULL) /* interrupted completion? */ |
| 6462 | return; |
| 6463 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6464 | #ifdef FEAT_MBYTE |
| 6465 | if (has_mbyte) |
| 6466 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6467 | else |
| 6468 | #endif |
| 6469 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6470 | if (buf == NULL) |
| 6471 | return; |
| 6472 | |
| 6473 | if (match == -1) /* don't show match but original text */ |
| 6474 | { |
| 6475 | match = 0; |
| 6476 | highlight = FALSE; |
| 6477 | } |
| 6478 | /* count 1 for the ending ">" */ |
| 6479 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6480 | if (match == 0) |
| 6481 | first_match = 0; |
| 6482 | else if (match < first_match) |
| 6483 | { |
| 6484 | /* jumping left, as far as we can go */ |
| 6485 | first_match = match; |
| 6486 | add_left = TRUE; |
| 6487 | } |
| 6488 | else |
| 6489 | { |
| 6490 | /* check if match fits on the screen */ |
| 6491 | for (i = first_match; i < match; ++i) |
| 6492 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6493 | if (first_match > 0) |
| 6494 | clen += 2; |
| 6495 | /* jumping right, put match at the left */ |
| 6496 | if ((long)clen > Columns) |
| 6497 | { |
| 6498 | first_match = match; |
| 6499 | /* if showing the last match, we can add some on the left */ |
| 6500 | clen = 2; |
| 6501 | for (i = match; i < num_matches; ++i) |
| 6502 | { |
| 6503 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6504 | if ((long)clen >= Columns) |
| 6505 | break; |
| 6506 | } |
| 6507 | if (i == num_matches) |
| 6508 | add_left = TRUE; |
| 6509 | } |
| 6510 | } |
| 6511 | if (add_left) |
| 6512 | while (first_match > 0) |
| 6513 | { |
| 6514 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6515 | if ((long)clen >= Columns) |
| 6516 | break; |
| 6517 | --first_match; |
| 6518 | } |
| 6519 | |
| 6520 | fillchar = fillchar_status(&attr, TRUE); |
| 6521 | |
| 6522 | if (first_match == 0) |
| 6523 | { |
| 6524 | *buf = NUL; |
| 6525 | len = 0; |
| 6526 | } |
| 6527 | else |
| 6528 | { |
| 6529 | STRCPY(buf, "< "); |
| 6530 | len = 2; |
| 6531 | } |
| 6532 | clen = len; |
| 6533 | |
| 6534 | i = first_match; |
| 6535 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6536 | { |
| 6537 | if (i == match) |
| 6538 | { |
| 6539 | selstart = buf + len; |
| 6540 | selstart_col = clen; |
| 6541 | } |
| 6542 | |
| 6543 | s = L_MATCH(i); |
| 6544 | /* Check for menu separators - replace with '|' */ |
| 6545 | #ifdef FEAT_MENU |
| 6546 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6547 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6548 | if (emenu && menu_is_separator(s)) |
| 6549 | { |
| 6550 | STRCPY(buf + len, transchar('|')); |
| 6551 | l = (int)STRLEN(buf + len); |
| 6552 | len += l; |
| 6553 | clen += l; |
| 6554 | } |
| 6555 | else |
| 6556 | #endif |
| 6557 | for ( ; *s != NUL; ++s) |
| 6558 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6559 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6560 | clen += ptr2cells(s); |
| 6561 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6562 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6563 | { |
| 6564 | STRNCPY(buf + len, s, l); |
| 6565 | s += l - 1; |
| 6566 | len += l; |
| 6567 | } |
| 6568 | else |
| 6569 | #endif |
| 6570 | { |
| 6571 | STRCPY(buf + len, transchar_byte(*s)); |
| 6572 | len += (int)STRLEN(buf + len); |
| 6573 | } |
| 6574 | } |
| 6575 | if (i == match) |
| 6576 | selend = buf + len; |
| 6577 | |
| 6578 | *(buf + len++) = ' '; |
| 6579 | *(buf + len++) = ' '; |
| 6580 | clen += 2; |
| 6581 | if (++i == num_matches) |
| 6582 | break; |
| 6583 | } |
| 6584 | |
| 6585 | if (i != num_matches) |
| 6586 | { |
| 6587 | *(buf + len++) = '>'; |
| 6588 | ++clen; |
| 6589 | } |
| 6590 | |
| 6591 | buf[len] = NUL; |
| 6592 | |
| 6593 | row = cmdline_row - 1; |
| 6594 | if (row >= 0) |
| 6595 | { |
| 6596 | if (wild_menu_showing == 0) |
| 6597 | { |
| 6598 | if (msg_scrolled > 0) |
| 6599 | { |
| 6600 | /* Put the wildmenu just above the command line. If there is |
| 6601 | * no room, scroll the screen one line up. */ |
| 6602 | if (cmdline_row == Rows - 1) |
| 6603 | { |
| 6604 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6605 | ++msg_scrolled; |
| 6606 | } |
| 6607 | else |
| 6608 | { |
| 6609 | ++cmdline_row; |
| 6610 | ++row; |
| 6611 | } |
| 6612 | wild_menu_showing = WM_SCROLLED; |
| 6613 | } |
| 6614 | else |
| 6615 | { |
| 6616 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6617 | * Set 'winminheight' to zero to avoid that the window is |
| 6618 | * resized. */ |
| 6619 | if (lastwin->w_status_height == 0) |
| 6620 | { |
| 6621 | save_p_ls = p_ls; |
| 6622 | save_p_wmh = p_wmh; |
| 6623 | p_ls = 2; |
| 6624 | p_wmh = 0; |
| 6625 | last_status(FALSE); |
| 6626 | } |
| 6627 | wild_menu_showing = WM_SHOWN; |
| 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | screen_puts(buf, row, 0, attr); |
| 6632 | if (selstart != NULL && highlight) |
| 6633 | { |
| 6634 | *selend = NUL; |
| 6635 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6636 | } |
| 6637 | |
| 6638 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6639 | } |
| 6640 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6641 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6642 | win_redraw_last_status(topframe); |
| 6643 | #else |
| 6644 | lastwin->w_redr_status = TRUE; |
| 6645 | #endif |
| 6646 | vim_free(buf); |
| 6647 | } |
| 6648 | #endif |
| 6649 | |
| 6650 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6651 | /* |
| 6652 | * Redraw the status line of window wp. |
| 6653 | * |
| 6654 | * If inversion is possible we use it. Else '=' characters are used. |
| 6655 | */ |
| 6656 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6657 | win_redr_status(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6658 | { |
| 6659 | int row; |
| 6660 | char_u *p; |
| 6661 | int len; |
| 6662 | int fillchar; |
| 6663 | int attr; |
| 6664 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6665 | static int busy = FALSE; |
| 6666 | |
| 6667 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6668 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6669 | if (busy) |
| 6670 | return; |
| 6671 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6672 | |
| 6673 | wp->w_redr_status = FALSE; |
| 6674 | if (wp->w_status_height == 0) |
| 6675 | { |
| 6676 | /* no status line, can only be last window */ |
| 6677 | redraw_cmdline = TRUE; |
| 6678 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6679 | else if (!redrawing() |
| 6680 | #ifdef FEAT_INS_EXPAND |
| 6681 | /* don't update status line when popup menu is visible and may be |
| 6682 | * drawn over it */ |
| 6683 | || pum_visible() |
| 6684 | #endif |
| 6685 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6686 | { |
| 6687 | /* Don't redraw right now, do it later. */ |
| 6688 | wp->w_redr_status = TRUE; |
| 6689 | } |
| 6690 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6691 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6692 | { |
| 6693 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6694 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6695 | } |
| 6696 | #endif |
| 6697 | else |
| 6698 | { |
| 6699 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6700 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6701 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6702 | p = NameBuff; |
| 6703 | len = (int)STRLEN(p); |
| 6704 | |
| 6705 | if (wp->w_buffer->b_help |
| 6706 | #ifdef FEAT_QUICKFIX |
| 6707 | || wp->w_p_pvw |
| 6708 | #endif |
| 6709 | || bufIsChanged(wp->w_buffer) |
| 6710 | || wp->w_buffer->b_p_ro) |
| 6711 | *(p + len++) = ' '; |
| 6712 | if (wp->w_buffer->b_help) |
| 6713 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6714 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6715 | len += (int)STRLEN(p + len); |
| 6716 | } |
| 6717 | #ifdef FEAT_QUICKFIX |
| 6718 | if (wp->w_p_pvw) |
| 6719 | { |
| 6720 | STRCPY(p + len, _("[Preview]")); |
| 6721 | len += (int)STRLEN(p + len); |
| 6722 | } |
| 6723 | #endif |
| 6724 | if (bufIsChanged(wp->w_buffer)) |
| 6725 | { |
| 6726 | STRCPY(p + len, "[+]"); |
| 6727 | len += 3; |
| 6728 | } |
| 6729 | if (wp->w_buffer->b_p_ro) |
| 6730 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6731 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6732 | len += 4; |
| 6733 | } |
| 6734 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6735 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6736 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6737 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6738 | if (this_ru_col <= 1) |
| 6739 | { |
| 6740 | p = (char_u *)"<"; /* No room for file name! */ |
| 6741 | len = 1; |
| 6742 | } |
| 6743 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6744 | #ifdef FEAT_MBYTE |
| 6745 | if (has_mbyte) |
| 6746 | { |
| 6747 | int clen = 0, i; |
| 6748 | |
| 6749 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6750 | clen = mb_string2cells(p, -1); |
| 6751 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6752 | /* Find first character that will fit. |
| 6753 | * Going from start to end is much faster for DBCS. */ |
| 6754 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6755 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6756 | clen -= (*mb_ptr2cells)(p + i); |
| 6757 | len = clen; |
| 6758 | if (i > 0) |
| 6759 | { |
| 6760 | p = p + i - 1; |
| 6761 | *p = '<'; |
| 6762 | ++len; |
| 6763 | } |
| 6764 | |
| 6765 | } |
| 6766 | else |
| 6767 | #endif |
| 6768 | if (len > this_ru_col - 1) |
| 6769 | { |
| 6770 | p += len - (this_ru_col - 1); |
| 6771 | *p = '<'; |
| 6772 | len = this_ru_col - 1; |
| 6773 | } |
| 6774 | |
| 6775 | row = W_WINROW(wp) + wp->w_height; |
| 6776 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6777 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6778 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6779 | |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6780 | if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6781 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6782 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6783 | - 1 + W_WINCOL(wp)), attr); |
| 6784 | |
| 6785 | #ifdef FEAT_CMDL_INFO |
| 6786 | win_redr_ruler(wp, TRUE); |
| 6787 | #endif |
| 6788 | } |
| 6789 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6790 | /* |
| 6791 | * May need to draw the character below the vertical separator. |
| 6792 | */ |
| 6793 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6794 | { |
| 6795 | if (stl_connected(wp)) |
| 6796 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6797 | else |
| 6798 | fillchar = fillchar_vsep(&attr); |
| 6799 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6800 | attr); |
| 6801 | } |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6802 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6803 | } |
| 6804 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6805 | #ifdef FEAT_STL_OPT |
| 6806 | /* |
| 6807 | * Redraw the status line according to 'statusline' and take care of any |
| 6808 | * errors encountered. |
| 6809 | */ |
| 6810 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6811 | redraw_custom_statusline(win_T *wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6812 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6813 | static int entered = FALSE; |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6814 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6815 | |
| 6816 | /* When called recursively return. This can happen when the statusline |
| 6817 | * contains an expression that triggers a redraw. */ |
| 6818 | if (entered) |
| 6819 | return; |
| 6820 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6821 | |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6822 | did_emsg = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6823 | win_redr_custom(wp, FALSE); |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6824 | if (did_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6825 | { |
| 6826 | /* When there is an error disable the statusline, otherwise the |
| 6827 | * display is messed up with errors and a redraw triggers the problem |
| 6828 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6829 | set_string_option_direct((char_u *)"statusline", -1, |
| 6830 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6831 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6832 | } |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6833 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6834 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6835 | } |
| 6836 | #endif |
| 6837 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6838 | /* |
| 6839 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6840 | * line of the window right of it. If not, then it's a vertical separator. |
| 6841 | * Only call if (wp->w_vsep_width != 0). |
| 6842 | */ |
| 6843 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6844 | stl_connected(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6845 | { |
| 6846 | frame_T *fr; |
| 6847 | |
| 6848 | fr = wp->w_frame; |
| 6849 | while (fr->fr_parent != NULL) |
| 6850 | { |
| 6851 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6852 | { |
| 6853 | if (fr->fr_next != NULL) |
| 6854 | break; |
| 6855 | } |
| 6856 | else |
| 6857 | { |
| 6858 | if (fr->fr_next != NULL) |
| 6859 | return TRUE; |
| 6860 | } |
| 6861 | fr = fr->fr_parent; |
| 6862 | } |
| 6863 | return FALSE; |
| 6864 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6865 | |
| 6866 | #endif /* FEAT_WINDOWS */ |
| 6867 | |
| 6868 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6869 | /* |
| 6870 | * Get the value to show for the language mappings, active 'keymap'. |
| 6871 | */ |
| 6872 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6873 | get_keymap_str( |
| 6874 | win_T *wp, |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6875 | char_u *fmt, /* format string containing one %s item */ |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6876 | char_u *buf, /* buffer for the result */ |
| 6877 | int len) /* length of buffer */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6878 | { |
| 6879 | char_u *p; |
| 6880 | |
| 6881 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6882 | return FALSE; |
| 6883 | |
| 6884 | { |
| 6885 | #ifdef FEAT_EVAL |
| 6886 | buf_T *old_curbuf = curbuf; |
| 6887 | win_T *old_curwin = curwin; |
| 6888 | char_u *s; |
| 6889 | |
| 6890 | curbuf = wp->w_buffer; |
| 6891 | curwin = wp; |
| 6892 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6893 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6894 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6895 | --emsg_skip; |
| 6896 | curbuf = old_curbuf; |
| 6897 | curwin = old_curwin; |
| 6898 | if (p == NULL || *p == NUL) |
| 6899 | #endif |
| 6900 | { |
| 6901 | #ifdef FEAT_KEYMAP |
| 6902 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6903 | p = wp->w_buffer->b_p_keymap; |
| 6904 | else |
| 6905 | #endif |
| 6906 | p = (char_u *)"lang"; |
| 6907 | } |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6908 | if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6909 | buf[0] = NUL; |
| 6910 | #ifdef FEAT_EVAL |
| 6911 | vim_free(s); |
| 6912 | #endif |
| 6913 | } |
| 6914 | return buf[0] != NUL; |
| 6915 | } |
| 6916 | #endif |
| 6917 | |
| 6918 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6919 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6920 | * Redraw the status line or ruler of window "wp". |
| 6921 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6922 | */ |
| 6923 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6924 | win_redr_custom( |
| 6925 | win_T *wp, |
| 6926 | int draw_ruler) /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6927 | { |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6928 | static int entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6929 | int attr; |
| 6930 | int curattr; |
| 6931 | int row; |
| 6932 | int col = 0; |
| 6933 | int maxwidth; |
| 6934 | int width; |
| 6935 | int n; |
| 6936 | int len; |
| 6937 | int fillchar; |
| 6938 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6939 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6940 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6941 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6942 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6943 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6944 | win_T *ewp; |
| 6945 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6946 | |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6947 | /* There is a tiny chance that this gets called recursively: When |
| 6948 | * redrawing a status line triggers redrawing the ruler or tabline. |
| 6949 | * Avoid trouble by not allowing recursion. */ |
| 6950 | if (entered) |
| 6951 | return; |
| 6952 | entered = TRUE; |
| 6953 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6954 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6955 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6956 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6957 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6958 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6959 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6960 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6961 | attr = hl_attr(HLF_TPF); |
| 6962 | maxwidth = Columns; |
| 6963 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6964 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6965 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6966 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6967 | else |
| 6968 | { |
| 6969 | row = W_WINROW(wp) + wp->w_height; |
| 6970 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6971 | maxwidth = W_WIDTH(wp); |
| 6972 | |
| 6973 | if (draw_ruler) |
| 6974 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6975 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6976 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6977 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6978 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6979 | if (*++stl == '-') |
| 6980 | stl++; |
| 6981 | if (atoi((char *)stl)) |
| 6982 | while (VIM_ISDIGIT(*stl)) |
| 6983 | stl++; |
| 6984 | if (*stl++ != '(') |
| 6985 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6986 | } |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6987 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6988 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6989 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6990 | col = (W_WIDTH(wp) + 1) / 2; |
| 6991 | #else |
| 6992 | col = ru_col; |
| 6993 | if (col > (Columns + 1) / 2) |
| 6994 | col = (Columns + 1) / 2; |
| 6995 | #endif |
| 6996 | maxwidth = W_WIDTH(wp) - col; |
| 6997 | #ifdef FEAT_WINDOWS |
| 6998 | if (!wp->w_status_height) |
| 6999 | #endif |
| 7000 | { |
| 7001 | row = Rows - 1; |
| 7002 | --maxwidth; /* writing in last column may cause scrolling */ |
| 7003 | fillchar = ' '; |
| 7004 | attr = 0; |
| 7005 | } |
| 7006 | |
| 7007 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7008 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7009 | # endif |
| 7010 | } |
| 7011 | else |
| 7012 | { |
| 7013 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7014 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7015 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7016 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7017 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7018 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 7019 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7020 | # endif |
| 7021 | } |
| 7022 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 7023 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7024 | col += W_WINCOL(wp); |
| 7025 | #endif |
| 7026 | } |
| 7027 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7028 | if (maxwidth <= 0) |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7029 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7030 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7031 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 7032 | * the cursor away and back. */ |
| 7033 | ewp = wp == NULL ? curwin : wp; |
| 7034 | p_crb_save = ewp->w_p_crb; |
| 7035 | ewp->w_p_crb = FALSE; |
| 7036 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7037 | /* Make a copy, because the statusline may include a function call that |
| 7038 | * might change the option value and free the memory. */ |
| 7039 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7040 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7041 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7042 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7043 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7044 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7045 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 7046 | /* Make all characters printable. */ |
| 7047 | p = transstr(buf); |
| 7048 | if (p != NULL) |
| 7049 | { |
| 7050 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 7051 | vim_free(p); |
| 7052 | } |
| 7053 | |
| 7054 | /* fill up with "fillchar" */ |
| 7055 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 7056 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7057 | { |
| 7058 | #ifdef FEAT_MBYTE |
| 7059 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 7060 | #else |
| 7061 | buf[len++] = fillchar; |
| 7062 | #endif |
| 7063 | ++width; |
| 7064 | } |
| 7065 | buf[len] = NUL; |
| 7066 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7067 | /* |
| 7068 | * Draw each snippet with the specified highlighting. |
| 7069 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7070 | curattr = attr; |
| 7071 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7072 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7073 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7074 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7075 | screen_puts_len(p, len, row, col, curattr); |
| 7076 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7077 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7078 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7079 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7080 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7081 | else if (hltab[n].userhl < 0) |
| 7082 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7083 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 7084 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7085 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7086 | #endif |
| 7087 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7088 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7089 | } |
| 7090 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7091 | |
| 7092 | if (wp == NULL) |
| 7093 | { |
| 7094 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 7095 | col = 0; |
| 7096 | len = 0; |
| 7097 | p = buf; |
| 7098 | fillchar = 0; |
| 7099 | for (n = 0; tabtab[n].start != NULL; n++) |
| 7100 | { |
| 7101 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 7102 | while (col < len) |
| 7103 | TabPageIdxs[col++] = fillchar; |
| 7104 | p = tabtab[n].start; |
| 7105 | fillchar = tabtab[n].userhl; |
| 7106 | } |
| 7107 | while (col < Columns) |
| 7108 | TabPageIdxs[col++] = fillchar; |
| 7109 | } |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7110 | |
| 7111 | theend: |
| 7112 | entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7113 | } |
| 7114 | |
| 7115 | #endif /* FEAT_STL_OPT */ |
| 7116 | |
| 7117 | /* |
| 7118 | * Output a single character directly to the screen and update ScreenLines. |
| 7119 | */ |
| 7120 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7121 | screen_putchar(int c, int row, int col, int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7122 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7123 | char_u buf[MB_MAXBYTES + 1]; |
| 7124 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7125 | #ifdef FEAT_MBYTE |
| 7126 | if (has_mbyte) |
| 7127 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 7128 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7129 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7130 | { |
| 7131 | buf[0] = c; |
| 7132 | buf[1] = NUL; |
| 7133 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7134 | screen_puts(buf, row, col, attr); |
| 7135 | } |
| 7136 | |
| 7137 | /* |
| 7138 | * Get a single character directly from ScreenLines into "bytes[]". |
| 7139 | * Also return its attribute in *attrp; |
| 7140 | */ |
| 7141 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7142 | screen_getbytes(int row, int col, char_u *bytes, int *attrp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7143 | { |
| 7144 | unsigned off; |
| 7145 | |
| 7146 | /* safety check */ |
| 7147 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 7148 | { |
| 7149 | off = LineOffset[row] + col; |
| 7150 | *attrp = ScreenAttrs[off]; |
| 7151 | bytes[0] = ScreenLines[off]; |
| 7152 | bytes[1] = NUL; |
| 7153 | |
| 7154 | #ifdef FEAT_MBYTE |
| 7155 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7156 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 7157 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7158 | { |
| 7159 | bytes[0] = ScreenLines[off]; |
| 7160 | bytes[1] = ScreenLines2[off]; |
| 7161 | bytes[2] = NUL; |
| 7162 | } |
| 7163 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 7164 | { |
| 7165 | bytes[1] = ScreenLines[off + 1]; |
| 7166 | bytes[2] = NUL; |
| 7167 | } |
| 7168 | #endif |
| 7169 | } |
| 7170 | } |
| 7171 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7172 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 7173 | static int screen_comp_differs(int, int*); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7174 | |
| 7175 | /* |
| 7176 | * Return TRUE if composing characters for screen posn "off" differs from |
| 7177 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7178 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7179 | */ |
| 7180 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7181 | screen_comp_differs(int off, int *u8cc) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7182 | { |
| 7183 | int i; |
| 7184 | |
| 7185 | for (i = 0; i < Screen_mco; ++i) |
| 7186 | { |
| 7187 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 7188 | return TRUE; |
| 7189 | if (u8cc[i] == 0) |
| 7190 | break; |
| 7191 | } |
| 7192 | return FALSE; |
| 7193 | } |
| 7194 | #endif |
| 7195 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7196 | /* |
| 7197 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 7198 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 7199 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 7200 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 7201 | */ |
| 7202 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7203 | screen_puts( |
| 7204 | char_u *text, |
| 7205 | int row, |
| 7206 | int col, |
| 7207 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7208 | { |
| 7209 | screen_puts_len(text, -1, row, col, attr); |
| 7210 | } |
| 7211 | |
| 7212 | /* |
| 7213 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 7214 | * a NUL. |
| 7215 | */ |
| 7216 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7217 | screen_puts_len( |
| 7218 | char_u *text, |
| 7219 | int textlen, |
| 7220 | int row, |
| 7221 | int col, |
| 7222 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7223 | { |
| 7224 | unsigned off; |
| 7225 | char_u *ptr = text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7226 | int len = textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7227 | int c; |
| 7228 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7229 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7230 | int mbyte_blen = 1; |
| 7231 | int mbyte_cells = 1; |
| 7232 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7233 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7234 | int clear_next_cell = FALSE; |
| 7235 | # ifdef FEAT_ARABIC |
| 7236 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7237 | int pc, nc, nc1; |
| 7238 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7239 | # endif |
| 7240 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7241 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7242 | int force_redraw_this; |
| 7243 | int force_redraw_next = FALSE; |
| 7244 | #endif |
| 7245 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7246 | |
| 7247 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 7248 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7249 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7250 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7251 | #ifdef FEAT_MBYTE |
| 7252 | /* When drawing over the right halve of a double-wide char clear out the |
| 7253 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7254 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7255 | # ifdef FEAT_GUI |
| 7256 | && !gui.in_use |
| 7257 | # endif |
| 7258 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7259 | { |
| 7260 | ScreenLines[off - 1] = ' '; |
| 7261 | ScreenAttrs[off - 1] = 0; |
| 7262 | if (enc_utf8) |
| 7263 | { |
| 7264 | ScreenLinesUC[off - 1] = 0; |
| 7265 | ScreenLinesC[0][off - 1] = 0; |
| 7266 | } |
| 7267 | /* redraw the previous cell, make it empty */ |
| 7268 | screen_char(off - 1, row, col - 1); |
| 7269 | /* force the cell at "col" to be redrawn */ |
| 7270 | force_redraw_next = TRUE; |
| 7271 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7272 | #endif |
| 7273 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7274 | #ifdef FEAT_MBYTE |
| 7275 | max_off = LineOffset[row] + screen_Columns; |
| 7276 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 7277 | while (col < screen_Columns |
| 7278 | && (len < 0 || (int)(ptr - text) < len) |
| 7279 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7280 | { |
| 7281 | c = *ptr; |
| 7282 | #ifdef FEAT_MBYTE |
| 7283 | /* check if this is the first byte of a multibyte */ |
| 7284 | if (has_mbyte) |
| 7285 | { |
| 7286 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7287 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7289 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7290 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7291 | mbyte_cells = 1; |
| 7292 | else if (enc_dbcs != 0) |
| 7293 | mbyte_cells = mbyte_blen; |
| 7294 | else /* enc_utf8 */ |
| 7295 | { |
| 7296 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7297 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7298 | (int)((text + len) - ptr)); |
| 7299 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7300 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7301 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7302 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7303 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 7304 | if (u8c >= 0x10000) |
| 7305 | { |
| 7306 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 7307 | if (attr == 0) |
| 7308 | attr = hl_attr(HLF_8); |
| 7309 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7310 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7311 | # ifdef FEAT_ARABIC |
| 7312 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 7313 | { |
| 7314 | /* Do Arabic shaping. */ |
| 7315 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 7316 | { |
| 7317 | /* Past end of string to be displayed. */ |
| 7318 | nc = NUL; |
| 7319 | nc1 = NUL; |
| 7320 | } |
| 7321 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7322 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 7323 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 7324 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7325 | nc1 = pcc[0]; |
| 7326 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7327 | pc = prev_c; |
| 7328 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7329 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7330 | } |
| 7331 | else |
| 7332 | prev_c = u8c; |
| 7333 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 7334 | if (col + mbyte_cells > screen_Columns) |
| 7335 | { |
| 7336 | /* Only 1 cell left, but character requires 2 cells: |
| 7337 | * display a '>' in the last column to avoid wrapping. */ |
| 7338 | c = '>'; |
| 7339 | mbyte_cells = 1; |
| 7340 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7341 | } |
| 7342 | } |
| 7343 | #endif |
| 7344 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7345 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7346 | force_redraw_this = force_redraw_next; |
| 7347 | force_redraw_next = FALSE; |
| 7348 | #endif |
| 7349 | |
| 7350 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7351 | #ifdef FEAT_MBYTE |
| 7352 | || (mbyte_cells == 2 |
| 7353 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 7354 | || (enc_dbcs == DBCS_JPNU |
| 7355 | && c == 0x8e |
| 7356 | && ScreenLines2[off] != ptr[1]) |
| 7357 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7358 | && (ScreenLinesUC[off] != |
| 7359 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 7360 | || (ScreenLinesUC[off] != 0 |
| 7361 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7362 | #endif |
| 7363 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7364 | || exmode_active; |
| 7365 | |
| 7366 | if (need_redraw |
| 7367 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7368 | || force_redraw_this |
| 7369 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7370 | ) |
| 7371 | { |
| 7372 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7373 | /* The bold trick makes a single row of pixels appear in the next |
| 7374 | * character. When a bold character is removed, the next |
| 7375 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7376 | * and for some xterms. */ |
| 7377 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7378 | # ifdef FEAT_GUI |
| 7379 | gui.in_use |
| 7380 | # endif |
| 7381 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7382 | || |
| 7383 | # endif |
| 7384 | # ifdef UNIX |
| 7385 | term_is_xterm |
| 7386 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7387 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7388 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7389 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7390 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7391 | if (n > HL_ALL) |
| 7392 | n = syn_attr2attr(n); |
| 7393 | if (n & HL_BOLD) |
| 7394 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7395 | } |
| 7396 | #endif |
| 7397 | #ifdef FEAT_MBYTE |
| 7398 | /* When at the end of the text and overwriting a two-cell |
| 7399 | * character with a one-cell character, need to clear the next |
| 7400 | * cell. Also when overwriting the left halve of a two-cell char |
| 7401 | * with the right halve of a two-cell char. Do this only once |
| 7402 | * (mb_off2cells() may return 2 on the right halve). */ |
| 7403 | if (clear_next_cell) |
| 7404 | clear_next_cell = FALSE; |
| 7405 | else if (has_mbyte |
| 7406 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 7407 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7408 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7409 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7410 | && (*mb_off2cells)(off, max_off) == 1 |
| 7411 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7412 | clear_next_cell = TRUE; |
| 7413 | |
| 7414 | /* Make sure we never leave a second byte of a double-byte behind, |
| 7415 | * it confuses mb_off2cells(). */ |
| 7416 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7417 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7418 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7419 | && (*mb_off2cells)(off, max_off) == 1 |
| 7420 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7421 | ScreenLines[off + mbyte_blen] = 0; |
| 7422 | #endif |
| 7423 | ScreenLines[off] = c; |
| 7424 | ScreenAttrs[off] = attr; |
| 7425 | #ifdef FEAT_MBYTE |
| 7426 | if (enc_utf8) |
| 7427 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7428 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7429 | ScreenLinesUC[off] = 0; |
| 7430 | else |
| 7431 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7432 | int i; |
| 7433 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7434 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7435 | for (i = 0; i < Screen_mco; ++i) |
| 7436 | { |
| 7437 | ScreenLinesC[i][off] = u8cc[i]; |
| 7438 | if (u8cc[i] == 0) |
| 7439 | break; |
| 7440 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7441 | } |
| 7442 | if (mbyte_cells == 2) |
| 7443 | { |
| 7444 | ScreenLines[off + 1] = 0; |
| 7445 | ScreenAttrs[off + 1] = attr; |
| 7446 | } |
| 7447 | screen_char(off, row, col); |
| 7448 | } |
| 7449 | else if (mbyte_cells == 2) |
| 7450 | { |
| 7451 | ScreenLines[off + 1] = ptr[1]; |
| 7452 | ScreenAttrs[off + 1] = attr; |
| 7453 | screen_char_2(off, row, col); |
| 7454 | } |
| 7455 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7456 | { |
| 7457 | ScreenLines2[off] = ptr[1]; |
| 7458 | screen_char(off, row, col); |
| 7459 | } |
| 7460 | else |
| 7461 | #endif |
| 7462 | screen_char(off, row, col); |
| 7463 | } |
| 7464 | #ifdef FEAT_MBYTE |
| 7465 | if (has_mbyte) |
| 7466 | { |
| 7467 | off += mbyte_cells; |
| 7468 | col += mbyte_cells; |
| 7469 | ptr += mbyte_blen; |
| 7470 | if (clear_next_cell) |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7471 | { |
| 7472 | /* This only happens at the end, display one space next. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7473 | ptr = (char_u *)" "; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7474 | len = -1; |
| 7475 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7476 | } |
| 7477 | else |
| 7478 | #endif |
| 7479 | { |
| 7480 | ++off; |
| 7481 | ++col; |
| 7482 | ++ptr; |
| 7483 | } |
| 7484 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7485 | |
| 7486 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7487 | /* If we detected the next character needs to be redrawn, but the text |
| 7488 | * doesn't extend up to there, update the character here. */ |
| 7489 | if (force_redraw_next && col < screen_Columns) |
| 7490 | { |
| 7491 | # ifdef FEAT_MBYTE |
| 7492 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7493 | screen_char_2(off, row, col); |
| 7494 | else |
| 7495 | # endif |
| 7496 | screen_char(off, row, col); |
| 7497 | } |
| 7498 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7499 | } |
| 7500 | |
| 7501 | #ifdef FEAT_SEARCH_EXTRA |
| 7502 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7503 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7504 | */ |
| 7505 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7506 | start_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7507 | { |
| 7508 | if (p_hls && !no_hlsearch) |
| 7509 | { |
| 7510 | last_pat_prog(&search_hl.rm); |
| 7511 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7512 | # ifdef FEAT_RELTIME |
| 7513 | /* Set the time limit to 'redrawtime'. */ |
| 7514 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7515 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7516 | } |
| 7517 | } |
| 7518 | |
| 7519 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7520 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7521 | */ |
| 7522 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7523 | end_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7524 | { |
| 7525 | if (search_hl.rm.regprog != NULL) |
| 7526 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7527 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7528 | search_hl.rm.regprog = NULL; |
| 7529 | } |
| 7530 | } |
| 7531 | |
| 7532 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7533 | * Init for calling prepare_search_hl(). |
| 7534 | */ |
| 7535 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7536 | init_search_hl(win_T *wp) |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7537 | { |
| 7538 | matchitem_T *cur; |
| 7539 | |
| 7540 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7541 | * match */ |
| 7542 | cur = wp->w_match_head; |
| 7543 | while (cur != NULL) |
| 7544 | { |
| 7545 | cur->hl.rm = cur->match; |
| 7546 | if (cur->hlg_id == 0) |
| 7547 | cur->hl.attr = 0; |
| 7548 | else |
| 7549 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7550 | cur->hl.buf = wp->w_buffer; |
| 7551 | cur->hl.lnum = 0; |
| 7552 | cur->hl.first_lnum = 0; |
| 7553 | # ifdef FEAT_RELTIME |
| 7554 | /* Set the time limit to 'redrawtime'. */ |
| 7555 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7556 | # endif |
| 7557 | cur = cur->next; |
| 7558 | } |
| 7559 | search_hl.buf = wp->w_buffer; |
| 7560 | search_hl.lnum = 0; |
| 7561 | search_hl.first_lnum = 0; |
| 7562 | /* time limit is set at the toplevel, for all windows */ |
| 7563 | } |
| 7564 | |
| 7565 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7566 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7567 | */ |
| 7568 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7569 | prepare_search_hl(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7570 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7571 | matchitem_T *cur; /* points to the match list */ |
| 7572 | match_T *shl; /* points to search_hl or a match */ |
| 7573 | int shl_flag; /* flag to indicate whether search_hl |
| 7574 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7575 | int pos_inprogress; /* marks that position match search is |
| 7576 | in progress */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7577 | int n; |
| 7578 | |
| 7579 | /* |
| 7580 | * When using a multi-line pattern, start searching at the top |
| 7581 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7582 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7583 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7584 | cur = wp->w_match_head; |
| 7585 | shl_flag = FALSE; |
| 7586 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7587 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7588 | if (shl_flag == FALSE) |
| 7589 | { |
| 7590 | shl = &search_hl; |
| 7591 | shl_flag = TRUE; |
| 7592 | } |
| 7593 | else |
| 7594 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7595 | if (shl->rm.regprog != NULL |
| 7596 | && shl->lnum == 0 |
| 7597 | && re_multiline(shl->rm.regprog)) |
| 7598 | { |
| 7599 | if (shl->first_lnum == 0) |
| 7600 | { |
| 7601 | # ifdef FEAT_FOLDING |
| 7602 | for (shl->first_lnum = lnum; |
| 7603 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7604 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7605 | NULL, NULL, TRUE, NULL)) |
| 7606 | break; |
| 7607 | # else |
| 7608 | shl->first_lnum = wp->w_topline; |
| 7609 | # endif |
| 7610 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7611 | if (cur != NULL) |
| 7612 | cur->pos.cur = 0; |
| 7613 | pos_inprogress = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7614 | n = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7615 | while (shl->first_lnum < lnum && (shl->rm.regprog != NULL |
| 7616 | || (cur != NULL && pos_inprogress))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7617 | { |
Bram Moolenaar | e17bdff | 2016-08-27 18:34:29 +0200 | [diff] [blame] | 7618 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, |
| 7619 | shl == &search_hl ? NULL : cur); |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7620 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
| 7621 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7622 | if (shl->lnum != 0) |
| 7623 | { |
| 7624 | shl->first_lnum = shl->lnum |
| 7625 | + shl->rm.endpos[0].lnum |
| 7626 | - shl->rm.startpos[0].lnum; |
| 7627 | n = shl->rm.endpos[0].col; |
| 7628 | } |
| 7629 | else |
| 7630 | { |
| 7631 | ++shl->first_lnum; |
| 7632 | n = 0; |
| 7633 | } |
| 7634 | } |
| 7635 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7636 | if (shl != &search_hl && cur != NULL) |
| 7637 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7638 | } |
| 7639 | } |
| 7640 | |
| 7641 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7642 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7643 | * Uses shl->buf. |
| 7644 | * Sets shl->lnum and shl->rm contents. |
| 7645 | * Note: Assumes a previous match is always before "lnum", unless |
| 7646 | * shl->lnum is zero. |
| 7647 | * Careful: Any pointers for buffer lines will become invalid. |
| 7648 | */ |
| 7649 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7650 | next_search_hl( |
| 7651 | win_T *win, |
| 7652 | match_T *shl, /* points to search_hl or a match */ |
| 7653 | linenr_T lnum, |
| 7654 | colnr_T mincol, /* minimal column for a match */ |
| 7655 | matchitem_T *cur) /* to retrieve match positions if any */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7656 | { |
| 7657 | linenr_T l; |
| 7658 | colnr_T matchcol; |
| 7659 | long nmatched; |
| 7660 | |
| 7661 | if (shl->lnum != 0) |
| 7662 | { |
| 7663 | /* Check for three situations: |
| 7664 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7665 | * 2. If the previous match includes "mincol", use it. |
| 7666 | * 3. Continue after the previous match. |
| 7667 | */ |
| 7668 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7669 | if (lnum > l) |
| 7670 | shl->lnum = 0; |
| 7671 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7672 | return; |
| 7673 | } |
| 7674 | |
| 7675 | /* |
| 7676 | * Repeat searching for a match until one is found that includes "mincol" |
| 7677 | * or none is found in this line. |
| 7678 | */ |
| 7679 | called_emsg = FALSE; |
| 7680 | for (;;) |
| 7681 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7682 | #ifdef FEAT_RELTIME |
| 7683 | /* Stop searching after passing the time limit. */ |
| 7684 | if (profile_passed_limit(&(shl->tm))) |
| 7685 | { |
| 7686 | shl->lnum = 0; /* no match found in time */ |
| 7687 | break; |
| 7688 | } |
| 7689 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7690 | /* Three situations: |
| 7691 | * 1. No useful previous match: search from start of line. |
| 7692 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7693 | * Break the loop if this is beyond the end of the line. |
| 7694 | * 3. Vi compatible searching: continue at end of previous match. |
| 7695 | */ |
| 7696 | if (shl->lnum == 0) |
| 7697 | matchcol = 0; |
| 7698 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7699 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7700 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7701 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7702 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7703 | |
| 7704 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7705 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7706 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7707 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7708 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7709 | shl->lnum = 0; |
| 7710 | break; |
| 7711 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7712 | #ifdef FEAT_MBYTE |
| 7713 | if (has_mbyte) |
| 7714 | matchcol += mb_ptr2len(ml); |
| 7715 | else |
| 7716 | #endif |
| 7717 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7718 | } |
| 7719 | else |
| 7720 | matchcol = shl->rm.endpos[0].col; |
| 7721 | |
| 7722 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7723 | if (shl->rm.regprog != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7724 | { |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7725 | /* Remember whether shl->rm is using a copy of the regprog in |
| 7726 | * cur->match. */ |
| 7727 | int regprog_is_copy = (shl != &search_hl && cur != NULL |
| 7728 | && shl == &cur->hl |
| 7729 | && cur->match.regprog == cur->hl.rm.regprog); |
| 7730 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7731 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, |
| 7732 | matchcol, |
| 7733 | #ifdef FEAT_RELTIME |
| 7734 | &(shl->tm) |
| 7735 | #else |
| 7736 | NULL |
| 7737 | #endif |
| 7738 | ); |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7739 | /* Copy the regprog, in case it got freed and recompiled. */ |
| 7740 | if (regprog_is_copy) |
| 7741 | cur->match.regprog = cur->hl.rm.regprog; |
| 7742 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7743 | if (called_emsg || got_int) |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7744 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7745 | /* Error while handling regexp: stop using this regexp. */ |
| 7746 | if (shl == &search_hl) |
| 7747 | { |
| 7748 | /* don't free regprog in the match list, it's a copy */ |
| 7749 | vim_regfree(shl->rm.regprog); |
| 7750 | SET_NO_HLSEARCH(TRUE); |
| 7751 | } |
| 7752 | shl->rm.regprog = NULL; |
| 7753 | shl->lnum = 0; |
| 7754 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" |
| 7755 | message */ |
| 7756 | break; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7757 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7758 | } |
| 7759 | else if (cur != NULL) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7760 | nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol); |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7761 | else |
| 7762 | nmatched = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7763 | if (nmatched == 0) |
| 7764 | { |
| 7765 | shl->lnum = 0; /* no match found */ |
| 7766 | break; |
| 7767 | } |
| 7768 | if (shl->rm.startpos[0].lnum > 0 |
| 7769 | || shl->rm.startpos[0].col >= mincol |
| 7770 | || nmatched > 1 |
| 7771 | || shl->rm.endpos[0].col > mincol) |
| 7772 | { |
| 7773 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7774 | break; /* useful match found */ |
| 7775 | } |
| 7776 | } |
| 7777 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7778 | |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7779 | /* |
| 7780 | * If there is a match fill "shl" and return one. |
| 7781 | * Return zero otherwise. |
| 7782 | */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7783 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7784 | next_search_hl_pos( |
| 7785 | match_T *shl, /* points to a match */ |
| 7786 | linenr_T lnum, |
| 7787 | posmatch_T *posmatch, /* match positions */ |
| 7788 | colnr_T mincol) /* minimal column for a match */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7789 | { |
| 7790 | int i; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7791 | int found = -1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7792 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7793 | for (i = posmatch->cur; i < MAXPOSMATCH; i++) |
| 7794 | { |
Bram Moolenaar | a6c27ee | 2016-10-15 14:56:30 +0200 | [diff] [blame] | 7795 | llpos_T *pos = &posmatch->pos[i]; |
| 7796 | |
| 7797 | if (pos->lnum == 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7798 | break; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7799 | if (pos->len == 0 && pos->col < mincol) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7800 | continue; |
Bram Moolenaar | a6c27ee | 2016-10-15 14:56:30 +0200 | [diff] [blame] | 7801 | if (pos->lnum == lnum) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7802 | { |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7803 | if (found >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7804 | { |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7805 | /* if this match comes before the one at "found" then swap |
| 7806 | * them */ |
| 7807 | if (pos->col < posmatch->pos[found].col) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7808 | { |
Bram Moolenaar | a6c27ee | 2016-10-15 14:56:30 +0200 | [diff] [blame] | 7809 | llpos_T tmp = *pos; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7810 | |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7811 | *pos = posmatch->pos[found]; |
| 7812 | posmatch->pos[found] = tmp; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7813 | } |
| 7814 | } |
| 7815 | else |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7816 | found = i; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7817 | } |
| 7818 | } |
| 7819 | posmatch->cur = 0; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7820 | if (found >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7821 | { |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7822 | colnr_T start = posmatch->pos[found].col == 0 |
| 7823 | ? 0 : posmatch->pos[found].col - 1; |
| 7824 | colnr_T end = posmatch->pos[found].col == 0 |
| 7825 | ? MAXCOL : start + posmatch->pos[found].len; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7826 | |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7827 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7828 | shl->rm.startpos[0].lnum = 0; |
| 7829 | shl->rm.startpos[0].col = start; |
| 7830 | shl->rm.endpos[0].lnum = 0; |
| 7831 | shl->rm.endpos[0].col = end; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 7832 | shl->is_addpos = TRUE; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7833 | posmatch->cur = found + 1; |
| 7834 | return 1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7835 | } |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7836 | return 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7837 | } |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 7838 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7839 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7840 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7841 | screen_start_highlight(int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7842 | { |
| 7843 | attrentry_T *aep = NULL; |
| 7844 | |
| 7845 | screen_attr = attr; |
| 7846 | if (full_screen |
| 7847 | #ifdef WIN3264 |
| 7848 | && termcap_active |
| 7849 | #endif |
| 7850 | ) |
| 7851 | { |
| 7852 | #ifdef FEAT_GUI |
| 7853 | if (gui.in_use) |
| 7854 | { |
| 7855 | char buf[20]; |
| 7856 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7857 | /* The GUI handles this internally. */ |
| 7858 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7859 | OUT_STR(buf); |
| 7860 | } |
| 7861 | else |
| 7862 | #endif |
| 7863 | { |
| 7864 | if (attr > HL_ALL) /* special HL attr. */ |
| 7865 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7866 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7867 | aep = syn_cterm_attr2entry(attr); |
| 7868 | else |
| 7869 | aep = syn_term_attr2entry(attr); |
| 7870 | if (aep == NULL) /* did ":syntax clear" */ |
| 7871 | attr = 0; |
| 7872 | else |
| 7873 | attr = aep->ae_attr; |
| 7874 | } |
| 7875 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7876 | out_str(T_MD); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7877 | else if (aep != NULL && cterm_normal_fg_bold && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7878 | #ifdef FEAT_TERMGUICOLORS |
| 7879 | (p_tgc ? |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7880 | (aep->ae_u.cterm.fg_rgb != INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7881 | #endif |
| 7882 | (t_colors > 1 && aep->ae_u.cterm.fg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7883 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7884 | ) |
| 7885 | #endif |
| 7886 | ) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7887 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7888 | * has a FG color defined, clear BOLD. */ |
| 7889 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7890 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7891 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7892 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7893 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7894 | out_str(T_US); |
| 7895 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7896 | out_str(T_CZH); |
| 7897 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7898 | out_str(T_MR); |
| 7899 | |
| 7900 | /* |
| 7901 | * Output the color or start string after bold etc., in case the |
| 7902 | * bold etc. override the color setting. |
| 7903 | */ |
| 7904 | if (aep != NULL) |
| 7905 | { |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7906 | #ifdef FEAT_TERMGUICOLORS |
| 7907 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7908 | { |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7909 | if (aep->ae_u.cterm.fg_rgb != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7910 | term_fg_rgb_color(aep->ae_u.cterm.fg_rgb); |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7911 | if (aep->ae_u.cterm.bg_rgb != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7912 | term_bg_rgb_color(aep->ae_u.cterm.bg_rgb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7913 | } |
| 7914 | else |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7915 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7916 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7917 | if (t_colors > 1) |
| 7918 | { |
| 7919 | if (aep->ae_u.cterm.fg_color) |
| 7920 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7921 | if (aep->ae_u.cterm.bg_color) |
| 7922 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7923 | } |
| 7924 | else |
| 7925 | { |
| 7926 | if (aep->ae_u.term.start != NULL) |
| 7927 | out_str(aep->ae_u.term.start); |
| 7928 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7929 | } |
| 7930 | } |
| 7931 | } |
| 7932 | } |
| 7933 | } |
| 7934 | |
| 7935 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7936 | screen_stop_highlight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7937 | { |
| 7938 | int do_ME = FALSE; /* output T_ME code */ |
| 7939 | |
| 7940 | if (screen_attr != 0 |
| 7941 | #ifdef WIN3264 |
| 7942 | && termcap_active |
| 7943 | #endif |
| 7944 | ) |
| 7945 | { |
| 7946 | #ifdef FEAT_GUI |
| 7947 | if (gui.in_use) |
| 7948 | { |
| 7949 | char buf[20]; |
| 7950 | |
| 7951 | /* use internal GUI code */ |
| 7952 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7953 | OUT_STR(buf); |
| 7954 | } |
| 7955 | else |
| 7956 | #endif |
| 7957 | { |
| 7958 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7959 | { |
| 7960 | attrentry_T *aep; |
| 7961 | |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7962 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7963 | { |
| 7964 | /* |
| 7965 | * Assume that t_me restores the original colors! |
| 7966 | */ |
| 7967 | aep = syn_cterm_attr2entry(screen_attr); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7968 | if (aep != NULL && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7969 | #ifdef FEAT_TERMGUICOLORS |
| 7970 | (p_tgc ? |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7971 | (aep->ae_u.cterm.fg_rgb != INVALCOLOR |
| 7972 | || aep->ae_u.cterm.bg_rgb != INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7973 | #endif |
| 7974 | (aep->ae_u.cterm.fg_color || aep->ae_u.cterm.bg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7975 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7976 | ) |
| 7977 | #endif |
| 7978 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7979 | do_ME = TRUE; |
| 7980 | } |
| 7981 | else |
| 7982 | { |
| 7983 | aep = syn_term_attr2entry(screen_attr); |
| 7984 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7985 | { |
| 7986 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7987 | do_ME = TRUE; |
| 7988 | else |
| 7989 | out_str(aep->ae_u.term.stop); |
| 7990 | } |
| 7991 | } |
| 7992 | if (aep == NULL) /* did ":syntax clear" */ |
| 7993 | screen_attr = 0; |
| 7994 | else |
| 7995 | screen_attr = aep->ae_attr; |
| 7996 | } |
| 7997 | |
| 7998 | /* |
| 7999 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 8000 | * same sequence several times. |
| 8001 | */ |
| 8002 | if (screen_attr & HL_STANDOUT) |
| 8003 | { |
| 8004 | if (STRCMP(T_SE, T_ME) == 0) |
| 8005 | do_ME = TRUE; |
| 8006 | else |
| 8007 | out_str(T_SE); |
| 8008 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8009 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8010 | { |
| 8011 | if (STRCMP(T_UE, T_ME) == 0) |
| 8012 | do_ME = TRUE; |
| 8013 | else |
| 8014 | out_str(T_UE); |
| 8015 | } |
| 8016 | if (screen_attr & HL_ITALIC) |
| 8017 | { |
| 8018 | if (STRCMP(T_CZR, T_ME) == 0) |
| 8019 | do_ME = TRUE; |
| 8020 | else |
| 8021 | out_str(T_CZR); |
| 8022 | } |
| 8023 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 8024 | out_str(T_ME); |
| 8025 | |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8026 | #ifdef FEAT_TERMGUICOLORS |
| 8027 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8028 | { |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8029 | if (cterm_normal_fg_gui_color != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8030 | term_fg_rgb_color(cterm_normal_fg_gui_color); |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8031 | if (cterm_normal_bg_gui_color != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8032 | term_bg_rgb_color(cterm_normal_bg_gui_color); |
| 8033 | } |
| 8034 | else |
| 8035 | #endif |
| 8036 | { |
| 8037 | if (t_colors > 1) |
| 8038 | { |
| 8039 | /* set Normal cterm colors */ |
| 8040 | if (cterm_normal_fg_color != 0) |
| 8041 | term_fg_color(cterm_normal_fg_color - 1); |
| 8042 | if (cterm_normal_bg_color != 0) |
| 8043 | term_bg_color(cterm_normal_bg_color - 1); |
| 8044 | if (cterm_normal_fg_bold) |
| 8045 | out_str(T_MD); |
| 8046 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8047 | } |
| 8048 | } |
| 8049 | } |
| 8050 | screen_attr = 0; |
| 8051 | } |
| 8052 | |
| 8053 | /* |
| 8054 | * Reset the colors for a cterm. Used when leaving Vim. |
| 8055 | * The machine specific code may override this again. |
| 8056 | */ |
| 8057 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8058 | reset_cterm_colors(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8059 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8060 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8061 | { |
| 8062 | /* set Normal cterm colors */ |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8063 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8064 | if (p_tgc ? (cterm_normal_fg_gui_color != INVALCOLOR |
| 8065 | || cterm_normal_bg_gui_color != INVALCOLOR) |
| 8066 | : (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8067 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8068 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8069 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8070 | { |
| 8071 | out_str(T_OP); |
| 8072 | screen_attr = -1; |
| 8073 | } |
| 8074 | if (cterm_normal_fg_bold) |
| 8075 | { |
| 8076 | out_str(T_ME); |
| 8077 | screen_attr = -1; |
| 8078 | } |
| 8079 | } |
| 8080 | } |
| 8081 | |
| 8082 | /* |
| 8083 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 8084 | * using the attributes from ScreenAttrs["off"]. |
| 8085 | */ |
| 8086 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8087 | screen_char(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8088 | { |
| 8089 | int attr; |
| 8090 | |
| 8091 | /* Check for illegal values, just in case (could happen just after |
| 8092 | * resizing). */ |
| 8093 | if (row >= screen_Rows || col >= screen_Columns) |
| 8094 | return; |
| 8095 | |
Bram Moolenaar | 494838a | 2015-02-10 19:20:37 +0100 | [diff] [blame] | 8096 | /* Outputting a character in the last cell on the screen may scroll the |
| 8097 | * screen up. Only do it when the "xn" termcap property is set, otherwise |
| 8098 | * mark the character invalid (update it when scrolled up). */ |
| 8099 | if (*T_XN == NUL |
| 8100 | && row == screen_Rows - 1 && col == screen_Columns - 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8101 | #ifdef FEAT_RIGHTLEFT |
| 8102 | /* account for first command-line character in rightleft mode */ |
| 8103 | && !cmdmsg_rl |
| 8104 | #endif |
| 8105 | ) |
| 8106 | { |
| 8107 | ScreenAttrs[off] = (sattr_T)-1; |
| 8108 | return; |
| 8109 | } |
| 8110 | |
| 8111 | /* |
| 8112 | * Stop highlighting first, so it's easier to move the cursor. |
| 8113 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8114 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8115 | if (screen_char_attr != 0) |
| 8116 | attr = screen_char_attr; |
| 8117 | else |
| 8118 | #endif |
| 8119 | attr = ScreenAttrs[off]; |
| 8120 | if (screen_attr != attr) |
| 8121 | screen_stop_highlight(); |
| 8122 | |
| 8123 | windgoto(row, col); |
| 8124 | |
| 8125 | if (screen_attr != attr) |
| 8126 | screen_start_highlight(attr); |
| 8127 | |
| 8128 | #ifdef FEAT_MBYTE |
| 8129 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 8130 | { |
| 8131 | char_u buf[MB_MAXBYTES + 1]; |
| 8132 | |
| 8133 | /* Convert UTF-8 character to bytes and write it. */ |
| 8134 | |
| 8135 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 8136 | |
| 8137 | out_str(buf); |
Bram Moolenaar | cb07008 | 2016-04-02 22:14:51 +0200 | [diff] [blame] | 8138 | if (utf_ambiguous_width(ScreenLinesUC[off])) |
| 8139 | screen_cur_col = 9999; |
| 8140 | else if (utf_char2cells(ScreenLinesUC[off]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8141 | ++screen_cur_col; |
| 8142 | } |
| 8143 | else |
| 8144 | #endif |
| 8145 | { |
| 8146 | #ifdef FEAT_MBYTE |
| 8147 | out_flush_check(); |
| 8148 | #endif |
| 8149 | out_char(ScreenLines[off]); |
| 8150 | #ifdef FEAT_MBYTE |
| 8151 | /* double-byte character in single-width cell */ |
| 8152 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 8153 | out_char(ScreenLines2[off]); |
| 8154 | #endif |
| 8155 | } |
| 8156 | |
| 8157 | screen_cur_col++; |
| 8158 | } |
| 8159 | |
| 8160 | #ifdef FEAT_MBYTE |
| 8161 | |
| 8162 | /* |
| 8163 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 8164 | * on the screen at position 'row' and 'col'. |
| 8165 | * The attributes of the first byte is used for all. This is required to |
| 8166 | * output the two bytes of a double-byte character with nothing in between. |
| 8167 | */ |
| 8168 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8169 | screen_char_2(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8170 | { |
| 8171 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 8172 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 8173 | return; |
| 8174 | |
| 8175 | /* Outputting the last character on the screen may scrollup the screen. |
| 8176 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 8177 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 8178 | { |
| 8179 | ScreenAttrs[off] = (sattr_T)-1; |
| 8180 | return; |
| 8181 | } |
| 8182 | |
| 8183 | /* Output the first byte normally (positions the cursor), then write the |
| 8184 | * second byte directly. */ |
| 8185 | screen_char(off, row, col); |
| 8186 | out_char(ScreenLines[off + 1]); |
| 8187 | ++screen_cur_col; |
| 8188 | } |
| 8189 | #endif |
| 8190 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8191 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8192 | /* |
| 8193 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 8194 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 8195 | */ |
| 8196 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8197 | screen_draw_rectangle( |
| 8198 | int row, |
| 8199 | int col, |
| 8200 | int height, |
| 8201 | int width, |
| 8202 | int invert) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8203 | { |
| 8204 | int r, c; |
| 8205 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8206 | #ifdef FEAT_MBYTE |
| 8207 | int max_off; |
| 8208 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8209 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8210 | /* Can't use ScreenLines unless initialized */ |
| 8211 | if (ScreenLines == NULL) |
| 8212 | return; |
| 8213 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8214 | if (invert) |
| 8215 | screen_char_attr = HL_INVERSE; |
| 8216 | for (r = row; r < row + height; ++r) |
| 8217 | { |
| 8218 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8219 | #ifdef FEAT_MBYTE |
| 8220 | max_off = off + screen_Columns; |
| 8221 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8222 | for (c = col; c < col + width; ++c) |
| 8223 | { |
| 8224 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8225 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8226 | { |
| 8227 | screen_char_2(off + c, r, c); |
| 8228 | ++c; |
| 8229 | } |
| 8230 | else |
| 8231 | #endif |
| 8232 | { |
| 8233 | screen_char(off + c, r, c); |
| 8234 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8235 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8236 | ++c; |
| 8237 | #endif |
| 8238 | } |
| 8239 | } |
| 8240 | } |
| 8241 | screen_char_attr = 0; |
| 8242 | } |
| 8243 | #endif |
| 8244 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8245 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8246 | /* |
| 8247 | * Redraw the characters for a vertically split window. |
| 8248 | */ |
| 8249 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8250 | redraw_block(int row, int end, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8251 | { |
| 8252 | int col; |
| 8253 | int width; |
| 8254 | |
| 8255 | # ifdef FEAT_CLIPBOARD |
| 8256 | clip_may_clear_selection(row, end - 1); |
| 8257 | # endif |
| 8258 | |
| 8259 | if (wp == NULL) |
| 8260 | { |
| 8261 | col = 0; |
| 8262 | width = Columns; |
| 8263 | } |
| 8264 | else |
| 8265 | { |
| 8266 | col = wp->w_wincol; |
| 8267 | width = wp->w_width; |
| 8268 | } |
| 8269 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 8270 | } |
| 8271 | #endif |
| 8272 | |
| 8273 | /* |
| 8274 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 8275 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 8276 | * Use attributes 'attr'. |
| 8277 | */ |
| 8278 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8279 | screen_fill( |
| 8280 | int start_row, |
| 8281 | int end_row, |
| 8282 | int start_col, |
| 8283 | int end_col, |
| 8284 | int c1, |
| 8285 | int c2, |
| 8286 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8287 | { |
| 8288 | int row; |
| 8289 | int col; |
| 8290 | int off; |
| 8291 | int end_off; |
| 8292 | int did_delete; |
| 8293 | int c; |
| 8294 | int norm_term; |
| 8295 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8296 | int force_next = FALSE; |
| 8297 | #endif |
| 8298 | |
| 8299 | if (end_row > screen_Rows) /* safety check */ |
| 8300 | end_row = screen_Rows; |
| 8301 | if (end_col > screen_Columns) /* safety check */ |
| 8302 | end_col = screen_Columns; |
| 8303 | if (ScreenLines == NULL |
| 8304 | || start_row >= end_row |
| 8305 | || start_col >= end_col) /* nothing to do */ |
| 8306 | return; |
| 8307 | |
| 8308 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 8309 | norm_term = ( |
| 8310 | #ifdef FEAT_GUI |
| 8311 | !gui.in_use && |
| 8312 | #endif |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8313 | !IS_CTERM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8314 | for (row = start_row; row < end_row; ++row) |
| 8315 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8316 | #ifdef FEAT_MBYTE |
| 8317 | if (has_mbyte |
| 8318 | # ifdef FEAT_GUI |
| 8319 | && !gui.in_use |
| 8320 | # endif |
| 8321 | ) |
| 8322 | { |
| 8323 | /* When drawing over the right halve of a double-wide char clear |
| 8324 | * out the left halve. When drawing over the left halve of a |
| 8325 | * double wide-char clear out the right halve. Only needed in a |
| 8326 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 8327 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8328 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 8329 | 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] | 8330 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8331 | } |
| 8332 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8333 | /* |
| 8334 | * Try to use delete-line termcap code, when no attributes or in a |
| 8335 | * "normal" terminal, where a bold/italic space is just a |
| 8336 | * space. |
| 8337 | */ |
| 8338 | did_delete = FALSE; |
| 8339 | if (c2 == ' ' |
| 8340 | && end_col == Columns |
| 8341 | && can_clear(T_CE) |
| 8342 | && (attr == 0 |
| 8343 | || (norm_term |
| 8344 | && attr <= HL_ALL |
| 8345 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 8346 | { |
| 8347 | /* |
| 8348 | * check if we really need to clear something |
| 8349 | */ |
| 8350 | col = start_col; |
| 8351 | if (c1 != ' ') /* don't clear first char */ |
| 8352 | ++col; |
| 8353 | |
| 8354 | off = LineOffset[row] + col; |
| 8355 | end_off = LineOffset[row] + end_col; |
| 8356 | |
| 8357 | /* skip blanks (used often, keep it fast!) */ |
| 8358 | #ifdef FEAT_MBYTE |
| 8359 | if (enc_utf8) |
| 8360 | while (off < end_off && ScreenLines[off] == ' ' |
| 8361 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 8362 | ++off; |
| 8363 | else |
| 8364 | #endif |
| 8365 | while (off < end_off && ScreenLines[off] == ' ' |
| 8366 | && ScreenAttrs[off] == 0) |
| 8367 | ++off; |
| 8368 | if (off < end_off) /* something to be cleared */ |
| 8369 | { |
| 8370 | col = off - LineOffset[row]; |
| 8371 | screen_stop_highlight(); |
| 8372 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 8373 | out_str(T_CE); |
| 8374 | screen_start(); /* don't know where cursor is now */ |
| 8375 | col = end_col - col; |
| 8376 | while (col--) /* clear chars in ScreenLines */ |
| 8377 | { |
| 8378 | ScreenLines[off] = ' '; |
| 8379 | #ifdef FEAT_MBYTE |
| 8380 | if (enc_utf8) |
| 8381 | ScreenLinesUC[off] = 0; |
| 8382 | #endif |
| 8383 | ScreenAttrs[off] = 0; |
| 8384 | ++off; |
| 8385 | } |
| 8386 | } |
| 8387 | did_delete = TRUE; /* the chars are cleared now */ |
| 8388 | } |
| 8389 | |
| 8390 | off = LineOffset[row] + start_col; |
| 8391 | c = c1; |
| 8392 | for (col = start_col; col < end_col; ++col) |
| 8393 | { |
| 8394 | if (ScreenLines[off] != c |
| 8395 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8396 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 8397 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8398 | #endif |
| 8399 | || ScreenAttrs[off] != attr |
| 8400 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8401 | || force_next |
| 8402 | #endif |
| 8403 | ) |
| 8404 | { |
| 8405 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8406 | /* The bold trick may make a single row of pixels appear in |
| 8407 | * the next character. When a bold character is removed, the |
| 8408 | * next character should be redrawn too. This happens for our |
| 8409 | * own GUI and for some xterms. */ |
| 8410 | if ( |
| 8411 | # ifdef FEAT_GUI |
| 8412 | gui.in_use |
| 8413 | # endif |
| 8414 | # if defined(FEAT_GUI) && defined(UNIX) |
| 8415 | || |
| 8416 | # endif |
| 8417 | # ifdef UNIX |
| 8418 | term_is_xterm |
| 8419 | # endif |
| 8420 | ) |
| 8421 | { |
| 8422 | if (ScreenLines[off] != ' ' |
| 8423 | && (ScreenAttrs[off] > HL_ALL |
| 8424 | || ScreenAttrs[off] & HL_BOLD)) |
| 8425 | force_next = TRUE; |
| 8426 | else |
| 8427 | force_next = FALSE; |
| 8428 | } |
| 8429 | #endif |
| 8430 | ScreenLines[off] = c; |
| 8431 | #ifdef FEAT_MBYTE |
| 8432 | if (enc_utf8) |
| 8433 | { |
| 8434 | if (c >= 0x80) |
| 8435 | { |
| 8436 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8437 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8438 | } |
| 8439 | else |
| 8440 | ScreenLinesUC[off] = 0; |
| 8441 | } |
| 8442 | #endif |
| 8443 | ScreenAttrs[off] = attr; |
| 8444 | if (!did_delete || c != ' ') |
| 8445 | screen_char(off, row, col); |
| 8446 | } |
| 8447 | ++off; |
| 8448 | if (col == start_col) |
| 8449 | { |
| 8450 | if (did_delete) |
| 8451 | break; |
| 8452 | c = c2; |
| 8453 | } |
| 8454 | } |
| 8455 | if (end_col == Columns) |
| 8456 | LineWraps[row] = FALSE; |
| 8457 | if (row == Rows - 1) /* overwritten the command line */ |
| 8458 | { |
| 8459 | redraw_cmdline = TRUE; |
| 8460 | if (c1 == ' ' && c2 == ' ') |
| 8461 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8462 | if (start_col == 0) |
| 8463 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8464 | } |
| 8465 | } |
| 8466 | } |
| 8467 | |
| 8468 | /* |
| 8469 | * Check if there should be a delay. Used before clearing or redrawing the |
| 8470 | * screen or the command line. |
| 8471 | */ |
| 8472 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8473 | check_for_delay(int check_msg_scroll) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8474 | { |
| 8475 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 8476 | && !did_wait_return |
| 8477 | && emsg_silent == 0) |
| 8478 | { |
| 8479 | out_flush(); |
| 8480 | ui_delay(1000L, TRUE); |
| 8481 | emsg_on_display = FALSE; |
| 8482 | if (check_msg_scroll) |
| 8483 | msg_scroll = FALSE; |
| 8484 | } |
| 8485 | } |
| 8486 | |
| 8487 | /* |
| 8488 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8489 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8490 | * Returns TRUE if there is a valid screen to write to. |
| 8491 | * Returns FALSE when starting up and screen not initialized yet. |
| 8492 | */ |
| 8493 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8494 | screen_valid(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8495 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8496 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8497 | return (ScreenLines != NULL); |
| 8498 | } |
| 8499 | |
| 8500 | /* |
| 8501 | * Resize the shell to Rows and Columns. |
| 8502 | * Allocate ScreenLines[] and associated items. |
| 8503 | * |
| 8504 | * There may be some time between setting Rows and Columns and (re)allocating |
| 8505 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 8506 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 8507 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 8508 | * final size of the shell is needed. |
| 8509 | */ |
| 8510 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8511 | screenalloc(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8512 | { |
| 8513 | int new_row, old_row; |
| 8514 | #ifdef FEAT_GUI |
| 8515 | int old_Rows; |
| 8516 | #endif |
| 8517 | win_T *wp; |
| 8518 | int outofmem = FALSE; |
| 8519 | int len; |
| 8520 | schar_T *new_ScreenLines; |
| 8521 | #ifdef FEAT_MBYTE |
| 8522 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8523 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8524 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8525 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8526 | #endif |
| 8527 | sattr_T *new_ScreenAttrs; |
| 8528 | unsigned *new_LineOffset; |
| 8529 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8530 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8531 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8532 | tabpage_T *tp; |
| 8533 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8534 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8535 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8536 | #ifdef FEAT_AUTOCMD |
| 8537 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8538 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8539 | retry: |
| 8540 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8541 | /* |
| 8542 | * Allocation of the screen buffers is done only when the size changes and |
| 8543 | * when Rows and Columns have been set and we have started doing full |
| 8544 | * screen stuff. |
| 8545 | */ |
| 8546 | if ((ScreenLines != NULL |
| 8547 | && Rows == screen_Rows |
| 8548 | && Columns == screen_Columns |
| 8549 | #ifdef FEAT_MBYTE |
| 8550 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 8551 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8552 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8553 | #endif |
| 8554 | ) |
| 8555 | || Rows == 0 |
| 8556 | || Columns == 0 |
| 8557 | || (!full_screen && ScreenLines == NULL)) |
| 8558 | return; |
| 8559 | |
| 8560 | /* |
| 8561 | * It's possible that we produce an out-of-memory message below, which |
| 8562 | * will cause this function to be called again. To break the loop, just |
| 8563 | * return here. |
| 8564 | */ |
| 8565 | if (entered) |
| 8566 | return; |
| 8567 | entered = TRUE; |
| 8568 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8569 | /* |
| 8570 | * Note that the window sizes are updated before reallocating the arrays, |
| 8571 | * thus we must not redraw here! |
| 8572 | */ |
| 8573 | ++RedrawingDisabled; |
| 8574 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8575 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8576 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8577 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8578 | |
| 8579 | /* |
| 8580 | * We're changing the size of the screen. |
| 8581 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8582 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8583 | * lines (unless the screen is going to be cleared). |
| 8584 | * - Free the old arrays. |
| 8585 | * |
| 8586 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8587 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8588 | * size is wrong. |
| 8589 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8590 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8591 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8592 | #ifdef FEAT_AUTOCMD |
| 8593 | if (aucmd_win != NULL) |
| 8594 | win_free_lsize(aucmd_win); |
| 8595 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8596 | |
| 8597 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8598 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8599 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8600 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8601 | if (enc_utf8) |
| 8602 | { |
| 8603 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8604 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8605 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8606 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8607 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8608 | } |
| 8609 | if (enc_dbcs == DBCS_JPNU) |
| 8610 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8611 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8612 | #endif |
| 8613 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8614 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8615 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8616 | Rows * sizeof(unsigned)), FALSE); |
| 8617 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8618 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8619 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8620 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8621 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8622 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8623 | { |
| 8624 | if (win_alloc_lines(wp) == FAIL) |
| 8625 | { |
| 8626 | outofmem = TRUE; |
| 8627 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8628 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8629 | #endif |
| 8630 | } |
| 8631 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8632 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8633 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8634 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8635 | outofmem = TRUE; |
| 8636 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8637 | #ifdef FEAT_WINDOWS |
| 8638 | give_up: |
| 8639 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8640 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8641 | #ifdef FEAT_MBYTE |
| 8642 | for (i = 0; i < p_mco; ++i) |
| 8643 | if (new_ScreenLinesC[i] == NULL) |
| 8644 | break; |
| 8645 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8646 | if (new_ScreenLines == NULL |
| 8647 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8648 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8649 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8650 | #endif |
| 8651 | || new_ScreenAttrs == NULL |
| 8652 | || new_LineOffset == NULL |
| 8653 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8654 | #ifdef FEAT_WINDOWS |
| 8655 | || new_TabPageIdxs == NULL |
| 8656 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8657 | || outofmem) |
| 8658 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8659 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8660 | { |
| 8661 | /* guess the size */ |
| 8662 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8663 | |
| 8664 | /* Remember we did this to avoid getting outofmem messages over |
| 8665 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8666 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8667 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8668 | vim_free(new_ScreenLines); |
| 8669 | new_ScreenLines = NULL; |
| 8670 | #ifdef FEAT_MBYTE |
| 8671 | vim_free(new_ScreenLinesUC); |
| 8672 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8673 | for (i = 0; i < p_mco; ++i) |
| 8674 | { |
| 8675 | vim_free(new_ScreenLinesC[i]); |
| 8676 | new_ScreenLinesC[i] = NULL; |
| 8677 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8678 | vim_free(new_ScreenLines2); |
| 8679 | new_ScreenLines2 = NULL; |
| 8680 | #endif |
| 8681 | vim_free(new_ScreenAttrs); |
| 8682 | new_ScreenAttrs = NULL; |
| 8683 | vim_free(new_LineOffset); |
| 8684 | new_LineOffset = NULL; |
| 8685 | vim_free(new_LineWraps); |
| 8686 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8687 | #ifdef FEAT_WINDOWS |
| 8688 | vim_free(new_TabPageIdxs); |
| 8689 | new_TabPageIdxs = NULL; |
| 8690 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8691 | } |
| 8692 | else |
| 8693 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8694 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8695 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8696 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8697 | { |
| 8698 | new_LineOffset[new_row] = new_row * Columns; |
| 8699 | new_LineWraps[new_row] = FALSE; |
| 8700 | |
| 8701 | /* |
| 8702 | * If the screen is not going to be cleared, copy as much as |
| 8703 | * possible from the old screen to the new one and clear the rest |
| 8704 | * (used when resizing the window at the "--more--" prompt or when |
| 8705 | * executing an external command, for the GUI). |
| 8706 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8707 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8708 | { |
| 8709 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8710 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8711 | #ifdef FEAT_MBYTE |
| 8712 | if (enc_utf8) |
| 8713 | { |
| 8714 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8715 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8716 | for (i = 0; i < p_mco; ++i) |
| 8717 | (void)vim_memset(new_ScreenLinesC[i] |
| 8718 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8719 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8720 | } |
| 8721 | if (enc_dbcs == DBCS_JPNU) |
| 8722 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8723 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8724 | #endif |
| 8725 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8726 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8727 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8728 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8729 | { |
| 8730 | if (screen_Columns < Columns) |
| 8731 | len = screen_Columns; |
| 8732 | else |
| 8733 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8734 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8735 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8736 | * may be invalid now. Also when p_mco changes. */ |
| 8737 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8738 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8739 | #endif |
| 8740 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8741 | ScreenLines + LineOffset[old_row], |
| 8742 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8743 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8744 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8745 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8746 | { |
| 8747 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8748 | ScreenLinesUC + LineOffset[old_row], |
| 8749 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8750 | for (i = 0; i < p_mco; ++i) |
| 8751 | mch_memmove(new_ScreenLinesC[i] |
| 8752 | + new_LineOffset[new_row], |
| 8753 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8754 | (size_t)len * sizeof(u8char_T)); |
| 8755 | } |
| 8756 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8757 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8758 | ScreenLines2 + LineOffset[old_row], |
| 8759 | (size_t)len * sizeof(schar_T)); |
| 8760 | #endif |
| 8761 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8762 | ScreenAttrs + LineOffset[old_row], |
| 8763 | (size_t)len * sizeof(sattr_T)); |
| 8764 | } |
| 8765 | } |
| 8766 | } |
| 8767 | /* Use the last line of the screen for the current line. */ |
| 8768 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8769 | } |
| 8770 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8771 | free_screenlines(); |
| 8772 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8773 | ScreenLines = new_ScreenLines; |
| 8774 | #ifdef FEAT_MBYTE |
| 8775 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8776 | for (i = 0; i < p_mco; ++i) |
| 8777 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8778 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8779 | ScreenLines2 = new_ScreenLines2; |
| 8780 | #endif |
| 8781 | ScreenAttrs = new_ScreenAttrs; |
| 8782 | LineOffset = new_LineOffset; |
| 8783 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8784 | #ifdef FEAT_WINDOWS |
| 8785 | TabPageIdxs = new_TabPageIdxs; |
| 8786 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8787 | |
| 8788 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8789 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8790 | #ifdef FEAT_GUI |
| 8791 | old_Rows = screen_Rows; |
| 8792 | #endif |
| 8793 | screen_Rows = Rows; |
| 8794 | screen_Columns = Columns; |
| 8795 | |
| 8796 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8797 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8798 | screenclear2(); |
| 8799 | |
| 8800 | #ifdef FEAT_GUI |
| 8801 | else if (gui.in_use |
| 8802 | && !gui.starting |
| 8803 | && ScreenLines != NULL |
| 8804 | && old_Rows != Rows) |
| 8805 | { |
| 8806 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8807 | /* |
| 8808 | * Adjust the position of the cursor, for when executing an external |
| 8809 | * command. |
| 8810 | */ |
| 8811 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8812 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8813 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8814 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8815 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8816 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8817 | } |
| 8818 | #endif |
| 8819 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8820 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8821 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8822 | |
| 8823 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8824 | /* |
| 8825 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8826 | * in case applying autocommands always changes Rows or Columns. |
| 8827 | */ |
| 8828 | if (starting == 0 && ++retry_count <= 3) |
| 8829 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8830 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8831 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8832 | * jump back to check if we need to allocate the screen again. */ |
| 8833 | goto retry; |
| 8834 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8835 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8836 | } |
| 8837 | |
| 8838 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8839 | free_screenlines(void) |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8840 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8841 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8842 | int i; |
| 8843 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8844 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8845 | for (i = 0; i < Screen_mco; ++i) |
| 8846 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8847 | vim_free(ScreenLines2); |
| 8848 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8849 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8850 | vim_free(ScreenAttrs); |
| 8851 | vim_free(LineOffset); |
| 8852 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8853 | #ifdef FEAT_WINDOWS |
| 8854 | vim_free(TabPageIdxs); |
| 8855 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8856 | } |
| 8857 | |
| 8858 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8859 | screenclear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8860 | { |
| 8861 | check_for_delay(FALSE); |
| 8862 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8863 | screenclear2(); /* clear the screen */ |
| 8864 | } |
| 8865 | |
| 8866 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8867 | screenclear2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8868 | { |
| 8869 | int i; |
| 8870 | |
| 8871 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8872 | #ifdef FEAT_GUI |
| 8873 | || (gui.in_use && gui.starting) |
| 8874 | #endif |
| 8875 | ) |
| 8876 | return; |
| 8877 | |
| 8878 | #ifdef FEAT_GUI |
| 8879 | if (!gui.in_use) |
| 8880 | #endif |
| 8881 | screen_attr = -1; /* force setting the Normal colors */ |
| 8882 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8883 | |
| 8884 | #ifdef FEAT_CLIPBOARD |
| 8885 | /* disable selection without redrawing it */ |
| 8886 | clip_scroll_selection(9999); |
| 8887 | #endif |
| 8888 | |
| 8889 | /* blank out ScreenLines */ |
| 8890 | for (i = 0; i < Rows; ++i) |
| 8891 | { |
| 8892 | lineclear(LineOffset[i], (int)Columns); |
| 8893 | LineWraps[i] = FALSE; |
| 8894 | } |
| 8895 | |
| 8896 | if (can_clear(T_CL)) |
| 8897 | { |
| 8898 | out_str(T_CL); /* clear the display */ |
| 8899 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8900 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8901 | } |
| 8902 | else |
| 8903 | { |
| 8904 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8905 | for (i = 0; i < Rows; ++i) |
| 8906 | lineinvalid(LineOffset[i], (int)Columns); |
| 8907 | clear_cmdline = TRUE; |
| 8908 | } |
| 8909 | |
| 8910 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8911 | |
| 8912 | win_rest_invalid(firstwin); |
| 8913 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8914 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8915 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8916 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8917 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8918 | must_redraw = NOT_VALID; |
| 8919 | compute_cmdrow(); |
| 8920 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8921 | msg_col = 0; |
| 8922 | screen_start(); /* don't know where cursor is now */ |
| 8923 | msg_scrolled = 0; /* can't scroll back */ |
| 8924 | msg_didany = FALSE; |
| 8925 | msg_didout = FALSE; |
| 8926 | } |
| 8927 | |
| 8928 | /* |
| 8929 | * Clear one line in ScreenLines. |
| 8930 | */ |
| 8931 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8932 | lineclear(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8933 | { |
| 8934 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8935 | #ifdef FEAT_MBYTE |
| 8936 | if (enc_utf8) |
| 8937 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8938 | (size_t)width * sizeof(u8char_T)); |
| 8939 | #endif |
| 8940 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8941 | } |
| 8942 | |
| 8943 | /* |
| 8944 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8945 | * invalid value. |
| 8946 | */ |
| 8947 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8948 | lineinvalid(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8949 | { |
| 8950 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8951 | } |
| 8952 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8953 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8954 | /* |
| 8955 | * Copy part of a Screenline for vertically split window "wp". |
| 8956 | */ |
| 8957 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8958 | linecopy(int to, int from, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8959 | { |
| 8960 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8961 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8962 | |
| 8963 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8964 | wp->w_width * sizeof(schar_T)); |
| 8965 | # ifdef FEAT_MBYTE |
| 8966 | if (enc_utf8) |
| 8967 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8968 | int i; |
| 8969 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8970 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8971 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8972 | for (i = 0; i < p_mco; ++i) |
| 8973 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8974 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8975 | } |
| 8976 | if (enc_dbcs == DBCS_JPNU) |
| 8977 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8978 | wp->w_width * sizeof(schar_T)); |
| 8979 | # endif |
| 8980 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8981 | wp->w_width * sizeof(sattr_T)); |
| 8982 | } |
| 8983 | #endif |
| 8984 | |
| 8985 | /* |
| 8986 | * Return TRUE if clearing with term string "p" would work. |
| 8987 | * It can't work when the string is empty or it won't set the right background. |
| 8988 | */ |
| 8989 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8990 | can_clear(char_u *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8991 | { |
| 8992 | return (*p != NUL && (t_colors <= 1 |
| 8993 | #ifdef FEAT_GUI |
| 8994 | || gui.in_use |
| 8995 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8996 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8997 | || (p_tgc && cterm_normal_bg_gui_color == INVALCOLOR) |
Bram Moolenaar | d18f672 | 2016-06-17 13:18:49 +0200 | [diff] [blame] | 8998 | || (!p_tgc && cterm_normal_bg_color == 0) |
| 8999 | #else |
| 9000 | || cterm_normal_bg_color == 0 |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 9001 | #endif |
Bram Moolenaar | d18f672 | 2016-06-17 13:18:49 +0200 | [diff] [blame] | 9002 | || *T_UT != NUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9003 | } |
| 9004 | |
| 9005 | /* |
| 9006 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 9007 | * something directly to the screen (shell commands) or a terminal control |
| 9008 | * code. |
| 9009 | */ |
| 9010 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9011 | screen_start(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9012 | { |
| 9013 | screen_cur_row = screen_cur_col = 9999; |
| 9014 | } |
| 9015 | |
| 9016 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9017 | * Move the cursor to position "row","col" in the screen. |
| 9018 | * This tries to find the most efficient way to move, minimizing the number of |
| 9019 | * characters sent to the terminal. |
| 9020 | */ |
| 9021 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9022 | windgoto(int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9023 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9024 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9025 | int i; |
| 9026 | int plan; |
| 9027 | int cost; |
| 9028 | int wouldbe_col; |
| 9029 | int noinvcurs; |
| 9030 | char_u *bs; |
| 9031 | int goto_cost; |
| 9032 | int attr; |
| 9033 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9034 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9035 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 9036 | |
| 9037 | #define PLAN_LE 1 |
| 9038 | #define PLAN_CR 2 |
| 9039 | #define PLAN_NL 3 |
| 9040 | #define PLAN_WRITE 4 |
| 9041 | /* Can't use ScreenLines unless initialized */ |
| 9042 | if (ScreenLines == NULL) |
| 9043 | return; |
| 9044 | |
| 9045 | if (col != screen_cur_col || row != screen_cur_row) |
| 9046 | { |
| 9047 | /* Check for valid position. */ |
| 9048 | if (row < 0) /* window without text lines? */ |
| 9049 | row = 0; |
| 9050 | if (row >= screen_Rows) |
| 9051 | row = screen_Rows - 1; |
| 9052 | if (col >= screen_Columns) |
| 9053 | col = screen_Columns - 1; |
| 9054 | |
| 9055 | /* check if no cursor movement is allowed in highlight mode */ |
| 9056 | if (screen_attr && *T_MS == NUL) |
| 9057 | noinvcurs = HIGHL_COST; |
| 9058 | else |
| 9059 | noinvcurs = 0; |
| 9060 | goto_cost = GOTO_COST + noinvcurs; |
| 9061 | |
| 9062 | /* |
| 9063 | * Plan how to do the positioning: |
| 9064 | * 1. Use CR to move it to column 0, same row. |
| 9065 | * 2. Use T_LE to move it a few columns to the left. |
| 9066 | * 3. Use NL to move a few lines down, column 0. |
| 9067 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 9068 | * |
| 9069 | * Don't do this if the cursor went beyond the last column, the cursor |
| 9070 | * position is unknown then (some terminals wrap, some don't ) |
| 9071 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9072 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9073 | * characters to move the cursor to the right. |
| 9074 | */ |
| 9075 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 9076 | { |
| 9077 | /* |
| 9078 | * If the cursor is in the same row, bigger col, we can use CR |
| 9079 | * or T_LE. |
| 9080 | */ |
| 9081 | bs = NULL; /* init for GCC */ |
| 9082 | attr = screen_attr; |
| 9083 | if (row == screen_cur_row && col < screen_cur_col) |
| 9084 | { |
| 9085 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 9086 | if (*T_LE) |
| 9087 | bs = T_LE; /* "cursor left" */ |
| 9088 | else |
| 9089 | bs = T_BC; /* "backspace character (old) */ |
| 9090 | if (*bs) |
| 9091 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 9092 | else |
| 9093 | cost = 999; |
| 9094 | if (col + 1 < cost) /* using CR is less characters */ |
| 9095 | { |
| 9096 | plan = PLAN_CR; |
| 9097 | wouldbe_col = 0; |
| 9098 | cost = 1; /* CR is just one character */ |
| 9099 | } |
| 9100 | else |
| 9101 | { |
| 9102 | plan = PLAN_LE; |
| 9103 | wouldbe_col = col; |
| 9104 | } |
| 9105 | if (noinvcurs) /* will stop highlighting */ |
| 9106 | { |
| 9107 | cost += noinvcurs; |
| 9108 | attr = 0; |
| 9109 | } |
| 9110 | } |
| 9111 | |
| 9112 | /* |
| 9113 | * If the cursor is above where we want to be, we can use CR LF. |
| 9114 | */ |
| 9115 | else if (row > screen_cur_row) |
| 9116 | { |
| 9117 | plan = PLAN_NL; |
| 9118 | wouldbe_col = 0; |
| 9119 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 9120 | if (noinvcurs) /* will stop highlighting */ |
| 9121 | { |
| 9122 | cost += noinvcurs; |
| 9123 | attr = 0; |
| 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | /* |
| 9128 | * If the cursor is in the same row, smaller col, just use write. |
| 9129 | */ |
| 9130 | else |
| 9131 | { |
| 9132 | plan = PLAN_WRITE; |
| 9133 | wouldbe_col = screen_cur_col; |
| 9134 | cost = 0; |
| 9135 | } |
| 9136 | |
| 9137 | /* |
| 9138 | * Check if any characters that need to be written have the |
| 9139 | * correct attributes. Also avoid UTF-8 characters. |
| 9140 | */ |
| 9141 | i = col - wouldbe_col; |
| 9142 | if (i > 0) |
| 9143 | cost += i; |
| 9144 | if (cost < goto_cost && i > 0) |
| 9145 | { |
| 9146 | /* |
| 9147 | * Check if the attributes are correct without additionally |
| 9148 | * stopping highlighting. |
| 9149 | */ |
| 9150 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 9151 | while (i && *p++ == attr) |
| 9152 | --i; |
| 9153 | if (i != 0) |
| 9154 | { |
| 9155 | /* |
| 9156 | * Try if it works when highlighting is stopped here. |
| 9157 | */ |
| 9158 | if (*--p == 0) |
| 9159 | { |
| 9160 | cost += noinvcurs; |
| 9161 | while (i && *p++ == 0) |
| 9162 | --i; |
| 9163 | } |
| 9164 | if (i != 0) |
| 9165 | cost = 999; /* different attributes, don't do it */ |
| 9166 | } |
| 9167 | #ifdef FEAT_MBYTE |
| 9168 | if (enc_utf8) |
| 9169 | { |
| 9170 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 9171 | for (i = wouldbe_col; i < col; ++i) |
| 9172 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 9173 | { |
| 9174 | cost = 999; |
| 9175 | break; |
| 9176 | } |
| 9177 | } |
| 9178 | #endif |
| 9179 | } |
| 9180 | |
| 9181 | /* |
| 9182 | * We can do it without term_windgoto()! |
| 9183 | */ |
| 9184 | if (cost < goto_cost) |
| 9185 | { |
| 9186 | if (plan == PLAN_LE) |
| 9187 | { |
| 9188 | if (noinvcurs) |
| 9189 | screen_stop_highlight(); |
| 9190 | while (screen_cur_col > col) |
| 9191 | { |
| 9192 | out_str(bs); |
| 9193 | --screen_cur_col; |
| 9194 | } |
| 9195 | } |
| 9196 | else if (plan == PLAN_CR) |
| 9197 | { |
| 9198 | if (noinvcurs) |
| 9199 | screen_stop_highlight(); |
| 9200 | out_char('\r'); |
| 9201 | screen_cur_col = 0; |
| 9202 | } |
| 9203 | else if (plan == PLAN_NL) |
| 9204 | { |
| 9205 | if (noinvcurs) |
| 9206 | screen_stop_highlight(); |
| 9207 | while (screen_cur_row < row) |
| 9208 | { |
| 9209 | out_char('\n'); |
| 9210 | ++screen_cur_row; |
| 9211 | } |
| 9212 | screen_cur_col = 0; |
| 9213 | } |
| 9214 | |
| 9215 | i = col - screen_cur_col; |
| 9216 | if (i > 0) |
| 9217 | { |
| 9218 | /* |
| 9219 | * Use cursor-right if it's one character only. Avoids |
| 9220 | * removing a line of pixels from the last bold char, when |
| 9221 | * using the bold trick in the GUI. |
| 9222 | */ |
| 9223 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 9224 | { |
| 9225 | while (i-- > 0) |
| 9226 | out_char(*T_ND); |
| 9227 | } |
| 9228 | else |
| 9229 | { |
| 9230 | int off; |
| 9231 | |
| 9232 | off = LineOffset[row] + screen_cur_col; |
| 9233 | while (i-- > 0) |
| 9234 | { |
| 9235 | if (ScreenAttrs[off] != screen_attr) |
| 9236 | screen_stop_highlight(); |
| 9237 | #ifdef FEAT_MBYTE |
| 9238 | out_flush_check(); |
| 9239 | #endif |
| 9240 | out_char(ScreenLines[off]); |
| 9241 | #ifdef FEAT_MBYTE |
| 9242 | if (enc_dbcs == DBCS_JPNU |
| 9243 | && ScreenLines[off] == 0x8e) |
| 9244 | out_char(ScreenLines2[off]); |
| 9245 | #endif |
| 9246 | ++off; |
| 9247 | } |
| 9248 | } |
| 9249 | } |
| 9250 | } |
| 9251 | } |
| 9252 | else |
| 9253 | cost = 999; |
| 9254 | |
| 9255 | if (cost >= goto_cost) |
| 9256 | { |
| 9257 | if (noinvcurs) |
| 9258 | screen_stop_highlight(); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 9259 | if (row == screen_cur_row && (col > screen_cur_col) |
| 9260 | && *T_CRI != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9261 | term_cursor_right(col - screen_cur_col); |
| 9262 | else |
| 9263 | term_windgoto(row, col); |
| 9264 | } |
| 9265 | screen_cur_row = row; |
| 9266 | screen_cur_col = col; |
| 9267 | } |
| 9268 | } |
| 9269 | |
| 9270 | /* |
| 9271 | * Set cursor to its position in the current window. |
| 9272 | */ |
| 9273 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9274 | setcursor(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9275 | { |
| 9276 | if (redrawing()) |
| 9277 | { |
| 9278 | validate_cursor(); |
| 9279 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 9280 | W_WINCOL(curwin) + ( |
| 9281 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9282 | /* With 'rightleft' set and the cursor on a double-wide |
| 9283 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9284 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 9285 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9286 | (has_mbyte |
| 9287 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 9288 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9289 | # endif |
| 9290 | 1)) : |
| 9291 | #endif |
| 9292 | curwin->w_wcol)); |
| 9293 | } |
| 9294 | } |
| 9295 | |
| 9296 | |
| 9297 | /* |
| 9298 | * insert 'line_count' lines at 'row' in window 'wp' |
| 9299 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 9300 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 9301 | * scrolling. |
| 9302 | * Returns FAIL if the lines are not inserted, OK for success. |
| 9303 | */ |
| 9304 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9305 | win_ins_lines( |
| 9306 | win_T *wp, |
| 9307 | int row, |
| 9308 | int line_count, |
| 9309 | int invalid, |
| 9310 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9311 | { |
| 9312 | int did_delete; |
| 9313 | int nextrow; |
| 9314 | int lastrow; |
| 9315 | int retval; |
| 9316 | |
| 9317 | if (invalid) |
| 9318 | wp->w_lines_valid = 0; |
| 9319 | |
| 9320 | if (wp->w_height < 5) |
| 9321 | return FAIL; |
| 9322 | |
| 9323 | if (line_count > wp->w_height - row) |
| 9324 | line_count = wp->w_height - row; |
| 9325 | |
| 9326 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 9327 | if (retval != MAYBE) |
| 9328 | return retval; |
| 9329 | |
| 9330 | /* |
| 9331 | * If there is a next window or a status line, we first try to delete the |
| 9332 | * lines at the bottom to avoid messing what is after the window. |
| 9333 | * If this fails and there are following windows, don't do anything to avoid |
| 9334 | * messing up those windows, better just redraw. |
| 9335 | */ |
| 9336 | did_delete = FALSE; |
| 9337 | #ifdef FEAT_WINDOWS |
| 9338 | if (wp->w_next != NULL || wp->w_status_height) |
| 9339 | { |
| 9340 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9341 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 9342 | did_delete = TRUE; |
| 9343 | else if (wp->w_next) |
| 9344 | return FAIL; |
| 9345 | } |
| 9346 | #endif |
| 9347 | /* |
| 9348 | * if no lines deleted, blank the lines that will end up below the window |
| 9349 | */ |
| 9350 | if (!did_delete) |
| 9351 | { |
| 9352 | #ifdef FEAT_WINDOWS |
| 9353 | wp->w_redr_status = TRUE; |
| 9354 | #endif |
| 9355 | redraw_cmdline = TRUE; |
| 9356 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 9357 | lastrow = nextrow + line_count; |
| 9358 | if (lastrow > Rows) |
| 9359 | lastrow = Rows; |
| 9360 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 9361 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9362 | ' ', ' ', 0); |
| 9363 | } |
| 9364 | |
| 9365 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 9366 | == FAIL) |
| 9367 | { |
| 9368 | /* deletion will have messed up other windows */ |
| 9369 | if (did_delete) |
| 9370 | { |
| 9371 | #ifdef FEAT_WINDOWS |
| 9372 | wp->w_redr_status = TRUE; |
| 9373 | #endif |
| 9374 | win_rest_invalid(W_NEXT(wp)); |
| 9375 | } |
| 9376 | return FAIL; |
| 9377 | } |
| 9378 | |
| 9379 | return OK; |
| 9380 | } |
| 9381 | |
| 9382 | /* |
| 9383 | * delete "line_count" window lines at "row" in window "wp" |
| 9384 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 9385 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 9386 | * scrolling |
| 9387 | * Return OK for success, FAIL if the lines are not deleted. |
| 9388 | */ |
| 9389 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9390 | win_del_lines( |
| 9391 | win_T *wp, |
| 9392 | int row, |
| 9393 | int line_count, |
| 9394 | int invalid, |
| 9395 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9396 | { |
| 9397 | int retval; |
| 9398 | |
| 9399 | if (invalid) |
| 9400 | wp->w_lines_valid = 0; |
| 9401 | |
| 9402 | if (line_count > wp->w_height - row) |
| 9403 | line_count = wp->w_height - row; |
| 9404 | |
| 9405 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 9406 | if (retval != MAYBE) |
| 9407 | return retval; |
| 9408 | |
| 9409 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 9410 | (int)Rows, FALSE, NULL) == FAIL) |
| 9411 | return FAIL; |
| 9412 | |
| 9413 | #ifdef FEAT_WINDOWS |
| 9414 | /* |
| 9415 | * If there are windows or status lines below, try to put them at the |
| 9416 | * correct place. If we can't do that, they have to be redrawn. |
| 9417 | */ |
| 9418 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 9419 | { |
| 9420 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9421 | line_count, (int)Rows, NULL) == FAIL) |
| 9422 | { |
| 9423 | wp->w_redr_status = TRUE; |
| 9424 | win_rest_invalid(wp->w_next); |
| 9425 | } |
| 9426 | } |
| 9427 | /* |
| 9428 | * If this is the last window and there is no status line, redraw the |
| 9429 | * command line later. |
| 9430 | */ |
| 9431 | else |
| 9432 | #endif |
| 9433 | redraw_cmdline = TRUE; |
| 9434 | return OK; |
| 9435 | } |
| 9436 | |
| 9437 | /* |
| 9438 | * Common code for win_ins_lines() and win_del_lines(). |
| 9439 | * Returns OK or FAIL when the work has been done. |
| 9440 | * Returns MAYBE when not finished yet. |
| 9441 | */ |
| 9442 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9443 | win_do_lines( |
| 9444 | win_T *wp, |
| 9445 | int row, |
| 9446 | int line_count, |
| 9447 | int mayclear, |
| 9448 | int del) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9449 | { |
| 9450 | int retval; |
| 9451 | |
| 9452 | if (!redrawing() || line_count <= 0) |
| 9453 | return FAIL; |
| 9454 | |
| 9455 | /* only a few lines left: redraw is faster */ |
| 9456 | if (mayclear && Rows - line_count < 5 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9457 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9458 | && wp->w_width == Columns |
| 9459 | #endif |
| 9460 | ) |
| 9461 | { |
| 9462 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 9463 | return FAIL; |
| 9464 | } |
| 9465 | |
| 9466 | /* |
| 9467 | * Delete all remaining lines |
| 9468 | */ |
| 9469 | if (row + line_count >= wp->w_height) |
| 9470 | { |
| 9471 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 9472 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9473 | ' ', ' ', 0); |
| 9474 | return OK; |
| 9475 | } |
| 9476 | |
| 9477 | /* |
| 9478 | * when scrolling, the message on the command line should be cleared, |
| 9479 | * otherwise it will stay there forever. |
| 9480 | */ |
| 9481 | clear_cmdline = TRUE; |
| 9482 | |
| 9483 | /* |
| 9484 | * If the terminal can set a scroll region, use that. |
| 9485 | * Always do this in a vertically split window. This will redraw from |
| 9486 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 9487 | * win_line(). |
| 9488 | * 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] | 9489 | * a character in the lower right corner of the scroll region may cause a |
| 9490 | * scroll-up . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9491 | */ |
| 9492 | if (scroll_region |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9493 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9494 | || W_WIDTH(wp) != Columns |
| 9495 | #endif |
| 9496 | ) |
| 9497 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9498 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9499 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9500 | #endif |
| 9501 | scroll_region_set(wp, row); |
| 9502 | if (del) |
| 9503 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 9504 | wp->w_height - row, FALSE, wp); |
| 9505 | else |
| 9506 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 9507 | wp->w_height - row, wp); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9508 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9509 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9510 | #endif |
| 9511 | scroll_region_reset(); |
| 9512 | return retval; |
| 9513 | } |
| 9514 | |
| 9515 | #ifdef FEAT_WINDOWS |
| 9516 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 9517 | return FAIL; |
| 9518 | #endif |
| 9519 | |
| 9520 | return MAYBE; |
| 9521 | } |
| 9522 | |
| 9523 | /* |
| 9524 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 9525 | */ |
| 9526 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9527 | win_rest_invalid(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9528 | { |
| 9529 | #ifdef FEAT_WINDOWS |
| 9530 | while (wp != NULL) |
| 9531 | #else |
| 9532 | if (wp != NULL) |
| 9533 | #endif |
| 9534 | { |
| 9535 | redraw_win_later(wp, NOT_VALID); |
| 9536 | #ifdef FEAT_WINDOWS |
| 9537 | wp->w_redr_status = TRUE; |
| 9538 | wp = wp->w_next; |
| 9539 | #endif |
| 9540 | } |
| 9541 | redraw_cmdline = TRUE; |
| 9542 | } |
| 9543 | |
| 9544 | /* |
| 9545 | * The rest of the routines in this file perform screen manipulations. The |
| 9546 | * given operation is performed physically on the screen. The corresponding |
| 9547 | * change is also made to the internal screen image. In this way, the editor |
| 9548 | * anticipates the effect of editing changes on the appearance of the screen. |
| 9549 | * That way, when we call screenupdate a complete redraw isn't usually |
| 9550 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 9551 | * screen changes, and in the meantime, everything still works. |
| 9552 | */ |
| 9553 | |
| 9554 | /* |
| 9555 | * types for inserting or deleting lines |
| 9556 | */ |
| 9557 | #define USE_T_CAL 1 |
| 9558 | #define USE_T_CDL 2 |
| 9559 | #define USE_T_AL 3 |
| 9560 | #define USE_T_CE 4 |
| 9561 | #define USE_T_DL 5 |
| 9562 | #define USE_T_SR 6 |
| 9563 | #define USE_NL 7 |
| 9564 | #define USE_T_CD 8 |
| 9565 | #define USE_REDRAW 9 |
| 9566 | |
| 9567 | /* |
| 9568 | * insert lines on the screen and update ScreenLines[] |
| 9569 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9570 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9571 | * 'row' and 'end' are relative to the start of the region. |
| 9572 | * |
| 9573 | * return FAIL for failure, OK for success. |
| 9574 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9575 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9576 | screen_ins_lines( |
| 9577 | int off, |
| 9578 | int row, |
| 9579 | int line_count, |
| 9580 | int end, |
| 9581 | win_T *wp) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9582 | { |
| 9583 | int i; |
| 9584 | int j; |
| 9585 | unsigned temp; |
| 9586 | int cursor_row; |
| 9587 | int type; |
| 9588 | int result_empty; |
| 9589 | int can_ce = can_clear(T_CE); |
| 9590 | |
| 9591 | /* |
| 9592 | * FAIL if |
| 9593 | * - there is no valid screen |
| 9594 | * - the screen has to be redrawn completely |
| 9595 | * - the line count is less than one |
| 9596 | * - the line count is more than 'ttyscroll' |
| 9597 | */ |
| 9598 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9599 | return FAIL; |
| 9600 | |
| 9601 | /* |
| 9602 | * There are seven ways to insert lines: |
| 9603 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9604 | * characters from ScreenLines[]. |
| 9605 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9606 | * the insert is just empty lines |
| 9607 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9608 | * present or line_count > 1. It looks better if we do all the inserts |
| 9609 | * at once. |
| 9610 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9611 | * insert is just empty lines and T_CE is not present or line_count > |
| 9612 | * 1. |
| 9613 | * 4. Use T_AL (insert line) if it exists. |
| 9614 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9615 | * just empty lines. |
| 9616 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9617 | * just empty lines. |
| 9618 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9619 | * the 'da' flag is not set or we have clear line capability. |
| 9620 | * 8. redraw the characters from ScreenLines[]. |
| 9621 | * |
| 9622 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9623 | * the scrollbar for the window. It does have insert line, use that if it |
| 9624 | * exists. |
| 9625 | */ |
| 9626 | result_empty = (row + line_count >= end); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9627 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9628 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9629 | type = USE_REDRAW; |
| 9630 | else |
| 9631 | #endif |
| 9632 | if (can_clear(T_CD) && result_empty) |
| 9633 | type = USE_T_CD; |
| 9634 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9635 | type = USE_T_CAL; |
| 9636 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9637 | type = USE_T_CDL; |
| 9638 | else if (*T_AL != NUL) |
| 9639 | type = USE_T_AL; |
| 9640 | else if (can_ce && result_empty) |
| 9641 | type = USE_T_CE; |
| 9642 | else if (*T_DL != NUL && result_empty) |
| 9643 | type = USE_T_DL; |
| 9644 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9645 | type = USE_T_SR; |
| 9646 | else |
| 9647 | return FAIL; |
| 9648 | |
| 9649 | /* |
| 9650 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9651 | * care of t_db if necessary. |
| 9652 | */ |
| 9653 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9654 | type == USE_T_CE || type == USE_T_DL) |
| 9655 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9656 | |
| 9657 | /* |
| 9658 | * If text is retained below the screen, first clear or delete as many |
| 9659 | * lines at the bottom of the window as are about to be inserted so that |
| 9660 | * the deleted lines won't later surface during a screen_del_lines. |
| 9661 | */ |
| 9662 | if (*T_DB) |
| 9663 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9664 | |
| 9665 | #ifdef FEAT_CLIPBOARD |
| 9666 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9667 | * or not the full width of the screen. */ |
| 9668 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9669 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9670 | || (wp != NULL && wp->w_width != Columns) |
| 9671 | # endif |
| 9672 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9673 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9674 | else |
| 9675 | clip_scroll_selection(-line_count); |
| 9676 | #endif |
| 9677 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9678 | #ifdef FEAT_GUI |
| 9679 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9680 | * scrolling is actually carried out. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 9681 | gui_dont_update_cursor(row + off <= gui.cursor_row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9682 | #endif |
| 9683 | |
| 9684 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9685 | cursor_row = row; |
| 9686 | else |
| 9687 | cursor_row = row + off; |
| 9688 | |
| 9689 | /* |
| 9690 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9691 | * Clear the inserted lines in ScreenLines[]. |
| 9692 | */ |
| 9693 | row += off; |
| 9694 | end += off; |
| 9695 | for (i = 0; i < line_count; ++i) |
| 9696 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9697 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9698 | if (wp != NULL && wp->w_width != Columns) |
| 9699 | { |
| 9700 | /* need to copy part of a line */ |
| 9701 | j = end - 1 - i; |
| 9702 | while ((j -= line_count) >= row) |
| 9703 | linecopy(j + line_count, j, wp); |
| 9704 | j += line_count; |
| 9705 | if (can_clear((char_u *)" ")) |
| 9706 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9707 | else |
| 9708 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9709 | LineWraps[j] = FALSE; |
| 9710 | } |
| 9711 | else |
| 9712 | #endif |
| 9713 | { |
| 9714 | j = end - 1 - i; |
| 9715 | temp = LineOffset[j]; |
| 9716 | while ((j -= line_count) >= row) |
| 9717 | { |
| 9718 | LineOffset[j + line_count] = LineOffset[j]; |
| 9719 | LineWraps[j + line_count] = LineWraps[j]; |
| 9720 | } |
| 9721 | LineOffset[j + line_count] = temp; |
| 9722 | LineWraps[j + line_count] = FALSE; |
| 9723 | if (can_clear((char_u *)" ")) |
| 9724 | lineclear(temp, (int)Columns); |
| 9725 | else |
| 9726 | lineinvalid(temp, (int)Columns); |
| 9727 | } |
| 9728 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9729 | |
| 9730 | screen_stop_highlight(); |
| 9731 | windgoto(cursor_row, 0); |
| 9732 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9733 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9734 | /* redraw the characters */ |
| 9735 | if (type == USE_REDRAW) |
| 9736 | redraw_block(row, end, wp); |
| 9737 | else |
| 9738 | #endif |
| 9739 | if (type == USE_T_CAL) |
| 9740 | { |
| 9741 | term_append_lines(line_count); |
| 9742 | screen_start(); /* don't know where cursor is now */ |
| 9743 | } |
| 9744 | else |
| 9745 | { |
| 9746 | for (i = 0; i < line_count; i++) |
| 9747 | { |
| 9748 | if (type == USE_T_AL) |
| 9749 | { |
| 9750 | if (i && cursor_row != 0) |
| 9751 | windgoto(cursor_row, 0); |
| 9752 | out_str(T_AL); |
| 9753 | } |
| 9754 | else /* type == USE_T_SR */ |
| 9755 | out_str(T_SR); |
| 9756 | screen_start(); /* don't know where cursor is now */ |
| 9757 | } |
| 9758 | } |
| 9759 | |
| 9760 | /* |
| 9761 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9762 | * have been scrolled down into the region. |
| 9763 | */ |
| 9764 | if (type == USE_T_SR && *T_DA) |
| 9765 | { |
| 9766 | for (i = 0; i < line_count; ++i) |
| 9767 | { |
| 9768 | windgoto(off + i, 0); |
| 9769 | out_str(T_CE); |
| 9770 | screen_start(); /* don't know where cursor is now */ |
| 9771 | } |
| 9772 | } |
| 9773 | |
| 9774 | #ifdef FEAT_GUI |
| 9775 | gui_can_update_cursor(); |
| 9776 | if (gui.in_use) |
| 9777 | out_flush(); /* always flush after a scroll */ |
| 9778 | #endif |
| 9779 | return OK; |
| 9780 | } |
| 9781 | |
| 9782 | /* |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 9783 | * Delete lines on the screen and update ScreenLines[]. |
| 9784 | * "end" is the line after the scrolled part. Normally it is Rows. |
| 9785 | * When scrolling region used "off" is the offset from the top for the region. |
| 9786 | * "row" and "end" are relative to the start of the region. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9787 | * |
| 9788 | * Return OK for success, FAIL if the lines are not deleted. |
| 9789 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9790 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9791 | screen_del_lines( |
| 9792 | int off, |
| 9793 | int row, |
| 9794 | int line_count, |
| 9795 | int end, |
| 9796 | int force, /* even when line_count > p_ttyscroll */ |
| 9797 | win_T *wp UNUSED) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9798 | { |
| 9799 | int j; |
| 9800 | int i; |
| 9801 | unsigned temp; |
| 9802 | int cursor_row; |
| 9803 | int cursor_end; |
| 9804 | int result_empty; /* result is empty until end of region */ |
| 9805 | int can_delete; /* deleting line codes can be used */ |
| 9806 | int type; |
| 9807 | |
| 9808 | /* |
| 9809 | * FAIL if |
| 9810 | * - there is no valid screen |
| 9811 | * - the screen has to be redrawn completely |
| 9812 | * - the line count is less than one |
| 9813 | * - the line count is more than 'ttyscroll' |
| 9814 | */ |
| 9815 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9816 | (!force && line_count > p_ttyscroll)) |
| 9817 | return FAIL; |
| 9818 | |
| 9819 | /* |
| 9820 | * Check if the rest of the current region will become empty. |
| 9821 | */ |
| 9822 | result_empty = row + line_count >= end; |
| 9823 | |
| 9824 | /* |
| 9825 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9826 | * available. |
| 9827 | */ |
| 9828 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9829 | |
| 9830 | /* |
| 9831 | * There are six ways to delete lines: |
| 9832 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9833 | * characters from ScreenLines[]. |
| 9834 | * 1. Use T_CD if it exists and the result is empty. |
| 9835 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9836 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9837 | * none of the other ways work. |
| 9838 | * 4. Use T_CE (erase line) if the result is empty. |
| 9839 | * 5. Use T_DL (delete line) if it exists. |
| 9840 | * 6. redraw the characters from ScreenLines[]. |
| 9841 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9842 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9843 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9844 | type = USE_REDRAW; |
| 9845 | else |
| 9846 | #endif |
| 9847 | if (can_clear(T_CD) && result_empty) |
| 9848 | type = USE_T_CD; |
| 9849 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9850 | /* |
| 9851 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9852 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9853 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9854 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9855 | * the trick... |
| 9856 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9857 | * (Olaf Seibert) |
| 9858 | */ |
| 9859 | else if (row == 0 && T_DB == empty_option |
| 9860 | && (line_count == 1 || *T_CDL == NUL)) |
| 9861 | #else |
| 9862 | else if (row == 0 && ( |
| 9863 | #ifndef AMIGA |
| 9864 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9865 | * up, so use delete-line command */ |
| 9866 | line_count == 1 || |
| 9867 | #endif |
| 9868 | *T_CDL == NUL)) |
| 9869 | #endif |
| 9870 | type = USE_NL; |
| 9871 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9872 | type = USE_T_CDL; |
| 9873 | else if (can_clear(T_CE) && result_empty |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9874 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9875 | && (wp == NULL || wp->w_width == Columns) |
| 9876 | #endif |
| 9877 | ) |
| 9878 | type = USE_T_CE; |
| 9879 | else if (*T_DL != NUL && can_delete) |
| 9880 | type = USE_T_DL; |
| 9881 | else if (*T_CDL != NUL && can_delete) |
| 9882 | type = USE_T_CDL; |
| 9883 | else |
| 9884 | return FAIL; |
| 9885 | |
| 9886 | #ifdef FEAT_CLIPBOARD |
| 9887 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9888 | * not the full width of the screen. */ |
| 9889 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9890 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9891 | || (wp != NULL && wp->w_width != Columns) |
| 9892 | # endif |
| 9893 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9894 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9895 | else |
| 9896 | clip_scroll_selection(line_count); |
| 9897 | #endif |
| 9898 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9899 | #ifdef FEAT_GUI |
| 9900 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9901 | * scrolling is actually carried out. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 9902 | gui_dont_update_cursor(gui.cursor_row >= row + off |
| 9903 | && gui.cursor_row < end + off); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9904 | #endif |
| 9905 | |
| 9906 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9907 | { |
| 9908 | cursor_row = row; |
| 9909 | cursor_end = end; |
| 9910 | } |
| 9911 | else |
| 9912 | { |
| 9913 | cursor_row = row + off; |
| 9914 | cursor_end = end + off; |
| 9915 | } |
| 9916 | |
| 9917 | /* |
| 9918 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9919 | * Clear the inserted lines in ScreenLines[]. |
| 9920 | */ |
| 9921 | row += off; |
| 9922 | end += off; |
| 9923 | for (i = 0; i < line_count; ++i) |
| 9924 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9925 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9926 | if (wp != NULL && wp->w_width != Columns) |
| 9927 | { |
| 9928 | /* need to copy part of a line */ |
| 9929 | j = row + i; |
| 9930 | while ((j += line_count) <= end - 1) |
| 9931 | linecopy(j - line_count, j, wp); |
| 9932 | j -= line_count; |
| 9933 | if (can_clear((char_u *)" ")) |
| 9934 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9935 | else |
| 9936 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9937 | LineWraps[j] = FALSE; |
| 9938 | } |
| 9939 | else |
| 9940 | #endif |
| 9941 | { |
| 9942 | /* whole width, moving the line pointers is faster */ |
| 9943 | j = row + i; |
| 9944 | temp = LineOffset[j]; |
| 9945 | while ((j += line_count) <= end - 1) |
| 9946 | { |
| 9947 | LineOffset[j - line_count] = LineOffset[j]; |
| 9948 | LineWraps[j - line_count] = LineWraps[j]; |
| 9949 | } |
| 9950 | LineOffset[j - line_count] = temp; |
| 9951 | LineWraps[j - line_count] = FALSE; |
| 9952 | if (can_clear((char_u *)" ")) |
| 9953 | lineclear(temp, (int)Columns); |
| 9954 | else |
| 9955 | lineinvalid(temp, (int)Columns); |
| 9956 | } |
| 9957 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9958 | |
| 9959 | screen_stop_highlight(); |
| 9960 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9961 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9962 | /* redraw the characters */ |
| 9963 | if (type == USE_REDRAW) |
| 9964 | redraw_block(row, end, wp); |
| 9965 | else |
| 9966 | #endif |
| 9967 | if (type == USE_T_CD) /* delete the lines */ |
| 9968 | { |
| 9969 | windgoto(cursor_row, 0); |
| 9970 | out_str(T_CD); |
| 9971 | screen_start(); /* don't know where cursor is now */ |
| 9972 | } |
| 9973 | else if (type == USE_T_CDL) |
| 9974 | { |
| 9975 | windgoto(cursor_row, 0); |
| 9976 | term_delete_lines(line_count); |
| 9977 | screen_start(); /* don't know where cursor is now */ |
| 9978 | } |
| 9979 | /* |
| 9980 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9981 | * the whole screen (scroll region) up by outputting newlines on the |
| 9982 | * last line. |
| 9983 | */ |
| 9984 | else if (type == USE_NL) |
| 9985 | { |
| 9986 | windgoto(cursor_end - 1, 0); |
| 9987 | for (i = line_count; --i >= 0; ) |
| 9988 | out_char('\n'); /* cursor will remain on same line */ |
| 9989 | } |
| 9990 | else |
| 9991 | { |
| 9992 | for (i = line_count; --i >= 0; ) |
| 9993 | { |
| 9994 | if (type == USE_T_DL) |
| 9995 | { |
| 9996 | windgoto(cursor_row, 0); |
| 9997 | out_str(T_DL); /* delete a line */ |
| 9998 | } |
| 9999 | else /* type == USE_T_CE */ |
| 10000 | { |
| 10001 | windgoto(cursor_row + i, 0); |
| 10002 | out_str(T_CE); /* erase a line */ |
| 10003 | } |
| 10004 | screen_start(); /* don't know where cursor is now */ |
| 10005 | } |
| 10006 | } |
| 10007 | |
| 10008 | /* |
| 10009 | * If the 'db' flag is set, we need to clear the lines that have been |
| 10010 | * scrolled up at the bottom of the region. |
| 10011 | */ |
| 10012 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 10013 | { |
| 10014 | for (i = line_count; i > 0; --i) |
| 10015 | { |
| 10016 | windgoto(cursor_end - i, 0); |
| 10017 | out_str(T_CE); /* erase a line */ |
| 10018 | screen_start(); /* don't know where cursor is now */ |
| 10019 | } |
| 10020 | } |
| 10021 | |
| 10022 | #ifdef FEAT_GUI |
| 10023 | gui_can_update_cursor(); |
| 10024 | if (gui.in_use) |
| 10025 | out_flush(); /* always flush after a scroll */ |
| 10026 | #endif |
| 10027 | |
| 10028 | return OK; |
| 10029 | } |
| 10030 | |
| 10031 | /* |
| 10032 | * show the current mode and ruler |
| 10033 | * |
| 10034 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 10035 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 10036 | * cleared only if a mode is shown. |
| 10037 | * Return the length of the message (0 if no message). |
| 10038 | */ |
| 10039 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10040 | showmode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10041 | { |
| 10042 | int need_clear; |
| 10043 | int length = 0; |
| 10044 | int do_mode; |
| 10045 | int attr; |
| 10046 | int nwr_save; |
| 10047 | #ifdef FEAT_INS_EXPAND |
| 10048 | int sub_attr; |
| 10049 | #endif |
| 10050 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 10051 | do_mode = ((p_smd && msg_silent == 0) |
| 10052 | && ((State & INSERT) |
| 10053 | || restart_edit |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 10054 | || VIsual_active)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10055 | if (do_mode || Recording) |
| 10056 | { |
| 10057 | /* |
| 10058 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 10059 | * Call char_avail() only when we are going to show something, because |
| 10060 | * it takes a bit of time. |
| 10061 | */ |
| 10062 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 10063 | { |
| 10064 | redraw_cmdline = TRUE; /* show mode later */ |
| 10065 | return 0; |
| 10066 | } |
| 10067 | |
| 10068 | nwr_save = need_wait_return; |
| 10069 | |
| 10070 | /* wait a bit before overwriting an important message */ |
| 10071 | check_for_delay(FALSE); |
| 10072 | |
| 10073 | /* if the cmdline is more than one line high, erase top lines */ |
| 10074 | need_clear = clear_cmdline; |
| 10075 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 10076 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 10077 | |
| 10078 | /* Position on the last line in the window, column 0 */ |
| 10079 | msg_pos_mode(); |
| 10080 | cursor_off(); |
| 10081 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 10082 | if (do_mode) |
| 10083 | { |
| 10084 | MSG_PUTS_ATTR("--", attr); |
| 10085 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10086 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10087 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10088 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10089 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10090 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10091 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10092 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 10093 | # 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] | 10094 | MSG_PUTS_ATTR(" IM", attr); |
| 10095 | # else |
| 10096 | MSG_PUTS_ATTR(" XIM", attr); |
| 10097 | # endif |
| 10098 | #endif |
| 10099 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 10100 | if (gui.in_use) |
| 10101 | { |
| 10102 | if (hangul_input_state_get()) |
Bram Moolenaar | 72f4cc4 | 2015-11-10 14:35:18 +0100 | [diff] [blame] | 10103 | { |
| 10104 | /* HANGUL */ |
| 10105 | if (enc_utf8) |
| 10106 | MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr); |
| 10107 | else |
| 10108 | MSG_PUTS_ATTR(" \307\321\261\333", attr); |
| 10109 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10110 | } |
| 10111 | #endif |
| 10112 | #ifdef FEAT_INS_EXPAND |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 10113 | /* CTRL-X in Insert mode */ |
| 10114 | if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10115 | { |
| 10116 | /* These messages can get long, avoid a wrap in a narrow |
| 10117 | * window. Prefer showing edit_submode_extra. */ |
| 10118 | length = (Rows - msg_row) * Columns - 3; |
| 10119 | if (edit_submode_extra != NULL) |
| 10120 | length -= vim_strsize(edit_submode_extra); |
| 10121 | if (length > 0) |
| 10122 | { |
| 10123 | if (edit_submode_pre != NULL) |
| 10124 | length -= vim_strsize(edit_submode_pre); |
| 10125 | if (length - vim_strsize(edit_submode) > 0) |
| 10126 | { |
| 10127 | if (edit_submode_pre != NULL) |
| 10128 | msg_puts_attr(edit_submode_pre, attr); |
| 10129 | msg_puts_attr(edit_submode, attr); |
| 10130 | } |
| 10131 | if (edit_submode_extra != NULL) |
| 10132 | { |
| 10133 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 10134 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 10135 | sub_attr = hl_attr(edit_submode_highl); |
| 10136 | else |
| 10137 | sub_attr = attr; |
| 10138 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 10139 | } |
| 10140 | } |
| 10141 | length = 0; |
| 10142 | } |
| 10143 | else |
| 10144 | #endif |
| 10145 | { |
| 10146 | #ifdef FEAT_VREPLACE |
| 10147 | if (State & VREPLACE_FLAG) |
| 10148 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 10149 | else |
| 10150 | #endif |
| 10151 | if (State & REPLACE_FLAG) |
| 10152 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 10153 | else if (State & INSERT) |
| 10154 | { |
| 10155 | #ifdef FEAT_RIGHTLEFT |
| 10156 | if (p_ri) |
| 10157 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 10158 | #endif |
| 10159 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 10160 | } |
| 10161 | else if (restart_edit == 'I') |
| 10162 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 10163 | else if (restart_edit == 'R') |
| 10164 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 10165 | else if (restart_edit == 'V') |
| 10166 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 10167 | #ifdef FEAT_RIGHTLEFT |
| 10168 | if (p_hkmap) |
| 10169 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 10170 | # ifdef FEAT_FKMAP |
| 10171 | if (p_fkmap) |
| 10172 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 10173 | # endif |
| 10174 | #endif |
| 10175 | #ifdef FEAT_KEYMAP |
| 10176 | if (State & LANGMAP) |
| 10177 | { |
| 10178 | # ifdef FEAT_ARABIC |
| 10179 | if (curwin->w_p_arab) |
| 10180 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 10181 | else |
| 10182 | # endif |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 10183 | if (get_keymap_str(curwin, (char_u *)" (%s)", |
| 10184 | NameBuff, MAXPATHL)) |
| 10185 | MSG_PUTS_ATTR(NameBuff, attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10186 | } |
| 10187 | #endif |
| 10188 | if ((State & INSERT) && p_paste) |
| 10189 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 10190 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10191 | if (VIsual_active) |
| 10192 | { |
| 10193 | char *p; |
| 10194 | |
| 10195 | /* Don't concatenate separate words to avoid translation |
| 10196 | * problems. */ |
| 10197 | switch ((VIsual_select ? 4 : 0) |
| 10198 | + (VIsual_mode == Ctrl_V) * 2 |
| 10199 | + (VIsual_mode == 'V')) |
| 10200 | { |
| 10201 | case 0: p = N_(" VISUAL"); break; |
| 10202 | case 1: p = N_(" VISUAL LINE"); break; |
| 10203 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 10204 | case 4: p = N_(" SELECT"); break; |
| 10205 | case 5: p = N_(" SELECT LINE"); break; |
| 10206 | default: p = N_(" SELECT BLOCK"); break; |
| 10207 | } |
| 10208 | MSG_PUTS_ATTR(_(p), attr); |
| 10209 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10210 | MSG_PUTS_ATTR(" --", attr); |
| 10211 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10212 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10213 | need_clear = TRUE; |
| 10214 | } |
| 10215 | if (Recording |
| 10216 | #ifdef FEAT_INS_EXPAND |
| 10217 | && edit_submode == NULL /* otherwise it gets too long */ |
| 10218 | #endif |
| 10219 | ) |
| 10220 | { |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10221 | recording_mode(attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10222 | need_clear = TRUE; |
| 10223 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10224 | |
| 10225 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10226 | if (need_clear || clear_cmdline) |
| 10227 | msg_clr_eos(); |
| 10228 | msg_didout = FALSE; /* overwrite this message */ |
| 10229 | length = msg_col; |
| 10230 | msg_col = 0; |
| 10231 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 10232 | } |
| 10233 | else if (clear_cmdline && msg_silent == 0) |
| 10234 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 10235 | msg_clr_cmdline(); |
| 10236 | |
| 10237 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10238 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 10239 | if (VIsual_active) |
| 10240 | clear_showcmd(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10241 | |
| 10242 | /* If the last window has no status line, the ruler is after the mode |
| 10243 | * message and must be redrawn */ |
| 10244 | if (redrawing() |
| 10245 | # ifdef FEAT_WINDOWS |
| 10246 | && lastwin->w_status_height == 0 |
| 10247 | # endif |
| 10248 | ) |
| 10249 | win_redr_ruler(lastwin, TRUE); |
| 10250 | #endif |
| 10251 | redraw_cmdline = FALSE; |
| 10252 | clear_cmdline = FALSE; |
| 10253 | |
| 10254 | return length; |
| 10255 | } |
| 10256 | |
| 10257 | /* |
| 10258 | * Position for a mode message. |
| 10259 | */ |
| 10260 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10261 | msg_pos_mode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10262 | { |
| 10263 | msg_col = 0; |
| 10264 | msg_row = Rows - 1; |
| 10265 | } |
| 10266 | |
| 10267 | /* |
| 10268 | * Delete mode message. Used when ESC is typed which is expected to end |
| 10269 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10270 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10271 | */ |
| 10272 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10273 | unshowmode(int force) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10274 | { |
| 10275 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 10276 | * 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] | 10277 | */ |
| 10278 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 10279 | redraw_cmdline = TRUE; /* delete mode later */ |
| 10280 | else |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10281 | clearmode(); |
| 10282 | } |
| 10283 | |
| 10284 | /* |
| 10285 | * Clear the mode message. |
| 10286 | */ |
| 10287 | void |
Bram Moolenaar | cf08946 | 2016-06-12 21:18:43 +0200 | [diff] [blame] | 10288 | clearmode(void) |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10289 | { |
| 10290 | msg_pos_mode(); |
| 10291 | if (Recording) |
| 10292 | recording_mode(hl_attr(HLF_CM)); |
| 10293 | msg_clr_eos(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10294 | } |
| 10295 | |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10296 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10297 | recording_mode(int attr) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10298 | { |
| 10299 | MSG_PUTS_ATTR(_("recording"), attr); |
| 10300 | if (!shortmess(SHM_RECORDING)) |
| 10301 | { |
| 10302 | char_u s[4]; |
| 10303 | sprintf((char *)s, " @%c", Recording); |
| 10304 | MSG_PUTS_ATTR(s, attr); |
| 10305 | } |
| 10306 | } |
| 10307 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10308 | #if defined(FEAT_WINDOWS) |
| 10309 | /* |
| 10310 | * Draw the tab pages line at the top of the Vim window. |
| 10311 | */ |
| 10312 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10313 | draw_tabline(void) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10314 | { |
| 10315 | int tabcount = 0; |
| 10316 | tabpage_T *tp; |
| 10317 | int tabwidth; |
| 10318 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10319 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10320 | int attr; |
| 10321 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10322 | win_T *cwp; |
| 10323 | int wincount; |
| 10324 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10325 | int c; |
| 10326 | int len; |
| 10327 | int attr_sel = hl_attr(HLF_TPS); |
| 10328 | int attr_nosel = hl_attr(HLF_TP); |
| 10329 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10330 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10331 | int room; |
| 10332 | int use_sep_chars = (t_colors < 8 |
| 10333 | #ifdef FEAT_GUI |
| 10334 | && !gui.in_use |
| 10335 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 10336 | #ifdef FEAT_TERMGUICOLORS |
| 10337 | && !p_tgc |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 10338 | #endif |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10339 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10340 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10341 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10342 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10343 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 10344 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10345 | if (gui_use_tabline()) |
| 10346 | { |
| 10347 | gui_update_tabline(); |
| 10348 | return; |
| 10349 | } |
| 10350 | #endif |
| 10351 | |
| 10352 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10353 | return; |
| 10354 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10355 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10356 | |
| 10357 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 10358 | for (scol = 0; scol < Columns; ++scol) |
| 10359 | TabPageIdxs[scol] = 0; |
| 10360 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10361 | /* Use the 'tabline' option if it's set. */ |
| 10362 | if (*p_tal != NUL) |
| 10363 | { |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10364 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10365 | |
| 10366 | /* Check for an error. If there is one we would loop in redrawing the |
| 10367 | * screen. Avoid that by making 'tabline' empty. */ |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10368 | did_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10369 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10370 | if (did_emsg) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10371 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10372 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10373 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10374 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10375 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10376 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10377 | { |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 10378 | FOR_ALL_TABPAGES(tp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10379 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10380 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10381 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 10382 | if (tabwidth < 6) |
| 10383 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10384 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10385 | attr = attr_nosel; |
| 10386 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10387 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10388 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 10389 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10390 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10391 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10392 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10393 | if (tp->tp_topframe == topframe) |
| 10394 | attr = attr_sel; |
| 10395 | if (use_sep_chars && col > 0) |
| 10396 | screen_putchar('|', 0, col++, attr); |
| 10397 | |
| 10398 | if (tp->tp_topframe != topframe) |
| 10399 | attr = attr_nosel; |
| 10400 | |
| 10401 | screen_putchar(' ', 0, col++, attr); |
| 10402 | |
| 10403 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10404 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10405 | cwp = curwin; |
| 10406 | wp = firstwin; |
| 10407 | } |
| 10408 | else |
| 10409 | { |
| 10410 | cwp = tp->tp_curwin; |
| 10411 | wp = tp->tp_firstwin; |
| 10412 | } |
| 10413 | |
| 10414 | modified = FALSE; |
| 10415 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 10416 | if (bufIsChanged(wp->w_buffer)) |
| 10417 | modified = TRUE; |
| 10418 | if (modified || wincount > 1) |
| 10419 | { |
| 10420 | if (wincount > 1) |
| 10421 | { |
| 10422 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10423 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10424 | if (col + len >= Columns - 3) |
| 10425 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10426 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10427 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10428 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10429 | #else |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10430 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10431 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10432 | ); |
| 10433 | col += len; |
| 10434 | } |
| 10435 | if (modified) |
| 10436 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 10437 | screen_putchar(' ', 0, col++, attr); |
| 10438 | } |
| 10439 | |
| 10440 | room = scol - col + tabwidth - 1; |
| 10441 | if (room > 0) |
| 10442 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10443 | /* Get buffer name in NameBuff[] */ |
| 10444 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 10445 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10446 | len = vim_strsize(NameBuff); |
| 10447 | p = NameBuff; |
| 10448 | #ifdef FEAT_MBYTE |
| 10449 | if (has_mbyte) |
| 10450 | while (len > room) |
| 10451 | { |
| 10452 | len -= ptr2cells(p); |
| 10453 | mb_ptr_adv(p); |
| 10454 | } |
| 10455 | else |
| 10456 | #endif |
| 10457 | if (len > room) |
| 10458 | { |
| 10459 | p += len - room; |
| 10460 | len = room; |
| 10461 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10462 | if (len > Columns - col - 1) |
| 10463 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10464 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10465 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10466 | col += len; |
| 10467 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10468 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10469 | |
| 10470 | /* Store the tab page number in TabPageIdxs[], so that |
| 10471 | * jump_to_mouse() knows where each one is. */ |
| 10472 | ++tabcount; |
| 10473 | while (scol < col) |
| 10474 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10475 | } |
| 10476 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10477 | if (use_sep_chars) |
| 10478 | c = '_'; |
| 10479 | else |
| 10480 | c = ' '; |
| 10481 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10482 | |
| 10483 | /* Put an "X" for closing the current tab if there are several. */ |
| 10484 | if (first_tabpage->tp_next != NULL) |
| 10485 | { |
| 10486 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 10487 | TabPageIdxs[Columns - 1] = -999; |
| 10488 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10489 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 10490 | |
| 10491 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 10492 | * set. */ |
| 10493 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10494 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10495 | |
| 10496 | /* |
| 10497 | * Get buffer name for "buf" into NameBuff[]. |
| 10498 | * Takes care of special buffer names and translates special characters. |
| 10499 | */ |
| 10500 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10501 | get_trans_bufname(buf_T *buf) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10502 | { |
| 10503 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 10504 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10505 | else |
| 10506 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 10507 | trans_characters(NameBuff, MAXPATHL); |
| 10508 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10509 | #endif |
| 10510 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10511 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 10512 | /* |
| 10513 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 10514 | */ |
| 10515 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10516 | fillchar_status(int *attr, int is_curwin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10517 | { |
| 10518 | int fill; |
| 10519 | if (is_curwin) |
| 10520 | { |
| 10521 | *attr = hl_attr(HLF_S); |
| 10522 | fill = fill_stl; |
| 10523 | } |
| 10524 | else |
| 10525 | { |
| 10526 | *attr = hl_attr(HLF_SNC); |
| 10527 | fill = fill_stlnc; |
| 10528 | } |
| 10529 | /* Use fill when there is highlighting, and highlighting of current |
| 10530 | * window differs, or the fillchars differ, or this is not the |
| 10531 | * current window */ |
| 10532 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
Bram Moolenaar | a1f4cb9 | 2016-11-06 15:25:42 +0100 | [diff] [blame] | 10533 | || !is_curwin || ONE_WINDOW) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10534 | || (fill_stl != fill_stlnc))) |
| 10535 | return fill; |
| 10536 | if (is_curwin) |
| 10537 | return '^'; |
| 10538 | return '='; |
| 10539 | } |
| 10540 | #endif |
| 10541 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10542 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10543 | /* |
| 10544 | * Get the character to use in a separator between vertically split windows. |
| 10545 | * Get its attributes in "*attr". |
| 10546 | */ |
| 10547 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10548 | fillchar_vsep(int *attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10549 | { |
| 10550 | *attr = hl_attr(HLF_C); |
| 10551 | if (*attr == 0 && fill_vert == ' ') |
| 10552 | return '|'; |
| 10553 | else |
| 10554 | return fill_vert; |
| 10555 | } |
| 10556 | #endif |
| 10557 | |
| 10558 | /* |
| 10559 | * Return TRUE if redrawing should currently be done. |
| 10560 | */ |
| 10561 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10562 | redrawing(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10563 | { |
| 10564 | return (!RedrawingDisabled |
| 10565 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 10566 | } |
| 10567 | |
| 10568 | /* |
| 10569 | * Return TRUE if printing messages should currently be done. |
| 10570 | */ |
| 10571 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10572 | messaging(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10573 | { |
| 10574 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10575 | } |
| 10576 | |
| 10577 | /* |
| 10578 | * Show current status info in ruler and various other places |
| 10579 | * If always is FALSE, only show ruler if position has changed. |
| 10580 | */ |
| 10581 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10582 | showruler(int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10583 | { |
| 10584 | if (!always && !redrawing()) |
| 10585 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10586 | #ifdef FEAT_INS_EXPAND |
| 10587 | if (pum_visible()) |
| 10588 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10589 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10590 | /* Don't redraw right now, do it later. */ |
| 10591 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10592 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10593 | return; |
| 10594 | } |
| 10595 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10596 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10597 | 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] | 10598 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10599 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10600 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10601 | else |
| 10602 | #endif |
| 10603 | #ifdef FEAT_CMDL_INFO |
| 10604 | win_redr_ruler(curwin, always); |
| 10605 | #endif |
| 10606 | |
| 10607 | #ifdef FEAT_TITLE |
| 10608 | if (need_maketitle |
| 10609 | # ifdef FEAT_STL_OPT |
| 10610 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10611 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10612 | # endif |
| 10613 | ) |
| 10614 | maketitle(); |
| 10615 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10616 | #ifdef FEAT_WINDOWS |
| 10617 | /* Redraw the tab pages line if needed. */ |
| 10618 | if (redraw_tabline) |
| 10619 | draw_tabline(); |
| 10620 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10621 | } |
| 10622 | |
| 10623 | #ifdef FEAT_CMDL_INFO |
| 10624 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10625 | win_redr_ruler(win_T *wp, int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10626 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10627 | #define RULER_BUF_LEN 70 |
| 10628 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10629 | int row; |
| 10630 | int fillchar; |
| 10631 | int attr; |
| 10632 | int empty_line = FALSE; |
| 10633 | colnr_T virtcol; |
| 10634 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10635 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10636 | int o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10637 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10638 | int this_ru_col; |
| 10639 | int off = 0; |
| 10640 | int width = Columns; |
| 10641 | # define WITH_OFF(x) x |
| 10642 | # define WITH_WIDTH(x) x |
| 10643 | #else |
| 10644 | # define WITH_OFF(x) 0 |
| 10645 | # define WITH_WIDTH(x) Columns |
| 10646 | # define this_ru_col ru_col |
| 10647 | #endif |
| 10648 | |
| 10649 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10650 | if (!p_ru) |
| 10651 | return; |
| 10652 | |
| 10653 | /* |
| 10654 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10655 | * after deleting lines, before cursor.lnum is corrected. |
| 10656 | */ |
| 10657 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10658 | return; |
| 10659 | |
| 10660 | #ifdef FEAT_INS_EXPAND |
| 10661 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10662 | * the (long) mode message. */ |
| 10663 | # ifdef FEAT_WINDOWS |
| 10664 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10665 | # endif |
| 10666 | if (edit_submode != NULL) |
| 10667 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10668 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10669 | if (pum_visible()) |
| 10670 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10671 | #endif |
| 10672 | |
| 10673 | #ifdef FEAT_STL_OPT |
| 10674 | if (*p_ruf) |
| 10675 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10676 | int save_called_emsg = called_emsg; |
| 10677 | |
| 10678 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10679 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10680 | if (called_emsg) |
| 10681 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10682 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10683 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10684 | return; |
| 10685 | } |
| 10686 | #endif |
| 10687 | |
| 10688 | /* |
| 10689 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10690 | */ |
| 10691 | if (!(State & INSERT) |
| 10692 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10693 | empty_line = TRUE; |
| 10694 | |
| 10695 | /* |
| 10696 | * Only draw the ruler when something changed. |
| 10697 | */ |
| 10698 | validate_virtcol_win(wp); |
| 10699 | if ( redraw_cmdline |
| 10700 | || always |
| 10701 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10702 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10703 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10704 | #ifdef FEAT_VIRTUALEDIT |
| 10705 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10706 | #endif |
| 10707 | || wp->w_topline != wp->w_ru_topline |
| 10708 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10709 | #ifdef FEAT_DIFF |
| 10710 | || wp->w_topfill != wp->w_ru_topfill |
| 10711 | #endif |
| 10712 | || empty_line != wp->w_ru_empty) |
| 10713 | { |
| 10714 | cursor_off(); |
| 10715 | #ifdef FEAT_WINDOWS |
| 10716 | if (wp->w_status_height) |
| 10717 | { |
| 10718 | row = W_WINROW(wp) + wp->w_height; |
| 10719 | fillchar = fillchar_status(&attr, wp == curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10720 | off = W_WINCOL(wp); |
| 10721 | width = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10722 | } |
| 10723 | else |
| 10724 | #endif |
| 10725 | { |
| 10726 | row = Rows - 1; |
| 10727 | fillchar = ' '; |
| 10728 | attr = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10729 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10730 | width = Columns; |
| 10731 | off = 0; |
| 10732 | #endif |
| 10733 | } |
| 10734 | |
| 10735 | /* In list mode virtcol needs to be recomputed */ |
| 10736 | virtcol = wp->w_virtcol; |
| 10737 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10738 | { |
| 10739 | wp->w_p_list = FALSE; |
| 10740 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10741 | wp->w_p_list = TRUE; |
| 10742 | } |
| 10743 | |
| 10744 | /* |
| 10745 | * Some sprintfs return the length, some return a pointer. |
| 10746 | * To avoid portability problems we use strlen() here. |
| 10747 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10748 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10749 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10750 | ? 0L |
| 10751 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10752 | len = STRLEN(buffer); |
| 10753 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10754 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10755 | (int)virtcol + 1); |
| 10756 | |
| 10757 | /* |
| 10758 | * Add a "50%" if there is room for it. |
| 10759 | * On the last line, don't print in the last column (scrolls the |
| 10760 | * screen up on some terminals). |
| 10761 | */ |
| 10762 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10763 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10764 | o = i + vim_strsize(buffer + i + 1); |
| 10765 | #ifdef FEAT_WINDOWS |
| 10766 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10767 | #endif |
| 10768 | ++o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10769 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10770 | this_ru_col = ru_col - (Columns - width); |
| 10771 | if (this_ru_col < 0) |
| 10772 | this_ru_col = 0; |
| 10773 | #endif |
| 10774 | /* Never use more than half the window/screen width, leave the other |
| 10775 | * half for the filename. */ |
| 10776 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10777 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10778 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10779 | { |
Bram Moolenaar | 0027c21 | 2015-01-07 13:31:52 +0100 | [diff] [blame] | 10780 | /* need at least 3 chars left for get_rel_pos() + NUL */ |
| 10781 | 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] | 10782 | { |
| 10783 | #ifdef FEAT_MBYTE |
| 10784 | if (has_mbyte) |
| 10785 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10786 | else |
| 10787 | #endif |
| 10788 | buffer[i++] = fillchar; |
| 10789 | ++o; |
| 10790 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10791 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10792 | } |
| 10793 | /* Truncate at window boundary. */ |
| 10794 | #ifdef FEAT_MBYTE |
| 10795 | if (has_mbyte) |
| 10796 | { |
| 10797 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10798 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10799 | { |
| 10800 | o += (*mb_ptr2cells)(buffer + i); |
| 10801 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10802 | { |
| 10803 | buffer[i] = NUL; |
| 10804 | break; |
| 10805 | } |
| 10806 | } |
| 10807 | } |
| 10808 | else |
| 10809 | #endif |
| 10810 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10811 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10812 | |
| 10813 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10814 | i = redraw_cmdline; |
| 10815 | screen_fill(row, row + 1, |
| 10816 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10817 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10818 | fillchar, fillchar, attr); |
| 10819 | /* don't redraw the cmdline because of showing the ruler */ |
| 10820 | redraw_cmdline = i; |
| 10821 | wp->w_ru_cursor = wp->w_cursor; |
| 10822 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10823 | wp->w_ru_empty = empty_line; |
| 10824 | wp->w_ru_topline = wp->w_topline; |
| 10825 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10826 | #ifdef FEAT_DIFF |
| 10827 | wp->w_ru_topfill = wp->w_topfill; |
| 10828 | #endif |
| 10829 | } |
| 10830 | } |
| 10831 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10832 | |
| 10833 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10834 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10835 | * Return the width of the 'number' and 'relativenumber' column. |
| 10836 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10837 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10838 | */ |
| 10839 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10840 | number_width(win_T *wp) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10841 | { |
| 10842 | int n; |
| 10843 | linenr_T lnum; |
| 10844 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10845 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10846 | /* cursor line shows "0" */ |
| 10847 | lnum = wp->w_height; |
| 10848 | else |
| 10849 | /* cursor line shows absolute line number */ |
| 10850 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10851 | |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10852 | 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] | 10853 | return wp->w_nrwidth_width; |
| 10854 | wp->w_nrwidth_line_count = lnum; |
| 10855 | |
| 10856 | n = 0; |
| 10857 | do |
| 10858 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10859 | lnum /= 10; |
| 10860 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10861 | } while (lnum > 0); |
| 10862 | |
| 10863 | /* 'numberwidth' gives the minimal width plus one */ |
| 10864 | if (n < wp->w_p_nuw - 1) |
| 10865 | n = wp->w_p_nuw - 1; |
| 10866 | |
| 10867 | wp->w_nrwidth_width = n; |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10868 | wp->w_nuw_cached = wp->w_p_nuw; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10869 | return n; |
| 10870 | } |
| 10871 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10872 | |
| 10873 | /* |
| 10874 | * Return the current cursor column. This is the actual position on the |
| 10875 | * screen. First column is 0. |
| 10876 | */ |
| 10877 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10878 | screen_screencol(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10879 | { |
| 10880 | return screen_cur_col; |
| 10881 | } |
| 10882 | |
| 10883 | /* |
| 10884 | * Return the current cursor row. This is the actual position on the screen. |
| 10885 | * First row is 0. |
| 10886 | */ |
| 10887 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10888 | screen_screenrow(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10889 | { |
| 10890 | return screen_cur_row; |
| 10891 | } |