Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * screen.c: code for displaying on the screen |
| 12 | * |
| 13 | * Output to the screen (console, terminal emulator or GUI window) is minimized |
| 14 | * by remembering what is already on the screen, and only updating the parts |
| 15 | * that changed. |
| 16 | * |
| 17 | * ScreenLines[off] Contains a copy of the whole screen, as it is currently |
| 18 | * displayed (excluding text written by external commands). |
| 19 | * ScreenAttrs[off] Contains the associated attributes. |
| 20 | * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] |
| 21 | * for each line. |
| 22 | * LineWraps[row] Flag for each line whether it wraps to the next line. |
| 23 | * |
| 24 | * For double-byte characters, two consecutive bytes in ScreenLines[] can form |
| 25 | * one character which occupies two display cells. |
| 26 | * For UTF-8 a multi-byte character is converted to Unicode and stored in |
| 27 | * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 28 | * character without composing chars ScreenLinesUC[] will be 0 and |
| 29 | * ScreenLinesC[][] is not used. When the character occupies two display |
| 30 | * cells the next byte in ScreenLines[] is 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 31 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 32 | * (drawn on top of the first character). There is 0 after the last one used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | * ScreenLines2[] is only used for euc-jp to store the second byte if the |
| 34 | * first byte is 0x8e (single-width character). |
| 35 | * |
| 36 | * The screen_*() functions write to the screen and handle updating |
| 37 | * ScreenLines[]. |
| 38 | * |
| 39 | * update_screen() is the function that updates all windows and status lines. |
| 40 | * It is called form the main loop when must_redraw is non-zero. It may be |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 41 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | * |
| 43 | * The part of the buffer that is displayed in a window is set with: |
| 44 | * - w_topline (first buffer line in window) |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 45 | * - w_topfill (filler lines above the first line) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | * - w_leftcol (leftmost window cell in window), |
| 47 | * - w_skipcol (skipped window cells of first line) |
| 48 | * |
| 49 | * Commands that only move the cursor around in a window, do not need to take |
| 50 | * action to update the display. The main loop will check if w_topline is |
| 51 | * valid and update it (scroll the window) when needed. |
| 52 | * |
| 53 | * Commands that scroll a window change w_topline and must call |
| 54 | * check_cursor() to move the cursor into the visible part of the window, and |
| 55 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 56 | * later. |
| 57 | * |
| 58 | * Commands that change text in the buffer must call changed_bytes() or |
| 59 | * changed_lines() to mark the area that changed and will require updating |
| 60 | * later. The main loop will call update_screen(), which will update each |
| 61 | * window that shows the changed buffer. This assumes text above the change |
| 62 | * can remain displayed as it is. Text after the change may need updating for |
| 63 | * scrolling, folding and syntax highlighting. |
| 64 | * |
| 65 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 66 | * invalidate the contents of a window in another way (e.g., change fold |
| 67 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 68 | * redisplayed by update_screen() later. |
| 69 | * |
| 70 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 71 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 72 | * buffer redisplayed by update_screen() later. |
| 73 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 74 | * Commands that change highlighting and possibly cause a scroll too must call |
| 75 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 76 | * to avoid redrawing everything. But the length of displayed lines must not |
| 77 | * change, use NOT_VALID then. |
| 78 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 80 | * TODO: should minimize redrawing by scrolling when possible. |
| 81 | * |
| 82 | * Commands that change everything (e.g., resizing the screen) must call |
| 83 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 84 | * |
| 85 | * Things that are handled indirectly: |
| 86 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 87 | * update_screen() called to redraw. |
| 88 | */ |
| 89 | |
| 90 | #include "vim.h" |
| 91 | |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 92 | #define MB_FILLER_CHAR '<' /* character used when a double-width character |
| 93 | * doesn't fit. */ |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * The attributes that are actually active for writing to the screen. |
| 97 | */ |
| 98 | static int screen_attr = 0; |
| 99 | |
| 100 | /* |
| 101 | * Positioning the cursor is reduced by remembering the last position. |
| 102 | * Mostly used by windgoto() and screen_char(). |
| 103 | */ |
| 104 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 105 | |
| 106 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef FEAT_FOLDING |
| 111 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 112 | static int compute_foldcolumn(win_T *wp, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | /* |
| 116 | * Buffer for one screen line (characters and attributes). |
| 117 | */ |
| 118 | static schar_T *current_ScreenLine; |
| 119 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 120 | static void win_update(win_T *wp); |
| 121 | static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | #ifdef FEAT_FOLDING |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 123 | static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row); |
| 124 | static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum); |
| 125 | static void copy_text_attr(int off, char_u *buf, int len, int attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 127 | static int win_line(win_T *, linenr_T, int, int, int nochange); |
| 128 | static int char_needs_redraw(int off_from, int off_to, int cols); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 129 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 130 | static void screen_line(int row, int coloff, int endcol, int clear_width, int rlflag); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 132 | #else |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 133 | static void screen_line(int row, int coloff, int endcol, int clear_width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 135 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 136 | #ifdef FEAT_VERTSPLIT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 137 | static void draw_vsep_win(win_T *wp, int row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 139 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 140 | static void redraw_custom_statusline(win_T *wp); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 141 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 142 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 143 | # define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 144 | static void start_search_hl(void); |
| 145 | static void end_search_hl(void); |
| 146 | static void init_search_hl(win_T *wp); |
| 147 | static void prepare_search_hl(win_T *wp, linenr_T lnum); |
| 148 | static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur); |
| 149 | static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 150 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 151 | static void screen_start_highlight(int attr); |
| 152 | static void screen_char(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 154 | static void screen_char_2(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 155 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 156 | static void screenclear2(void); |
| 157 | static void lineclear(unsigned off, int width); |
| 158 | static void lineinvalid(unsigned off, int width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 159 | #ifdef FEAT_VERTSPLIT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 160 | static void linecopy(int to, int from, win_T *wp); |
| 161 | static void redraw_block(int row, int end, win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 163 | static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del); |
| 164 | static void win_rest_invalid(win_T *wp); |
| 165 | static void msg_pos_mode(void); |
| 166 | static void recording_mode(int attr); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 167 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 168 | static void draw_tabline(void); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 169 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 171 | static int fillchar_status(int *attr, int is_curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | #endif |
| 173 | #ifdef FEAT_VERTSPLIT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 174 | static int fillchar_vsep(int *attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | #endif |
| 176 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 177 | static void win_redr_custom(win_T *wp, int draw_ruler); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 178 | #endif |
| 179 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 180 | static void win_redr_ruler(win_T *wp, int always); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
| 183 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 184 | /* Ugly global: overrule attribute used by screen_char() */ |
| 185 | static int screen_char_attr = 0; |
| 186 | #endif |
| 187 | |
| 188 | /* |
| 189 | * Redraw the current window later, with update_screen(type). |
| 190 | * Set must_redraw only if not already set to a higher value. |
| 191 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 192 | */ |
| 193 | void |
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 | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 414 | * Changed something in the current window, at buffer line "lnum", that |
| 415 | * requires that line and possibly other lines to be redrawn. |
| 416 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 417 | * Used to remove the "$" from a change command. |
| 418 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 419 | * may become invalid and the whole window will have to be redrawn. |
| 420 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 421 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 422 | redrawWinline( |
| 423 | linenr_T lnum, |
| 424 | int invalid UNUSED) /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 425 | { |
| 426 | #ifdef FEAT_FOLDING |
| 427 | int i; |
| 428 | #endif |
| 429 | |
| 430 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 431 | curwin->w_redraw_top = lnum; |
| 432 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 433 | curwin->w_redraw_bot = lnum; |
| 434 | redraw_later(VALID); |
| 435 | |
| 436 | #ifdef FEAT_FOLDING |
| 437 | if (invalid) |
| 438 | { |
| 439 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 440 | i = find_wl_entry(curwin, lnum); |
| 441 | if (i >= 0) |
| 442 | curwin->w_lines[i].wl_valid = FALSE; |
| 443 | } |
| 444 | #endif |
| 445 | } |
| 446 | |
| 447 | /* |
| 448 | * update all windows that are editing the current buffer |
| 449 | */ |
| 450 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 451 | update_curbuf(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 452 | { |
| 453 | redraw_curbuf_later(type); |
| 454 | update_screen(type); |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * update_screen() |
| 459 | * |
| 460 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 461 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 462 | */ |
| 463 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 464 | update_screen(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 465 | { |
| 466 | win_T *wp; |
| 467 | static int did_intro = FALSE; |
| 468 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 469 | int did_one; |
| 470 | #endif |
| 471 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 472 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 473 | if (!screen_valid(TRUE)) |
| 474 | return; |
| 475 | |
| 476 | if (must_redraw) |
| 477 | { |
| 478 | if (type < must_redraw) /* use maximal type */ |
| 479 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 480 | |
| 481 | /* must_redraw is reset here, so that when we run into some weird |
| 482 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 483 | * scrolling), or update_topline() in win_update() will cause a |
| 484 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 485 | must_redraw = 0; |
| 486 | } |
| 487 | |
| 488 | /* Need to update w_lines[]. */ |
| 489 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 490 | type = NOT_VALID; |
| 491 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 492 | /* Postpone the redrawing when it's not needed and when being called |
| 493 | * recursively. */ |
| 494 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 495 | { |
| 496 | redraw_later(type); /* remember type for next time */ |
| 497 | must_redraw = type; |
| 498 | if (type > INVERTED_ALL) |
| 499 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 500 | return; |
| 501 | } |
| 502 | |
| 503 | updating_screen = TRUE; |
| 504 | #ifdef FEAT_SYN_HL |
| 505 | ++display_tick; /* let syntax code know we're in a next round of |
| 506 | * display updating */ |
| 507 | #endif |
| 508 | |
| 509 | /* |
| 510 | * if the screen was scrolled up when displaying a message, scroll it down |
| 511 | */ |
| 512 | if (msg_scrolled) |
| 513 | { |
| 514 | clear_cmdline = TRUE; |
| 515 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 516 | type = CLEAR; |
| 517 | else if (type != CLEAR) |
| 518 | { |
| 519 | check_for_delay(FALSE); |
| 520 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 521 | type = CLEAR; |
| 522 | FOR_ALL_WINDOWS(wp) |
| 523 | { |
| 524 | if (W_WINROW(wp) < msg_scrolled) |
| 525 | { |
| 526 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 527 | && wp->w_redr_type < REDRAW_TOP |
| 528 | && wp->w_lines_valid > 0 |
| 529 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 530 | { |
| 531 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 532 | wp->w_redr_type = REDRAW_TOP; |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | wp->w_redr_type = NOT_VALID; |
| 537 | #ifdef FEAT_WINDOWS |
| 538 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 539 | <= msg_scrolled) |
| 540 | wp->w_redr_status = TRUE; |
| 541 | #endif |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 546 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 547 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 548 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 549 | } |
| 550 | msg_scrolled = 0; |
| 551 | need_wait_return = FALSE; |
| 552 | } |
| 553 | |
| 554 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 555 | compute_cmdrow(); |
| 556 | |
| 557 | /* Check for changed highlighting */ |
| 558 | if (need_highlight_changed) |
| 559 | highlight_changed(); |
| 560 | |
| 561 | if (type == CLEAR) /* first clear screen */ |
| 562 | { |
| 563 | screenclear(); /* will reset clear_cmdline */ |
| 564 | type = NOT_VALID; |
| 565 | } |
| 566 | |
| 567 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 568 | check_for_delay(FALSE); |
| 569 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 570 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 571 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 572 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 573 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 574 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 575 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 576 | curwin->w_redr_type = NOT_VALID; |
| 577 | #endif |
| 578 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 579 | /* |
| 580 | * Only start redrawing if there is really something to do. |
| 581 | */ |
| 582 | if (type == INVERTED) |
| 583 | update_curswant(); |
| 584 | if (curwin->w_redr_type < type |
| 585 | && !((type == VALID |
| 586 | && curwin->w_lines[0].wl_valid |
| 587 | #ifdef FEAT_DIFF |
| 588 | && curwin->w_topfill == curwin->w_old_topfill |
| 589 | && curwin->w_botfill == curwin->w_old_botfill |
| 590 | #endif |
| 591 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 592 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 593 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 594 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 595 | && curwin->w_old_visual_mode == VIsual_mode |
| 596 | && (curwin->w_valid & VALID_VIRTCOL) |
| 597 | && curwin->w_old_curswant == curwin->w_curswant) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 598 | )) |
| 599 | curwin->w_redr_type = type; |
| 600 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 601 | #ifdef FEAT_WINDOWS |
| 602 | /* Redraw the tab pages line if needed. */ |
| 603 | if (redraw_tabline || type >= NOT_VALID) |
| 604 | draw_tabline(); |
| 605 | #endif |
| 606 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 607 | #ifdef FEAT_SYN_HL |
| 608 | /* |
| 609 | * Correct stored syntax highlighting info for changes in each displayed |
| 610 | * buffer. Each buffer must only be done once. |
| 611 | */ |
| 612 | FOR_ALL_WINDOWS(wp) |
| 613 | { |
| 614 | if (wp->w_buffer->b_mod_set) |
| 615 | { |
| 616 | # ifdef FEAT_WINDOWS |
| 617 | win_T *wwp; |
| 618 | |
| 619 | /* Check if we already did this buffer. */ |
| 620 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 621 | if (wwp->w_buffer == wp->w_buffer) |
| 622 | break; |
| 623 | # endif |
| 624 | if ( |
| 625 | # ifdef FEAT_WINDOWS |
| 626 | wwp == wp && |
| 627 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 628 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 629 | syn_stack_apply_changes(wp->w_buffer); |
| 630 | } |
| 631 | } |
| 632 | #endif |
| 633 | |
| 634 | /* |
| 635 | * Go from top to bottom through the windows, redrawing the ones that need |
| 636 | * it. |
| 637 | */ |
| 638 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 639 | did_one = FALSE; |
| 640 | #endif |
| 641 | #ifdef FEAT_SEARCH_EXTRA |
| 642 | search_hl.rm.regprog = NULL; |
| 643 | #endif |
| 644 | FOR_ALL_WINDOWS(wp) |
| 645 | { |
| 646 | if (wp->w_redr_type != 0) |
| 647 | { |
| 648 | cursor_off(); |
| 649 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 650 | if (!did_one) |
| 651 | { |
| 652 | did_one = TRUE; |
| 653 | # ifdef FEAT_SEARCH_EXTRA |
| 654 | start_search_hl(); |
| 655 | # endif |
| 656 | # ifdef FEAT_CLIPBOARD |
| 657 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 658 | if (clip_star.available && clip_isautosel_star()) |
| 659 | clip_update_selection(&clip_star); |
| 660 | if (clip_plus.available && clip_isautosel_plus()) |
| 661 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 662 | # endif |
| 663 | #ifdef FEAT_GUI |
| 664 | /* Remove the cursor before starting to do anything, because |
| 665 | * scrolling may make it difficult to redraw the text under |
| 666 | * it. */ |
| 667 | if (gui.in_use) |
| 668 | gui_undraw_cursor(); |
| 669 | #endif |
| 670 | } |
| 671 | #endif |
| 672 | win_update(wp); |
| 673 | } |
| 674 | |
| 675 | #ifdef FEAT_WINDOWS |
| 676 | /* redraw status line after the window to minimize cursor movement */ |
| 677 | if (wp->w_redr_status) |
| 678 | { |
| 679 | cursor_off(); |
| 680 | win_redr_status(wp); |
| 681 | } |
| 682 | #endif |
| 683 | } |
| 684 | #if defined(FEAT_SEARCH_EXTRA) |
| 685 | end_search_hl(); |
| 686 | #endif |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 687 | #ifdef FEAT_INS_EXPAND |
| 688 | /* May need to redraw the popup menu. */ |
| 689 | if (pum_visible()) |
| 690 | pum_redraw(); |
| 691 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 692 | |
| 693 | #ifdef FEAT_WINDOWS |
| 694 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 695 | * than going through all buffers (there could be many buffers). */ |
| 696 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 697 | wp->w_buffer->b_mod_set = FALSE; |
| 698 | #else |
| 699 | curbuf->b_mod_set = FALSE; |
| 700 | #endif |
| 701 | |
| 702 | updating_screen = FALSE; |
| 703 | #ifdef FEAT_GUI |
| 704 | gui_may_resize_shell(); |
| 705 | #endif |
| 706 | |
| 707 | /* Clear or redraw the command line. Done last, because scrolling may |
| 708 | * mess up the command line. */ |
| 709 | if (clear_cmdline || redraw_cmdline) |
| 710 | showmode(); |
| 711 | |
| 712 | /* May put up an introductory message when not editing a file */ |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 713 | if (!did_intro) |
| 714 | maybe_intro_message(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 715 | did_intro = TRUE; |
| 716 | |
| 717 | #ifdef FEAT_GUI |
| 718 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 719 | * done. */ |
| 720 | if (gui.in_use) |
| 721 | { |
| 722 | out_flush(); /* required before updating the cursor */ |
| 723 | if (did_one) |
| 724 | gui_update_cursor(FALSE, FALSE); |
| 725 | gui_update_scrollbars(FALSE); |
| 726 | } |
| 727 | #endif |
| 728 | } |
| 729 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 730 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 731 | /* |
| 732 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 733 | * to the 'concealcursor' option. |
| 734 | */ |
| 735 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 736 | conceal_cursor_line(win_T *wp) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 737 | { |
| 738 | int c; |
| 739 | |
| 740 | if (*wp->w_p_cocu == NUL) |
| 741 | return FALSE; |
| 742 | if (get_real_state() & VISUAL) |
| 743 | c = 'v'; |
| 744 | else if (State & INSERT) |
| 745 | c = 'i'; |
| 746 | else if (State & NORMAL) |
| 747 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 748 | else if (State & CMDLINE) |
| 749 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 750 | else |
| 751 | return FALSE; |
| 752 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 757 | */ |
| 758 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 759 | conceal_check_cursur_line(void) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 760 | { |
| 761 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 762 | { |
| 763 | need_cursor_line_redraw = TRUE; |
| 764 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 765 | * without concealing. */ |
| 766 | curs_columns(TRUE); |
| 767 | } |
| 768 | } |
| 769 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 770 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 771 | update_single_line(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 772 | { |
| 773 | int row; |
| 774 | int j; |
| 775 | |
| 776 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 777 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 778 | { |
| 779 | # ifdef FEAT_GUI |
| 780 | /* Remove the cursor before starting to do anything, because scrolling |
| 781 | * may make it difficult to redraw the text under it. */ |
| 782 | if (gui.in_use) |
| 783 | gui_undraw_cursor(); |
| 784 | # endif |
| 785 | row = 0; |
| 786 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 787 | { |
| 788 | if (lnum == wp->w_lines[j].wl_lnum) |
| 789 | { |
| 790 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 791 | # ifdef FEAT_SEARCH_EXTRA |
| 792 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 793 | start_search_hl(); |
| 794 | prepare_search_hl(wp, lnum); |
| 795 | # endif |
| 796 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 797 | # if defined(FEAT_SEARCH_EXTRA) |
| 798 | end_search_hl(); |
| 799 | # endif |
| 800 | break; |
| 801 | } |
| 802 | row += wp->w_lines[j].wl_size; |
| 803 | } |
| 804 | # ifdef FEAT_GUI |
| 805 | /* Redraw the cursor */ |
| 806 | if (gui.in_use) |
| 807 | { |
| 808 | out_flush(); /* required before updating the cursor */ |
| 809 | gui_update_cursor(FALSE, FALSE); |
| 810 | } |
| 811 | # endif |
| 812 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 813 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 814 | } |
| 815 | #endif |
| 816 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 817 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 818 | static void update_prepare(void); |
| 819 | static void update_finish(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 820 | |
| 821 | /* |
| 822 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 823 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 824 | */ |
| 825 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 826 | update_prepare(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 827 | { |
| 828 | cursor_off(); |
| 829 | updating_screen = TRUE; |
| 830 | #ifdef FEAT_GUI |
| 831 | /* Remove the cursor before starting to do anything, because scrolling may |
| 832 | * make it difficult to redraw the text under it. */ |
| 833 | if (gui.in_use) |
| 834 | gui_undraw_cursor(); |
| 835 | #endif |
| 836 | #ifdef FEAT_SEARCH_EXTRA |
| 837 | start_search_hl(); |
| 838 | #endif |
| 839 | } |
| 840 | |
| 841 | /* |
| 842 | * Finish updating one or more windows. |
| 843 | */ |
| 844 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 845 | update_finish(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 846 | { |
| 847 | if (redraw_cmdline) |
| 848 | showmode(); |
| 849 | |
| 850 | # ifdef FEAT_SEARCH_EXTRA |
| 851 | end_search_hl(); |
| 852 | # endif |
| 853 | |
| 854 | updating_screen = FALSE; |
| 855 | |
| 856 | # ifdef FEAT_GUI |
| 857 | gui_may_resize_shell(); |
| 858 | |
| 859 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 860 | * done. */ |
| 861 | if (gui.in_use) |
| 862 | { |
| 863 | out_flush(); /* required before updating the cursor */ |
| 864 | gui_update_cursor(FALSE, FALSE); |
| 865 | gui_update_scrollbars(FALSE); |
| 866 | } |
| 867 | # endif |
| 868 | } |
| 869 | #endif |
| 870 | |
| 871 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 872 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 873 | update_debug_sign(buf_T *buf, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 874 | { |
| 875 | win_T *wp; |
| 876 | int doit = FALSE; |
| 877 | |
| 878 | # ifdef FEAT_FOLDING |
| 879 | win_foldinfo.fi_level = 0; |
| 880 | # endif |
| 881 | |
| 882 | /* update/delete a specific mark */ |
| 883 | FOR_ALL_WINDOWS(wp) |
| 884 | { |
| 885 | if (buf != NULL && lnum > 0) |
| 886 | { |
| 887 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 888 | && lnum < wp->w_botline) |
| 889 | { |
| 890 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 891 | wp->w_redraw_top = lnum; |
| 892 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 893 | wp->w_redraw_bot = lnum; |
| 894 | redraw_win_later(wp, VALID); |
| 895 | } |
| 896 | } |
| 897 | else |
| 898 | redraw_win_later(wp, VALID); |
| 899 | if (wp->w_redr_type != 0) |
| 900 | doit = TRUE; |
| 901 | } |
| 902 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 903 | /* Return when there is nothing to do, screen updating is already |
| 904 | * happening (recursive call) or still starting up. */ |
| 905 | if (!doit || updating_screen |
| 906 | #ifdef FEAT_GUI |
| 907 | || gui.starting |
| 908 | #endif |
| 909 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 910 | return; |
| 911 | |
| 912 | /* update all windows that need updating */ |
| 913 | update_prepare(); |
| 914 | |
| 915 | # ifdef FEAT_WINDOWS |
| 916 | for (wp = firstwin; wp; wp = wp->w_next) |
| 917 | { |
| 918 | if (wp->w_redr_type != 0) |
| 919 | win_update(wp); |
| 920 | if (wp->w_redr_status) |
| 921 | win_redr_status(wp); |
| 922 | } |
| 923 | # else |
| 924 | if (curwin->w_redr_type != 0) |
| 925 | win_update(curwin); |
| 926 | # endif |
| 927 | |
| 928 | update_finish(); |
| 929 | } |
| 930 | #endif |
| 931 | |
| 932 | |
| 933 | #if defined(FEAT_GUI) || defined(PROTO) |
| 934 | /* |
| 935 | * Update a single window, its status line and maybe the command line msg. |
| 936 | * Used for the GUI scrollbar. |
| 937 | */ |
| 938 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 939 | updateWindow(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 940 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 941 | /* return if already busy updating */ |
| 942 | if (updating_screen) |
| 943 | return; |
| 944 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 945 | update_prepare(); |
| 946 | |
| 947 | #ifdef FEAT_CLIPBOARD |
| 948 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 949 | if (clip_star.available && clip_isautosel_star()) |
| 950 | clip_update_selection(&clip_star); |
| 951 | if (clip_plus.available && clip_isautosel_plus()) |
| 952 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 953 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 954 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 955 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 956 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 957 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 958 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 959 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 960 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 961 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 962 | if (wp->w_redr_status |
| 963 | # ifdef FEAT_CMDL_INFO |
| 964 | || p_ru |
| 965 | # endif |
| 966 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 967 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 968 | # endif |
| 969 | ) |
| 970 | win_redr_status(wp); |
| 971 | #endif |
| 972 | |
| 973 | update_finish(); |
| 974 | } |
| 975 | #endif |
| 976 | |
| 977 | /* |
| 978 | * Update a single window. |
| 979 | * |
| 980 | * This may cause the windows below it also to be redrawn (when clearing the |
| 981 | * screen or scrolling lines). |
| 982 | * |
| 983 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 984 | * implies the one below it. |
| 985 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 986 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 987 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 988 | * INVERTED redraw the changed part of the Visual area |
| 989 | * INVERTED_ALL redraw the whole Visual area |
| 990 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 991 | * 2. update lines at the top when scrolled down |
| 992 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 993 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 994 | * b_mod_top and b_mod_bot. |
| 995 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 996 | * wp->w_redraw_top and wp->w_redr_bot. |
| 997 | * - continue redrawing when syntax status is invalid. |
| 998 | * 4. if scrolled up, update lines at the bottom. |
| 999 | * This results in three areas that may need updating: |
| 1000 | * top: from first row to top_end (when scrolled down) |
| 1001 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1002 | * bot: from bot_start to last row (when scrolled up) |
| 1003 | */ |
| 1004 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 1005 | win_update(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | { |
| 1007 | buf_T *buf = wp->w_buffer; |
| 1008 | int type; |
| 1009 | int top_end = 0; /* Below last row of the top area that needs |
| 1010 | updating. 0 when no top area updating. */ |
| 1011 | int mid_start = 999;/* first row of the mid area that needs |
| 1012 | updating. 999 when no mid area updating. */ |
| 1013 | int mid_end = 0; /* Below last row of the mid area that needs |
| 1014 | updating. 0 when no mid area updating. */ |
| 1015 | int bot_start = 999;/* first row of the bot area that needs |
| 1016 | updating. 999 when no bot area updating */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1017 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 1018 | w_topline got smaller a bit */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1019 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1020 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1021 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 1022 | #endif |
| 1023 | |
| 1024 | int row; /* current window row to display */ |
| 1025 | linenr_T lnum; /* current buffer lnum to display */ |
| 1026 | int idx; /* current index in w_lines[] */ |
| 1027 | int srow; /* starting row of the current line */ |
| 1028 | |
| 1029 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 1030 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 1031 | int i; |
| 1032 | long j; |
| 1033 | static int recursive = FALSE; /* being called recursively */ |
| 1034 | int old_botline = wp->w_botline; |
| 1035 | #ifdef FEAT_FOLDING |
| 1036 | long fold_count; |
| 1037 | #endif |
| 1038 | #ifdef FEAT_SYN_HL |
| 1039 | /* remember what happened to the previous line, to know if |
| 1040 | * check_visual_highlight() can be used */ |
| 1041 | #define DID_NONE 1 /* didn't update a line */ |
| 1042 | #define DID_LINE 2 /* updated a normal line */ |
| 1043 | #define DID_FOLD 3 /* updated a folded line */ |
| 1044 | int did_update = DID_NONE; |
| 1045 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 1046 | #endif |
| 1047 | linenr_T mod_top = 0; |
| 1048 | linenr_T mod_bot = 0; |
| 1049 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1050 | int save_got_int; |
| 1051 | #endif |
| 1052 | |
| 1053 | type = wp->w_redr_type; |
| 1054 | |
| 1055 | if (type == NOT_VALID) |
| 1056 | { |
| 1057 | #ifdef FEAT_WINDOWS |
| 1058 | wp->w_redr_status = TRUE; |
| 1059 | #endif |
| 1060 | wp->w_lines_valid = 0; |
| 1061 | } |
| 1062 | |
| 1063 | /* Window is zero-height: nothing to draw. */ |
| 1064 | if (wp->w_height == 0) |
| 1065 | { |
| 1066 | wp->w_redr_type = 0; |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | #ifdef FEAT_VERTSPLIT |
| 1071 | /* Window is zero-width: Only need to draw the separator. */ |
| 1072 | if (wp->w_width == 0) |
| 1073 | { |
| 1074 | /* draw the vertical separator right of this window */ |
| 1075 | draw_vsep_win(wp, 0); |
| 1076 | wp->w_redr_type = 0; |
| 1077 | return; |
| 1078 | } |
| 1079 | #endif |
| 1080 | |
| 1081 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 1082 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1083 | #endif |
| 1084 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1085 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 1086 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 1087 | * changes. */ |
| 1088 | 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] | 1089 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1090 | { |
| 1091 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1092 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1093 | } |
| 1094 | else |
| 1095 | #endif |
| 1096 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1097 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 1098 | { |
| 1099 | /* |
| 1100 | * When there are both inserted/deleted lines and specific lines to be |
| 1101 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 1102 | * everything (only happens when redrawing is off for while). |
| 1103 | */ |
| 1104 | type = NOT_VALID; |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | /* |
| 1109 | * Set mod_top to the first line that needs displaying because of |
| 1110 | * changes. Set mod_bot to the first line after the changes. |
| 1111 | */ |
| 1112 | mod_top = wp->w_redraw_top; |
| 1113 | if (wp->w_redraw_bot != 0) |
| 1114 | mod_bot = wp->w_redraw_bot + 1; |
| 1115 | else |
| 1116 | mod_bot = 0; |
| 1117 | wp->w_redraw_top = 0; /* reset for next time */ |
| 1118 | wp->w_redraw_bot = 0; |
| 1119 | if (buf->b_mod_set) |
| 1120 | { |
| 1121 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1122 | { |
| 1123 | mod_top = buf->b_mod_top; |
| 1124 | #ifdef FEAT_SYN_HL |
| 1125 | /* Need to redraw lines above the change that may be included |
| 1126 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1127 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1128 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1129 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1130 | if (mod_top < 1) |
| 1131 | mod_top = 1; |
| 1132 | } |
| 1133 | #endif |
| 1134 | } |
| 1135 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1136 | mod_bot = buf->b_mod_bot; |
| 1137 | |
| 1138 | #ifdef FEAT_SEARCH_EXTRA |
| 1139 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1140 | * change in one line may make the Search highlighting in a |
| 1141 | * previous line invalid. Simple solution: redraw all visible |
| 1142 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1143 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1144 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1145 | if (search_hl.rm.regprog != NULL |
| 1146 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1147 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1148 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1149 | { |
| 1150 | cur = wp->w_match_head; |
| 1151 | while (cur != NULL) |
| 1152 | { |
| 1153 | if (cur->match.regprog != NULL |
| 1154 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1155 | { |
| 1156 | top_to_mod = TRUE; |
| 1157 | break; |
| 1158 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1159 | cur = cur->next; |
| 1160 | } |
| 1161 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1162 | #endif |
| 1163 | } |
| 1164 | #ifdef FEAT_FOLDING |
| 1165 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1166 | { |
| 1167 | linenr_T lnumt, lnumb; |
| 1168 | |
| 1169 | /* |
| 1170 | * A change in a line can cause lines above it to become folded or |
| 1171 | * unfolded. Find the top most buffer line that may be affected. |
| 1172 | * If the line was previously folded and displayed, get the first |
| 1173 | * line of that fold. If the line is folded now, get the first |
| 1174 | * folded line. Use the minimum of these two. |
| 1175 | */ |
| 1176 | |
| 1177 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1178 | * the line below it. If there is no valid entry, use w_topline. |
| 1179 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1180 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1181 | lnumt = wp->w_topline; |
| 1182 | lnumb = MAXLNUM; |
| 1183 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1184 | if (wp->w_lines[i].wl_valid) |
| 1185 | { |
| 1186 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1187 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1188 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1189 | { |
| 1190 | lnumb = wp->w_lines[i].wl_lnum; |
| 1191 | /* When there is a fold column it might need updating |
| 1192 | * in the next line ("J" just above an open fold). */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 1193 | if (compute_foldcolumn(wp, 0) > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1194 | ++lnumb; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1199 | if (mod_top > lnumt) |
| 1200 | mod_top = lnumt; |
| 1201 | |
| 1202 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1203 | --mod_bot; |
| 1204 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1205 | ++mod_bot; |
| 1206 | if (mod_bot < lnumb) |
| 1207 | mod_bot = lnumb; |
| 1208 | } |
| 1209 | #endif |
| 1210 | |
| 1211 | /* When a change starts above w_topline and the end is below |
| 1212 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1213 | * If the end of the change is above w_topline: do like no change was |
| 1214 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1215 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1216 | { |
| 1217 | if (mod_bot > wp->w_topline) |
| 1218 | mod_top = wp->w_topline; |
| 1219 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1220 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1221 | top_end = 1; |
| 1222 | #endif |
| 1223 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1224 | |
| 1225 | /* When line numbers are displayed need to redraw all lines below |
| 1226 | * inserted/deleted lines. */ |
| 1227 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1228 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | /* |
| 1232 | * When only displaying the lines at the top, set top_end. Used when |
| 1233 | * window has scrolled down for msg_scrolled. |
| 1234 | */ |
| 1235 | if (type == REDRAW_TOP) |
| 1236 | { |
| 1237 | j = 0; |
| 1238 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1239 | { |
| 1240 | j += wp->w_lines[i].wl_size; |
| 1241 | if (j >= wp->w_upd_rows) |
| 1242 | { |
| 1243 | top_end = j; |
| 1244 | break; |
| 1245 | } |
| 1246 | } |
| 1247 | if (top_end == 0) |
| 1248 | /* not found (cannot happen?): redraw everything */ |
| 1249 | type = NOT_VALID; |
| 1250 | else |
| 1251 | /* top area defined, the rest is VALID */ |
| 1252 | type = VALID; |
| 1253 | } |
| 1254 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1255 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1256 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1257 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1258 | * called. */ |
| 1259 | if (screen_cleared) |
| 1260 | screen_cleared = MAYBE; |
| 1261 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1262 | /* |
| 1263 | * If there are no changes on the screen that require a complete redraw, |
| 1264 | * handle three cases: |
| 1265 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1266 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1267 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1268 | * w_lines[] that needs updating. |
| 1269 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1270 | if ((type == VALID || type == SOME_VALID |
| 1271 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1272 | #ifdef FEAT_DIFF |
| 1273 | && !wp->w_botfill && !wp->w_old_botfill |
| 1274 | #endif |
| 1275 | ) |
| 1276 | { |
| 1277 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1278 | { |
| 1279 | /* |
| 1280 | * w_topline is the first changed line, the scrolling will be done |
| 1281 | * further down. |
| 1282 | */ |
| 1283 | } |
| 1284 | else if (wp->w_lines[0].wl_valid |
| 1285 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1286 | #ifdef FEAT_DIFF |
| 1287 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1288 | && wp->w_topfill > wp->w_old_topfill) |
| 1289 | #endif |
| 1290 | )) |
| 1291 | { |
| 1292 | /* |
| 1293 | * New topline is above old topline: May scroll down. |
| 1294 | */ |
| 1295 | #ifdef FEAT_FOLDING |
| 1296 | if (hasAnyFolding(wp)) |
| 1297 | { |
| 1298 | linenr_T ln; |
| 1299 | |
| 1300 | /* count the number of lines we are off, counting a sequence |
| 1301 | * of folded lines as one */ |
| 1302 | j = 0; |
| 1303 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1304 | { |
| 1305 | ++j; |
| 1306 | if (j >= wp->w_height - 2) |
| 1307 | break; |
| 1308 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1309 | } |
| 1310 | } |
| 1311 | else |
| 1312 | #endif |
| 1313 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1314 | if (j < wp->w_height - 2) /* not too far off */ |
| 1315 | { |
| 1316 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1317 | #ifdef FEAT_DIFF |
| 1318 | /* insert extra lines for previously invisible filler lines */ |
| 1319 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1320 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1321 | - wp->w_old_topfill; |
| 1322 | #endif |
| 1323 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1324 | { |
| 1325 | /* |
| 1326 | * Try to insert the correct number of lines. |
| 1327 | * If not the last window, delete the lines at the bottom. |
| 1328 | * win_ins_lines may fail when the terminal can't do it. |
| 1329 | */ |
| 1330 | if (i > 0) |
| 1331 | check_for_delay(FALSE); |
| 1332 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1333 | { |
| 1334 | if (wp->w_lines_valid != 0) |
| 1335 | { |
| 1336 | /* Need to update rows that are new, stop at the |
| 1337 | * first one that scrolled down. */ |
| 1338 | top_end = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1339 | scrolled_down = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1340 | |
| 1341 | /* Move the entries that were scrolled, disable |
| 1342 | * the entries for the lines to be redrawn. */ |
| 1343 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1344 | wp->w_lines_valid = wp->w_height; |
| 1345 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1346 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1347 | while (idx >= 0) |
| 1348 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1349 | } |
| 1350 | } |
| 1351 | else |
| 1352 | mid_start = 0; /* redraw all lines */ |
| 1353 | } |
| 1354 | else |
| 1355 | mid_start = 0; /* redraw all lines */ |
| 1356 | } |
| 1357 | else |
| 1358 | mid_start = 0; /* redraw all lines */ |
| 1359 | } |
| 1360 | else |
| 1361 | { |
| 1362 | /* |
| 1363 | * New topline is at or below old topline: May scroll up. |
| 1364 | * When topline didn't change, find first entry in w_lines[] that |
| 1365 | * needs updating. |
| 1366 | */ |
| 1367 | |
| 1368 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1369 | j = -1; |
| 1370 | row = 0; |
| 1371 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1372 | { |
| 1373 | if (wp->w_lines[i].wl_valid |
| 1374 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1375 | { |
| 1376 | j = i; |
| 1377 | break; |
| 1378 | } |
| 1379 | row += wp->w_lines[i].wl_size; |
| 1380 | } |
| 1381 | if (j == -1) |
| 1382 | { |
| 1383 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1384 | * lines */ |
| 1385 | mid_start = 0; |
| 1386 | } |
| 1387 | else |
| 1388 | { |
| 1389 | /* |
| 1390 | * Try to delete the correct number of lines. |
| 1391 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1392 | */ |
| 1393 | #ifdef FEAT_DIFF |
| 1394 | /* If the topline didn't change, delete old filler lines, |
| 1395 | * otherwise delete filler lines of the new topline... */ |
| 1396 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1397 | row += wp->w_old_topfill; |
| 1398 | else |
| 1399 | row += diff_check_fill(wp, wp->w_topline); |
| 1400 | /* ... but don't delete new filler lines. */ |
| 1401 | row -= wp->w_topfill; |
| 1402 | #endif |
| 1403 | if (row > 0) |
| 1404 | { |
| 1405 | check_for_delay(FALSE); |
| 1406 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1407 | bot_start = wp->w_height - row; |
| 1408 | else |
| 1409 | mid_start = 0; /* redraw all lines */ |
| 1410 | } |
| 1411 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1412 | { |
| 1413 | /* |
| 1414 | * Skip the lines (below the deleted lines) that are still |
| 1415 | * valid and don't need redrawing. Copy their info |
| 1416 | * upwards, to compensate for the deleted lines. Set |
| 1417 | * bot_start to the first row that needs redrawing. |
| 1418 | */ |
| 1419 | bot_start = 0; |
| 1420 | idx = 0; |
| 1421 | for (;;) |
| 1422 | { |
| 1423 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1424 | /* stop at line that didn't fit, unless it is still |
| 1425 | * valid (no lines deleted) */ |
| 1426 | if (row > 0 && bot_start + row |
| 1427 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1428 | { |
| 1429 | wp->w_lines_valid = idx + 1; |
| 1430 | break; |
| 1431 | } |
| 1432 | bot_start += wp->w_lines[idx++].wl_size; |
| 1433 | |
| 1434 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1435 | if (++j >= wp->w_lines_valid) |
| 1436 | { |
| 1437 | wp->w_lines_valid = idx; |
| 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | #ifdef FEAT_DIFF |
| 1442 | /* Correct the first entry for filler lines at the top |
| 1443 | * when it won't get updated below. */ |
| 1444 | if (wp->w_p_diff && bot_start > 0) |
| 1445 | wp->w_lines[0].wl_size = |
| 1446 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1447 | + wp->w_topfill; |
| 1448 | #endif |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | /* When starting redraw in the first line, redraw all lines. When |
| 1454 | * there is only one window it's probably faster to clear the screen |
| 1455 | * first. */ |
| 1456 | if (mid_start == 0) |
| 1457 | { |
| 1458 | mid_end = wp->w_height; |
| 1459 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1460 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1461 | /* Clear the screen when it was not done by win_del_lines() or |
| 1462 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1463 | * then. */ |
| 1464 | if (screen_cleared != TRUE) |
| 1465 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1466 | #ifdef FEAT_WINDOWS |
| 1467 | /* The screen was cleared, redraw the tab pages line. */ |
| 1468 | if (redraw_tabline) |
| 1469 | draw_tabline(); |
| 1470 | #endif |
| 1471 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1472 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1473 | |
| 1474 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1475 | * cleared (only happens for the first window) or when screenclear() |
| 1476 | * was called directly above, "must_redraw" will have been set to |
| 1477 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1478 | if (screen_cleared == TRUE) |
| 1479 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1480 | } |
| 1481 | else |
| 1482 | { |
| 1483 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1484 | mid_start = 0; |
| 1485 | mid_end = wp->w_height; |
| 1486 | } |
| 1487 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1488 | if (type == SOME_VALID) |
| 1489 | { |
| 1490 | /* SOME_VALID: redraw all lines. */ |
| 1491 | mid_start = 0; |
| 1492 | mid_end = wp->w_height; |
| 1493 | type = NOT_VALID; |
| 1494 | } |
| 1495 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1496 | /* check if we are updating or removing the inverted part */ |
| 1497 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1498 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1499 | { |
| 1500 | linenr_T from, to; |
| 1501 | |
| 1502 | if (VIsual_active) |
| 1503 | { |
| 1504 | if (VIsual_active |
| 1505 | && (VIsual_mode != wp->w_old_visual_mode |
| 1506 | || type == INVERTED_ALL)) |
| 1507 | { |
| 1508 | /* |
| 1509 | * If the type of Visual selection changed, redraw the whole |
| 1510 | * selection. Also when the ownership of the X selection is |
| 1511 | * gained or lost. |
| 1512 | */ |
| 1513 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1514 | { |
| 1515 | from = curwin->w_cursor.lnum; |
| 1516 | to = VIsual.lnum; |
| 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | from = VIsual.lnum; |
| 1521 | to = curwin->w_cursor.lnum; |
| 1522 | } |
| 1523 | /* redraw more when the cursor moved as well */ |
| 1524 | if (wp->w_old_cursor_lnum < from) |
| 1525 | from = wp->w_old_cursor_lnum; |
| 1526 | if (wp->w_old_cursor_lnum > to) |
| 1527 | to = wp->w_old_cursor_lnum; |
| 1528 | if (wp->w_old_visual_lnum < from) |
| 1529 | from = wp->w_old_visual_lnum; |
| 1530 | if (wp->w_old_visual_lnum > to) |
| 1531 | to = wp->w_old_visual_lnum; |
| 1532 | } |
| 1533 | else |
| 1534 | { |
| 1535 | /* |
| 1536 | * Find the line numbers that need to be updated: The lines |
| 1537 | * between the old cursor position and the current cursor |
| 1538 | * position. Also check if the Visual position changed. |
| 1539 | */ |
| 1540 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1541 | { |
| 1542 | from = curwin->w_cursor.lnum; |
| 1543 | to = wp->w_old_cursor_lnum; |
| 1544 | } |
| 1545 | else |
| 1546 | { |
| 1547 | from = wp->w_old_cursor_lnum; |
| 1548 | to = curwin->w_cursor.lnum; |
| 1549 | if (from == 0) /* Visual mode just started */ |
| 1550 | from = to; |
| 1551 | } |
| 1552 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1553 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1554 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1555 | { |
| 1556 | if (wp->w_old_visual_lnum < from |
| 1557 | && wp->w_old_visual_lnum != 0) |
| 1558 | from = wp->w_old_visual_lnum; |
| 1559 | if (wp->w_old_visual_lnum > to) |
| 1560 | to = wp->w_old_visual_lnum; |
| 1561 | if (VIsual.lnum < from) |
| 1562 | from = VIsual.lnum; |
| 1563 | if (VIsual.lnum > to) |
| 1564 | to = VIsual.lnum; |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | /* |
| 1569 | * If in block mode and changed column or curwin->w_curswant: |
| 1570 | * update all lines. |
| 1571 | * First compute the actual start and end column. |
| 1572 | */ |
| 1573 | if (VIsual_mode == Ctrl_V) |
| 1574 | { |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1575 | colnr_T fromc, toc; |
| 1576 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1577 | int save_ve_flags = ve_flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1578 | |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1579 | if (curwin->w_p_lbr) |
| 1580 | ve_flags = VE_ALL; |
| 1581 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1582 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1583 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1584 | ve_flags = save_ve_flags; |
| 1585 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1586 | ++toc; |
| 1587 | if (curwin->w_curswant == MAXCOL) |
| 1588 | toc = MAXCOL; |
| 1589 | |
| 1590 | if (fromc != wp->w_old_cursor_fcol |
| 1591 | || toc != wp->w_old_cursor_lcol) |
| 1592 | { |
| 1593 | if (from > VIsual.lnum) |
| 1594 | from = VIsual.lnum; |
| 1595 | if (to < VIsual.lnum) |
| 1596 | to = VIsual.lnum; |
| 1597 | } |
| 1598 | wp->w_old_cursor_fcol = fromc; |
| 1599 | wp->w_old_cursor_lcol = toc; |
| 1600 | } |
| 1601 | } |
| 1602 | else |
| 1603 | { |
| 1604 | /* Use the line numbers of the old Visual area. */ |
| 1605 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1606 | { |
| 1607 | from = wp->w_old_cursor_lnum; |
| 1608 | to = wp->w_old_visual_lnum; |
| 1609 | } |
| 1610 | else |
| 1611 | { |
| 1612 | from = wp->w_old_visual_lnum; |
| 1613 | to = wp->w_old_cursor_lnum; |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | /* |
| 1618 | * There is no need to update lines above the top of the window. |
| 1619 | */ |
| 1620 | if (from < wp->w_topline) |
| 1621 | from = wp->w_topline; |
| 1622 | |
| 1623 | /* |
| 1624 | * If we know the value of w_botline, use it to restrict the update to |
| 1625 | * the lines that are visible in the window. |
| 1626 | */ |
| 1627 | if (wp->w_valid & VALID_BOTLINE) |
| 1628 | { |
| 1629 | if (from >= wp->w_botline) |
| 1630 | from = wp->w_botline - 1; |
| 1631 | if (to >= wp->w_botline) |
| 1632 | to = wp->w_botline - 1; |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * Find the minimal part to be updated. |
| 1637 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1638 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1639 | * top_end; need to redraw from top_end to the "to" line. |
| 1640 | * A middle mouse click with a Visual selection may change the text |
| 1641 | * above the Visual area and reset wl_valid, do count these for |
| 1642 | * mid_end (in srow). |
| 1643 | */ |
| 1644 | if (mid_start > 0) |
| 1645 | { |
| 1646 | lnum = wp->w_topline; |
| 1647 | idx = 0; |
| 1648 | srow = 0; |
| 1649 | if (scrolled_down) |
| 1650 | mid_start = top_end; |
| 1651 | else |
| 1652 | mid_start = 0; |
| 1653 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1654 | { |
| 1655 | if (wp->w_lines[idx].wl_valid) |
| 1656 | mid_start += wp->w_lines[idx].wl_size; |
| 1657 | else if (!scrolled_down) |
| 1658 | srow += wp->w_lines[idx].wl_size; |
| 1659 | ++idx; |
| 1660 | # ifdef FEAT_FOLDING |
| 1661 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1662 | lnum = wp->w_lines[idx].wl_lnum; |
| 1663 | else |
| 1664 | # endif |
| 1665 | ++lnum; |
| 1666 | } |
| 1667 | srow += mid_start; |
| 1668 | mid_end = wp->w_height; |
| 1669 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1670 | { |
| 1671 | if (wp->w_lines[idx].wl_valid |
| 1672 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1673 | { |
| 1674 | /* Only update until first row of this line */ |
| 1675 | mid_end = srow; |
| 1676 | break; |
| 1677 | } |
| 1678 | srow += wp->w_lines[idx].wl_size; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | if (VIsual_active && buf == curwin->w_buffer) |
| 1684 | { |
| 1685 | wp->w_old_visual_mode = VIsual_mode; |
| 1686 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1687 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1688 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1689 | wp->w_old_curswant = curwin->w_curswant; |
| 1690 | } |
| 1691 | else |
| 1692 | { |
| 1693 | wp->w_old_visual_mode = 0; |
| 1694 | wp->w_old_cursor_lnum = 0; |
| 1695 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1696 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1697 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1698 | |
| 1699 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1700 | /* reset got_int, otherwise regexp won't work */ |
| 1701 | save_got_int = got_int; |
| 1702 | got_int = 0; |
| 1703 | #endif |
| 1704 | #ifdef FEAT_FOLDING |
| 1705 | win_foldinfo.fi_level = 0; |
| 1706 | #endif |
| 1707 | |
| 1708 | /* |
| 1709 | * Update all the window rows. |
| 1710 | */ |
| 1711 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1712 | row = 0; |
| 1713 | srow = 0; |
| 1714 | lnum = wp->w_topline; /* first line shown in window */ |
| 1715 | for (;;) |
| 1716 | { |
| 1717 | /* stop updating when reached the end of the window (check for _past_ |
| 1718 | * the end of the window is at the end of the loop) */ |
| 1719 | if (row == wp->w_height) |
| 1720 | { |
| 1721 | didline = TRUE; |
| 1722 | break; |
| 1723 | } |
| 1724 | |
| 1725 | /* stop updating when hit the end of the file */ |
| 1726 | if (lnum > buf->b_ml.ml_line_count) |
| 1727 | { |
| 1728 | eof = TRUE; |
| 1729 | break; |
| 1730 | } |
| 1731 | |
| 1732 | /* Remember the starting row of the line that is going to be dealt |
| 1733 | * with. It is used further down when the line doesn't fit. */ |
| 1734 | srow = row; |
| 1735 | |
| 1736 | /* |
| 1737 | * Update a line when it is in an area that needs updating, when it |
| 1738 | * has changes or w_lines[idx] is invalid. |
| 1739 | * bot_start may be halfway a wrapped line after using |
| 1740 | * win_del_lines(), check if the current line includes it. |
| 1741 | * When syntax folding is being used, the saved syntax states will |
| 1742 | * already have been updated, we can't see where the syntax state is |
| 1743 | * the same again, just update until the end of the window. |
| 1744 | */ |
| 1745 | if (row < top_end |
| 1746 | || (row >= mid_start && row < mid_end) |
| 1747 | #ifdef FEAT_SEARCH_EXTRA |
| 1748 | || top_to_mod |
| 1749 | #endif |
| 1750 | || idx >= wp->w_lines_valid |
| 1751 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1752 | || (mod_top != 0 |
| 1753 | && (lnum == mod_top |
| 1754 | || (lnum >= mod_top |
| 1755 | && (lnum < mod_bot |
| 1756 | #ifdef FEAT_SYN_HL |
| 1757 | || did_update == DID_FOLD |
| 1758 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1759 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1760 | && ( |
| 1761 | # ifdef FEAT_FOLDING |
| 1762 | (foldmethodIsSyntax(wp) |
| 1763 | && hasAnyFolding(wp)) || |
| 1764 | # endif |
| 1765 | syntax_check_changed(lnum))) |
| 1766 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1767 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | dab70c6 | 2014-07-02 17:16:58 +0200 | [diff] [blame] | 1768 | /* match in fixed position might need redraw |
| 1769 | * if lines were inserted or deleted */ |
| 1770 | || (wp->w_match_head != NULL |
| 1771 | && buf->b_mod_xlines != 0) |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1772 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1773 | ))))) |
| 1774 | { |
| 1775 | #ifdef FEAT_SEARCH_EXTRA |
| 1776 | if (lnum == mod_top) |
| 1777 | top_to_mod = FALSE; |
| 1778 | #endif |
| 1779 | |
| 1780 | /* |
| 1781 | * When at start of changed lines: May scroll following lines |
| 1782 | * up or down to minimize redrawing. |
| 1783 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1784 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1785 | */ |
| 1786 | if (lnum == mod_top |
| 1787 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1788 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1789 | { |
| 1790 | int old_rows = 0; |
| 1791 | int new_rows = 0; |
| 1792 | int xtra_rows; |
| 1793 | linenr_T l; |
| 1794 | |
| 1795 | /* Count the old number of window rows, using w_lines[], which |
| 1796 | * should still contain the sizes for the lines as they are |
| 1797 | * currently displayed. */ |
| 1798 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1799 | { |
| 1800 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1801 | * lines are part of the changed area. */ |
| 1802 | if (wp->w_lines[i].wl_valid |
| 1803 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1804 | break; |
| 1805 | old_rows += wp->w_lines[i].wl_size; |
| 1806 | #ifdef FEAT_FOLDING |
| 1807 | if (wp->w_lines[i].wl_valid |
| 1808 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1809 | { |
| 1810 | /* Must have found the last valid entry above mod_bot. |
| 1811 | * Add following invalid entries. */ |
| 1812 | ++i; |
| 1813 | while (i < wp->w_lines_valid |
| 1814 | && !wp->w_lines[i].wl_valid) |
| 1815 | old_rows += wp->w_lines[i++].wl_size; |
| 1816 | break; |
| 1817 | } |
| 1818 | #endif |
| 1819 | } |
| 1820 | |
| 1821 | if (i >= wp->w_lines_valid) |
| 1822 | { |
| 1823 | /* We can't find a valid line below the changed lines, |
| 1824 | * need to redraw until the end of the window. |
| 1825 | * Inserting/deleting lines has no use. */ |
| 1826 | bot_start = 0; |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | /* Able to count old number of rows: Count new window |
| 1831 | * rows, and may insert/delete lines */ |
| 1832 | j = idx; |
| 1833 | for (l = lnum; l < mod_bot; ++l) |
| 1834 | { |
| 1835 | #ifdef FEAT_FOLDING |
| 1836 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1837 | ++new_rows; |
| 1838 | else |
| 1839 | #endif |
| 1840 | #ifdef FEAT_DIFF |
| 1841 | if (l == wp->w_topline) |
| 1842 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1843 | + wp->w_topfill; |
| 1844 | else |
| 1845 | #endif |
| 1846 | new_rows += plines_win(wp, l, TRUE); |
| 1847 | ++j; |
| 1848 | if (new_rows > wp->w_height - row - 2) |
| 1849 | { |
| 1850 | /* it's getting too much, must redraw the rest */ |
| 1851 | new_rows = 9999; |
| 1852 | break; |
| 1853 | } |
| 1854 | } |
| 1855 | xtra_rows = new_rows - old_rows; |
| 1856 | if (xtra_rows < 0) |
| 1857 | { |
| 1858 | /* May scroll text up. If there is not enough |
| 1859 | * remaining text or scrolling fails, must redraw the |
| 1860 | * rest. If scrolling works, must redraw the text |
| 1861 | * below the scrolled text. */ |
| 1862 | if (row - xtra_rows >= wp->w_height - 2) |
| 1863 | mod_bot = MAXLNUM; |
| 1864 | else |
| 1865 | { |
| 1866 | check_for_delay(FALSE); |
| 1867 | if (win_del_lines(wp, row, |
| 1868 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1869 | mod_bot = MAXLNUM; |
| 1870 | else |
| 1871 | bot_start = wp->w_height + xtra_rows; |
| 1872 | } |
| 1873 | } |
| 1874 | else if (xtra_rows > 0) |
| 1875 | { |
| 1876 | /* May scroll text down. If there is not enough |
| 1877 | * remaining text of scrolling fails, must redraw the |
| 1878 | * rest. */ |
| 1879 | if (row + xtra_rows >= wp->w_height - 2) |
| 1880 | mod_bot = MAXLNUM; |
| 1881 | else |
| 1882 | { |
| 1883 | check_for_delay(FALSE); |
| 1884 | if (win_ins_lines(wp, row + old_rows, |
| 1885 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1886 | mod_bot = MAXLNUM; |
| 1887 | else if (top_end > row + old_rows) |
| 1888 | /* Scrolled the part at the top that requires |
| 1889 | * updating down. */ |
| 1890 | top_end += xtra_rows; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | /* When not updating the rest, may need to move w_lines[] |
| 1895 | * entries. */ |
| 1896 | if (mod_bot != MAXLNUM && i != j) |
| 1897 | { |
| 1898 | if (j < i) |
| 1899 | { |
| 1900 | int x = row + new_rows; |
| 1901 | |
| 1902 | /* move entries in w_lines[] upwards */ |
| 1903 | for (;;) |
| 1904 | { |
| 1905 | /* stop at last valid entry in w_lines[] */ |
| 1906 | if (i >= wp->w_lines_valid) |
| 1907 | { |
| 1908 | wp->w_lines_valid = j; |
| 1909 | break; |
| 1910 | } |
| 1911 | wp->w_lines[j] = wp->w_lines[i]; |
| 1912 | /* stop at a line that won't fit */ |
| 1913 | if (x + (int)wp->w_lines[j].wl_size |
| 1914 | > wp->w_height) |
| 1915 | { |
| 1916 | wp->w_lines_valid = j + 1; |
| 1917 | break; |
| 1918 | } |
| 1919 | x += wp->w_lines[j++].wl_size; |
| 1920 | ++i; |
| 1921 | } |
| 1922 | if (bot_start > x) |
| 1923 | bot_start = x; |
| 1924 | } |
| 1925 | else /* j > i */ |
| 1926 | { |
| 1927 | /* move entries in w_lines[] downwards */ |
| 1928 | j -= i; |
| 1929 | wp->w_lines_valid += j; |
| 1930 | if (wp->w_lines_valid > wp->w_height) |
| 1931 | wp->w_lines_valid = wp->w_height; |
| 1932 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1933 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1934 | |
| 1935 | /* The w_lines[] entries for inserted lines are |
| 1936 | * now invalid, but wl_size may be used above. |
| 1937 | * Reset to zero. */ |
| 1938 | while (i >= idx) |
| 1939 | { |
| 1940 | wp->w_lines[i].wl_size = 0; |
| 1941 | wp->w_lines[i--].wl_valid = FALSE; |
| 1942 | } |
| 1943 | } |
| 1944 | } |
| 1945 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | #ifdef FEAT_FOLDING |
| 1949 | /* |
| 1950 | * When lines are folded, display one line for all of them. |
| 1951 | * Otherwise, display normally (can be several display lines when |
| 1952 | * 'wrap' is on). |
| 1953 | */ |
| 1954 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1955 | if (fold_count != 0) |
| 1956 | { |
| 1957 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1958 | ++row; |
| 1959 | --fold_count; |
| 1960 | wp->w_lines[idx].wl_folded = TRUE; |
| 1961 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1962 | # ifdef FEAT_SYN_HL |
| 1963 | did_update = DID_FOLD; |
| 1964 | # endif |
| 1965 | } |
| 1966 | else |
| 1967 | #endif |
| 1968 | if (idx < wp->w_lines_valid |
| 1969 | && wp->w_lines[idx].wl_valid |
| 1970 | && wp->w_lines[idx].wl_lnum == lnum |
| 1971 | && lnum > wp->w_topline |
| 1972 | && !(dy_flags & DY_LASTLINE) |
| 1973 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1974 | #ifdef FEAT_DIFF |
| 1975 | && diff_check_fill(wp, lnum) == 0 |
| 1976 | #endif |
| 1977 | ) |
| 1978 | { |
| 1979 | /* This line is not going to fit. Don't draw anything here, |
| 1980 | * will draw "@ " lines below. */ |
| 1981 | row = wp->w_height + 1; |
| 1982 | } |
| 1983 | else |
| 1984 | { |
| 1985 | #ifdef FEAT_SEARCH_EXTRA |
| 1986 | prepare_search_hl(wp, lnum); |
| 1987 | #endif |
| 1988 | #ifdef FEAT_SYN_HL |
| 1989 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1990 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1991 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1992 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1993 | #endif |
| 1994 | |
| 1995 | /* |
| 1996 | * Display one line. |
| 1997 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1998 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1999 | |
| 2000 | #ifdef FEAT_FOLDING |
| 2001 | wp->w_lines[idx].wl_folded = FALSE; |
| 2002 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2003 | #endif |
| 2004 | #ifdef FEAT_SYN_HL |
| 2005 | did_update = DID_LINE; |
| 2006 | syntax_last_parsed = lnum; |
| 2007 | #endif |
| 2008 | } |
| 2009 | |
| 2010 | wp->w_lines[idx].wl_lnum = lnum; |
| 2011 | wp->w_lines[idx].wl_valid = TRUE; |
| 2012 | if (row > wp->w_height) /* past end of screen */ |
| 2013 | { |
| 2014 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2015 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2016 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2017 | ++idx; |
| 2018 | break; |
| 2019 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2020 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2021 | wp->w_lines[idx].wl_size = row - srow; |
| 2022 | ++idx; |
| 2023 | #ifdef FEAT_FOLDING |
| 2024 | lnum += fold_count + 1; |
| 2025 | #else |
| 2026 | ++lnum; |
| 2027 | #endif |
| 2028 | } |
| 2029 | else |
| 2030 | { |
| 2031 | /* This line does not need updating, advance to the next one */ |
| 2032 | row += wp->w_lines[idx++].wl_size; |
| 2033 | if (row > wp->w_height) /* past end of screen */ |
| 2034 | break; |
| 2035 | #ifdef FEAT_FOLDING |
| 2036 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2037 | #else |
| 2038 | ++lnum; |
| 2039 | #endif |
| 2040 | #ifdef FEAT_SYN_HL |
| 2041 | did_update = DID_NONE; |
| 2042 | #endif |
| 2043 | } |
| 2044 | |
| 2045 | if (lnum > buf->b_ml.ml_line_count) |
| 2046 | { |
| 2047 | eof = TRUE; |
| 2048 | break; |
| 2049 | } |
| 2050 | } |
| 2051 | /* |
| 2052 | * End of loop over all window lines. |
| 2053 | */ |
| 2054 | |
| 2055 | |
| 2056 | if (idx > wp->w_lines_valid) |
| 2057 | wp->w_lines_valid = idx; |
| 2058 | |
| 2059 | #ifdef FEAT_SYN_HL |
| 2060 | /* |
| 2061 | * Let the syntax stuff know we stop parsing here. |
| 2062 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2063 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2064 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2065 | #endif |
| 2066 | |
| 2067 | /* |
| 2068 | * If we didn't hit the end of the file, and we didn't finish the last |
| 2069 | * line we were working on, then the line didn't fit. |
| 2070 | */ |
| 2071 | wp->w_empty_rows = 0; |
| 2072 | #ifdef FEAT_DIFF |
| 2073 | wp->w_filler_rows = 0; |
| 2074 | #endif |
| 2075 | if (!eof && !didline) |
| 2076 | { |
| 2077 | if (lnum == wp->w_topline) |
| 2078 | { |
| 2079 | /* |
| 2080 | * Single line that does not fit! |
| 2081 | * Don't overwrite it, it can be edited. |
| 2082 | */ |
| 2083 | wp->w_botline = lnum + 1; |
| 2084 | } |
| 2085 | #ifdef FEAT_DIFF |
| 2086 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2087 | { |
| 2088 | /* Window ends in filler lines. */ |
| 2089 | wp->w_botline = lnum; |
| 2090 | wp->w_filler_rows = wp->w_height - srow; |
| 2091 | } |
| 2092 | #endif |
| 2093 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 2094 | { |
| 2095 | /* |
| 2096 | * Last line isn't finished: Display "@@@" at the end. |
| 2097 | */ |
| 2098 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2099 | W_WINROW(wp) + wp->w_height, |
| 2100 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 2101 | '@', '@', hl_attr(HLF_AT)); |
| 2102 | set_empty_rows(wp, srow); |
| 2103 | wp->w_botline = lnum; |
| 2104 | } |
| 2105 | else |
| 2106 | { |
| 2107 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 2108 | wp->w_botline = lnum; |
| 2109 | } |
| 2110 | } |
| 2111 | else |
| 2112 | { |
| 2113 | #ifdef FEAT_VERTSPLIT |
| 2114 | draw_vsep_win(wp, row); |
| 2115 | #endif |
| 2116 | if (eof) /* we hit the end of the file */ |
| 2117 | { |
| 2118 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2119 | #ifdef FEAT_DIFF |
| 2120 | j = diff_check_fill(wp, wp->w_botline); |
| 2121 | if (j > 0 && !wp->w_botfill) |
| 2122 | { |
| 2123 | /* |
| 2124 | * Display filler lines at the end of the file |
| 2125 | */ |
| 2126 | if (char2cells(fill_diff) > 1) |
| 2127 | i = '-'; |
| 2128 | else |
| 2129 | i = fill_diff; |
| 2130 | if (row + j > wp->w_height) |
| 2131 | j = wp->w_height - row; |
| 2132 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2133 | row += j; |
| 2134 | } |
| 2135 | #endif |
| 2136 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2137 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2138 | wp->w_botline = lnum; |
| 2139 | |
| 2140 | /* make sure the rest of the screen is blank */ |
| 2141 | /* put '~'s on rows that aren't part of the file. */ |
| 2142 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 2143 | } |
| 2144 | |
| 2145 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2146 | wp->w_redr_type = 0; |
| 2147 | #ifdef FEAT_DIFF |
| 2148 | wp->w_old_topfill = wp->w_topfill; |
| 2149 | wp->w_old_botfill = wp->w_botfill; |
| 2150 | #endif |
| 2151 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2152 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2153 | { |
| 2154 | /* |
| 2155 | * There is a trick with w_botline. If we invalidate it on each |
| 2156 | * change that might modify it, this will cause a lot of expensive |
| 2157 | * calls to plines() in update_topline() each time. Therefore the |
| 2158 | * value of w_botline is often approximated, and this value is used to |
| 2159 | * compute the value of w_topline. If the value of w_botline was |
| 2160 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2161 | * the visible part of the text). If it's not, we need to redraw |
| 2162 | * again. Mostly this just means scrolling up a few lines, so it |
| 2163 | * doesn't look too bad. Only do this for the current window (where |
| 2164 | * changes are relevant). |
| 2165 | */ |
| 2166 | wp->w_valid |= VALID_BOTLINE; |
| 2167 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2168 | { |
| 2169 | recursive = TRUE; |
| 2170 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2171 | update_topline(); /* may invalidate w_botline again */ |
| 2172 | if (must_redraw != 0) |
| 2173 | { |
| 2174 | /* Don't update for changes in buffer again. */ |
| 2175 | i = curbuf->b_mod_set; |
| 2176 | curbuf->b_mod_set = FALSE; |
| 2177 | win_update(curwin); |
| 2178 | must_redraw = 0; |
| 2179 | curbuf->b_mod_set = i; |
| 2180 | } |
| 2181 | recursive = FALSE; |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2186 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2187 | if (!got_int) |
| 2188 | got_int = save_got_int; |
| 2189 | #endif |
| 2190 | } |
| 2191 | |
| 2192 | #ifdef FEAT_SIGNS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2193 | static int draw_signcolumn(win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2194 | |
| 2195 | /* |
| 2196 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2197 | */ |
| 2198 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2199 | draw_signcolumn(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2200 | { |
| 2201 | return (wp->w_buffer->b_signlist != NULL |
| 2202 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | 3b7b836 | 2015-03-20 18:11:48 +0100 | [diff] [blame] | 2203 | || wp->w_buffer->b_has_sign_column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2204 | # endif |
| 2205 | ); |
| 2206 | } |
| 2207 | #endif |
| 2208 | |
| 2209 | /* |
| 2210 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2211 | * as the filler character. |
| 2212 | */ |
| 2213 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2214 | win_draw_end( |
| 2215 | win_T *wp, |
| 2216 | int c1, |
| 2217 | int c2, |
| 2218 | int row, |
| 2219 | int endrow, |
| 2220 | hlf_T hl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2221 | { |
| 2222 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2223 | int n = 0; |
| 2224 | # define FDC_OFF n |
| 2225 | #else |
| 2226 | # define FDC_OFF 0 |
| 2227 | #endif |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2228 | #ifdef FEAT_FOLDING |
| 2229 | int fdc = compute_foldcolumn(wp, 0); |
| 2230 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2231 | |
| 2232 | #ifdef FEAT_RIGHTLEFT |
| 2233 | if (wp->w_p_rl) |
| 2234 | { |
| 2235 | /* No check for cmdline window: should never be right-left. */ |
| 2236 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2237 | n = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2238 | |
| 2239 | if (n > 0) |
| 2240 | { |
| 2241 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2242 | if (n > W_WIDTH(wp)) |
| 2243 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2244 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2245 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2246 | ' ', ' ', hl_attr(HLF_FC)); |
| 2247 | } |
| 2248 | # endif |
| 2249 | # ifdef FEAT_SIGNS |
| 2250 | if (draw_signcolumn(wp)) |
| 2251 | { |
| 2252 | int nn = n + 2; |
| 2253 | |
| 2254 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2255 | if (nn > W_WIDTH(wp)) |
| 2256 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2257 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2258 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2259 | ' ', ' ', hl_attr(HLF_SC)); |
| 2260 | n = nn; |
| 2261 | } |
| 2262 | # endif |
| 2263 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2264 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2265 | c2, c2, hl_attr(hl)); |
| 2266 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2267 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2268 | c1, c2, hl_attr(hl)); |
| 2269 | } |
| 2270 | else |
| 2271 | #endif |
| 2272 | { |
| 2273 | #ifdef FEAT_CMDWIN |
| 2274 | if (cmdwin_type != 0 && wp == curwin) |
| 2275 | { |
| 2276 | /* draw the cmdline character in the leftmost column */ |
| 2277 | n = 1; |
| 2278 | if (n > wp->w_width) |
| 2279 | n = wp->w_width; |
| 2280 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2281 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2282 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2283 | } |
| 2284 | #endif |
| 2285 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2286 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2287 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2288 | int nn = n + fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2289 | |
| 2290 | /* draw the fold column at the left */ |
| 2291 | if (nn > W_WIDTH(wp)) |
| 2292 | nn = W_WIDTH(wp); |
| 2293 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2294 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2295 | ' ', ' ', hl_attr(HLF_FC)); |
| 2296 | n = nn; |
| 2297 | } |
| 2298 | #endif |
| 2299 | #ifdef FEAT_SIGNS |
| 2300 | if (draw_signcolumn(wp)) |
| 2301 | { |
| 2302 | int nn = n + 2; |
| 2303 | |
| 2304 | /* draw the sign column after the fold column */ |
| 2305 | if (nn > W_WIDTH(wp)) |
| 2306 | nn = W_WIDTH(wp); |
| 2307 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2308 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2309 | ' ', ' ', hl_attr(HLF_SC)); |
| 2310 | n = nn; |
| 2311 | } |
| 2312 | #endif |
| 2313 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2314 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2315 | c1, c2, hl_attr(hl)); |
| 2316 | } |
| 2317 | set_empty_rows(wp, row); |
| 2318 | } |
| 2319 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2320 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2321 | static int advance_color_col(int vcol, int **color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2322 | |
| 2323 | /* |
| 2324 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2325 | */ |
| 2326 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2327 | advance_color_col(int vcol, int **color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2328 | { |
| 2329 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2330 | ++*color_cols; |
| 2331 | return (**color_cols >= 0); |
| 2332 | } |
| 2333 | #endif |
| 2334 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2335 | #ifdef FEAT_FOLDING |
| 2336 | /* |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2337 | * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much |
| 2338 | * space is available for window "wp", minus "col". |
| 2339 | */ |
| 2340 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2341 | compute_foldcolumn(win_T *wp, int col) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2342 | { |
| 2343 | int fdc = wp->w_p_fdc; |
| 2344 | int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; |
| 2345 | int wwidth = W_WIDTH(wp); |
| 2346 | |
| 2347 | if (fdc > wwidth - (col + wmw)) |
| 2348 | fdc = wwidth - (col + wmw); |
| 2349 | return fdc; |
| 2350 | } |
| 2351 | |
| 2352 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2353 | * Display one folded line. |
| 2354 | */ |
| 2355 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2356 | fold_line( |
| 2357 | win_T *wp, |
| 2358 | long fold_count, |
| 2359 | foldinfo_T *foldinfo, |
| 2360 | linenr_T lnum, |
| 2361 | int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2362 | { |
| 2363 | char_u buf[51]; |
| 2364 | pos_T *top, *bot; |
| 2365 | linenr_T lnume = lnum + fold_count - 1; |
| 2366 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2367 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2368 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2369 | int col; |
| 2370 | int txtcol; |
| 2371 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2372 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2373 | |
| 2374 | /* Build the fold line: |
| 2375 | * 1. Add the cmdwin_type for the command-line window |
| 2376 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2377 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2378 | * 4. Compose the text |
| 2379 | * 5. Add the text |
| 2380 | * 6. set highlighting for the Visual area an other text |
| 2381 | */ |
| 2382 | col = 0; |
| 2383 | |
| 2384 | /* |
| 2385 | * 1. Add the cmdwin_type for the command-line window |
| 2386 | * Ignores 'rightleft', this window is never right-left. |
| 2387 | */ |
| 2388 | #ifdef FEAT_CMDWIN |
| 2389 | if (cmdwin_type != 0 && wp == curwin) |
| 2390 | { |
| 2391 | ScreenLines[off] = cmdwin_type; |
| 2392 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2393 | #ifdef FEAT_MBYTE |
| 2394 | if (enc_utf8) |
| 2395 | ScreenLinesUC[off] = 0; |
| 2396 | #endif |
| 2397 | ++col; |
| 2398 | } |
| 2399 | #endif |
| 2400 | |
| 2401 | /* |
| 2402 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2403 | * Reduce the width when there is not enough space. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2404 | */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2405 | fdc = compute_foldcolumn(wp, col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2406 | if (fdc > 0) |
| 2407 | { |
| 2408 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2409 | #ifdef FEAT_RIGHTLEFT |
| 2410 | if (wp->w_p_rl) |
| 2411 | { |
| 2412 | int i; |
| 2413 | |
| 2414 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2415 | hl_attr(HLF_FC)); |
| 2416 | /* reverse the fold column */ |
| 2417 | for (i = 0; i < fdc; ++i) |
| 2418 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2419 | } |
| 2420 | else |
| 2421 | #endif |
| 2422 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2423 | col += fdc; |
| 2424 | } |
| 2425 | |
| 2426 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2427 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2428 | for (ri = 0; ri < l; ++ri) \ |
| 2429 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2430 | else \ |
| 2431 | for (ri = 0; ri < l; ++ri) \ |
| 2432 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2433 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2434 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2435 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2436 | #endif |
| 2437 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2438 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2439 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2440 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2441 | |
| 2442 | #ifdef FEAT_SIGNS |
| 2443 | /* If signs are being displayed, add two spaces. */ |
| 2444 | if (draw_signcolumn(wp)) |
| 2445 | { |
| 2446 | len = W_WIDTH(wp) - col; |
| 2447 | if (len > 0) |
| 2448 | { |
| 2449 | if (len > 2) |
| 2450 | len = 2; |
| 2451 | # ifdef FEAT_RIGHTLEFT |
| 2452 | if (wp->w_p_rl) |
| 2453 | /* the line number isn't reversed */ |
| 2454 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2455 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2456 | else |
| 2457 | # endif |
| 2458 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2459 | col += len; |
| 2460 | } |
| 2461 | } |
| 2462 | #endif |
| 2463 | |
| 2464 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2465 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2466 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2467 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2468 | { |
| 2469 | len = W_WIDTH(wp) - col; |
| 2470 | if (len > 0) |
| 2471 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2472 | int w = number_width(wp); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2473 | long num; |
| 2474 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2475 | |
| 2476 | if (len > w + 1) |
| 2477 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2478 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2479 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2480 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2481 | num = (long)lnum; |
| 2482 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2483 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2484 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2485 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2486 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2487 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2488 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2489 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2490 | num = lnum; |
| 2491 | fmt = "%-*ld "; |
| 2492 | } |
| 2493 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2494 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2495 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2496 | #ifdef FEAT_RIGHTLEFT |
| 2497 | if (wp->w_p_rl) |
| 2498 | /* the line number isn't reversed */ |
| 2499 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2500 | hl_attr(HLF_FL)); |
| 2501 | else |
| 2502 | #endif |
| 2503 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2504 | col += len; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | /* |
| 2509 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2510 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2511 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2512 | |
| 2513 | txtcol = col; /* remember where text starts */ |
| 2514 | |
| 2515 | /* |
| 2516 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2517 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2518 | * in columns number-col - window-width. |
| 2519 | */ |
| 2520 | #ifdef FEAT_MBYTE |
| 2521 | if (has_mbyte) |
| 2522 | { |
| 2523 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2524 | int u8c, u8cc[MAX_MCO]; |
| 2525 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2526 | int idx; |
| 2527 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2528 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2529 | # ifdef FEAT_ARABIC |
| 2530 | int prev_c = 0; /* previous Arabic character */ |
| 2531 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2532 | # endif |
| 2533 | |
| 2534 | # ifdef FEAT_RIGHTLEFT |
| 2535 | if (wp->w_p_rl) |
| 2536 | idx = off; |
| 2537 | else |
| 2538 | # endif |
| 2539 | idx = off + col; |
| 2540 | |
| 2541 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2542 | for (p = text; *p != NUL; ) |
| 2543 | { |
| 2544 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2545 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2546 | if (col + cells > W_WIDTH(wp) |
| 2547 | # ifdef FEAT_RIGHTLEFT |
| 2548 | - (wp->w_p_rl ? col : 0) |
| 2549 | # endif |
| 2550 | ) |
| 2551 | break; |
| 2552 | ScreenLines[idx] = *p; |
| 2553 | if (enc_utf8) |
| 2554 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2555 | u8c = utfc_ptr2char(p, u8cc); |
| 2556 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2557 | { |
| 2558 | ScreenLinesUC[idx] = 0; |
| 2559 | #ifdef FEAT_ARABIC |
| 2560 | prev_c = u8c; |
| 2561 | #endif |
| 2562 | } |
| 2563 | else |
| 2564 | { |
| 2565 | #ifdef FEAT_ARABIC |
| 2566 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2567 | { |
| 2568 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2569 | int pc, pc1, nc; |
| 2570 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2571 | int firstbyte = *p; |
| 2572 | |
| 2573 | /* The idea of what is the previous and next |
| 2574 | * character depends on 'rightleft'. */ |
| 2575 | if (wp->w_p_rl) |
| 2576 | { |
| 2577 | pc = prev_c; |
| 2578 | pc1 = prev_c1; |
| 2579 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2580 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2581 | } |
| 2582 | else |
| 2583 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2584 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2585 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2586 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2587 | } |
| 2588 | prev_c = u8c; |
| 2589 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2590 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2591 | pc, pc1, nc); |
| 2592 | ScreenLines[idx] = firstbyte; |
| 2593 | } |
| 2594 | else |
| 2595 | prev_c = u8c; |
| 2596 | #endif |
| 2597 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2598 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2599 | if (u8c >= 0x10000) |
| 2600 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2601 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2602 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2603 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2604 | for (i = 0; i < Screen_mco; ++i) |
| 2605 | { |
| 2606 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2607 | if (u8cc[i] == 0) |
| 2608 | break; |
| 2609 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2610 | } |
| 2611 | if (cells > 1) |
| 2612 | ScreenLines[idx + 1] = 0; |
| 2613 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2614 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2615 | /* double-byte single width character */ |
| 2616 | ScreenLines2[idx] = p[1]; |
| 2617 | else if (cells > 1) |
| 2618 | /* double-width character */ |
| 2619 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2620 | col += cells; |
| 2621 | idx += cells; |
| 2622 | p += c_len; |
| 2623 | } |
| 2624 | } |
| 2625 | else |
| 2626 | #endif |
| 2627 | { |
| 2628 | len = (int)STRLEN(text); |
| 2629 | if (len > W_WIDTH(wp) - col) |
| 2630 | len = W_WIDTH(wp) - col; |
| 2631 | if (len > 0) |
| 2632 | { |
| 2633 | #ifdef FEAT_RIGHTLEFT |
| 2634 | if (wp->w_p_rl) |
| 2635 | STRNCPY(current_ScreenLine, text, len); |
| 2636 | else |
| 2637 | #endif |
| 2638 | STRNCPY(current_ScreenLine + col, text, len); |
| 2639 | col += len; |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | /* Fill the rest of the line with the fold filler */ |
| 2644 | #ifdef FEAT_RIGHTLEFT |
| 2645 | if (wp->w_p_rl) |
| 2646 | col -= txtcol; |
| 2647 | #endif |
| 2648 | while (col < W_WIDTH(wp) |
| 2649 | #ifdef FEAT_RIGHTLEFT |
| 2650 | - (wp->w_p_rl ? txtcol : 0) |
| 2651 | #endif |
| 2652 | ) |
| 2653 | { |
| 2654 | #ifdef FEAT_MBYTE |
| 2655 | if (enc_utf8) |
| 2656 | { |
| 2657 | if (fill_fold >= 0x80) |
| 2658 | { |
| 2659 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2660 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2661 | } |
| 2662 | else |
| 2663 | ScreenLinesUC[off + col] = 0; |
| 2664 | } |
| 2665 | #endif |
| 2666 | ScreenLines[off + col++] = fill_fold; |
| 2667 | } |
| 2668 | |
| 2669 | if (text != buf) |
| 2670 | vim_free(text); |
| 2671 | |
| 2672 | /* |
| 2673 | * 6. set highlighting for the Visual area an other text. |
| 2674 | * If all folded lines are in the Visual area, highlight the line. |
| 2675 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2676 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2677 | { |
| 2678 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2679 | { |
| 2680 | /* Visual is after curwin->w_cursor */ |
| 2681 | top = &curwin->w_cursor; |
| 2682 | bot = &VIsual; |
| 2683 | } |
| 2684 | else |
| 2685 | { |
| 2686 | /* Visual is before curwin->w_cursor */ |
| 2687 | top = &VIsual; |
| 2688 | bot = &curwin->w_cursor; |
| 2689 | } |
| 2690 | if (lnum >= top->lnum |
| 2691 | && lnume <= bot->lnum |
| 2692 | && (VIsual_mode != 'v' |
| 2693 | || ((lnum > top->lnum |
| 2694 | || (lnum == top->lnum |
| 2695 | && top->col == 0)) |
| 2696 | && (lnume < bot->lnum |
| 2697 | || (lnume == bot->lnum |
| 2698 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2699 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2700 | { |
| 2701 | if (VIsual_mode == Ctrl_V) |
| 2702 | { |
| 2703 | /* Visual block mode: highlight the chars part of the block */ |
| 2704 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2705 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2706 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2707 | && wp->w_old_cursor_lcol + txtcol |
| 2708 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2709 | len = wp->w_old_cursor_lcol; |
| 2710 | else |
| 2711 | len = W_WIDTH(wp) - txtcol; |
| 2712 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2713 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2714 | } |
| 2715 | } |
| 2716 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2717 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2718 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2719 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2720 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2721 | } |
| 2722 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2723 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2724 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | fbc25b2 | 2015-03-20 17:16:27 +0100 | [diff] [blame] | 2725 | /* Show colorcolumn in the fold line, but let cursorcolumn override it. */ |
| 2726 | if (wp->w_p_cc_cols) |
| 2727 | { |
| 2728 | int i = 0; |
| 2729 | int j = wp->w_p_cc_cols[i]; |
| 2730 | int old_txtcol = txtcol; |
| 2731 | |
| 2732 | while (j > -1) |
| 2733 | { |
| 2734 | txtcol += j; |
| 2735 | if (wp->w_p_wrap) |
| 2736 | txtcol -= wp->w_skipcol; |
| 2737 | else |
| 2738 | txtcol -= wp->w_leftcol; |
| 2739 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2740 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2741 | ScreenAttrs[off + txtcol], hl_attr(HLF_MC)); |
| 2742 | txtcol = old_txtcol; |
| 2743 | j = wp->w_p_cc_cols[++i]; |
| 2744 | } |
| 2745 | } |
| 2746 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2747 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2748 | if (wp->w_p_cuc) |
| 2749 | { |
| 2750 | txtcol += wp->w_virtcol; |
| 2751 | if (wp->w_p_wrap) |
| 2752 | txtcol -= wp->w_skipcol; |
| 2753 | else |
| 2754 | txtcol -= wp->w_leftcol; |
| 2755 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2756 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2757 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2758 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2759 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2760 | |
| 2761 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2762 | (int)W_WIDTH(wp), FALSE); |
| 2763 | |
| 2764 | /* |
| 2765 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2766 | * updated (saves a call to plines() later). |
| 2767 | */ |
| 2768 | if (wp == curwin |
| 2769 | && lnum <= curwin->w_cursor.lnum |
| 2770 | && lnume >= curwin->w_cursor.lnum) |
| 2771 | { |
| 2772 | curwin->w_cline_row = row; |
| 2773 | curwin->w_cline_height = 1; |
| 2774 | curwin->w_cline_folded = TRUE; |
| 2775 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | /* |
| 2780 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2781 | */ |
| 2782 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2783 | copy_text_attr( |
| 2784 | int off, |
| 2785 | char_u *buf, |
| 2786 | int len, |
| 2787 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2788 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2789 | int i; |
| 2790 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2791 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2792 | # ifdef FEAT_MBYTE |
| 2793 | if (enc_utf8) |
| 2794 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2795 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2796 | for (i = 0; i < len; ++i) |
| 2797 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | /* |
| 2801 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2802 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2803 | */ |
| 2804 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2805 | fill_foldcolumn( |
| 2806 | char_u *p, |
| 2807 | win_T *wp, |
| 2808 | int closed, /* TRUE of FALSE */ |
| 2809 | linenr_T lnum) /* current line number */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2810 | { |
| 2811 | int i = 0; |
| 2812 | int level; |
| 2813 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2814 | int empty; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2815 | int fdc = compute_foldcolumn(wp, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2816 | |
| 2817 | /* Init to all spaces. */ |
Bram Moolenaar | 2536d4f | 2015-07-17 13:22:51 +0200 | [diff] [blame] | 2818 | vim_memset(p, ' ', (size_t)fdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2819 | |
| 2820 | level = win_foldinfo.fi_level; |
| 2821 | if (level > 0) |
| 2822 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2823 | /* If there is only one column put more info in it. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2824 | empty = (fdc == 1) ? 0 : 1; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2825 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2826 | /* If the column is too narrow, we start at the lowest level that |
| 2827 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2828 | first_level = level - fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2829 | if (first_level < 1) |
| 2830 | first_level = 1; |
| 2831 | |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2832 | for (i = 0; i + empty < fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2833 | { |
| 2834 | if (win_foldinfo.fi_lnum == lnum |
| 2835 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2836 | p[i] = '-'; |
| 2837 | else if (first_level == 1) |
| 2838 | p[i] = '|'; |
| 2839 | else if (first_level + i <= 9) |
| 2840 | p[i] = '0' + first_level + i; |
| 2841 | else |
| 2842 | p[i] = '>'; |
| 2843 | if (first_level + i == level) |
| 2844 | break; |
| 2845 | } |
| 2846 | } |
| 2847 | if (closed) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2848 | p[i >= fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2849 | } |
| 2850 | #endif /* FEAT_FOLDING */ |
| 2851 | |
| 2852 | /* |
| 2853 | * Display line "lnum" of window 'wp' on the screen. |
| 2854 | * Start at row "startrow", stop when "endrow" is reached. |
| 2855 | * wp->w_virtcol needs to be valid. |
| 2856 | * |
| 2857 | * Return the number of last row the line occupies. |
| 2858 | */ |
| 2859 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2860 | win_line( |
| 2861 | win_T *wp, |
| 2862 | linenr_T lnum, |
| 2863 | int startrow, |
| 2864 | int endrow, |
| 2865 | int nochange UNUSED) /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2866 | { |
| 2867 | int col; /* visual column on screen */ |
| 2868 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2869 | int c = 0; /* init for GCC */ |
| 2870 | long vcol = 0; /* virtual column (for tabs) */ |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 2871 | #ifdef FEAT_LINEBREAK |
| 2872 | long vcol_sbr = -1; /* virtual column after showbreak */ |
| 2873 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2874 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2875 | char_u *line; /* current line */ |
| 2876 | char_u *ptr; /* current position in "line" */ |
| 2877 | int row; /* row in the window, excl w_winrow */ |
| 2878 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2879 | |
| 2880 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2881 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2882 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 2883 | char_u *p_extra_free = NULL; /* p_extra needs to be freed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2884 | int c_extra = NUL; /* extra chars, all the same */ |
| 2885 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2886 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2887 | displaying lcs_eol at end-of-line */ |
| 2888 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2889 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2890 | |
| 2891 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2892 | int saved_n_extra = 0; |
| 2893 | char_u *saved_p_extra = NULL; |
| 2894 | int saved_c_extra = 0; |
| 2895 | int saved_char_attr = 0; |
| 2896 | |
| 2897 | int n_attr = 0; /* chars with special attr */ |
| 2898 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2899 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2900 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2901 | |
| 2902 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2903 | |
| 2904 | int fromcol, tocol; /* start/end of inverting */ |
| 2905 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2906 | int noinvcur = FALSE; /* don't invert the cursor */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2907 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2908 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2909 | pos_T pos; |
| 2910 | long v; |
| 2911 | |
| 2912 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2913 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2914 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2915 | in this line */ |
| 2916 | int attr = 0; /* attributes for area highlighting */ |
| 2917 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2918 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2919 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2920 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2921 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2922 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2923 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2924 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2925 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2926 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2927 | #endif |
| 2928 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2929 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2930 | # define SPWORDLEN 150 |
| 2931 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2932 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2933 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2934 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2935 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2936 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2937 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2938 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2939 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2940 | static int cap_col = -1; /* column to check for Cap word */ |
| 2941 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2942 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2943 | #endif |
| 2944 | int extra_check; /* has syntax or linebreak */ |
| 2945 | #ifdef FEAT_MBYTE |
| 2946 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2947 | int mb_l = 1; /* multi-byte byte length */ |
| 2948 | int mb_c = 0; /* decoded multi-byte character */ |
| 2949 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2950 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2951 | #endif |
| 2952 | #ifdef FEAT_DIFF |
| 2953 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2954 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2955 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2956 | int change_start = MAXCOL; /* first col of changed area */ |
| 2957 | int change_end = -1; /* last col of changed area */ |
| 2958 | #endif |
| 2959 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2960 | #ifdef FEAT_LINEBREAK |
| 2961 | int need_showbreak = FALSE; |
| 2962 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2963 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2964 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2965 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 2966 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2967 | #endif |
| 2968 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2969 | matchitem_T *cur; /* points to the match list */ |
| 2970 | match_T *shl; /* points to search_hl or a match */ |
| 2971 | int shl_flag; /* flag to indicate whether search_hl |
| 2972 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 2973 | int pos_inprogress; /* marks that position match search is |
| 2974 | in progress */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2975 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 2976 | equals startcol of search_hl or one |
| 2977 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2978 | #endif |
| 2979 | #ifdef FEAT_ARABIC |
| 2980 | int prev_c = 0; /* previous Arabic character */ |
| 2981 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2982 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2983 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 2984 | int did_line_attr = 0; |
| 2985 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2986 | |
| 2987 | /* draw_state: items that are drawn in sequence: */ |
| 2988 | #define WL_START 0 /* nothing done yet */ |
| 2989 | #ifdef FEAT_CMDWIN |
| 2990 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2991 | #else |
| 2992 | # define WL_CMDLINE WL_START |
| 2993 | #endif |
| 2994 | #ifdef FEAT_FOLDING |
| 2995 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2996 | #else |
| 2997 | # define WL_FOLD WL_CMDLINE |
| 2998 | #endif |
| 2999 | #ifdef FEAT_SIGNS |
| 3000 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 3001 | #else |
| 3002 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 3003 | #endif |
| 3004 | #define WL_NR WL_SIGN + 1 /* line number */ |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3005 | #ifdef FEAT_LINEBREAK |
| 3006 | # define WL_BRI WL_NR + 1 /* 'breakindent' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3007 | #else |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3008 | # define WL_BRI WL_NR |
| 3009 | #endif |
| 3010 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3011 | # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */ |
| 3012 | #else |
| 3013 | # define WL_SBR WL_BRI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3014 | #endif |
| 3015 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 3016 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 3017 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3018 | int feedback_col = 0; |
| 3019 | int feedback_old_attr = -1; |
| 3020 | #endif |
| 3021 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3022 | #ifdef FEAT_CONCEAL |
| 3023 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 3024 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 3025 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3026 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3027 | int is_concealing = FALSE; |
| 3028 | int boguscols = 0; /* nonexistent columns added to force |
| 3029 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3030 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3031 | int did_wcol = FALSE; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3032 | int match_conc = FALSE; /* cchar for match functions */ |
| 3033 | int has_match_conc = FALSE; /* match wants to conceal */ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3034 | int old_boguscols = 0; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3035 | # define VCOL_HLC (vcol - vcol_off) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3036 | # define FIX_FOR_BOGUSCOLS \ |
| 3037 | { \ |
| 3038 | n_extra += vcol_off; \ |
| 3039 | vcol -= vcol_off; \ |
| 3040 | vcol_off = 0; \ |
| 3041 | col -= boguscols; \ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3042 | old_boguscols = boguscols; \ |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3043 | boguscols = 0; \ |
| 3044 | } |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3045 | #else |
| 3046 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3047 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3048 | |
| 3049 | if (startrow > endrow) /* past the end already! */ |
| 3050 | return startrow; |
| 3051 | |
| 3052 | row = startrow; |
| 3053 | screen_row = row + W_WINROW(wp); |
| 3054 | |
| 3055 | /* |
| 3056 | * To speed up the loop below, set extra_check when there is linebreak, |
| 3057 | * trailing white space and/or syntax processing to be done. |
| 3058 | */ |
| 3059 | #ifdef FEAT_LINEBREAK |
| 3060 | extra_check = wp->w_p_lbr; |
| 3061 | #else |
| 3062 | extra_check = 0; |
| 3063 | #endif |
| 3064 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3065 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3066 | { |
| 3067 | /* Prepare for syntax highlighting in this line. When there is an |
| 3068 | * error, stop syntax highlighting. */ |
| 3069 | save_did_emsg = did_emsg; |
| 3070 | did_emsg = FALSE; |
| 3071 | syntax_start(wp, lnum); |
| 3072 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3073 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3074 | else |
| 3075 | { |
| 3076 | did_emsg = save_did_emsg; |
| 3077 | has_syntax = TRUE; |
| 3078 | extra_check = TRUE; |
| 3079 | } |
| 3080 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3081 | |
| 3082 | /* Check for columns to display for 'colorcolumn'. */ |
| 3083 | color_cols = wp->w_p_cc_cols; |
| 3084 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3085 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3086 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3087 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3088 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3089 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3090 | && *wp->w_s->b_p_spl != NUL |
| 3091 | && wp->w_s->b_langp.ga_len > 0 |
| 3092 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3093 | { |
| 3094 | /* Prepare for spell checking. */ |
| 3095 | has_spell = TRUE; |
| 3096 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3097 | |
| 3098 | /* Get the start of the next line, so that words that wrap to the next |
| 3099 | * line are found too: "et<line-break>al.". |
| 3100 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 3101 | nextline[SPWORDLEN] = NUL; |
| 3102 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 3103 | { |
| 3104 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 3105 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 3106 | } |
| 3107 | |
| 3108 | /* When a word wrapped from the previous line the start of the current |
| 3109 | * line is valid. */ |
| 3110 | if (lnum == checked_lnum) |
| 3111 | cur_checked_col = checked_col; |
| 3112 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3113 | |
| 3114 | /* When there was a sentence end in the previous line may require a |
| 3115 | * word starting with capital in this line. In line 1 always check |
| 3116 | * the first word. */ |
| 3117 | if (lnum != capcol_lnum) |
| 3118 | cap_col = -1; |
| 3119 | if (lnum == 1) |
| 3120 | cap_col = 0; |
| 3121 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3122 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3123 | #endif |
| 3124 | |
| 3125 | /* |
| 3126 | * handle visual active in this window |
| 3127 | */ |
| 3128 | fromcol = -10; |
| 3129 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3130 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3131 | { |
| 3132 | /* Visual is after curwin->w_cursor */ |
| 3133 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 3134 | { |
| 3135 | top = &curwin->w_cursor; |
| 3136 | bot = &VIsual; |
| 3137 | } |
| 3138 | else /* Visual is before curwin->w_cursor */ |
| 3139 | { |
| 3140 | top = &VIsual; |
| 3141 | bot = &curwin->w_cursor; |
| 3142 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3143 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3144 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 3145 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3146 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3147 | { |
| 3148 | fromcol = wp->w_old_cursor_fcol; |
| 3149 | tocol = wp->w_old_cursor_lcol; |
| 3150 | } |
| 3151 | } |
| 3152 | else /* non-block mode */ |
| 3153 | { |
| 3154 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 3155 | fromcol = 0; |
| 3156 | else if (lnum == top->lnum) |
| 3157 | { |
| 3158 | if (VIsual_mode == 'V') /* linewise */ |
| 3159 | fromcol = 0; |
| 3160 | else |
| 3161 | { |
| 3162 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 3163 | if (gchar_pos(top) == NUL) |
| 3164 | tocol = fromcol + 1; |
| 3165 | } |
| 3166 | } |
| 3167 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 3168 | { |
| 3169 | if (*p_sel == 'e' && bot->col == 0 |
| 3170 | #ifdef FEAT_VIRTUALEDIT |
| 3171 | && bot->coladd == 0 |
| 3172 | #endif |
| 3173 | ) |
| 3174 | { |
| 3175 | fromcol = -10; |
| 3176 | tocol = MAXCOL; |
| 3177 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3178 | else if (bot->col == MAXCOL) |
| 3179 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3180 | else |
| 3181 | { |
| 3182 | pos = *bot; |
| 3183 | if (*p_sel == 'e') |
| 3184 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3185 | else |
| 3186 | { |
| 3187 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3188 | ++tocol; |
| 3189 | } |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3194 | /* Check if the character under the cursor should not be inverted */ |
| 3195 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3196 | #ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3197 | && !gui.in_use |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3198 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3199 | ) |
| 3200 | noinvcur = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3201 | |
| 3202 | /* if inverting in this line set area_highlighting */ |
| 3203 | if (fromcol >= 0) |
| 3204 | { |
| 3205 | area_highlighting = TRUE; |
| 3206 | attr = hl_attr(HLF_V); |
| 3207 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3208 | if ((clip_star.available && !clip_star.owned |
| 3209 | && clip_isautosel_star()) |
| 3210 | || (clip_plus.available && !clip_plus.owned |
| 3211 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3212 | attr = hl_attr(HLF_VNC); |
| 3213 | #endif |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3218 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3219 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3220 | else if (highlight_match |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3221 | && wp == curwin |
| 3222 | && lnum >= curwin->w_cursor.lnum |
| 3223 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3224 | { |
| 3225 | if (lnum == curwin->w_cursor.lnum) |
| 3226 | getvcol(curwin, &(curwin->w_cursor), |
| 3227 | (colnr_T *)&fromcol, NULL, NULL); |
| 3228 | else |
| 3229 | fromcol = 0; |
| 3230 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3231 | { |
| 3232 | pos.lnum = lnum; |
| 3233 | pos.col = search_match_endcol; |
| 3234 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3235 | } |
| 3236 | else |
| 3237 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3238 | /* do at least one character; happens when past end of line */ |
| 3239 | if (fromcol == tocol) |
| 3240 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3241 | area_highlighting = TRUE; |
| 3242 | attr = hl_attr(HLF_I); |
| 3243 | } |
| 3244 | |
| 3245 | #ifdef FEAT_DIFF |
| 3246 | filler_lines = diff_check(wp, lnum); |
| 3247 | if (filler_lines < 0) |
| 3248 | { |
| 3249 | if (filler_lines == -1) |
| 3250 | { |
| 3251 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3252 | diff_hlf = HLF_ADD; /* added line */ |
| 3253 | else if (change_start == 0) |
| 3254 | diff_hlf = HLF_TXD; /* changed text */ |
| 3255 | else |
| 3256 | diff_hlf = HLF_CHD; /* changed line */ |
| 3257 | } |
| 3258 | else |
| 3259 | diff_hlf = HLF_ADD; /* added line */ |
| 3260 | filler_lines = 0; |
| 3261 | area_highlighting = TRUE; |
| 3262 | } |
| 3263 | if (lnum == wp->w_topline) |
| 3264 | filler_lines = wp->w_topfill; |
| 3265 | filler_todo = filler_lines; |
| 3266 | #endif |
| 3267 | |
| 3268 | #ifdef LINE_ATTR |
| 3269 | # ifdef FEAT_SIGNS |
| 3270 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3271 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3272 | if (v != 0) |
| 3273 | line_attr = sign_get_attr((int)v, TRUE); |
| 3274 | # endif |
| 3275 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3276 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3277 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3278 | line_attr = hl_attr(HLF_L); |
| 3279 | # endif |
| 3280 | if (line_attr != 0) |
| 3281 | area_highlighting = TRUE; |
| 3282 | #endif |
| 3283 | |
| 3284 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3285 | ptr = line; |
| 3286 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3287 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3288 | if (has_spell) |
| 3289 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3290 | /* For checking first word with a capital skip white space. */ |
| 3291 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3292 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3293 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3294 | /* To be able to spell-check over line boundaries copy the end of the |
| 3295 | * current line into nextline[]. Above the start of the next line was |
| 3296 | * copied to nextline[SPWORDLEN]. */ |
| 3297 | if (nextline[SPWORDLEN] == NUL) |
| 3298 | { |
| 3299 | /* No next line or it is empty. */ |
| 3300 | nextlinecol = MAXCOL; |
| 3301 | nextline_idx = 0; |
| 3302 | } |
| 3303 | else |
| 3304 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3305 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3306 | if (v < SPWORDLEN) |
| 3307 | { |
| 3308 | /* Short line, use it completely and append the start of the |
| 3309 | * next line. */ |
| 3310 | nextlinecol = 0; |
| 3311 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3312 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3313 | nextline_idx = v + 1; |
| 3314 | } |
| 3315 | else |
| 3316 | { |
| 3317 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3318 | nextlinecol = v - SPWORDLEN; |
| 3319 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3320 | nextline_idx = SPWORDLEN + 1; |
| 3321 | } |
| 3322 | } |
| 3323 | } |
| 3324 | #endif |
| 3325 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3326 | if (wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3327 | { |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3328 | if (lcs_space || lcs_trail) |
| 3329 | extra_check = TRUE; |
| 3330 | /* find start of trailing whitespace */ |
| 3331 | if (lcs_trail) |
| 3332 | { |
| 3333 | trailcol = (colnr_T)STRLEN(ptr); |
| 3334 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3335 | --trailcol; |
| 3336 | trailcol += (colnr_T) (ptr - line); |
| 3337 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | /* |
| 3341 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3342 | * first character to be displayed. |
| 3343 | */ |
| 3344 | if (wp->w_p_wrap) |
| 3345 | v = wp->w_skipcol; |
| 3346 | else |
| 3347 | v = wp->w_leftcol; |
| 3348 | if (v > 0) |
| 3349 | { |
| 3350 | #ifdef FEAT_MBYTE |
| 3351 | char_u *prev_ptr = ptr; |
| 3352 | #endif |
| 3353 | while (vcol < v && *ptr != NUL) |
| 3354 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3355 | c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3356 | vcol += c; |
| 3357 | #ifdef FEAT_MBYTE |
| 3358 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3359 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3360 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3363 | /* When: |
| 3364 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3365 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3366 | * - 'virtualedit' is set, or |
| 3367 | * - the visual mode is active, |
| 3368 | * the end of the line may be before the start of the displayed part. |
| 3369 | */ |
| 3370 | if (vcol < v && ( |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3371 | #ifdef FEAT_SYN_HL |
| 3372 | wp->w_p_cuc || draw_color_col || |
| 3373 | #endif |
| 3374 | #ifdef FEAT_VIRTUALEDIT |
| 3375 | virtual_active() || |
| 3376 | #endif |
| 3377 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3378 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3379 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3380 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3381 | |
| 3382 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3383 | * that character but skip the first few screen characters. */ |
| 3384 | if (vcol > v) |
| 3385 | { |
| 3386 | vcol -= c; |
| 3387 | #ifdef FEAT_MBYTE |
| 3388 | ptr = prev_ptr; |
| 3389 | #else |
| 3390 | --ptr; |
| 3391 | #endif |
| 3392 | n_skip = v - vcol; |
| 3393 | } |
| 3394 | |
| 3395 | /* |
| 3396 | * Adjust for when the inverted text is before the screen, |
| 3397 | * and when the start of the inverted text is before the screen. |
| 3398 | */ |
| 3399 | if (tocol <= vcol) |
| 3400 | fromcol = 0; |
| 3401 | else if (fromcol >= 0 && fromcol < vcol) |
| 3402 | fromcol = vcol; |
| 3403 | |
| 3404 | #ifdef FEAT_LINEBREAK |
| 3405 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3406 | if (wp->w_p_wrap) |
| 3407 | need_showbreak = TRUE; |
| 3408 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3409 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3410 | /* When spell checking a word we need to figure out the start of the |
| 3411 | * word and if it's badly spelled or not. */ |
| 3412 | if (has_spell) |
| 3413 | { |
| 3414 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3415 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3416 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3417 | |
| 3418 | pos = wp->w_cursor; |
| 3419 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3420 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3421 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3422 | |
| 3423 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3424 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3425 | ptr = line + linecol; |
| 3426 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3427 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3428 | { |
| 3429 | /* no bad word found at line start, don't check until end of a |
| 3430 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3431 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3432 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3433 | } |
| 3434 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3435 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3436 | /* bad word found, use attributes until end of word */ |
| 3437 | word_end = wp->w_cursor.col + len + 1; |
| 3438 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3439 | /* Turn index into actual attributes. */ |
| 3440 | if (spell_hlf != HLF_COUNT) |
| 3441 | spell_attr = highlight_attr[spell_hlf]; |
| 3442 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3443 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3444 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3445 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3446 | /* Need to restart syntax highlighting for this line. */ |
| 3447 | if (has_syntax) |
| 3448 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3449 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3450 | } |
| 3451 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | /* |
| 3455 | * Correct highlighting for cursor that can't be disabled. |
| 3456 | * Avoids having to check this for each character. |
| 3457 | */ |
| 3458 | if (fromcol >= 0) |
| 3459 | { |
| 3460 | if (noinvcur) |
| 3461 | { |
| 3462 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3463 | { |
| 3464 | /* highlighting starts at cursor, let it start just after the |
| 3465 | * cursor */ |
| 3466 | fromcol_prev = fromcol; |
| 3467 | fromcol = -1; |
| 3468 | } |
| 3469 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3470 | /* restart highlighting after the cursor */ |
| 3471 | fromcol_prev = wp->w_virtcol; |
| 3472 | } |
| 3473 | if (fromcol >= tocol) |
| 3474 | fromcol = -1; |
| 3475 | } |
| 3476 | |
| 3477 | #ifdef FEAT_SEARCH_EXTRA |
| 3478 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3479 | * Handle highlighting the last used search pattern and matches. |
| 3480 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3481 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3482 | cur = wp->w_match_head; |
| 3483 | shl_flag = FALSE; |
| 3484 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3485 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3486 | if (shl_flag == FALSE) |
| 3487 | { |
| 3488 | shl = &search_hl; |
| 3489 | shl_flag = TRUE; |
| 3490 | } |
| 3491 | else |
| 3492 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3493 | shl->startcol = MAXCOL; |
| 3494 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3495 | shl->attr_cur = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3496 | v = (long)(ptr - line); |
| 3497 | if (cur != NULL) |
| 3498 | cur->pos.cur = 0; |
| 3499 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3500 | |
| 3501 | /* Need to get the line again, a multi-line regexp may have made it |
| 3502 | * invalid. */ |
| 3503 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3504 | ptr = line + v; |
| 3505 | |
| 3506 | if (shl->lnum != 0 && shl->lnum <= lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3507 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3508 | if (shl->lnum == lnum) |
| 3509 | shl->startcol = shl->rm.startpos[0].col; |
| 3510 | else |
| 3511 | shl->startcol = 0; |
| 3512 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3513 | - shl->rm.startpos[0].lnum) |
| 3514 | shl->endcol = shl->rm.endpos[0].col; |
| 3515 | else |
| 3516 | shl->endcol = MAXCOL; |
| 3517 | /* Highlight one character for an empty match. */ |
| 3518 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3519 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3520 | #ifdef FEAT_MBYTE |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3521 | if (has_mbyte && line[shl->endcol] != NUL) |
| 3522 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
| 3523 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3524 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3525 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3526 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3527 | if ((long)shl->startcol < v) /* match at leftcol */ |
| 3528 | { |
| 3529 | shl->attr_cur = shl->attr; |
| 3530 | search_attr = shl->attr; |
| 3531 | } |
| 3532 | area_highlighting = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3533 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3534 | if (shl != &search_hl && cur != NULL) |
| 3535 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3536 | } |
| 3537 | #endif |
| 3538 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3539 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3540 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3541 | * when Visual mode is active, because it's not clear what is selected |
| 3542 | * then. */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3543 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3544 | && !(wp == curwin && VIsual_active)) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3545 | { |
| 3546 | line_attr = hl_attr(HLF_CUL); |
| 3547 | area_highlighting = TRUE; |
| 3548 | } |
| 3549 | #endif |
| 3550 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3551 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3552 | col = 0; |
| 3553 | #ifdef FEAT_RIGHTLEFT |
| 3554 | if (wp->w_p_rl) |
| 3555 | { |
| 3556 | /* Rightleft window: process the text in the normal direction, but put |
| 3557 | * it in current_ScreenLine[] from right to left. Start at the |
| 3558 | * rightmost column of the window. */ |
| 3559 | col = W_WIDTH(wp) - 1; |
| 3560 | off += col; |
| 3561 | } |
| 3562 | #endif |
| 3563 | |
| 3564 | /* |
| 3565 | * Repeat for the whole displayed line. |
| 3566 | */ |
| 3567 | for (;;) |
| 3568 | { |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3569 | #ifdef FEAT_CONCEAL |
| 3570 | has_match_conc = FALSE; |
| 3571 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3572 | /* Skip this quickly when working on the text. */ |
| 3573 | if (draw_state != WL_LINE) |
| 3574 | { |
| 3575 | #ifdef FEAT_CMDWIN |
| 3576 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3577 | { |
| 3578 | draw_state = WL_CMDLINE; |
| 3579 | if (cmdwin_type != 0 && wp == curwin) |
| 3580 | { |
| 3581 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3582 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3583 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3584 | char_attr = hl_attr(HLF_AT); |
| 3585 | } |
| 3586 | } |
| 3587 | #endif |
| 3588 | |
| 3589 | #ifdef FEAT_FOLDING |
| 3590 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3591 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3592 | int fdc = compute_foldcolumn(wp, 0); |
| 3593 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3594 | draw_state = WL_FOLD; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3595 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3596 | { |
| 3597 | /* Draw the 'foldcolumn'. */ |
| 3598 | fill_foldcolumn(extra, wp, FALSE, lnum); |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3599 | n_extra = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3600 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3601 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3602 | c_extra = NUL; |
| 3603 | char_attr = hl_attr(HLF_FC); |
| 3604 | } |
| 3605 | } |
| 3606 | #endif |
| 3607 | |
| 3608 | #ifdef FEAT_SIGNS |
| 3609 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3610 | { |
| 3611 | draw_state = WL_SIGN; |
| 3612 | /* Show the sign column when there are any signs in this |
| 3613 | * buffer or when using Netbeans. */ |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3614 | if (draw_signcolumn(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3615 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3616 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3617 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3618 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3619 | # endif |
| 3620 | |
| 3621 | /* Draw two cells with the sign value or blank. */ |
| 3622 | c_extra = ' '; |
| 3623 | char_attr = hl_attr(HLF_SC); |
| 3624 | n_extra = 2; |
| 3625 | |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3626 | if (row == startrow |
| 3627 | #ifdef FEAT_DIFF |
| 3628 | + filler_lines && filler_todo <= 0 |
| 3629 | #endif |
| 3630 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3631 | { |
| 3632 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3633 | SIGN_TEXT); |
| 3634 | # ifdef FEAT_SIGN_ICONS |
| 3635 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3636 | SIGN_ICON); |
| 3637 | if (gui.in_use && icon_sign != 0) |
| 3638 | { |
| 3639 | /* Use the image in this position. */ |
| 3640 | c_extra = SIGN_BYTE; |
| 3641 | # ifdef FEAT_NETBEANS_INTG |
| 3642 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3643 | c_extra = MULTISIGN_BYTE; |
| 3644 | # endif |
| 3645 | char_attr = icon_sign; |
| 3646 | } |
| 3647 | else |
| 3648 | # endif |
| 3649 | if (text_sign != 0) |
| 3650 | { |
| 3651 | p_extra = sign_get_text(text_sign); |
| 3652 | if (p_extra != NULL) |
| 3653 | { |
| 3654 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3655 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3656 | } |
| 3657 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | #endif |
| 3663 | |
| 3664 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3665 | { |
| 3666 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3667 | /* Display the absolute or relative line number. After the |
| 3668 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3669 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3670 | && (row == startrow |
| 3671 | #ifdef FEAT_DIFF |
| 3672 | + filler_lines |
| 3673 | #endif |
| 3674 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3675 | { |
| 3676 | /* Draw the line number (empty space after wrapping). */ |
| 3677 | if (row == startrow |
| 3678 | #ifdef FEAT_DIFF |
| 3679 | + filler_lines |
| 3680 | #endif |
| 3681 | ) |
| 3682 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3683 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3684 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3685 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3686 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3687 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3688 | num = (long)lnum; |
| 3689 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3690 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3691 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3692 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3693 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3694 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3695 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3696 | num = lnum; |
| 3697 | fmt = "%-*ld "; |
| 3698 | } |
| 3699 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3700 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3701 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3702 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3703 | if (wp->w_skipcol > 0) |
| 3704 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3705 | *p_extra = '-'; |
| 3706 | #ifdef FEAT_RIGHTLEFT |
| 3707 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3708 | rl_mirror(extra); |
| 3709 | #endif |
| 3710 | p_extra = extra; |
| 3711 | c_extra = NUL; |
| 3712 | } |
| 3713 | else |
| 3714 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3715 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3716 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3717 | #ifdef FEAT_SYN_HL |
| 3718 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3719 | * the current line differently. |
| 3720 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3721 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3722 | if ((wp->w_p_cul || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3723 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3724 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3725 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3726 | } |
| 3727 | } |
| 3728 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3729 | #ifdef FEAT_LINEBREAK |
| 3730 | if (wp->w_p_brisbr && draw_state == WL_BRI - 1 |
| 3731 | && n_extra == 0 && *p_sbr != NUL) |
| 3732 | /* draw indent after showbreak value */ |
| 3733 | draw_state = WL_BRI; |
| 3734 | else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) |
| 3735 | /* After the showbreak, draw the breakindent */ |
| 3736 | draw_state = WL_BRI - 1; |
| 3737 | |
| 3738 | /* draw 'breakindent': indent wrapped text accordingly */ |
| 3739 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 3740 | { |
| 3741 | draw_state = WL_BRI; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3742 | if (wp->w_p_bri && n_extra == 0 && row != startrow |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3743 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3744 | && filler_lines == 0 |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3745 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3746 | ) |
| 3747 | { |
| 3748 | char_attr = 0; /* was: hl_attr(HLF_AT); */ |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3749 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3750 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3751 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3752 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3753 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3754 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3755 | char_attr = hl_combine_attr(char_attr, |
| 3756 | hl_attr(HLF_CUL)); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3757 | # endif |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3758 | } |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3759 | # endif |
Bram Moolenaar | b8b5746 | 2014-07-03 22:54:08 +0200 | [diff] [blame] | 3760 | p_extra = NULL; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3761 | c_extra = ' '; |
| 3762 | n_extra = get_breakindent_win(wp, |
| 3763 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 3764 | /* Correct end of highlighted area for 'breakindent', |
| 3765 | * required when 'linebreak' is also set. */ |
| 3766 | if (tocol == vcol) |
| 3767 | tocol += n_extra; |
| 3768 | } |
| 3769 | } |
| 3770 | #endif |
| 3771 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3772 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3773 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3774 | { |
| 3775 | draw_state = WL_SBR; |
| 3776 | # ifdef FEAT_DIFF |
| 3777 | if (filler_todo > 0) |
| 3778 | { |
| 3779 | /* Draw "deleted" diff line(s). */ |
| 3780 | if (char2cells(fill_diff) > 1) |
| 3781 | c_extra = '-'; |
| 3782 | else |
| 3783 | c_extra = fill_diff; |
| 3784 | # ifdef FEAT_RIGHTLEFT |
| 3785 | if (wp->w_p_rl) |
| 3786 | n_extra = col + 1; |
| 3787 | else |
| 3788 | # endif |
| 3789 | n_extra = W_WIDTH(wp) - col; |
| 3790 | char_attr = hl_attr(HLF_DED); |
| 3791 | } |
| 3792 | # endif |
| 3793 | # ifdef FEAT_LINEBREAK |
| 3794 | if (*p_sbr != NUL && need_showbreak) |
| 3795 | { |
| 3796 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3797 | p_extra = p_sbr; |
| 3798 | c_extra = NUL; |
| 3799 | n_extra = (int)STRLEN(p_sbr); |
| 3800 | char_attr = hl_attr(HLF_AT); |
| 3801 | need_showbreak = FALSE; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 3802 | vcol_sbr = vcol + MB_CHARLEN(p_sbr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3803 | /* Correct end of highlighted area for 'showbreak', |
| 3804 | * required when 'linebreak' is also set. */ |
| 3805 | if (tocol == vcol) |
| 3806 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3807 | #ifdef FEAT_SYN_HL |
| 3808 | /* combine 'showbreak' with 'cursorline' */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3809 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3810 | char_attr = hl_combine_attr(char_attr, |
| 3811 | hl_attr(HLF_CUL)); |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3812 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3813 | } |
| 3814 | # endif |
| 3815 | } |
| 3816 | #endif |
| 3817 | |
| 3818 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3819 | { |
| 3820 | draw_state = WL_LINE; |
| 3821 | if (saved_n_extra) |
| 3822 | { |
| 3823 | /* Continue item from end of wrapped line. */ |
| 3824 | n_extra = saved_n_extra; |
| 3825 | c_extra = saved_c_extra; |
| 3826 | p_extra = saved_p_extra; |
| 3827 | char_attr = saved_char_attr; |
| 3828 | } |
| 3829 | else |
| 3830 | char_attr = 0; |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3835 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3836 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3837 | #ifdef FEAT_DIFF |
| 3838 | && filler_todo <= 0 |
| 3839 | #endif |
| 3840 | ) |
| 3841 | { |
| 3842 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3843 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3844 | /* Pretend we have finished updating the window. Except when |
| 3845 | * 'cursorcolumn' is set. */ |
| 3846 | #ifdef FEAT_SYN_HL |
| 3847 | if (wp->w_p_cuc) |
| 3848 | row = wp->w_cline_row + wp->w_cline_height; |
| 3849 | else |
| 3850 | #endif |
| 3851 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3852 | break; |
| 3853 | } |
| 3854 | |
| 3855 | if (draw_state == WL_LINE && area_highlighting) |
| 3856 | { |
| 3857 | /* handle Visual or match highlighting in this line */ |
| 3858 | if (vcol == fromcol |
| 3859 | #ifdef FEAT_MBYTE |
| 3860 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3861 | && (*mb_ptr2cells)(ptr) > 1) |
| 3862 | #endif |
| 3863 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3864 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3865 | && vcol < tocol)) |
| 3866 | area_attr = attr; /* start highlighting */ |
| 3867 | else if (area_attr != 0 |
| 3868 | && (vcol == tocol |
| 3869 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3870 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3871 | |
| 3872 | #ifdef FEAT_SEARCH_EXTRA |
| 3873 | if (!n_extra) |
| 3874 | { |
| 3875 | /* |
| 3876 | * Check for start/end of search pattern match. |
| 3877 | * After end, check for start/end of next match. |
| 3878 | * When another match, have to check for start again. |
| 3879 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3880 | * Do this for 'search_hl' and the match list (ordered by |
| 3881 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3882 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3883 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3884 | cur = wp->w_match_head; |
| 3885 | shl_flag = FALSE; |
| 3886 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3887 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3888 | if (shl_flag == FALSE |
| 3889 | && ((cur != NULL |
| 3890 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3891 | || cur == NULL)) |
| 3892 | { |
| 3893 | shl = &search_hl; |
| 3894 | shl_flag = TRUE; |
| 3895 | } |
| 3896 | else |
| 3897 | shl = &cur->hl; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3898 | if (cur != NULL) |
| 3899 | cur->pos.cur = 0; |
| 3900 | pos_inprogress = TRUE; |
| 3901 | while (shl->rm.regprog != NULL |
| 3902 | || (cur != NULL && pos_inprogress)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3903 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3904 | if (shl->startcol != MAXCOL |
| 3905 | && v >= (long)shl->startcol |
| 3906 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3907 | { |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3908 | #ifdef FEAT_MBYTE |
| 3909 | int tmp_col = v + MB_PTR2LEN(ptr); |
| 3910 | |
| 3911 | if (shl->endcol < tmp_col) |
| 3912 | shl->endcol = tmp_col; |
| 3913 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3914 | shl->attr_cur = shl->attr; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3915 | #ifdef FEAT_CONCEAL |
| 3916 | if (cur != NULL && syn_name2id((char_u *)"Conceal") |
| 3917 | == cur->hlg_id) |
| 3918 | { |
| 3919 | has_match_conc = TRUE; |
| 3920 | match_conc = cur->conceal_char; |
| 3921 | } |
| 3922 | else |
| 3923 | has_match_conc = match_conc = FALSE; |
| 3924 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3925 | } |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3926 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3927 | { |
| 3928 | shl->attr_cur = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3929 | #ifdef FEAT_CONCEAL |
| 3930 | prev_syntax_id = 0; |
| 3931 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3932 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3933 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3934 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3935 | |
| 3936 | /* Need to get the line again, a multi-line regexp |
| 3937 | * may have made it invalid. */ |
| 3938 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3939 | ptr = line + v; |
| 3940 | |
| 3941 | if (shl->lnum == lnum) |
| 3942 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3943 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3944 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3945 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3946 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3947 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3948 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3949 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3950 | { |
| 3951 | /* highlight empty match, try again after |
| 3952 | * it */ |
| 3953 | #ifdef FEAT_MBYTE |
| 3954 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3955 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3956 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3957 | else |
| 3958 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3959 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | /* Loop to check if the match starts at the |
| 3963 | * current position */ |
| 3964 | continue; |
| 3965 | } |
| 3966 | } |
| 3967 | break; |
| 3968 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3969 | if (shl != &search_hl && cur != NULL) |
| 3970 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3971 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3972 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3973 | /* Use attributes from match with highest priority among |
| 3974 | * 'search_hl' and the match list. */ |
| 3975 | search_attr = search_hl.attr_cur; |
| 3976 | cur = wp->w_match_head; |
| 3977 | shl_flag = FALSE; |
| 3978 | while (cur != NULL || shl_flag == FALSE) |
| 3979 | { |
| 3980 | if (shl_flag == FALSE |
| 3981 | && ((cur != NULL |
| 3982 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3983 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3984 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3985 | shl = &search_hl; |
| 3986 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3987 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3988 | else |
| 3989 | shl = &cur->hl; |
| 3990 | if (shl->attr_cur != 0) |
| 3991 | search_attr = shl->attr_cur; |
| 3992 | if (shl != &search_hl && cur != NULL) |
| 3993 | cur = cur->next; |
| 3994 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3995 | } |
| 3996 | #endif |
| 3997 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3998 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3999 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4000 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4001 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 4002 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4003 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4004 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 4005 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4006 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4007 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4008 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4009 | line_attr = hl_combine_attr(line_attr, hl_attr(HLF_CUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4010 | } |
| 4011 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4012 | |
| 4013 | /* Decide which of the highlight attributes to use. */ |
| 4014 | attr_pri = TRUE; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4015 | #ifdef LINE_ATTR |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4016 | if (area_attr != 0) |
| 4017 | char_attr = hl_combine_attr(line_attr, area_attr); |
| 4018 | else if (search_attr != 0) |
| 4019 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4020 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 4021 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 4022 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 4023 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 4024 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4025 | char_attr = line_attr; |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4026 | #else |
| 4027 | if (area_attr != 0) |
| 4028 | char_attr = area_attr; |
| 4029 | else if (search_attr != 0) |
| 4030 | char_attr = search_attr; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4031 | #endif |
| 4032 | else |
| 4033 | { |
| 4034 | attr_pri = FALSE; |
| 4035 | #ifdef FEAT_SYN_HL |
| 4036 | if (has_syntax) |
| 4037 | char_attr = syntax_attr; |
| 4038 | else |
| 4039 | #endif |
| 4040 | char_attr = 0; |
| 4041 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | /* |
| 4045 | * Get the next character to put on the screen. |
| 4046 | */ |
| 4047 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 4048 | * The "p_extra" points to the extra stuff that is inserted to |
| 4049 | * represent special characters (non-printable stuff) and other |
| 4050 | * things. When all characters are the same, c_extra is used. |
| 4051 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 4052 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4053 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 4054 | */ |
| 4055 | if (n_extra > 0) |
| 4056 | { |
| 4057 | if (c_extra != NUL) |
| 4058 | { |
| 4059 | c = c_extra; |
| 4060 | #ifdef FEAT_MBYTE |
| 4061 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 4062 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4063 | { |
| 4064 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4065 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4066 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4067 | } |
| 4068 | else |
| 4069 | mb_utf8 = FALSE; |
| 4070 | #endif |
| 4071 | } |
| 4072 | else |
| 4073 | { |
| 4074 | c = *p_extra; |
| 4075 | #ifdef FEAT_MBYTE |
| 4076 | if (has_mbyte) |
| 4077 | { |
| 4078 | mb_c = c; |
| 4079 | if (enc_utf8) |
| 4080 | { |
| 4081 | /* If the UTF-8 character is more than one byte: |
| 4082 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4083 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4084 | mb_utf8 = FALSE; |
| 4085 | if (mb_l > n_extra) |
| 4086 | mb_l = 1; |
| 4087 | else if (mb_l > 1) |
| 4088 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4089 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4090 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4091 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | else |
| 4095 | { |
| 4096 | /* if this is a DBCS character, put it in "mb_c" */ |
| 4097 | mb_l = MB_BYTE2LEN(c); |
| 4098 | if (mb_l >= n_extra) |
| 4099 | mb_l = 1; |
| 4100 | else if (mb_l > 1) |
| 4101 | mb_c = (c << 8) + p_extra[1]; |
| 4102 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4103 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4104 | mb_l = 1; |
| 4105 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4106 | /* If a double-width char doesn't fit display a '>' in the |
| 4107 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4108 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4109 | # ifdef FEAT_RIGHTLEFT |
| 4110 | wp->w_p_rl ? (col <= 0) : |
| 4111 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4112 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4113 | && (*mb_char2cells)(mb_c) == 2) |
| 4114 | { |
| 4115 | c = '>'; |
| 4116 | mb_c = c; |
| 4117 | mb_l = 1; |
| 4118 | mb_utf8 = FALSE; |
| 4119 | multi_attr = hl_attr(HLF_AT); |
| 4120 | /* put the pointer back to output the double-width |
| 4121 | * character at the start of the next line. */ |
| 4122 | ++n_extra; |
| 4123 | --p_extra; |
| 4124 | } |
| 4125 | else |
| 4126 | { |
| 4127 | n_extra -= mb_l - 1; |
| 4128 | p_extra += mb_l - 1; |
| 4129 | } |
| 4130 | } |
| 4131 | #endif |
| 4132 | ++p_extra; |
| 4133 | } |
| 4134 | --n_extra; |
| 4135 | } |
| 4136 | else |
| 4137 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4138 | if (p_extra_free != NULL) |
| 4139 | { |
| 4140 | vim_free(p_extra_free); |
| 4141 | p_extra_free = NULL; |
| 4142 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4143 | /* |
| 4144 | * Get a character from the line itself. |
| 4145 | */ |
| 4146 | c = *ptr; |
| 4147 | #ifdef FEAT_MBYTE |
| 4148 | if (has_mbyte) |
| 4149 | { |
| 4150 | mb_c = c; |
| 4151 | if (enc_utf8) |
| 4152 | { |
| 4153 | /* If the UTF-8 character is more than one byte: Decode it |
| 4154 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4155 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4156 | mb_utf8 = FALSE; |
| 4157 | if (mb_l > 1) |
| 4158 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4159 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4160 | /* Overlong encoded ASCII or ASCII with composing char |
| 4161 | * is displayed normally, except a NUL. */ |
| 4162 | if (mb_c < 0x80) |
| 4163 | c = mb_c; |
| 4164 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4165 | |
| 4166 | /* At start of the line we can have a composing char. |
| 4167 | * Draw it as a space with a composing char. */ |
| 4168 | if (utf_iscomposing(mb_c)) |
| 4169 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4170 | int i; |
| 4171 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4172 | for (i = Screen_mco - 1; i > 0; --i) |
| 4173 | u8cc[i] = u8cc[i - 1]; |
| 4174 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4175 | mb_c = ' '; |
| 4176 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | if ((mb_l == 1 && c >= 0x80) |
| 4180 | || (mb_l >= 1 && mb_c == 0) |
| 4181 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4182 | # ifdef UNICODE16 |
| 4183 | || mb_c >= 0x10000 |
| 4184 | # endif |
| 4185 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4186 | { |
| 4187 | /* |
| 4188 | * Illegal UTF-8 byte: display as <xx>. |
| 4189 | * Non-BMP character : display as ? or fullwidth ?. |
| 4190 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4191 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4192 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4193 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4194 | { |
| 4195 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4196 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4197 | if (wp->w_p_rl) /* reverse */ |
| 4198 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4199 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4200 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4201 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4202 | else if (utf_char2cells(mb_c) != 2) |
| 4203 | STRCPY(extra, "?"); |
| 4204 | else |
| 4205 | /* 0xff1f in UTF-8: full-width '?' */ |
| 4206 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4207 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4208 | |
| 4209 | p_extra = extra; |
| 4210 | c = *p_extra; |
| 4211 | mb_c = mb_ptr2char_adv(&p_extra); |
| 4212 | mb_utf8 = (c >= 0x80); |
| 4213 | n_extra = (int)STRLEN(p_extra); |
| 4214 | c_extra = NUL; |
| 4215 | if (area_attr == 0 && search_attr == 0) |
| 4216 | { |
| 4217 | n_attr = n_extra + 1; |
| 4218 | extra_attr = hl_attr(HLF_8); |
| 4219 | saved_attr2 = char_attr; /* save current attr */ |
| 4220 | } |
| 4221 | } |
| 4222 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4223 | mb_l = 1; |
| 4224 | #ifdef FEAT_ARABIC |
| 4225 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 4226 | { |
| 4227 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4228 | int pc, pc1, nc; |
| 4229 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4230 | |
| 4231 | /* The idea of what is the previous and next |
| 4232 | * character depends on 'rightleft'. */ |
| 4233 | if (wp->w_p_rl) |
| 4234 | { |
| 4235 | pc = prev_c; |
| 4236 | pc1 = prev_c1; |
| 4237 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4238 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4239 | } |
| 4240 | else |
| 4241 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4242 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4243 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4244 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4245 | } |
| 4246 | prev_c = mb_c; |
| 4247 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4248 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4249 | } |
| 4250 | else |
| 4251 | prev_c = mb_c; |
| 4252 | #endif |
| 4253 | } |
| 4254 | else /* enc_dbcs */ |
| 4255 | { |
| 4256 | mb_l = MB_BYTE2LEN(c); |
| 4257 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4258 | mb_l = 1; |
| 4259 | else if (mb_l > 1) |
| 4260 | { |
| 4261 | /* We assume a second byte below 32 is illegal. |
| 4262 | * Hopefully this is OK for all double-byte encodings! |
| 4263 | */ |
| 4264 | if (ptr[1] >= 32) |
| 4265 | mb_c = (c << 8) + ptr[1]; |
| 4266 | else |
| 4267 | { |
| 4268 | if (ptr[1] == NUL) |
| 4269 | { |
| 4270 | /* head byte at end of line */ |
| 4271 | mb_l = 1; |
| 4272 | transchar_nonprint(extra, c); |
| 4273 | } |
| 4274 | else |
| 4275 | { |
| 4276 | /* illegal tail byte */ |
| 4277 | mb_l = 2; |
| 4278 | STRCPY(extra, "XX"); |
| 4279 | } |
| 4280 | p_extra = extra; |
| 4281 | n_extra = (int)STRLEN(extra) - 1; |
| 4282 | c_extra = NUL; |
| 4283 | c = *p_extra++; |
| 4284 | if (area_attr == 0 && search_attr == 0) |
| 4285 | { |
| 4286 | n_attr = n_extra + 1; |
| 4287 | extra_attr = hl_attr(HLF_8); |
| 4288 | saved_attr2 = char_attr; /* save current attr */ |
| 4289 | } |
| 4290 | mb_c = c; |
| 4291 | } |
| 4292 | } |
| 4293 | } |
| 4294 | /* If a double-width char doesn't fit display a '>' in the |
| 4295 | * last column; the character is displayed at the start of the |
| 4296 | * next line. */ |
| 4297 | if (( |
| 4298 | # ifdef FEAT_RIGHTLEFT |
| 4299 | wp->w_p_rl ? (col <= 0) : |
| 4300 | # endif |
| 4301 | (col >= W_WIDTH(wp) - 1)) |
| 4302 | && (*mb_char2cells)(mb_c) == 2) |
| 4303 | { |
| 4304 | c = '>'; |
| 4305 | mb_c = c; |
| 4306 | mb_utf8 = FALSE; |
| 4307 | mb_l = 1; |
| 4308 | multi_attr = hl_attr(HLF_AT); |
| 4309 | /* Put pointer back so that the character will be |
| 4310 | * displayed at the start of the next line. */ |
| 4311 | --ptr; |
| 4312 | } |
| 4313 | else if (*ptr != NUL) |
| 4314 | ptr += mb_l - 1; |
| 4315 | |
| 4316 | /* 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] | 4317 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4318 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4319 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4320 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4321 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4322 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4323 | c = ' '; |
| 4324 | if (area_attr == 0 && search_attr == 0) |
| 4325 | { |
| 4326 | n_attr = n_extra + 1; |
| 4327 | extra_attr = hl_attr(HLF_AT); |
| 4328 | saved_attr2 = char_attr; /* save current attr */ |
| 4329 | } |
| 4330 | mb_c = c; |
| 4331 | mb_utf8 = FALSE; |
| 4332 | mb_l = 1; |
| 4333 | } |
| 4334 | |
| 4335 | } |
| 4336 | #endif |
| 4337 | ++ptr; |
| 4338 | |
| 4339 | if (extra_check) |
| 4340 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4341 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4342 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4343 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4344 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4345 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4346 | /* Get syntax attribute, unless still at the start of the line |
| 4347 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4348 | v = (long)(ptr - line); |
| 4349 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4350 | { |
| 4351 | /* Get the syntax attribute for the character. If there |
| 4352 | * is an error, disable syntax highlighting. */ |
| 4353 | save_did_emsg = did_emsg; |
| 4354 | did_emsg = FALSE; |
| 4355 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4356 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4357 | # ifdef FEAT_SPELL |
| 4358 | has_spell ? &can_spell : |
| 4359 | # endif |
| 4360 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4361 | |
| 4362 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4363 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4364 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4365 | has_syntax = FALSE; |
| 4366 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4367 | else |
| 4368 | did_emsg = save_did_emsg; |
| 4369 | |
| 4370 | /* Need to get the line again, a multi-line regexp may |
| 4371 | * have made it invalid. */ |
| 4372 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4373 | ptr = line + v; |
| 4374 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4375 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4376 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4377 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4378 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4379 | # ifdef FEAT_CONCEAL |
| 4380 | /* no concealing past the end of the line, it interferes |
| 4381 | * with line highlighting */ |
| 4382 | if (c == NUL) |
| 4383 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4384 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4385 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4386 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4387 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4388 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4389 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4390 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4391 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4392 | * Only do this when there is no syntax highlighting, the |
| 4393 | * @Spell cluster is not used or the current syntax item |
| 4394 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4395 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4396 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4397 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4398 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4399 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4400 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4401 | # endif |
| 4402 | if (c != 0 && ( |
| 4403 | # ifdef FEAT_SYN_HL |
| 4404 | !has_syntax || |
| 4405 | # endif |
| 4406 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4407 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4408 | char_u *prev_ptr, *p; |
| 4409 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4410 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4411 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4412 | if (has_mbyte) |
| 4413 | { |
| 4414 | prev_ptr = ptr - mb_l; |
| 4415 | v -= mb_l - 1; |
| 4416 | } |
| 4417 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4418 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4419 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4420 | |
| 4421 | /* Use nextline[] if possible, it has the start of the |
| 4422 | * next line concatenated. */ |
| 4423 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4424 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4425 | else |
| 4426 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4427 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4428 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4429 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4430 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4431 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4432 | /* In Insert mode only highlight a word that |
| 4433 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4434 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4435 | && (State & INSERT) != 0 |
| 4436 | && wp->w_cursor.lnum == lnum |
| 4437 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4438 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4439 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4440 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4441 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4442 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4443 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4444 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4445 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4446 | && (p - nextline) + len > nextline_idx) |
| 4447 | { |
| 4448 | /* Remember that the good word continues at the |
| 4449 | * start of the next line. */ |
| 4450 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4451 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4452 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4453 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4454 | /* Turn index into actual attributes. */ |
| 4455 | if (spell_hlf != HLF_COUNT) |
| 4456 | spell_attr = highlight_attr[spell_hlf]; |
| 4457 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4458 | if (cap_col > 0) |
| 4459 | { |
| 4460 | if (p != prev_ptr |
| 4461 | && (p - nextline) + cap_col >= nextline_idx) |
| 4462 | { |
| 4463 | /* Remember that the word in the next line |
| 4464 | * must start with a capital. */ |
| 4465 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4466 | cap_col = (int)((p - nextline) + cap_col |
| 4467 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4468 | } |
| 4469 | else |
| 4470 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4471 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4472 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4473 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4474 | } |
| 4475 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4476 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4477 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4478 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4479 | else |
| 4480 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4481 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4482 | #endif |
| 4483 | #ifdef FEAT_LINEBREAK |
| 4484 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4485 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4486 | */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4487 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4488 | { |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4489 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4490 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4491 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4492 | char_u *p = ptr - ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4493 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4494 | mb_off + |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4495 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4496 | 1); |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4497 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4498 | /* TODO: is passing p for start of the line OK? */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4499 | n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4500 | NULL) - 1; |
Bram Moolenaar | a365091 | 2014-11-19 13:21:57 +0100 | [diff] [blame] | 4501 | if (c == TAB && n_extra + col > W_WIDTH(wp)) |
| 4502 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4503 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4504 | |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4505 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4506 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4507 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4508 | c_extra = ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4509 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4510 | if (vim_iswhite(c)) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4511 | { |
| 4512 | #ifdef FEAT_CONCEAL |
| 4513 | if (c == TAB) |
| 4514 | /* See "Tab alignment" below. */ |
| 4515 | FIX_FOR_BOGUSCOLS; |
| 4516 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4517 | if (!wp->w_p_list) |
| 4518 | c = ' '; |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4519 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4520 | } |
| 4521 | #endif |
| 4522 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 4523 | /* 'list': change char 160 to lcs_nbsp and space to lcs_space. |
| 4524 | */ |
| 4525 | if (wp->w_p_list |
| 4526 | && (((c == 160 |
| 4527 | #ifdef FEAT_MBYTE |
| 4528 | || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)) |
| 4529 | #endif |
| 4530 | ) && lcs_nbsp) |
| 4531 | || (c == ' ' && lcs_space && ptr - line <= trailcol))) |
| 4532 | { |
| 4533 | c = (c == ' ') ? lcs_space : lcs_nbsp; |
| 4534 | if (area_attr == 0 && search_attr == 0) |
| 4535 | { |
| 4536 | n_attr = 1; |
| 4537 | extra_attr = hl_attr(HLF_8); |
| 4538 | saved_attr2 = char_attr; /* save current attr */ |
| 4539 | } |
| 4540 | #ifdef FEAT_MBYTE |
| 4541 | mb_c = c; |
| 4542 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4543 | { |
| 4544 | mb_utf8 = TRUE; |
| 4545 | u8cc[0] = 0; |
| 4546 | c = 0xc0; |
| 4547 | } |
| 4548 | else |
| 4549 | mb_utf8 = FALSE; |
| 4550 | #endif |
| 4551 | } |
| 4552 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4553 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4554 | { |
| 4555 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4556 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4557 | { |
| 4558 | n_attr = 1; |
| 4559 | extra_attr = hl_attr(HLF_8); |
| 4560 | saved_attr2 = char_attr; /* save current attr */ |
| 4561 | } |
| 4562 | #ifdef FEAT_MBYTE |
| 4563 | mb_c = c; |
| 4564 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4565 | { |
| 4566 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4567 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4568 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4569 | } |
| 4570 | else |
| 4571 | mb_utf8 = FALSE; |
| 4572 | #endif |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | /* |
| 4577 | * Handling of non-printable characters. |
| 4578 | */ |
Bram Moolenaar | 88e8f9f | 2016-01-20 22:48:02 +0100 | [diff] [blame] | 4579 | if (!vim_isprintc(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4580 | { |
| 4581 | /* |
| 4582 | * when getting a character from the file, we may have to |
| 4583 | * turn it into something else on the way to putting it |
| 4584 | * into "ScreenLines". |
| 4585 | */ |
| 4586 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4587 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4588 | int tab_len = 0; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4589 | long vcol_adjusted = vcol; /* removed showbreak length */ |
| 4590 | #ifdef FEAT_LINEBREAK |
| 4591 | /* only adjust the tab_len, when at the first column |
| 4592 | * after the showbreak value was drawn */ |
| 4593 | if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 4594 | vcol_adjusted = vcol - MB_CHARLEN(p_sbr); |
| 4595 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4596 | /* tab amount depends on current column */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4597 | tab_len = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4598 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 4599 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4600 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81c85d | 2014-07-30 16:44:22 +0200 | [diff] [blame] | 4601 | if (!wp->w_p_lbr || !wp->w_p_list) |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4602 | #endif |
| 4603 | /* tab amount depends on current column */ |
| 4604 | n_extra = tab_len; |
| 4605 | #ifdef FEAT_LINEBREAK |
| 4606 | else |
| 4607 | { |
| 4608 | char_u *p; |
| 4609 | int len = n_extra; |
| 4610 | int i; |
| 4611 | int saved_nextra = n_extra; |
| 4612 | |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4613 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4614 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4615 | /* there are characters to conceal */ |
| 4616 | tab_len += vcol_off; |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4617 | /* boguscols before FIX_FOR_BOGUSCOLS macro from above |
| 4618 | */ |
| 4619 | if (wp->w_p_list && lcs_tab1 && old_boguscols > 0 |
| 4620 | && n_extra > tab_len) |
| 4621 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4622 | #endif |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4623 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4624 | /* if n_extra > 0, it gives the number of chars, to |
| 4625 | * use for a tab, else we need to calculate the width |
| 4626 | * for a tab */ |
| 4627 | #ifdef FEAT_MBYTE |
| 4628 | len = (tab_len * mb_char2len(lcs_tab2)); |
| 4629 | if (n_extra > 0) |
| 4630 | len += n_extra - tab_len; |
| 4631 | #endif |
| 4632 | c = lcs_tab1; |
| 4633 | p = alloc((unsigned)(len + 1)); |
| 4634 | vim_memset(p, ' ', len); |
| 4635 | p[len] = NUL; |
| 4636 | p_extra_free = p; |
| 4637 | for (i = 0; i < tab_len; i++) |
| 4638 | { |
| 4639 | #ifdef FEAT_MBYTE |
| 4640 | mb_char2bytes(lcs_tab2, p); |
| 4641 | p += mb_char2len(lcs_tab2); |
| 4642 | n_extra += mb_char2len(lcs_tab2) |
| 4643 | - (saved_nextra > 0 ? 1 : 0); |
| 4644 | #else |
| 4645 | p[i] = lcs_tab2; |
| 4646 | #endif |
| 4647 | } |
| 4648 | p_extra = p_extra_free; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4649 | #ifdef FEAT_CONCEAL |
| 4650 | /* n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 4651 | * macro below, so need to adjust for that here */ |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4652 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4653 | n_extra -= vcol_off; |
| 4654 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4655 | } |
| 4656 | #endif |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4657 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4658 | { |
| 4659 | int vc_saved = vcol_off; |
| 4660 | |
| 4661 | /* Tab alignment should be identical regardless of |
| 4662 | * 'conceallevel' value. So tab compensates of all |
| 4663 | * previous concealed characters, and thus resets |
| 4664 | * vcol_off and boguscols accumulated so far in the |
| 4665 | * line. Note that the tab can be longer than |
| 4666 | * 'tabstop' when there are concealed characters. */ |
| 4667 | FIX_FOR_BOGUSCOLS; |
| 4668 | |
| 4669 | /* Make sure, the highlighting for the tab char will be |
| 4670 | * correctly set further below (effectively reverts the |
| 4671 | * FIX_FOR_BOGSUCOLS macro */ |
| 4672 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4673 | && lcs_tab1) |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4674 | tab_len += vc_saved; |
| 4675 | } |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4676 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4677 | #ifdef FEAT_MBYTE |
| 4678 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4679 | #endif |
| 4680 | if (wp->w_p_list) |
| 4681 | { |
| 4682 | c = lcs_tab1; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4683 | #ifdef FEAT_LINEBREAK |
| 4684 | if (wp->w_p_lbr) |
| 4685 | c_extra = NUL; /* using p_extra from above */ |
| 4686 | else |
| 4687 | #endif |
| 4688 | c_extra = lcs_tab2; |
| 4689 | n_attr = tab_len + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4690 | extra_attr = hl_attr(HLF_8); |
| 4691 | saved_attr2 = char_attr; /* save current attr */ |
| 4692 | #ifdef FEAT_MBYTE |
| 4693 | mb_c = c; |
| 4694 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4695 | { |
| 4696 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4697 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4698 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4699 | } |
| 4700 | #endif |
| 4701 | } |
| 4702 | else |
| 4703 | { |
| 4704 | c_extra = ' '; |
| 4705 | c = ' '; |
| 4706 | } |
| 4707 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4708 | else if (c == NUL |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4709 | && (wp->w_p_list |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4710 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4711 | && tocol > vcol |
| 4712 | && VIsual_mode != Ctrl_V |
| 4713 | && ( |
| 4714 | # ifdef FEAT_RIGHTLEFT |
| 4715 | wp->w_p_rl ? (col >= 0) : |
| 4716 | # endif |
| 4717 | (col < W_WIDTH(wp))) |
| 4718 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4719 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4720 | && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 0481fee | 2015-05-14 05:56:09 +0200 | [diff] [blame] | 4721 | && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4722 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4723 | /* Display a '$' after the line or highlight an extra |
| 4724 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4725 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4726 | /* For a diff line the highlighting continues after the |
| 4727 | * "$". */ |
| 4728 | if ( |
| 4729 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4730 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4731 | # ifdef LINE_ATTR |
| 4732 | && |
| 4733 | # endif |
| 4734 | # endif |
| 4735 | # ifdef LINE_ATTR |
| 4736 | line_attr == 0 |
| 4737 | # endif |
| 4738 | ) |
| 4739 | #endif |
| 4740 | { |
| 4741 | #ifdef FEAT_VIRTUALEDIT |
| 4742 | /* In virtualedit, visual selections may extend |
| 4743 | * beyond end of line. */ |
| 4744 | if (area_highlighting && virtual_active() |
| 4745 | && tocol != MAXCOL && vcol < tocol) |
| 4746 | n_extra = 0; |
| 4747 | else |
| 4748 | #endif |
| 4749 | { |
| 4750 | p_extra = at_end_str; |
| 4751 | n_extra = 1; |
| 4752 | c_extra = NUL; |
| 4753 | } |
| 4754 | } |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4755 | if (wp->w_p_list && lcs_eol > 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4756 | c = lcs_eol; |
| 4757 | else |
| 4758 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4759 | lcs_eol_one = -1; |
| 4760 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4761 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4762 | { |
| 4763 | extra_attr = hl_attr(HLF_AT); |
| 4764 | n_attr = 1; |
| 4765 | } |
| 4766 | #ifdef FEAT_MBYTE |
| 4767 | mb_c = c; |
| 4768 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4769 | { |
| 4770 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4771 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4772 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4773 | } |
| 4774 | else |
| 4775 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4776 | #endif |
| 4777 | } |
| 4778 | else if (c != NUL) |
| 4779 | { |
| 4780 | p_extra = transchar(c); |
Bram Moolenaar | 5524aeb | 2014-07-16 17:29:51 +0200 | [diff] [blame] | 4781 | if (n_extra == 0) |
| 4782 | n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4783 | #ifdef FEAT_RIGHTLEFT |
| 4784 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4785 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4786 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4787 | c_extra = NUL; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4788 | #ifdef FEAT_LINEBREAK |
| 4789 | if (wp->w_p_lbr) |
| 4790 | { |
| 4791 | char_u *p; |
| 4792 | |
| 4793 | c = *p_extra; |
| 4794 | p = alloc((unsigned)n_extra + 1); |
| 4795 | vim_memset(p, ' ', n_extra); |
| 4796 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 4797 | p[n_extra] = NUL; |
| 4798 | p_extra_free = p_extra = p; |
| 4799 | } |
| 4800 | else |
| 4801 | #endif |
| 4802 | { |
| 4803 | n_extra = byte2cells(c) - 1; |
| 4804 | c = *p_extra++; |
| 4805 | } |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4806 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4807 | { |
| 4808 | n_attr = n_extra + 1; |
| 4809 | extra_attr = hl_attr(HLF_8); |
| 4810 | saved_attr2 = char_attr; /* save current attr */ |
| 4811 | } |
| 4812 | #ifdef FEAT_MBYTE |
| 4813 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4814 | #endif |
| 4815 | } |
| 4816 | #ifdef FEAT_VIRTUALEDIT |
| 4817 | else if (VIsual_active |
| 4818 | && (VIsual_mode == Ctrl_V |
| 4819 | || VIsual_mode == 'v') |
| 4820 | && virtual_active() |
| 4821 | && tocol != MAXCOL |
| 4822 | && vcol < tocol |
| 4823 | && ( |
| 4824 | # ifdef FEAT_RIGHTLEFT |
| 4825 | wp->w_p_rl ? (col >= 0) : |
| 4826 | # endif |
| 4827 | (col < W_WIDTH(wp)))) |
| 4828 | { |
| 4829 | c = ' '; |
| 4830 | --ptr; /* put it back at the NUL */ |
| 4831 | } |
| 4832 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4833 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4834 | else if (( |
| 4835 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4836 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4837 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4838 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4839 | ) && ( |
| 4840 | # ifdef FEAT_RIGHTLEFT |
| 4841 | wp->w_p_rl ? (col >= 0) : |
| 4842 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4843 | (col |
| 4844 | # ifdef FEAT_CONCEAL |
| 4845 | - boguscols |
| 4846 | # endif |
| 4847 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4848 | { |
| 4849 | /* Highlight until the right side of the window */ |
| 4850 | c = ' '; |
| 4851 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4852 | |
| 4853 | /* Remember we do the char for line highlighting. */ |
| 4854 | ++did_line_attr; |
| 4855 | |
| 4856 | /* don't do search HL for the rest of the line */ |
| 4857 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4858 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4859 | # ifdef FEAT_DIFF |
| 4860 | if (diff_hlf == HLF_TXD) |
| 4861 | { |
| 4862 | diff_hlf = HLF_CHD; |
| 4863 | if (attr == 0 || char_attr != attr) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4864 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4865 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4866 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4867 | char_attr = hl_combine_attr(char_attr, |
| 4868 | hl_attr(HLF_CUL)); |
| 4869 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4870 | } |
| 4871 | # endif |
| 4872 | } |
| 4873 | #endif |
| 4874 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4875 | |
| 4876 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4877 | if ( wp->w_p_cole > 0 |
| 4878 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4879 | conceal_cursor_line(wp) ) |
| 4880 | && ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc) |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4881 | && !(lnum_in_visual_area |
| 4882 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4883 | { |
| 4884 | char_attr = conceal_attr; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4885 | if (prev_syntax_id != syntax_seqnr |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4886 | && (syn_get_sub_char() != NUL || match_conc |
| 4887 | || wp->w_p_cole == 1) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4888 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4889 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4890 | /* First time at this concealed item: display one |
| 4891 | * character. */ |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4892 | if (match_conc) |
| 4893 | c = match_conc; |
| 4894 | else if (syn_get_sub_char() != NUL) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4895 | c = syn_get_sub_char(); |
| 4896 | else if (lcs_conceal != NUL) |
| 4897 | c = lcs_conceal; |
| 4898 | else |
| 4899 | c = ' '; |
| 4900 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4901 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4902 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4903 | if (n_extra > 0) |
| 4904 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4905 | vcol += n_extra; |
| 4906 | if (wp->w_p_wrap && n_extra > 0) |
| 4907 | { |
| 4908 | # ifdef FEAT_RIGHTLEFT |
| 4909 | if (wp->w_p_rl) |
| 4910 | { |
| 4911 | col -= n_extra; |
| 4912 | boguscols -= n_extra; |
| 4913 | } |
| 4914 | else |
| 4915 | # endif |
| 4916 | { |
| 4917 | boguscols += n_extra; |
| 4918 | col += n_extra; |
| 4919 | } |
| 4920 | } |
| 4921 | n_extra = 0; |
| 4922 | n_attr = 0; |
| 4923 | } |
| 4924 | else if (n_skip == 0) |
| 4925 | { |
| 4926 | is_concealing = TRUE; |
| 4927 | n_skip = 1; |
| 4928 | } |
| 4929 | # ifdef FEAT_MBYTE |
| 4930 | mb_c = c; |
| 4931 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4932 | { |
| 4933 | mb_utf8 = TRUE; |
| 4934 | u8cc[0] = 0; |
| 4935 | c = 0xc0; |
| 4936 | } |
| 4937 | else |
| 4938 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4939 | # endif |
| 4940 | } |
| 4941 | else |
| 4942 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4943 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4944 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4945 | } |
| 4946 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4947 | } |
| 4948 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4949 | #ifdef FEAT_CONCEAL |
| 4950 | /* In the cursor line and we may be concealing characters: correct |
| 4951 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 4952 | if (!did_wcol && draw_state == WL_LINE |
| 4953 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4954 | && conceal_cursor_line(wp) |
| 4955 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 4956 | { |
Bram Moolenaar | e39b3d9 | 2016-01-15 22:52:22 +0100 | [diff] [blame] | 4957 | # ifdef FEAT_RIGHTLEFT |
| 4958 | if (wp->w_p_rl) |
| 4959 | wp->w_wcol = W_WIDTH(wp) - col + boguscols - 1; |
| 4960 | else |
| 4961 | # endif |
| 4962 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 4963 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4964 | did_wcol = TRUE; |
| 4965 | } |
| 4966 | #endif |
| 4967 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4968 | /* Don't override visual selection highlighting. */ |
| 4969 | if (n_attr > 0 |
| 4970 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4971 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4972 | char_attr = extra_attr; |
| 4973 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4974 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4975 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4976 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4977 | * im_is_preediting() here. */ |
| 4978 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4979 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4980 | && (State & INSERT) |
| 4981 | && !p_imdisable |
| 4982 | && im_is_preediting() |
| 4983 | && draw_state == WL_LINE) |
| 4984 | { |
| 4985 | colnr_T tcol; |
| 4986 | |
| 4987 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4988 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4989 | else |
| 4990 | tcol = preedit_end_col; |
| 4991 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4992 | { |
| 4993 | if (feedback_old_attr < 0) |
| 4994 | { |
| 4995 | feedback_col = 0; |
| 4996 | feedback_old_attr = char_attr; |
| 4997 | } |
| 4998 | char_attr = im_get_feedback_attr(feedback_col); |
| 4999 | if (char_attr < 0) |
| 5000 | char_attr = feedback_old_attr; |
| 5001 | feedback_col++; |
| 5002 | } |
| 5003 | else if (feedback_old_attr >= 0) |
| 5004 | { |
| 5005 | char_attr = feedback_old_attr; |
| 5006 | feedback_old_attr = -1; |
| 5007 | feedback_col = 0; |
| 5008 | } |
| 5009 | } |
| 5010 | #endif |
| 5011 | /* |
| 5012 | * Handle the case where we are in column 0 but not on the first |
| 5013 | * character of the line and the user wants us to show us a |
| 5014 | * special character (via 'listchars' option "precedes:<char>". |
| 5015 | */ |
| 5016 | if (lcs_prec_todo != NUL |
Bram Moolenaar | 7425b93 | 2014-10-10 15:28:46 +0200 | [diff] [blame] | 5017 | && wp->w_p_list |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5018 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 5019 | #ifdef FEAT_DIFF |
| 5020 | && filler_todo <= 0 |
| 5021 | #endif |
| 5022 | && draw_state > WL_NR |
| 5023 | && c != NUL) |
| 5024 | { |
| 5025 | c = lcs_prec; |
| 5026 | lcs_prec_todo = NUL; |
| 5027 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 5028 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5029 | { |
| 5030 | /* Double-width character being overwritten by the "precedes" |
| 5031 | * character, need to fill up half the character. */ |
| 5032 | c_extra = MB_FILLER_CHAR; |
| 5033 | n_extra = 1; |
| 5034 | n_attr = 2; |
| 5035 | extra_attr = hl_attr(HLF_AT); |
| 5036 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5037 | mb_c = c; |
| 5038 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5039 | { |
| 5040 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5041 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5042 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5043 | } |
| 5044 | else |
| 5045 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5046 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5047 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5048 | { |
| 5049 | saved_attr3 = char_attr; /* save current attr */ |
| 5050 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 5051 | n_attr3 = 1; |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5056 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5057 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5058 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5059 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5060 | || did_line_attr == 1 |
| 5061 | #endif |
| 5062 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5063 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5064 | #ifdef FEAT_SEARCH_EXTRA |
| 5065 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5066 | |
| 5067 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 5068 | 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] | 5069 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5070 | #endif |
| 5071 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5072 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5073 | * highlight match at end of line. If it's beyond the last |
| 5074 | * char on the screen, just overwrite that one (tricky!) Not |
| 5075 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5076 | #ifdef FEAT_SEARCH_EXTRA |
| 5077 | prevcol_hl_flag = FALSE; |
| 5078 | if (prevcol == (long)search_hl.startcol) |
| 5079 | prevcol_hl_flag = TRUE; |
| 5080 | else |
| 5081 | { |
| 5082 | cur = wp->w_match_head; |
| 5083 | while (cur != NULL) |
| 5084 | { |
| 5085 | if (prevcol == (long)cur->hl.startcol) |
| 5086 | { |
| 5087 | prevcol_hl_flag = TRUE; |
| 5088 | break; |
| 5089 | } |
| 5090 | cur = cur->next; |
| 5091 | } |
| 5092 | } |
| 5093 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5094 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5095 | && ((area_attr != 0 && vcol == fromcol |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5096 | && (VIsual_mode != Ctrl_V |
| 5097 | || lnum == VIsual.lnum |
| 5098 | || lnum == curwin->w_cursor.lnum) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5099 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5100 | #ifdef FEAT_SEARCH_EXTRA |
| 5101 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5102 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5103 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5104 | && did_line_attr <= 1 |
| 5105 | # endif |
| 5106 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5107 | #endif |
| 5108 | )) |
| 5109 | { |
| 5110 | int n = 0; |
| 5111 | |
| 5112 | #ifdef FEAT_RIGHTLEFT |
| 5113 | if (wp->w_p_rl) |
| 5114 | { |
| 5115 | if (col < 0) |
| 5116 | n = 1; |
| 5117 | } |
| 5118 | else |
| 5119 | #endif |
| 5120 | { |
| 5121 | if (col >= W_WIDTH(wp)) |
| 5122 | n = -1; |
| 5123 | } |
| 5124 | if (n != 0) |
| 5125 | { |
| 5126 | /* At the window boundary, highlight the last character |
| 5127 | * instead (better than nothing). */ |
| 5128 | off += n; |
| 5129 | col += n; |
| 5130 | } |
| 5131 | else |
| 5132 | { |
| 5133 | /* Add a blank character to highlight. */ |
| 5134 | ScreenLines[off] = ' '; |
| 5135 | #ifdef FEAT_MBYTE |
| 5136 | if (enc_utf8) |
| 5137 | ScreenLinesUC[off] = 0; |
| 5138 | #endif |
| 5139 | } |
| 5140 | #ifdef FEAT_SEARCH_EXTRA |
| 5141 | if (area_attr == 0) |
| 5142 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5143 | /* Use attributes from match with highest priority among |
| 5144 | * 'search_hl' and the match list. */ |
| 5145 | char_attr = search_hl.attr; |
| 5146 | cur = wp->w_match_head; |
| 5147 | shl_flag = FALSE; |
| 5148 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5149 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5150 | if (shl_flag == FALSE |
| 5151 | && ((cur != NULL |
| 5152 | && cur->priority > SEARCH_HL_PRIORITY) |
| 5153 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5154 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5155 | shl = &search_hl; |
| 5156 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5157 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5158 | else |
| 5159 | shl = &cur->hl; |
| 5160 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 5161 | char_attr = shl->attr; |
| 5162 | if (shl != &search_hl && cur != NULL) |
| 5163 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5164 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5165 | } |
| 5166 | #endif |
| 5167 | ScreenAttrs[off] = char_attr; |
| 5168 | #ifdef FEAT_RIGHTLEFT |
| 5169 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5170 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5171 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5172 | --off; |
| 5173 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5174 | else |
| 5175 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5176 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5177 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5178 | ++off; |
| 5179 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5180 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5181 | #ifdef FEAT_SYN_HL |
| 5182 | eol_hl_off = 1; |
| 5183 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5184 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5185 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5186 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5187 | /* |
| 5188 | * At end of the text line. |
| 5189 | */ |
| 5190 | if (c == NUL) |
| 5191 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5192 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5193 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 5194 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5195 | { |
| 5196 | /* highlight last char after line */ |
| 5197 | --col; |
| 5198 | --off; |
| 5199 | --vcol; |
| 5200 | } |
| 5201 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5202 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 5203 | if (wp->w_p_wrap) |
| 5204 | v = wp->w_skipcol; |
| 5205 | else |
| 5206 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5207 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5208 | /* check if line ends before left margin */ |
| 5209 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5210 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5211 | #ifdef FEAT_CONCEAL |
| 5212 | /* Get rid of the boguscols now, we want to draw until the right |
| 5213 | * edge for 'cursorcolumn'. */ |
| 5214 | col -= boguscols; |
| 5215 | boguscols = 0; |
| 5216 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5217 | |
| 5218 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5219 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5220 | |
| 5221 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5222 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 5223 | && (int)wp->w_virtcol < |
| 5224 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5225 | && lnum != wp->w_cursor.lnum) |
| 5226 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5227 | # ifdef FEAT_RIGHTLEFT |
| 5228 | && !wp->w_p_rl |
| 5229 | # endif |
| 5230 | ) |
| 5231 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5232 | int rightmost_vcol = 0; |
| 5233 | int i; |
| 5234 | |
| 5235 | if (wp->w_p_cuc) |
| 5236 | rightmost_vcol = wp->w_virtcol; |
| 5237 | if (draw_color_col) |
| 5238 | /* determine rightmost colorcolumn to possibly draw */ |
| 5239 | for (i = 0; color_cols[i] >= 0; ++i) |
| 5240 | if (rightmost_vcol < color_cols[i]) |
| 5241 | rightmost_vcol = color_cols[i]; |
| 5242 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5243 | while (col < W_WIDTH(wp)) |
| 5244 | { |
| 5245 | ScreenLines[off] = ' '; |
| 5246 | #ifdef FEAT_MBYTE |
| 5247 | if (enc_utf8) |
| 5248 | ScreenLinesUC[off] = 0; |
| 5249 | #endif |
| 5250 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 5251 | if (draw_color_col) |
| 5252 | draw_color_col = advance_color_col(VCOL_HLC, |
| 5253 | &color_cols); |
| 5254 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5255 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5256 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5257 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5258 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 5259 | else |
| 5260 | ScreenAttrs[off++] = 0; |
| 5261 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5262 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5263 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5264 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5265 | ++vcol; |
| 5266 | } |
| 5267 | } |
| 5268 | #endif |
| 5269 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5270 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5271 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5272 | row++; |
| 5273 | |
| 5274 | /* |
| 5275 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 5276 | * updated (saves a call to plines() later). |
| 5277 | */ |
| 5278 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 5279 | { |
| 5280 | curwin->w_cline_row = startrow; |
| 5281 | curwin->w_cline_height = row - startrow; |
| 5282 | #ifdef FEAT_FOLDING |
| 5283 | curwin->w_cline_folded = FALSE; |
| 5284 | #endif |
| 5285 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 5286 | } |
| 5287 | |
| 5288 | break; |
| 5289 | } |
| 5290 | |
| 5291 | /* line continues beyond line end */ |
| 5292 | if (lcs_ext |
| 5293 | && !wp->w_p_wrap |
| 5294 | #ifdef FEAT_DIFF |
| 5295 | && filler_todo <= 0 |
| 5296 | #endif |
| 5297 | && ( |
| 5298 | #ifdef FEAT_RIGHTLEFT |
| 5299 | wp->w_p_rl ? col == 0 : |
| 5300 | #endif |
| 5301 | col == W_WIDTH(wp) - 1) |
| 5302 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 5303 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5304 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 5305 | { |
| 5306 | c = lcs_ext; |
| 5307 | char_attr = hl_attr(HLF_AT); |
| 5308 | #ifdef FEAT_MBYTE |
| 5309 | mb_c = c; |
| 5310 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5311 | { |
| 5312 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5313 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5314 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5315 | } |
| 5316 | else |
| 5317 | mb_utf8 = FALSE; |
| 5318 | #endif |
| 5319 | } |
| 5320 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5321 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5322 | /* advance to the next 'colorcolumn' */ |
| 5323 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5324 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5325 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5326 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5327 | * highlight the cursor position itself. |
| 5328 | * Also highlight the 'colorcolumn' if it is different than |
| 5329 | * 'cursorcolumn' */ |
| 5330 | vcol_save_attr = -1; |
| 5331 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5332 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5333 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5334 | && lnum != wp->w_cursor.lnum) |
| 5335 | { |
| 5336 | vcol_save_attr = char_attr; |
| 5337 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 5338 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 5339 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5340 | { |
| 5341 | vcol_save_attr = char_attr; |
| 5342 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 5343 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5344 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5345 | #endif |
| 5346 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5347 | /* |
| 5348 | * Store character to be displayed. |
| 5349 | * Skip characters that are left of the screen for 'nowrap'. |
| 5350 | */ |
| 5351 | vcol_prev = vcol; |
| 5352 | if (draw_state < WL_LINE || n_skip <= 0) |
| 5353 | { |
| 5354 | /* |
| 5355 | * Store the character. |
| 5356 | */ |
| 5357 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 5358 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 5359 | { |
| 5360 | /* A double-wide character is: put first halve in left cell. */ |
| 5361 | --off; |
| 5362 | --col; |
| 5363 | } |
| 5364 | #endif |
| 5365 | ScreenLines[off] = c; |
| 5366 | #ifdef FEAT_MBYTE |
| 5367 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5368 | { |
| 5369 | if ((mb_c & 0xff00) == 0x8e00) |
| 5370 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5371 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5372 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5373 | else if (enc_utf8) |
| 5374 | { |
| 5375 | if (mb_utf8) |
| 5376 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5377 | int i; |
| 5378 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5379 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5380 | if ((c & 0xff) == 0) |
| 5381 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5382 | for (i = 0; i < Screen_mco; ++i) |
| 5383 | { |
| 5384 | ScreenLinesC[i][off] = u8cc[i]; |
| 5385 | if (u8cc[i] == 0) |
| 5386 | break; |
| 5387 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5388 | } |
| 5389 | else |
| 5390 | ScreenLinesUC[off] = 0; |
| 5391 | } |
| 5392 | if (multi_attr) |
| 5393 | { |
| 5394 | ScreenAttrs[off] = multi_attr; |
| 5395 | multi_attr = 0; |
| 5396 | } |
| 5397 | else |
| 5398 | #endif |
| 5399 | ScreenAttrs[off] = char_attr; |
| 5400 | |
| 5401 | #ifdef FEAT_MBYTE |
| 5402 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5403 | { |
| 5404 | /* Need to fill two screen columns. */ |
| 5405 | ++off; |
| 5406 | ++col; |
| 5407 | if (enc_utf8) |
| 5408 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5409 | ScreenLines[off] = 0; |
| 5410 | else |
| 5411 | /* DBCS: Put second byte in the second screen char. */ |
| 5412 | ScreenLines[off] = mb_c & 0xff; |
Bram Moolenaar | 32a214e | 2015-12-03 14:29:02 +0100 | [diff] [blame] | 5413 | if (draw_state > WL_NR |
| 5414 | #ifdef FEAT_DIFF |
| 5415 | && filler_todo <= 0 |
| 5416 | #endif |
| 5417 | ) |
| 5418 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5419 | /* When "tocol" is halfway a character, set it to the end of |
| 5420 | * the character, otherwise highlighting won't stop. */ |
| 5421 | if (tocol == vcol) |
| 5422 | ++tocol; |
| 5423 | #ifdef FEAT_RIGHTLEFT |
| 5424 | if (wp->w_p_rl) |
| 5425 | { |
| 5426 | /* now it's time to backup one cell */ |
| 5427 | --off; |
| 5428 | --col; |
| 5429 | } |
| 5430 | #endif |
| 5431 | } |
| 5432 | #endif |
| 5433 | #ifdef FEAT_RIGHTLEFT |
| 5434 | if (wp->w_p_rl) |
| 5435 | { |
| 5436 | --off; |
| 5437 | --col; |
| 5438 | } |
| 5439 | else |
| 5440 | #endif |
| 5441 | { |
| 5442 | ++off; |
| 5443 | ++col; |
| 5444 | } |
| 5445 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5446 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5447 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5448 | { |
| 5449 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5450 | ++vcol_off; |
| 5451 | if (n_extra > 0) |
| 5452 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5453 | if (wp->w_p_wrap) |
| 5454 | { |
| 5455 | /* |
| 5456 | * Special voodoo required if 'wrap' is on. |
| 5457 | * |
| 5458 | * Advance the column indicator to force the line |
| 5459 | * drawing to wrap early. This will make the line |
| 5460 | * take up the same screen space when parts are concealed, |
| 5461 | * so that cursor line computations aren't messed up. |
| 5462 | * |
| 5463 | * To avoid the fictitious advance of 'col' causing |
| 5464 | * trailing junk to be written out of the screen line |
| 5465 | * we are building, 'boguscols' keeps track of the number |
| 5466 | * of bad columns we have advanced. |
| 5467 | */ |
| 5468 | if (n_extra > 0) |
| 5469 | { |
| 5470 | vcol += n_extra; |
| 5471 | # ifdef FEAT_RIGHTLEFT |
| 5472 | if (wp->w_p_rl) |
| 5473 | { |
| 5474 | col -= n_extra; |
| 5475 | boguscols -= n_extra; |
| 5476 | } |
| 5477 | else |
| 5478 | # endif |
| 5479 | { |
| 5480 | col += n_extra; |
| 5481 | boguscols += n_extra; |
| 5482 | } |
| 5483 | n_extra = 0; |
| 5484 | n_attr = 0; |
| 5485 | } |
| 5486 | |
| 5487 | |
| 5488 | # ifdef FEAT_MBYTE |
| 5489 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5490 | { |
| 5491 | /* Need to fill two screen columns. */ |
| 5492 | # ifdef FEAT_RIGHTLEFT |
| 5493 | if (wp->w_p_rl) |
| 5494 | { |
| 5495 | --boguscols; |
| 5496 | --col; |
| 5497 | } |
| 5498 | else |
| 5499 | # endif |
| 5500 | { |
| 5501 | ++boguscols; |
| 5502 | ++col; |
| 5503 | } |
| 5504 | } |
| 5505 | # endif |
| 5506 | |
| 5507 | # ifdef FEAT_RIGHTLEFT |
| 5508 | if (wp->w_p_rl) |
| 5509 | { |
| 5510 | --boguscols; |
| 5511 | --col; |
| 5512 | } |
| 5513 | else |
| 5514 | # endif |
| 5515 | { |
| 5516 | ++boguscols; |
| 5517 | ++col; |
| 5518 | } |
| 5519 | } |
| 5520 | else |
| 5521 | { |
| 5522 | if (n_extra > 0) |
| 5523 | { |
| 5524 | vcol += n_extra; |
| 5525 | n_extra = 0; |
| 5526 | n_attr = 0; |
| 5527 | } |
| 5528 | } |
| 5529 | |
| 5530 | } |
| 5531 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5532 | else |
| 5533 | --n_skip; |
| 5534 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5535 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5536 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5537 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5538 | #ifdef FEAT_DIFF |
| 5539 | && filler_todo <= 0 |
| 5540 | #endif |
| 5541 | ) |
| 5542 | ++vcol; |
| 5543 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5544 | #ifdef FEAT_SYN_HL |
| 5545 | if (vcol_save_attr >= 0) |
| 5546 | char_attr = vcol_save_attr; |
| 5547 | #endif |
| 5548 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5549 | /* restore attributes after "predeces" in 'listchars' */ |
| 5550 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5551 | char_attr = saved_attr3; |
| 5552 | |
| 5553 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5554 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5555 | char_attr = saved_attr2; |
| 5556 | |
| 5557 | /* |
| 5558 | * 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] | 5559 | * 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] | 5560 | */ |
| 5561 | if (( |
| 5562 | #ifdef FEAT_RIGHTLEFT |
| 5563 | wp->w_p_rl ? (col < 0) : |
| 5564 | #endif |
| 5565 | (col >= W_WIDTH(wp))) |
| 5566 | && (*ptr != NUL |
| 5567 | #ifdef FEAT_DIFF |
| 5568 | || filler_todo > 0 |
| 5569 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5570 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5571 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5572 | ) |
| 5573 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5574 | #ifdef FEAT_CONCEAL |
| 5575 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5576 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5577 | boguscols = 0; |
| 5578 | #else |
| 5579 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5580 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5581 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5582 | ++row; |
| 5583 | ++screen_row; |
| 5584 | |
| 5585 | /* When not wrapping and finished diff lines, or when displayed |
| 5586 | * '$' and highlighting until last column, break here. */ |
| 5587 | if ((!wp->w_p_wrap |
| 5588 | #ifdef FEAT_DIFF |
| 5589 | && filler_todo <= 0 |
| 5590 | #endif |
| 5591 | ) || lcs_eol_one == -1) |
| 5592 | break; |
| 5593 | |
| 5594 | /* When the window is too narrow draw all "@" lines. */ |
| 5595 | if (draw_state != WL_LINE |
| 5596 | #ifdef FEAT_DIFF |
| 5597 | && filler_todo <= 0 |
| 5598 | #endif |
| 5599 | ) |
| 5600 | { |
| 5601 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 5602 | #ifdef FEAT_VERTSPLIT |
| 5603 | draw_vsep_win(wp, row); |
| 5604 | #endif |
| 5605 | row = endrow; |
| 5606 | } |
| 5607 | |
| 5608 | /* When line got too long for screen break here. */ |
| 5609 | if (row == endrow) |
| 5610 | { |
| 5611 | ++row; |
| 5612 | break; |
| 5613 | } |
| 5614 | |
| 5615 | if (screen_cur_row == screen_row - 1 |
| 5616 | #ifdef FEAT_DIFF |
| 5617 | && filler_todo <= 0 |
| 5618 | #endif |
| 5619 | && W_WIDTH(wp) == Columns) |
| 5620 | { |
| 5621 | /* Remember that the line wraps, used for modeless copy. */ |
| 5622 | LineWraps[screen_row - 1] = TRUE; |
| 5623 | |
| 5624 | /* |
| 5625 | * Special trick to make copy/paste of wrapped lines work with |
| 5626 | * xterm/screen: write an extra character beyond the end of |
| 5627 | * the line. This will work with all terminal types |
| 5628 | * (regardless of the xn,am settings). |
| 5629 | * Only do this on a fast tty. |
| 5630 | * Only do this if the cursor is on the current line |
| 5631 | * (something has been written in it). |
| 5632 | * Don't do this for the GUI. |
| 5633 | * Don't do this for double-width characters. |
| 5634 | * Don't do this for a window not at the right screen border. |
| 5635 | */ |
| 5636 | if (p_tf |
| 5637 | #ifdef FEAT_GUI |
| 5638 | && !gui.in_use |
| 5639 | #endif |
| 5640 | #ifdef FEAT_MBYTE |
| 5641 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5642 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5643 | LineOffset[screen_row] + screen_Columns) |
| 5644 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5645 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5646 | + (int)Columns - 2, |
| 5647 | LineOffset[screen_row] + screen_Columns) |
| 5648 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5649 | #endif |
| 5650 | ) |
| 5651 | { |
| 5652 | /* First make sure we are at the end of the screen line, |
| 5653 | * then output the same character again to let the |
| 5654 | * terminal know about the wrap. If the terminal doesn't |
| 5655 | * auto-wrap, we overwrite the character. */ |
| 5656 | if (screen_cur_col != W_WIDTH(wp)) |
| 5657 | screen_char(LineOffset[screen_row - 1] |
| 5658 | + (unsigned)Columns - 1, |
| 5659 | screen_row - 1, (int)(Columns - 1)); |
| 5660 | |
| 5661 | #ifdef FEAT_MBYTE |
| 5662 | /* When there is a multi-byte character, just output a |
| 5663 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5664 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5665 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5666 | out_char(' '); |
| 5667 | else |
| 5668 | #endif |
| 5669 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5670 | + (Columns - 1)]); |
| 5671 | /* force a redraw of the first char on the next line */ |
| 5672 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5673 | screen_start(); /* don't know where cursor is now */ |
| 5674 | } |
| 5675 | } |
| 5676 | |
| 5677 | col = 0; |
| 5678 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5679 | #ifdef FEAT_RIGHTLEFT |
| 5680 | if (wp->w_p_rl) |
| 5681 | { |
| 5682 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5683 | off += col; |
| 5684 | } |
| 5685 | #endif |
| 5686 | |
| 5687 | /* reset the drawing state for the start of a wrapped line */ |
| 5688 | draw_state = WL_START; |
| 5689 | saved_n_extra = n_extra; |
| 5690 | saved_p_extra = p_extra; |
| 5691 | saved_c_extra = c_extra; |
| 5692 | saved_char_attr = char_attr; |
| 5693 | n_extra = 0; |
| 5694 | lcs_prec_todo = lcs_prec; |
| 5695 | #ifdef FEAT_LINEBREAK |
| 5696 | # ifdef FEAT_DIFF |
| 5697 | if (filler_todo <= 0) |
| 5698 | # endif |
| 5699 | need_showbreak = TRUE; |
| 5700 | #endif |
| 5701 | #ifdef FEAT_DIFF |
| 5702 | --filler_todo; |
| 5703 | /* When the filler lines are actually below the last line of the |
| 5704 | * file, don't draw the line itself, break here. */ |
| 5705 | if (filler_todo == 0 && wp->w_botfill) |
| 5706 | break; |
| 5707 | #endif |
| 5708 | } |
| 5709 | |
| 5710 | } /* for every character in the line */ |
| 5711 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5712 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5713 | /* After an empty line check first word for capital. */ |
| 5714 | if (*skipwhite(line) == NUL) |
| 5715 | { |
| 5716 | capcol_lnum = lnum + 1; |
| 5717 | cap_col = 0; |
| 5718 | } |
| 5719 | #endif |
| 5720 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5721 | return row; |
| 5722 | } |
| 5723 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5724 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 5725 | static int comp_char_differs(int, int); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5726 | |
| 5727 | /* |
| 5728 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5729 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5730 | */ |
| 5731 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5732 | comp_char_differs(int off_from, int off_to) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5733 | { |
| 5734 | int i; |
| 5735 | |
| 5736 | for (i = 0; i < Screen_mco; ++i) |
| 5737 | { |
| 5738 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5739 | return TRUE; |
| 5740 | if (ScreenLinesC[i][off_from] == 0) |
| 5741 | break; |
| 5742 | } |
| 5743 | return FALSE; |
| 5744 | } |
| 5745 | #endif |
| 5746 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5747 | /* |
| 5748 | * Check whether the given character needs redrawing: |
| 5749 | * - the (first byte of the) character is different |
| 5750 | * - the attributes are different |
| 5751 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5752 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5753 | */ |
| 5754 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5755 | char_needs_redraw(int off_from, int off_to, int cols) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5756 | { |
| 5757 | if (cols > 0 |
| 5758 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5759 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5760 | |
| 5761 | #ifdef FEAT_MBYTE |
| 5762 | || (enc_dbcs != 0 |
| 5763 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5764 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5765 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5766 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5767 | != ScreenLines[off_to + 1]))) |
| 5768 | || (enc_utf8 |
| 5769 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5770 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5771 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5772 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5773 | && ScreenLines[off_from + 1] |
| 5774 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5775 | #endif |
| 5776 | )) |
| 5777 | return TRUE; |
| 5778 | return FALSE; |
| 5779 | } |
| 5780 | |
| 5781 | /* |
| 5782 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5783 | * have actually changed. Handle insert/delete character. |
| 5784 | * "coloff" gives the first column on the screen for this line. |
| 5785 | * "endcol" gives the columns where valid characters are. |
| 5786 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5787 | * needs to be cleared, negative otherwise. |
| 5788 | * "rlflag" is TRUE in a rightleft window: |
| 5789 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5790 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5791 | */ |
| 5792 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5793 | screen_line( |
| 5794 | int row, |
| 5795 | int coloff, |
| 5796 | int endcol, |
| 5797 | int clear_width |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5798 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5799 | , int rlflag |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5800 | #endif |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5801 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5802 | { |
| 5803 | unsigned off_from; |
| 5804 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5805 | #ifdef FEAT_MBYTE |
| 5806 | unsigned max_off_from; |
| 5807 | unsigned max_off_to; |
| 5808 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5809 | int col = 0; |
| 5810 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 5811 | int hl; |
| 5812 | #endif |
| 5813 | int force = FALSE; /* force update rest of the line */ |
| 5814 | int redraw_this /* bool: does character need redraw? */ |
| 5815 | #ifdef FEAT_GUI |
| 5816 | = TRUE /* For GUI when while-loop empty */ |
| 5817 | #endif |
| 5818 | ; |
| 5819 | int redraw_next; /* redraw_this for next character */ |
| 5820 | #ifdef FEAT_MBYTE |
| 5821 | int clear_next = FALSE; |
| 5822 | int char_cells; /* 1: normal char */ |
| 5823 | /* 2: occupies two display cells */ |
| 5824 | # define CHAR_CELLS char_cells |
| 5825 | #else |
| 5826 | # define CHAR_CELLS 1 |
| 5827 | #endif |
| 5828 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5829 | /* Check for illegal row and col, just in case. */ |
| 5830 | if (row >= Rows) |
| 5831 | row = Rows - 1; |
| 5832 | if (endcol > Columns) |
| 5833 | endcol = Columns; |
| 5834 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5835 | # ifdef FEAT_CLIPBOARD |
| 5836 | clip_may_clear_selection(row, row); |
| 5837 | # endif |
| 5838 | |
| 5839 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5840 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5841 | #ifdef FEAT_MBYTE |
| 5842 | max_off_from = off_from + screen_Columns; |
| 5843 | max_off_to = LineOffset[row] + screen_Columns; |
| 5844 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5845 | |
| 5846 | #ifdef FEAT_RIGHTLEFT |
| 5847 | if (rlflag) |
| 5848 | { |
| 5849 | /* Clear rest first, because it's left of the text. */ |
| 5850 | if (clear_width > 0) |
| 5851 | { |
| 5852 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5853 | && ScreenAttrs[off_to] == 0 |
| 5854 | # ifdef FEAT_MBYTE |
| 5855 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5856 | # endif |
| 5857 | ) |
| 5858 | { |
| 5859 | ++off_to; |
| 5860 | ++col; |
| 5861 | } |
| 5862 | if (col <= endcol) |
| 5863 | screen_fill(row, row + 1, col + coloff, |
| 5864 | endcol + coloff + 1, ' ', ' ', 0); |
| 5865 | } |
| 5866 | col = endcol + 1; |
| 5867 | off_to = LineOffset[row] + col + coloff; |
| 5868 | off_from += col; |
| 5869 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5870 | } |
| 5871 | #endif /* FEAT_RIGHTLEFT */ |
| 5872 | |
| 5873 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5874 | |
| 5875 | while (col < endcol) |
| 5876 | { |
| 5877 | #ifdef FEAT_MBYTE |
| 5878 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5879 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5880 | else |
| 5881 | char_cells = 1; |
| 5882 | #endif |
| 5883 | |
| 5884 | redraw_this = redraw_next; |
| 5885 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5886 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5887 | |
| 5888 | #ifdef FEAT_GUI |
| 5889 | /* If the next character was bold, then redraw the current character to |
| 5890 | * remove any pixels that might have spilt over into us. This only |
| 5891 | * happens in the GUI. |
| 5892 | */ |
| 5893 | if (redraw_next && gui.in_use) |
| 5894 | { |
| 5895 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5896 | if (hl > HL_ALL) |
| 5897 | hl = syn_attr2attr(hl); |
| 5898 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5899 | redraw_this = TRUE; |
| 5900 | } |
| 5901 | #endif |
| 5902 | |
| 5903 | if (redraw_this) |
| 5904 | { |
| 5905 | /* |
| 5906 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5907 | * Attributes for characters are stored at the position where the |
| 5908 | * cursor is when writing the highlighting code. The |
| 5909 | * start-highlighting code must be written with the cursor on the |
| 5910 | * first highlighted character. The stop-highlighting code must |
| 5911 | * be written with the cursor just after the last highlighted |
| 5912 | * character. |
| 5913 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5914 | * to clear the rest of the line, and force redrawing it |
| 5915 | * completely. |
| 5916 | */ |
| 5917 | if ( p_wiv |
| 5918 | && !force |
| 5919 | #ifdef FEAT_GUI |
| 5920 | && !gui.in_use |
| 5921 | #endif |
| 5922 | && ScreenAttrs[off_to] != 0 |
| 5923 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5924 | { |
| 5925 | /* |
| 5926 | * Need to remove highlighting attributes here. |
| 5927 | */ |
| 5928 | windgoto(row, col + coloff); |
| 5929 | out_str(T_CE); /* clear rest of this screen line */ |
| 5930 | screen_start(); /* don't know where cursor is now */ |
| 5931 | force = TRUE; /* force redraw of rest of the line */ |
| 5932 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5933 | |
| 5934 | /* |
| 5935 | * If the previous character was highlighted, need to stop |
| 5936 | * highlighting at this character. |
| 5937 | */ |
| 5938 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5939 | { |
| 5940 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5941 | term_windgoto(row, col + coloff); |
| 5942 | screen_stop_highlight(); |
| 5943 | } |
| 5944 | else |
| 5945 | screen_attr = 0; /* highlighting has stopped */ |
| 5946 | } |
| 5947 | #ifdef FEAT_MBYTE |
| 5948 | if (enc_dbcs != 0) |
| 5949 | { |
| 5950 | /* Check if overwriting a double-byte with a single-byte or |
| 5951 | * the other way around requires another character to be |
| 5952 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5953 | * ScreenLinesUC[] is sufficient. */ |
| 5954 | if (char_cells == 1 |
| 5955 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5956 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5957 | { |
| 5958 | /* Writing a single-cell character over a double-cell |
| 5959 | * character: need to redraw the next cell. */ |
| 5960 | ScreenLines[off_to + 1] = 0; |
| 5961 | redraw_next = TRUE; |
| 5962 | } |
| 5963 | else if (char_cells == 2 |
| 5964 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5965 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5966 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5967 | { |
| 5968 | /* Writing the second half of a double-cell character over |
| 5969 | * a double-cell character: need to redraw the second |
| 5970 | * cell. */ |
| 5971 | ScreenLines[off_to + 2] = 0; |
| 5972 | redraw_next = TRUE; |
| 5973 | } |
| 5974 | |
| 5975 | if (enc_dbcs == DBCS_JPNU) |
| 5976 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 5977 | } |
| 5978 | /* When writing a single-width character over a double-width |
| 5979 | * character and at the end of the redrawn text, need to clear out |
| 5980 | * the right halve of the old character. |
| 5981 | * Also required when writing the right halve of a double-width |
| 5982 | * char over the left halve of an existing one. */ |
| 5983 | if (has_mbyte && col + char_cells == endcol |
| 5984 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5985 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5986 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5987 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5988 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5989 | clear_next = TRUE; |
| 5990 | #endif |
| 5991 | |
| 5992 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 5993 | #ifdef FEAT_MBYTE |
| 5994 | if (enc_utf8) |
| 5995 | { |
| 5996 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 5997 | if (ScreenLinesUC[off_from] != 0) |
| 5998 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5999 | int i; |
| 6000 | |
| 6001 | for (i = 0; i < Screen_mco; ++i) |
| 6002 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6003 | } |
| 6004 | } |
| 6005 | if (char_cells == 2) |
| 6006 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 6007 | #endif |
| 6008 | |
| 6009 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6010 | /* The bold trick makes a single column of pixels appear in the |
| 6011 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6012 | * character should be redrawn too. This happens for our own GUI |
| 6013 | * and for some xterms. */ |
| 6014 | if ( |
| 6015 | # ifdef FEAT_GUI |
| 6016 | gui.in_use |
| 6017 | # endif |
| 6018 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6019 | || |
| 6020 | # endif |
| 6021 | # ifdef UNIX |
| 6022 | term_is_xterm |
| 6023 | # endif |
| 6024 | ) |
| 6025 | { |
| 6026 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 6027 | if (hl > HL_ALL) |
| 6028 | hl = syn_attr2attr(hl); |
| 6029 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6030 | redraw_next = TRUE; |
| 6031 | } |
| 6032 | #endif |
| 6033 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 6034 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6035 | /* For simplicity set the attributes of second half of a |
| 6036 | * double-wide character equal to the first half. */ |
| 6037 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6038 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6039 | |
| 6040 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6041 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6042 | else |
| 6043 | #endif |
| 6044 | screen_char(off_to, row, col + coloff); |
| 6045 | } |
| 6046 | else if ( p_wiv |
| 6047 | #ifdef FEAT_GUI |
| 6048 | && !gui.in_use |
| 6049 | #endif |
| 6050 | && col + coloff > 0) |
| 6051 | { |
| 6052 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 6053 | { |
| 6054 | /* |
| 6055 | * Don't output stop-highlight when moving the cursor, it will |
| 6056 | * stop the highlighting when it should continue. |
| 6057 | */ |
| 6058 | screen_attr = 0; |
| 6059 | } |
| 6060 | else if (screen_attr != 0) |
| 6061 | screen_stop_highlight(); |
| 6062 | } |
| 6063 | |
| 6064 | off_to += CHAR_CELLS; |
| 6065 | off_from += CHAR_CELLS; |
| 6066 | col += CHAR_CELLS; |
| 6067 | } |
| 6068 | |
| 6069 | #ifdef FEAT_MBYTE |
| 6070 | if (clear_next) |
| 6071 | { |
| 6072 | /* Clear the second half of a double-wide character of which the left |
| 6073 | * half was overwritten with a single-wide character. */ |
| 6074 | ScreenLines[off_to] = ' '; |
| 6075 | if (enc_utf8) |
| 6076 | ScreenLinesUC[off_to] = 0; |
| 6077 | screen_char(off_to, row, col + coloff); |
| 6078 | } |
| 6079 | #endif |
| 6080 | |
| 6081 | if (clear_width > 0 |
| 6082 | #ifdef FEAT_RIGHTLEFT |
| 6083 | && !rlflag |
| 6084 | #endif |
| 6085 | ) |
| 6086 | { |
| 6087 | #ifdef FEAT_GUI |
| 6088 | int startCol = col; |
| 6089 | #endif |
| 6090 | |
| 6091 | /* blank out the rest of the line */ |
| 6092 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 6093 | && ScreenAttrs[off_to] == 0 |
| 6094 | #ifdef FEAT_MBYTE |
| 6095 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 6096 | #endif |
| 6097 | ) |
| 6098 | { |
| 6099 | ++off_to; |
| 6100 | ++col; |
| 6101 | } |
| 6102 | if (col < clear_width) |
| 6103 | { |
| 6104 | #ifdef FEAT_GUI |
| 6105 | /* |
| 6106 | * In the GUI, clearing the rest of the line may leave pixels |
| 6107 | * behind if the first character cleared was bold. Some bold |
| 6108 | * fonts spill over the left. In this case we redraw the previous |
| 6109 | * character too. If we didn't skip any blanks above, then we |
| 6110 | * only redraw if the character wasn't already redrawn anyway. |
| 6111 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6112 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6113 | { |
| 6114 | hl = ScreenAttrs[off_to]; |
| 6115 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6116 | { |
| 6117 | int prev_cells = 1; |
| 6118 | # ifdef FEAT_MBYTE |
| 6119 | if (enc_utf8) |
| 6120 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 6121 | * that its width is 2. */ |
| 6122 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 6123 | else if (enc_dbcs != 0) |
| 6124 | { |
| 6125 | /* find previous character by counting from first |
| 6126 | * column and get its width. */ |
| 6127 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6128 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6129 | |
| 6130 | while (off < off_to) |
| 6131 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6132 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6133 | off += prev_cells; |
| 6134 | } |
| 6135 | } |
| 6136 | |
| 6137 | if (enc_dbcs != 0 && prev_cells > 1) |
| 6138 | screen_char_2(off_to - prev_cells, row, |
| 6139 | col + coloff - prev_cells); |
| 6140 | else |
| 6141 | # endif |
| 6142 | screen_char(off_to - prev_cells, row, |
| 6143 | col + coloff - prev_cells); |
| 6144 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6145 | } |
| 6146 | #endif |
| 6147 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 6148 | ' ', ' ', 0); |
| 6149 | #ifdef FEAT_VERTSPLIT |
| 6150 | off_to += clear_width - col; |
| 6151 | col = clear_width; |
| 6152 | #endif |
| 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | if (clear_width > 0) |
| 6157 | { |
| 6158 | #ifdef FEAT_VERTSPLIT |
| 6159 | /* For a window that's left of another, draw the separator char. */ |
| 6160 | if (col + coloff < Columns) |
| 6161 | { |
| 6162 | int c; |
| 6163 | |
| 6164 | c = fillchar_vsep(&hl); |
Bram Moolenaar | c60c4f6 | 2015-01-07 19:04:28 +0100 | [diff] [blame] | 6165 | if (ScreenLines[off_to] != (schar_T)c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6166 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6167 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 6168 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6169 | # endif |
| 6170 | || ScreenAttrs[off_to] != hl) |
| 6171 | { |
| 6172 | ScreenLines[off_to] = c; |
| 6173 | ScreenAttrs[off_to] = hl; |
| 6174 | # ifdef FEAT_MBYTE |
| 6175 | if (enc_utf8) |
| 6176 | { |
| 6177 | if (c >= 0x80) |
| 6178 | { |
| 6179 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6180 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6181 | } |
| 6182 | else |
| 6183 | ScreenLinesUC[off_to] = 0; |
| 6184 | } |
| 6185 | # endif |
| 6186 | screen_char(off_to, row, col + coloff); |
| 6187 | } |
| 6188 | } |
| 6189 | else |
| 6190 | #endif |
| 6191 | LineWraps[row] = FALSE; |
| 6192 | } |
| 6193 | } |
| 6194 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6195 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6196 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6197 | * Mirror text "str" for right-left displaying. |
| 6198 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6199 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6200 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6201 | rl_mirror(char_u *str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6202 | { |
| 6203 | char_u *p1, *p2; |
| 6204 | int t; |
| 6205 | |
| 6206 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 6207 | { |
| 6208 | t = *p1; |
| 6209 | *p1 = *p2; |
| 6210 | *p2 = t; |
| 6211 | } |
| 6212 | } |
| 6213 | #endif |
| 6214 | |
| 6215 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6216 | /* |
| 6217 | * mark all status lines for redraw; used after first :cd |
| 6218 | */ |
| 6219 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6220 | status_redraw_all(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6221 | { |
| 6222 | win_T *wp; |
| 6223 | |
| 6224 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6225 | if (wp->w_status_height) |
| 6226 | { |
| 6227 | wp->w_redr_status = TRUE; |
| 6228 | redraw_later(VALID); |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | /* |
| 6233 | * mark all status lines of the current buffer for redraw |
| 6234 | */ |
| 6235 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6236 | status_redraw_curbuf(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6237 | { |
| 6238 | win_T *wp; |
| 6239 | |
| 6240 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6241 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 6242 | { |
| 6243 | wp->w_redr_status = TRUE; |
| 6244 | redraw_later(VALID); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | /* |
| 6249 | * Redraw all status lines that need to be redrawn. |
| 6250 | */ |
| 6251 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6252 | redraw_statuslines(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6253 | { |
| 6254 | win_T *wp; |
| 6255 | |
| 6256 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6257 | if (wp->w_redr_status) |
| 6258 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 6259 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6260 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6261 | } |
| 6262 | #endif |
| 6263 | |
| 6264 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 6265 | /* |
| 6266 | * Redraw all status lines at the bottom of frame "frp". |
| 6267 | */ |
| 6268 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6269 | win_redraw_last_status(frame_T *frp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6270 | { |
| 6271 | if (frp->fr_layout == FR_LEAF) |
| 6272 | frp->fr_win->w_redr_status = TRUE; |
| 6273 | else if (frp->fr_layout == FR_ROW) |
| 6274 | { |
| 6275 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 6276 | win_redraw_last_status(frp); |
| 6277 | } |
| 6278 | else /* frp->fr_layout == FR_COL */ |
| 6279 | { |
| 6280 | frp = frp->fr_child; |
| 6281 | while (frp->fr_next != NULL) |
| 6282 | frp = frp->fr_next; |
| 6283 | win_redraw_last_status(frp); |
| 6284 | } |
| 6285 | } |
| 6286 | #endif |
| 6287 | |
| 6288 | #ifdef FEAT_VERTSPLIT |
| 6289 | /* |
| 6290 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 6291 | */ |
| 6292 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6293 | draw_vsep_win(win_T *wp, int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6294 | { |
| 6295 | int hl; |
| 6296 | int c; |
| 6297 | |
| 6298 | if (wp->w_vsep_width) |
| 6299 | { |
| 6300 | /* draw the vertical separator right of this window */ |
| 6301 | c = fillchar_vsep(&hl); |
| 6302 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 6303 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 6304 | c, ' ', hl); |
| 6305 | } |
| 6306 | } |
| 6307 | #endif |
| 6308 | |
| 6309 | #ifdef FEAT_WILDMENU |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 6310 | static int status_match_len(expand_T *xp, char_u *s); |
| 6311 | static int skip_status_match_char(expand_T *xp, char_u *s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6312 | |
| 6313 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6314 | * 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] | 6315 | */ |
| 6316 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6317 | status_match_len(expand_T *xp, char_u *s) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6318 | { |
| 6319 | int len = 0; |
| 6320 | |
| 6321 | #ifdef FEAT_MENU |
| 6322 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 6323 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6324 | |
| 6325 | /* Check for menu separators - replace with '|'. */ |
| 6326 | if (emenu && menu_is_separator(s)) |
| 6327 | return 1; |
| 6328 | #endif |
| 6329 | |
| 6330 | while (*s != NUL) |
| 6331 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6332 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 6333 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6334 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | return len; |
| 6338 | } |
| 6339 | |
| 6340 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6341 | * 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] | 6342 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 6343 | */ |
| 6344 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6345 | skip_status_match_char(expand_T *xp, char_u *s) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6346 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6347 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6348 | #ifdef FEAT_MENU |
| 6349 | || ((xp->xp_context == EXPAND_MENUS |
| 6350 | || xp->xp_context == EXPAND_MENUNAMES) |
| 6351 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 6352 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6353 | ) |
| 6354 | { |
| 6355 | #ifndef BACKSLASH_IN_FILENAME |
| 6356 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 6357 | return 2; |
| 6358 | #endif |
| 6359 | return 1; |
| 6360 | } |
| 6361 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6365 | * Show wildchar matches in the status line. |
| 6366 | * Show at least the "match" item. |
| 6367 | * We start at item 'first_match' in the list and show all matches that fit. |
| 6368 | * |
| 6369 | * If inversion is possible we use it. Else '=' characters are used. |
| 6370 | */ |
| 6371 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6372 | win_redr_status_matches( |
| 6373 | expand_T *xp, |
| 6374 | int num_matches, |
| 6375 | char_u **matches, /* list of matches */ |
| 6376 | int match, |
| 6377 | int showtail) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6378 | { |
| 6379 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6380 | int row; |
| 6381 | char_u *buf; |
| 6382 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6383 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6384 | int fillchar; |
| 6385 | int attr; |
| 6386 | int i; |
| 6387 | int highlight = TRUE; |
| 6388 | char_u *selstart = NULL; |
| 6389 | int selstart_col = 0; |
| 6390 | char_u *selend = NULL; |
| 6391 | static int first_match = 0; |
| 6392 | int add_left = FALSE; |
| 6393 | char_u *s; |
| 6394 | #ifdef FEAT_MENU |
| 6395 | int emenu; |
| 6396 | #endif |
| 6397 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6398 | int l; |
| 6399 | #endif |
| 6400 | |
| 6401 | if (matches == NULL) /* interrupted completion? */ |
| 6402 | return; |
| 6403 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6404 | #ifdef FEAT_MBYTE |
| 6405 | if (has_mbyte) |
| 6406 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6407 | else |
| 6408 | #endif |
| 6409 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6410 | if (buf == NULL) |
| 6411 | return; |
| 6412 | |
| 6413 | if (match == -1) /* don't show match but original text */ |
| 6414 | { |
| 6415 | match = 0; |
| 6416 | highlight = FALSE; |
| 6417 | } |
| 6418 | /* count 1 for the ending ">" */ |
| 6419 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6420 | if (match == 0) |
| 6421 | first_match = 0; |
| 6422 | else if (match < first_match) |
| 6423 | { |
| 6424 | /* jumping left, as far as we can go */ |
| 6425 | first_match = match; |
| 6426 | add_left = TRUE; |
| 6427 | } |
| 6428 | else |
| 6429 | { |
| 6430 | /* check if match fits on the screen */ |
| 6431 | for (i = first_match; i < match; ++i) |
| 6432 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6433 | if (first_match > 0) |
| 6434 | clen += 2; |
| 6435 | /* jumping right, put match at the left */ |
| 6436 | if ((long)clen > Columns) |
| 6437 | { |
| 6438 | first_match = match; |
| 6439 | /* if showing the last match, we can add some on the left */ |
| 6440 | clen = 2; |
| 6441 | for (i = match; i < num_matches; ++i) |
| 6442 | { |
| 6443 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6444 | if ((long)clen >= Columns) |
| 6445 | break; |
| 6446 | } |
| 6447 | if (i == num_matches) |
| 6448 | add_left = TRUE; |
| 6449 | } |
| 6450 | } |
| 6451 | if (add_left) |
| 6452 | while (first_match > 0) |
| 6453 | { |
| 6454 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6455 | if ((long)clen >= Columns) |
| 6456 | break; |
| 6457 | --first_match; |
| 6458 | } |
| 6459 | |
| 6460 | fillchar = fillchar_status(&attr, TRUE); |
| 6461 | |
| 6462 | if (first_match == 0) |
| 6463 | { |
| 6464 | *buf = NUL; |
| 6465 | len = 0; |
| 6466 | } |
| 6467 | else |
| 6468 | { |
| 6469 | STRCPY(buf, "< "); |
| 6470 | len = 2; |
| 6471 | } |
| 6472 | clen = len; |
| 6473 | |
| 6474 | i = first_match; |
| 6475 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6476 | { |
| 6477 | if (i == match) |
| 6478 | { |
| 6479 | selstart = buf + len; |
| 6480 | selstart_col = clen; |
| 6481 | } |
| 6482 | |
| 6483 | s = L_MATCH(i); |
| 6484 | /* Check for menu separators - replace with '|' */ |
| 6485 | #ifdef FEAT_MENU |
| 6486 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6487 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6488 | if (emenu && menu_is_separator(s)) |
| 6489 | { |
| 6490 | STRCPY(buf + len, transchar('|')); |
| 6491 | l = (int)STRLEN(buf + len); |
| 6492 | len += l; |
| 6493 | clen += l; |
| 6494 | } |
| 6495 | else |
| 6496 | #endif |
| 6497 | for ( ; *s != NUL; ++s) |
| 6498 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6499 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6500 | clen += ptr2cells(s); |
| 6501 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6502 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6503 | { |
| 6504 | STRNCPY(buf + len, s, l); |
| 6505 | s += l - 1; |
| 6506 | len += l; |
| 6507 | } |
| 6508 | else |
| 6509 | #endif |
| 6510 | { |
| 6511 | STRCPY(buf + len, transchar_byte(*s)); |
| 6512 | len += (int)STRLEN(buf + len); |
| 6513 | } |
| 6514 | } |
| 6515 | if (i == match) |
| 6516 | selend = buf + len; |
| 6517 | |
| 6518 | *(buf + len++) = ' '; |
| 6519 | *(buf + len++) = ' '; |
| 6520 | clen += 2; |
| 6521 | if (++i == num_matches) |
| 6522 | break; |
| 6523 | } |
| 6524 | |
| 6525 | if (i != num_matches) |
| 6526 | { |
| 6527 | *(buf + len++) = '>'; |
| 6528 | ++clen; |
| 6529 | } |
| 6530 | |
| 6531 | buf[len] = NUL; |
| 6532 | |
| 6533 | row = cmdline_row - 1; |
| 6534 | if (row >= 0) |
| 6535 | { |
| 6536 | if (wild_menu_showing == 0) |
| 6537 | { |
| 6538 | if (msg_scrolled > 0) |
| 6539 | { |
| 6540 | /* Put the wildmenu just above the command line. If there is |
| 6541 | * no room, scroll the screen one line up. */ |
| 6542 | if (cmdline_row == Rows - 1) |
| 6543 | { |
| 6544 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6545 | ++msg_scrolled; |
| 6546 | } |
| 6547 | else |
| 6548 | { |
| 6549 | ++cmdline_row; |
| 6550 | ++row; |
| 6551 | } |
| 6552 | wild_menu_showing = WM_SCROLLED; |
| 6553 | } |
| 6554 | else |
| 6555 | { |
| 6556 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6557 | * Set 'winminheight' to zero to avoid that the window is |
| 6558 | * resized. */ |
| 6559 | if (lastwin->w_status_height == 0) |
| 6560 | { |
| 6561 | save_p_ls = p_ls; |
| 6562 | save_p_wmh = p_wmh; |
| 6563 | p_ls = 2; |
| 6564 | p_wmh = 0; |
| 6565 | last_status(FALSE); |
| 6566 | } |
| 6567 | wild_menu_showing = WM_SHOWN; |
| 6568 | } |
| 6569 | } |
| 6570 | |
| 6571 | screen_puts(buf, row, 0, attr); |
| 6572 | if (selstart != NULL && highlight) |
| 6573 | { |
| 6574 | *selend = NUL; |
| 6575 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6576 | } |
| 6577 | |
| 6578 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6579 | } |
| 6580 | |
| 6581 | #ifdef FEAT_VERTSPLIT |
| 6582 | win_redraw_last_status(topframe); |
| 6583 | #else |
| 6584 | lastwin->w_redr_status = TRUE; |
| 6585 | #endif |
| 6586 | vim_free(buf); |
| 6587 | } |
| 6588 | #endif |
| 6589 | |
| 6590 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6591 | /* |
| 6592 | * Redraw the status line of window wp. |
| 6593 | * |
| 6594 | * If inversion is possible we use it. Else '=' characters are used. |
| 6595 | */ |
| 6596 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6597 | win_redr_status(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6598 | { |
| 6599 | int row; |
| 6600 | char_u *p; |
| 6601 | int len; |
| 6602 | int fillchar; |
| 6603 | int attr; |
| 6604 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6605 | static int busy = FALSE; |
| 6606 | |
| 6607 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6608 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6609 | if (busy) |
| 6610 | return; |
| 6611 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6612 | |
| 6613 | wp->w_redr_status = FALSE; |
| 6614 | if (wp->w_status_height == 0) |
| 6615 | { |
| 6616 | /* no status line, can only be last window */ |
| 6617 | redraw_cmdline = TRUE; |
| 6618 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6619 | else if (!redrawing() |
| 6620 | #ifdef FEAT_INS_EXPAND |
| 6621 | /* don't update status line when popup menu is visible and may be |
| 6622 | * drawn over it */ |
| 6623 | || pum_visible() |
| 6624 | #endif |
| 6625 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6626 | { |
| 6627 | /* Don't redraw right now, do it later. */ |
| 6628 | wp->w_redr_status = TRUE; |
| 6629 | } |
| 6630 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6631 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6632 | { |
| 6633 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6634 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6635 | } |
| 6636 | #endif |
| 6637 | else |
| 6638 | { |
| 6639 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6640 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6641 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6642 | p = NameBuff; |
| 6643 | len = (int)STRLEN(p); |
| 6644 | |
| 6645 | if (wp->w_buffer->b_help |
| 6646 | #ifdef FEAT_QUICKFIX |
| 6647 | || wp->w_p_pvw |
| 6648 | #endif |
| 6649 | || bufIsChanged(wp->w_buffer) |
| 6650 | || wp->w_buffer->b_p_ro) |
| 6651 | *(p + len++) = ' '; |
| 6652 | if (wp->w_buffer->b_help) |
| 6653 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6654 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6655 | len += (int)STRLEN(p + len); |
| 6656 | } |
| 6657 | #ifdef FEAT_QUICKFIX |
| 6658 | if (wp->w_p_pvw) |
| 6659 | { |
| 6660 | STRCPY(p + len, _("[Preview]")); |
| 6661 | len += (int)STRLEN(p + len); |
| 6662 | } |
| 6663 | #endif |
| 6664 | if (bufIsChanged(wp->w_buffer)) |
| 6665 | { |
| 6666 | STRCPY(p + len, "[+]"); |
| 6667 | len += 3; |
| 6668 | } |
| 6669 | if (wp->w_buffer->b_p_ro) |
| 6670 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6671 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6672 | len += 4; |
| 6673 | } |
| 6674 | |
| 6675 | #ifndef FEAT_VERTSPLIT |
| 6676 | this_ru_col = ru_col; |
| 6677 | if (this_ru_col < (Columns + 1) / 2) |
| 6678 | this_ru_col = (Columns + 1) / 2; |
| 6679 | #else |
| 6680 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6681 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6682 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6683 | if (this_ru_col <= 1) |
| 6684 | { |
| 6685 | p = (char_u *)"<"; /* No room for file name! */ |
| 6686 | len = 1; |
| 6687 | } |
| 6688 | else |
| 6689 | #endif |
| 6690 | #ifdef FEAT_MBYTE |
| 6691 | if (has_mbyte) |
| 6692 | { |
| 6693 | int clen = 0, i; |
| 6694 | |
| 6695 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6696 | clen = mb_string2cells(p, -1); |
| 6697 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6698 | /* Find first character that will fit. |
| 6699 | * Going from start to end is much faster for DBCS. */ |
| 6700 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6701 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6702 | clen -= (*mb_ptr2cells)(p + i); |
| 6703 | len = clen; |
| 6704 | if (i > 0) |
| 6705 | { |
| 6706 | p = p + i - 1; |
| 6707 | *p = '<'; |
| 6708 | ++len; |
| 6709 | } |
| 6710 | |
| 6711 | } |
| 6712 | else |
| 6713 | #endif |
| 6714 | if (len > this_ru_col - 1) |
| 6715 | { |
| 6716 | p += len - (this_ru_col - 1); |
| 6717 | *p = '<'; |
| 6718 | len = this_ru_col - 1; |
| 6719 | } |
| 6720 | |
| 6721 | row = W_WINROW(wp) + wp->w_height; |
| 6722 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6723 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6724 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6725 | |
| 6726 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 6727 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6728 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6729 | - 1 + W_WINCOL(wp)), attr); |
| 6730 | |
| 6731 | #ifdef FEAT_CMDL_INFO |
| 6732 | win_redr_ruler(wp, TRUE); |
| 6733 | #endif |
| 6734 | } |
| 6735 | |
| 6736 | #ifdef FEAT_VERTSPLIT |
| 6737 | /* |
| 6738 | * May need to draw the character below the vertical separator. |
| 6739 | */ |
| 6740 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6741 | { |
| 6742 | if (stl_connected(wp)) |
| 6743 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6744 | else |
| 6745 | fillchar = fillchar_vsep(&attr); |
| 6746 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6747 | attr); |
| 6748 | } |
| 6749 | #endif |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6750 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6751 | } |
| 6752 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6753 | #ifdef FEAT_STL_OPT |
| 6754 | /* |
| 6755 | * Redraw the status line according to 'statusline' and take care of any |
| 6756 | * errors encountered. |
| 6757 | */ |
| 6758 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6759 | redraw_custom_statusline(win_T *wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6760 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6761 | static int entered = FALSE; |
| 6762 | int save_called_emsg = called_emsg; |
| 6763 | |
| 6764 | /* When called recursively return. This can happen when the statusline |
| 6765 | * contains an expression that triggers a redraw. */ |
| 6766 | if (entered) |
| 6767 | return; |
| 6768 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6769 | |
| 6770 | called_emsg = FALSE; |
| 6771 | win_redr_custom(wp, FALSE); |
| 6772 | if (called_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6773 | { |
| 6774 | /* When there is an error disable the statusline, otherwise the |
| 6775 | * display is messed up with errors and a redraw triggers the problem |
| 6776 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6777 | set_string_option_direct((char_u *)"statusline", -1, |
| 6778 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6779 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6780 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6781 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6782 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6783 | } |
| 6784 | #endif |
| 6785 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6786 | # ifdef FEAT_VERTSPLIT |
| 6787 | /* |
| 6788 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6789 | * line of the window right of it. If not, then it's a vertical separator. |
| 6790 | * Only call if (wp->w_vsep_width != 0). |
| 6791 | */ |
| 6792 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6793 | stl_connected(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6794 | { |
| 6795 | frame_T *fr; |
| 6796 | |
| 6797 | fr = wp->w_frame; |
| 6798 | while (fr->fr_parent != NULL) |
| 6799 | { |
| 6800 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6801 | { |
| 6802 | if (fr->fr_next != NULL) |
| 6803 | break; |
| 6804 | } |
| 6805 | else |
| 6806 | { |
| 6807 | if (fr->fr_next != NULL) |
| 6808 | return TRUE; |
| 6809 | } |
| 6810 | fr = fr->fr_parent; |
| 6811 | } |
| 6812 | return FALSE; |
| 6813 | } |
| 6814 | # endif |
| 6815 | |
| 6816 | #endif /* FEAT_WINDOWS */ |
| 6817 | |
| 6818 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6819 | /* |
| 6820 | * Get the value to show for the language mappings, active 'keymap'. |
| 6821 | */ |
| 6822 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6823 | get_keymap_str( |
| 6824 | win_T *wp, |
| 6825 | char_u *buf, /* buffer for the result */ |
| 6826 | int len) /* length of buffer */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6827 | { |
| 6828 | char_u *p; |
| 6829 | |
| 6830 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6831 | return FALSE; |
| 6832 | |
| 6833 | { |
| 6834 | #ifdef FEAT_EVAL |
| 6835 | buf_T *old_curbuf = curbuf; |
| 6836 | win_T *old_curwin = curwin; |
| 6837 | char_u *s; |
| 6838 | |
| 6839 | curbuf = wp->w_buffer; |
| 6840 | curwin = wp; |
| 6841 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6842 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6843 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6844 | --emsg_skip; |
| 6845 | curbuf = old_curbuf; |
| 6846 | curwin = old_curwin; |
| 6847 | if (p == NULL || *p == NUL) |
| 6848 | #endif |
| 6849 | { |
| 6850 | #ifdef FEAT_KEYMAP |
| 6851 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6852 | p = wp->w_buffer->b_p_keymap; |
| 6853 | else |
| 6854 | #endif |
| 6855 | p = (char_u *)"lang"; |
| 6856 | } |
| 6857 | if ((int)(STRLEN(p) + 3) < len) |
| 6858 | sprintf((char *)buf, "<%s>", p); |
| 6859 | else |
| 6860 | buf[0] = NUL; |
| 6861 | #ifdef FEAT_EVAL |
| 6862 | vim_free(s); |
| 6863 | #endif |
| 6864 | } |
| 6865 | return buf[0] != NUL; |
| 6866 | } |
| 6867 | #endif |
| 6868 | |
| 6869 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6870 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6871 | * Redraw the status line or ruler of window "wp". |
| 6872 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6873 | */ |
| 6874 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6875 | win_redr_custom( |
| 6876 | win_T *wp, |
| 6877 | int draw_ruler) /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6878 | { |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6879 | static int entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6880 | int attr; |
| 6881 | int curattr; |
| 6882 | int row; |
| 6883 | int col = 0; |
| 6884 | int maxwidth; |
| 6885 | int width; |
| 6886 | int n; |
| 6887 | int len; |
| 6888 | int fillchar; |
| 6889 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6890 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6891 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6892 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6893 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6894 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6895 | win_T *ewp; |
| 6896 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6897 | |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6898 | /* There is a tiny chance that this gets called recursively: When |
| 6899 | * redrawing a status line triggers redrawing the ruler or tabline. |
| 6900 | * Avoid trouble by not allowing recursion. */ |
| 6901 | if (entered) |
| 6902 | return; |
| 6903 | entered = TRUE; |
| 6904 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6905 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6906 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6907 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6908 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6909 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6910 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6911 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6912 | attr = hl_attr(HLF_TPF); |
| 6913 | maxwidth = Columns; |
| 6914 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6915 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6916 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6917 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6918 | else |
| 6919 | { |
| 6920 | row = W_WINROW(wp) + wp->w_height; |
| 6921 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6922 | maxwidth = W_WIDTH(wp); |
| 6923 | |
| 6924 | if (draw_ruler) |
| 6925 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6926 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6927 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6928 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6929 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6930 | if (*++stl == '-') |
| 6931 | stl++; |
| 6932 | if (atoi((char *)stl)) |
| 6933 | while (VIM_ISDIGIT(*stl)) |
| 6934 | stl++; |
| 6935 | if (*stl++ != '(') |
| 6936 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6937 | } |
| 6938 | #ifdef FEAT_VERTSPLIT |
| 6939 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6940 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6941 | col = (W_WIDTH(wp) + 1) / 2; |
| 6942 | #else |
| 6943 | col = ru_col; |
| 6944 | if (col > (Columns + 1) / 2) |
| 6945 | col = (Columns + 1) / 2; |
| 6946 | #endif |
| 6947 | maxwidth = W_WIDTH(wp) - col; |
| 6948 | #ifdef FEAT_WINDOWS |
| 6949 | if (!wp->w_status_height) |
| 6950 | #endif |
| 6951 | { |
| 6952 | row = Rows - 1; |
| 6953 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6954 | fillchar = ' '; |
| 6955 | attr = 0; |
| 6956 | } |
| 6957 | |
| 6958 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6959 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6960 | # endif |
| 6961 | } |
| 6962 | else |
| 6963 | { |
| 6964 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6965 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6966 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6967 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6968 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6969 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 6970 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6971 | # endif |
| 6972 | } |
| 6973 | |
| 6974 | #ifdef FEAT_VERTSPLIT |
| 6975 | col += W_WINCOL(wp); |
| 6976 | #endif |
| 6977 | } |
| 6978 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6979 | if (maxwidth <= 0) |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6980 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6981 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6982 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 6983 | * the cursor away and back. */ |
| 6984 | ewp = wp == NULL ? curwin : wp; |
| 6985 | p_crb_save = ewp->w_p_crb; |
| 6986 | ewp->w_p_crb = FALSE; |
| 6987 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6988 | /* Make a copy, because the statusline may include a function call that |
| 6989 | * might change the option value and free the memory. */ |
| 6990 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6991 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6992 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6993 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6994 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6995 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6996 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 6997 | /* Make all characters printable. */ |
| 6998 | p = transstr(buf); |
| 6999 | if (p != NULL) |
| 7000 | { |
| 7001 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 7002 | vim_free(p); |
| 7003 | } |
| 7004 | |
| 7005 | /* fill up with "fillchar" */ |
| 7006 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 7007 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7008 | { |
| 7009 | #ifdef FEAT_MBYTE |
| 7010 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 7011 | #else |
| 7012 | buf[len++] = fillchar; |
| 7013 | #endif |
| 7014 | ++width; |
| 7015 | } |
| 7016 | buf[len] = NUL; |
| 7017 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7018 | /* |
| 7019 | * Draw each snippet with the specified highlighting. |
| 7020 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7021 | curattr = attr; |
| 7022 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7023 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7024 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7025 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7026 | screen_puts_len(p, len, row, col, curattr); |
| 7027 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7028 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7029 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7030 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7031 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7032 | else if (hltab[n].userhl < 0) |
| 7033 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7034 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 7035 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7036 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7037 | #endif |
| 7038 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7039 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7040 | } |
| 7041 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7042 | |
| 7043 | if (wp == NULL) |
| 7044 | { |
| 7045 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 7046 | col = 0; |
| 7047 | len = 0; |
| 7048 | p = buf; |
| 7049 | fillchar = 0; |
| 7050 | for (n = 0; tabtab[n].start != NULL; n++) |
| 7051 | { |
| 7052 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 7053 | while (col < len) |
| 7054 | TabPageIdxs[col++] = fillchar; |
| 7055 | p = tabtab[n].start; |
| 7056 | fillchar = tabtab[n].userhl; |
| 7057 | } |
| 7058 | while (col < Columns) |
| 7059 | TabPageIdxs[col++] = fillchar; |
| 7060 | } |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7061 | |
| 7062 | theend: |
| 7063 | entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7064 | } |
| 7065 | |
| 7066 | #endif /* FEAT_STL_OPT */ |
| 7067 | |
| 7068 | /* |
| 7069 | * Output a single character directly to the screen and update ScreenLines. |
| 7070 | */ |
| 7071 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7072 | screen_putchar(int c, int row, int col, int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7073 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7074 | char_u buf[MB_MAXBYTES + 1]; |
| 7075 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7076 | #ifdef FEAT_MBYTE |
| 7077 | if (has_mbyte) |
| 7078 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 7079 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7080 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7081 | { |
| 7082 | buf[0] = c; |
| 7083 | buf[1] = NUL; |
| 7084 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7085 | screen_puts(buf, row, col, attr); |
| 7086 | } |
| 7087 | |
| 7088 | /* |
| 7089 | * Get a single character directly from ScreenLines into "bytes[]". |
| 7090 | * Also return its attribute in *attrp; |
| 7091 | */ |
| 7092 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7093 | screen_getbytes(int row, int col, char_u *bytes, int *attrp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7094 | { |
| 7095 | unsigned off; |
| 7096 | |
| 7097 | /* safety check */ |
| 7098 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 7099 | { |
| 7100 | off = LineOffset[row] + col; |
| 7101 | *attrp = ScreenAttrs[off]; |
| 7102 | bytes[0] = ScreenLines[off]; |
| 7103 | bytes[1] = NUL; |
| 7104 | |
| 7105 | #ifdef FEAT_MBYTE |
| 7106 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7107 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 7108 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7109 | { |
| 7110 | bytes[0] = ScreenLines[off]; |
| 7111 | bytes[1] = ScreenLines2[off]; |
| 7112 | bytes[2] = NUL; |
| 7113 | } |
| 7114 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 7115 | { |
| 7116 | bytes[1] = ScreenLines[off + 1]; |
| 7117 | bytes[2] = NUL; |
| 7118 | } |
| 7119 | #endif |
| 7120 | } |
| 7121 | } |
| 7122 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7123 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 7124 | static int screen_comp_differs(int, int*); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7125 | |
| 7126 | /* |
| 7127 | * Return TRUE if composing characters for screen posn "off" differs from |
| 7128 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7129 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7130 | */ |
| 7131 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7132 | screen_comp_differs(int off, int *u8cc) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7133 | { |
| 7134 | int i; |
| 7135 | |
| 7136 | for (i = 0; i < Screen_mco; ++i) |
| 7137 | { |
| 7138 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 7139 | return TRUE; |
| 7140 | if (u8cc[i] == 0) |
| 7141 | break; |
| 7142 | } |
| 7143 | return FALSE; |
| 7144 | } |
| 7145 | #endif |
| 7146 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7147 | /* |
| 7148 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 7149 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 7150 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 7151 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 7152 | */ |
| 7153 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7154 | screen_puts( |
| 7155 | char_u *text, |
| 7156 | int row, |
| 7157 | int col, |
| 7158 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7159 | { |
| 7160 | screen_puts_len(text, -1, row, col, attr); |
| 7161 | } |
| 7162 | |
| 7163 | /* |
| 7164 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 7165 | * a NUL. |
| 7166 | */ |
| 7167 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7168 | screen_puts_len( |
| 7169 | char_u *text, |
| 7170 | int textlen, |
| 7171 | int row, |
| 7172 | int col, |
| 7173 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7174 | { |
| 7175 | unsigned off; |
| 7176 | char_u *ptr = text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7177 | int len = textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7178 | int c; |
| 7179 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7180 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7181 | int mbyte_blen = 1; |
| 7182 | int mbyte_cells = 1; |
| 7183 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7184 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7185 | int clear_next_cell = FALSE; |
| 7186 | # ifdef FEAT_ARABIC |
| 7187 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7188 | int pc, nc, nc1; |
| 7189 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7190 | # endif |
| 7191 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7192 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7193 | int force_redraw_this; |
| 7194 | int force_redraw_next = FALSE; |
| 7195 | #endif |
| 7196 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7197 | |
| 7198 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 7199 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7200 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7201 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7202 | #ifdef FEAT_MBYTE |
| 7203 | /* When drawing over the right halve of a double-wide char clear out the |
| 7204 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7205 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7206 | # ifdef FEAT_GUI |
| 7207 | && !gui.in_use |
| 7208 | # endif |
| 7209 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7210 | { |
| 7211 | ScreenLines[off - 1] = ' '; |
| 7212 | ScreenAttrs[off - 1] = 0; |
| 7213 | if (enc_utf8) |
| 7214 | { |
| 7215 | ScreenLinesUC[off - 1] = 0; |
| 7216 | ScreenLinesC[0][off - 1] = 0; |
| 7217 | } |
| 7218 | /* redraw the previous cell, make it empty */ |
| 7219 | screen_char(off - 1, row, col - 1); |
| 7220 | /* force the cell at "col" to be redrawn */ |
| 7221 | force_redraw_next = TRUE; |
| 7222 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7223 | #endif |
| 7224 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7225 | #ifdef FEAT_MBYTE |
| 7226 | max_off = LineOffset[row] + screen_Columns; |
| 7227 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 7228 | while (col < screen_Columns |
| 7229 | && (len < 0 || (int)(ptr - text) < len) |
| 7230 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7231 | { |
| 7232 | c = *ptr; |
| 7233 | #ifdef FEAT_MBYTE |
| 7234 | /* check if this is the first byte of a multibyte */ |
| 7235 | if (has_mbyte) |
| 7236 | { |
| 7237 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7238 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7239 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7240 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7241 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7242 | mbyte_cells = 1; |
| 7243 | else if (enc_dbcs != 0) |
| 7244 | mbyte_cells = mbyte_blen; |
| 7245 | else /* enc_utf8 */ |
| 7246 | { |
| 7247 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7248 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7249 | (int)((text + len) - ptr)); |
| 7250 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7251 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7252 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7253 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7254 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 7255 | if (u8c >= 0x10000) |
| 7256 | { |
| 7257 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 7258 | if (attr == 0) |
| 7259 | attr = hl_attr(HLF_8); |
| 7260 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7261 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7262 | # ifdef FEAT_ARABIC |
| 7263 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 7264 | { |
| 7265 | /* Do Arabic shaping. */ |
| 7266 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 7267 | { |
| 7268 | /* Past end of string to be displayed. */ |
| 7269 | nc = NUL; |
| 7270 | nc1 = NUL; |
| 7271 | } |
| 7272 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7273 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 7274 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 7275 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7276 | nc1 = pcc[0]; |
| 7277 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7278 | pc = prev_c; |
| 7279 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7280 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7281 | } |
| 7282 | else |
| 7283 | prev_c = u8c; |
| 7284 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 7285 | if (col + mbyte_cells > screen_Columns) |
| 7286 | { |
| 7287 | /* Only 1 cell left, but character requires 2 cells: |
| 7288 | * display a '>' in the last column to avoid wrapping. */ |
| 7289 | c = '>'; |
| 7290 | mbyte_cells = 1; |
| 7291 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7292 | } |
| 7293 | } |
| 7294 | #endif |
| 7295 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7296 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7297 | force_redraw_this = force_redraw_next; |
| 7298 | force_redraw_next = FALSE; |
| 7299 | #endif |
| 7300 | |
| 7301 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7302 | #ifdef FEAT_MBYTE |
| 7303 | || (mbyte_cells == 2 |
| 7304 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 7305 | || (enc_dbcs == DBCS_JPNU |
| 7306 | && c == 0x8e |
| 7307 | && ScreenLines2[off] != ptr[1]) |
| 7308 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7309 | && (ScreenLinesUC[off] != |
| 7310 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 7311 | || (ScreenLinesUC[off] != 0 |
| 7312 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7313 | #endif |
| 7314 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7315 | || exmode_active; |
| 7316 | |
| 7317 | if (need_redraw |
| 7318 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7319 | || force_redraw_this |
| 7320 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7321 | ) |
| 7322 | { |
| 7323 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7324 | /* The bold trick makes a single row of pixels appear in the next |
| 7325 | * character. When a bold character is removed, the next |
| 7326 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7327 | * and for some xterms. */ |
| 7328 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7329 | # ifdef FEAT_GUI |
| 7330 | gui.in_use |
| 7331 | # endif |
| 7332 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7333 | || |
| 7334 | # endif |
| 7335 | # ifdef UNIX |
| 7336 | term_is_xterm |
| 7337 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7338 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7339 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7340 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7341 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7342 | if (n > HL_ALL) |
| 7343 | n = syn_attr2attr(n); |
| 7344 | if (n & HL_BOLD) |
| 7345 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7346 | } |
| 7347 | #endif |
| 7348 | #ifdef FEAT_MBYTE |
| 7349 | /* When at the end of the text and overwriting a two-cell |
| 7350 | * character with a one-cell character, need to clear the next |
| 7351 | * cell. Also when overwriting the left halve of a two-cell char |
| 7352 | * with the right halve of a two-cell char. Do this only once |
| 7353 | * (mb_off2cells() may return 2 on the right halve). */ |
| 7354 | if (clear_next_cell) |
| 7355 | clear_next_cell = FALSE; |
| 7356 | else if (has_mbyte |
| 7357 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 7358 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7359 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7360 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7361 | && (*mb_off2cells)(off, max_off) == 1 |
| 7362 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7363 | clear_next_cell = TRUE; |
| 7364 | |
| 7365 | /* Make sure we never leave a second byte of a double-byte behind, |
| 7366 | * it confuses mb_off2cells(). */ |
| 7367 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7368 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7369 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7370 | && (*mb_off2cells)(off, max_off) == 1 |
| 7371 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7372 | ScreenLines[off + mbyte_blen] = 0; |
| 7373 | #endif |
| 7374 | ScreenLines[off] = c; |
| 7375 | ScreenAttrs[off] = attr; |
| 7376 | #ifdef FEAT_MBYTE |
| 7377 | if (enc_utf8) |
| 7378 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7379 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7380 | ScreenLinesUC[off] = 0; |
| 7381 | else |
| 7382 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7383 | int i; |
| 7384 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7385 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7386 | for (i = 0; i < Screen_mco; ++i) |
| 7387 | { |
| 7388 | ScreenLinesC[i][off] = u8cc[i]; |
| 7389 | if (u8cc[i] == 0) |
| 7390 | break; |
| 7391 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7392 | } |
| 7393 | if (mbyte_cells == 2) |
| 7394 | { |
| 7395 | ScreenLines[off + 1] = 0; |
| 7396 | ScreenAttrs[off + 1] = attr; |
| 7397 | } |
| 7398 | screen_char(off, row, col); |
| 7399 | } |
| 7400 | else if (mbyte_cells == 2) |
| 7401 | { |
| 7402 | ScreenLines[off + 1] = ptr[1]; |
| 7403 | ScreenAttrs[off + 1] = attr; |
| 7404 | screen_char_2(off, row, col); |
| 7405 | } |
| 7406 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7407 | { |
| 7408 | ScreenLines2[off] = ptr[1]; |
| 7409 | screen_char(off, row, col); |
| 7410 | } |
| 7411 | else |
| 7412 | #endif |
| 7413 | screen_char(off, row, col); |
| 7414 | } |
| 7415 | #ifdef FEAT_MBYTE |
| 7416 | if (has_mbyte) |
| 7417 | { |
| 7418 | off += mbyte_cells; |
| 7419 | col += mbyte_cells; |
| 7420 | ptr += mbyte_blen; |
| 7421 | if (clear_next_cell) |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7422 | { |
| 7423 | /* This only happens at the end, display one space next. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7424 | ptr = (char_u *)" "; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7425 | len = -1; |
| 7426 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7427 | } |
| 7428 | else |
| 7429 | #endif |
| 7430 | { |
| 7431 | ++off; |
| 7432 | ++col; |
| 7433 | ++ptr; |
| 7434 | } |
| 7435 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7436 | |
| 7437 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7438 | /* If we detected the next character needs to be redrawn, but the text |
| 7439 | * doesn't extend up to there, update the character here. */ |
| 7440 | if (force_redraw_next && col < screen_Columns) |
| 7441 | { |
| 7442 | # ifdef FEAT_MBYTE |
| 7443 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7444 | screen_char_2(off, row, col); |
| 7445 | else |
| 7446 | # endif |
| 7447 | screen_char(off, row, col); |
| 7448 | } |
| 7449 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7450 | } |
| 7451 | |
| 7452 | #ifdef FEAT_SEARCH_EXTRA |
| 7453 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7454 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7455 | */ |
| 7456 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7457 | start_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7458 | { |
| 7459 | if (p_hls && !no_hlsearch) |
| 7460 | { |
| 7461 | last_pat_prog(&search_hl.rm); |
| 7462 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7463 | # ifdef FEAT_RELTIME |
| 7464 | /* Set the time limit to 'redrawtime'. */ |
| 7465 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7466 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7467 | } |
| 7468 | } |
| 7469 | |
| 7470 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7471 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7472 | */ |
| 7473 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7474 | end_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7475 | { |
| 7476 | if (search_hl.rm.regprog != NULL) |
| 7477 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7478 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7479 | search_hl.rm.regprog = NULL; |
| 7480 | } |
| 7481 | } |
| 7482 | |
| 7483 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7484 | * Init for calling prepare_search_hl(). |
| 7485 | */ |
| 7486 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7487 | init_search_hl(win_T *wp) |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7488 | { |
| 7489 | matchitem_T *cur; |
| 7490 | |
| 7491 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7492 | * match */ |
| 7493 | cur = wp->w_match_head; |
| 7494 | while (cur != NULL) |
| 7495 | { |
| 7496 | cur->hl.rm = cur->match; |
| 7497 | if (cur->hlg_id == 0) |
| 7498 | cur->hl.attr = 0; |
| 7499 | else |
| 7500 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7501 | cur->hl.buf = wp->w_buffer; |
| 7502 | cur->hl.lnum = 0; |
| 7503 | cur->hl.first_lnum = 0; |
| 7504 | # ifdef FEAT_RELTIME |
| 7505 | /* Set the time limit to 'redrawtime'. */ |
| 7506 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7507 | # endif |
| 7508 | cur = cur->next; |
| 7509 | } |
| 7510 | search_hl.buf = wp->w_buffer; |
| 7511 | search_hl.lnum = 0; |
| 7512 | search_hl.first_lnum = 0; |
| 7513 | /* time limit is set at the toplevel, for all windows */ |
| 7514 | } |
| 7515 | |
| 7516 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7517 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7518 | */ |
| 7519 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7520 | prepare_search_hl(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7521 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7522 | matchitem_T *cur; /* points to the match list */ |
| 7523 | match_T *shl; /* points to search_hl or a match */ |
| 7524 | int shl_flag; /* flag to indicate whether search_hl |
| 7525 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7526 | int pos_inprogress; /* marks that position match search is |
| 7527 | in progress */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7528 | int n; |
| 7529 | |
| 7530 | /* |
| 7531 | * When using a multi-line pattern, start searching at the top |
| 7532 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7533 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7534 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7535 | cur = wp->w_match_head; |
| 7536 | shl_flag = FALSE; |
| 7537 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7538 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7539 | if (shl_flag == FALSE) |
| 7540 | { |
| 7541 | shl = &search_hl; |
| 7542 | shl_flag = TRUE; |
| 7543 | } |
| 7544 | else |
| 7545 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7546 | if (shl->rm.regprog != NULL |
| 7547 | && shl->lnum == 0 |
| 7548 | && re_multiline(shl->rm.regprog)) |
| 7549 | { |
| 7550 | if (shl->first_lnum == 0) |
| 7551 | { |
| 7552 | # ifdef FEAT_FOLDING |
| 7553 | for (shl->first_lnum = lnum; |
| 7554 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7555 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7556 | NULL, NULL, TRUE, NULL)) |
| 7557 | break; |
| 7558 | # else |
| 7559 | shl->first_lnum = wp->w_topline; |
| 7560 | # endif |
| 7561 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7562 | if (cur != NULL) |
| 7563 | cur->pos.cur = 0; |
| 7564 | pos_inprogress = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7565 | n = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7566 | while (shl->first_lnum < lnum && (shl->rm.regprog != NULL |
| 7567 | || (cur != NULL && pos_inprogress))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7568 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7569 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, cur); |
| 7570 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
| 7571 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7572 | if (shl->lnum != 0) |
| 7573 | { |
| 7574 | shl->first_lnum = shl->lnum |
| 7575 | + shl->rm.endpos[0].lnum |
| 7576 | - shl->rm.startpos[0].lnum; |
| 7577 | n = shl->rm.endpos[0].col; |
| 7578 | } |
| 7579 | else |
| 7580 | { |
| 7581 | ++shl->first_lnum; |
| 7582 | n = 0; |
| 7583 | } |
| 7584 | } |
| 7585 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7586 | if (shl != &search_hl && cur != NULL) |
| 7587 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7592 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7593 | * Uses shl->buf. |
| 7594 | * Sets shl->lnum and shl->rm contents. |
| 7595 | * Note: Assumes a previous match is always before "lnum", unless |
| 7596 | * shl->lnum is zero. |
| 7597 | * Careful: Any pointers for buffer lines will become invalid. |
| 7598 | */ |
| 7599 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7600 | next_search_hl( |
| 7601 | win_T *win, |
| 7602 | match_T *shl, /* points to search_hl or a match */ |
| 7603 | linenr_T lnum, |
| 7604 | colnr_T mincol, /* minimal column for a match */ |
| 7605 | matchitem_T *cur) /* to retrieve match positions if any */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7606 | { |
| 7607 | linenr_T l; |
| 7608 | colnr_T matchcol; |
| 7609 | long nmatched; |
| 7610 | |
| 7611 | if (shl->lnum != 0) |
| 7612 | { |
| 7613 | /* Check for three situations: |
| 7614 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7615 | * 2. If the previous match includes "mincol", use it. |
| 7616 | * 3. Continue after the previous match. |
| 7617 | */ |
| 7618 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7619 | if (lnum > l) |
| 7620 | shl->lnum = 0; |
| 7621 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7622 | return; |
| 7623 | } |
| 7624 | |
| 7625 | /* |
| 7626 | * Repeat searching for a match until one is found that includes "mincol" |
| 7627 | * or none is found in this line. |
| 7628 | */ |
| 7629 | called_emsg = FALSE; |
| 7630 | for (;;) |
| 7631 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7632 | #ifdef FEAT_RELTIME |
| 7633 | /* Stop searching after passing the time limit. */ |
| 7634 | if (profile_passed_limit(&(shl->tm))) |
| 7635 | { |
| 7636 | shl->lnum = 0; /* no match found in time */ |
| 7637 | break; |
| 7638 | } |
| 7639 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7640 | /* Three situations: |
| 7641 | * 1. No useful previous match: search from start of line. |
| 7642 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7643 | * Break the loop if this is beyond the end of the line. |
| 7644 | * 3. Vi compatible searching: continue at end of previous match. |
| 7645 | */ |
| 7646 | if (shl->lnum == 0) |
| 7647 | matchcol = 0; |
| 7648 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7649 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7650 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7651 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7652 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7653 | |
| 7654 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7655 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7656 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7657 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7658 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7659 | shl->lnum = 0; |
| 7660 | break; |
| 7661 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7662 | #ifdef FEAT_MBYTE |
| 7663 | if (has_mbyte) |
| 7664 | matchcol += mb_ptr2len(ml); |
| 7665 | else |
| 7666 | #endif |
| 7667 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7668 | } |
| 7669 | else |
| 7670 | matchcol = shl->rm.endpos[0].col; |
| 7671 | |
| 7672 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7673 | if (shl->rm.regprog != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7674 | { |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7675 | /* Remember whether shl->rm is using a copy of the regprog in |
| 7676 | * cur->match. */ |
| 7677 | int regprog_is_copy = (shl != &search_hl && cur != NULL |
| 7678 | && shl == &cur->hl |
| 7679 | && cur->match.regprog == cur->hl.rm.regprog); |
| 7680 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7681 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, |
| 7682 | matchcol, |
| 7683 | #ifdef FEAT_RELTIME |
| 7684 | &(shl->tm) |
| 7685 | #else |
| 7686 | NULL |
| 7687 | #endif |
| 7688 | ); |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7689 | /* Copy the regprog, in case it got freed and recompiled. */ |
| 7690 | if (regprog_is_copy) |
| 7691 | cur->match.regprog = cur->hl.rm.regprog; |
| 7692 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7693 | if (called_emsg || got_int) |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7694 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7695 | /* Error while handling regexp: stop using this regexp. */ |
| 7696 | if (shl == &search_hl) |
| 7697 | { |
| 7698 | /* don't free regprog in the match list, it's a copy */ |
| 7699 | vim_regfree(shl->rm.regprog); |
| 7700 | SET_NO_HLSEARCH(TRUE); |
| 7701 | } |
| 7702 | shl->rm.regprog = NULL; |
| 7703 | shl->lnum = 0; |
| 7704 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" |
| 7705 | message */ |
| 7706 | break; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7707 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7708 | } |
| 7709 | else if (cur != NULL) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7710 | nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol); |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7711 | else |
| 7712 | nmatched = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7713 | if (nmatched == 0) |
| 7714 | { |
| 7715 | shl->lnum = 0; /* no match found */ |
| 7716 | break; |
| 7717 | } |
| 7718 | if (shl->rm.startpos[0].lnum > 0 |
| 7719 | || shl->rm.startpos[0].col >= mincol |
| 7720 | || nmatched > 1 |
| 7721 | || shl->rm.endpos[0].col > mincol) |
| 7722 | { |
| 7723 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7724 | break; /* useful match found */ |
| 7725 | } |
| 7726 | } |
| 7727 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7728 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7729 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7730 | next_search_hl_pos( |
| 7731 | match_T *shl, /* points to a match */ |
| 7732 | linenr_T lnum, |
| 7733 | posmatch_T *posmatch, /* match positions */ |
| 7734 | colnr_T mincol) /* minimal column for a match */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7735 | { |
| 7736 | int i; |
Bram Moolenaar | b6da44a | 2014-06-25 18:15:22 +0200 | [diff] [blame] | 7737 | int bot = -1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7738 | |
| 7739 | shl->lnum = 0; |
| 7740 | for (i = posmatch->cur; i < MAXPOSMATCH; i++) |
| 7741 | { |
| 7742 | if (posmatch->pos[i].lnum == 0) |
| 7743 | break; |
| 7744 | if (posmatch->pos[i].col < mincol) |
| 7745 | continue; |
| 7746 | if (posmatch->pos[i].lnum == lnum) |
| 7747 | { |
| 7748 | if (shl->lnum == lnum) |
| 7749 | { |
| 7750 | /* partially sort positions by column numbers |
| 7751 | * on the same line */ |
| 7752 | if (posmatch->pos[i].col < posmatch->pos[bot].col) |
| 7753 | { |
| 7754 | llpos_T tmp = posmatch->pos[i]; |
| 7755 | |
| 7756 | posmatch->pos[i] = posmatch->pos[bot]; |
| 7757 | posmatch->pos[bot] = tmp; |
| 7758 | } |
| 7759 | } |
| 7760 | else |
| 7761 | { |
| 7762 | bot = i; |
| 7763 | shl->lnum = lnum; |
| 7764 | } |
| 7765 | } |
| 7766 | } |
| 7767 | posmatch->cur = 0; |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 7768 | if (shl->lnum == lnum && bot >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7769 | { |
| 7770 | colnr_T start = posmatch->pos[bot].col == 0 |
| 7771 | ? 0 : posmatch->pos[bot].col - 1; |
| 7772 | colnr_T end = posmatch->pos[bot].col == 0 |
| 7773 | ? MAXCOL : start + posmatch->pos[bot].len; |
| 7774 | |
| 7775 | shl->rm.startpos[0].lnum = 0; |
| 7776 | shl->rm.startpos[0].col = start; |
| 7777 | shl->rm.endpos[0].lnum = 0; |
| 7778 | shl->rm.endpos[0].col = end; |
| 7779 | posmatch->cur = bot + 1; |
| 7780 | return TRUE; |
| 7781 | } |
| 7782 | return FALSE; |
| 7783 | } |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 7784 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7785 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7786 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7787 | screen_start_highlight(int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7788 | { |
| 7789 | attrentry_T *aep = NULL; |
| 7790 | |
| 7791 | screen_attr = attr; |
| 7792 | if (full_screen |
| 7793 | #ifdef WIN3264 |
| 7794 | && termcap_active |
| 7795 | #endif |
| 7796 | ) |
| 7797 | { |
| 7798 | #ifdef FEAT_GUI |
| 7799 | if (gui.in_use) |
| 7800 | { |
| 7801 | char buf[20]; |
| 7802 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7803 | /* The GUI handles this internally. */ |
| 7804 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7805 | OUT_STR(buf); |
| 7806 | } |
| 7807 | else |
| 7808 | #endif |
| 7809 | { |
| 7810 | if (attr > HL_ALL) /* special HL attr. */ |
| 7811 | { |
| 7812 | if (t_colors > 1) |
| 7813 | aep = syn_cterm_attr2entry(attr); |
| 7814 | else |
| 7815 | aep = syn_term_attr2entry(attr); |
| 7816 | if (aep == NULL) /* did ":syntax clear" */ |
| 7817 | attr = 0; |
| 7818 | else |
| 7819 | attr = aep->ae_attr; |
| 7820 | } |
| 7821 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7822 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7823 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 7824 | && cterm_normal_fg_bold) |
| 7825 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7826 | * has a FG color defined, clear BOLD. */ |
| 7827 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7828 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7829 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7830 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7831 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7832 | out_str(T_US); |
| 7833 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7834 | out_str(T_CZH); |
| 7835 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7836 | out_str(T_MR); |
| 7837 | |
| 7838 | /* |
| 7839 | * Output the color or start string after bold etc., in case the |
| 7840 | * bold etc. override the color setting. |
| 7841 | */ |
| 7842 | if (aep != NULL) |
| 7843 | { |
| 7844 | if (t_colors > 1) |
| 7845 | { |
| 7846 | if (aep->ae_u.cterm.fg_color) |
| 7847 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7848 | if (aep->ae_u.cterm.bg_color) |
| 7849 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7850 | } |
| 7851 | else |
| 7852 | { |
| 7853 | if (aep->ae_u.term.start != NULL) |
| 7854 | out_str(aep->ae_u.term.start); |
| 7855 | } |
| 7856 | } |
| 7857 | } |
| 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7862 | screen_stop_highlight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7863 | { |
| 7864 | int do_ME = FALSE; /* output T_ME code */ |
| 7865 | |
| 7866 | if (screen_attr != 0 |
| 7867 | #ifdef WIN3264 |
| 7868 | && termcap_active |
| 7869 | #endif |
| 7870 | ) |
| 7871 | { |
| 7872 | #ifdef FEAT_GUI |
| 7873 | if (gui.in_use) |
| 7874 | { |
| 7875 | char buf[20]; |
| 7876 | |
| 7877 | /* use internal GUI code */ |
| 7878 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7879 | OUT_STR(buf); |
| 7880 | } |
| 7881 | else |
| 7882 | #endif |
| 7883 | { |
| 7884 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7885 | { |
| 7886 | attrentry_T *aep; |
| 7887 | |
| 7888 | if (t_colors > 1) |
| 7889 | { |
| 7890 | /* |
| 7891 | * Assume that t_me restores the original colors! |
| 7892 | */ |
| 7893 | aep = syn_cterm_attr2entry(screen_attr); |
| 7894 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 7895 | || aep->ae_u.cterm.bg_color)) |
| 7896 | do_ME = TRUE; |
| 7897 | } |
| 7898 | else |
| 7899 | { |
| 7900 | aep = syn_term_attr2entry(screen_attr); |
| 7901 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7902 | { |
| 7903 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7904 | do_ME = TRUE; |
| 7905 | else |
| 7906 | out_str(aep->ae_u.term.stop); |
| 7907 | } |
| 7908 | } |
| 7909 | if (aep == NULL) /* did ":syntax clear" */ |
| 7910 | screen_attr = 0; |
| 7911 | else |
| 7912 | screen_attr = aep->ae_attr; |
| 7913 | } |
| 7914 | |
| 7915 | /* |
| 7916 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7917 | * same sequence several times. |
| 7918 | */ |
| 7919 | if (screen_attr & HL_STANDOUT) |
| 7920 | { |
| 7921 | if (STRCMP(T_SE, T_ME) == 0) |
| 7922 | do_ME = TRUE; |
| 7923 | else |
| 7924 | out_str(T_SE); |
| 7925 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7926 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7927 | { |
| 7928 | if (STRCMP(T_UE, T_ME) == 0) |
| 7929 | do_ME = TRUE; |
| 7930 | else |
| 7931 | out_str(T_UE); |
| 7932 | } |
| 7933 | if (screen_attr & HL_ITALIC) |
| 7934 | { |
| 7935 | if (STRCMP(T_CZR, T_ME) == 0) |
| 7936 | do_ME = TRUE; |
| 7937 | else |
| 7938 | out_str(T_CZR); |
| 7939 | } |
| 7940 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 7941 | out_str(T_ME); |
| 7942 | |
| 7943 | if (t_colors > 1) |
| 7944 | { |
| 7945 | /* set Normal cterm colors */ |
| 7946 | if (cterm_normal_fg_color != 0) |
| 7947 | term_fg_color(cterm_normal_fg_color - 1); |
| 7948 | if (cterm_normal_bg_color != 0) |
| 7949 | term_bg_color(cterm_normal_bg_color - 1); |
| 7950 | if (cterm_normal_fg_bold) |
| 7951 | out_str(T_MD); |
| 7952 | } |
| 7953 | } |
| 7954 | } |
| 7955 | screen_attr = 0; |
| 7956 | } |
| 7957 | |
| 7958 | /* |
| 7959 | * Reset the colors for a cterm. Used when leaving Vim. |
| 7960 | * The machine specific code may override this again. |
| 7961 | */ |
| 7962 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7963 | reset_cterm_colors(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7964 | { |
| 7965 | if (t_colors > 1) |
| 7966 | { |
| 7967 | /* set Normal cterm colors */ |
| 7968 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 7969 | { |
| 7970 | out_str(T_OP); |
| 7971 | screen_attr = -1; |
| 7972 | } |
| 7973 | if (cterm_normal_fg_bold) |
| 7974 | { |
| 7975 | out_str(T_ME); |
| 7976 | screen_attr = -1; |
| 7977 | } |
| 7978 | } |
| 7979 | } |
| 7980 | |
| 7981 | /* |
| 7982 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 7983 | * using the attributes from ScreenAttrs["off"]. |
| 7984 | */ |
| 7985 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7986 | screen_char(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7987 | { |
| 7988 | int attr; |
| 7989 | |
| 7990 | /* Check for illegal values, just in case (could happen just after |
| 7991 | * resizing). */ |
| 7992 | if (row >= screen_Rows || col >= screen_Columns) |
| 7993 | return; |
| 7994 | |
Bram Moolenaar | 494838a | 2015-02-10 19:20:37 +0100 | [diff] [blame] | 7995 | /* Outputting a character in the last cell on the screen may scroll the |
| 7996 | * screen up. Only do it when the "xn" termcap property is set, otherwise |
| 7997 | * mark the character invalid (update it when scrolled up). */ |
| 7998 | if (*T_XN == NUL |
| 7999 | && row == screen_Rows - 1 && col == screen_Columns - 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8000 | #ifdef FEAT_RIGHTLEFT |
| 8001 | /* account for first command-line character in rightleft mode */ |
| 8002 | && !cmdmsg_rl |
| 8003 | #endif |
| 8004 | ) |
| 8005 | { |
| 8006 | ScreenAttrs[off] = (sattr_T)-1; |
| 8007 | return; |
| 8008 | } |
| 8009 | |
| 8010 | /* |
| 8011 | * Stop highlighting first, so it's easier to move the cursor. |
| 8012 | */ |
| 8013 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 8014 | if (screen_char_attr != 0) |
| 8015 | attr = screen_char_attr; |
| 8016 | else |
| 8017 | #endif |
| 8018 | attr = ScreenAttrs[off]; |
| 8019 | if (screen_attr != attr) |
| 8020 | screen_stop_highlight(); |
| 8021 | |
| 8022 | windgoto(row, col); |
| 8023 | |
| 8024 | if (screen_attr != attr) |
| 8025 | screen_start_highlight(attr); |
| 8026 | |
| 8027 | #ifdef FEAT_MBYTE |
| 8028 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 8029 | { |
| 8030 | char_u buf[MB_MAXBYTES + 1]; |
| 8031 | |
| 8032 | /* Convert UTF-8 character to bytes and write it. */ |
| 8033 | |
| 8034 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 8035 | |
| 8036 | out_str(buf); |
| 8037 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 8038 | ++screen_cur_col; |
| 8039 | } |
| 8040 | else |
| 8041 | #endif |
| 8042 | { |
| 8043 | #ifdef FEAT_MBYTE |
| 8044 | out_flush_check(); |
| 8045 | #endif |
| 8046 | out_char(ScreenLines[off]); |
| 8047 | #ifdef FEAT_MBYTE |
| 8048 | /* double-byte character in single-width cell */ |
| 8049 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 8050 | out_char(ScreenLines2[off]); |
| 8051 | #endif |
| 8052 | } |
| 8053 | |
| 8054 | screen_cur_col++; |
| 8055 | } |
| 8056 | |
| 8057 | #ifdef FEAT_MBYTE |
| 8058 | |
| 8059 | /* |
| 8060 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 8061 | * on the screen at position 'row' and 'col'. |
| 8062 | * The attributes of the first byte is used for all. This is required to |
| 8063 | * output the two bytes of a double-byte character with nothing in between. |
| 8064 | */ |
| 8065 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8066 | screen_char_2(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8067 | { |
| 8068 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 8069 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 8070 | return; |
| 8071 | |
| 8072 | /* Outputting the last character on the screen may scrollup the screen. |
| 8073 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 8074 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 8075 | { |
| 8076 | ScreenAttrs[off] = (sattr_T)-1; |
| 8077 | return; |
| 8078 | } |
| 8079 | |
| 8080 | /* Output the first byte normally (positions the cursor), then write the |
| 8081 | * second byte directly. */ |
| 8082 | screen_char(off, row, col); |
| 8083 | out_char(ScreenLines[off + 1]); |
| 8084 | ++screen_cur_col; |
| 8085 | } |
| 8086 | #endif |
| 8087 | |
| 8088 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 8089 | /* |
| 8090 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 8091 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 8092 | */ |
| 8093 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8094 | screen_draw_rectangle( |
| 8095 | int row, |
| 8096 | int col, |
| 8097 | int height, |
| 8098 | int width, |
| 8099 | int invert) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8100 | { |
| 8101 | int r, c; |
| 8102 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8103 | #ifdef FEAT_MBYTE |
| 8104 | int max_off; |
| 8105 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8106 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8107 | /* Can't use ScreenLines unless initialized */ |
| 8108 | if (ScreenLines == NULL) |
| 8109 | return; |
| 8110 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8111 | if (invert) |
| 8112 | screen_char_attr = HL_INVERSE; |
| 8113 | for (r = row; r < row + height; ++r) |
| 8114 | { |
| 8115 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8116 | #ifdef FEAT_MBYTE |
| 8117 | max_off = off + screen_Columns; |
| 8118 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8119 | for (c = col; c < col + width; ++c) |
| 8120 | { |
| 8121 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8122 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8123 | { |
| 8124 | screen_char_2(off + c, r, c); |
| 8125 | ++c; |
| 8126 | } |
| 8127 | else |
| 8128 | #endif |
| 8129 | { |
| 8130 | screen_char(off + c, r, c); |
| 8131 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8132 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8133 | ++c; |
| 8134 | #endif |
| 8135 | } |
| 8136 | } |
| 8137 | } |
| 8138 | screen_char_attr = 0; |
| 8139 | } |
| 8140 | #endif |
| 8141 | |
| 8142 | #ifdef FEAT_VERTSPLIT |
| 8143 | /* |
| 8144 | * Redraw the characters for a vertically split window. |
| 8145 | */ |
| 8146 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8147 | redraw_block(int row, int end, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8148 | { |
| 8149 | int col; |
| 8150 | int width; |
| 8151 | |
| 8152 | # ifdef FEAT_CLIPBOARD |
| 8153 | clip_may_clear_selection(row, end - 1); |
| 8154 | # endif |
| 8155 | |
| 8156 | if (wp == NULL) |
| 8157 | { |
| 8158 | col = 0; |
| 8159 | width = Columns; |
| 8160 | } |
| 8161 | else |
| 8162 | { |
| 8163 | col = wp->w_wincol; |
| 8164 | width = wp->w_width; |
| 8165 | } |
| 8166 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 8167 | } |
| 8168 | #endif |
| 8169 | |
| 8170 | /* |
| 8171 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 8172 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 8173 | * Use attributes 'attr'. |
| 8174 | */ |
| 8175 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8176 | screen_fill( |
| 8177 | int start_row, |
| 8178 | int end_row, |
| 8179 | int start_col, |
| 8180 | int end_col, |
| 8181 | int c1, |
| 8182 | int c2, |
| 8183 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8184 | { |
| 8185 | int row; |
| 8186 | int col; |
| 8187 | int off; |
| 8188 | int end_off; |
| 8189 | int did_delete; |
| 8190 | int c; |
| 8191 | int norm_term; |
| 8192 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8193 | int force_next = FALSE; |
| 8194 | #endif |
| 8195 | |
| 8196 | if (end_row > screen_Rows) /* safety check */ |
| 8197 | end_row = screen_Rows; |
| 8198 | if (end_col > screen_Columns) /* safety check */ |
| 8199 | end_col = screen_Columns; |
| 8200 | if (ScreenLines == NULL |
| 8201 | || start_row >= end_row |
| 8202 | || start_col >= end_col) /* nothing to do */ |
| 8203 | return; |
| 8204 | |
| 8205 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 8206 | norm_term = ( |
| 8207 | #ifdef FEAT_GUI |
| 8208 | !gui.in_use && |
| 8209 | #endif |
| 8210 | t_colors <= 1); |
| 8211 | for (row = start_row; row < end_row; ++row) |
| 8212 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8213 | #ifdef FEAT_MBYTE |
| 8214 | if (has_mbyte |
| 8215 | # ifdef FEAT_GUI |
| 8216 | && !gui.in_use |
| 8217 | # endif |
| 8218 | ) |
| 8219 | { |
| 8220 | /* When drawing over the right halve of a double-wide char clear |
| 8221 | * out the left halve. When drawing over the left halve of a |
| 8222 | * double wide-char clear out the right halve. Only needed in a |
| 8223 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 8224 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8225 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 8226 | 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] | 8227 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8228 | } |
| 8229 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8230 | /* |
| 8231 | * Try to use delete-line termcap code, when no attributes or in a |
| 8232 | * "normal" terminal, where a bold/italic space is just a |
| 8233 | * space. |
| 8234 | */ |
| 8235 | did_delete = FALSE; |
| 8236 | if (c2 == ' ' |
| 8237 | && end_col == Columns |
| 8238 | && can_clear(T_CE) |
| 8239 | && (attr == 0 |
| 8240 | || (norm_term |
| 8241 | && attr <= HL_ALL |
| 8242 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 8243 | { |
| 8244 | /* |
| 8245 | * check if we really need to clear something |
| 8246 | */ |
| 8247 | col = start_col; |
| 8248 | if (c1 != ' ') /* don't clear first char */ |
| 8249 | ++col; |
| 8250 | |
| 8251 | off = LineOffset[row] + col; |
| 8252 | end_off = LineOffset[row] + end_col; |
| 8253 | |
| 8254 | /* skip blanks (used often, keep it fast!) */ |
| 8255 | #ifdef FEAT_MBYTE |
| 8256 | if (enc_utf8) |
| 8257 | while (off < end_off && ScreenLines[off] == ' ' |
| 8258 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 8259 | ++off; |
| 8260 | else |
| 8261 | #endif |
| 8262 | while (off < end_off && ScreenLines[off] == ' ' |
| 8263 | && ScreenAttrs[off] == 0) |
| 8264 | ++off; |
| 8265 | if (off < end_off) /* something to be cleared */ |
| 8266 | { |
| 8267 | col = off - LineOffset[row]; |
| 8268 | screen_stop_highlight(); |
| 8269 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 8270 | out_str(T_CE); |
| 8271 | screen_start(); /* don't know where cursor is now */ |
| 8272 | col = end_col - col; |
| 8273 | while (col--) /* clear chars in ScreenLines */ |
| 8274 | { |
| 8275 | ScreenLines[off] = ' '; |
| 8276 | #ifdef FEAT_MBYTE |
| 8277 | if (enc_utf8) |
| 8278 | ScreenLinesUC[off] = 0; |
| 8279 | #endif |
| 8280 | ScreenAttrs[off] = 0; |
| 8281 | ++off; |
| 8282 | } |
| 8283 | } |
| 8284 | did_delete = TRUE; /* the chars are cleared now */ |
| 8285 | } |
| 8286 | |
| 8287 | off = LineOffset[row] + start_col; |
| 8288 | c = c1; |
| 8289 | for (col = start_col; col < end_col; ++col) |
| 8290 | { |
| 8291 | if (ScreenLines[off] != c |
| 8292 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8293 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 8294 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8295 | #endif |
| 8296 | || ScreenAttrs[off] != attr |
| 8297 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8298 | || force_next |
| 8299 | #endif |
| 8300 | ) |
| 8301 | { |
| 8302 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8303 | /* The bold trick may make a single row of pixels appear in |
| 8304 | * the next character. When a bold character is removed, the |
| 8305 | * next character should be redrawn too. This happens for our |
| 8306 | * own GUI and for some xterms. */ |
| 8307 | if ( |
| 8308 | # ifdef FEAT_GUI |
| 8309 | gui.in_use |
| 8310 | # endif |
| 8311 | # if defined(FEAT_GUI) && defined(UNIX) |
| 8312 | || |
| 8313 | # endif |
| 8314 | # ifdef UNIX |
| 8315 | term_is_xterm |
| 8316 | # endif |
| 8317 | ) |
| 8318 | { |
| 8319 | if (ScreenLines[off] != ' ' |
| 8320 | && (ScreenAttrs[off] > HL_ALL |
| 8321 | || ScreenAttrs[off] & HL_BOLD)) |
| 8322 | force_next = TRUE; |
| 8323 | else |
| 8324 | force_next = FALSE; |
| 8325 | } |
| 8326 | #endif |
| 8327 | ScreenLines[off] = c; |
| 8328 | #ifdef FEAT_MBYTE |
| 8329 | if (enc_utf8) |
| 8330 | { |
| 8331 | if (c >= 0x80) |
| 8332 | { |
| 8333 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8334 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8335 | } |
| 8336 | else |
| 8337 | ScreenLinesUC[off] = 0; |
| 8338 | } |
| 8339 | #endif |
| 8340 | ScreenAttrs[off] = attr; |
| 8341 | if (!did_delete || c != ' ') |
| 8342 | screen_char(off, row, col); |
| 8343 | } |
| 8344 | ++off; |
| 8345 | if (col == start_col) |
| 8346 | { |
| 8347 | if (did_delete) |
| 8348 | break; |
| 8349 | c = c2; |
| 8350 | } |
| 8351 | } |
| 8352 | if (end_col == Columns) |
| 8353 | LineWraps[row] = FALSE; |
| 8354 | if (row == Rows - 1) /* overwritten the command line */ |
| 8355 | { |
| 8356 | redraw_cmdline = TRUE; |
| 8357 | if (c1 == ' ' && c2 == ' ') |
| 8358 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8359 | if (start_col == 0) |
| 8360 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8361 | } |
| 8362 | } |
| 8363 | } |
| 8364 | |
| 8365 | /* |
| 8366 | * Check if there should be a delay. Used before clearing or redrawing the |
| 8367 | * screen or the command line. |
| 8368 | */ |
| 8369 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8370 | check_for_delay(int check_msg_scroll) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8371 | { |
| 8372 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 8373 | && !did_wait_return |
| 8374 | && emsg_silent == 0) |
| 8375 | { |
| 8376 | out_flush(); |
| 8377 | ui_delay(1000L, TRUE); |
| 8378 | emsg_on_display = FALSE; |
| 8379 | if (check_msg_scroll) |
| 8380 | msg_scroll = FALSE; |
| 8381 | } |
| 8382 | } |
| 8383 | |
| 8384 | /* |
| 8385 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8386 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8387 | * Returns TRUE if there is a valid screen to write to. |
| 8388 | * Returns FALSE when starting up and screen not initialized yet. |
| 8389 | */ |
| 8390 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8391 | screen_valid(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8392 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8393 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8394 | return (ScreenLines != NULL); |
| 8395 | } |
| 8396 | |
| 8397 | /* |
| 8398 | * Resize the shell to Rows and Columns. |
| 8399 | * Allocate ScreenLines[] and associated items. |
| 8400 | * |
| 8401 | * There may be some time between setting Rows and Columns and (re)allocating |
| 8402 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 8403 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 8404 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 8405 | * final size of the shell is needed. |
| 8406 | */ |
| 8407 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8408 | screenalloc(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8409 | { |
| 8410 | int new_row, old_row; |
| 8411 | #ifdef FEAT_GUI |
| 8412 | int old_Rows; |
| 8413 | #endif |
| 8414 | win_T *wp; |
| 8415 | int outofmem = FALSE; |
| 8416 | int len; |
| 8417 | schar_T *new_ScreenLines; |
| 8418 | #ifdef FEAT_MBYTE |
| 8419 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8420 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8421 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8422 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8423 | #endif |
| 8424 | sattr_T *new_ScreenAttrs; |
| 8425 | unsigned *new_LineOffset; |
| 8426 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8427 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8428 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8429 | tabpage_T *tp; |
| 8430 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8431 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8432 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8433 | #ifdef FEAT_AUTOCMD |
| 8434 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8435 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8436 | retry: |
| 8437 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8438 | /* |
| 8439 | * Allocation of the screen buffers is done only when the size changes and |
| 8440 | * when Rows and Columns have been set and we have started doing full |
| 8441 | * screen stuff. |
| 8442 | */ |
| 8443 | if ((ScreenLines != NULL |
| 8444 | && Rows == screen_Rows |
| 8445 | && Columns == screen_Columns |
| 8446 | #ifdef FEAT_MBYTE |
| 8447 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 8448 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8449 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8450 | #endif |
| 8451 | ) |
| 8452 | || Rows == 0 |
| 8453 | || Columns == 0 |
| 8454 | || (!full_screen && ScreenLines == NULL)) |
| 8455 | return; |
| 8456 | |
| 8457 | /* |
| 8458 | * It's possible that we produce an out-of-memory message below, which |
| 8459 | * will cause this function to be called again. To break the loop, just |
| 8460 | * return here. |
| 8461 | */ |
| 8462 | if (entered) |
| 8463 | return; |
| 8464 | entered = TRUE; |
| 8465 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8466 | /* |
| 8467 | * Note that the window sizes are updated before reallocating the arrays, |
| 8468 | * thus we must not redraw here! |
| 8469 | */ |
| 8470 | ++RedrawingDisabled; |
| 8471 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8472 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8473 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8474 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8475 | |
| 8476 | /* |
| 8477 | * We're changing the size of the screen. |
| 8478 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8479 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8480 | * lines (unless the screen is going to be cleared). |
| 8481 | * - Free the old arrays. |
| 8482 | * |
| 8483 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8484 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8485 | * size is wrong. |
| 8486 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8487 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8488 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8489 | #ifdef FEAT_AUTOCMD |
| 8490 | if (aucmd_win != NULL) |
| 8491 | win_free_lsize(aucmd_win); |
| 8492 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8493 | |
| 8494 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8495 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8496 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8497 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8498 | if (enc_utf8) |
| 8499 | { |
| 8500 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8501 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8502 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8503 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8504 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8505 | } |
| 8506 | if (enc_dbcs == DBCS_JPNU) |
| 8507 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8508 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8509 | #endif |
| 8510 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8511 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8512 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8513 | Rows * sizeof(unsigned)), FALSE); |
| 8514 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8515 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8516 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8517 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8518 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8519 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8520 | { |
| 8521 | if (win_alloc_lines(wp) == FAIL) |
| 8522 | { |
| 8523 | outofmem = TRUE; |
| 8524 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8525 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8526 | #endif |
| 8527 | } |
| 8528 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8529 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8530 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8531 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8532 | outofmem = TRUE; |
| 8533 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8534 | #ifdef FEAT_WINDOWS |
| 8535 | give_up: |
| 8536 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8537 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8538 | #ifdef FEAT_MBYTE |
| 8539 | for (i = 0; i < p_mco; ++i) |
| 8540 | if (new_ScreenLinesC[i] == NULL) |
| 8541 | break; |
| 8542 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8543 | if (new_ScreenLines == NULL |
| 8544 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8545 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8546 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8547 | #endif |
| 8548 | || new_ScreenAttrs == NULL |
| 8549 | || new_LineOffset == NULL |
| 8550 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8551 | #ifdef FEAT_WINDOWS |
| 8552 | || new_TabPageIdxs == NULL |
| 8553 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8554 | || outofmem) |
| 8555 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8556 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8557 | { |
| 8558 | /* guess the size */ |
| 8559 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8560 | |
| 8561 | /* Remember we did this to avoid getting outofmem messages over |
| 8562 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8563 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8564 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8565 | vim_free(new_ScreenLines); |
| 8566 | new_ScreenLines = NULL; |
| 8567 | #ifdef FEAT_MBYTE |
| 8568 | vim_free(new_ScreenLinesUC); |
| 8569 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8570 | for (i = 0; i < p_mco; ++i) |
| 8571 | { |
| 8572 | vim_free(new_ScreenLinesC[i]); |
| 8573 | new_ScreenLinesC[i] = NULL; |
| 8574 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8575 | vim_free(new_ScreenLines2); |
| 8576 | new_ScreenLines2 = NULL; |
| 8577 | #endif |
| 8578 | vim_free(new_ScreenAttrs); |
| 8579 | new_ScreenAttrs = NULL; |
| 8580 | vim_free(new_LineOffset); |
| 8581 | new_LineOffset = NULL; |
| 8582 | vim_free(new_LineWraps); |
| 8583 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8584 | #ifdef FEAT_WINDOWS |
| 8585 | vim_free(new_TabPageIdxs); |
| 8586 | new_TabPageIdxs = NULL; |
| 8587 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8588 | } |
| 8589 | else |
| 8590 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8591 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8592 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8593 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8594 | { |
| 8595 | new_LineOffset[new_row] = new_row * Columns; |
| 8596 | new_LineWraps[new_row] = FALSE; |
| 8597 | |
| 8598 | /* |
| 8599 | * If the screen is not going to be cleared, copy as much as |
| 8600 | * possible from the old screen to the new one and clear the rest |
| 8601 | * (used when resizing the window at the "--more--" prompt or when |
| 8602 | * executing an external command, for the GUI). |
| 8603 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8604 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8605 | { |
| 8606 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8607 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8608 | #ifdef FEAT_MBYTE |
| 8609 | if (enc_utf8) |
| 8610 | { |
| 8611 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8612 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8613 | for (i = 0; i < p_mco; ++i) |
| 8614 | (void)vim_memset(new_ScreenLinesC[i] |
| 8615 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8616 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8617 | } |
| 8618 | if (enc_dbcs == DBCS_JPNU) |
| 8619 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8620 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8621 | #endif |
| 8622 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8623 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8624 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8625 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8626 | { |
| 8627 | if (screen_Columns < Columns) |
| 8628 | len = screen_Columns; |
| 8629 | else |
| 8630 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8631 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8632 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8633 | * may be invalid now. Also when p_mco changes. */ |
| 8634 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8635 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8636 | #endif |
| 8637 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8638 | ScreenLines + LineOffset[old_row], |
| 8639 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8640 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8641 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8642 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8643 | { |
| 8644 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8645 | ScreenLinesUC + LineOffset[old_row], |
| 8646 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8647 | for (i = 0; i < p_mco; ++i) |
| 8648 | mch_memmove(new_ScreenLinesC[i] |
| 8649 | + new_LineOffset[new_row], |
| 8650 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8651 | (size_t)len * sizeof(u8char_T)); |
| 8652 | } |
| 8653 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8654 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8655 | ScreenLines2 + LineOffset[old_row], |
| 8656 | (size_t)len * sizeof(schar_T)); |
| 8657 | #endif |
| 8658 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8659 | ScreenAttrs + LineOffset[old_row], |
| 8660 | (size_t)len * sizeof(sattr_T)); |
| 8661 | } |
| 8662 | } |
| 8663 | } |
| 8664 | /* Use the last line of the screen for the current line. */ |
| 8665 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8666 | } |
| 8667 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8668 | free_screenlines(); |
| 8669 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8670 | ScreenLines = new_ScreenLines; |
| 8671 | #ifdef FEAT_MBYTE |
| 8672 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8673 | for (i = 0; i < p_mco; ++i) |
| 8674 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8675 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8676 | ScreenLines2 = new_ScreenLines2; |
| 8677 | #endif |
| 8678 | ScreenAttrs = new_ScreenAttrs; |
| 8679 | LineOffset = new_LineOffset; |
| 8680 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8681 | #ifdef FEAT_WINDOWS |
| 8682 | TabPageIdxs = new_TabPageIdxs; |
| 8683 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8684 | |
| 8685 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8686 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8687 | #ifdef FEAT_GUI |
| 8688 | old_Rows = screen_Rows; |
| 8689 | #endif |
| 8690 | screen_Rows = Rows; |
| 8691 | screen_Columns = Columns; |
| 8692 | |
| 8693 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8694 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8695 | screenclear2(); |
| 8696 | |
| 8697 | #ifdef FEAT_GUI |
| 8698 | else if (gui.in_use |
| 8699 | && !gui.starting |
| 8700 | && ScreenLines != NULL |
| 8701 | && old_Rows != Rows) |
| 8702 | { |
| 8703 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8704 | /* |
| 8705 | * Adjust the position of the cursor, for when executing an external |
| 8706 | * command. |
| 8707 | */ |
| 8708 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8709 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8710 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8711 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8712 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8713 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8714 | } |
| 8715 | #endif |
| 8716 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8717 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8718 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8719 | |
| 8720 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8721 | /* |
| 8722 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8723 | * in case applying autocommands always changes Rows or Columns. |
| 8724 | */ |
| 8725 | if (starting == 0 && ++retry_count <= 3) |
| 8726 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8727 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8728 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8729 | * jump back to check if we need to allocate the screen again. */ |
| 8730 | goto retry; |
| 8731 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8732 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8733 | } |
| 8734 | |
| 8735 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8736 | free_screenlines(void) |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8737 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8738 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8739 | int i; |
| 8740 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8741 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8742 | for (i = 0; i < Screen_mco; ++i) |
| 8743 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8744 | vim_free(ScreenLines2); |
| 8745 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8746 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8747 | vim_free(ScreenAttrs); |
| 8748 | vim_free(LineOffset); |
| 8749 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8750 | #ifdef FEAT_WINDOWS |
| 8751 | vim_free(TabPageIdxs); |
| 8752 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8753 | } |
| 8754 | |
| 8755 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8756 | screenclear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8757 | { |
| 8758 | check_for_delay(FALSE); |
| 8759 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8760 | screenclear2(); /* clear the screen */ |
| 8761 | } |
| 8762 | |
| 8763 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8764 | screenclear2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8765 | { |
| 8766 | int i; |
| 8767 | |
| 8768 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8769 | #ifdef FEAT_GUI |
| 8770 | || (gui.in_use && gui.starting) |
| 8771 | #endif |
| 8772 | ) |
| 8773 | return; |
| 8774 | |
| 8775 | #ifdef FEAT_GUI |
| 8776 | if (!gui.in_use) |
| 8777 | #endif |
| 8778 | screen_attr = -1; /* force setting the Normal colors */ |
| 8779 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8780 | |
| 8781 | #ifdef FEAT_CLIPBOARD |
| 8782 | /* disable selection without redrawing it */ |
| 8783 | clip_scroll_selection(9999); |
| 8784 | #endif |
| 8785 | |
| 8786 | /* blank out ScreenLines */ |
| 8787 | for (i = 0; i < Rows; ++i) |
| 8788 | { |
| 8789 | lineclear(LineOffset[i], (int)Columns); |
| 8790 | LineWraps[i] = FALSE; |
| 8791 | } |
| 8792 | |
| 8793 | if (can_clear(T_CL)) |
| 8794 | { |
| 8795 | out_str(T_CL); /* clear the display */ |
| 8796 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8797 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8798 | } |
| 8799 | else |
| 8800 | { |
| 8801 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8802 | for (i = 0; i < Rows; ++i) |
| 8803 | lineinvalid(LineOffset[i], (int)Columns); |
| 8804 | clear_cmdline = TRUE; |
| 8805 | } |
| 8806 | |
| 8807 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8808 | |
| 8809 | win_rest_invalid(firstwin); |
| 8810 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8811 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8812 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8813 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8814 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8815 | must_redraw = NOT_VALID; |
| 8816 | compute_cmdrow(); |
| 8817 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8818 | msg_col = 0; |
| 8819 | screen_start(); /* don't know where cursor is now */ |
| 8820 | msg_scrolled = 0; /* can't scroll back */ |
| 8821 | msg_didany = FALSE; |
| 8822 | msg_didout = FALSE; |
| 8823 | } |
| 8824 | |
| 8825 | /* |
| 8826 | * Clear one line in ScreenLines. |
| 8827 | */ |
| 8828 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8829 | lineclear(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8830 | { |
| 8831 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8832 | #ifdef FEAT_MBYTE |
| 8833 | if (enc_utf8) |
| 8834 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8835 | (size_t)width * sizeof(u8char_T)); |
| 8836 | #endif |
| 8837 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8838 | } |
| 8839 | |
| 8840 | /* |
| 8841 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8842 | * invalid value. |
| 8843 | */ |
| 8844 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8845 | lineinvalid(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8846 | { |
| 8847 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8848 | } |
| 8849 | |
| 8850 | #ifdef FEAT_VERTSPLIT |
| 8851 | /* |
| 8852 | * Copy part of a Screenline for vertically split window "wp". |
| 8853 | */ |
| 8854 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8855 | linecopy(int to, int from, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8856 | { |
| 8857 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8858 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8859 | |
| 8860 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8861 | wp->w_width * sizeof(schar_T)); |
| 8862 | # ifdef FEAT_MBYTE |
| 8863 | if (enc_utf8) |
| 8864 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8865 | int i; |
| 8866 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8867 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8868 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8869 | for (i = 0; i < p_mco; ++i) |
| 8870 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8871 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8872 | } |
| 8873 | if (enc_dbcs == DBCS_JPNU) |
| 8874 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8875 | wp->w_width * sizeof(schar_T)); |
| 8876 | # endif |
| 8877 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8878 | wp->w_width * sizeof(sattr_T)); |
| 8879 | } |
| 8880 | #endif |
| 8881 | |
| 8882 | /* |
| 8883 | * Return TRUE if clearing with term string "p" would work. |
| 8884 | * It can't work when the string is empty or it won't set the right background. |
| 8885 | */ |
| 8886 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8887 | can_clear(char_u *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8888 | { |
| 8889 | return (*p != NUL && (t_colors <= 1 |
| 8890 | #ifdef FEAT_GUI |
| 8891 | || gui.in_use |
| 8892 | #endif |
| 8893 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 8894 | } |
| 8895 | |
| 8896 | /* |
| 8897 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8898 | * something directly to the screen (shell commands) or a terminal control |
| 8899 | * code. |
| 8900 | */ |
| 8901 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8902 | screen_start(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8903 | { |
| 8904 | screen_cur_row = screen_cur_col = 9999; |
| 8905 | } |
| 8906 | |
| 8907 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8908 | * Move the cursor to position "row","col" in the screen. |
| 8909 | * This tries to find the most efficient way to move, minimizing the number of |
| 8910 | * characters sent to the terminal. |
| 8911 | */ |
| 8912 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8913 | windgoto(int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8914 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8915 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8916 | int i; |
| 8917 | int plan; |
| 8918 | int cost; |
| 8919 | int wouldbe_col; |
| 8920 | int noinvcurs; |
| 8921 | char_u *bs; |
| 8922 | int goto_cost; |
| 8923 | int attr; |
| 8924 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8925 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8926 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 8927 | |
| 8928 | #define PLAN_LE 1 |
| 8929 | #define PLAN_CR 2 |
| 8930 | #define PLAN_NL 3 |
| 8931 | #define PLAN_WRITE 4 |
| 8932 | /* Can't use ScreenLines unless initialized */ |
| 8933 | if (ScreenLines == NULL) |
| 8934 | return; |
| 8935 | |
| 8936 | if (col != screen_cur_col || row != screen_cur_row) |
| 8937 | { |
| 8938 | /* Check for valid position. */ |
| 8939 | if (row < 0) /* window without text lines? */ |
| 8940 | row = 0; |
| 8941 | if (row >= screen_Rows) |
| 8942 | row = screen_Rows - 1; |
| 8943 | if (col >= screen_Columns) |
| 8944 | col = screen_Columns - 1; |
| 8945 | |
| 8946 | /* check if no cursor movement is allowed in highlight mode */ |
| 8947 | if (screen_attr && *T_MS == NUL) |
| 8948 | noinvcurs = HIGHL_COST; |
| 8949 | else |
| 8950 | noinvcurs = 0; |
| 8951 | goto_cost = GOTO_COST + noinvcurs; |
| 8952 | |
| 8953 | /* |
| 8954 | * Plan how to do the positioning: |
| 8955 | * 1. Use CR to move it to column 0, same row. |
| 8956 | * 2. Use T_LE to move it a few columns to the left. |
| 8957 | * 3. Use NL to move a few lines down, column 0. |
| 8958 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 8959 | * |
| 8960 | * Don't do this if the cursor went beyond the last column, the cursor |
| 8961 | * position is unknown then (some terminals wrap, some don't ) |
| 8962 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8963 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8964 | * characters to move the cursor to the right. |
| 8965 | */ |
| 8966 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 8967 | { |
| 8968 | /* |
| 8969 | * If the cursor is in the same row, bigger col, we can use CR |
| 8970 | * or T_LE. |
| 8971 | */ |
| 8972 | bs = NULL; /* init for GCC */ |
| 8973 | attr = screen_attr; |
| 8974 | if (row == screen_cur_row && col < screen_cur_col) |
| 8975 | { |
| 8976 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 8977 | if (*T_LE) |
| 8978 | bs = T_LE; /* "cursor left" */ |
| 8979 | else |
| 8980 | bs = T_BC; /* "backspace character (old) */ |
| 8981 | if (*bs) |
| 8982 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 8983 | else |
| 8984 | cost = 999; |
| 8985 | if (col + 1 < cost) /* using CR is less characters */ |
| 8986 | { |
| 8987 | plan = PLAN_CR; |
| 8988 | wouldbe_col = 0; |
| 8989 | cost = 1; /* CR is just one character */ |
| 8990 | } |
| 8991 | else |
| 8992 | { |
| 8993 | plan = PLAN_LE; |
| 8994 | wouldbe_col = col; |
| 8995 | } |
| 8996 | if (noinvcurs) /* will stop highlighting */ |
| 8997 | { |
| 8998 | cost += noinvcurs; |
| 8999 | attr = 0; |
| 9000 | } |
| 9001 | } |
| 9002 | |
| 9003 | /* |
| 9004 | * If the cursor is above where we want to be, we can use CR LF. |
| 9005 | */ |
| 9006 | else if (row > screen_cur_row) |
| 9007 | { |
| 9008 | plan = PLAN_NL; |
| 9009 | wouldbe_col = 0; |
| 9010 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 9011 | if (noinvcurs) /* will stop highlighting */ |
| 9012 | { |
| 9013 | cost += noinvcurs; |
| 9014 | attr = 0; |
| 9015 | } |
| 9016 | } |
| 9017 | |
| 9018 | /* |
| 9019 | * If the cursor is in the same row, smaller col, just use write. |
| 9020 | */ |
| 9021 | else |
| 9022 | { |
| 9023 | plan = PLAN_WRITE; |
| 9024 | wouldbe_col = screen_cur_col; |
| 9025 | cost = 0; |
| 9026 | } |
| 9027 | |
| 9028 | /* |
| 9029 | * Check if any characters that need to be written have the |
| 9030 | * correct attributes. Also avoid UTF-8 characters. |
| 9031 | */ |
| 9032 | i = col - wouldbe_col; |
| 9033 | if (i > 0) |
| 9034 | cost += i; |
| 9035 | if (cost < goto_cost && i > 0) |
| 9036 | { |
| 9037 | /* |
| 9038 | * Check if the attributes are correct without additionally |
| 9039 | * stopping highlighting. |
| 9040 | */ |
| 9041 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 9042 | while (i && *p++ == attr) |
| 9043 | --i; |
| 9044 | if (i != 0) |
| 9045 | { |
| 9046 | /* |
| 9047 | * Try if it works when highlighting is stopped here. |
| 9048 | */ |
| 9049 | if (*--p == 0) |
| 9050 | { |
| 9051 | cost += noinvcurs; |
| 9052 | while (i && *p++ == 0) |
| 9053 | --i; |
| 9054 | } |
| 9055 | if (i != 0) |
| 9056 | cost = 999; /* different attributes, don't do it */ |
| 9057 | } |
| 9058 | #ifdef FEAT_MBYTE |
| 9059 | if (enc_utf8) |
| 9060 | { |
| 9061 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 9062 | for (i = wouldbe_col; i < col; ++i) |
| 9063 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 9064 | { |
| 9065 | cost = 999; |
| 9066 | break; |
| 9067 | } |
| 9068 | } |
| 9069 | #endif |
| 9070 | } |
| 9071 | |
| 9072 | /* |
| 9073 | * We can do it without term_windgoto()! |
| 9074 | */ |
| 9075 | if (cost < goto_cost) |
| 9076 | { |
| 9077 | if (plan == PLAN_LE) |
| 9078 | { |
| 9079 | if (noinvcurs) |
| 9080 | screen_stop_highlight(); |
| 9081 | while (screen_cur_col > col) |
| 9082 | { |
| 9083 | out_str(bs); |
| 9084 | --screen_cur_col; |
| 9085 | } |
| 9086 | } |
| 9087 | else if (plan == PLAN_CR) |
| 9088 | { |
| 9089 | if (noinvcurs) |
| 9090 | screen_stop_highlight(); |
| 9091 | out_char('\r'); |
| 9092 | screen_cur_col = 0; |
| 9093 | } |
| 9094 | else if (plan == PLAN_NL) |
| 9095 | { |
| 9096 | if (noinvcurs) |
| 9097 | screen_stop_highlight(); |
| 9098 | while (screen_cur_row < row) |
| 9099 | { |
| 9100 | out_char('\n'); |
| 9101 | ++screen_cur_row; |
| 9102 | } |
| 9103 | screen_cur_col = 0; |
| 9104 | } |
| 9105 | |
| 9106 | i = col - screen_cur_col; |
| 9107 | if (i > 0) |
| 9108 | { |
| 9109 | /* |
| 9110 | * Use cursor-right if it's one character only. Avoids |
| 9111 | * removing a line of pixels from the last bold char, when |
| 9112 | * using the bold trick in the GUI. |
| 9113 | */ |
| 9114 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 9115 | { |
| 9116 | while (i-- > 0) |
| 9117 | out_char(*T_ND); |
| 9118 | } |
| 9119 | else |
| 9120 | { |
| 9121 | int off; |
| 9122 | |
| 9123 | off = LineOffset[row] + screen_cur_col; |
| 9124 | while (i-- > 0) |
| 9125 | { |
| 9126 | if (ScreenAttrs[off] != screen_attr) |
| 9127 | screen_stop_highlight(); |
| 9128 | #ifdef FEAT_MBYTE |
| 9129 | out_flush_check(); |
| 9130 | #endif |
| 9131 | out_char(ScreenLines[off]); |
| 9132 | #ifdef FEAT_MBYTE |
| 9133 | if (enc_dbcs == DBCS_JPNU |
| 9134 | && ScreenLines[off] == 0x8e) |
| 9135 | out_char(ScreenLines2[off]); |
| 9136 | #endif |
| 9137 | ++off; |
| 9138 | } |
| 9139 | } |
| 9140 | } |
| 9141 | } |
| 9142 | } |
| 9143 | else |
| 9144 | cost = 999; |
| 9145 | |
| 9146 | if (cost >= goto_cost) |
| 9147 | { |
| 9148 | if (noinvcurs) |
| 9149 | screen_stop_highlight(); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 9150 | if (row == screen_cur_row && (col > screen_cur_col) |
| 9151 | && *T_CRI != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9152 | term_cursor_right(col - screen_cur_col); |
| 9153 | else |
| 9154 | term_windgoto(row, col); |
| 9155 | } |
| 9156 | screen_cur_row = row; |
| 9157 | screen_cur_col = col; |
| 9158 | } |
| 9159 | } |
| 9160 | |
| 9161 | /* |
| 9162 | * Set cursor to its position in the current window. |
| 9163 | */ |
| 9164 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9165 | setcursor(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9166 | { |
| 9167 | if (redrawing()) |
| 9168 | { |
| 9169 | validate_cursor(); |
| 9170 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 9171 | W_WINCOL(curwin) + ( |
| 9172 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9173 | /* With 'rightleft' set and the cursor on a double-wide |
| 9174 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9175 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 9176 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9177 | (has_mbyte |
| 9178 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 9179 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9180 | # endif |
| 9181 | 1)) : |
| 9182 | #endif |
| 9183 | curwin->w_wcol)); |
| 9184 | } |
| 9185 | } |
| 9186 | |
| 9187 | |
| 9188 | /* |
| 9189 | * insert 'line_count' lines at 'row' in window 'wp' |
| 9190 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 9191 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 9192 | * scrolling. |
| 9193 | * Returns FAIL if the lines are not inserted, OK for success. |
| 9194 | */ |
| 9195 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9196 | win_ins_lines( |
| 9197 | win_T *wp, |
| 9198 | int row, |
| 9199 | int line_count, |
| 9200 | int invalid, |
| 9201 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9202 | { |
| 9203 | int did_delete; |
| 9204 | int nextrow; |
| 9205 | int lastrow; |
| 9206 | int retval; |
| 9207 | |
| 9208 | if (invalid) |
| 9209 | wp->w_lines_valid = 0; |
| 9210 | |
| 9211 | if (wp->w_height < 5) |
| 9212 | return FAIL; |
| 9213 | |
| 9214 | if (line_count > wp->w_height - row) |
| 9215 | line_count = wp->w_height - row; |
| 9216 | |
| 9217 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 9218 | if (retval != MAYBE) |
| 9219 | return retval; |
| 9220 | |
| 9221 | /* |
| 9222 | * If there is a next window or a status line, we first try to delete the |
| 9223 | * lines at the bottom to avoid messing what is after the window. |
| 9224 | * If this fails and there are following windows, don't do anything to avoid |
| 9225 | * messing up those windows, better just redraw. |
| 9226 | */ |
| 9227 | did_delete = FALSE; |
| 9228 | #ifdef FEAT_WINDOWS |
| 9229 | if (wp->w_next != NULL || wp->w_status_height) |
| 9230 | { |
| 9231 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9232 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 9233 | did_delete = TRUE; |
| 9234 | else if (wp->w_next) |
| 9235 | return FAIL; |
| 9236 | } |
| 9237 | #endif |
| 9238 | /* |
| 9239 | * if no lines deleted, blank the lines that will end up below the window |
| 9240 | */ |
| 9241 | if (!did_delete) |
| 9242 | { |
| 9243 | #ifdef FEAT_WINDOWS |
| 9244 | wp->w_redr_status = TRUE; |
| 9245 | #endif |
| 9246 | redraw_cmdline = TRUE; |
| 9247 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 9248 | lastrow = nextrow + line_count; |
| 9249 | if (lastrow > Rows) |
| 9250 | lastrow = Rows; |
| 9251 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 9252 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9253 | ' ', ' ', 0); |
| 9254 | } |
| 9255 | |
| 9256 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 9257 | == FAIL) |
| 9258 | { |
| 9259 | /* deletion will have messed up other windows */ |
| 9260 | if (did_delete) |
| 9261 | { |
| 9262 | #ifdef FEAT_WINDOWS |
| 9263 | wp->w_redr_status = TRUE; |
| 9264 | #endif |
| 9265 | win_rest_invalid(W_NEXT(wp)); |
| 9266 | } |
| 9267 | return FAIL; |
| 9268 | } |
| 9269 | |
| 9270 | return OK; |
| 9271 | } |
| 9272 | |
| 9273 | /* |
| 9274 | * delete "line_count" window lines at "row" in window "wp" |
| 9275 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 9276 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 9277 | * scrolling |
| 9278 | * Return OK for success, FAIL if the lines are not deleted. |
| 9279 | */ |
| 9280 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9281 | win_del_lines( |
| 9282 | win_T *wp, |
| 9283 | int row, |
| 9284 | int line_count, |
| 9285 | int invalid, |
| 9286 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9287 | { |
| 9288 | int retval; |
| 9289 | |
| 9290 | if (invalid) |
| 9291 | wp->w_lines_valid = 0; |
| 9292 | |
| 9293 | if (line_count > wp->w_height - row) |
| 9294 | line_count = wp->w_height - row; |
| 9295 | |
| 9296 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 9297 | if (retval != MAYBE) |
| 9298 | return retval; |
| 9299 | |
| 9300 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 9301 | (int)Rows, FALSE, NULL) == FAIL) |
| 9302 | return FAIL; |
| 9303 | |
| 9304 | #ifdef FEAT_WINDOWS |
| 9305 | /* |
| 9306 | * If there are windows or status lines below, try to put them at the |
| 9307 | * correct place. If we can't do that, they have to be redrawn. |
| 9308 | */ |
| 9309 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 9310 | { |
| 9311 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9312 | line_count, (int)Rows, NULL) == FAIL) |
| 9313 | { |
| 9314 | wp->w_redr_status = TRUE; |
| 9315 | win_rest_invalid(wp->w_next); |
| 9316 | } |
| 9317 | } |
| 9318 | /* |
| 9319 | * If this is the last window and there is no status line, redraw the |
| 9320 | * command line later. |
| 9321 | */ |
| 9322 | else |
| 9323 | #endif |
| 9324 | redraw_cmdline = TRUE; |
| 9325 | return OK; |
| 9326 | } |
| 9327 | |
| 9328 | /* |
| 9329 | * Common code for win_ins_lines() and win_del_lines(). |
| 9330 | * Returns OK or FAIL when the work has been done. |
| 9331 | * Returns MAYBE when not finished yet. |
| 9332 | */ |
| 9333 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9334 | win_do_lines( |
| 9335 | win_T *wp, |
| 9336 | int row, |
| 9337 | int line_count, |
| 9338 | int mayclear, |
| 9339 | int del) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9340 | { |
| 9341 | int retval; |
| 9342 | |
| 9343 | if (!redrawing() || line_count <= 0) |
| 9344 | return FAIL; |
| 9345 | |
| 9346 | /* only a few lines left: redraw is faster */ |
| 9347 | if (mayclear && Rows - line_count < 5 |
| 9348 | #ifdef FEAT_VERTSPLIT |
| 9349 | && wp->w_width == Columns |
| 9350 | #endif |
| 9351 | ) |
| 9352 | { |
| 9353 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 9354 | return FAIL; |
| 9355 | } |
| 9356 | |
| 9357 | /* |
| 9358 | * Delete all remaining lines |
| 9359 | */ |
| 9360 | if (row + line_count >= wp->w_height) |
| 9361 | { |
| 9362 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 9363 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9364 | ' ', ' ', 0); |
| 9365 | return OK; |
| 9366 | } |
| 9367 | |
| 9368 | /* |
| 9369 | * when scrolling, the message on the command line should be cleared, |
| 9370 | * otherwise it will stay there forever. |
| 9371 | */ |
| 9372 | clear_cmdline = TRUE; |
| 9373 | |
| 9374 | /* |
| 9375 | * If the terminal can set a scroll region, use that. |
| 9376 | * Always do this in a vertically split window. This will redraw from |
| 9377 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 9378 | * win_line(). |
| 9379 | * 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] | 9380 | * a character in the lower right corner of the scroll region may cause a |
| 9381 | * scroll-up . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9382 | */ |
| 9383 | if (scroll_region |
| 9384 | #ifdef FEAT_VERTSPLIT |
| 9385 | || W_WIDTH(wp) != Columns |
| 9386 | #endif |
| 9387 | ) |
| 9388 | { |
| 9389 | #ifdef FEAT_VERTSPLIT |
| 9390 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9391 | #endif |
| 9392 | scroll_region_set(wp, row); |
| 9393 | if (del) |
| 9394 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 9395 | wp->w_height - row, FALSE, wp); |
| 9396 | else |
| 9397 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 9398 | wp->w_height - row, wp); |
| 9399 | #ifdef FEAT_VERTSPLIT |
| 9400 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9401 | #endif |
| 9402 | scroll_region_reset(); |
| 9403 | return retval; |
| 9404 | } |
| 9405 | |
| 9406 | #ifdef FEAT_WINDOWS |
| 9407 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 9408 | return FAIL; |
| 9409 | #endif |
| 9410 | |
| 9411 | return MAYBE; |
| 9412 | } |
| 9413 | |
| 9414 | /* |
| 9415 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 9416 | */ |
| 9417 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9418 | win_rest_invalid(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9419 | { |
| 9420 | #ifdef FEAT_WINDOWS |
| 9421 | while (wp != NULL) |
| 9422 | #else |
| 9423 | if (wp != NULL) |
| 9424 | #endif |
| 9425 | { |
| 9426 | redraw_win_later(wp, NOT_VALID); |
| 9427 | #ifdef FEAT_WINDOWS |
| 9428 | wp->w_redr_status = TRUE; |
| 9429 | wp = wp->w_next; |
| 9430 | #endif |
| 9431 | } |
| 9432 | redraw_cmdline = TRUE; |
| 9433 | } |
| 9434 | |
| 9435 | /* |
| 9436 | * The rest of the routines in this file perform screen manipulations. The |
| 9437 | * given operation is performed physically on the screen. The corresponding |
| 9438 | * change is also made to the internal screen image. In this way, the editor |
| 9439 | * anticipates the effect of editing changes on the appearance of the screen. |
| 9440 | * That way, when we call screenupdate a complete redraw isn't usually |
| 9441 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 9442 | * screen changes, and in the meantime, everything still works. |
| 9443 | */ |
| 9444 | |
| 9445 | /* |
| 9446 | * types for inserting or deleting lines |
| 9447 | */ |
| 9448 | #define USE_T_CAL 1 |
| 9449 | #define USE_T_CDL 2 |
| 9450 | #define USE_T_AL 3 |
| 9451 | #define USE_T_CE 4 |
| 9452 | #define USE_T_DL 5 |
| 9453 | #define USE_T_SR 6 |
| 9454 | #define USE_NL 7 |
| 9455 | #define USE_T_CD 8 |
| 9456 | #define USE_REDRAW 9 |
| 9457 | |
| 9458 | /* |
| 9459 | * insert lines on the screen and update ScreenLines[] |
| 9460 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9461 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9462 | * 'row' and 'end' are relative to the start of the region. |
| 9463 | * |
| 9464 | * return FAIL for failure, OK for success. |
| 9465 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9466 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9467 | screen_ins_lines( |
| 9468 | int off, |
| 9469 | int row, |
| 9470 | int line_count, |
| 9471 | int end, |
| 9472 | win_T *wp) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9473 | { |
| 9474 | int i; |
| 9475 | int j; |
| 9476 | unsigned temp; |
| 9477 | int cursor_row; |
| 9478 | int type; |
| 9479 | int result_empty; |
| 9480 | int can_ce = can_clear(T_CE); |
| 9481 | |
| 9482 | /* |
| 9483 | * FAIL if |
| 9484 | * - there is no valid screen |
| 9485 | * - the screen has to be redrawn completely |
| 9486 | * - the line count is less than one |
| 9487 | * - the line count is more than 'ttyscroll' |
| 9488 | */ |
| 9489 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9490 | return FAIL; |
| 9491 | |
| 9492 | /* |
| 9493 | * There are seven ways to insert lines: |
| 9494 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9495 | * characters from ScreenLines[]. |
| 9496 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9497 | * the insert is just empty lines |
| 9498 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9499 | * present or line_count > 1. It looks better if we do all the inserts |
| 9500 | * at once. |
| 9501 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9502 | * insert is just empty lines and T_CE is not present or line_count > |
| 9503 | * 1. |
| 9504 | * 4. Use T_AL (insert line) if it exists. |
| 9505 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9506 | * just empty lines. |
| 9507 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9508 | * just empty lines. |
| 9509 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9510 | * the 'da' flag is not set or we have clear line capability. |
| 9511 | * 8. redraw the characters from ScreenLines[]. |
| 9512 | * |
| 9513 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9514 | * the scrollbar for the window. It does have insert line, use that if it |
| 9515 | * exists. |
| 9516 | */ |
| 9517 | result_empty = (row + line_count >= end); |
| 9518 | #ifdef FEAT_VERTSPLIT |
| 9519 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9520 | type = USE_REDRAW; |
| 9521 | else |
| 9522 | #endif |
| 9523 | if (can_clear(T_CD) && result_empty) |
| 9524 | type = USE_T_CD; |
| 9525 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9526 | type = USE_T_CAL; |
| 9527 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9528 | type = USE_T_CDL; |
| 9529 | else if (*T_AL != NUL) |
| 9530 | type = USE_T_AL; |
| 9531 | else if (can_ce && result_empty) |
| 9532 | type = USE_T_CE; |
| 9533 | else if (*T_DL != NUL && result_empty) |
| 9534 | type = USE_T_DL; |
| 9535 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9536 | type = USE_T_SR; |
| 9537 | else |
| 9538 | return FAIL; |
| 9539 | |
| 9540 | /* |
| 9541 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9542 | * care of t_db if necessary. |
| 9543 | */ |
| 9544 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9545 | type == USE_T_CE || type == USE_T_DL) |
| 9546 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9547 | |
| 9548 | /* |
| 9549 | * If text is retained below the screen, first clear or delete as many |
| 9550 | * lines at the bottom of the window as are about to be inserted so that |
| 9551 | * the deleted lines won't later surface during a screen_del_lines. |
| 9552 | */ |
| 9553 | if (*T_DB) |
| 9554 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9555 | |
| 9556 | #ifdef FEAT_CLIPBOARD |
| 9557 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9558 | * or not the full width of the screen. */ |
| 9559 | if (off + row > 0 |
| 9560 | # ifdef FEAT_VERTSPLIT |
| 9561 | || (wp != NULL && wp->w_width != Columns) |
| 9562 | # endif |
| 9563 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9564 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9565 | else |
| 9566 | clip_scroll_selection(-line_count); |
| 9567 | #endif |
| 9568 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9569 | #ifdef FEAT_GUI |
| 9570 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9571 | * scrolling is actually carried out. */ |
| 9572 | gui_dont_update_cursor(); |
| 9573 | #endif |
| 9574 | |
| 9575 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9576 | cursor_row = row; |
| 9577 | else |
| 9578 | cursor_row = row + off; |
| 9579 | |
| 9580 | /* |
| 9581 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9582 | * Clear the inserted lines in ScreenLines[]. |
| 9583 | */ |
| 9584 | row += off; |
| 9585 | end += off; |
| 9586 | for (i = 0; i < line_count; ++i) |
| 9587 | { |
| 9588 | #ifdef FEAT_VERTSPLIT |
| 9589 | if (wp != NULL && wp->w_width != Columns) |
| 9590 | { |
| 9591 | /* need to copy part of a line */ |
| 9592 | j = end - 1 - i; |
| 9593 | while ((j -= line_count) >= row) |
| 9594 | linecopy(j + line_count, j, wp); |
| 9595 | j += line_count; |
| 9596 | if (can_clear((char_u *)" ")) |
| 9597 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9598 | else |
| 9599 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9600 | LineWraps[j] = FALSE; |
| 9601 | } |
| 9602 | else |
| 9603 | #endif |
| 9604 | { |
| 9605 | j = end - 1 - i; |
| 9606 | temp = LineOffset[j]; |
| 9607 | while ((j -= line_count) >= row) |
| 9608 | { |
| 9609 | LineOffset[j + line_count] = LineOffset[j]; |
| 9610 | LineWraps[j + line_count] = LineWraps[j]; |
| 9611 | } |
| 9612 | LineOffset[j + line_count] = temp; |
| 9613 | LineWraps[j + line_count] = FALSE; |
| 9614 | if (can_clear((char_u *)" ")) |
| 9615 | lineclear(temp, (int)Columns); |
| 9616 | else |
| 9617 | lineinvalid(temp, (int)Columns); |
| 9618 | } |
| 9619 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9620 | |
| 9621 | screen_stop_highlight(); |
| 9622 | windgoto(cursor_row, 0); |
| 9623 | |
| 9624 | #ifdef FEAT_VERTSPLIT |
| 9625 | /* redraw the characters */ |
| 9626 | if (type == USE_REDRAW) |
| 9627 | redraw_block(row, end, wp); |
| 9628 | else |
| 9629 | #endif |
| 9630 | if (type == USE_T_CAL) |
| 9631 | { |
| 9632 | term_append_lines(line_count); |
| 9633 | screen_start(); /* don't know where cursor is now */ |
| 9634 | } |
| 9635 | else |
| 9636 | { |
| 9637 | for (i = 0; i < line_count; i++) |
| 9638 | { |
| 9639 | if (type == USE_T_AL) |
| 9640 | { |
| 9641 | if (i && cursor_row != 0) |
| 9642 | windgoto(cursor_row, 0); |
| 9643 | out_str(T_AL); |
| 9644 | } |
| 9645 | else /* type == USE_T_SR */ |
| 9646 | out_str(T_SR); |
| 9647 | screen_start(); /* don't know where cursor is now */ |
| 9648 | } |
| 9649 | } |
| 9650 | |
| 9651 | /* |
| 9652 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9653 | * have been scrolled down into the region. |
| 9654 | */ |
| 9655 | if (type == USE_T_SR && *T_DA) |
| 9656 | { |
| 9657 | for (i = 0; i < line_count; ++i) |
| 9658 | { |
| 9659 | windgoto(off + i, 0); |
| 9660 | out_str(T_CE); |
| 9661 | screen_start(); /* don't know where cursor is now */ |
| 9662 | } |
| 9663 | } |
| 9664 | |
| 9665 | #ifdef FEAT_GUI |
| 9666 | gui_can_update_cursor(); |
| 9667 | if (gui.in_use) |
| 9668 | out_flush(); /* always flush after a scroll */ |
| 9669 | #endif |
| 9670 | return OK; |
| 9671 | } |
| 9672 | |
| 9673 | /* |
| 9674 | * delete lines on the screen and update ScreenLines[] |
| 9675 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9676 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9677 | * 'row' and 'end' are relative to the start of the region. |
| 9678 | * |
| 9679 | * Return OK for success, FAIL if the lines are not deleted. |
| 9680 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9681 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9682 | screen_del_lines( |
| 9683 | int off, |
| 9684 | int row, |
| 9685 | int line_count, |
| 9686 | int end, |
| 9687 | int force, /* even when line_count > p_ttyscroll */ |
| 9688 | win_T *wp UNUSED) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9689 | { |
| 9690 | int j; |
| 9691 | int i; |
| 9692 | unsigned temp; |
| 9693 | int cursor_row; |
| 9694 | int cursor_end; |
| 9695 | int result_empty; /* result is empty until end of region */ |
| 9696 | int can_delete; /* deleting line codes can be used */ |
| 9697 | int type; |
| 9698 | |
| 9699 | /* |
| 9700 | * FAIL if |
| 9701 | * - there is no valid screen |
| 9702 | * - the screen has to be redrawn completely |
| 9703 | * - the line count is less than one |
| 9704 | * - the line count is more than 'ttyscroll' |
| 9705 | */ |
| 9706 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9707 | (!force && line_count > p_ttyscroll)) |
| 9708 | return FAIL; |
| 9709 | |
| 9710 | /* |
| 9711 | * Check if the rest of the current region will become empty. |
| 9712 | */ |
| 9713 | result_empty = row + line_count >= end; |
| 9714 | |
| 9715 | /* |
| 9716 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9717 | * available. |
| 9718 | */ |
| 9719 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9720 | |
| 9721 | /* |
| 9722 | * There are six ways to delete lines: |
| 9723 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9724 | * characters from ScreenLines[]. |
| 9725 | * 1. Use T_CD if it exists and the result is empty. |
| 9726 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9727 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9728 | * none of the other ways work. |
| 9729 | * 4. Use T_CE (erase line) if the result is empty. |
| 9730 | * 5. Use T_DL (delete line) if it exists. |
| 9731 | * 6. redraw the characters from ScreenLines[]. |
| 9732 | */ |
| 9733 | #ifdef FEAT_VERTSPLIT |
| 9734 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9735 | type = USE_REDRAW; |
| 9736 | else |
| 9737 | #endif |
| 9738 | if (can_clear(T_CD) && result_empty) |
| 9739 | type = USE_T_CD; |
| 9740 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9741 | /* |
| 9742 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9743 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9744 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9745 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9746 | * the trick... |
| 9747 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9748 | * (Olaf Seibert) |
| 9749 | */ |
| 9750 | else if (row == 0 && T_DB == empty_option |
| 9751 | && (line_count == 1 || *T_CDL == NUL)) |
| 9752 | #else |
| 9753 | else if (row == 0 && ( |
| 9754 | #ifndef AMIGA |
| 9755 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9756 | * up, so use delete-line command */ |
| 9757 | line_count == 1 || |
| 9758 | #endif |
| 9759 | *T_CDL == NUL)) |
| 9760 | #endif |
| 9761 | type = USE_NL; |
| 9762 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9763 | type = USE_T_CDL; |
| 9764 | else if (can_clear(T_CE) && result_empty |
| 9765 | #ifdef FEAT_VERTSPLIT |
| 9766 | && (wp == NULL || wp->w_width == Columns) |
| 9767 | #endif |
| 9768 | ) |
| 9769 | type = USE_T_CE; |
| 9770 | else if (*T_DL != NUL && can_delete) |
| 9771 | type = USE_T_DL; |
| 9772 | else if (*T_CDL != NUL && can_delete) |
| 9773 | type = USE_T_CDL; |
| 9774 | else |
| 9775 | return FAIL; |
| 9776 | |
| 9777 | #ifdef FEAT_CLIPBOARD |
| 9778 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9779 | * not the full width of the screen. */ |
| 9780 | if (off + row > 0 |
| 9781 | # ifdef FEAT_VERTSPLIT |
| 9782 | || (wp != NULL && wp->w_width != Columns) |
| 9783 | # endif |
| 9784 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9785 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9786 | else |
| 9787 | clip_scroll_selection(line_count); |
| 9788 | #endif |
| 9789 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9790 | #ifdef FEAT_GUI |
| 9791 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9792 | * scrolling is actually carried out. */ |
| 9793 | gui_dont_update_cursor(); |
| 9794 | #endif |
| 9795 | |
| 9796 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9797 | { |
| 9798 | cursor_row = row; |
| 9799 | cursor_end = end; |
| 9800 | } |
| 9801 | else |
| 9802 | { |
| 9803 | cursor_row = row + off; |
| 9804 | cursor_end = end + off; |
| 9805 | } |
| 9806 | |
| 9807 | /* |
| 9808 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9809 | * Clear the inserted lines in ScreenLines[]. |
| 9810 | */ |
| 9811 | row += off; |
| 9812 | end += off; |
| 9813 | for (i = 0; i < line_count; ++i) |
| 9814 | { |
| 9815 | #ifdef FEAT_VERTSPLIT |
| 9816 | if (wp != NULL && wp->w_width != Columns) |
| 9817 | { |
| 9818 | /* need to copy part of a line */ |
| 9819 | j = row + i; |
| 9820 | while ((j += line_count) <= end - 1) |
| 9821 | linecopy(j - line_count, j, wp); |
| 9822 | j -= line_count; |
| 9823 | if (can_clear((char_u *)" ")) |
| 9824 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9825 | else |
| 9826 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9827 | LineWraps[j] = FALSE; |
| 9828 | } |
| 9829 | else |
| 9830 | #endif |
| 9831 | { |
| 9832 | /* whole width, moving the line pointers is faster */ |
| 9833 | j = row + i; |
| 9834 | temp = LineOffset[j]; |
| 9835 | while ((j += line_count) <= end - 1) |
| 9836 | { |
| 9837 | LineOffset[j - line_count] = LineOffset[j]; |
| 9838 | LineWraps[j - line_count] = LineWraps[j]; |
| 9839 | } |
| 9840 | LineOffset[j - line_count] = temp; |
| 9841 | LineWraps[j - line_count] = FALSE; |
| 9842 | if (can_clear((char_u *)" ")) |
| 9843 | lineclear(temp, (int)Columns); |
| 9844 | else |
| 9845 | lineinvalid(temp, (int)Columns); |
| 9846 | } |
| 9847 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9848 | |
| 9849 | screen_stop_highlight(); |
| 9850 | |
| 9851 | #ifdef FEAT_VERTSPLIT |
| 9852 | /* redraw the characters */ |
| 9853 | if (type == USE_REDRAW) |
| 9854 | redraw_block(row, end, wp); |
| 9855 | else |
| 9856 | #endif |
| 9857 | if (type == USE_T_CD) /* delete the lines */ |
| 9858 | { |
| 9859 | windgoto(cursor_row, 0); |
| 9860 | out_str(T_CD); |
| 9861 | screen_start(); /* don't know where cursor is now */ |
| 9862 | } |
| 9863 | else if (type == USE_T_CDL) |
| 9864 | { |
| 9865 | windgoto(cursor_row, 0); |
| 9866 | term_delete_lines(line_count); |
| 9867 | screen_start(); /* don't know where cursor is now */ |
| 9868 | } |
| 9869 | /* |
| 9870 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9871 | * the whole screen (scroll region) up by outputting newlines on the |
| 9872 | * last line. |
| 9873 | */ |
| 9874 | else if (type == USE_NL) |
| 9875 | { |
| 9876 | windgoto(cursor_end - 1, 0); |
| 9877 | for (i = line_count; --i >= 0; ) |
| 9878 | out_char('\n'); /* cursor will remain on same line */ |
| 9879 | } |
| 9880 | else |
| 9881 | { |
| 9882 | for (i = line_count; --i >= 0; ) |
| 9883 | { |
| 9884 | if (type == USE_T_DL) |
| 9885 | { |
| 9886 | windgoto(cursor_row, 0); |
| 9887 | out_str(T_DL); /* delete a line */ |
| 9888 | } |
| 9889 | else /* type == USE_T_CE */ |
| 9890 | { |
| 9891 | windgoto(cursor_row + i, 0); |
| 9892 | out_str(T_CE); /* erase a line */ |
| 9893 | } |
| 9894 | screen_start(); /* don't know where cursor is now */ |
| 9895 | } |
| 9896 | } |
| 9897 | |
| 9898 | /* |
| 9899 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9900 | * scrolled up at the bottom of the region. |
| 9901 | */ |
| 9902 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9903 | { |
| 9904 | for (i = line_count; i > 0; --i) |
| 9905 | { |
| 9906 | windgoto(cursor_end - i, 0); |
| 9907 | out_str(T_CE); /* erase a line */ |
| 9908 | screen_start(); /* don't know where cursor is now */ |
| 9909 | } |
| 9910 | } |
| 9911 | |
| 9912 | #ifdef FEAT_GUI |
| 9913 | gui_can_update_cursor(); |
| 9914 | if (gui.in_use) |
| 9915 | out_flush(); /* always flush after a scroll */ |
| 9916 | #endif |
| 9917 | |
| 9918 | return OK; |
| 9919 | } |
| 9920 | |
| 9921 | /* |
| 9922 | * show the current mode and ruler |
| 9923 | * |
| 9924 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 9925 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 9926 | * cleared only if a mode is shown. |
| 9927 | * Return the length of the message (0 if no message). |
| 9928 | */ |
| 9929 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9930 | showmode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9931 | { |
| 9932 | int need_clear; |
| 9933 | int length = 0; |
| 9934 | int do_mode; |
| 9935 | int attr; |
| 9936 | int nwr_save; |
| 9937 | #ifdef FEAT_INS_EXPAND |
| 9938 | int sub_attr; |
| 9939 | #endif |
| 9940 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 9941 | do_mode = ((p_smd && msg_silent == 0) |
| 9942 | && ((State & INSERT) |
| 9943 | || restart_edit |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9944 | || VIsual_active)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9945 | if (do_mode || Recording) |
| 9946 | { |
| 9947 | /* |
| 9948 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 9949 | * Call char_avail() only when we are going to show something, because |
| 9950 | * it takes a bit of time. |
| 9951 | */ |
| 9952 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 9953 | { |
| 9954 | redraw_cmdline = TRUE; /* show mode later */ |
| 9955 | return 0; |
| 9956 | } |
| 9957 | |
| 9958 | nwr_save = need_wait_return; |
| 9959 | |
| 9960 | /* wait a bit before overwriting an important message */ |
| 9961 | check_for_delay(FALSE); |
| 9962 | |
| 9963 | /* if the cmdline is more than one line high, erase top lines */ |
| 9964 | need_clear = clear_cmdline; |
| 9965 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 9966 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 9967 | |
| 9968 | /* Position on the last line in the window, column 0 */ |
| 9969 | msg_pos_mode(); |
| 9970 | cursor_off(); |
| 9971 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 9972 | if (do_mode) |
| 9973 | { |
| 9974 | MSG_PUTS_ATTR("--", attr); |
| 9975 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9976 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9977 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9978 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9979 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9980 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9981 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9982 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 9983 | # 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] | 9984 | MSG_PUTS_ATTR(" IM", attr); |
| 9985 | # else |
| 9986 | MSG_PUTS_ATTR(" XIM", attr); |
| 9987 | # endif |
| 9988 | #endif |
| 9989 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 9990 | if (gui.in_use) |
| 9991 | { |
| 9992 | if (hangul_input_state_get()) |
Bram Moolenaar | 72f4cc4 | 2015-11-10 14:35:18 +0100 | [diff] [blame] | 9993 | { |
| 9994 | /* HANGUL */ |
| 9995 | if (enc_utf8) |
| 9996 | MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr); |
| 9997 | else |
| 9998 | MSG_PUTS_ATTR(" \307\321\261\333", attr); |
| 9999 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10000 | } |
| 10001 | #endif |
| 10002 | #ifdef FEAT_INS_EXPAND |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 10003 | /* CTRL-X in Insert mode */ |
| 10004 | if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10005 | { |
| 10006 | /* These messages can get long, avoid a wrap in a narrow |
| 10007 | * window. Prefer showing edit_submode_extra. */ |
| 10008 | length = (Rows - msg_row) * Columns - 3; |
| 10009 | if (edit_submode_extra != NULL) |
| 10010 | length -= vim_strsize(edit_submode_extra); |
| 10011 | if (length > 0) |
| 10012 | { |
| 10013 | if (edit_submode_pre != NULL) |
| 10014 | length -= vim_strsize(edit_submode_pre); |
| 10015 | if (length - vim_strsize(edit_submode) > 0) |
| 10016 | { |
| 10017 | if (edit_submode_pre != NULL) |
| 10018 | msg_puts_attr(edit_submode_pre, attr); |
| 10019 | msg_puts_attr(edit_submode, attr); |
| 10020 | } |
| 10021 | if (edit_submode_extra != NULL) |
| 10022 | { |
| 10023 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 10024 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 10025 | sub_attr = hl_attr(edit_submode_highl); |
| 10026 | else |
| 10027 | sub_attr = attr; |
| 10028 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 10029 | } |
| 10030 | } |
| 10031 | length = 0; |
| 10032 | } |
| 10033 | else |
| 10034 | #endif |
| 10035 | { |
| 10036 | #ifdef FEAT_VREPLACE |
| 10037 | if (State & VREPLACE_FLAG) |
| 10038 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 10039 | else |
| 10040 | #endif |
| 10041 | if (State & REPLACE_FLAG) |
| 10042 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 10043 | else if (State & INSERT) |
| 10044 | { |
| 10045 | #ifdef FEAT_RIGHTLEFT |
| 10046 | if (p_ri) |
| 10047 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 10048 | #endif |
| 10049 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 10050 | } |
| 10051 | else if (restart_edit == 'I') |
| 10052 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 10053 | else if (restart_edit == 'R') |
| 10054 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 10055 | else if (restart_edit == 'V') |
| 10056 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 10057 | #ifdef FEAT_RIGHTLEFT |
| 10058 | if (p_hkmap) |
| 10059 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 10060 | # ifdef FEAT_FKMAP |
| 10061 | if (p_fkmap) |
| 10062 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 10063 | # endif |
| 10064 | #endif |
| 10065 | #ifdef FEAT_KEYMAP |
| 10066 | if (State & LANGMAP) |
| 10067 | { |
| 10068 | # ifdef FEAT_ARABIC |
| 10069 | if (curwin->w_p_arab) |
| 10070 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 10071 | else |
| 10072 | # endif |
| 10073 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 10074 | } |
| 10075 | #endif |
| 10076 | if ((State & INSERT) && p_paste) |
| 10077 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 10078 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10079 | if (VIsual_active) |
| 10080 | { |
| 10081 | char *p; |
| 10082 | |
| 10083 | /* Don't concatenate separate words to avoid translation |
| 10084 | * problems. */ |
| 10085 | switch ((VIsual_select ? 4 : 0) |
| 10086 | + (VIsual_mode == Ctrl_V) * 2 |
| 10087 | + (VIsual_mode == 'V')) |
| 10088 | { |
| 10089 | case 0: p = N_(" VISUAL"); break; |
| 10090 | case 1: p = N_(" VISUAL LINE"); break; |
| 10091 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 10092 | case 4: p = N_(" SELECT"); break; |
| 10093 | case 5: p = N_(" SELECT LINE"); break; |
| 10094 | default: p = N_(" SELECT BLOCK"); break; |
| 10095 | } |
| 10096 | MSG_PUTS_ATTR(_(p), attr); |
| 10097 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10098 | MSG_PUTS_ATTR(" --", attr); |
| 10099 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10100 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10101 | need_clear = TRUE; |
| 10102 | } |
| 10103 | if (Recording |
| 10104 | #ifdef FEAT_INS_EXPAND |
| 10105 | && edit_submode == NULL /* otherwise it gets too long */ |
| 10106 | #endif |
| 10107 | ) |
| 10108 | { |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10109 | recording_mode(attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10110 | need_clear = TRUE; |
| 10111 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10112 | |
| 10113 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10114 | if (need_clear || clear_cmdline) |
| 10115 | msg_clr_eos(); |
| 10116 | msg_didout = FALSE; /* overwrite this message */ |
| 10117 | length = msg_col; |
| 10118 | msg_col = 0; |
| 10119 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 10120 | } |
| 10121 | else if (clear_cmdline && msg_silent == 0) |
| 10122 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 10123 | msg_clr_cmdline(); |
| 10124 | |
| 10125 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10126 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 10127 | if (VIsual_active) |
| 10128 | clear_showcmd(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10129 | |
| 10130 | /* If the last window has no status line, the ruler is after the mode |
| 10131 | * message and must be redrawn */ |
| 10132 | if (redrawing() |
| 10133 | # ifdef FEAT_WINDOWS |
| 10134 | && lastwin->w_status_height == 0 |
| 10135 | # endif |
| 10136 | ) |
| 10137 | win_redr_ruler(lastwin, TRUE); |
| 10138 | #endif |
| 10139 | redraw_cmdline = FALSE; |
| 10140 | clear_cmdline = FALSE; |
| 10141 | |
| 10142 | return length; |
| 10143 | } |
| 10144 | |
| 10145 | /* |
| 10146 | * Position for a mode message. |
| 10147 | */ |
| 10148 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10149 | msg_pos_mode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10150 | { |
| 10151 | msg_col = 0; |
| 10152 | msg_row = Rows - 1; |
| 10153 | } |
| 10154 | |
| 10155 | /* |
| 10156 | * Delete mode message. Used when ESC is typed which is expected to end |
| 10157 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10158 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10159 | */ |
| 10160 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10161 | unshowmode(int force) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10162 | { |
| 10163 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 10164 | * 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] | 10165 | */ |
| 10166 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 10167 | redraw_cmdline = TRUE; /* delete mode later */ |
| 10168 | else |
| 10169 | { |
| 10170 | msg_pos_mode(); |
| 10171 | if (Recording) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10172 | recording_mode(hl_attr(HLF_CM)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10173 | msg_clr_eos(); |
| 10174 | } |
| 10175 | } |
| 10176 | |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10177 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10178 | recording_mode(int attr) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10179 | { |
| 10180 | MSG_PUTS_ATTR(_("recording"), attr); |
| 10181 | if (!shortmess(SHM_RECORDING)) |
| 10182 | { |
| 10183 | char_u s[4]; |
| 10184 | sprintf((char *)s, " @%c", Recording); |
| 10185 | MSG_PUTS_ATTR(s, attr); |
| 10186 | } |
| 10187 | } |
| 10188 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10189 | #if defined(FEAT_WINDOWS) |
| 10190 | /* |
| 10191 | * Draw the tab pages line at the top of the Vim window. |
| 10192 | */ |
| 10193 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10194 | draw_tabline(void) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10195 | { |
| 10196 | int tabcount = 0; |
| 10197 | tabpage_T *tp; |
| 10198 | int tabwidth; |
| 10199 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10200 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10201 | int attr; |
| 10202 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10203 | win_T *cwp; |
| 10204 | int wincount; |
| 10205 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10206 | int c; |
| 10207 | int len; |
| 10208 | int attr_sel = hl_attr(HLF_TPS); |
| 10209 | int attr_nosel = hl_attr(HLF_TP); |
| 10210 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10211 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10212 | int room; |
| 10213 | int use_sep_chars = (t_colors < 8 |
| 10214 | #ifdef FEAT_GUI |
| 10215 | && !gui.in_use |
| 10216 | #endif |
| 10217 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10218 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10219 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10220 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10221 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 10222 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10223 | if (gui_use_tabline()) |
| 10224 | { |
| 10225 | gui_update_tabline(); |
| 10226 | return; |
| 10227 | } |
| 10228 | #endif |
| 10229 | |
| 10230 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10231 | return; |
| 10232 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10233 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10234 | |
| 10235 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 10236 | for (scol = 0; scol < Columns; ++scol) |
| 10237 | TabPageIdxs[scol] = 0; |
| 10238 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10239 | /* Use the 'tabline' option if it's set. */ |
| 10240 | if (*p_tal != NUL) |
| 10241 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10242 | int save_called_emsg = called_emsg; |
| 10243 | |
| 10244 | /* Check for an error. If there is one we would loop in redrawing the |
| 10245 | * screen. Avoid that by making 'tabline' empty. */ |
| 10246 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10247 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10248 | if (called_emsg) |
| 10249 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10250 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10251 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10252 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10253 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10254 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10255 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10256 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 10257 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10258 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10259 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 10260 | if (tabwidth < 6) |
| 10261 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10262 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10263 | attr = attr_nosel; |
| 10264 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10265 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10266 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 10267 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10268 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10269 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10270 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10271 | if (tp->tp_topframe == topframe) |
| 10272 | attr = attr_sel; |
| 10273 | if (use_sep_chars && col > 0) |
| 10274 | screen_putchar('|', 0, col++, attr); |
| 10275 | |
| 10276 | if (tp->tp_topframe != topframe) |
| 10277 | attr = attr_nosel; |
| 10278 | |
| 10279 | screen_putchar(' ', 0, col++, attr); |
| 10280 | |
| 10281 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10282 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10283 | cwp = curwin; |
| 10284 | wp = firstwin; |
| 10285 | } |
| 10286 | else |
| 10287 | { |
| 10288 | cwp = tp->tp_curwin; |
| 10289 | wp = tp->tp_firstwin; |
| 10290 | } |
| 10291 | |
| 10292 | modified = FALSE; |
| 10293 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 10294 | if (bufIsChanged(wp->w_buffer)) |
| 10295 | modified = TRUE; |
| 10296 | if (modified || wincount > 1) |
| 10297 | { |
| 10298 | if (wincount > 1) |
| 10299 | { |
| 10300 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10301 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10302 | if (col + len >= Columns - 3) |
| 10303 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10304 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10305 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10306 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10307 | #else |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10308 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10309 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10310 | ); |
| 10311 | col += len; |
| 10312 | } |
| 10313 | if (modified) |
| 10314 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 10315 | screen_putchar(' ', 0, col++, attr); |
| 10316 | } |
| 10317 | |
| 10318 | room = scol - col + tabwidth - 1; |
| 10319 | if (room > 0) |
| 10320 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10321 | /* Get buffer name in NameBuff[] */ |
| 10322 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 10323 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10324 | len = vim_strsize(NameBuff); |
| 10325 | p = NameBuff; |
| 10326 | #ifdef FEAT_MBYTE |
| 10327 | if (has_mbyte) |
| 10328 | while (len > room) |
| 10329 | { |
| 10330 | len -= ptr2cells(p); |
| 10331 | mb_ptr_adv(p); |
| 10332 | } |
| 10333 | else |
| 10334 | #endif |
| 10335 | if (len > room) |
| 10336 | { |
| 10337 | p += len - room; |
| 10338 | len = room; |
| 10339 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10340 | if (len > Columns - col - 1) |
| 10341 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10342 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10343 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10344 | col += len; |
| 10345 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10346 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10347 | |
| 10348 | /* Store the tab page number in TabPageIdxs[], so that |
| 10349 | * jump_to_mouse() knows where each one is. */ |
| 10350 | ++tabcount; |
| 10351 | while (scol < col) |
| 10352 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10353 | } |
| 10354 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10355 | if (use_sep_chars) |
| 10356 | c = '_'; |
| 10357 | else |
| 10358 | c = ' '; |
| 10359 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10360 | |
| 10361 | /* Put an "X" for closing the current tab if there are several. */ |
| 10362 | if (first_tabpage->tp_next != NULL) |
| 10363 | { |
| 10364 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 10365 | TabPageIdxs[Columns - 1] = -999; |
| 10366 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10367 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 10368 | |
| 10369 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 10370 | * set. */ |
| 10371 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10372 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10373 | |
| 10374 | /* |
| 10375 | * Get buffer name for "buf" into NameBuff[]. |
| 10376 | * Takes care of special buffer names and translates special characters. |
| 10377 | */ |
| 10378 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10379 | get_trans_bufname(buf_T *buf) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10380 | { |
| 10381 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 10382 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10383 | else |
| 10384 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 10385 | trans_characters(NameBuff, MAXPATHL); |
| 10386 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10387 | #endif |
| 10388 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10389 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 10390 | /* |
| 10391 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 10392 | */ |
| 10393 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10394 | fillchar_status(int *attr, int is_curwin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10395 | { |
| 10396 | int fill; |
| 10397 | if (is_curwin) |
| 10398 | { |
| 10399 | *attr = hl_attr(HLF_S); |
| 10400 | fill = fill_stl; |
| 10401 | } |
| 10402 | else |
| 10403 | { |
| 10404 | *attr = hl_attr(HLF_SNC); |
| 10405 | fill = fill_stlnc; |
| 10406 | } |
| 10407 | /* Use fill when there is highlighting, and highlighting of current |
| 10408 | * window differs, or the fillchars differ, or this is not the |
| 10409 | * current window */ |
| 10410 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 10411 | || !is_curwin || firstwin == lastwin) |
| 10412 | || (fill_stl != fill_stlnc))) |
| 10413 | return fill; |
| 10414 | if (is_curwin) |
| 10415 | return '^'; |
| 10416 | return '='; |
| 10417 | } |
| 10418 | #endif |
| 10419 | |
| 10420 | #ifdef FEAT_VERTSPLIT |
| 10421 | /* |
| 10422 | * Get the character to use in a separator between vertically split windows. |
| 10423 | * Get its attributes in "*attr". |
| 10424 | */ |
| 10425 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10426 | fillchar_vsep(int *attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10427 | { |
| 10428 | *attr = hl_attr(HLF_C); |
| 10429 | if (*attr == 0 && fill_vert == ' ') |
| 10430 | return '|'; |
| 10431 | else |
| 10432 | return fill_vert; |
| 10433 | } |
| 10434 | #endif |
| 10435 | |
| 10436 | /* |
| 10437 | * Return TRUE if redrawing should currently be done. |
| 10438 | */ |
| 10439 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10440 | redrawing(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10441 | { |
| 10442 | return (!RedrawingDisabled |
| 10443 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 10444 | } |
| 10445 | |
| 10446 | /* |
| 10447 | * Return TRUE if printing messages should currently be done. |
| 10448 | */ |
| 10449 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10450 | messaging(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10451 | { |
| 10452 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10453 | } |
| 10454 | |
| 10455 | /* |
| 10456 | * Show current status info in ruler and various other places |
| 10457 | * If always is FALSE, only show ruler if position has changed. |
| 10458 | */ |
| 10459 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10460 | showruler(int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10461 | { |
| 10462 | if (!always && !redrawing()) |
| 10463 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10464 | #ifdef FEAT_INS_EXPAND |
| 10465 | if (pum_visible()) |
| 10466 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10467 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10468 | /* Don't redraw right now, do it later. */ |
| 10469 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10470 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10471 | return; |
| 10472 | } |
| 10473 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10474 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10475 | 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] | 10476 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10477 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10478 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10479 | else |
| 10480 | #endif |
| 10481 | #ifdef FEAT_CMDL_INFO |
| 10482 | win_redr_ruler(curwin, always); |
| 10483 | #endif |
| 10484 | |
| 10485 | #ifdef FEAT_TITLE |
| 10486 | if (need_maketitle |
| 10487 | # ifdef FEAT_STL_OPT |
| 10488 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10489 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10490 | # endif |
| 10491 | ) |
| 10492 | maketitle(); |
| 10493 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10494 | #ifdef FEAT_WINDOWS |
| 10495 | /* Redraw the tab pages line if needed. */ |
| 10496 | if (redraw_tabline) |
| 10497 | draw_tabline(); |
| 10498 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10499 | } |
| 10500 | |
| 10501 | #ifdef FEAT_CMDL_INFO |
| 10502 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10503 | win_redr_ruler(win_T *wp, int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10504 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10505 | #define RULER_BUF_LEN 70 |
| 10506 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10507 | int row; |
| 10508 | int fillchar; |
| 10509 | int attr; |
| 10510 | int empty_line = FALSE; |
| 10511 | colnr_T virtcol; |
| 10512 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10513 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10514 | int o; |
| 10515 | #ifdef FEAT_VERTSPLIT |
| 10516 | int this_ru_col; |
| 10517 | int off = 0; |
| 10518 | int width = Columns; |
| 10519 | # define WITH_OFF(x) x |
| 10520 | # define WITH_WIDTH(x) x |
| 10521 | #else |
| 10522 | # define WITH_OFF(x) 0 |
| 10523 | # define WITH_WIDTH(x) Columns |
| 10524 | # define this_ru_col ru_col |
| 10525 | #endif |
| 10526 | |
| 10527 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10528 | if (!p_ru) |
| 10529 | return; |
| 10530 | |
| 10531 | /* |
| 10532 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10533 | * after deleting lines, before cursor.lnum is corrected. |
| 10534 | */ |
| 10535 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10536 | return; |
| 10537 | |
| 10538 | #ifdef FEAT_INS_EXPAND |
| 10539 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10540 | * the (long) mode message. */ |
| 10541 | # ifdef FEAT_WINDOWS |
| 10542 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10543 | # endif |
| 10544 | if (edit_submode != NULL) |
| 10545 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10546 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10547 | if (pum_visible()) |
| 10548 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10549 | #endif |
| 10550 | |
| 10551 | #ifdef FEAT_STL_OPT |
| 10552 | if (*p_ruf) |
| 10553 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10554 | int save_called_emsg = called_emsg; |
| 10555 | |
| 10556 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10557 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10558 | if (called_emsg) |
| 10559 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10560 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10561 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10562 | return; |
| 10563 | } |
| 10564 | #endif |
| 10565 | |
| 10566 | /* |
| 10567 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10568 | */ |
| 10569 | if (!(State & INSERT) |
| 10570 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10571 | empty_line = TRUE; |
| 10572 | |
| 10573 | /* |
| 10574 | * Only draw the ruler when something changed. |
| 10575 | */ |
| 10576 | validate_virtcol_win(wp); |
| 10577 | if ( redraw_cmdline |
| 10578 | || always |
| 10579 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10580 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10581 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10582 | #ifdef FEAT_VIRTUALEDIT |
| 10583 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10584 | #endif |
| 10585 | || wp->w_topline != wp->w_ru_topline |
| 10586 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10587 | #ifdef FEAT_DIFF |
| 10588 | || wp->w_topfill != wp->w_ru_topfill |
| 10589 | #endif |
| 10590 | || empty_line != wp->w_ru_empty) |
| 10591 | { |
| 10592 | cursor_off(); |
| 10593 | #ifdef FEAT_WINDOWS |
| 10594 | if (wp->w_status_height) |
| 10595 | { |
| 10596 | row = W_WINROW(wp) + wp->w_height; |
| 10597 | fillchar = fillchar_status(&attr, wp == curwin); |
| 10598 | # ifdef FEAT_VERTSPLIT |
| 10599 | off = W_WINCOL(wp); |
| 10600 | width = W_WIDTH(wp); |
| 10601 | # endif |
| 10602 | } |
| 10603 | else |
| 10604 | #endif |
| 10605 | { |
| 10606 | row = Rows - 1; |
| 10607 | fillchar = ' '; |
| 10608 | attr = 0; |
| 10609 | #ifdef FEAT_VERTSPLIT |
| 10610 | width = Columns; |
| 10611 | off = 0; |
| 10612 | #endif |
| 10613 | } |
| 10614 | |
| 10615 | /* In list mode virtcol needs to be recomputed */ |
| 10616 | virtcol = wp->w_virtcol; |
| 10617 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10618 | { |
| 10619 | wp->w_p_list = FALSE; |
| 10620 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10621 | wp->w_p_list = TRUE; |
| 10622 | } |
| 10623 | |
| 10624 | /* |
| 10625 | * Some sprintfs return the length, some return a pointer. |
| 10626 | * To avoid portability problems we use strlen() here. |
| 10627 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10628 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10629 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10630 | ? 0L |
| 10631 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10632 | len = STRLEN(buffer); |
| 10633 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10634 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10635 | (int)virtcol + 1); |
| 10636 | |
| 10637 | /* |
| 10638 | * Add a "50%" if there is room for it. |
| 10639 | * On the last line, don't print in the last column (scrolls the |
| 10640 | * screen up on some terminals). |
| 10641 | */ |
| 10642 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10643 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10644 | o = i + vim_strsize(buffer + i + 1); |
| 10645 | #ifdef FEAT_WINDOWS |
| 10646 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10647 | #endif |
| 10648 | ++o; |
| 10649 | #ifdef FEAT_VERTSPLIT |
| 10650 | this_ru_col = ru_col - (Columns - width); |
| 10651 | if (this_ru_col < 0) |
| 10652 | this_ru_col = 0; |
| 10653 | #endif |
| 10654 | /* Never use more than half the window/screen width, leave the other |
| 10655 | * half for the filename. */ |
| 10656 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10657 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10658 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10659 | { |
Bram Moolenaar | 0027c21 | 2015-01-07 13:31:52 +0100 | [diff] [blame] | 10660 | /* need at least 3 chars left for get_rel_pos() + NUL */ |
| 10661 | 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] | 10662 | { |
| 10663 | #ifdef FEAT_MBYTE |
| 10664 | if (has_mbyte) |
| 10665 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10666 | else |
| 10667 | #endif |
| 10668 | buffer[i++] = fillchar; |
| 10669 | ++o; |
| 10670 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10671 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10672 | } |
| 10673 | /* Truncate at window boundary. */ |
| 10674 | #ifdef FEAT_MBYTE |
| 10675 | if (has_mbyte) |
| 10676 | { |
| 10677 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10678 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10679 | { |
| 10680 | o += (*mb_ptr2cells)(buffer + i); |
| 10681 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10682 | { |
| 10683 | buffer[i] = NUL; |
| 10684 | break; |
| 10685 | } |
| 10686 | } |
| 10687 | } |
| 10688 | else |
| 10689 | #endif |
| 10690 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10691 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10692 | |
| 10693 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10694 | i = redraw_cmdline; |
| 10695 | screen_fill(row, row + 1, |
| 10696 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10697 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10698 | fillchar, fillchar, attr); |
| 10699 | /* don't redraw the cmdline because of showing the ruler */ |
| 10700 | redraw_cmdline = i; |
| 10701 | wp->w_ru_cursor = wp->w_cursor; |
| 10702 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10703 | wp->w_ru_empty = empty_line; |
| 10704 | wp->w_ru_topline = wp->w_topline; |
| 10705 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10706 | #ifdef FEAT_DIFF |
| 10707 | wp->w_ru_topfill = wp->w_topfill; |
| 10708 | #endif |
| 10709 | } |
| 10710 | } |
| 10711 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10712 | |
| 10713 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10714 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10715 | * Return the width of the 'number' and 'relativenumber' column. |
| 10716 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10717 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10718 | */ |
| 10719 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10720 | number_width(win_T *wp) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10721 | { |
| 10722 | int n; |
| 10723 | linenr_T lnum; |
| 10724 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10725 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10726 | /* cursor line shows "0" */ |
| 10727 | lnum = wp->w_height; |
| 10728 | else |
| 10729 | /* cursor line shows absolute line number */ |
| 10730 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10731 | |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10732 | 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] | 10733 | return wp->w_nrwidth_width; |
| 10734 | wp->w_nrwidth_line_count = lnum; |
| 10735 | |
| 10736 | n = 0; |
| 10737 | do |
| 10738 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10739 | lnum /= 10; |
| 10740 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10741 | } while (lnum > 0); |
| 10742 | |
| 10743 | /* 'numberwidth' gives the minimal width plus one */ |
| 10744 | if (n < wp->w_p_nuw - 1) |
| 10745 | n = wp->w_p_nuw - 1; |
| 10746 | |
| 10747 | wp->w_nrwidth_width = n; |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10748 | wp->w_nuw_cached = wp->w_p_nuw; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10749 | return n; |
| 10750 | } |
| 10751 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10752 | |
| 10753 | /* |
| 10754 | * Return the current cursor column. This is the actual position on the |
| 10755 | * screen. First column is 0. |
| 10756 | */ |
| 10757 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10758 | screen_screencol(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10759 | { |
| 10760 | return screen_cur_col; |
| 10761 | } |
| 10762 | |
| 10763 | /* |
| 10764 | * Return the current cursor row. This is the actual position on the screen. |
| 10765 | * First row is 0. |
| 10766 | */ |
| 10767 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10768 | screen_screenrow(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10769 | { |
| 10770 | return screen_cur_row; |
| 10771 | } |