Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * screen.c: code for displaying on the screen |
| 12 | * |
| 13 | * Output to the screen (console, terminal emulator or GUI window) is minimized |
| 14 | * by remembering what is already on the screen, and only updating the parts |
| 15 | * that changed. |
| 16 | * |
| 17 | * ScreenLines[off] Contains a copy of the whole screen, as it is currently |
| 18 | * displayed (excluding text written by external commands). |
| 19 | * ScreenAttrs[off] Contains the associated attributes. |
| 20 | * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] |
| 21 | * for each line. |
| 22 | * LineWraps[row] Flag for each line whether it wraps to the next line. |
| 23 | * |
| 24 | * For double-byte characters, two consecutive bytes in ScreenLines[] can form |
| 25 | * one character which occupies two display cells. |
| 26 | * For UTF-8 a multi-byte character is converted to Unicode and stored in |
| 27 | * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 28 | * character without composing chars ScreenLinesUC[] will be 0 and |
| 29 | * ScreenLinesC[][] is not used. When the character occupies two display |
| 30 | * cells the next byte in ScreenLines[] is 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 31 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 32 | * (drawn on top of the first character). There is 0 after the last one used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | * ScreenLines2[] is only used for euc-jp to store the second byte if the |
| 34 | * first byte is 0x8e (single-width character). |
| 35 | * |
| 36 | * The screen_*() functions write to the screen and handle updating |
| 37 | * ScreenLines[]. |
| 38 | * |
| 39 | * update_screen() is the function that updates all windows and status lines. |
| 40 | * It is called form the main loop when must_redraw is non-zero. It may be |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 41 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | * |
| 43 | * The part of the buffer that is displayed in a window is set with: |
| 44 | * - w_topline (first buffer line in window) |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 45 | * - w_topfill (filler lines above the first line) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | * - w_leftcol (leftmost window cell in window), |
| 47 | * - w_skipcol (skipped window cells of first line) |
| 48 | * |
| 49 | * Commands that only move the cursor around in a window, do not need to take |
| 50 | * action to update the display. The main loop will check if w_topline is |
| 51 | * valid and update it (scroll the window) when needed. |
| 52 | * |
| 53 | * Commands that scroll a window change w_topline and must call |
| 54 | * check_cursor() to move the cursor into the visible part of the window, and |
| 55 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 56 | * later. |
| 57 | * |
| 58 | * Commands that change text in the buffer must call changed_bytes() or |
| 59 | * changed_lines() to mark the area that changed and will require updating |
| 60 | * later. The main loop will call update_screen(), which will update each |
| 61 | * window that shows the changed buffer. This assumes text above the change |
| 62 | * can remain displayed as it is. Text after the change may need updating for |
| 63 | * scrolling, folding and syntax highlighting. |
| 64 | * |
| 65 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 66 | * invalidate the contents of a window in another way (e.g., change fold |
| 67 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 68 | * redisplayed by update_screen() later. |
| 69 | * |
| 70 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 71 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 72 | * buffer redisplayed by update_screen() later. |
| 73 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 74 | * Commands that change highlighting and possibly cause a scroll too must call |
| 75 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 76 | * to avoid redrawing everything. But the length of displayed lines must not |
| 77 | * change, use NOT_VALID then. |
| 78 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 80 | * TODO: should minimize redrawing by scrolling when possible. |
| 81 | * |
| 82 | * Commands that change everything (e.g., resizing the screen) must call |
| 83 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 84 | * |
| 85 | * Things that are handled indirectly: |
| 86 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 87 | * update_screen() called to redraw. |
| 88 | */ |
| 89 | |
| 90 | #include "vim.h" |
| 91 | |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 92 | #define MB_FILLER_CHAR '<' /* character used when a double-width character |
| 93 | * doesn't fit. */ |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * The attributes that are actually active for writing to the screen. |
| 97 | */ |
| 98 | static int screen_attr = 0; |
| 99 | |
| 100 | /* |
| 101 | * Positioning the cursor is reduced by remembering the last position. |
| 102 | * Mostly used by windgoto() and screen_char(). |
| 103 | */ |
| 104 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 105 | |
| 106 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef FEAT_FOLDING |
| 111 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 112 | static int compute_foldcolumn(win_T *wp, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | /* |
| 116 | * Buffer for one screen line (characters and attributes). |
| 117 | */ |
| 118 | static schar_T *current_ScreenLine; |
| 119 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 120 | static void win_update(win_T *wp); |
| 121 | static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | #ifdef FEAT_FOLDING |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 123 | static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row); |
| 124 | static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum); |
| 125 | static void copy_text_attr(int off, char_u *buf, int len, int attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 127 | static int win_line(win_T *, linenr_T, int, int, int nochange); |
| 128 | static int char_needs_redraw(int off_from, int off_to, int cols); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 129 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 130 | static void screen_line(int row, int coloff, int endcol, int clear_width, int rlflag); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 132 | #else |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 133 | static void screen_line(int row, int coloff, int endcol, int clear_width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 135 | #endif |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 136 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 137 | static void draw_vsep_win(win_T *wp, int row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 139 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 140 | static void redraw_custom_statusline(win_T *wp); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 141 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 142 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 143 | # define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 144 | static void start_search_hl(void); |
| 145 | static void end_search_hl(void); |
| 146 | static void init_search_hl(win_T *wp); |
| 147 | static void prepare_search_hl(win_T *wp, linenr_T lnum); |
| 148 | static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur); |
| 149 | static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 150 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 151 | static void screen_start_highlight(int attr); |
| 152 | static void screen_char(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 154 | static void screen_char_2(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 155 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 156 | static void screenclear2(void); |
| 157 | static void lineclear(unsigned off, int width); |
| 158 | static void lineinvalid(unsigned off, int width); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 159 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 160 | static void linecopy(int to, int from, win_T *wp); |
| 161 | static void redraw_block(int row, int end, win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 163 | static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del); |
| 164 | static void win_rest_invalid(win_T *wp); |
| 165 | static void msg_pos_mode(void); |
| 166 | static void recording_mode(int attr); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 167 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 168 | static void draw_tabline(void); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 169 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 171 | static int fillchar_status(int *attr, int is_curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | #endif |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 173 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 174 | static int fillchar_vsep(int *attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | #endif |
| 176 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 177 | static void win_redr_custom(win_T *wp, int draw_ruler); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 178 | #endif |
| 179 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 180 | static void win_redr_ruler(win_T *wp, int always); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 183 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | /* Ugly global: overrule attribute used by screen_char() */ |
| 185 | static int screen_char_attr = 0; |
| 186 | #endif |
| 187 | |
| 188 | /* |
| 189 | * Redraw the current window later, with update_screen(type). |
| 190 | * Set must_redraw only if not already set to a higher value. |
| 191 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 192 | */ |
| 193 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 194 | redraw_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 195 | { |
| 196 | redraw_win_later(curwin, type); |
| 197 | } |
| 198 | |
| 199 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 200 | redraw_win_later( |
| 201 | win_T *wp, |
| 202 | int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 203 | { |
| 204 | if (wp->w_redr_type < type) |
| 205 | { |
| 206 | wp->w_redr_type = type; |
| 207 | if (type >= NOT_VALID) |
| 208 | wp->w_lines_valid = 0; |
| 209 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 210 | must_redraw = type; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 216 | * after executing a shell command that messes up the screen. |
| 217 | */ |
| 218 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 219 | redraw_later_clear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 220 | { |
| 221 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 222 | #ifdef FEAT_GUI |
| 223 | if (gui.in_use) |
| 224 | /* Use a code that will reset gui.highlight_mask in |
| 225 | * gui_stop_highlight(). */ |
| 226 | screen_attr = HL_ALL + 1; |
| 227 | else |
| 228 | #endif |
| 229 | /* Use attributes that is very unlikely to appear in text. */ |
| 230 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Mark all windows to be redrawn later. |
| 235 | */ |
| 236 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 237 | redraw_all_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | { |
| 239 | win_T *wp; |
| 240 | |
| 241 | FOR_ALL_WINDOWS(wp) |
| 242 | { |
| 243 | redraw_win_later(wp, type); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 248 | * Mark all windows that are editing the current buffer to be updated later. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 249 | */ |
| 250 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 251 | redraw_curbuf_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 252 | { |
| 253 | redraw_buf_later(curbuf, type); |
| 254 | } |
| 255 | |
| 256 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 257 | redraw_buf_later(buf_T *buf, int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 258 | { |
| 259 | win_T *wp; |
| 260 | |
| 261 | FOR_ALL_WINDOWS(wp) |
| 262 | { |
| 263 | if (wp->w_buffer == buf) |
| 264 | redraw_win_later(wp, type); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /* |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 269 | * Redraw as soon as possible. When the command line is not scrolled redraw |
| 270 | * right away and restore what was on the command line. |
| 271 | * Return a code indicating what happened. |
| 272 | */ |
| 273 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 274 | redraw_asap(int type) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 275 | { |
| 276 | int rows; |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 277 | int cols = screen_Columns; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 278 | int r; |
| 279 | int ret = 0; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 280 | schar_T *screenline; /* copy from ScreenLines[] */ |
| 281 | sattr_T *screenattr; /* copy from ScreenAttrs[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 282 | #ifdef FEAT_MBYTE |
| 283 | int i; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 284 | u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 285 | u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */ |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 286 | schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 287 | #endif |
| 288 | |
| 289 | redraw_later(type); |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 290 | if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 291 | return ret; |
| 292 | |
| 293 | /* Allocate space to save the text displayed in the command line area. */ |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 294 | rows = screen_Rows - cmdline_row; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 295 | screenline = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 296 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 297 | screenattr = (sattr_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 298 | (long_u)(rows * cols * sizeof(sattr_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 299 | if (screenline == NULL || screenattr == NULL) |
| 300 | ret = 2; |
| 301 | #ifdef FEAT_MBYTE |
| 302 | if (enc_utf8) |
| 303 | { |
| 304 | screenlineUC = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 305 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 306 | if (screenlineUC == NULL) |
| 307 | ret = 2; |
| 308 | for (i = 0; i < p_mco; ++i) |
| 309 | { |
| 310 | screenlineC[i] = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 311 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 312 | if (screenlineC[i] == NULL) |
| 313 | ret = 2; |
| 314 | } |
| 315 | } |
| 316 | if (enc_dbcs == DBCS_JPNU) |
| 317 | { |
| 318 | screenline2 = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 319 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 320 | if (screenline2 == NULL) |
| 321 | ret = 2; |
| 322 | } |
| 323 | #endif |
| 324 | |
| 325 | if (ret != 2) |
| 326 | { |
| 327 | /* Save the text displayed in the command line area. */ |
| 328 | for (r = 0; r < rows; ++r) |
| 329 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 330 | mch_memmove(screenline + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 331 | ScreenLines + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 332 | (size_t)cols * sizeof(schar_T)); |
| 333 | mch_memmove(screenattr + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 334 | ScreenAttrs + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 335 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 336 | #ifdef FEAT_MBYTE |
| 337 | if (enc_utf8) |
| 338 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 339 | mch_memmove(screenlineUC + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 340 | ScreenLinesUC + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 341 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 342 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 343 | mch_memmove(screenlineC[i] + r * cols, |
| 344 | ScreenLinesC[i] + LineOffset[cmdline_row + r], |
| 345 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 346 | } |
| 347 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 348 | mch_memmove(screenline2 + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 349 | ScreenLines2 + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 350 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 351 | #endif |
| 352 | } |
| 353 | |
| 354 | update_screen(0); |
| 355 | ret = 3; |
| 356 | |
| 357 | if (must_redraw == 0) |
| 358 | { |
| 359 | int off = (int)(current_ScreenLine - ScreenLines); |
| 360 | |
| 361 | /* Restore the text displayed in the command line area. */ |
| 362 | for (r = 0; r < rows; ++r) |
| 363 | { |
| 364 | mch_memmove(current_ScreenLine, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 365 | screenline + r * cols, |
| 366 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 367 | mch_memmove(ScreenAttrs + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 368 | screenattr + r * cols, |
| 369 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 370 | #ifdef FEAT_MBYTE |
| 371 | if (enc_utf8) |
| 372 | { |
| 373 | mch_memmove(ScreenLinesUC + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 374 | screenlineUC + r * cols, |
| 375 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 376 | for (i = 0; i < p_mco; ++i) |
| 377 | mch_memmove(ScreenLinesC[i] + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 378 | screenlineC[i] + r * cols, |
| 379 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 380 | } |
| 381 | if (enc_dbcs == DBCS_JPNU) |
| 382 | mch_memmove(ScreenLines2 + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 383 | screenline2 + r * cols, |
| 384 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 385 | #endif |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 386 | SCREEN_LINE(cmdline_row + r, 0, cols, cols, FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 387 | } |
| 388 | ret = 4; |
| 389 | } |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | vim_free(screenline); |
| 393 | vim_free(screenattr); |
| 394 | #ifdef FEAT_MBYTE |
| 395 | if (enc_utf8) |
| 396 | { |
| 397 | vim_free(screenlineUC); |
| 398 | for (i = 0; i < p_mco; ++i) |
| 399 | vim_free(screenlineC[i]); |
| 400 | } |
| 401 | if (enc_dbcs == DBCS_JPNU) |
| 402 | vim_free(screenline2); |
| 403 | #endif |
| 404 | |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 405 | /* Show the intro message when appropriate. */ |
| 406 | maybe_intro_message(); |
| 407 | |
| 408 | setcursor(); |
| 409 | |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | /* |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 414 | * Invoked after an asynchronous callback is called. |
| 415 | * If an echo command was used the cursor needs to be put back where |
| 416 | * it belongs. If highlighting was changed a redraw is needed. |
| 417 | */ |
| 418 | void |
Bram Moolenaar | cf08946 | 2016-06-12 21:18:43 +0200 | [diff] [blame] | 419 | redraw_after_callback(void) |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 420 | { |
Bram Moolenaar | bfb96c0 | 2016-03-19 17:05:20 +0100 | [diff] [blame] | 421 | if (State == HITRETURN || State == ASKMORE) |
| 422 | ; /* do nothing */ |
| 423 | else if (State & CMDLINE) |
| 424 | redrawcmdline(); |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 425 | else if (State & (NORMAL | INSERT)) |
Bram Moolenaar | bfb96c0 | 2016-03-19 17:05:20 +0100 | [diff] [blame] | 426 | { |
| 427 | update_screen(0); |
| 428 | setcursor(); |
| 429 | } |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 430 | cursor_on(); |
| 431 | out_flush(); |
| 432 | #ifdef FEAT_GUI |
| 433 | if (gui.in_use) |
| 434 | { |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 435 | /* Don't update the cursor when it is blinking and off to avoid |
| 436 | * flicker. */ |
| 437 | if (!gui_mch_is_blink_off()) |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 438 | gui_update_cursor(FALSE, FALSE); |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 439 | gui_mch_flush(); |
| 440 | } |
| 441 | #endif |
| 442 | } |
| 443 | |
| 444 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 445 | * Changed something in the current window, at buffer line "lnum", that |
| 446 | * requires that line and possibly other lines to be redrawn. |
| 447 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 448 | * Used to remove the "$" from a change command. |
| 449 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 450 | * may become invalid and the whole window will have to be redrawn. |
| 451 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 452 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 453 | redrawWinline( |
| 454 | linenr_T lnum, |
| 455 | int invalid UNUSED) /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 456 | { |
| 457 | #ifdef FEAT_FOLDING |
| 458 | int i; |
| 459 | #endif |
| 460 | |
| 461 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 462 | curwin->w_redraw_top = lnum; |
| 463 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 464 | curwin->w_redraw_bot = lnum; |
| 465 | redraw_later(VALID); |
| 466 | |
| 467 | #ifdef FEAT_FOLDING |
| 468 | if (invalid) |
| 469 | { |
| 470 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 471 | i = find_wl_entry(curwin, lnum); |
| 472 | if (i >= 0) |
| 473 | curwin->w_lines[i].wl_valid = FALSE; |
| 474 | } |
| 475 | #endif |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * update all windows that are editing the current buffer |
| 480 | */ |
| 481 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 482 | update_curbuf(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 483 | { |
| 484 | redraw_curbuf_later(type); |
| 485 | update_screen(type); |
| 486 | } |
| 487 | |
| 488 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 489 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 490 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 491 | */ |
| 492 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 493 | update_screen(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 494 | { |
| 495 | win_T *wp; |
| 496 | static int did_intro = FALSE; |
| 497 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 498 | int did_one; |
| 499 | #endif |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 500 | #ifdef FEAT_GUI |
| 501 | int gui_cursor_col; |
| 502 | int gui_cursor_row; |
| 503 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 504 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 505 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 506 | if (!screen_valid(TRUE)) |
| 507 | return; |
| 508 | |
| 509 | if (must_redraw) |
| 510 | { |
| 511 | if (type < must_redraw) /* use maximal type */ |
| 512 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 513 | |
| 514 | /* must_redraw is reset here, so that when we run into some weird |
| 515 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 516 | * scrolling), or update_topline() in win_update() will cause a |
| 517 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 518 | must_redraw = 0; |
| 519 | } |
| 520 | |
| 521 | /* Need to update w_lines[]. */ |
| 522 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 523 | type = NOT_VALID; |
| 524 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 525 | /* Postpone the redrawing when it's not needed and when being called |
| 526 | * recursively. */ |
| 527 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 528 | { |
| 529 | redraw_later(type); /* remember type for next time */ |
| 530 | must_redraw = type; |
| 531 | if (type > INVERTED_ALL) |
| 532 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | updating_screen = TRUE; |
| 537 | #ifdef FEAT_SYN_HL |
| 538 | ++display_tick; /* let syntax code know we're in a next round of |
| 539 | * display updating */ |
| 540 | #endif |
| 541 | |
| 542 | /* |
| 543 | * if the screen was scrolled up when displaying a message, scroll it down |
| 544 | */ |
| 545 | if (msg_scrolled) |
| 546 | { |
| 547 | clear_cmdline = TRUE; |
| 548 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 549 | type = CLEAR; |
| 550 | else if (type != CLEAR) |
| 551 | { |
| 552 | check_for_delay(FALSE); |
| 553 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 554 | type = CLEAR; |
| 555 | FOR_ALL_WINDOWS(wp) |
| 556 | { |
| 557 | if (W_WINROW(wp) < msg_scrolled) |
| 558 | { |
| 559 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 560 | && wp->w_redr_type < REDRAW_TOP |
| 561 | && wp->w_lines_valid > 0 |
| 562 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 563 | { |
| 564 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 565 | wp->w_redr_type = REDRAW_TOP; |
| 566 | } |
| 567 | else |
| 568 | { |
| 569 | wp->w_redr_type = NOT_VALID; |
| 570 | #ifdef FEAT_WINDOWS |
| 571 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 572 | <= msg_scrolled) |
| 573 | wp->w_redr_status = TRUE; |
| 574 | #endif |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 579 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 580 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 581 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 582 | } |
| 583 | msg_scrolled = 0; |
| 584 | need_wait_return = FALSE; |
| 585 | } |
| 586 | |
| 587 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 588 | compute_cmdrow(); |
| 589 | |
| 590 | /* Check for changed highlighting */ |
| 591 | if (need_highlight_changed) |
| 592 | highlight_changed(); |
| 593 | |
| 594 | if (type == CLEAR) /* first clear screen */ |
| 595 | { |
| 596 | screenclear(); /* will reset clear_cmdline */ |
| 597 | type = NOT_VALID; |
| 598 | } |
| 599 | |
| 600 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 601 | check_for_delay(FALSE); |
| 602 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 603 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 604 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 605 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 606 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 607 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 608 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 609 | curwin->w_redr_type = NOT_VALID; |
| 610 | #endif |
| 611 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 612 | /* |
| 613 | * Only start redrawing if there is really something to do. |
| 614 | */ |
| 615 | if (type == INVERTED) |
| 616 | update_curswant(); |
| 617 | if (curwin->w_redr_type < type |
| 618 | && !((type == VALID |
| 619 | && curwin->w_lines[0].wl_valid |
| 620 | #ifdef FEAT_DIFF |
| 621 | && curwin->w_topfill == curwin->w_old_topfill |
| 622 | && curwin->w_botfill == curwin->w_old_botfill |
| 623 | #endif |
| 624 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 625 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 626 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 627 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 628 | && curwin->w_old_visual_mode == VIsual_mode |
| 629 | && (curwin->w_valid & VALID_VIRTCOL) |
| 630 | && curwin->w_old_curswant == curwin->w_curswant) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 631 | )) |
| 632 | curwin->w_redr_type = type; |
| 633 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 634 | #ifdef FEAT_WINDOWS |
| 635 | /* Redraw the tab pages line if needed. */ |
| 636 | if (redraw_tabline || type >= NOT_VALID) |
| 637 | draw_tabline(); |
| 638 | #endif |
| 639 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 640 | #ifdef FEAT_SYN_HL |
| 641 | /* |
| 642 | * Correct stored syntax highlighting info for changes in each displayed |
| 643 | * buffer. Each buffer must only be done once. |
| 644 | */ |
| 645 | FOR_ALL_WINDOWS(wp) |
| 646 | { |
| 647 | if (wp->w_buffer->b_mod_set) |
| 648 | { |
| 649 | # ifdef FEAT_WINDOWS |
| 650 | win_T *wwp; |
| 651 | |
| 652 | /* Check if we already did this buffer. */ |
| 653 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 654 | if (wwp->w_buffer == wp->w_buffer) |
| 655 | break; |
| 656 | # endif |
| 657 | if ( |
| 658 | # ifdef FEAT_WINDOWS |
| 659 | wwp == wp && |
| 660 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 661 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 662 | syn_stack_apply_changes(wp->w_buffer); |
| 663 | } |
| 664 | } |
| 665 | #endif |
| 666 | |
| 667 | /* |
| 668 | * Go from top to bottom through the windows, redrawing the ones that need |
| 669 | * it. |
| 670 | */ |
| 671 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 672 | did_one = FALSE; |
| 673 | #endif |
| 674 | #ifdef FEAT_SEARCH_EXTRA |
| 675 | search_hl.rm.regprog = NULL; |
| 676 | #endif |
| 677 | FOR_ALL_WINDOWS(wp) |
| 678 | { |
| 679 | if (wp->w_redr_type != 0) |
| 680 | { |
| 681 | cursor_off(); |
| 682 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 683 | if (!did_one) |
| 684 | { |
| 685 | did_one = TRUE; |
| 686 | # ifdef FEAT_SEARCH_EXTRA |
| 687 | start_search_hl(); |
| 688 | # endif |
| 689 | # ifdef FEAT_CLIPBOARD |
| 690 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 691 | if (clip_star.available && clip_isautosel_star()) |
| 692 | clip_update_selection(&clip_star); |
| 693 | if (clip_plus.available && clip_isautosel_plus()) |
| 694 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 695 | # endif |
| 696 | #ifdef FEAT_GUI |
| 697 | /* Remove the cursor before starting to do anything, because |
| 698 | * scrolling may make it difficult to redraw the text under |
| 699 | * it. */ |
| 700 | if (gui.in_use) |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 701 | { |
| 702 | gui_cursor_col = gui.cursor_col; |
| 703 | gui_cursor_row = gui.cursor_row; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 704 | gui_undraw_cursor(); |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 705 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 706 | #endif |
| 707 | } |
| 708 | #endif |
| 709 | win_update(wp); |
| 710 | } |
| 711 | |
| 712 | #ifdef FEAT_WINDOWS |
| 713 | /* redraw status line after the window to minimize cursor movement */ |
| 714 | if (wp->w_redr_status) |
| 715 | { |
| 716 | cursor_off(); |
| 717 | win_redr_status(wp); |
| 718 | } |
| 719 | #endif |
| 720 | } |
| 721 | #if defined(FEAT_SEARCH_EXTRA) |
| 722 | end_search_hl(); |
| 723 | #endif |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 724 | #ifdef FEAT_INS_EXPAND |
| 725 | /* May need to redraw the popup menu. */ |
| 726 | if (pum_visible()) |
| 727 | pum_redraw(); |
| 728 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 729 | |
| 730 | #ifdef FEAT_WINDOWS |
| 731 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 732 | * than going through all buffers (there could be many buffers). */ |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 733 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 734 | wp->w_buffer->b_mod_set = FALSE; |
| 735 | #else |
| 736 | curbuf->b_mod_set = FALSE; |
| 737 | #endif |
| 738 | |
| 739 | updating_screen = FALSE; |
| 740 | #ifdef FEAT_GUI |
| 741 | gui_may_resize_shell(); |
| 742 | #endif |
| 743 | |
| 744 | /* Clear or redraw the command line. Done last, because scrolling may |
| 745 | * mess up the command line. */ |
| 746 | if (clear_cmdline || redraw_cmdline) |
| 747 | showmode(); |
| 748 | |
| 749 | /* May put up an introductory message when not editing a file */ |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 750 | if (!did_intro) |
| 751 | maybe_intro_message(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 752 | did_intro = TRUE; |
| 753 | |
| 754 | #ifdef FEAT_GUI |
| 755 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 756 | * done. */ |
| 757 | if (gui.in_use) |
| 758 | { |
| 759 | out_flush(); /* required before updating the cursor */ |
Bram Moolenaar | da3a77d | 2016-07-10 23:16:09 +0200 | [diff] [blame] | 760 | if (did_one && !gui_mch_is_blink_off()) |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 761 | { |
| 762 | /* Put the GUI position where the cursor was, gui_update_cursor() |
| 763 | * uses that. */ |
| 764 | gui.col = gui_cursor_col; |
| 765 | gui.row = gui_cursor_row; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 766 | gui_update_cursor(FALSE, FALSE); |
Bram Moolenaar | 65549bd | 2016-07-08 22:52:37 +0200 | [diff] [blame] | 767 | screen_cur_col = gui.col; |
| 768 | screen_cur_row = gui.row; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 769 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 770 | gui_update_scrollbars(FALSE); |
| 771 | } |
| 772 | #endif |
| 773 | } |
| 774 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 775 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 776 | /* |
| 777 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 778 | * to the 'concealcursor' option. |
| 779 | */ |
| 780 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 781 | conceal_cursor_line(win_T *wp) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 782 | { |
| 783 | int c; |
| 784 | |
| 785 | if (*wp->w_p_cocu == NUL) |
| 786 | return FALSE; |
| 787 | if (get_real_state() & VISUAL) |
| 788 | c = 'v'; |
| 789 | else if (State & INSERT) |
| 790 | c = 'i'; |
| 791 | else if (State & NORMAL) |
| 792 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 793 | else if (State & CMDLINE) |
| 794 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 795 | else |
| 796 | return FALSE; |
| 797 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 802 | */ |
| 803 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 804 | conceal_check_cursur_line(void) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 805 | { |
| 806 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 807 | { |
| 808 | need_cursor_line_redraw = TRUE; |
| 809 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 810 | * without concealing. */ |
| 811 | curs_columns(TRUE); |
| 812 | } |
| 813 | } |
| 814 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 815 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 816 | update_single_line(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 817 | { |
| 818 | int row; |
| 819 | int j; |
| 820 | |
Bram Moolenaar | 908be43 | 2016-05-24 10:51:30 +0200 | [diff] [blame] | 821 | /* Don't do anything if the screen structures are (not yet) valid. */ |
| 822 | if (!screen_valid(TRUE)) |
| 823 | return; |
| 824 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 825 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 826 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 827 | { |
| 828 | # ifdef FEAT_GUI |
| 829 | /* Remove the cursor before starting to do anything, because scrolling |
| 830 | * may make it difficult to redraw the text under it. */ |
| 831 | if (gui.in_use) |
| 832 | gui_undraw_cursor(); |
| 833 | # endif |
| 834 | row = 0; |
| 835 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 836 | { |
| 837 | if (lnum == wp->w_lines[j].wl_lnum) |
| 838 | { |
| 839 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 840 | # ifdef FEAT_SEARCH_EXTRA |
| 841 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 842 | start_search_hl(); |
| 843 | prepare_search_hl(wp, lnum); |
| 844 | # endif |
| 845 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 846 | # if defined(FEAT_SEARCH_EXTRA) |
| 847 | end_search_hl(); |
| 848 | # endif |
| 849 | break; |
| 850 | } |
| 851 | row += wp->w_lines[j].wl_size; |
| 852 | } |
| 853 | # ifdef FEAT_GUI |
| 854 | /* Redraw the cursor */ |
| 855 | if (gui.in_use) |
| 856 | { |
| 857 | out_flush(); /* required before updating the cursor */ |
| 858 | gui_update_cursor(FALSE, FALSE); |
| 859 | } |
| 860 | # endif |
| 861 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 862 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 863 | } |
| 864 | #endif |
| 865 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 866 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 867 | static void update_prepare(void); |
| 868 | static void update_finish(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 872 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 873 | */ |
| 874 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 875 | update_prepare(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 876 | { |
| 877 | cursor_off(); |
| 878 | updating_screen = TRUE; |
| 879 | #ifdef FEAT_GUI |
| 880 | /* Remove the cursor before starting to do anything, because scrolling may |
| 881 | * make it difficult to redraw the text under it. */ |
| 882 | if (gui.in_use) |
| 883 | gui_undraw_cursor(); |
| 884 | #endif |
| 885 | #ifdef FEAT_SEARCH_EXTRA |
| 886 | start_search_hl(); |
| 887 | #endif |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | * Finish updating one or more windows. |
| 892 | */ |
| 893 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 894 | update_finish(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 895 | { |
| 896 | if (redraw_cmdline) |
| 897 | showmode(); |
| 898 | |
| 899 | # ifdef FEAT_SEARCH_EXTRA |
| 900 | end_search_hl(); |
| 901 | # endif |
| 902 | |
| 903 | updating_screen = FALSE; |
| 904 | |
| 905 | # ifdef FEAT_GUI |
| 906 | gui_may_resize_shell(); |
| 907 | |
| 908 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 909 | * done. */ |
| 910 | if (gui.in_use) |
| 911 | { |
| 912 | out_flush(); /* required before updating the cursor */ |
| 913 | gui_update_cursor(FALSE, FALSE); |
| 914 | gui_update_scrollbars(FALSE); |
| 915 | } |
| 916 | # endif |
| 917 | } |
| 918 | #endif |
| 919 | |
| 920 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 921 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 922 | update_debug_sign(buf_T *buf, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 923 | { |
| 924 | win_T *wp; |
| 925 | int doit = FALSE; |
| 926 | |
| 927 | # ifdef FEAT_FOLDING |
| 928 | win_foldinfo.fi_level = 0; |
| 929 | # endif |
| 930 | |
| 931 | /* update/delete a specific mark */ |
| 932 | FOR_ALL_WINDOWS(wp) |
| 933 | { |
| 934 | if (buf != NULL && lnum > 0) |
| 935 | { |
| 936 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 937 | && lnum < wp->w_botline) |
| 938 | { |
| 939 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 940 | wp->w_redraw_top = lnum; |
| 941 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 942 | wp->w_redraw_bot = lnum; |
| 943 | redraw_win_later(wp, VALID); |
| 944 | } |
| 945 | } |
| 946 | else |
| 947 | redraw_win_later(wp, VALID); |
| 948 | if (wp->w_redr_type != 0) |
| 949 | doit = TRUE; |
| 950 | } |
| 951 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 952 | /* Return when there is nothing to do, screen updating is already |
| 953 | * happening (recursive call) or still starting up. */ |
| 954 | if (!doit || updating_screen |
| 955 | #ifdef FEAT_GUI |
| 956 | || gui.starting |
| 957 | #endif |
| 958 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 959 | return; |
| 960 | |
| 961 | /* update all windows that need updating */ |
| 962 | update_prepare(); |
| 963 | |
| 964 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 965 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 966 | { |
| 967 | if (wp->w_redr_type != 0) |
| 968 | win_update(wp); |
| 969 | if (wp->w_redr_status) |
| 970 | win_redr_status(wp); |
| 971 | } |
| 972 | # else |
| 973 | if (curwin->w_redr_type != 0) |
| 974 | win_update(curwin); |
| 975 | # endif |
| 976 | |
| 977 | update_finish(); |
| 978 | } |
| 979 | #endif |
| 980 | |
| 981 | |
| 982 | #if defined(FEAT_GUI) || defined(PROTO) |
| 983 | /* |
| 984 | * Update a single window, its status line and maybe the command line msg. |
| 985 | * Used for the GUI scrollbar. |
| 986 | */ |
| 987 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 988 | updateWindow(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 989 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 990 | /* return if already busy updating */ |
| 991 | if (updating_screen) |
| 992 | return; |
| 993 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 994 | update_prepare(); |
| 995 | |
| 996 | #ifdef FEAT_CLIPBOARD |
| 997 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 998 | if (clip_star.available && clip_isautosel_star()) |
| 999 | clip_update_selection(&clip_star); |
| 1000 | if (clip_plus.available && clip_isautosel_plus()) |
| 1001 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1002 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1003 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1004 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1005 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1007 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 1008 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1009 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1010 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1011 | if (wp->w_redr_status |
| 1012 | # ifdef FEAT_CMDL_INFO |
| 1013 | || p_ru |
| 1014 | # endif |
| 1015 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 1016 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1017 | # endif |
| 1018 | ) |
| 1019 | win_redr_status(wp); |
| 1020 | #endif |
| 1021 | |
| 1022 | update_finish(); |
| 1023 | } |
| 1024 | #endif |
| 1025 | |
| 1026 | /* |
| 1027 | * Update a single window. |
| 1028 | * |
| 1029 | * This may cause the windows below it also to be redrawn (when clearing the |
| 1030 | * screen or scrolling lines). |
| 1031 | * |
| 1032 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 1033 | * implies the one below it. |
| 1034 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1035 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1036 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 1037 | * INVERTED redraw the changed part of the Visual area |
| 1038 | * INVERTED_ALL redraw the whole Visual area |
| 1039 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 1040 | * 2. update lines at the top when scrolled down |
| 1041 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 1042 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1043 | * b_mod_top and b_mod_bot. |
| 1044 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 1045 | * wp->w_redraw_top and wp->w_redr_bot. |
| 1046 | * - continue redrawing when syntax status is invalid. |
| 1047 | * 4. if scrolled up, update lines at the bottom. |
| 1048 | * This results in three areas that may need updating: |
| 1049 | * top: from first row to top_end (when scrolled down) |
| 1050 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1051 | * bot: from bot_start to last row (when scrolled up) |
| 1052 | */ |
| 1053 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 1054 | win_update(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1055 | { |
| 1056 | buf_T *buf = wp->w_buffer; |
| 1057 | int type; |
| 1058 | int top_end = 0; /* Below last row of the top area that needs |
| 1059 | updating. 0 when no top area updating. */ |
| 1060 | int mid_start = 999;/* first row of the mid area that needs |
| 1061 | updating. 999 when no mid area updating. */ |
| 1062 | int mid_end = 0; /* Below last row of the mid area that needs |
| 1063 | updating. 0 when no mid area updating. */ |
| 1064 | int bot_start = 999;/* first row of the bot area that needs |
| 1065 | updating. 999 when no bot area updating */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1066 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 1067 | w_topline got smaller a bit */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1068 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1069 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1070 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 1071 | #endif |
| 1072 | |
| 1073 | int row; /* current window row to display */ |
| 1074 | linenr_T lnum; /* current buffer lnum to display */ |
| 1075 | int idx; /* current index in w_lines[] */ |
| 1076 | int srow; /* starting row of the current line */ |
| 1077 | |
| 1078 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 1079 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 1080 | int i; |
| 1081 | long j; |
| 1082 | static int recursive = FALSE; /* being called recursively */ |
| 1083 | int old_botline = wp->w_botline; |
| 1084 | #ifdef FEAT_FOLDING |
| 1085 | long fold_count; |
| 1086 | #endif |
| 1087 | #ifdef FEAT_SYN_HL |
| 1088 | /* remember what happened to the previous line, to know if |
| 1089 | * check_visual_highlight() can be used */ |
| 1090 | #define DID_NONE 1 /* didn't update a line */ |
| 1091 | #define DID_LINE 2 /* updated a normal line */ |
| 1092 | #define DID_FOLD 3 /* updated a folded line */ |
| 1093 | int did_update = DID_NONE; |
| 1094 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 1095 | #endif |
| 1096 | linenr_T mod_top = 0; |
| 1097 | linenr_T mod_bot = 0; |
| 1098 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1099 | int save_got_int; |
| 1100 | #endif |
| 1101 | |
| 1102 | type = wp->w_redr_type; |
| 1103 | |
| 1104 | if (type == NOT_VALID) |
| 1105 | { |
| 1106 | #ifdef FEAT_WINDOWS |
| 1107 | wp->w_redr_status = TRUE; |
| 1108 | #endif |
| 1109 | wp->w_lines_valid = 0; |
| 1110 | } |
| 1111 | |
| 1112 | /* Window is zero-height: nothing to draw. */ |
| 1113 | if (wp->w_height == 0) |
| 1114 | { |
| 1115 | wp->w_redr_type = 0; |
| 1116 | return; |
| 1117 | } |
| 1118 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 1119 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1120 | /* Window is zero-width: Only need to draw the separator. */ |
| 1121 | if (wp->w_width == 0) |
| 1122 | { |
| 1123 | /* draw the vertical separator right of this window */ |
| 1124 | draw_vsep_win(wp, 0); |
| 1125 | wp->w_redr_type = 0; |
| 1126 | return; |
| 1127 | } |
| 1128 | #endif |
| 1129 | |
| 1130 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 1131 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1132 | #endif |
| 1133 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1134 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 1135 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 1136 | * changes. */ |
| 1137 | 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] | 1138 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1139 | { |
| 1140 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1141 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1142 | } |
| 1143 | else |
| 1144 | #endif |
| 1145 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1146 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 1147 | { |
| 1148 | /* |
| 1149 | * When there are both inserted/deleted lines and specific lines to be |
| 1150 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 1151 | * everything (only happens when redrawing is off for while). |
| 1152 | */ |
| 1153 | type = NOT_VALID; |
| 1154 | } |
| 1155 | else |
| 1156 | { |
| 1157 | /* |
| 1158 | * Set mod_top to the first line that needs displaying because of |
| 1159 | * changes. Set mod_bot to the first line after the changes. |
| 1160 | */ |
| 1161 | mod_top = wp->w_redraw_top; |
| 1162 | if (wp->w_redraw_bot != 0) |
| 1163 | mod_bot = wp->w_redraw_bot + 1; |
| 1164 | else |
| 1165 | mod_bot = 0; |
| 1166 | wp->w_redraw_top = 0; /* reset for next time */ |
| 1167 | wp->w_redraw_bot = 0; |
| 1168 | if (buf->b_mod_set) |
| 1169 | { |
| 1170 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1171 | { |
| 1172 | mod_top = buf->b_mod_top; |
| 1173 | #ifdef FEAT_SYN_HL |
| 1174 | /* Need to redraw lines above the change that may be included |
| 1175 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1176 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1177 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1178 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1179 | if (mod_top < 1) |
| 1180 | mod_top = 1; |
| 1181 | } |
| 1182 | #endif |
| 1183 | } |
| 1184 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1185 | mod_bot = buf->b_mod_bot; |
| 1186 | |
| 1187 | #ifdef FEAT_SEARCH_EXTRA |
| 1188 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1189 | * change in one line may make the Search highlighting in a |
| 1190 | * previous line invalid. Simple solution: redraw all visible |
| 1191 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1192 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1193 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1194 | if (search_hl.rm.regprog != NULL |
| 1195 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1196 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1197 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1198 | { |
| 1199 | cur = wp->w_match_head; |
| 1200 | while (cur != NULL) |
| 1201 | { |
| 1202 | if (cur->match.regprog != NULL |
| 1203 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1204 | { |
| 1205 | top_to_mod = TRUE; |
| 1206 | break; |
| 1207 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1208 | cur = cur->next; |
| 1209 | } |
| 1210 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1211 | #endif |
| 1212 | } |
| 1213 | #ifdef FEAT_FOLDING |
| 1214 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1215 | { |
| 1216 | linenr_T lnumt, lnumb; |
| 1217 | |
| 1218 | /* |
| 1219 | * A change in a line can cause lines above it to become folded or |
| 1220 | * unfolded. Find the top most buffer line that may be affected. |
| 1221 | * If the line was previously folded and displayed, get the first |
| 1222 | * line of that fold. If the line is folded now, get the first |
| 1223 | * folded line. Use the minimum of these two. |
| 1224 | */ |
| 1225 | |
| 1226 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1227 | * the line below it. If there is no valid entry, use w_topline. |
| 1228 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1229 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1230 | lnumt = wp->w_topline; |
| 1231 | lnumb = MAXLNUM; |
| 1232 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1233 | if (wp->w_lines[i].wl_valid) |
| 1234 | { |
| 1235 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1236 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1237 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1238 | { |
| 1239 | lnumb = wp->w_lines[i].wl_lnum; |
| 1240 | /* When there is a fold column it might need updating |
| 1241 | * in the next line ("J" just above an open fold). */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 1242 | if (compute_foldcolumn(wp, 0) > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1243 | ++lnumb; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1248 | if (mod_top > lnumt) |
| 1249 | mod_top = lnumt; |
| 1250 | |
| 1251 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1252 | --mod_bot; |
| 1253 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1254 | ++mod_bot; |
| 1255 | if (mod_bot < lnumb) |
| 1256 | mod_bot = lnumb; |
| 1257 | } |
| 1258 | #endif |
| 1259 | |
| 1260 | /* When a change starts above w_topline and the end is below |
| 1261 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1262 | * If the end of the change is above w_topline: do like no change was |
| 1263 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1264 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1265 | { |
| 1266 | if (mod_bot > wp->w_topline) |
| 1267 | mod_top = wp->w_topline; |
| 1268 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1269 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1270 | top_end = 1; |
| 1271 | #endif |
| 1272 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1273 | |
| 1274 | /* When line numbers are displayed need to redraw all lines below |
| 1275 | * inserted/deleted lines. */ |
| 1276 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1277 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | /* |
| 1281 | * When only displaying the lines at the top, set top_end. Used when |
| 1282 | * window has scrolled down for msg_scrolled. |
| 1283 | */ |
| 1284 | if (type == REDRAW_TOP) |
| 1285 | { |
| 1286 | j = 0; |
| 1287 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1288 | { |
| 1289 | j += wp->w_lines[i].wl_size; |
| 1290 | if (j >= wp->w_upd_rows) |
| 1291 | { |
| 1292 | top_end = j; |
| 1293 | break; |
| 1294 | } |
| 1295 | } |
| 1296 | if (top_end == 0) |
| 1297 | /* not found (cannot happen?): redraw everything */ |
| 1298 | type = NOT_VALID; |
| 1299 | else |
| 1300 | /* top area defined, the rest is VALID */ |
| 1301 | type = VALID; |
| 1302 | } |
| 1303 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1304 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1305 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1306 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1307 | * called. */ |
| 1308 | if (screen_cleared) |
| 1309 | screen_cleared = MAYBE; |
| 1310 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1311 | /* |
| 1312 | * If there are no changes on the screen that require a complete redraw, |
| 1313 | * handle three cases: |
| 1314 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1315 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1316 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1317 | * w_lines[] that needs updating. |
| 1318 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1319 | if ((type == VALID || type == SOME_VALID |
| 1320 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1321 | #ifdef FEAT_DIFF |
| 1322 | && !wp->w_botfill && !wp->w_old_botfill |
| 1323 | #endif |
| 1324 | ) |
| 1325 | { |
| 1326 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1327 | { |
| 1328 | /* |
| 1329 | * w_topline is the first changed line, the scrolling will be done |
| 1330 | * further down. |
| 1331 | */ |
| 1332 | } |
| 1333 | else if (wp->w_lines[0].wl_valid |
| 1334 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1335 | #ifdef FEAT_DIFF |
| 1336 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1337 | && wp->w_topfill > wp->w_old_topfill) |
| 1338 | #endif |
| 1339 | )) |
| 1340 | { |
| 1341 | /* |
| 1342 | * New topline is above old topline: May scroll down. |
| 1343 | */ |
| 1344 | #ifdef FEAT_FOLDING |
| 1345 | if (hasAnyFolding(wp)) |
| 1346 | { |
| 1347 | linenr_T ln; |
| 1348 | |
| 1349 | /* count the number of lines we are off, counting a sequence |
| 1350 | * of folded lines as one */ |
| 1351 | j = 0; |
| 1352 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1353 | { |
| 1354 | ++j; |
| 1355 | if (j >= wp->w_height - 2) |
| 1356 | break; |
| 1357 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1358 | } |
| 1359 | } |
| 1360 | else |
| 1361 | #endif |
| 1362 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1363 | if (j < wp->w_height - 2) /* not too far off */ |
| 1364 | { |
| 1365 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1366 | #ifdef FEAT_DIFF |
| 1367 | /* insert extra lines for previously invisible filler lines */ |
| 1368 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1369 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1370 | - wp->w_old_topfill; |
| 1371 | #endif |
| 1372 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1373 | { |
| 1374 | /* |
| 1375 | * Try to insert the correct number of lines. |
| 1376 | * If not the last window, delete the lines at the bottom. |
| 1377 | * win_ins_lines may fail when the terminal can't do it. |
| 1378 | */ |
| 1379 | if (i > 0) |
| 1380 | check_for_delay(FALSE); |
| 1381 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1382 | { |
| 1383 | if (wp->w_lines_valid != 0) |
| 1384 | { |
| 1385 | /* Need to update rows that are new, stop at the |
| 1386 | * first one that scrolled down. */ |
| 1387 | top_end = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1388 | scrolled_down = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1389 | |
| 1390 | /* Move the entries that were scrolled, disable |
| 1391 | * the entries for the lines to be redrawn. */ |
| 1392 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1393 | wp->w_lines_valid = wp->w_height; |
| 1394 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1395 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1396 | while (idx >= 0) |
| 1397 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1398 | } |
| 1399 | } |
| 1400 | else |
| 1401 | mid_start = 0; /* redraw all lines */ |
| 1402 | } |
| 1403 | else |
| 1404 | mid_start = 0; /* redraw all lines */ |
| 1405 | } |
| 1406 | else |
| 1407 | mid_start = 0; /* redraw all lines */ |
| 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | /* |
| 1412 | * New topline is at or below old topline: May scroll up. |
| 1413 | * When topline didn't change, find first entry in w_lines[] that |
| 1414 | * needs updating. |
| 1415 | */ |
| 1416 | |
| 1417 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1418 | j = -1; |
| 1419 | row = 0; |
| 1420 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1421 | { |
| 1422 | if (wp->w_lines[i].wl_valid |
| 1423 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1424 | { |
| 1425 | j = i; |
| 1426 | break; |
| 1427 | } |
| 1428 | row += wp->w_lines[i].wl_size; |
| 1429 | } |
| 1430 | if (j == -1) |
| 1431 | { |
| 1432 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1433 | * lines */ |
| 1434 | mid_start = 0; |
| 1435 | } |
| 1436 | else |
| 1437 | { |
| 1438 | /* |
| 1439 | * Try to delete the correct number of lines. |
| 1440 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1441 | */ |
| 1442 | #ifdef FEAT_DIFF |
| 1443 | /* If the topline didn't change, delete old filler lines, |
| 1444 | * otherwise delete filler lines of the new topline... */ |
| 1445 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1446 | row += wp->w_old_topfill; |
| 1447 | else |
| 1448 | row += diff_check_fill(wp, wp->w_topline); |
| 1449 | /* ... but don't delete new filler lines. */ |
| 1450 | row -= wp->w_topfill; |
| 1451 | #endif |
| 1452 | if (row > 0) |
| 1453 | { |
| 1454 | check_for_delay(FALSE); |
| 1455 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1456 | bot_start = wp->w_height - row; |
| 1457 | else |
| 1458 | mid_start = 0; /* redraw all lines */ |
| 1459 | } |
| 1460 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1461 | { |
| 1462 | /* |
| 1463 | * Skip the lines (below the deleted lines) that are still |
| 1464 | * valid and don't need redrawing. Copy their info |
| 1465 | * upwards, to compensate for the deleted lines. Set |
| 1466 | * bot_start to the first row that needs redrawing. |
| 1467 | */ |
| 1468 | bot_start = 0; |
| 1469 | idx = 0; |
| 1470 | for (;;) |
| 1471 | { |
| 1472 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1473 | /* stop at line that didn't fit, unless it is still |
| 1474 | * valid (no lines deleted) */ |
| 1475 | if (row > 0 && bot_start + row |
| 1476 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1477 | { |
| 1478 | wp->w_lines_valid = idx + 1; |
| 1479 | break; |
| 1480 | } |
| 1481 | bot_start += wp->w_lines[idx++].wl_size; |
| 1482 | |
| 1483 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1484 | if (++j >= wp->w_lines_valid) |
| 1485 | { |
| 1486 | wp->w_lines_valid = idx; |
| 1487 | break; |
| 1488 | } |
| 1489 | } |
| 1490 | #ifdef FEAT_DIFF |
| 1491 | /* Correct the first entry for filler lines at the top |
| 1492 | * when it won't get updated below. */ |
| 1493 | if (wp->w_p_diff && bot_start > 0) |
| 1494 | wp->w_lines[0].wl_size = |
| 1495 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1496 | + wp->w_topfill; |
| 1497 | #endif |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | /* When starting redraw in the first line, redraw all lines. When |
| 1503 | * there is only one window it's probably faster to clear the screen |
| 1504 | * first. */ |
| 1505 | if (mid_start == 0) |
| 1506 | { |
| 1507 | mid_end = wp->w_height; |
| 1508 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1509 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1510 | /* Clear the screen when it was not done by win_del_lines() or |
| 1511 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1512 | * then. */ |
| 1513 | if (screen_cleared != TRUE) |
| 1514 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1515 | #ifdef FEAT_WINDOWS |
| 1516 | /* The screen was cleared, redraw the tab pages line. */ |
| 1517 | if (redraw_tabline) |
| 1518 | draw_tabline(); |
| 1519 | #endif |
| 1520 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1521 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1522 | |
| 1523 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1524 | * cleared (only happens for the first window) or when screenclear() |
| 1525 | * was called directly above, "must_redraw" will have been set to |
| 1526 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1527 | if (screen_cleared == TRUE) |
| 1528 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1529 | } |
| 1530 | else |
| 1531 | { |
| 1532 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1533 | mid_start = 0; |
| 1534 | mid_end = wp->w_height; |
| 1535 | } |
| 1536 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1537 | if (type == SOME_VALID) |
| 1538 | { |
| 1539 | /* SOME_VALID: redraw all lines. */ |
| 1540 | mid_start = 0; |
| 1541 | mid_end = wp->w_height; |
| 1542 | type = NOT_VALID; |
| 1543 | } |
| 1544 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1545 | /* check if we are updating or removing the inverted part */ |
| 1546 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1547 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1548 | { |
| 1549 | linenr_T from, to; |
| 1550 | |
| 1551 | if (VIsual_active) |
| 1552 | { |
| 1553 | if (VIsual_active |
| 1554 | && (VIsual_mode != wp->w_old_visual_mode |
| 1555 | || type == INVERTED_ALL)) |
| 1556 | { |
| 1557 | /* |
| 1558 | * If the type of Visual selection changed, redraw the whole |
| 1559 | * selection. Also when the ownership of the X selection is |
| 1560 | * gained or lost. |
| 1561 | */ |
| 1562 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1563 | { |
| 1564 | from = curwin->w_cursor.lnum; |
| 1565 | to = VIsual.lnum; |
| 1566 | } |
| 1567 | else |
| 1568 | { |
| 1569 | from = VIsual.lnum; |
| 1570 | to = curwin->w_cursor.lnum; |
| 1571 | } |
| 1572 | /* redraw more when the cursor moved as well */ |
| 1573 | if (wp->w_old_cursor_lnum < from) |
| 1574 | from = wp->w_old_cursor_lnum; |
| 1575 | if (wp->w_old_cursor_lnum > to) |
| 1576 | to = wp->w_old_cursor_lnum; |
| 1577 | if (wp->w_old_visual_lnum < from) |
| 1578 | from = wp->w_old_visual_lnum; |
| 1579 | if (wp->w_old_visual_lnum > to) |
| 1580 | to = wp->w_old_visual_lnum; |
| 1581 | } |
| 1582 | else |
| 1583 | { |
| 1584 | /* |
| 1585 | * Find the line numbers that need to be updated: The lines |
| 1586 | * between the old cursor position and the current cursor |
| 1587 | * position. Also check if the Visual position changed. |
| 1588 | */ |
| 1589 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1590 | { |
| 1591 | from = curwin->w_cursor.lnum; |
| 1592 | to = wp->w_old_cursor_lnum; |
| 1593 | } |
| 1594 | else |
| 1595 | { |
| 1596 | from = wp->w_old_cursor_lnum; |
| 1597 | to = curwin->w_cursor.lnum; |
| 1598 | if (from == 0) /* Visual mode just started */ |
| 1599 | from = to; |
| 1600 | } |
| 1601 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1602 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1603 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1604 | { |
| 1605 | if (wp->w_old_visual_lnum < from |
| 1606 | && wp->w_old_visual_lnum != 0) |
| 1607 | from = wp->w_old_visual_lnum; |
| 1608 | if (wp->w_old_visual_lnum > to) |
| 1609 | to = wp->w_old_visual_lnum; |
| 1610 | if (VIsual.lnum < from) |
| 1611 | from = VIsual.lnum; |
| 1612 | if (VIsual.lnum > to) |
| 1613 | to = VIsual.lnum; |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | /* |
| 1618 | * If in block mode and changed column or curwin->w_curswant: |
| 1619 | * update all lines. |
| 1620 | * First compute the actual start and end column. |
| 1621 | */ |
| 1622 | if (VIsual_mode == Ctrl_V) |
| 1623 | { |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1624 | colnr_T fromc, toc; |
| 1625 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1626 | int save_ve_flags = ve_flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1627 | |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1628 | if (curwin->w_p_lbr) |
| 1629 | ve_flags = VE_ALL; |
| 1630 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1631 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1632 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1633 | ve_flags = save_ve_flags; |
| 1634 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1635 | ++toc; |
| 1636 | if (curwin->w_curswant == MAXCOL) |
| 1637 | toc = MAXCOL; |
| 1638 | |
| 1639 | if (fromc != wp->w_old_cursor_fcol |
| 1640 | || toc != wp->w_old_cursor_lcol) |
| 1641 | { |
| 1642 | if (from > VIsual.lnum) |
| 1643 | from = VIsual.lnum; |
| 1644 | if (to < VIsual.lnum) |
| 1645 | to = VIsual.lnum; |
| 1646 | } |
| 1647 | wp->w_old_cursor_fcol = fromc; |
| 1648 | wp->w_old_cursor_lcol = toc; |
| 1649 | } |
| 1650 | } |
| 1651 | else |
| 1652 | { |
| 1653 | /* Use the line numbers of the old Visual area. */ |
| 1654 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1655 | { |
| 1656 | from = wp->w_old_cursor_lnum; |
| 1657 | to = wp->w_old_visual_lnum; |
| 1658 | } |
| 1659 | else |
| 1660 | { |
| 1661 | from = wp->w_old_visual_lnum; |
| 1662 | to = wp->w_old_cursor_lnum; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | /* |
| 1667 | * There is no need to update lines above the top of the window. |
| 1668 | */ |
| 1669 | if (from < wp->w_topline) |
| 1670 | from = wp->w_topline; |
| 1671 | |
| 1672 | /* |
| 1673 | * If we know the value of w_botline, use it to restrict the update to |
| 1674 | * the lines that are visible in the window. |
| 1675 | */ |
| 1676 | if (wp->w_valid & VALID_BOTLINE) |
| 1677 | { |
| 1678 | if (from >= wp->w_botline) |
| 1679 | from = wp->w_botline - 1; |
| 1680 | if (to >= wp->w_botline) |
| 1681 | to = wp->w_botline - 1; |
| 1682 | } |
| 1683 | |
| 1684 | /* |
| 1685 | * Find the minimal part to be updated. |
| 1686 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1687 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1688 | * top_end; need to redraw from top_end to the "to" line. |
| 1689 | * A middle mouse click with a Visual selection may change the text |
| 1690 | * above the Visual area and reset wl_valid, do count these for |
| 1691 | * mid_end (in srow). |
| 1692 | */ |
| 1693 | if (mid_start > 0) |
| 1694 | { |
| 1695 | lnum = wp->w_topline; |
| 1696 | idx = 0; |
| 1697 | srow = 0; |
| 1698 | if (scrolled_down) |
| 1699 | mid_start = top_end; |
| 1700 | else |
| 1701 | mid_start = 0; |
| 1702 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1703 | { |
| 1704 | if (wp->w_lines[idx].wl_valid) |
| 1705 | mid_start += wp->w_lines[idx].wl_size; |
| 1706 | else if (!scrolled_down) |
| 1707 | srow += wp->w_lines[idx].wl_size; |
| 1708 | ++idx; |
| 1709 | # ifdef FEAT_FOLDING |
| 1710 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1711 | lnum = wp->w_lines[idx].wl_lnum; |
| 1712 | else |
| 1713 | # endif |
| 1714 | ++lnum; |
| 1715 | } |
| 1716 | srow += mid_start; |
| 1717 | mid_end = wp->w_height; |
| 1718 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1719 | { |
| 1720 | if (wp->w_lines[idx].wl_valid |
| 1721 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1722 | { |
| 1723 | /* Only update until first row of this line */ |
| 1724 | mid_end = srow; |
| 1725 | break; |
| 1726 | } |
| 1727 | srow += wp->w_lines[idx].wl_size; |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | if (VIsual_active && buf == curwin->w_buffer) |
| 1733 | { |
| 1734 | wp->w_old_visual_mode = VIsual_mode; |
| 1735 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1736 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1737 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1738 | wp->w_old_curswant = curwin->w_curswant; |
| 1739 | } |
| 1740 | else |
| 1741 | { |
| 1742 | wp->w_old_visual_mode = 0; |
| 1743 | wp->w_old_cursor_lnum = 0; |
| 1744 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1745 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1746 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1747 | |
| 1748 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1749 | /* reset got_int, otherwise regexp won't work */ |
| 1750 | save_got_int = got_int; |
| 1751 | got_int = 0; |
| 1752 | #endif |
| 1753 | #ifdef FEAT_FOLDING |
| 1754 | win_foldinfo.fi_level = 0; |
| 1755 | #endif |
| 1756 | |
| 1757 | /* |
| 1758 | * Update all the window rows. |
| 1759 | */ |
| 1760 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1761 | row = 0; |
| 1762 | srow = 0; |
| 1763 | lnum = wp->w_topline; /* first line shown in window */ |
| 1764 | for (;;) |
| 1765 | { |
| 1766 | /* stop updating when reached the end of the window (check for _past_ |
| 1767 | * the end of the window is at the end of the loop) */ |
| 1768 | if (row == wp->w_height) |
| 1769 | { |
| 1770 | didline = TRUE; |
| 1771 | break; |
| 1772 | } |
| 1773 | |
| 1774 | /* stop updating when hit the end of the file */ |
| 1775 | if (lnum > buf->b_ml.ml_line_count) |
| 1776 | { |
| 1777 | eof = TRUE; |
| 1778 | break; |
| 1779 | } |
| 1780 | |
| 1781 | /* Remember the starting row of the line that is going to be dealt |
| 1782 | * with. It is used further down when the line doesn't fit. */ |
| 1783 | srow = row; |
| 1784 | |
| 1785 | /* |
| 1786 | * Update a line when it is in an area that needs updating, when it |
| 1787 | * has changes or w_lines[idx] is invalid. |
| 1788 | * bot_start may be halfway a wrapped line after using |
| 1789 | * win_del_lines(), check if the current line includes it. |
| 1790 | * When syntax folding is being used, the saved syntax states will |
| 1791 | * already have been updated, we can't see where the syntax state is |
| 1792 | * the same again, just update until the end of the window. |
| 1793 | */ |
| 1794 | if (row < top_end |
| 1795 | || (row >= mid_start && row < mid_end) |
| 1796 | #ifdef FEAT_SEARCH_EXTRA |
| 1797 | || top_to_mod |
| 1798 | #endif |
| 1799 | || idx >= wp->w_lines_valid |
| 1800 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1801 | || (mod_top != 0 |
| 1802 | && (lnum == mod_top |
| 1803 | || (lnum >= mod_top |
| 1804 | && (lnum < mod_bot |
| 1805 | #ifdef FEAT_SYN_HL |
| 1806 | || did_update == DID_FOLD |
| 1807 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1808 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1809 | && ( |
| 1810 | # ifdef FEAT_FOLDING |
| 1811 | (foldmethodIsSyntax(wp) |
| 1812 | && hasAnyFolding(wp)) || |
| 1813 | # endif |
| 1814 | syntax_check_changed(lnum))) |
| 1815 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1816 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | dab70c6 | 2014-07-02 17:16:58 +0200 | [diff] [blame] | 1817 | /* match in fixed position might need redraw |
| 1818 | * if lines were inserted or deleted */ |
| 1819 | || (wp->w_match_head != NULL |
| 1820 | && buf->b_mod_xlines != 0) |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1821 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1822 | ))))) |
| 1823 | { |
| 1824 | #ifdef FEAT_SEARCH_EXTRA |
| 1825 | if (lnum == mod_top) |
| 1826 | top_to_mod = FALSE; |
| 1827 | #endif |
| 1828 | |
| 1829 | /* |
| 1830 | * When at start of changed lines: May scroll following lines |
| 1831 | * up or down to minimize redrawing. |
| 1832 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1833 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1834 | */ |
| 1835 | if (lnum == mod_top |
| 1836 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1837 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1838 | { |
| 1839 | int old_rows = 0; |
| 1840 | int new_rows = 0; |
| 1841 | int xtra_rows; |
| 1842 | linenr_T l; |
| 1843 | |
| 1844 | /* Count the old number of window rows, using w_lines[], which |
| 1845 | * should still contain the sizes for the lines as they are |
| 1846 | * currently displayed. */ |
| 1847 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1848 | { |
| 1849 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1850 | * lines are part of the changed area. */ |
| 1851 | if (wp->w_lines[i].wl_valid |
| 1852 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1853 | break; |
| 1854 | old_rows += wp->w_lines[i].wl_size; |
| 1855 | #ifdef FEAT_FOLDING |
| 1856 | if (wp->w_lines[i].wl_valid |
| 1857 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1858 | { |
| 1859 | /* Must have found the last valid entry above mod_bot. |
| 1860 | * Add following invalid entries. */ |
| 1861 | ++i; |
| 1862 | while (i < wp->w_lines_valid |
| 1863 | && !wp->w_lines[i].wl_valid) |
| 1864 | old_rows += wp->w_lines[i++].wl_size; |
| 1865 | break; |
| 1866 | } |
| 1867 | #endif |
| 1868 | } |
| 1869 | |
| 1870 | if (i >= wp->w_lines_valid) |
| 1871 | { |
| 1872 | /* We can't find a valid line below the changed lines, |
| 1873 | * need to redraw until the end of the window. |
| 1874 | * Inserting/deleting lines has no use. */ |
| 1875 | bot_start = 0; |
| 1876 | } |
| 1877 | else |
| 1878 | { |
| 1879 | /* Able to count old number of rows: Count new window |
| 1880 | * rows, and may insert/delete lines */ |
| 1881 | j = idx; |
| 1882 | for (l = lnum; l < mod_bot; ++l) |
| 1883 | { |
| 1884 | #ifdef FEAT_FOLDING |
| 1885 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1886 | ++new_rows; |
| 1887 | else |
| 1888 | #endif |
| 1889 | #ifdef FEAT_DIFF |
| 1890 | if (l == wp->w_topline) |
| 1891 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1892 | + wp->w_topfill; |
| 1893 | else |
| 1894 | #endif |
| 1895 | new_rows += plines_win(wp, l, TRUE); |
| 1896 | ++j; |
| 1897 | if (new_rows > wp->w_height - row - 2) |
| 1898 | { |
| 1899 | /* it's getting too much, must redraw the rest */ |
| 1900 | new_rows = 9999; |
| 1901 | break; |
| 1902 | } |
| 1903 | } |
| 1904 | xtra_rows = new_rows - old_rows; |
| 1905 | if (xtra_rows < 0) |
| 1906 | { |
| 1907 | /* May scroll text up. If there is not enough |
| 1908 | * remaining text or scrolling fails, must redraw the |
| 1909 | * rest. If scrolling works, must redraw the text |
| 1910 | * below the scrolled text. */ |
| 1911 | if (row - xtra_rows >= wp->w_height - 2) |
| 1912 | mod_bot = MAXLNUM; |
| 1913 | else |
| 1914 | { |
| 1915 | check_for_delay(FALSE); |
| 1916 | if (win_del_lines(wp, row, |
| 1917 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1918 | mod_bot = MAXLNUM; |
| 1919 | else |
| 1920 | bot_start = wp->w_height + xtra_rows; |
| 1921 | } |
| 1922 | } |
| 1923 | else if (xtra_rows > 0) |
| 1924 | { |
| 1925 | /* May scroll text down. If there is not enough |
| 1926 | * remaining text of scrolling fails, must redraw the |
| 1927 | * rest. */ |
| 1928 | if (row + xtra_rows >= wp->w_height - 2) |
| 1929 | mod_bot = MAXLNUM; |
| 1930 | else |
| 1931 | { |
| 1932 | check_for_delay(FALSE); |
| 1933 | if (win_ins_lines(wp, row + old_rows, |
| 1934 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1935 | mod_bot = MAXLNUM; |
| 1936 | else if (top_end > row + old_rows) |
| 1937 | /* Scrolled the part at the top that requires |
| 1938 | * updating down. */ |
| 1939 | top_end += xtra_rows; |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | /* When not updating the rest, may need to move w_lines[] |
| 1944 | * entries. */ |
| 1945 | if (mod_bot != MAXLNUM && i != j) |
| 1946 | { |
| 1947 | if (j < i) |
| 1948 | { |
| 1949 | int x = row + new_rows; |
| 1950 | |
| 1951 | /* move entries in w_lines[] upwards */ |
| 1952 | for (;;) |
| 1953 | { |
| 1954 | /* stop at last valid entry in w_lines[] */ |
| 1955 | if (i >= wp->w_lines_valid) |
| 1956 | { |
| 1957 | wp->w_lines_valid = j; |
| 1958 | break; |
| 1959 | } |
| 1960 | wp->w_lines[j] = wp->w_lines[i]; |
| 1961 | /* stop at a line that won't fit */ |
| 1962 | if (x + (int)wp->w_lines[j].wl_size |
| 1963 | > wp->w_height) |
| 1964 | { |
| 1965 | wp->w_lines_valid = j + 1; |
| 1966 | break; |
| 1967 | } |
| 1968 | x += wp->w_lines[j++].wl_size; |
| 1969 | ++i; |
| 1970 | } |
| 1971 | if (bot_start > x) |
| 1972 | bot_start = x; |
| 1973 | } |
| 1974 | else /* j > i */ |
| 1975 | { |
| 1976 | /* move entries in w_lines[] downwards */ |
| 1977 | j -= i; |
| 1978 | wp->w_lines_valid += j; |
| 1979 | if (wp->w_lines_valid > wp->w_height) |
| 1980 | wp->w_lines_valid = wp->w_height; |
| 1981 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1982 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1983 | |
| 1984 | /* The w_lines[] entries for inserted lines are |
| 1985 | * now invalid, but wl_size may be used above. |
| 1986 | * Reset to zero. */ |
| 1987 | while (i >= idx) |
| 1988 | { |
| 1989 | wp->w_lines[i].wl_size = 0; |
| 1990 | wp->w_lines[i--].wl_valid = FALSE; |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | #ifdef FEAT_FOLDING |
| 1998 | /* |
| 1999 | * When lines are folded, display one line for all of them. |
| 2000 | * Otherwise, display normally (can be several display lines when |
| 2001 | * 'wrap' is on). |
| 2002 | */ |
| 2003 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 2004 | if (fold_count != 0) |
| 2005 | { |
| 2006 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 2007 | ++row; |
| 2008 | --fold_count; |
| 2009 | wp->w_lines[idx].wl_folded = TRUE; |
| 2010 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 2011 | # ifdef FEAT_SYN_HL |
| 2012 | did_update = DID_FOLD; |
| 2013 | # endif |
| 2014 | } |
| 2015 | else |
| 2016 | #endif |
| 2017 | if (idx < wp->w_lines_valid |
| 2018 | && wp->w_lines[idx].wl_valid |
| 2019 | && wp->w_lines[idx].wl_lnum == lnum |
| 2020 | && lnum > wp->w_topline |
| 2021 | && !(dy_flags & DY_LASTLINE) |
| 2022 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 2023 | #ifdef FEAT_DIFF |
| 2024 | && diff_check_fill(wp, lnum) == 0 |
| 2025 | #endif |
| 2026 | ) |
| 2027 | { |
| 2028 | /* This line is not going to fit. Don't draw anything here, |
| 2029 | * will draw "@ " lines below. */ |
| 2030 | row = wp->w_height + 1; |
| 2031 | } |
| 2032 | else |
| 2033 | { |
| 2034 | #ifdef FEAT_SEARCH_EXTRA |
| 2035 | prepare_search_hl(wp, lnum); |
| 2036 | #endif |
| 2037 | #ifdef FEAT_SYN_HL |
| 2038 | /* Let the syntax stuff know we skipped a few lines. */ |
| 2039 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2040 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2041 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2042 | #endif |
| 2043 | |
| 2044 | /* |
| 2045 | * Display one line. |
| 2046 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2047 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2048 | |
| 2049 | #ifdef FEAT_FOLDING |
| 2050 | wp->w_lines[idx].wl_folded = FALSE; |
| 2051 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2052 | #endif |
| 2053 | #ifdef FEAT_SYN_HL |
| 2054 | did_update = DID_LINE; |
| 2055 | syntax_last_parsed = lnum; |
| 2056 | #endif |
| 2057 | } |
| 2058 | |
| 2059 | wp->w_lines[idx].wl_lnum = lnum; |
| 2060 | wp->w_lines[idx].wl_valid = TRUE; |
| 2061 | if (row > wp->w_height) /* past end of screen */ |
| 2062 | { |
| 2063 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2064 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2065 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2066 | ++idx; |
| 2067 | break; |
| 2068 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2069 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2070 | wp->w_lines[idx].wl_size = row - srow; |
| 2071 | ++idx; |
| 2072 | #ifdef FEAT_FOLDING |
| 2073 | lnum += fold_count + 1; |
| 2074 | #else |
| 2075 | ++lnum; |
| 2076 | #endif |
| 2077 | } |
| 2078 | else |
| 2079 | { |
| 2080 | /* This line does not need updating, advance to the next one */ |
| 2081 | row += wp->w_lines[idx++].wl_size; |
| 2082 | if (row > wp->w_height) /* past end of screen */ |
| 2083 | break; |
| 2084 | #ifdef FEAT_FOLDING |
| 2085 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2086 | #else |
| 2087 | ++lnum; |
| 2088 | #endif |
| 2089 | #ifdef FEAT_SYN_HL |
| 2090 | did_update = DID_NONE; |
| 2091 | #endif |
| 2092 | } |
| 2093 | |
| 2094 | if (lnum > buf->b_ml.ml_line_count) |
| 2095 | { |
| 2096 | eof = TRUE; |
| 2097 | break; |
| 2098 | } |
| 2099 | } |
| 2100 | /* |
| 2101 | * End of loop over all window lines. |
| 2102 | */ |
| 2103 | |
| 2104 | |
| 2105 | if (idx > wp->w_lines_valid) |
| 2106 | wp->w_lines_valid = idx; |
| 2107 | |
| 2108 | #ifdef FEAT_SYN_HL |
| 2109 | /* |
| 2110 | * Let the syntax stuff know we stop parsing here. |
| 2111 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2112 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2113 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2114 | #endif |
| 2115 | |
| 2116 | /* |
| 2117 | * If we didn't hit the end of the file, and we didn't finish the last |
| 2118 | * line we were working on, then the line didn't fit. |
| 2119 | */ |
| 2120 | wp->w_empty_rows = 0; |
| 2121 | #ifdef FEAT_DIFF |
| 2122 | wp->w_filler_rows = 0; |
| 2123 | #endif |
| 2124 | if (!eof && !didline) |
| 2125 | { |
| 2126 | if (lnum == wp->w_topline) |
| 2127 | { |
| 2128 | /* |
| 2129 | * Single line that does not fit! |
| 2130 | * Don't overwrite it, it can be edited. |
| 2131 | */ |
| 2132 | wp->w_botline = lnum + 1; |
| 2133 | } |
| 2134 | #ifdef FEAT_DIFF |
| 2135 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2136 | { |
| 2137 | /* Window ends in filler lines. */ |
| 2138 | wp->w_botline = lnum; |
| 2139 | wp->w_filler_rows = wp->w_height - srow; |
| 2140 | } |
| 2141 | #endif |
| 2142 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 2143 | { |
| 2144 | /* |
| 2145 | * Last line isn't finished: Display "@@@" at the end. |
| 2146 | */ |
| 2147 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2148 | W_WINROW(wp) + wp->w_height, |
| 2149 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 2150 | '@', '@', hl_attr(HLF_AT)); |
| 2151 | set_empty_rows(wp, srow); |
| 2152 | wp->w_botline = lnum; |
| 2153 | } |
| 2154 | else |
| 2155 | { |
| 2156 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 2157 | wp->w_botline = lnum; |
| 2158 | } |
| 2159 | } |
| 2160 | else |
| 2161 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 2162 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2163 | draw_vsep_win(wp, row); |
| 2164 | #endif |
| 2165 | if (eof) /* we hit the end of the file */ |
| 2166 | { |
| 2167 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2168 | #ifdef FEAT_DIFF |
| 2169 | j = diff_check_fill(wp, wp->w_botline); |
| 2170 | if (j > 0 && !wp->w_botfill) |
| 2171 | { |
| 2172 | /* |
| 2173 | * Display filler lines at the end of the file |
| 2174 | */ |
| 2175 | if (char2cells(fill_diff) > 1) |
| 2176 | i = '-'; |
| 2177 | else |
| 2178 | i = fill_diff; |
| 2179 | if (row + j > wp->w_height) |
| 2180 | j = wp->w_height - row; |
| 2181 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2182 | row += j; |
| 2183 | } |
| 2184 | #endif |
| 2185 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2186 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2187 | wp->w_botline = lnum; |
| 2188 | |
| 2189 | /* make sure the rest of the screen is blank */ |
| 2190 | /* put '~'s on rows that aren't part of the file. */ |
| 2191 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 2192 | } |
| 2193 | |
| 2194 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2195 | wp->w_redr_type = 0; |
| 2196 | #ifdef FEAT_DIFF |
| 2197 | wp->w_old_topfill = wp->w_topfill; |
| 2198 | wp->w_old_botfill = wp->w_botfill; |
| 2199 | #endif |
| 2200 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2201 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2202 | { |
| 2203 | /* |
| 2204 | * There is a trick with w_botline. If we invalidate it on each |
| 2205 | * change that might modify it, this will cause a lot of expensive |
| 2206 | * calls to plines() in update_topline() each time. Therefore the |
| 2207 | * value of w_botline is often approximated, and this value is used to |
| 2208 | * compute the value of w_topline. If the value of w_botline was |
| 2209 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2210 | * the visible part of the text). If it's not, we need to redraw |
| 2211 | * again. Mostly this just means scrolling up a few lines, so it |
| 2212 | * doesn't look too bad. Only do this for the current window (where |
| 2213 | * changes are relevant). |
| 2214 | */ |
| 2215 | wp->w_valid |= VALID_BOTLINE; |
| 2216 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2217 | { |
| 2218 | recursive = TRUE; |
| 2219 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2220 | update_topline(); /* may invalidate w_botline again */ |
| 2221 | if (must_redraw != 0) |
| 2222 | { |
| 2223 | /* Don't update for changes in buffer again. */ |
| 2224 | i = curbuf->b_mod_set; |
| 2225 | curbuf->b_mod_set = FALSE; |
| 2226 | win_update(curwin); |
| 2227 | must_redraw = 0; |
| 2228 | curbuf->b_mod_set = i; |
| 2229 | } |
| 2230 | recursive = FALSE; |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2235 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2236 | if (!got_int) |
| 2237 | got_int = save_got_int; |
| 2238 | #endif |
| 2239 | } |
| 2240 | |
| 2241 | #ifdef FEAT_SIGNS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2242 | static int draw_signcolumn(win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2243 | |
| 2244 | /* |
| 2245 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2246 | */ |
| 2247 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2248 | draw_signcolumn(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2249 | { |
| 2250 | return (wp->w_buffer->b_signlist != NULL |
| 2251 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | 3b7b836 | 2015-03-20 18:11:48 +0100 | [diff] [blame] | 2252 | || wp->w_buffer->b_has_sign_column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2253 | # endif |
| 2254 | ); |
| 2255 | } |
| 2256 | #endif |
| 2257 | |
| 2258 | /* |
| 2259 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2260 | * as the filler character. |
| 2261 | */ |
| 2262 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2263 | win_draw_end( |
| 2264 | win_T *wp, |
| 2265 | int c1, |
| 2266 | int c2, |
| 2267 | int row, |
| 2268 | int endrow, |
| 2269 | hlf_T hl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2270 | { |
| 2271 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2272 | int n = 0; |
| 2273 | # define FDC_OFF n |
| 2274 | #else |
| 2275 | # define FDC_OFF 0 |
| 2276 | #endif |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2277 | #ifdef FEAT_FOLDING |
| 2278 | int fdc = compute_foldcolumn(wp, 0); |
| 2279 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2280 | |
| 2281 | #ifdef FEAT_RIGHTLEFT |
| 2282 | if (wp->w_p_rl) |
| 2283 | { |
| 2284 | /* No check for cmdline window: should never be right-left. */ |
| 2285 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2286 | n = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2287 | |
| 2288 | if (n > 0) |
| 2289 | { |
| 2290 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2291 | if (n > W_WIDTH(wp)) |
| 2292 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2293 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2294 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2295 | ' ', ' ', hl_attr(HLF_FC)); |
| 2296 | } |
| 2297 | # endif |
| 2298 | # ifdef FEAT_SIGNS |
| 2299 | if (draw_signcolumn(wp)) |
| 2300 | { |
| 2301 | int nn = n + 2; |
| 2302 | |
| 2303 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2304 | if (nn > W_WIDTH(wp)) |
| 2305 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2306 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2307 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2308 | ' ', ' ', hl_attr(HLF_SC)); |
| 2309 | n = nn; |
| 2310 | } |
| 2311 | # endif |
| 2312 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2313 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2314 | c2, c2, hl_attr(hl)); |
| 2315 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2316 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2317 | c1, c2, hl_attr(hl)); |
| 2318 | } |
| 2319 | else |
| 2320 | #endif |
| 2321 | { |
| 2322 | #ifdef FEAT_CMDWIN |
| 2323 | if (cmdwin_type != 0 && wp == curwin) |
| 2324 | { |
| 2325 | /* draw the cmdline character in the leftmost column */ |
| 2326 | n = 1; |
| 2327 | if (n > wp->w_width) |
| 2328 | n = wp->w_width; |
| 2329 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2330 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2331 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2332 | } |
| 2333 | #endif |
| 2334 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2335 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2336 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2337 | int nn = n + fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2338 | |
| 2339 | /* draw the fold column at the left */ |
| 2340 | if (nn > W_WIDTH(wp)) |
| 2341 | nn = W_WIDTH(wp); |
| 2342 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2343 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2344 | ' ', ' ', hl_attr(HLF_FC)); |
| 2345 | n = nn; |
| 2346 | } |
| 2347 | #endif |
| 2348 | #ifdef FEAT_SIGNS |
| 2349 | if (draw_signcolumn(wp)) |
| 2350 | { |
| 2351 | int nn = n + 2; |
| 2352 | |
| 2353 | /* draw the sign column after the fold column */ |
| 2354 | if (nn > W_WIDTH(wp)) |
| 2355 | nn = W_WIDTH(wp); |
| 2356 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2357 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2358 | ' ', ' ', hl_attr(HLF_SC)); |
| 2359 | n = nn; |
| 2360 | } |
| 2361 | #endif |
| 2362 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2363 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2364 | c1, c2, hl_attr(hl)); |
| 2365 | } |
| 2366 | set_empty_rows(wp, row); |
| 2367 | } |
| 2368 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2369 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2370 | static int advance_color_col(int vcol, int **color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2371 | |
| 2372 | /* |
| 2373 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2374 | */ |
| 2375 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2376 | advance_color_col(int vcol, int **color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2377 | { |
| 2378 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2379 | ++*color_cols; |
| 2380 | return (**color_cols >= 0); |
| 2381 | } |
| 2382 | #endif |
| 2383 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2384 | #ifdef FEAT_FOLDING |
| 2385 | /* |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2386 | * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much |
| 2387 | * space is available for window "wp", minus "col". |
| 2388 | */ |
| 2389 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2390 | compute_foldcolumn(win_T *wp, int col) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2391 | { |
| 2392 | int fdc = wp->w_p_fdc; |
| 2393 | int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; |
| 2394 | int wwidth = W_WIDTH(wp); |
| 2395 | |
| 2396 | if (fdc > wwidth - (col + wmw)) |
| 2397 | fdc = wwidth - (col + wmw); |
| 2398 | return fdc; |
| 2399 | } |
| 2400 | |
| 2401 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2402 | * Display one folded line. |
| 2403 | */ |
| 2404 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2405 | fold_line( |
| 2406 | win_T *wp, |
| 2407 | long fold_count, |
| 2408 | foldinfo_T *foldinfo, |
| 2409 | linenr_T lnum, |
| 2410 | int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2411 | { |
| 2412 | char_u buf[51]; |
| 2413 | pos_T *top, *bot; |
| 2414 | linenr_T lnume = lnum + fold_count - 1; |
| 2415 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2416 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2417 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2418 | int col; |
| 2419 | int txtcol; |
| 2420 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2421 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2422 | |
| 2423 | /* Build the fold line: |
| 2424 | * 1. Add the cmdwin_type for the command-line window |
| 2425 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2426 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2427 | * 4. Compose the text |
| 2428 | * 5. Add the text |
| 2429 | * 6. set highlighting for the Visual area an other text |
| 2430 | */ |
| 2431 | col = 0; |
| 2432 | |
| 2433 | /* |
| 2434 | * 1. Add the cmdwin_type for the command-line window |
| 2435 | * Ignores 'rightleft', this window is never right-left. |
| 2436 | */ |
| 2437 | #ifdef FEAT_CMDWIN |
| 2438 | if (cmdwin_type != 0 && wp == curwin) |
| 2439 | { |
| 2440 | ScreenLines[off] = cmdwin_type; |
| 2441 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2442 | #ifdef FEAT_MBYTE |
| 2443 | if (enc_utf8) |
| 2444 | ScreenLinesUC[off] = 0; |
| 2445 | #endif |
| 2446 | ++col; |
| 2447 | } |
| 2448 | #endif |
| 2449 | |
| 2450 | /* |
| 2451 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2452 | * Reduce the width when there is not enough space. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2453 | */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2454 | fdc = compute_foldcolumn(wp, col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2455 | if (fdc > 0) |
| 2456 | { |
| 2457 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2458 | #ifdef FEAT_RIGHTLEFT |
| 2459 | if (wp->w_p_rl) |
| 2460 | { |
| 2461 | int i; |
| 2462 | |
| 2463 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2464 | hl_attr(HLF_FC)); |
| 2465 | /* reverse the fold column */ |
| 2466 | for (i = 0; i < fdc; ++i) |
| 2467 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2468 | } |
| 2469 | else |
| 2470 | #endif |
| 2471 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2472 | col += fdc; |
| 2473 | } |
| 2474 | |
| 2475 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2476 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2477 | for (ri = 0; ri < l; ++ri) \ |
| 2478 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2479 | else \ |
| 2480 | for (ri = 0; ri < l; ++ri) \ |
| 2481 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2482 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2483 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2484 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2485 | #endif |
| 2486 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2487 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2488 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2489 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2490 | |
| 2491 | #ifdef FEAT_SIGNS |
| 2492 | /* If signs are being displayed, add two spaces. */ |
| 2493 | if (draw_signcolumn(wp)) |
| 2494 | { |
| 2495 | len = W_WIDTH(wp) - col; |
| 2496 | if (len > 0) |
| 2497 | { |
| 2498 | if (len > 2) |
| 2499 | len = 2; |
| 2500 | # ifdef FEAT_RIGHTLEFT |
| 2501 | if (wp->w_p_rl) |
| 2502 | /* the line number isn't reversed */ |
| 2503 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2504 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2505 | else |
| 2506 | # endif |
| 2507 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2508 | col += len; |
| 2509 | } |
| 2510 | } |
| 2511 | #endif |
| 2512 | |
| 2513 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2514 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2515 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2516 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2517 | { |
| 2518 | len = W_WIDTH(wp) - col; |
| 2519 | if (len > 0) |
| 2520 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2521 | int w = number_width(wp); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2522 | long num; |
| 2523 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2524 | |
| 2525 | if (len > w + 1) |
| 2526 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2527 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2528 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2529 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2530 | num = (long)lnum; |
| 2531 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2532 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2533 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2534 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2535 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2536 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2537 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2538 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2539 | num = lnum; |
| 2540 | fmt = "%-*ld "; |
| 2541 | } |
| 2542 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2543 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2544 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2545 | #ifdef FEAT_RIGHTLEFT |
| 2546 | if (wp->w_p_rl) |
| 2547 | /* the line number isn't reversed */ |
| 2548 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2549 | hl_attr(HLF_FL)); |
| 2550 | else |
| 2551 | #endif |
| 2552 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2553 | col += len; |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | /* |
| 2558 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2559 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2560 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2561 | |
| 2562 | txtcol = col; /* remember where text starts */ |
| 2563 | |
| 2564 | /* |
| 2565 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2566 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2567 | * in columns number-col - window-width. |
| 2568 | */ |
| 2569 | #ifdef FEAT_MBYTE |
| 2570 | if (has_mbyte) |
| 2571 | { |
| 2572 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2573 | int u8c, u8cc[MAX_MCO]; |
| 2574 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2575 | int idx; |
| 2576 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2577 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2578 | # ifdef FEAT_ARABIC |
| 2579 | int prev_c = 0; /* previous Arabic character */ |
| 2580 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2581 | # endif |
| 2582 | |
| 2583 | # ifdef FEAT_RIGHTLEFT |
| 2584 | if (wp->w_p_rl) |
| 2585 | idx = off; |
| 2586 | else |
| 2587 | # endif |
| 2588 | idx = off + col; |
| 2589 | |
| 2590 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2591 | for (p = text; *p != NUL; ) |
| 2592 | { |
| 2593 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2594 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2595 | if (col + cells > W_WIDTH(wp) |
| 2596 | # ifdef FEAT_RIGHTLEFT |
| 2597 | - (wp->w_p_rl ? col : 0) |
| 2598 | # endif |
| 2599 | ) |
| 2600 | break; |
| 2601 | ScreenLines[idx] = *p; |
| 2602 | if (enc_utf8) |
| 2603 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2604 | u8c = utfc_ptr2char(p, u8cc); |
| 2605 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2606 | { |
| 2607 | ScreenLinesUC[idx] = 0; |
| 2608 | #ifdef FEAT_ARABIC |
| 2609 | prev_c = u8c; |
| 2610 | #endif |
| 2611 | } |
| 2612 | else |
| 2613 | { |
| 2614 | #ifdef FEAT_ARABIC |
| 2615 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2616 | { |
| 2617 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2618 | int pc, pc1, nc; |
| 2619 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2620 | int firstbyte = *p; |
| 2621 | |
| 2622 | /* The idea of what is the previous and next |
| 2623 | * character depends on 'rightleft'. */ |
| 2624 | if (wp->w_p_rl) |
| 2625 | { |
| 2626 | pc = prev_c; |
| 2627 | pc1 = prev_c1; |
| 2628 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2629 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2630 | } |
| 2631 | else |
| 2632 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2633 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2634 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2635 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2636 | } |
| 2637 | prev_c = u8c; |
| 2638 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2639 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2640 | pc, pc1, nc); |
| 2641 | ScreenLines[idx] = firstbyte; |
| 2642 | } |
| 2643 | else |
| 2644 | prev_c = u8c; |
| 2645 | #endif |
| 2646 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2647 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2648 | if (u8c >= 0x10000) |
| 2649 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2650 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2651 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2652 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2653 | for (i = 0; i < Screen_mco; ++i) |
| 2654 | { |
| 2655 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2656 | if (u8cc[i] == 0) |
| 2657 | break; |
| 2658 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2659 | } |
| 2660 | if (cells > 1) |
| 2661 | ScreenLines[idx + 1] = 0; |
| 2662 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2663 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2664 | /* double-byte single width character */ |
| 2665 | ScreenLines2[idx] = p[1]; |
| 2666 | else if (cells > 1) |
| 2667 | /* double-width character */ |
| 2668 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2669 | col += cells; |
| 2670 | idx += cells; |
| 2671 | p += c_len; |
| 2672 | } |
| 2673 | } |
| 2674 | else |
| 2675 | #endif |
| 2676 | { |
| 2677 | len = (int)STRLEN(text); |
| 2678 | if (len > W_WIDTH(wp) - col) |
| 2679 | len = W_WIDTH(wp) - col; |
| 2680 | if (len > 0) |
| 2681 | { |
| 2682 | #ifdef FEAT_RIGHTLEFT |
| 2683 | if (wp->w_p_rl) |
| 2684 | STRNCPY(current_ScreenLine, text, len); |
| 2685 | else |
| 2686 | #endif |
| 2687 | STRNCPY(current_ScreenLine + col, text, len); |
| 2688 | col += len; |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | /* Fill the rest of the line with the fold filler */ |
| 2693 | #ifdef FEAT_RIGHTLEFT |
| 2694 | if (wp->w_p_rl) |
| 2695 | col -= txtcol; |
| 2696 | #endif |
| 2697 | while (col < W_WIDTH(wp) |
| 2698 | #ifdef FEAT_RIGHTLEFT |
| 2699 | - (wp->w_p_rl ? txtcol : 0) |
| 2700 | #endif |
| 2701 | ) |
| 2702 | { |
| 2703 | #ifdef FEAT_MBYTE |
| 2704 | if (enc_utf8) |
| 2705 | { |
| 2706 | if (fill_fold >= 0x80) |
| 2707 | { |
| 2708 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2709 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2710 | } |
| 2711 | else |
| 2712 | ScreenLinesUC[off + col] = 0; |
| 2713 | } |
| 2714 | #endif |
| 2715 | ScreenLines[off + col++] = fill_fold; |
| 2716 | } |
| 2717 | |
| 2718 | if (text != buf) |
| 2719 | vim_free(text); |
| 2720 | |
| 2721 | /* |
| 2722 | * 6. set highlighting for the Visual area an other text. |
| 2723 | * If all folded lines are in the Visual area, highlight the line. |
| 2724 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2725 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2726 | { |
| 2727 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2728 | { |
| 2729 | /* Visual is after curwin->w_cursor */ |
| 2730 | top = &curwin->w_cursor; |
| 2731 | bot = &VIsual; |
| 2732 | } |
| 2733 | else |
| 2734 | { |
| 2735 | /* Visual is before curwin->w_cursor */ |
| 2736 | top = &VIsual; |
| 2737 | bot = &curwin->w_cursor; |
| 2738 | } |
| 2739 | if (lnum >= top->lnum |
| 2740 | && lnume <= bot->lnum |
| 2741 | && (VIsual_mode != 'v' |
| 2742 | || ((lnum > top->lnum |
| 2743 | || (lnum == top->lnum |
| 2744 | && top->col == 0)) |
| 2745 | && (lnume < bot->lnum |
| 2746 | || (lnume == bot->lnum |
| 2747 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2748 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2749 | { |
| 2750 | if (VIsual_mode == Ctrl_V) |
| 2751 | { |
| 2752 | /* Visual block mode: highlight the chars part of the block */ |
| 2753 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2754 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2755 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2756 | && wp->w_old_cursor_lcol + txtcol |
| 2757 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2758 | len = wp->w_old_cursor_lcol; |
| 2759 | else |
| 2760 | len = W_WIDTH(wp) - txtcol; |
| 2761 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2762 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2763 | } |
| 2764 | } |
| 2765 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2766 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2767 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2768 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2769 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2770 | } |
| 2771 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2772 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2773 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | fbc25b2 | 2015-03-20 17:16:27 +0100 | [diff] [blame] | 2774 | /* Show colorcolumn in the fold line, but let cursorcolumn override it. */ |
| 2775 | if (wp->w_p_cc_cols) |
| 2776 | { |
| 2777 | int i = 0; |
| 2778 | int j = wp->w_p_cc_cols[i]; |
| 2779 | int old_txtcol = txtcol; |
| 2780 | |
| 2781 | while (j > -1) |
| 2782 | { |
| 2783 | txtcol += j; |
| 2784 | if (wp->w_p_wrap) |
| 2785 | txtcol -= wp->w_skipcol; |
| 2786 | else |
| 2787 | txtcol -= wp->w_leftcol; |
| 2788 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2789 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2790 | ScreenAttrs[off + txtcol], hl_attr(HLF_MC)); |
| 2791 | txtcol = old_txtcol; |
| 2792 | j = wp->w_p_cc_cols[++i]; |
| 2793 | } |
| 2794 | } |
| 2795 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2796 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2797 | if (wp->w_p_cuc) |
| 2798 | { |
| 2799 | txtcol += wp->w_virtcol; |
| 2800 | if (wp->w_p_wrap) |
| 2801 | txtcol -= wp->w_skipcol; |
| 2802 | else |
| 2803 | txtcol -= wp->w_leftcol; |
| 2804 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2805 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2806 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2807 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2808 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2809 | |
| 2810 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2811 | (int)W_WIDTH(wp), FALSE); |
| 2812 | |
| 2813 | /* |
| 2814 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2815 | * updated (saves a call to plines() later). |
| 2816 | */ |
| 2817 | if (wp == curwin |
| 2818 | && lnum <= curwin->w_cursor.lnum |
| 2819 | && lnume >= curwin->w_cursor.lnum) |
| 2820 | { |
| 2821 | curwin->w_cline_row = row; |
| 2822 | curwin->w_cline_height = 1; |
| 2823 | curwin->w_cline_folded = TRUE; |
| 2824 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | /* |
| 2829 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2830 | */ |
| 2831 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2832 | copy_text_attr( |
| 2833 | int off, |
| 2834 | char_u *buf, |
| 2835 | int len, |
| 2836 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2837 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2838 | int i; |
| 2839 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2840 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2841 | # ifdef FEAT_MBYTE |
| 2842 | if (enc_utf8) |
| 2843 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2844 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2845 | for (i = 0; i < len; ++i) |
| 2846 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | /* |
| 2850 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2851 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2852 | */ |
| 2853 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2854 | fill_foldcolumn( |
| 2855 | char_u *p, |
| 2856 | win_T *wp, |
| 2857 | int closed, /* TRUE of FALSE */ |
| 2858 | linenr_T lnum) /* current line number */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2859 | { |
| 2860 | int i = 0; |
| 2861 | int level; |
| 2862 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2863 | int empty; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2864 | int fdc = compute_foldcolumn(wp, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2865 | |
| 2866 | /* Init to all spaces. */ |
Bram Moolenaar | 2536d4f | 2015-07-17 13:22:51 +0200 | [diff] [blame] | 2867 | vim_memset(p, ' ', (size_t)fdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2868 | |
| 2869 | level = win_foldinfo.fi_level; |
| 2870 | if (level > 0) |
| 2871 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2872 | /* If there is only one column put more info in it. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2873 | empty = (fdc == 1) ? 0 : 1; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2874 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2875 | /* If the column is too narrow, we start at the lowest level that |
| 2876 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2877 | first_level = level - fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2878 | if (first_level < 1) |
| 2879 | first_level = 1; |
| 2880 | |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2881 | for (i = 0; i + empty < fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2882 | { |
| 2883 | if (win_foldinfo.fi_lnum == lnum |
| 2884 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2885 | p[i] = '-'; |
| 2886 | else if (first_level == 1) |
| 2887 | p[i] = '|'; |
| 2888 | else if (first_level + i <= 9) |
| 2889 | p[i] = '0' + first_level + i; |
| 2890 | else |
| 2891 | p[i] = '>'; |
| 2892 | if (first_level + i == level) |
| 2893 | break; |
| 2894 | } |
| 2895 | } |
| 2896 | if (closed) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2897 | p[i >= fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2898 | } |
| 2899 | #endif /* FEAT_FOLDING */ |
| 2900 | |
| 2901 | /* |
| 2902 | * Display line "lnum" of window 'wp' on the screen. |
| 2903 | * Start at row "startrow", stop when "endrow" is reached. |
| 2904 | * wp->w_virtcol needs to be valid. |
| 2905 | * |
| 2906 | * Return the number of last row the line occupies. |
| 2907 | */ |
| 2908 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2909 | win_line( |
| 2910 | win_T *wp, |
| 2911 | linenr_T lnum, |
| 2912 | int startrow, |
| 2913 | int endrow, |
| 2914 | int nochange UNUSED) /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2915 | { |
| 2916 | int col; /* visual column on screen */ |
| 2917 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2918 | int c = 0; /* init for GCC */ |
| 2919 | long vcol = 0; /* virtual column (for tabs) */ |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 2920 | #ifdef FEAT_LINEBREAK |
| 2921 | long vcol_sbr = -1; /* virtual column after showbreak */ |
| 2922 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2923 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2924 | char_u *line; /* current line */ |
| 2925 | char_u *ptr; /* current position in "line" */ |
| 2926 | int row; /* row in the window, excl w_winrow */ |
| 2927 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2928 | |
| 2929 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2930 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2931 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 2932 | char_u *p_extra_free = NULL; /* p_extra needs to be freed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2933 | int c_extra = NUL; /* extra chars, all the same */ |
| 2934 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2935 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2936 | displaying lcs_eol at end-of-line */ |
| 2937 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2938 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2939 | |
| 2940 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2941 | int saved_n_extra = 0; |
| 2942 | char_u *saved_p_extra = NULL; |
| 2943 | int saved_c_extra = 0; |
| 2944 | int saved_char_attr = 0; |
| 2945 | |
| 2946 | int n_attr = 0; /* chars with special attr */ |
| 2947 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2948 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2949 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2950 | |
| 2951 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2952 | |
| 2953 | int fromcol, tocol; /* start/end of inverting */ |
| 2954 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2955 | int noinvcur = FALSE; /* don't invert the cursor */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2956 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2957 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2958 | pos_T pos; |
| 2959 | long v; |
| 2960 | |
| 2961 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2962 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2963 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2964 | in this line */ |
| 2965 | int attr = 0; /* attributes for area highlighting */ |
| 2966 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2967 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2968 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2969 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2970 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2971 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2972 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2973 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2974 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2975 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2976 | #endif |
| 2977 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2978 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2979 | # define SPWORDLEN 150 |
| 2980 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2981 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2982 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2983 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2984 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2985 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2986 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2987 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2988 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2989 | static int cap_col = -1; /* column to check for Cap word */ |
| 2990 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2991 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2992 | #endif |
| 2993 | int extra_check; /* has syntax or linebreak */ |
| 2994 | #ifdef FEAT_MBYTE |
| 2995 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2996 | int mb_l = 1; /* multi-byte byte length */ |
| 2997 | int mb_c = 0; /* decoded multi-byte character */ |
| 2998 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2999 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3000 | #endif |
| 3001 | #ifdef FEAT_DIFF |
| 3002 | int filler_lines; /* nr of filler lines to be drawn */ |
| 3003 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3004 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3005 | int change_start = MAXCOL; /* first col of changed area */ |
| 3006 | int change_end = -1; /* last col of changed area */ |
| 3007 | #endif |
| 3008 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 3009 | #ifdef FEAT_LINEBREAK |
| 3010 | int need_showbreak = FALSE; |
| 3011 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3012 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 3013 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3014 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3015 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3016 | #endif |
| 3017 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3018 | matchitem_T *cur; /* points to the match list */ |
| 3019 | match_T *shl; /* points to search_hl or a match */ |
| 3020 | int shl_flag; /* flag to indicate whether search_hl |
| 3021 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3022 | int pos_inprogress; /* marks that position match search is |
| 3023 | in progress */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3024 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 3025 | equals startcol of search_hl or one |
| 3026 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3027 | #endif |
| 3028 | #ifdef FEAT_ARABIC |
| 3029 | int prev_c = 0; /* previous Arabic character */ |
| 3030 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 3031 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3032 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 3033 | int did_line_attr = 0; |
| 3034 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3035 | |
| 3036 | /* draw_state: items that are drawn in sequence: */ |
| 3037 | #define WL_START 0 /* nothing done yet */ |
| 3038 | #ifdef FEAT_CMDWIN |
| 3039 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 3040 | #else |
| 3041 | # define WL_CMDLINE WL_START |
| 3042 | #endif |
| 3043 | #ifdef FEAT_FOLDING |
| 3044 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 3045 | #else |
| 3046 | # define WL_FOLD WL_CMDLINE |
| 3047 | #endif |
| 3048 | #ifdef FEAT_SIGNS |
| 3049 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 3050 | #else |
| 3051 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 3052 | #endif |
| 3053 | #define WL_NR WL_SIGN + 1 /* line number */ |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3054 | #ifdef FEAT_LINEBREAK |
| 3055 | # define WL_BRI WL_NR + 1 /* 'breakindent' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3056 | #else |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3057 | # define WL_BRI WL_NR |
| 3058 | #endif |
| 3059 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3060 | # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */ |
| 3061 | #else |
| 3062 | # define WL_SBR WL_BRI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3063 | #endif |
| 3064 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 3065 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 3066 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3067 | int feedback_col = 0; |
| 3068 | int feedback_old_attr = -1; |
| 3069 | #endif |
| 3070 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3071 | #ifdef FEAT_CONCEAL |
| 3072 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 3073 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 3074 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3075 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3076 | int is_concealing = FALSE; |
| 3077 | int boguscols = 0; /* nonexistent columns added to force |
| 3078 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3079 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3080 | int did_wcol = FALSE; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3081 | int match_conc = 0; /* cchar for match functions */ |
| 3082 | int has_match_conc = 0; /* match wants to conceal */ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3083 | int old_boguscols = 0; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3084 | # define VCOL_HLC (vcol - vcol_off) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3085 | # define FIX_FOR_BOGUSCOLS \ |
| 3086 | { \ |
| 3087 | n_extra += vcol_off; \ |
| 3088 | vcol -= vcol_off; \ |
| 3089 | vcol_off = 0; \ |
| 3090 | col -= boguscols; \ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3091 | old_boguscols = boguscols; \ |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3092 | boguscols = 0; \ |
| 3093 | } |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3094 | #else |
| 3095 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3096 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3097 | |
| 3098 | if (startrow > endrow) /* past the end already! */ |
| 3099 | return startrow; |
| 3100 | |
| 3101 | row = startrow; |
| 3102 | screen_row = row + W_WINROW(wp); |
| 3103 | |
| 3104 | /* |
| 3105 | * To speed up the loop below, set extra_check when there is linebreak, |
| 3106 | * trailing white space and/or syntax processing to be done. |
| 3107 | */ |
| 3108 | #ifdef FEAT_LINEBREAK |
| 3109 | extra_check = wp->w_p_lbr; |
| 3110 | #else |
| 3111 | extra_check = 0; |
| 3112 | #endif |
| 3113 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3114 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3115 | { |
| 3116 | /* Prepare for syntax highlighting in this line. When there is an |
| 3117 | * error, stop syntax highlighting. */ |
| 3118 | save_did_emsg = did_emsg; |
| 3119 | did_emsg = FALSE; |
| 3120 | syntax_start(wp, lnum); |
| 3121 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3122 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3123 | else |
| 3124 | { |
| 3125 | did_emsg = save_did_emsg; |
| 3126 | has_syntax = TRUE; |
| 3127 | extra_check = TRUE; |
| 3128 | } |
| 3129 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3130 | |
| 3131 | /* Check for columns to display for 'colorcolumn'. */ |
| 3132 | color_cols = wp->w_p_cc_cols; |
| 3133 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3134 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3135 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3136 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3137 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3138 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3139 | && *wp->w_s->b_p_spl != NUL |
| 3140 | && wp->w_s->b_langp.ga_len > 0 |
| 3141 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3142 | { |
| 3143 | /* Prepare for spell checking. */ |
| 3144 | has_spell = TRUE; |
| 3145 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3146 | |
| 3147 | /* Get the start of the next line, so that words that wrap to the next |
| 3148 | * line are found too: "et<line-break>al.". |
| 3149 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 3150 | nextline[SPWORDLEN] = NUL; |
| 3151 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 3152 | { |
| 3153 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 3154 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 3155 | } |
| 3156 | |
| 3157 | /* When a word wrapped from the previous line the start of the current |
| 3158 | * line is valid. */ |
| 3159 | if (lnum == checked_lnum) |
| 3160 | cur_checked_col = checked_col; |
| 3161 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3162 | |
| 3163 | /* When there was a sentence end in the previous line may require a |
| 3164 | * word starting with capital in this line. In line 1 always check |
| 3165 | * the first word. */ |
| 3166 | if (lnum != capcol_lnum) |
| 3167 | cap_col = -1; |
| 3168 | if (lnum == 1) |
| 3169 | cap_col = 0; |
| 3170 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3171 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3172 | #endif |
| 3173 | |
| 3174 | /* |
| 3175 | * handle visual active in this window |
| 3176 | */ |
| 3177 | fromcol = -10; |
| 3178 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3179 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3180 | { |
| 3181 | /* Visual is after curwin->w_cursor */ |
| 3182 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 3183 | { |
| 3184 | top = &curwin->w_cursor; |
| 3185 | bot = &VIsual; |
| 3186 | } |
| 3187 | else /* Visual is before curwin->w_cursor */ |
| 3188 | { |
| 3189 | top = &VIsual; |
| 3190 | bot = &curwin->w_cursor; |
| 3191 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3192 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3193 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 3194 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3195 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3196 | { |
| 3197 | fromcol = wp->w_old_cursor_fcol; |
| 3198 | tocol = wp->w_old_cursor_lcol; |
| 3199 | } |
| 3200 | } |
| 3201 | else /* non-block mode */ |
| 3202 | { |
| 3203 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 3204 | fromcol = 0; |
| 3205 | else if (lnum == top->lnum) |
| 3206 | { |
| 3207 | if (VIsual_mode == 'V') /* linewise */ |
| 3208 | fromcol = 0; |
| 3209 | else |
| 3210 | { |
| 3211 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 3212 | if (gchar_pos(top) == NUL) |
| 3213 | tocol = fromcol + 1; |
| 3214 | } |
| 3215 | } |
| 3216 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 3217 | { |
| 3218 | if (*p_sel == 'e' && bot->col == 0 |
| 3219 | #ifdef FEAT_VIRTUALEDIT |
| 3220 | && bot->coladd == 0 |
| 3221 | #endif |
| 3222 | ) |
| 3223 | { |
| 3224 | fromcol = -10; |
| 3225 | tocol = MAXCOL; |
| 3226 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3227 | else if (bot->col == MAXCOL) |
| 3228 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3229 | else |
| 3230 | { |
| 3231 | pos = *bot; |
| 3232 | if (*p_sel == 'e') |
| 3233 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3234 | else |
| 3235 | { |
| 3236 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3237 | ++tocol; |
| 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | } |
| 3242 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3243 | /* Check if the character under the cursor should not be inverted */ |
| 3244 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3245 | #ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3246 | && !gui.in_use |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3247 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3248 | ) |
| 3249 | noinvcur = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3250 | |
| 3251 | /* if inverting in this line set area_highlighting */ |
| 3252 | if (fromcol >= 0) |
| 3253 | { |
| 3254 | area_highlighting = TRUE; |
| 3255 | attr = hl_attr(HLF_V); |
| 3256 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3257 | if ((clip_star.available && !clip_star.owned |
| 3258 | && clip_isautosel_star()) |
| 3259 | || (clip_plus.available && !clip_plus.owned |
| 3260 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3261 | attr = hl_attr(HLF_VNC); |
| 3262 | #endif |
| 3263 | } |
| 3264 | } |
| 3265 | |
| 3266 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3267 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3268 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3269 | else if (highlight_match |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3270 | && wp == curwin |
| 3271 | && lnum >= curwin->w_cursor.lnum |
| 3272 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3273 | { |
| 3274 | if (lnum == curwin->w_cursor.lnum) |
| 3275 | getvcol(curwin, &(curwin->w_cursor), |
| 3276 | (colnr_T *)&fromcol, NULL, NULL); |
| 3277 | else |
| 3278 | fromcol = 0; |
| 3279 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3280 | { |
| 3281 | pos.lnum = lnum; |
| 3282 | pos.col = search_match_endcol; |
| 3283 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3284 | } |
| 3285 | else |
| 3286 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3287 | /* do at least one character; happens when past end of line */ |
| 3288 | if (fromcol == tocol) |
| 3289 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3290 | area_highlighting = TRUE; |
| 3291 | attr = hl_attr(HLF_I); |
| 3292 | } |
| 3293 | |
| 3294 | #ifdef FEAT_DIFF |
| 3295 | filler_lines = diff_check(wp, lnum); |
| 3296 | if (filler_lines < 0) |
| 3297 | { |
| 3298 | if (filler_lines == -1) |
| 3299 | { |
| 3300 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3301 | diff_hlf = HLF_ADD; /* added line */ |
| 3302 | else if (change_start == 0) |
| 3303 | diff_hlf = HLF_TXD; /* changed text */ |
| 3304 | else |
| 3305 | diff_hlf = HLF_CHD; /* changed line */ |
| 3306 | } |
| 3307 | else |
| 3308 | diff_hlf = HLF_ADD; /* added line */ |
| 3309 | filler_lines = 0; |
| 3310 | area_highlighting = TRUE; |
| 3311 | } |
| 3312 | if (lnum == wp->w_topline) |
| 3313 | filler_lines = wp->w_topfill; |
| 3314 | filler_todo = filler_lines; |
| 3315 | #endif |
| 3316 | |
| 3317 | #ifdef LINE_ATTR |
| 3318 | # ifdef FEAT_SIGNS |
| 3319 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3320 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3321 | if (v != 0) |
| 3322 | line_attr = sign_get_attr((int)v, TRUE); |
| 3323 | # endif |
| 3324 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3325 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3326 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3327 | line_attr = hl_attr(HLF_L); |
| 3328 | # endif |
| 3329 | if (line_attr != 0) |
| 3330 | area_highlighting = TRUE; |
| 3331 | #endif |
| 3332 | |
| 3333 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3334 | ptr = line; |
| 3335 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3336 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3337 | if (has_spell) |
| 3338 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3339 | /* For checking first word with a capital skip white space. */ |
| 3340 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3341 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3342 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3343 | /* To be able to spell-check over line boundaries copy the end of the |
| 3344 | * current line into nextline[]. Above the start of the next line was |
| 3345 | * copied to nextline[SPWORDLEN]. */ |
| 3346 | if (nextline[SPWORDLEN] == NUL) |
| 3347 | { |
| 3348 | /* No next line or it is empty. */ |
| 3349 | nextlinecol = MAXCOL; |
| 3350 | nextline_idx = 0; |
| 3351 | } |
| 3352 | else |
| 3353 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3354 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3355 | if (v < SPWORDLEN) |
| 3356 | { |
| 3357 | /* Short line, use it completely and append the start of the |
| 3358 | * next line. */ |
| 3359 | nextlinecol = 0; |
| 3360 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3361 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3362 | nextline_idx = v + 1; |
| 3363 | } |
| 3364 | else |
| 3365 | { |
| 3366 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3367 | nextlinecol = v - SPWORDLEN; |
| 3368 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3369 | nextline_idx = SPWORDLEN + 1; |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | #endif |
| 3374 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3375 | if (wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3376 | { |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3377 | if (lcs_space || lcs_trail) |
| 3378 | extra_check = TRUE; |
| 3379 | /* find start of trailing whitespace */ |
| 3380 | if (lcs_trail) |
| 3381 | { |
| 3382 | trailcol = (colnr_T)STRLEN(ptr); |
| 3383 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3384 | --trailcol; |
| 3385 | trailcol += (colnr_T) (ptr - line); |
| 3386 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | /* |
| 3390 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3391 | * first character to be displayed. |
| 3392 | */ |
| 3393 | if (wp->w_p_wrap) |
| 3394 | v = wp->w_skipcol; |
| 3395 | else |
| 3396 | v = wp->w_leftcol; |
| 3397 | if (v > 0) |
| 3398 | { |
| 3399 | #ifdef FEAT_MBYTE |
| 3400 | char_u *prev_ptr = ptr; |
| 3401 | #endif |
| 3402 | while (vcol < v && *ptr != NUL) |
| 3403 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3404 | c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3405 | vcol += c; |
| 3406 | #ifdef FEAT_MBYTE |
| 3407 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3408 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3409 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3412 | /* When: |
| 3413 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3414 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3415 | * - 'virtualedit' is set, or |
| 3416 | * - the visual mode is active, |
| 3417 | * the end of the line may be before the start of the displayed part. |
| 3418 | */ |
| 3419 | if (vcol < v && ( |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3420 | #ifdef FEAT_SYN_HL |
| 3421 | wp->w_p_cuc || draw_color_col || |
| 3422 | #endif |
| 3423 | #ifdef FEAT_VIRTUALEDIT |
| 3424 | virtual_active() || |
| 3425 | #endif |
| 3426 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3427 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3428 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3429 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3430 | |
| 3431 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3432 | * that character but skip the first few screen characters. */ |
| 3433 | if (vcol > v) |
| 3434 | { |
| 3435 | vcol -= c; |
| 3436 | #ifdef FEAT_MBYTE |
| 3437 | ptr = prev_ptr; |
| 3438 | #else |
| 3439 | --ptr; |
| 3440 | #endif |
| 3441 | n_skip = v - vcol; |
| 3442 | } |
| 3443 | |
| 3444 | /* |
| 3445 | * Adjust for when the inverted text is before the screen, |
| 3446 | * and when the start of the inverted text is before the screen. |
| 3447 | */ |
| 3448 | if (tocol <= vcol) |
| 3449 | fromcol = 0; |
| 3450 | else if (fromcol >= 0 && fromcol < vcol) |
| 3451 | fromcol = vcol; |
| 3452 | |
| 3453 | #ifdef FEAT_LINEBREAK |
| 3454 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3455 | if (wp->w_p_wrap) |
| 3456 | need_showbreak = TRUE; |
| 3457 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3458 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3459 | /* When spell checking a word we need to figure out the start of the |
| 3460 | * word and if it's badly spelled or not. */ |
| 3461 | if (has_spell) |
| 3462 | { |
| 3463 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3464 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3465 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3466 | |
| 3467 | pos = wp->w_cursor; |
| 3468 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3469 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3470 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3471 | |
| 3472 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3473 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3474 | ptr = line + linecol; |
| 3475 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3476 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3477 | { |
| 3478 | /* no bad word found at line start, don't check until end of a |
| 3479 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3480 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3481 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3482 | } |
| 3483 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3484 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3485 | /* bad word found, use attributes until end of word */ |
| 3486 | word_end = wp->w_cursor.col + len + 1; |
| 3487 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3488 | /* Turn index into actual attributes. */ |
| 3489 | if (spell_hlf != HLF_COUNT) |
| 3490 | spell_attr = highlight_attr[spell_hlf]; |
| 3491 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3492 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3493 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3494 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3495 | /* Need to restart syntax highlighting for this line. */ |
| 3496 | if (has_syntax) |
| 3497 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3498 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3499 | } |
| 3500 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | /* |
| 3504 | * Correct highlighting for cursor that can't be disabled. |
| 3505 | * Avoids having to check this for each character. |
| 3506 | */ |
| 3507 | if (fromcol >= 0) |
| 3508 | { |
| 3509 | if (noinvcur) |
| 3510 | { |
| 3511 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3512 | { |
| 3513 | /* highlighting starts at cursor, let it start just after the |
| 3514 | * cursor */ |
| 3515 | fromcol_prev = fromcol; |
| 3516 | fromcol = -1; |
| 3517 | } |
| 3518 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3519 | /* restart highlighting after the cursor */ |
| 3520 | fromcol_prev = wp->w_virtcol; |
| 3521 | } |
| 3522 | if (fromcol >= tocol) |
| 3523 | fromcol = -1; |
| 3524 | } |
| 3525 | |
| 3526 | #ifdef FEAT_SEARCH_EXTRA |
| 3527 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3528 | * Handle highlighting the last used search pattern and matches. |
| 3529 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3530 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3531 | cur = wp->w_match_head; |
| 3532 | shl_flag = FALSE; |
| 3533 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3534 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3535 | if (shl_flag == FALSE) |
| 3536 | { |
| 3537 | shl = &search_hl; |
| 3538 | shl_flag = TRUE; |
| 3539 | } |
| 3540 | else |
| 3541 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3542 | shl->startcol = MAXCOL; |
| 3543 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3544 | shl->attr_cur = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3545 | v = (long)(ptr - line); |
| 3546 | if (cur != NULL) |
| 3547 | cur->pos.cur = 0; |
| 3548 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3549 | |
| 3550 | /* Need to get the line again, a multi-line regexp may have made it |
| 3551 | * invalid. */ |
| 3552 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3553 | ptr = line + v; |
| 3554 | |
| 3555 | if (shl->lnum != 0 && shl->lnum <= lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3556 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3557 | if (shl->lnum == lnum) |
| 3558 | shl->startcol = shl->rm.startpos[0].col; |
| 3559 | else |
| 3560 | shl->startcol = 0; |
| 3561 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3562 | - shl->rm.startpos[0].lnum) |
| 3563 | shl->endcol = shl->rm.endpos[0].col; |
| 3564 | else |
| 3565 | shl->endcol = MAXCOL; |
| 3566 | /* Highlight one character for an empty match. */ |
| 3567 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3568 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3569 | #ifdef FEAT_MBYTE |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3570 | if (has_mbyte && line[shl->endcol] != NUL) |
| 3571 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
| 3572 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3573 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3574 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3575 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3576 | if ((long)shl->startcol < v) /* match at leftcol */ |
| 3577 | { |
| 3578 | shl->attr_cur = shl->attr; |
| 3579 | search_attr = shl->attr; |
| 3580 | } |
| 3581 | area_highlighting = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3582 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3583 | if (shl != &search_hl && cur != NULL) |
| 3584 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3585 | } |
| 3586 | #endif |
| 3587 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3588 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3589 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3590 | * when Visual mode is active, because it's not clear what is selected |
| 3591 | * then. */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3592 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3593 | && !(wp == curwin && VIsual_active)) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3594 | { |
| 3595 | line_attr = hl_attr(HLF_CUL); |
| 3596 | area_highlighting = TRUE; |
| 3597 | } |
| 3598 | #endif |
| 3599 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3600 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3601 | col = 0; |
| 3602 | #ifdef FEAT_RIGHTLEFT |
| 3603 | if (wp->w_p_rl) |
| 3604 | { |
| 3605 | /* Rightleft window: process the text in the normal direction, but put |
| 3606 | * it in current_ScreenLine[] from right to left. Start at the |
| 3607 | * rightmost column of the window. */ |
| 3608 | col = W_WIDTH(wp) - 1; |
| 3609 | off += col; |
| 3610 | } |
| 3611 | #endif |
| 3612 | |
| 3613 | /* |
| 3614 | * Repeat for the whole displayed line. |
| 3615 | */ |
| 3616 | for (;;) |
| 3617 | { |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3618 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3619 | has_match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3620 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3621 | /* Skip this quickly when working on the text. */ |
| 3622 | if (draw_state != WL_LINE) |
| 3623 | { |
| 3624 | #ifdef FEAT_CMDWIN |
| 3625 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3626 | { |
| 3627 | draw_state = WL_CMDLINE; |
| 3628 | if (cmdwin_type != 0 && wp == curwin) |
| 3629 | { |
| 3630 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3631 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3632 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3633 | char_attr = hl_attr(HLF_AT); |
| 3634 | } |
| 3635 | } |
| 3636 | #endif |
| 3637 | |
| 3638 | #ifdef FEAT_FOLDING |
| 3639 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3640 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3641 | int fdc = compute_foldcolumn(wp, 0); |
| 3642 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3643 | draw_state = WL_FOLD; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3644 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3645 | { |
| 3646 | /* Draw the 'foldcolumn'. */ |
| 3647 | fill_foldcolumn(extra, wp, FALSE, lnum); |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3648 | n_extra = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3649 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3650 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3651 | c_extra = NUL; |
| 3652 | char_attr = hl_attr(HLF_FC); |
| 3653 | } |
| 3654 | } |
| 3655 | #endif |
| 3656 | |
| 3657 | #ifdef FEAT_SIGNS |
| 3658 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3659 | { |
| 3660 | draw_state = WL_SIGN; |
| 3661 | /* Show the sign column when there are any signs in this |
| 3662 | * buffer or when using Netbeans. */ |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3663 | if (draw_signcolumn(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3664 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3665 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3666 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3667 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3668 | # endif |
| 3669 | |
| 3670 | /* Draw two cells with the sign value or blank. */ |
| 3671 | c_extra = ' '; |
| 3672 | char_attr = hl_attr(HLF_SC); |
| 3673 | n_extra = 2; |
| 3674 | |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3675 | if (row == startrow |
| 3676 | #ifdef FEAT_DIFF |
| 3677 | + filler_lines && filler_todo <= 0 |
| 3678 | #endif |
| 3679 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3680 | { |
| 3681 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3682 | SIGN_TEXT); |
| 3683 | # ifdef FEAT_SIGN_ICONS |
| 3684 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3685 | SIGN_ICON); |
| 3686 | if (gui.in_use && icon_sign != 0) |
| 3687 | { |
| 3688 | /* Use the image in this position. */ |
| 3689 | c_extra = SIGN_BYTE; |
| 3690 | # ifdef FEAT_NETBEANS_INTG |
| 3691 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3692 | c_extra = MULTISIGN_BYTE; |
| 3693 | # endif |
| 3694 | char_attr = icon_sign; |
| 3695 | } |
| 3696 | else |
| 3697 | # endif |
| 3698 | if (text_sign != 0) |
| 3699 | { |
| 3700 | p_extra = sign_get_text(text_sign); |
| 3701 | if (p_extra != NULL) |
| 3702 | { |
| 3703 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3704 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3705 | } |
| 3706 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | #endif |
| 3712 | |
| 3713 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3714 | { |
| 3715 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3716 | /* Display the absolute or relative line number. After the |
| 3717 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3718 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3719 | && (row == startrow |
| 3720 | #ifdef FEAT_DIFF |
| 3721 | + filler_lines |
| 3722 | #endif |
| 3723 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3724 | { |
| 3725 | /* Draw the line number (empty space after wrapping). */ |
| 3726 | if (row == startrow |
| 3727 | #ifdef FEAT_DIFF |
| 3728 | + filler_lines |
| 3729 | #endif |
| 3730 | ) |
| 3731 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3732 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3733 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3734 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3735 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3736 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3737 | num = (long)lnum; |
| 3738 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3739 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3740 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3741 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3742 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3743 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3744 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3745 | num = lnum; |
| 3746 | fmt = "%-*ld "; |
| 3747 | } |
| 3748 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3749 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3750 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3751 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3752 | if (wp->w_skipcol > 0) |
| 3753 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3754 | *p_extra = '-'; |
| 3755 | #ifdef FEAT_RIGHTLEFT |
| 3756 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3757 | rl_mirror(extra); |
| 3758 | #endif |
| 3759 | p_extra = extra; |
| 3760 | c_extra = NUL; |
| 3761 | } |
| 3762 | else |
| 3763 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3764 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3765 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3766 | #ifdef FEAT_SYN_HL |
| 3767 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3768 | * the current line differently. |
| 3769 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3770 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3771 | if ((wp->w_p_cul || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3772 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3773 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3774 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3775 | } |
| 3776 | } |
| 3777 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3778 | #ifdef FEAT_LINEBREAK |
| 3779 | if (wp->w_p_brisbr && draw_state == WL_BRI - 1 |
| 3780 | && n_extra == 0 && *p_sbr != NUL) |
| 3781 | /* draw indent after showbreak value */ |
| 3782 | draw_state = WL_BRI; |
| 3783 | else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) |
| 3784 | /* After the showbreak, draw the breakindent */ |
| 3785 | draw_state = WL_BRI - 1; |
| 3786 | |
| 3787 | /* draw 'breakindent': indent wrapped text accordingly */ |
| 3788 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 3789 | { |
| 3790 | draw_state = WL_BRI; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3791 | if (wp->w_p_bri && n_extra == 0 && row != startrow |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3792 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3793 | && filler_lines == 0 |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3794 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3795 | ) |
| 3796 | { |
| 3797 | char_attr = 0; /* was: hl_attr(HLF_AT); */ |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3798 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3799 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3800 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3801 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3802 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3803 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3804 | char_attr = hl_combine_attr(char_attr, |
| 3805 | hl_attr(HLF_CUL)); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3806 | # endif |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3807 | } |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3808 | # endif |
Bram Moolenaar | b8b5746 | 2014-07-03 22:54:08 +0200 | [diff] [blame] | 3809 | p_extra = NULL; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3810 | c_extra = ' '; |
| 3811 | n_extra = get_breakindent_win(wp, |
| 3812 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 3813 | /* Correct end of highlighted area for 'breakindent', |
| 3814 | * required when 'linebreak' is also set. */ |
| 3815 | if (tocol == vcol) |
| 3816 | tocol += n_extra; |
| 3817 | } |
| 3818 | } |
| 3819 | #endif |
| 3820 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3821 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3822 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3823 | { |
| 3824 | draw_state = WL_SBR; |
| 3825 | # ifdef FEAT_DIFF |
| 3826 | if (filler_todo > 0) |
| 3827 | { |
| 3828 | /* Draw "deleted" diff line(s). */ |
| 3829 | if (char2cells(fill_diff) > 1) |
| 3830 | c_extra = '-'; |
| 3831 | else |
| 3832 | c_extra = fill_diff; |
| 3833 | # ifdef FEAT_RIGHTLEFT |
| 3834 | if (wp->w_p_rl) |
| 3835 | n_extra = col + 1; |
| 3836 | else |
| 3837 | # endif |
| 3838 | n_extra = W_WIDTH(wp) - col; |
| 3839 | char_attr = hl_attr(HLF_DED); |
| 3840 | } |
| 3841 | # endif |
| 3842 | # ifdef FEAT_LINEBREAK |
| 3843 | if (*p_sbr != NUL && need_showbreak) |
| 3844 | { |
| 3845 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3846 | p_extra = p_sbr; |
| 3847 | c_extra = NUL; |
| 3848 | n_extra = (int)STRLEN(p_sbr); |
| 3849 | char_attr = hl_attr(HLF_AT); |
| 3850 | need_showbreak = FALSE; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 3851 | vcol_sbr = vcol + MB_CHARLEN(p_sbr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3852 | /* Correct end of highlighted area for 'showbreak', |
| 3853 | * required when 'linebreak' is also set. */ |
| 3854 | if (tocol == vcol) |
| 3855 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3856 | #ifdef FEAT_SYN_HL |
| 3857 | /* combine 'showbreak' with 'cursorline' */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3858 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3859 | char_attr = hl_combine_attr(char_attr, |
| 3860 | hl_attr(HLF_CUL)); |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3861 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3862 | } |
| 3863 | # endif |
| 3864 | } |
| 3865 | #endif |
| 3866 | |
| 3867 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3868 | { |
| 3869 | draw_state = WL_LINE; |
| 3870 | if (saved_n_extra) |
| 3871 | { |
| 3872 | /* Continue item from end of wrapped line. */ |
| 3873 | n_extra = saved_n_extra; |
| 3874 | c_extra = saved_c_extra; |
| 3875 | p_extra = saved_p_extra; |
| 3876 | char_attr = saved_char_attr; |
| 3877 | } |
| 3878 | else |
| 3879 | char_attr = 0; |
| 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3884 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3885 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3886 | #ifdef FEAT_DIFF |
| 3887 | && filler_todo <= 0 |
| 3888 | #endif |
| 3889 | ) |
| 3890 | { |
| 3891 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3892 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3893 | /* Pretend we have finished updating the window. Except when |
| 3894 | * 'cursorcolumn' is set. */ |
| 3895 | #ifdef FEAT_SYN_HL |
| 3896 | if (wp->w_p_cuc) |
| 3897 | row = wp->w_cline_row + wp->w_cline_height; |
| 3898 | else |
| 3899 | #endif |
| 3900 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3901 | break; |
| 3902 | } |
| 3903 | |
| 3904 | if (draw_state == WL_LINE && area_highlighting) |
| 3905 | { |
| 3906 | /* handle Visual or match highlighting in this line */ |
| 3907 | if (vcol == fromcol |
| 3908 | #ifdef FEAT_MBYTE |
| 3909 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3910 | && (*mb_ptr2cells)(ptr) > 1) |
| 3911 | #endif |
| 3912 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3913 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3914 | && vcol < tocol)) |
| 3915 | area_attr = attr; /* start highlighting */ |
| 3916 | else if (area_attr != 0 |
| 3917 | && (vcol == tocol |
| 3918 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3919 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3920 | |
| 3921 | #ifdef FEAT_SEARCH_EXTRA |
| 3922 | if (!n_extra) |
| 3923 | { |
| 3924 | /* |
| 3925 | * Check for start/end of search pattern match. |
| 3926 | * After end, check for start/end of next match. |
| 3927 | * When another match, have to check for start again. |
| 3928 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3929 | * Do this for 'search_hl' and the match list (ordered by |
| 3930 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3931 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3932 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3933 | cur = wp->w_match_head; |
| 3934 | shl_flag = FALSE; |
| 3935 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3936 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3937 | if (shl_flag == FALSE |
| 3938 | && ((cur != NULL |
| 3939 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3940 | || cur == NULL)) |
| 3941 | { |
| 3942 | shl = &search_hl; |
| 3943 | shl_flag = TRUE; |
| 3944 | } |
| 3945 | else |
| 3946 | shl = &cur->hl; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3947 | if (cur != NULL) |
| 3948 | cur->pos.cur = 0; |
| 3949 | pos_inprogress = TRUE; |
| 3950 | while (shl->rm.regprog != NULL |
| 3951 | || (cur != NULL && pos_inprogress)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3952 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3953 | if (shl->startcol != MAXCOL |
| 3954 | && v >= (long)shl->startcol |
| 3955 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3956 | { |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3957 | #ifdef FEAT_MBYTE |
| 3958 | int tmp_col = v + MB_PTR2LEN(ptr); |
| 3959 | |
| 3960 | if (shl->endcol < tmp_col) |
| 3961 | shl->endcol = tmp_col; |
| 3962 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3963 | shl->attr_cur = shl->attr; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3964 | #ifdef FEAT_CONCEAL |
| 3965 | if (cur != NULL && syn_name2id((char_u *)"Conceal") |
| 3966 | == cur->hlg_id) |
| 3967 | { |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3968 | has_match_conc = |
| 3969 | v == (long)shl->startcol ? 2 : 1; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3970 | match_conc = cur->conceal_char; |
| 3971 | } |
| 3972 | else |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3973 | has_match_conc = match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3974 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3975 | } |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3976 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3977 | { |
| 3978 | shl->attr_cur = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3979 | #ifdef FEAT_CONCEAL |
| 3980 | prev_syntax_id = 0; |
| 3981 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3982 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3983 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3984 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3985 | |
| 3986 | /* Need to get the line again, a multi-line regexp |
| 3987 | * may have made it invalid. */ |
| 3988 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3989 | ptr = line + v; |
| 3990 | |
| 3991 | if (shl->lnum == lnum) |
| 3992 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3993 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3994 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3995 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3996 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3997 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3998 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3999 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4000 | { |
| 4001 | /* highlight empty match, try again after |
| 4002 | * it */ |
| 4003 | #ifdef FEAT_MBYTE |
| 4004 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4005 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4006 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4007 | else |
| 4008 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4009 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | /* Loop to check if the match starts at the |
| 4013 | * current position */ |
| 4014 | continue; |
| 4015 | } |
| 4016 | } |
| 4017 | break; |
| 4018 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4019 | if (shl != &search_hl && cur != NULL) |
| 4020 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4021 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4022 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4023 | /* Use attributes from match with highest priority among |
| 4024 | * 'search_hl' and the match list. */ |
| 4025 | search_attr = search_hl.attr_cur; |
| 4026 | cur = wp->w_match_head; |
| 4027 | shl_flag = FALSE; |
| 4028 | while (cur != NULL || shl_flag == FALSE) |
| 4029 | { |
| 4030 | if (shl_flag == FALSE |
| 4031 | && ((cur != NULL |
| 4032 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4033 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4034 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4035 | shl = &search_hl; |
| 4036 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4037 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4038 | else |
| 4039 | shl = &cur->hl; |
| 4040 | if (shl->attr_cur != 0) |
| 4041 | search_attr = shl->attr_cur; |
| 4042 | if (shl != &search_hl && cur != NULL) |
| 4043 | cur = cur->next; |
| 4044 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4045 | } |
| 4046 | #endif |
| 4047 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4048 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4049 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4050 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4051 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 4052 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4053 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4054 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 4055 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4056 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4057 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4058 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4059 | line_attr = hl_combine_attr(line_attr, hl_attr(HLF_CUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4060 | } |
| 4061 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4062 | |
| 4063 | /* Decide which of the highlight attributes to use. */ |
| 4064 | attr_pri = TRUE; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4065 | #ifdef LINE_ATTR |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4066 | if (area_attr != 0) |
| 4067 | char_attr = hl_combine_attr(line_attr, area_attr); |
| 4068 | else if (search_attr != 0) |
| 4069 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4070 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 4071 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 4072 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 4073 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 4074 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4075 | char_attr = line_attr; |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4076 | #else |
| 4077 | if (area_attr != 0) |
| 4078 | char_attr = area_attr; |
| 4079 | else if (search_attr != 0) |
| 4080 | char_attr = search_attr; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4081 | #endif |
| 4082 | else |
| 4083 | { |
| 4084 | attr_pri = FALSE; |
| 4085 | #ifdef FEAT_SYN_HL |
| 4086 | if (has_syntax) |
| 4087 | char_attr = syntax_attr; |
| 4088 | else |
| 4089 | #endif |
| 4090 | char_attr = 0; |
| 4091 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | /* |
| 4095 | * Get the next character to put on the screen. |
| 4096 | */ |
| 4097 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 4098 | * The "p_extra" points to the extra stuff that is inserted to |
| 4099 | * represent special characters (non-printable stuff) and other |
| 4100 | * things. When all characters are the same, c_extra is used. |
| 4101 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 4102 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4103 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 4104 | */ |
| 4105 | if (n_extra > 0) |
| 4106 | { |
| 4107 | if (c_extra != NUL) |
| 4108 | { |
| 4109 | c = c_extra; |
| 4110 | #ifdef FEAT_MBYTE |
| 4111 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 4112 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4113 | { |
| 4114 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4115 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4116 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4117 | } |
| 4118 | else |
| 4119 | mb_utf8 = FALSE; |
| 4120 | #endif |
| 4121 | } |
| 4122 | else |
| 4123 | { |
| 4124 | c = *p_extra; |
| 4125 | #ifdef FEAT_MBYTE |
| 4126 | if (has_mbyte) |
| 4127 | { |
| 4128 | mb_c = c; |
| 4129 | if (enc_utf8) |
| 4130 | { |
| 4131 | /* If the UTF-8 character is more than one byte: |
| 4132 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4133 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4134 | mb_utf8 = FALSE; |
| 4135 | if (mb_l > n_extra) |
| 4136 | mb_l = 1; |
| 4137 | else if (mb_l > 1) |
| 4138 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4139 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4140 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4141 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | else |
| 4145 | { |
| 4146 | /* if this is a DBCS character, put it in "mb_c" */ |
| 4147 | mb_l = MB_BYTE2LEN(c); |
| 4148 | if (mb_l >= n_extra) |
| 4149 | mb_l = 1; |
| 4150 | else if (mb_l > 1) |
| 4151 | mb_c = (c << 8) + p_extra[1]; |
| 4152 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4153 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4154 | mb_l = 1; |
| 4155 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4156 | /* If a double-width char doesn't fit display a '>' in the |
| 4157 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4158 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4159 | # ifdef FEAT_RIGHTLEFT |
| 4160 | wp->w_p_rl ? (col <= 0) : |
| 4161 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4162 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4163 | && (*mb_char2cells)(mb_c) == 2) |
| 4164 | { |
| 4165 | c = '>'; |
| 4166 | mb_c = c; |
| 4167 | mb_l = 1; |
| 4168 | mb_utf8 = FALSE; |
| 4169 | multi_attr = hl_attr(HLF_AT); |
| 4170 | /* put the pointer back to output the double-width |
| 4171 | * character at the start of the next line. */ |
| 4172 | ++n_extra; |
| 4173 | --p_extra; |
| 4174 | } |
| 4175 | else |
| 4176 | { |
| 4177 | n_extra -= mb_l - 1; |
| 4178 | p_extra += mb_l - 1; |
| 4179 | } |
| 4180 | } |
| 4181 | #endif |
| 4182 | ++p_extra; |
| 4183 | } |
| 4184 | --n_extra; |
| 4185 | } |
| 4186 | else |
| 4187 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4188 | if (p_extra_free != NULL) |
| 4189 | { |
| 4190 | vim_free(p_extra_free); |
| 4191 | p_extra_free = NULL; |
| 4192 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4193 | /* |
| 4194 | * Get a character from the line itself. |
| 4195 | */ |
| 4196 | c = *ptr; |
| 4197 | #ifdef FEAT_MBYTE |
| 4198 | if (has_mbyte) |
| 4199 | { |
| 4200 | mb_c = c; |
| 4201 | if (enc_utf8) |
| 4202 | { |
| 4203 | /* If the UTF-8 character is more than one byte: Decode it |
| 4204 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4205 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4206 | mb_utf8 = FALSE; |
| 4207 | if (mb_l > 1) |
| 4208 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4209 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4210 | /* Overlong encoded ASCII or ASCII with composing char |
| 4211 | * is displayed normally, except a NUL. */ |
| 4212 | if (mb_c < 0x80) |
| 4213 | c = mb_c; |
| 4214 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4215 | |
| 4216 | /* At start of the line we can have a composing char. |
| 4217 | * Draw it as a space with a composing char. */ |
| 4218 | if (utf_iscomposing(mb_c)) |
| 4219 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4220 | int i; |
| 4221 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4222 | for (i = Screen_mco - 1; i > 0; --i) |
| 4223 | u8cc[i] = u8cc[i - 1]; |
| 4224 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4225 | mb_c = ' '; |
| 4226 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | if ((mb_l == 1 && c >= 0x80) |
| 4230 | || (mb_l >= 1 && mb_c == 0) |
| 4231 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4232 | # ifdef UNICODE16 |
| 4233 | || mb_c >= 0x10000 |
| 4234 | # endif |
| 4235 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4236 | { |
| 4237 | /* |
| 4238 | * Illegal UTF-8 byte: display as <xx>. |
| 4239 | * Non-BMP character : display as ? or fullwidth ?. |
| 4240 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4241 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4242 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4243 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4244 | { |
| 4245 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4246 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4247 | if (wp->w_p_rl) /* reverse */ |
| 4248 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4249 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4250 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4251 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4252 | else if (utf_char2cells(mb_c) != 2) |
| 4253 | STRCPY(extra, "?"); |
| 4254 | else |
| 4255 | /* 0xff1f in UTF-8: full-width '?' */ |
| 4256 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4257 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4258 | |
| 4259 | p_extra = extra; |
| 4260 | c = *p_extra; |
| 4261 | mb_c = mb_ptr2char_adv(&p_extra); |
| 4262 | mb_utf8 = (c >= 0x80); |
| 4263 | n_extra = (int)STRLEN(p_extra); |
| 4264 | c_extra = NUL; |
| 4265 | if (area_attr == 0 && search_attr == 0) |
| 4266 | { |
| 4267 | n_attr = n_extra + 1; |
| 4268 | extra_attr = hl_attr(HLF_8); |
| 4269 | saved_attr2 = char_attr; /* save current attr */ |
| 4270 | } |
| 4271 | } |
| 4272 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4273 | mb_l = 1; |
| 4274 | #ifdef FEAT_ARABIC |
| 4275 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 4276 | { |
| 4277 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4278 | int pc, pc1, nc; |
| 4279 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4280 | |
| 4281 | /* The idea of what is the previous and next |
| 4282 | * character depends on 'rightleft'. */ |
| 4283 | if (wp->w_p_rl) |
| 4284 | { |
| 4285 | pc = prev_c; |
| 4286 | pc1 = prev_c1; |
| 4287 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4288 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4289 | } |
| 4290 | else |
| 4291 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4292 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4293 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4294 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4295 | } |
| 4296 | prev_c = mb_c; |
| 4297 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4298 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4299 | } |
| 4300 | else |
| 4301 | prev_c = mb_c; |
| 4302 | #endif |
| 4303 | } |
| 4304 | else /* enc_dbcs */ |
| 4305 | { |
| 4306 | mb_l = MB_BYTE2LEN(c); |
| 4307 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4308 | mb_l = 1; |
| 4309 | else if (mb_l > 1) |
| 4310 | { |
| 4311 | /* We assume a second byte below 32 is illegal. |
| 4312 | * Hopefully this is OK for all double-byte encodings! |
| 4313 | */ |
| 4314 | if (ptr[1] >= 32) |
| 4315 | mb_c = (c << 8) + ptr[1]; |
| 4316 | else |
| 4317 | { |
| 4318 | if (ptr[1] == NUL) |
| 4319 | { |
| 4320 | /* head byte at end of line */ |
| 4321 | mb_l = 1; |
| 4322 | transchar_nonprint(extra, c); |
| 4323 | } |
| 4324 | else |
| 4325 | { |
| 4326 | /* illegal tail byte */ |
| 4327 | mb_l = 2; |
| 4328 | STRCPY(extra, "XX"); |
| 4329 | } |
| 4330 | p_extra = extra; |
| 4331 | n_extra = (int)STRLEN(extra) - 1; |
| 4332 | c_extra = NUL; |
| 4333 | c = *p_extra++; |
| 4334 | if (area_attr == 0 && search_attr == 0) |
| 4335 | { |
| 4336 | n_attr = n_extra + 1; |
| 4337 | extra_attr = hl_attr(HLF_8); |
| 4338 | saved_attr2 = char_attr; /* save current attr */ |
| 4339 | } |
| 4340 | mb_c = c; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | /* If a double-width char doesn't fit display a '>' in the |
| 4345 | * last column; the character is displayed at the start of the |
| 4346 | * next line. */ |
| 4347 | if (( |
| 4348 | # ifdef FEAT_RIGHTLEFT |
| 4349 | wp->w_p_rl ? (col <= 0) : |
| 4350 | # endif |
| 4351 | (col >= W_WIDTH(wp) - 1)) |
| 4352 | && (*mb_char2cells)(mb_c) == 2) |
| 4353 | { |
| 4354 | c = '>'; |
| 4355 | mb_c = c; |
| 4356 | mb_utf8 = FALSE; |
| 4357 | mb_l = 1; |
| 4358 | multi_attr = hl_attr(HLF_AT); |
| 4359 | /* Put pointer back so that the character will be |
| 4360 | * displayed at the start of the next line. */ |
| 4361 | --ptr; |
| 4362 | } |
| 4363 | else if (*ptr != NUL) |
| 4364 | ptr += mb_l - 1; |
| 4365 | |
| 4366 | /* 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] | 4367 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4368 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4369 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4370 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4371 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4372 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4373 | c = ' '; |
| 4374 | if (area_attr == 0 && search_attr == 0) |
| 4375 | { |
| 4376 | n_attr = n_extra + 1; |
| 4377 | extra_attr = hl_attr(HLF_AT); |
| 4378 | saved_attr2 = char_attr; /* save current attr */ |
| 4379 | } |
| 4380 | mb_c = c; |
| 4381 | mb_utf8 = FALSE; |
| 4382 | mb_l = 1; |
| 4383 | } |
| 4384 | |
| 4385 | } |
| 4386 | #endif |
| 4387 | ++ptr; |
| 4388 | |
| 4389 | if (extra_check) |
| 4390 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4391 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4392 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4393 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4394 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4395 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4396 | /* Get syntax attribute, unless still at the start of the line |
| 4397 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4398 | v = (long)(ptr - line); |
| 4399 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4400 | { |
| 4401 | /* Get the syntax attribute for the character. If there |
| 4402 | * is an error, disable syntax highlighting. */ |
| 4403 | save_did_emsg = did_emsg; |
| 4404 | did_emsg = FALSE; |
| 4405 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4406 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4407 | # ifdef FEAT_SPELL |
| 4408 | has_spell ? &can_spell : |
| 4409 | # endif |
| 4410 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4411 | |
| 4412 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4413 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4414 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4415 | has_syntax = FALSE; |
| 4416 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4417 | else |
| 4418 | did_emsg = save_did_emsg; |
| 4419 | |
| 4420 | /* Need to get the line again, a multi-line regexp may |
| 4421 | * have made it invalid. */ |
| 4422 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4423 | ptr = line + v; |
| 4424 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4425 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4426 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4427 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4428 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4429 | # ifdef FEAT_CONCEAL |
| 4430 | /* no concealing past the end of the line, it interferes |
| 4431 | * with line highlighting */ |
| 4432 | if (c == NUL) |
| 4433 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4434 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4435 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4436 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4437 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4438 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4439 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4440 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4441 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4442 | * Only do this when there is no syntax highlighting, the |
| 4443 | * @Spell cluster is not used or the current syntax item |
| 4444 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4445 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4446 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4447 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4448 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4449 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4450 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4451 | # endif |
| 4452 | if (c != 0 && ( |
| 4453 | # ifdef FEAT_SYN_HL |
| 4454 | !has_syntax || |
| 4455 | # endif |
| 4456 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4457 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4458 | char_u *prev_ptr, *p; |
| 4459 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4460 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4461 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4462 | if (has_mbyte) |
| 4463 | { |
| 4464 | prev_ptr = ptr - mb_l; |
| 4465 | v -= mb_l - 1; |
| 4466 | } |
| 4467 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4468 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4469 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4470 | |
| 4471 | /* Use nextline[] if possible, it has the start of the |
| 4472 | * next line concatenated. */ |
| 4473 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4474 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4475 | else |
| 4476 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4477 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4478 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4479 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4480 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4481 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4482 | /* In Insert mode only highlight a word that |
| 4483 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4484 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4485 | && (State & INSERT) != 0 |
| 4486 | && wp->w_cursor.lnum == lnum |
| 4487 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4488 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4489 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4490 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4491 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4492 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4493 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4494 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4495 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4496 | && (p - nextline) + len > nextline_idx) |
| 4497 | { |
| 4498 | /* Remember that the good word continues at the |
| 4499 | * start of the next line. */ |
| 4500 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4501 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4502 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4503 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4504 | /* Turn index into actual attributes. */ |
| 4505 | if (spell_hlf != HLF_COUNT) |
| 4506 | spell_attr = highlight_attr[spell_hlf]; |
| 4507 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4508 | if (cap_col > 0) |
| 4509 | { |
| 4510 | if (p != prev_ptr |
| 4511 | && (p - nextline) + cap_col >= nextline_idx) |
| 4512 | { |
| 4513 | /* Remember that the word in the next line |
| 4514 | * must start with a capital. */ |
| 4515 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4516 | cap_col = (int)((p - nextline) + cap_col |
| 4517 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4518 | } |
| 4519 | else |
| 4520 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4521 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4522 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4523 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4524 | } |
| 4525 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4526 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4527 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4528 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4529 | else |
| 4530 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4531 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4532 | #endif |
| 4533 | #ifdef FEAT_LINEBREAK |
| 4534 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4535 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4536 | */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4537 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4538 | { |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4539 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4540 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4541 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4542 | char_u *p = ptr - ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4543 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4544 | mb_off + |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4545 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4546 | 1); |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4547 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4548 | /* TODO: is passing p for start of the line OK? */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4549 | n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4550 | NULL) - 1; |
Bram Moolenaar | a365091 | 2014-11-19 13:21:57 +0100 | [diff] [blame] | 4551 | if (c == TAB && n_extra + col > W_WIDTH(wp)) |
| 4552 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4553 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4554 | |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4555 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4556 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4557 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4558 | c_extra = ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4559 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4560 | if (vim_iswhite(c)) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4561 | { |
| 4562 | #ifdef FEAT_CONCEAL |
| 4563 | if (c == TAB) |
| 4564 | /* See "Tab alignment" below. */ |
| 4565 | FIX_FOR_BOGUSCOLS; |
| 4566 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4567 | if (!wp->w_p_list) |
| 4568 | c = ' '; |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4569 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4570 | } |
| 4571 | #endif |
| 4572 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 4573 | /* 'list': change char 160 to lcs_nbsp and space to lcs_space. |
| 4574 | */ |
| 4575 | if (wp->w_p_list |
| 4576 | && (((c == 160 |
| 4577 | #ifdef FEAT_MBYTE |
| 4578 | || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)) |
| 4579 | #endif |
| 4580 | ) && lcs_nbsp) |
| 4581 | || (c == ' ' && lcs_space && ptr - line <= trailcol))) |
| 4582 | { |
| 4583 | c = (c == ' ') ? lcs_space : lcs_nbsp; |
| 4584 | if (area_attr == 0 && search_attr == 0) |
| 4585 | { |
| 4586 | n_attr = 1; |
| 4587 | extra_attr = hl_attr(HLF_8); |
| 4588 | saved_attr2 = char_attr; /* save current attr */ |
| 4589 | } |
| 4590 | #ifdef FEAT_MBYTE |
| 4591 | mb_c = c; |
| 4592 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4593 | { |
| 4594 | mb_utf8 = TRUE; |
| 4595 | u8cc[0] = 0; |
| 4596 | c = 0xc0; |
| 4597 | } |
| 4598 | else |
| 4599 | mb_utf8 = FALSE; |
| 4600 | #endif |
| 4601 | } |
| 4602 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4603 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4604 | { |
| 4605 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4606 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4607 | { |
| 4608 | n_attr = 1; |
| 4609 | extra_attr = hl_attr(HLF_8); |
| 4610 | saved_attr2 = char_attr; /* save current attr */ |
| 4611 | } |
| 4612 | #ifdef FEAT_MBYTE |
| 4613 | mb_c = c; |
| 4614 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4615 | { |
| 4616 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4617 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4618 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4619 | } |
| 4620 | else |
| 4621 | mb_utf8 = FALSE; |
| 4622 | #endif |
| 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | /* |
| 4627 | * Handling of non-printable characters. |
| 4628 | */ |
Bram Moolenaar | 88e8f9f | 2016-01-20 22:48:02 +0100 | [diff] [blame] | 4629 | if (!vim_isprintc(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4630 | { |
| 4631 | /* |
| 4632 | * when getting a character from the file, we may have to |
| 4633 | * turn it into something else on the way to putting it |
| 4634 | * into "ScreenLines". |
| 4635 | */ |
| 4636 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4637 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4638 | int tab_len = 0; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4639 | long vcol_adjusted = vcol; /* removed showbreak length */ |
| 4640 | #ifdef FEAT_LINEBREAK |
| 4641 | /* only adjust the tab_len, when at the first column |
| 4642 | * after the showbreak value was drawn */ |
| 4643 | if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 4644 | vcol_adjusted = vcol - MB_CHARLEN(p_sbr); |
| 4645 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4646 | /* tab amount depends on current column */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4647 | tab_len = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4648 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 4649 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4650 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81c85d | 2014-07-30 16:44:22 +0200 | [diff] [blame] | 4651 | if (!wp->w_p_lbr || !wp->w_p_list) |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4652 | #endif |
| 4653 | /* tab amount depends on current column */ |
| 4654 | n_extra = tab_len; |
| 4655 | #ifdef FEAT_LINEBREAK |
| 4656 | else |
| 4657 | { |
| 4658 | char_u *p; |
| 4659 | int len = n_extra; |
| 4660 | int i; |
| 4661 | int saved_nextra = n_extra; |
| 4662 | |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4663 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4664 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4665 | /* there are characters to conceal */ |
| 4666 | tab_len += vcol_off; |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4667 | /* boguscols before FIX_FOR_BOGUSCOLS macro from above |
| 4668 | */ |
| 4669 | if (wp->w_p_list && lcs_tab1 && old_boguscols > 0 |
| 4670 | && n_extra > tab_len) |
| 4671 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4672 | #endif |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4673 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4674 | /* if n_extra > 0, it gives the number of chars, to |
| 4675 | * use for a tab, else we need to calculate the width |
| 4676 | * for a tab */ |
| 4677 | #ifdef FEAT_MBYTE |
| 4678 | len = (tab_len * mb_char2len(lcs_tab2)); |
| 4679 | if (n_extra > 0) |
| 4680 | len += n_extra - tab_len; |
| 4681 | #endif |
| 4682 | c = lcs_tab1; |
| 4683 | p = alloc((unsigned)(len + 1)); |
| 4684 | vim_memset(p, ' ', len); |
| 4685 | p[len] = NUL; |
| 4686 | p_extra_free = p; |
| 4687 | for (i = 0; i < tab_len; i++) |
| 4688 | { |
| 4689 | #ifdef FEAT_MBYTE |
| 4690 | mb_char2bytes(lcs_tab2, p); |
| 4691 | p += mb_char2len(lcs_tab2); |
| 4692 | n_extra += mb_char2len(lcs_tab2) |
| 4693 | - (saved_nextra > 0 ? 1 : 0); |
| 4694 | #else |
| 4695 | p[i] = lcs_tab2; |
| 4696 | #endif |
| 4697 | } |
| 4698 | p_extra = p_extra_free; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4699 | #ifdef FEAT_CONCEAL |
| 4700 | /* n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 4701 | * macro below, so need to adjust for that here */ |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4702 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4703 | n_extra -= vcol_off; |
| 4704 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4705 | } |
| 4706 | #endif |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4707 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4708 | { |
| 4709 | int vc_saved = vcol_off; |
| 4710 | |
| 4711 | /* Tab alignment should be identical regardless of |
| 4712 | * 'conceallevel' value. So tab compensates of all |
| 4713 | * previous concealed characters, and thus resets |
| 4714 | * vcol_off and boguscols accumulated so far in the |
| 4715 | * line. Note that the tab can be longer than |
| 4716 | * 'tabstop' when there are concealed characters. */ |
| 4717 | FIX_FOR_BOGUSCOLS; |
| 4718 | |
| 4719 | /* Make sure, the highlighting for the tab char will be |
| 4720 | * correctly set further below (effectively reverts the |
| 4721 | * FIX_FOR_BOGSUCOLS macro */ |
| 4722 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4723 | && lcs_tab1) |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4724 | tab_len += vc_saved; |
| 4725 | } |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4726 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4727 | #ifdef FEAT_MBYTE |
| 4728 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4729 | #endif |
| 4730 | if (wp->w_p_list) |
| 4731 | { |
| 4732 | c = lcs_tab1; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4733 | #ifdef FEAT_LINEBREAK |
| 4734 | if (wp->w_p_lbr) |
| 4735 | c_extra = NUL; /* using p_extra from above */ |
| 4736 | else |
| 4737 | #endif |
| 4738 | c_extra = lcs_tab2; |
| 4739 | n_attr = tab_len + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4740 | extra_attr = hl_attr(HLF_8); |
| 4741 | saved_attr2 = char_attr; /* save current attr */ |
| 4742 | #ifdef FEAT_MBYTE |
| 4743 | mb_c = c; |
| 4744 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4745 | { |
| 4746 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4747 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4748 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4749 | } |
| 4750 | #endif |
| 4751 | } |
| 4752 | else |
| 4753 | { |
| 4754 | c_extra = ' '; |
| 4755 | c = ' '; |
| 4756 | } |
| 4757 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4758 | else if (c == NUL |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4759 | && (wp->w_p_list |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4760 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4761 | && tocol > vcol |
| 4762 | && VIsual_mode != Ctrl_V |
| 4763 | && ( |
| 4764 | # ifdef FEAT_RIGHTLEFT |
| 4765 | wp->w_p_rl ? (col >= 0) : |
| 4766 | # endif |
| 4767 | (col < W_WIDTH(wp))) |
| 4768 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4769 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4770 | && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 0481fee | 2015-05-14 05:56:09 +0200 | [diff] [blame] | 4771 | && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4772 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4773 | /* Display a '$' after the line or highlight an extra |
| 4774 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4775 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4776 | /* For a diff line the highlighting continues after the |
| 4777 | * "$". */ |
| 4778 | if ( |
| 4779 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4780 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4781 | # ifdef LINE_ATTR |
| 4782 | && |
| 4783 | # endif |
| 4784 | # endif |
| 4785 | # ifdef LINE_ATTR |
| 4786 | line_attr == 0 |
| 4787 | # endif |
| 4788 | ) |
| 4789 | #endif |
| 4790 | { |
| 4791 | #ifdef FEAT_VIRTUALEDIT |
| 4792 | /* In virtualedit, visual selections may extend |
| 4793 | * beyond end of line. */ |
| 4794 | if (area_highlighting && virtual_active() |
| 4795 | && tocol != MAXCOL && vcol < tocol) |
| 4796 | n_extra = 0; |
| 4797 | else |
| 4798 | #endif |
| 4799 | { |
| 4800 | p_extra = at_end_str; |
| 4801 | n_extra = 1; |
| 4802 | c_extra = NUL; |
| 4803 | } |
| 4804 | } |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4805 | if (wp->w_p_list && lcs_eol > 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4806 | c = lcs_eol; |
| 4807 | else |
| 4808 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4809 | lcs_eol_one = -1; |
| 4810 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4811 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4812 | { |
| 4813 | extra_attr = hl_attr(HLF_AT); |
| 4814 | n_attr = 1; |
| 4815 | } |
| 4816 | #ifdef FEAT_MBYTE |
| 4817 | mb_c = c; |
| 4818 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4819 | { |
| 4820 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4821 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4822 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4823 | } |
| 4824 | else |
| 4825 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4826 | #endif |
| 4827 | } |
| 4828 | else if (c != NUL) |
| 4829 | { |
| 4830 | p_extra = transchar(c); |
Bram Moolenaar | 5524aeb | 2014-07-16 17:29:51 +0200 | [diff] [blame] | 4831 | if (n_extra == 0) |
| 4832 | n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4833 | #ifdef FEAT_RIGHTLEFT |
| 4834 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4835 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4836 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4837 | c_extra = NUL; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4838 | #ifdef FEAT_LINEBREAK |
| 4839 | if (wp->w_p_lbr) |
| 4840 | { |
| 4841 | char_u *p; |
| 4842 | |
| 4843 | c = *p_extra; |
| 4844 | p = alloc((unsigned)n_extra + 1); |
| 4845 | vim_memset(p, ' ', n_extra); |
| 4846 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 4847 | p[n_extra] = NUL; |
| 4848 | p_extra_free = p_extra = p; |
| 4849 | } |
| 4850 | else |
| 4851 | #endif |
| 4852 | { |
| 4853 | n_extra = byte2cells(c) - 1; |
| 4854 | c = *p_extra++; |
| 4855 | } |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4856 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4857 | { |
| 4858 | n_attr = n_extra + 1; |
| 4859 | extra_attr = hl_attr(HLF_8); |
| 4860 | saved_attr2 = char_attr; /* save current attr */ |
| 4861 | } |
| 4862 | #ifdef FEAT_MBYTE |
| 4863 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4864 | #endif |
| 4865 | } |
| 4866 | #ifdef FEAT_VIRTUALEDIT |
| 4867 | else if (VIsual_active |
| 4868 | && (VIsual_mode == Ctrl_V |
| 4869 | || VIsual_mode == 'v') |
| 4870 | && virtual_active() |
| 4871 | && tocol != MAXCOL |
| 4872 | && vcol < tocol |
| 4873 | && ( |
| 4874 | # ifdef FEAT_RIGHTLEFT |
| 4875 | wp->w_p_rl ? (col >= 0) : |
| 4876 | # endif |
| 4877 | (col < W_WIDTH(wp)))) |
| 4878 | { |
| 4879 | c = ' '; |
| 4880 | --ptr; /* put it back at the NUL */ |
| 4881 | } |
| 4882 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4883 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4884 | else if (( |
| 4885 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4886 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4887 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4888 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4889 | ) && ( |
| 4890 | # ifdef FEAT_RIGHTLEFT |
| 4891 | wp->w_p_rl ? (col >= 0) : |
| 4892 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4893 | (col |
| 4894 | # ifdef FEAT_CONCEAL |
| 4895 | - boguscols |
| 4896 | # endif |
| 4897 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4898 | { |
| 4899 | /* Highlight until the right side of the window */ |
| 4900 | c = ' '; |
| 4901 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4902 | |
| 4903 | /* Remember we do the char for line highlighting. */ |
| 4904 | ++did_line_attr; |
| 4905 | |
| 4906 | /* don't do search HL for the rest of the line */ |
| 4907 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4908 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4909 | # ifdef FEAT_DIFF |
| 4910 | if (diff_hlf == HLF_TXD) |
| 4911 | { |
| 4912 | diff_hlf = HLF_CHD; |
| 4913 | if (attr == 0 || char_attr != attr) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4914 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4915 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4916 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4917 | char_attr = hl_combine_attr(char_attr, |
| 4918 | hl_attr(HLF_CUL)); |
| 4919 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4920 | } |
| 4921 | # endif |
| 4922 | } |
| 4923 | #endif |
| 4924 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4925 | |
| 4926 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4927 | if ( wp->w_p_cole > 0 |
| 4928 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4929 | conceal_cursor_line(wp) ) |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4930 | && ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4931 | && !(lnum_in_visual_area |
| 4932 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4933 | { |
| 4934 | char_attr = conceal_attr; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4935 | if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1) |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4936 | && (syn_get_sub_char() != NUL || match_conc |
| 4937 | || wp->w_p_cole == 1) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4938 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4939 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4940 | /* First time at this concealed item: display one |
| 4941 | * character. */ |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4942 | if (match_conc) |
| 4943 | c = match_conc; |
| 4944 | else if (syn_get_sub_char() != NUL) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4945 | c = syn_get_sub_char(); |
| 4946 | else if (lcs_conceal != NUL) |
| 4947 | c = lcs_conceal; |
| 4948 | else |
| 4949 | c = ' '; |
| 4950 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4951 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4952 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4953 | if (n_extra > 0) |
| 4954 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4955 | vcol += n_extra; |
| 4956 | if (wp->w_p_wrap && n_extra > 0) |
| 4957 | { |
| 4958 | # ifdef FEAT_RIGHTLEFT |
| 4959 | if (wp->w_p_rl) |
| 4960 | { |
| 4961 | col -= n_extra; |
| 4962 | boguscols -= n_extra; |
| 4963 | } |
| 4964 | else |
| 4965 | # endif |
| 4966 | { |
| 4967 | boguscols += n_extra; |
| 4968 | col += n_extra; |
| 4969 | } |
| 4970 | } |
| 4971 | n_extra = 0; |
| 4972 | n_attr = 0; |
| 4973 | } |
| 4974 | else if (n_skip == 0) |
| 4975 | { |
| 4976 | is_concealing = TRUE; |
| 4977 | n_skip = 1; |
| 4978 | } |
| 4979 | # ifdef FEAT_MBYTE |
| 4980 | mb_c = c; |
| 4981 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4982 | { |
| 4983 | mb_utf8 = TRUE; |
| 4984 | u8cc[0] = 0; |
| 4985 | c = 0xc0; |
| 4986 | } |
| 4987 | else |
| 4988 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4989 | # endif |
| 4990 | } |
| 4991 | else |
| 4992 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4993 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4994 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4995 | } |
| 4996 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4999 | #ifdef FEAT_CONCEAL |
| 5000 | /* In the cursor line and we may be concealing characters: correct |
| 5001 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 5002 | if (!did_wcol && draw_state == WL_LINE |
| 5003 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5004 | && conceal_cursor_line(wp) |
| 5005 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 5006 | { |
Bram Moolenaar | e39b3d9 | 2016-01-15 22:52:22 +0100 | [diff] [blame] | 5007 | # ifdef FEAT_RIGHTLEFT |
| 5008 | if (wp->w_p_rl) |
| 5009 | wp->w_wcol = W_WIDTH(wp) - col + boguscols - 1; |
| 5010 | else |
| 5011 | # endif |
| 5012 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 5013 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5014 | did_wcol = TRUE; |
| 5015 | } |
| 5016 | #endif |
| 5017 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5018 | /* Don't override visual selection highlighting. */ |
| 5019 | if (n_attr > 0 |
| 5020 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5021 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5022 | char_attr = extra_attr; |
| 5023 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5024 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5025 | /* XIM don't send preedit_start and preedit_end, but they send |
| 5026 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 5027 | * im_is_preediting() here. */ |
| 5028 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5029 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5030 | && (State & INSERT) |
| 5031 | && !p_imdisable |
| 5032 | && im_is_preediting() |
| 5033 | && draw_state == WL_LINE) |
| 5034 | { |
| 5035 | colnr_T tcol; |
| 5036 | |
| 5037 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5038 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5039 | else |
| 5040 | tcol = preedit_end_col; |
| 5041 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 5042 | { |
| 5043 | if (feedback_old_attr < 0) |
| 5044 | { |
| 5045 | feedback_col = 0; |
| 5046 | feedback_old_attr = char_attr; |
| 5047 | } |
| 5048 | char_attr = im_get_feedback_attr(feedback_col); |
| 5049 | if (char_attr < 0) |
| 5050 | char_attr = feedback_old_attr; |
| 5051 | feedback_col++; |
| 5052 | } |
| 5053 | else if (feedback_old_attr >= 0) |
| 5054 | { |
| 5055 | char_attr = feedback_old_attr; |
| 5056 | feedback_old_attr = -1; |
| 5057 | feedback_col = 0; |
| 5058 | } |
| 5059 | } |
| 5060 | #endif |
| 5061 | /* |
| 5062 | * Handle the case where we are in column 0 but not on the first |
| 5063 | * character of the line and the user wants us to show us a |
| 5064 | * special character (via 'listchars' option "precedes:<char>". |
| 5065 | */ |
| 5066 | if (lcs_prec_todo != NUL |
Bram Moolenaar | 7425b93 | 2014-10-10 15:28:46 +0200 | [diff] [blame] | 5067 | && wp->w_p_list |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5068 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 5069 | #ifdef FEAT_DIFF |
| 5070 | && filler_todo <= 0 |
| 5071 | #endif |
| 5072 | && draw_state > WL_NR |
| 5073 | && c != NUL) |
| 5074 | { |
| 5075 | c = lcs_prec; |
| 5076 | lcs_prec_todo = NUL; |
| 5077 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 5078 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5079 | { |
| 5080 | /* Double-width character being overwritten by the "precedes" |
| 5081 | * character, need to fill up half the character. */ |
| 5082 | c_extra = MB_FILLER_CHAR; |
| 5083 | n_extra = 1; |
| 5084 | n_attr = 2; |
| 5085 | extra_attr = hl_attr(HLF_AT); |
| 5086 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5087 | mb_c = c; |
| 5088 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5089 | { |
| 5090 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5091 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5092 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5093 | } |
| 5094 | else |
| 5095 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5096 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5097 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5098 | { |
| 5099 | saved_attr3 = char_attr; /* save current attr */ |
| 5100 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 5101 | n_attr3 = 1; |
| 5102 | } |
| 5103 | } |
| 5104 | |
| 5105 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5106 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5107 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5108 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5109 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5110 | || did_line_attr == 1 |
| 5111 | #endif |
| 5112 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5113 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5114 | #ifdef FEAT_SEARCH_EXTRA |
| 5115 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5116 | |
| 5117 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 5118 | 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] | 5119 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5120 | #endif |
| 5121 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5122 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5123 | * highlight match at end of line. If it's beyond the last |
| 5124 | * char on the screen, just overwrite that one (tricky!) Not |
| 5125 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5126 | #ifdef FEAT_SEARCH_EXTRA |
| 5127 | prevcol_hl_flag = FALSE; |
| 5128 | if (prevcol == (long)search_hl.startcol) |
| 5129 | prevcol_hl_flag = TRUE; |
| 5130 | else |
| 5131 | { |
| 5132 | cur = wp->w_match_head; |
| 5133 | while (cur != NULL) |
| 5134 | { |
| 5135 | if (prevcol == (long)cur->hl.startcol) |
| 5136 | { |
| 5137 | prevcol_hl_flag = TRUE; |
| 5138 | break; |
| 5139 | } |
| 5140 | cur = cur->next; |
| 5141 | } |
| 5142 | } |
| 5143 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5144 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5145 | && ((area_attr != 0 && vcol == fromcol |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5146 | && (VIsual_mode != Ctrl_V |
| 5147 | || lnum == VIsual.lnum |
| 5148 | || lnum == curwin->w_cursor.lnum) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5149 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5150 | #ifdef FEAT_SEARCH_EXTRA |
| 5151 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5152 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5153 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5154 | && did_line_attr <= 1 |
| 5155 | # endif |
| 5156 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5157 | #endif |
| 5158 | )) |
| 5159 | { |
| 5160 | int n = 0; |
| 5161 | |
| 5162 | #ifdef FEAT_RIGHTLEFT |
| 5163 | if (wp->w_p_rl) |
| 5164 | { |
| 5165 | if (col < 0) |
| 5166 | n = 1; |
| 5167 | } |
| 5168 | else |
| 5169 | #endif |
| 5170 | { |
| 5171 | if (col >= W_WIDTH(wp)) |
| 5172 | n = -1; |
| 5173 | } |
| 5174 | if (n != 0) |
| 5175 | { |
| 5176 | /* At the window boundary, highlight the last character |
| 5177 | * instead (better than nothing). */ |
| 5178 | off += n; |
| 5179 | col += n; |
| 5180 | } |
| 5181 | else |
| 5182 | { |
| 5183 | /* Add a blank character to highlight. */ |
| 5184 | ScreenLines[off] = ' '; |
| 5185 | #ifdef FEAT_MBYTE |
| 5186 | if (enc_utf8) |
| 5187 | ScreenLinesUC[off] = 0; |
| 5188 | #endif |
| 5189 | } |
| 5190 | #ifdef FEAT_SEARCH_EXTRA |
| 5191 | if (area_attr == 0) |
| 5192 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5193 | /* Use attributes from match with highest priority among |
| 5194 | * 'search_hl' and the match list. */ |
| 5195 | char_attr = search_hl.attr; |
| 5196 | cur = wp->w_match_head; |
| 5197 | shl_flag = FALSE; |
| 5198 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5199 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5200 | if (shl_flag == FALSE |
| 5201 | && ((cur != NULL |
| 5202 | && cur->priority > SEARCH_HL_PRIORITY) |
| 5203 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5204 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5205 | shl = &search_hl; |
| 5206 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5207 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5208 | else |
| 5209 | shl = &cur->hl; |
| 5210 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 5211 | char_attr = shl->attr; |
| 5212 | if (shl != &search_hl && cur != NULL) |
| 5213 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5214 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5215 | } |
| 5216 | #endif |
| 5217 | ScreenAttrs[off] = char_attr; |
| 5218 | #ifdef FEAT_RIGHTLEFT |
| 5219 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5220 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5221 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5222 | --off; |
| 5223 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5224 | else |
| 5225 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5226 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5227 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5228 | ++off; |
| 5229 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5230 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5231 | #ifdef FEAT_SYN_HL |
| 5232 | eol_hl_off = 1; |
| 5233 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5234 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5235 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5236 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5237 | /* |
| 5238 | * At end of the text line. |
| 5239 | */ |
| 5240 | if (c == NUL) |
| 5241 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5242 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5243 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 5244 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5245 | { |
| 5246 | /* highlight last char after line */ |
| 5247 | --col; |
| 5248 | --off; |
| 5249 | --vcol; |
| 5250 | } |
| 5251 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5252 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 5253 | if (wp->w_p_wrap) |
| 5254 | v = wp->w_skipcol; |
| 5255 | else |
| 5256 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5257 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5258 | /* check if line ends before left margin */ |
| 5259 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5260 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5261 | #ifdef FEAT_CONCEAL |
| 5262 | /* Get rid of the boguscols now, we want to draw until the right |
| 5263 | * edge for 'cursorcolumn'. */ |
| 5264 | col -= boguscols; |
| 5265 | boguscols = 0; |
| 5266 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5267 | |
| 5268 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5269 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5270 | |
| 5271 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5272 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 5273 | && (int)wp->w_virtcol < |
| 5274 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5275 | && lnum != wp->w_cursor.lnum) |
| 5276 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5277 | # ifdef FEAT_RIGHTLEFT |
| 5278 | && !wp->w_p_rl |
| 5279 | # endif |
| 5280 | ) |
| 5281 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5282 | int rightmost_vcol = 0; |
| 5283 | int i; |
| 5284 | |
| 5285 | if (wp->w_p_cuc) |
| 5286 | rightmost_vcol = wp->w_virtcol; |
| 5287 | if (draw_color_col) |
| 5288 | /* determine rightmost colorcolumn to possibly draw */ |
| 5289 | for (i = 0; color_cols[i] >= 0; ++i) |
| 5290 | if (rightmost_vcol < color_cols[i]) |
| 5291 | rightmost_vcol = color_cols[i]; |
| 5292 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5293 | while (col < W_WIDTH(wp)) |
| 5294 | { |
| 5295 | ScreenLines[off] = ' '; |
| 5296 | #ifdef FEAT_MBYTE |
| 5297 | if (enc_utf8) |
| 5298 | ScreenLinesUC[off] = 0; |
| 5299 | #endif |
| 5300 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 5301 | if (draw_color_col) |
| 5302 | draw_color_col = advance_color_col(VCOL_HLC, |
| 5303 | &color_cols); |
| 5304 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5305 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5306 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5307 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5308 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 5309 | else |
| 5310 | ScreenAttrs[off++] = 0; |
| 5311 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5312 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5313 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5314 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5315 | ++vcol; |
| 5316 | } |
| 5317 | } |
| 5318 | #endif |
| 5319 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5320 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5321 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5322 | row++; |
| 5323 | |
| 5324 | /* |
| 5325 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 5326 | * updated (saves a call to plines() later). |
| 5327 | */ |
| 5328 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 5329 | { |
| 5330 | curwin->w_cline_row = startrow; |
| 5331 | curwin->w_cline_height = row - startrow; |
| 5332 | #ifdef FEAT_FOLDING |
| 5333 | curwin->w_cline_folded = FALSE; |
| 5334 | #endif |
| 5335 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 5336 | } |
| 5337 | |
| 5338 | break; |
| 5339 | } |
| 5340 | |
| 5341 | /* line continues beyond line end */ |
| 5342 | if (lcs_ext |
| 5343 | && !wp->w_p_wrap |
| 5344 | #ifdef FEAT_DIFF |
| 5345 | && filler_todo <= 0 |
| 5346 | #endif |
| 5347 | && ( |
| 5348 | #ifdef FEAT_RIGHTLEFT |
| 5349 | wp->w_p_rl ? col == 0 : |
| 5350 | #endif |
| 5351 | col == W_WIDTH(wp) - 1) |
| 5352 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 5353 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5354 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 5355 | { |
| 5356 | c = lcs_ext; |
| 5357 | char_attr = hl_attr(HLF_AT); |
| 5358 | #ifdef FEAT_MBYTE |
| 5359 | mb_c = c; |
| 5360 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5361 | { |
| 5362 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5363 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5364 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5365 | } |
| 5366 | else |
| 5367 | mb_utf8 = FALSE; |
| 5368 | #endif |
| 5369 | } |
| 5370 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5371 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5372 | /* advance to the next 'colorcolumn' */ |
| 5373 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5374 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5375 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5376 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5377 | * highlight the cursor position itself. |
| 5378 | * Also highlight the 'colorcolumn' if it is different than |
| 5379 | * 'cursorcolumn' */ |
| 5380 | vcol_save_attr = -1; |
| 5381 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5382 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5383 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5384 | && lnum != wp->w_cursor.lnum) |
| 5385 | { |
| 5386 | vcol_save_attr = char_attr; |
| 5387 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 5388 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 5389 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5390 | { |
| 5391 | vcol_save_attr = char_attr; |
| 5392 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 5393 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5394 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5395 | #endif |
| 5396 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5397 | /* |
| 5398 | * Store character to be displayed. |
| 5399 | * Skip characters that are left of the screen for 'nowrap'. |
| 5400 | */ |
| 5401 | vcol_prev = vcol; |
| 5402 | if (draw_state < WL_LINE || n_skip <= 0) |
| 5403 | { |
| 5404 | /* |
| 5405 | * Store the character. |
| 5406 | */ |
| 5407 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 5408 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 5409 | { |
| 5410 | /* A double-wide character is: put first halve in left cell. */ |
| 5411 | --off; |
| 5412 | --col; |
| 5413 | } |
| 5414 | #endif |
| 5415 | ScreenLines[off] = c; |
| 5416 | #ifdef FEAT_MBYTE |
| 5417 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5418 | { |
| 5419 | if ((mb_c & 0xff00) == 0x8e00) |
| 5420 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5421 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5422 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5423 | else if (enc_utf8) |
| 5424 | { |
| 5425 | if (mb_utf8) |
| 5426 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5427 | int i; |
| 5428 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5429 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5430 | if ((c & 0xff) == 0) |
| 5431 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5432 | for (i = 0; i < Screen_mco; ++i) |
| 5433 | { |
| 5434 | ScreenLinesC[i][off] = u8cc[i]; |
| 5435 | if (u8cc[i] == 0) |
| 5436 | break; |
| 5437 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5438 | } |
| 5439 | else |
| 5440 | ScreenLinesUC[off] = 0; |
| 5441 | } |
| 5442 | if (multi_attr) |
| 5443 | { |
| 5444 | ScreenAttrs[off] = multi_attr; |
| 5445 | multi_attr = 0; |
| 5446 | } |
| 5447 | else |
| 5448 | #endif |
| 5449 | ScreenAttrs[off] = char_attr; |
| 5450 | |
| 5451 | #ifdef FEAT_MBYTE |
| 5452 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5453 | { |
| 5454 | /* Need to fill two screen columns. */ |
| 5455 | ++off; |
| 5456 | ++col; |
| 5457 | if (enc_utf8) |
| 5458 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5459 | ScreenLines[off] = 0; |
| 5460 | else |
| 5461 | /* DBCS: Put second byte in the second screen char. */ |
| 5462 | ScreenLines[off] = mb_c & 0xff; |
Bram Moolenaar | 32a214e | 2015-12-03 14:29:02 +0100 | [diff] [blame] | 5463 | if (draw_state > WL_NR |
| 5464 | #ifdef FEAT_DIFF |
| 5465 | && filler_todo <= 0 |
| 5466 | #endif |
| 5467 | ) |
| 5468 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5469 | /* When "tocol" is halfway a character, set it to the end of |
| 5470 | * the character, otherwise highlighting won't stop. */ |
| 5471 | if (tocol == vcol) |
| 5472 | ++tocol; |
| 5473 | #ifdef FEAT_RIGHTLEFT |
| 5474 | if (wp->w_p_rl) |
| 5475 | { |
| 5476 | /* now it's time to backup one cell */ |
| 5477 | --off; |
| 5478 | --col; |
| 5479 | } |
| 5480 | #endif |
| 5481 | } |
| 5482 | #endif |
| 5483 | #ifdef FEAT_RIGHTLEFT |
| 5484 | if (wp->w_p_rl) |
| 5485 | { |
| 5486 | --off; |
| 5487 | --col; |
| 5488 | } |
| 5489 | else |
| 5490 | #endif |
| 5491 | { |
| 5492 | ++off; |
| 5493 | ++col; |
| 5494 | } |
| 5495 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5496 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5497 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5498 | { |
| 5499 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5500 | ++vcol_off; |
| 5501 | if (n_extra > 0) |
| 5502 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5503 | if (wp->w_p_wrap) |
| 5504 | { |
| 5505 | /* |
| 5506 | * Special voodoo required if 'wrap' is on. |
| 5507 | * |
| 5508 | * Advance the column indicator to force the line |
| 5509 | * drawing to wrap early. This will make the line |
| 5510 | * take up the same screen space when parts are concealed, |
| 5511 | * so that cursor line computations aren't messed up. |
| 5512 | * |
| 5513 | * To avoid the fictitious advance of 'col' causing |
| 5514 | * trailing junk to be written out of the screen line |
| 5515 | * we are building, 'boguscols' keeps track of the number |
| 5516 | * of bad columns we have advanced. |
| 5517 | */ |
| 5518 | if (n_extra > 0) |
| 5519 | { |
| 5520 | vcol += n_extra; |
| 5521 | # ifdef FEAT_RIGHTLEFT |
| 5522 | if (wp->w_p_rl) |
| 5523 | { |
| 5524 | col -= n_extra; |
| 5525 | boguscols -= n_extra; |
| 5526 | } |
| 5527 | else |
| 5528 | # endif |
| 5529 | { |
| 5530 | col += n_extra; |
| 5531 | boguscols += n_extra; |
| 5532 | } |
| 5533 | n_extra = 0; |
| 5534 | n_attr = 0; |
| 5535 | } |
| 5536 | |
| 5537 | |
| 5538 | # ifdef FEAT_MBYTE |
| 5539 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5540 | { |
| 5541 | /* Need to fill two screen columns. */ |
| 5542 | # ifdef FEAT_RIGHTLEFT |
| 5543 | if (wp->w_p_rl) |
| 5544 | { |
| 5545 | --boguscols; |
| 5546 | --col; |
| 5547 | } |
| 5548 | else |
| 5549 | # endif |
| 5550 | { |
| 5551 | ++boguscols; |
| 5552 | ++col; |
| 5553 | } |
| 5554 | } |
| 5555 | # endif |
| 5556 | |
| 5557 | # ifdef FEAT_RIGHTLEFT |
| 5558 | if (wp->w_p_rl) |
| 5559 | { |
| 5560 | --boguscols; |
| 5561 | --col; |
| 5562 | } |
| 5563 | else |
| 5564 | # endif |
| 5565 | { |
| 5566 | ++boguscols; |
| 5567 | ++col; |
| 5568 | } |
| 5569 | } |
| 5570 | else |
| 5571 | { |
| 5572 | if (n_extra > 0) |
| 5573 | { |
| 5574 | vcol += n_extra; |
| 5575 | n_extra = 0; |
| 5576 | n_attr = 0; |
| 5577 | } |
| 5578 | } |
| 5579 | |
| 5580 | } |
| 5581 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5582 | else |
| 5583 | --n_skip; |
| 5584 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5585 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5586 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5587 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5588 | #ifdef FEAT_DIFF |
| 5589 | && filler_todo <= 0 |
| 5590 | #endif |
| 5591 | ) |
| 5592 | ++vcol; |
| 5593 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5594 | #ifdef FEAT_SYN_HL |
| 5595 | if (vcol_save_attr >= 0) |
| 5596 | char_attr = vcol_save_attr; |
| 5597 | #endif |
| 5598 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5599 | /* restore attributes after "predeces" in 'listchars' */ |
| 5600 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5601 | char_attr = saved_attr3; |
| 5602 | |
| 5603 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5604 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5605 | char_attr = saved_attr2; |
| 5606 | |
| 5607 | /* |
| 5608 | * 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] | 5609 | * 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] | 5610 | */ |
| 5611 | if (( |
| 5612 | #ifdef FEAT_RIGHTLEFT |
| 5613 | wp->w_p_rl ? (col < 0) : |
| 5614 | #endif |
| 5615 | (col >= W_WIDTH(wp))) |
| 5616 | && (*ptr != NUL |
| 5617 | #ifdef FEAT_DIFF |
| 5618 | || filler_todo > 0 |
| 5619 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5620 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5621 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5622 | ) |
| 5623 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5624 | #ifdef FEAT_CONCEAL |
| 5625 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5626 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5627 | boguscols = 0; |
| 5628 | #else |
| 5629 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5630 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5631 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5632 | ++row; |
| 5633 | ++screen_row; |
| 5634 | |
| 5635 | /* When not wrapping and finished diff lines, or when displayed |
| 5636 | * '$' and highlighting until last column, break here. */ |
| 5637 | if ((!wp->w_p_wrap |
| 5638 | #ifdef FEAT_DIFF |
| 5639 | && filler_todo <= 0 |
| 5640 | #endif |
| 5641 | ) || lcs_eol_one == -1) |
| 5642 | break; |
| 5643 | |
| 5644 | /* When the window is too narrow draw all "@" lines. */ |
| 5645 | if (draw_state != WL_LINE |
| 5646 | #ifdef FEAT_DIFF |
| 5647 | && filler_todo <= 0 |
| 5648 | #endif |
| 5649 | ) |
| 5650 | { |
| 5651 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5652 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5653 | draw_vsep_win(wp, row); |
| 5654 | #endif |
| 5655 | row = endrow; |
| 5656 | } |
| 5657 | |
| 5658 | /* When line got too long for screen break here. */ |
| 5659 | if (row == endrow) |
| 5660 | { |
| 5661 | ++row; |
| 5662 | break; |
| 5663 | } |
| 5664 | |
| 5665 | if (screen_cur_row == screen_row - 1 |
| 5666 | #ifdef FEAT_DIFF |
| 5667 | && filler_todo <= 0 |
| 5668 | #endif |
| 5669 | && W_WIDTH(wp) == Columns) |
| 5670 | { |
| 5671 | /* Remember that the line wraps, used for modeless copy. */ |
| 5672 | LineWraps[screen_row - 1] = TRUE; |
| 5673 | |
| 5674 | /* |
| 5675 | * Special trick to make copy/paste of wrapped lines work with |
| 5676 | * xterm/screen: write an extra character beyond the end of |
| 5677 | * the line. This will work with all terminal types |
| 5678 | * (regardless of the xn,am settings). |
| 5679 | * Only do this on a fast tty. |
| 5680 | * Only do this if the cursor is on the current line |
| 5681 | * (something has been written in it). |
| 5682 | * Don't do this for the GUI. |
| 5683 | * Don't do this for double-width characters. |
| 5684 | * Don't do this for a window not at the right screen border. |
| 5685 | */ |
| 5686 | if (p_tf |
| 5687 | #ifdef FEAT_GUI |
| 5688 | && !gui.in_use |
| 5689 | #endif |
| 5690 | #ifdef FEAT_MBYTE |
| 5691 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5692 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5693 | LineOffset[screen_row] + screen_Columns) |
| 5694 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5695 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5696 | + (int)Columns - 2, |
| 5697 | LineOffset[screen_row] + screen_Columns) |
| 5698 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5699 | #endif |
| 5700 | ) |
| 5701 | { |
| 5702 | /* First make sure we are at the end of the screen line, |
| 5703 | * then output the same character again to let the |
| 5704 | * terminal know about the wrap. If the terminal doesn't |
| 5705 | * auto-wrap, we overwrite the character. */ |
| 5706 | if (screen_cur_col != W_WIDTH(wp)) |
| 5707 | screen_char(LineOffset[screen_row - 1] |
| 5708 | + (unsigned)Columns - 1, |
| 5709 | screen_row - 1, (int)(Columns - 1)); |
| 5710 | |
| 5711 | #ifdef FEAT_MBYTE |
| 5712 | /* When there is a multi-byte character, just output a |
| 5713 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5714 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5715 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5716 | out_char(' '); |
| 5717 | else |
| 5718 | #endif |
| 5719 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5720 | + (Columns - 1)]); |
| 5721 | /* force a redraw of the first char on the next line */ |
| 5722 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5723 | screen_start(); /* don't know where cursor is now */ |
| 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | col = 0; |
| 5728 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5729 | #ifdef FEAT_RIGHTLEFT |
| 5730 | if (wp->w_p_rl) |
| 5731 | { |
| 5732 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5733 | off += col; |
| 5734 | } |
| 5735 | #endif |
| 5736 | |
| 5737 | /* reset the drawing state for the start of a wrapped line */ |
| 5738 | draw_state = WL_START; |
| 5739 | saved_n_extra = n_extra; |
| 5740 | saved_p_extra = p_extra; |
| 5741 | saved_c_extra = c_extra; |
| 5742 | saved_char_attr = char_attr; |
| 5743 | n_extra = 0; |
| 5744 | lcs_prec_todo = lcs_prec; |
| 5745 | #ifdef FEAT_LINEBREAK |
| 5746 | # ifdef FEAT_DIFF |
| 5747 | if (filler_todo <= 0) |
| 5748 | # endif |
| 5749 | need_showbreak = TRUE; |
| 5750 | #endif |
| 5751 | #ifdef FEAT_DIFF |
| 5752 | --filler_todo; |
| 5753 | /* When the filler lines are actually below the last line of the |
| 5754 | * file, don't draw the line itself, break here. */ |
| 5755 | if (filler_todo == 0 && wp->w_botfill) |
| 5756 | break; |
| 5757 | #endif |
| 5758 | } |
| 5759 | |
| 5760 | } /* for every character in the line */ |
| 5761 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5762 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5763 | /* After an empty line check first word for capital. */ |
| 5764 | if (*skipwhite(line) == NUL) |
| 5765 | { |
| 5766 | capcol_lnum = lnum + 1; |
| 5767 | cap_col = 0; |
| 5768 | } |
| 5769 | #endif |
| 5770 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5771 | return row; |
| 5772 | } |
| 5773 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5774 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 5775 | static int comp_char_differs(int, int); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5776 | |
| 5777 | /* |
| 5778 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5779 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5780 | */ |
| 5781 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5782 | comp_char_differs(int off_from, int off_to) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5783 | { |
| 5784 | int i; |
| 5785 | |
| 5786 | for (i = 0; i < Screen_mco; ++i) |
| 5787 | { |
| 5788 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5789 | return TRUE; |
| 5790 | if (ScreenLinesC[i][off_from] == 0) |
| 5791 | break; |
| 5792 | } |
| 5793 | return FALSE; |
| 5794 | } |
| 5795 | #endif |
| 5796 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5797 | /* |
| 5798 | * Check whether the given character needs redrawing: |
| 5799 | * - the (first byte of the) character is different |
| 5800 | * - the attributes are different |
| 5801 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5802 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5803 | */ |
| 5804 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5805 | char_needs_redraw(int off_from, int off_to, int cols) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5806 | { |
| 5807 | if (cols > 0 |
| 5808 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5809 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5810 | |
| 5811 | #ifdef FEAT_MBYTE |
| 5812 | || (enc_dbcs != 0 |
| 5813 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5814 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5815 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5816 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5817 | != ScreenLines[off_to + 1]))) |
| 5818 | || (enc_utf8 |
| 5819 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5820 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5821 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5822 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5823 | && ScreenLines[off_from + 1] |
| 5824 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5825 | #endif |
| 5826 | )) |
| 5827 | return TRUE; |
| 5828 | return FALSE; |
| 5829 | } |
| 5830 | |
| 5831 | /* |
| 5832 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5833 | * have actually changed. Handle insert/delete character. |
| 5834 | * "coloff" gives the first column on the screen for this line. |
| 5835 | * "endcol" gives the columns where valid characters are. |
| 5836 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5837 | * needs to be cleared, negative otherwise. |
| 5838 | * "rlflag" is TRUE in a rightleft window: |
| 5839 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5840 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5841 | */ |
| 5842 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5843 | screen_line( |
| 5844 | int row, |
| 5845 | int coloff, |
| 5846 | int endcol, |
| 5847 | int clear_width |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5848 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5849 | , int rlflag |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5850 | #endif |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5851 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5852 | { |
| 5853 | unsigned off_from; |
| 5854 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5855 | #ifdef FEAT_MBYTE |
| 5856 | unsigned max_off_from; |
| 5857 | unsigned max_off_to; |
| 5858 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5859 | int col = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5860 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5861 | int hl; |
| 5862 | #endif |
| 5863 | int force = FALSE; /* force update rest of the line */ |
| 5864 | int redraw_this /* bool: does character need redraw? */ |
| 5865 | #ifdef FEAT_GUI |
| 5866 | = TRUE /* For GUI when while-loop empty */ |
| 5867 | #endif |
| 5868 | ; |
| 5869 | int redraw_next; /* redraw_this for next character */ |
| 5870 | #ifdef FEAT_MBYTE |
| 5871 | int clear_next = FALSE; |
| 5872 | int char_cells; /* 1: normal char */ |
| 5873 | /* 2: occupies two display cells */ |
| 5874 | # define CHAR_CELLS char_cells |
| 5875 | #else |
| 5876 | # define CHAR_CELLS 1 |
| 5877 | #endif |
| 5878 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5879 | /* Check for illegal row and col, just in case. */ |
| 5880 | if (row >= Rows) |
| 5881 | row = Rows - 1; |
| 5882 | if (endcol > Columns) |
| 5883 | endcol = Columns; |
| 5884 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5885 | # ifdef FEAT_CLIPBOARD |
| 5886 | clip_may_clear_selection(row, row); |
| 5887 | # endif |
| 5888 | |
| 5889 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5890 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5891 | #ifdef FEAT_MBYTE |
| 5892 | max_off_from = off_from + screen_Columns; |
| 5893 | max_off_to = LineOffset[row] + screen_Columns; |
| 5894 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5895 | |
| 5896 | #ifdef FEAT_RIGHTLEFT |
| 5897 | if (rlflag) |
| 5898 | { |
| 5899 | /* Clear rest first, because it's left of the text. */ |
| 5900 | if (clear_width > 0) |
| 5901 | { |
| 5902 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5903 | && ScreenAttrs[off_to] == 0 |
| 5904 | # ifdef FEAT_MBYTE |
| 5905 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5906 | # endif |
| 5907 | ) |
| 5908 | { |
| 5909 | ++off_to; |
| 5910 | ++col; |
| 5911 | } |
| 5912 | if (col <= endcol) |
| 5913 | screen_fill(row, row + 1, col + coloff, |
| 5914 | endcol + coloff + 1, ' ', ' ', 0); |
| 5915 | } |
| 5916 | col = endcol + 1; |
| 5917 | off_to = LineOffset[row] + col + coloff; |
| 5918 | off_from += col; |
| 5919 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5920 | } |
| 5921 | #endif /* FEAT_RIGHTLEFT */ |
| 5922 | |
| 5923 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5924 | |
| 5925 | while (col < endcol) |
| 5926 | { |
| 5927 | #ifdef FEAT_MBYTE |
| 5928 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5929 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5930 | else |
| 5931 | char_cells = 1; |
| 5932 | #endif |
| 5933 | |
| 5934 | redraw_this = redraw_next; |
| 5935 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5936 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5937 | |
| 5938 | #ifdef FEAT_GUI |
| 5939 | /* If the next character was bold, then redraw the current character to |
| 5940 | * remove any pixels that might have spilt over into us. This only |
| 5941 | * happens in the GUI. |
| 5942 | */ |
| 5943 | if (redraw_next && gui.in_use) |
| 5944 | { |
| 5945 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5946 | if (hl > HL_ALL) |
| 5947 | hl = syn_attr2attr(hl); |
| 5948 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5949 | redraw_this = TRUE; |
| 5950 | } |
| 5951 | #endif |
| 5952 | |
| 5953 | if (redraw_this) |
| 5954 | { |
| 5955 | /* |
| 5956 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5957 | * Attributes for characters are stored at the position where the |
| 5958 | * cursor is when writing the highlighting code. The |
| 5959 | * start-highlighting code must be written with the cursor on the |
| 5960 | * first highlighted character. The stop-highlighting code must |
| 5961 | * be written with the cursor just after the last highlighted |
| 5962 | * character. |
| 5963 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5964 | * to clear the rest of the line, and force redrawing it |
| 5965 | * completely. |
| 5966 | */ |
| 5967 | if ( p_wiv |
| 5968 | && !force |
| 5969 | #ifdef FEAT_GUI |
| 5970 | && !gui.in_use |
| 5971 | #endif |
| 5972 | && ScreenAttrs[off_to] != 0 |
| 5973 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5974 | { |
| 5975 | /* |
| 5976 | * Need to remove highlighting attributes here. |
| 5977 | */ |
| 5978 | windgoto(row, col + coloff); |
| 5979 | out_str(T_CE); /* clear rest of this screen line */ |
| 5980 | screen_start(); /* don't know where cursor is now */ |
| 5981 | force = TRUE; /* force redraw of rest of the line */ |
| 5982 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5983 | |
| 5984 | /* |
| 5985 | * If the previous character was highlighted, need to stop |
| 5986 | * highlighting at this character. |
| 5987 | */ |
| 5988 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5989 | { |
| 5990 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5991 | term_windgoto(row, col + coloff); |
| 5992 | screen_stop_highlight(); |
| 5993 | } |
| 5994 | else |
| 5995 | screen_attr = 0; /* highlighting has stopped */ |
| 5996 | } |
| 5997 | #ifdef FEAT_MBYTE |
| 5998 | if (enc_dbcs != 0) |
| 5999 | { |
| 6000 | /* Check if overwriting a double-byte with a single-byte or |
| 6001 | * the other way around requires another character to be |
| 6002 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 6003 | * ScreenLinesUC[] is sufficient. */ |
| 6004 | if (char_cells == 1 |
| 6005 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6006 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6007 | { |
| 6008 | /* Writing a single-cell character over a double-cell |
| 6009 | * character: need to redraw the next cell. */ |
| 6010 | ScreenLines[off_to + 1] = 0; |
| 6011 | redraw_next = TRUE; |
| 6012 | } |
| 6013 | else if (char_cells == 2 |
| 6014 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6015 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6016 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6017 | { |
| 6018 | /* Writing the second half of a double-cell character over |
| 6019 | * a double-cell character: need to redraw the second |
| 6020 | * cell. */ |
| 6021 | ScreenLines[off_to + 2] = 0; |
| 6022 | redraw_next = TRUE; |
| 6023 | } |
| 6024 | |
| 6025 | if (enc_dbcs == DBCS_JPNU) |
| 6026 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 6027 | } |
| 6028 | /* When writing a single-width character over a double-width |
| 6029 | * character and at the end of the redrawn text, need to clear out |
| 6030 | * the right halve of the old character. |
| 6031 | * Also required when writing the right halve of a double-width |
| 6032 | * char over the left halve of an existing one. */ |
| 6033 | if (has_mbyte && col + char_cells == endcol |
| 6034 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6035 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6036 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6037 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6038 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6039 | clear_next = TRUE; |
| 6040 | #endif |
| 6041 | |
| 6042 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 6043 | #ifdef FEAT_MBYTE |
| 6044 | if (enc_utf8) |
| 6045 | { |
| 6046 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 6047 | if (ScreenLinesUC[off_from] != 0) |
| 6048 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6049 | int i; |
| 6050 | |
| 6051 | for (i = 0; i < Screen_mco; ++i) |
| 6052 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6053 | } |
| 6054 | } |
| 6055 | if (char_cells == 2) |
| 6056 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 6057 | #endif |
| 6058 | |
| 6059 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6060 | /* The bold trick makes a single column of pixels appear in the |
| 6061 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6062 | * character should be redrawn too. This happens for our own GUI |
| 6063 | * and for some xterms. */ |
| 6064 | if ( |
| 6065 | # ifdef FEAT_GUI |
| 6066 | gui.in_use |
| 6067 | # endif |
| 6068 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6069 | || |
| 6070 | # endif |
| 6071 | # ifdef UNIX |
| 6072 | term_is_xterm |
| 6073 | # endif |
| 6074 | ) |
| 6075 | { |
| 6076 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 6077 | if (hl > HL_ALL) |
| 6078 | hl = syn_attr2attr(hl); |
| 6079 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6080 | redraw_next = TRUE; |
| 6081 | } |
| 6082 | #endif |
| 6083 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 6084 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6085 | /* For simplicity set the attributes of second half of a |
| 6086 | * double-wide character equal to the first half. */ |
| 6087 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6088 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6089 | |
| 6090 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6091 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6092 | else |
| 6093 | #endif |
| 6094 | screen_char(off_to, row, col + coloff); |
| 6095 | } |
| 6096 | else if ( p_wiv |
| 6097 | #ifdef FEAT_GUI |
| 6098 | && !gui.in_use |
| 6099 | #endif |
| 6100 | && col + coloff > 0) |
| 6101 | { |
| 6102 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 6103 | { |
| 6104 | /* |
| 6105 | * Don't output stop-highlight when moving the cursor, it will |
| 6106 | * stop the highlighting when it should continue. |
| 6107 | */ |
| 6108 | screen_attr = 0; |
| 6109 | } |
| 6110 | else if (screen_attr != 0) |
| 6111 | screen_stop_highlight(); |
| 6112 | } |
| 6113 | |
| 6114 | off_to += CHAR_CELLS; |
| 6115 | off_from += CHAR_CELLS; |
| 6116 | col += CHAR_CELLS; |
| 6117 | } |
| 6118 | |
| 6119 | #ifdef FEAT_MBYTE |
| 6120 | if (clear_next) |
| 6121 | { |
| 6122 | /* Clear the second half of a double-wide character of which the left |
| 6123 | * half was overwritten with a single-wide character. */ |
| 6124 | ScreenLines[off_to] = ' '; |
| 6125 | if (enc_utf8) |
| 6126 | ScreenLinesUC[off_to] = 0; |
| 6127 | screen_char(off_to, row, col + coloff); |
| 6128 | } |
| 6129 | #endif |
| 6130 | |
| 6131 | if (clear_width > 0 |
| 6132 | #ifdef FEAT_RIGHTLEFT |
| 6133 | && !rlflag |
| 6134 | #endif |
| 6135 | ) |
| 6136 | { |
| 6137 | #ifdef FEAT_GUI |
| 6138 | int startCol = col; |
| 6139 | #endif |
| 6140 | |
| 6141 | /* blank out the rest of the line */ |
| 6142 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 6143 | && ScreenAttrs[off_to] == 0 |
| 6144 | #ifdef FEAT_MBYTE |
| 6145 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 6146 | #endif |
| 6147 | ) |
| 6148 | { |
| 6149 | ++off_to; |
| 6150 | ++col; |
| 6151 | } |
| 6152 | if (col < clear_width) |
| 6153 | { |
| 6154 | #ifdef FEAT_GUI |
| 6155 | /* |
| 6156 | * In the GUI, clearing the rest of the line may leave pixels |
| 6157 | * behind if the first character cleared was bold. Some bold |
| 6158 | * fonts spill over the left. In this case we redraw the previous |
| 6159 | * character too. If we didn't skip any blanks above, then we |
| 6160 | * only redraw if the character wasn't already redrawn anyway. |
| 6161 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6162 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6163 | { |
| 6164 | hl = ScreenAttrs[off_to]; |
| 6165 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6166 | { |
| 6167 | int prev_cells = 1; |
| 6168 | # ifdef FEAT_MBYTE |
| 6169 | if (enc_utf8) |
| 6170 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 6171 | * that its width is 2. */ |
| 6172 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 6173 | else if (enc_dbcs != 0) |
| 6174 | { |
| 6175 | /* find previous character by counting from first |
| 6176 | * column and get its width. */ |
| 6177 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6178 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6179 | |
| 6180 | while (off < off_to) |
| 6181 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6182 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6183 | off += prev_cells; |
| 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | if (enc_dbcs != 0 && prev_cells > 1) |
| 6188 | screen_char_2(off_to - prev_cells, row, |
| 6189 | col + coloff - prev_cells); |
| 6190 | else |
| 6191 | # endif |
| 6192 | screen_char(off_to - prev_cells, row, |
| 6193 | col + coloff - prev_cells); |
| 6194 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6195 | } |
| 6196 | #endif |
| 6197 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 6198 | ' ', ' ', 0); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6199 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6200 | off_to += clear_width - col; |
| 6201 | col = clear_width; |
| 6202 | #endif |
| 6203 | } |
| 6204 | } |
| 6205 | |
| 6206 | if (clear_width > 0) |
| 6207 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6208 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6209 | /* For a window that's left of another, draw the separator char. */ |
| 6210 | if (col + coloff < Columns) |
| 6211 | { |
| 6212 | int c; |
| 6213 | |
| 6214 | c = fillchar_vsep(&hl); |
Bram Moolenaar | c60c4f6 | 2015-01-07 19:04:28 +0100 | [diff] [blame] | 6215 | if (ScreenLines[off_to] != (schar_T)c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6216 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6217 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 6218 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6219 | # endif |
| 6220 | || ScreenAttrs[off_to] != hl) |
| 6221 | { |
| 6222 | ScreenLines[off_to] = c; |
| 6223 | ScreenAttrs[off_to] = hl; |
| 6224 | # ifdef FEAT_MBYTE |
| 6225 | if (enc_utf8) |
| 6226 | { |
| 6227 | if (c >= 0x80) |
| 6228 | { |
| 6229 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6230 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6231 | } |
| 6232 | else |
| 6233 | ScreenLinesUC[off_to] = 0; |
| 6234 | } |
| 6235 | # endif |
| 6236 | screen_char(off_to, row, col + coloff); |
| 6237 | } |
| 6238 | } |
| 6239 | else |
| 6240 | #endif |
| 6241 | LineWraps[row] = FALSE; |
| 6242 | } |
| 6243 | } |
| 6244 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6245 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6246 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6247 | * Mirror text "str" for right-left displaying. |
| 6248 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6249 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6250 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6251 | rl_mirror(char_u *str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6252 | { |
| 6253 | char_u *p1, *p2; |
| 6254 | int t; |
| 6255 | |
| 6256 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 6257 | { |
| 6258 | t = *p1; |
| 6259 | *p1 = *p2; |
| 6260 | *p2 = t; |
| 6261 | } |
| 6262 | } |
| 6263 | #endif |
| 6264 | |
| 6265 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6266 | /* |
| 6267 | * mark all status lines for redraw; used after first :cd |
| 6268 | */ |
| 6269 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6270 | status_redraw_all(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6271 | { |
| 6272 | win_T *wp; |
| 6273 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6274 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6275 | if (wp->w_status_height) |
| 6276 | { |
| 6277 | wp->w_redr_status = TRUE; |
| 6278 | redraw_later(VALID); |
| 6279 | } |
| 6280 | } |
| 6281 | |
| 6282 | /* |
| 6283 | * mark all status lines of the current buffer for redraw |
| 6284 | */ |
| 6285 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6286 | status_redraw_curbuf(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6287 | { |
| 6288 | win_T *wp; |
| 6289 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6290 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6291 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 6292 | { |
| 6293 | wp->w_redr_status = TRUE; |
| 6294 | redraw_later(VALID); |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | /* |
| 6299 | * Redraw all status lines that need to be redrawn. |
| 6300 | */ |
| 6301 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6302 | redraw_statuslines(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6303 | { |
| 6304 | win_T *wp; |
| 6305 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6306 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6307 | if (wp->w_redr_status) |
| 6308 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 6309 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6310 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6311 | } |
| 6312 | #endif |
| 6313 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6314 | #if (defined(FEAT_WILDMENU) && defined(FEAT_WINDOWS)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6315 | /* |
| 6316 | * Redraw all status lines at the bottom of frame "frp". |
| 6317 | */ |
| 6318 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6319 | win_redraw_last_status(frame_T *frp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6320 | { |
| 6321 | if (frp->fr_layout == FR_LEAF) |
| 6322 | frp->fr_win->w_redr_status = TRUE; |
| 6323 | else if (frp->fr_layout == FR_ROW) |
| 6324 | { |
| 6325 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 6326 | win_redraw_last_status(frp); |
| 6327 | } |
| 6328 | else /* frp->fr_layout == FR_COL */ |
| 6329 | { |
| 6330 | frp = frp->fr_child; |
| 6331 | while (frp->fr_next != NULL) |
| 6332 | frp = frp->fr_next; |
| 6333 | win_redraw_last_status(frp); |
| 6334 | } |
| 6335 | } |
| 6336 | #endif |
| 6337 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6338 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6339 | /* |
| 6340 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 6341 | */ |
| 6342 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6343 | draw_vsep_win(win_T *wp, int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6344 | { |
| 6345 | int hl; |
| 6346 | int c; |
| 6347 | |
| 6348 | if (wp->w_vsep_width) |
| 6349 | { |
| 6350 | /* draw the vertical separator right of this window */ |
| 6351 | c = fillchar_vsep(&hl); |
| 6352 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 6353 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 6354 | c, ' ', hl); |
| 6355 | } |
| 6356 | } |
| 6357 | #endif |
| 6358 | |
| 6359 | #ifdef FEAT_WILDMENU |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 6360 | static int status_match_len(expand_T *xp, char_u *s); |
| 6361 | static int skip_status_match_char(expand_T *xp, char_u *s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6362 | |
| 6363 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6364 | * 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] | 6365 | */ |
| 6366 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6367 | status_match_len(expand_T *xp, char_u *s) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6368 | { |
| 6369 | int len = 0; |
| 6370 | |
| 6371 | #ifdef FEAT_MENU |
| 6372 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 6373 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6374 | |
| 6375 | /* Check for menu separators - replace with '|'. */ |
| 6376 | if (emenu && menu_is_separator(s)) |
| 6377 | return 1; |
| 6378 | #endif |
| 6379 | |
| 6380 | while (*s != NUL) |
| 6381 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6382 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 6383 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6384 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | return len; |
| 6388 | } |
| 6389 | |
| 6390 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6391 | * 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] | 6392 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 6393 | */ |
| 6394 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6395 | skip_status_match_char(expand_T *xp, char_u *s) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6396 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6397 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6398 | #ifdef FEAT_MENU |
| 6399 | || ((xp->xp_context == EXPAND_MENUS |
| 6400 | || xp->xp_context == EXPAND_MENUNAMES) |
| 6401 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 6402 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6403 | ) |
| 6404 | { |
| 6405 | #ifndef BACKSLASH_IN_FILENAME |
| 6406 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 6407 | return 2; |
| 6408 | #endif |
| 6409 | return 1; |
| 6410 | } |
| 6411 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6415 | * Show wildchar matches in the status line. |
| 6416 | * Show at least the "match" item. |
| 6417 | * We start at item 'first_match' in the list and show all matches that fit. |
| 6418 | * |
| 6419 | * If inversion is possible we use it. Else '=' characters are used. |
| 6420 | */ |
| 6421 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6422 | win_redr_status_matches( |
| 6423 | expand_T *xp, |
| 6424 | int num_matches, |
| 6425 | char_u **matches, /* list of matches */ |
| 6426 | int match, |
| 6427 | int showtail) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6428 | { |
| 6429 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6430 | int row; |
| 6431 | char_u *buf; |
| 6432 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6433 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6434 | int fillchar; |
| 6435 | int attr; |
| 6436 | int i; |
| 6437 | int highlight = TRUE; |
| 6438 | char_u *selstart = NULL; |
| 6439 | int selstart_col = 0; |
| 6440 | char_u *selend = NULL; |
| 6441 | static int first_match = 0; |
| 6442 | int add_left = FALSE; |
| 6443 | char_u *s; |
| 6444 | #ifdef FEAT_MENU |
| 6445 | int emenu; |
| 6446 | #endif |
| 6447 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6448 | int l; |
| 6449 | #endif |
| 6450 | |
| 6451 | if (matches == NULL) /* interrupted completion? */ |
| 6452 | return; |
| 6453 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6454 | #ifdef FEAT_MBYTE |
| 6455 | if (has_mbyte) |
| 6456 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6457 | else |
| 6458 | #endif |
| 6459 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6460 | if (buf == NULL) |
| 6461 | return; |
| 6462 | |
| 6463 | if (match == -1) /* don't show match but original text */ |
| 6464 | { |
| 6465 | match = 0; |
| 6466 | highlight = FALSE; |
| 6467 | } |
| 6468 | /* count 1 for the ending ">" */ |
| 6469 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6470 | if (match == 0) |
| 6471 | first_match = 0; |
| 6472 | else if (match < first_match) |
| 6473 | { |
| 6474 | /* jumping left, as far as we can go */ |
| 6475 | first_match = match; |
| 6476 | add_left = TRUE; |
| 6477 | } |
| 6478 | else |
| 6479 | { |
| 6480 | /* check if match fits on the screen */ |
| 6481 | for (i = first_match; i < match; ++i) |
| 6482 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6483 | if (first_match > 0) |
| 6484 | clen += 2; |
| 6485 | /* jumping right, put match at the left */ |
| 6486 | if ((long)clen > Columns) |
| 6487 | { |
| 6488 | first_match = match; |
| 6489 | /* if showing the last match, we can add some on the left */ |
| 6490 | clen = 2; |
| 6491 | for (i = match; i < num_matches; ++i) |
| 6492 | { |
| 6493 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6494 | if ((long)clen >= Columns) |
| 6495 | break; |
| 6496 | } |
| 6497 | if (i == num_matches) |
| 6498 | add_left = TRUE; |
| 6499 | } |
| 6500 | } |
| 6501 | if (add_left) |
| 6502 | while (first_match > 0) |
| 6503 | { |
| 6504 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6505 | if ((long)clen >= Columns) |
| 6506 | break; |
| 6507 | --first_match; |
| 6508 | } |
| 6509 | |
| 6510 | fillchar = fillchar_status(&attr, TRUE); |
| 6511 | |
| 6512 | if (first_match == 0) |
| 6513 | { |
| 6514 | *buf = NUL; |
| 6515 | len = 0; |
| 6516 | } |
| 6517 | else |
| 6518 | { |
| 6519 | STRCPY(buf, "< "); |
| 6520 | len = 2; |
| 6521 | } |
| 6522 | clen = len; |
| 6523 | |
| 6524 | i = first_match; |
| 6525 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6526 | { |
| 6527 | if (i == match) |
| 6528 | { |
| 6529 | selstart = buf + len; |
| 6530 | selstart_col = clen; |
| 6531 | } |
| 6532 | |
| 6533 | s = L_MATCH(i); |
| 6534 | /* Check for menu separators - replace with '|' */ |
| 6535 | #ifdef FEAT_MENU |
| 6536 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6537 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6538 | if (emenu && menu_is_separator(s)) |
| 6539 | { |
| 6540 | STRCPY(buf + len, transchar('|')); |
| 6541 | l = (int)STRLEN(buf + len); |
| 6542 | len += l; |
| 6543 | clen += l; |
| 6544 | } |
| 6545 | else |
| 6546 | #endif |
| 6547 | for ( ; *s != NUL; ++s) |
| 6548 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6549 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6550 | clen += ptr2cells(s); |
| 6551 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6552 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6553 | { |
| 6554 | STRNCPY(buf + len, s, l); |
| 6555 | s += l - 1; |
| 6556 | len += l; |
| 6557 | } |
| 6558 | else |
| 6559 | #endif |
| 6560 | { |
| 6561 | STRCPY(buf + len, transchar_byte(*s)); |
| 6562 | len += (int)STRLEN(buf + len); |
| 6563 | } |
| 6564 | } |
| 6565 | if (i == match) |
| 6566 | selend = buf + len; |
| 6567 | |
| 6568 | *(buf + len++) = ' '; |
| 6569 | *(buf + len++) = ' '; |
| 6570 | clen += 2; |
| 6571 | if (++i == num_matches) |
| 6572 | break; |
| 6573 | } |
| 6574 | |
| 6575 | if (i != num_matches) |
| 6576 | { |
| 6577 | *(buf + len++) = '>'; |
| 6578 | ++clen; |
| 6579 | } |
| 6580 | |
| 6581 | buf[len] = NUL; |
| 6582 | |
| 6583 | row = cmdline_row - 1; |
| 6584 | if (row >= 0) |
| 6585 | { |
| 6586 | if (wild_menu_showing == 0) |
| 6587 | { |
| 6588 | if (msg_scrolled > 0) |
| 6589 | { |
| 6590 | /* Put the wildmenu just above the command line. If there is |
| 6591 | * no room, scroll the screen one line up. */ |
| 6592 | if (cmdline_row == Rows - 1) |
| 6593 | { |
| 6594 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6595 | ++msg_scrolled; |
| 6596 | } |
| 6597 | else |
| 6598 | { |
| 6599 | ++cmdline_row; |
| 6600 | ++row; |
| 6601 | } |
| 6602 | wild_menu_showing = WM_SCROLLED; |
| 6603 | } |
| 6604 | else |
| 6605 | { |
| 6606 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6607 | * Set 'winminheight' to zero to avoid that the window is |
| 6608 | * resized. */ |
| 6609 | if (lastwin->w_status_height == 0) |
| 6610 | { |
| 6611 | save_p_ls = p_ls; |
| 6612 | save_p_wmh = p_wmh; |
| 6613 | p_ls = 2; |
| 6614 | p_wmh = 0; |
| 6615 | last_status(FALSE); |
| 6616 | } |
| 6617 | wild_menu_showing = WM_SHOWN; |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | screen_puts(buf, row, 0, attr); |
| 6622 | if (selstart != NULL && highlight) |
| 6623 | { |
| 6624 | *selend = NUL; |
| 6625 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6626 | } |
| 6627 | |
| 6628 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6629 | } |
| 6630 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6631 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6632 | win_redraw_last_status(topframe); |
| 6633 | #else |
| 6634 | lastwin->w_redr_status = TRUE; |
| 6635 | #endif |
| 6636 | vim_free(buf); |
| 6637 | } |
| 6638 | #endif |
| 6639 | |
| 6640 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6641 | /* |
| 6642 | * Redraw the status line of window wp. |
| 6643 | * |
| 6644 | * If inversion is possible we use it. Else '=' characters are used. |
| 6645 | */ |
| 6646 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6647 | win_redr_status(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6648 | { |
| 6649 | int row; |
| 6650 | char_u *p; |
| 6651 | int len; |
| 6652 | int fillchar; |
| 6653 | int attr; |
| 6654 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6655 | static int busy = FALSE; |
| 6656 | |
| 6657 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6658 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6659 | if (busy) |
| 6660 | return; |
| 6661 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6662 | |
| 6663 | wp->w_redr_status = FALSE; |
| 6664 | if (wp->w_status_height == 0) |
| 6665 | { |
| 6666 | /* no status line, can only be last window */ |
| 6667 | redraw_cmdline = TRUE; |
| 6668 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6669 | else if (!redrawing() |
| 6670 | #ifdef FEAT_INS_EXPAND |
| 6671 | /* don't update status line when popup menu is visible and may be |
| 6672 | * drawn over it */ |
| 6673 | || pum_visible() |
| 6674 | #endif |
| 6675 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6676 | { |
| 6677 | /* Don't redraw right now, do it later. */ |
| 6678 | wp->w_redr_status = TRUE; |
| 6679 | } |
| 6680 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6681 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6682 | { |
| 6683 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6684 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6685 | } |
| 6686 | #endif |
| 6687 | else |
| 6688 | { |
| 6689 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6690 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6691 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6692 | p = NameBuff; |
| 6693 | len = (int)STRLEN(p); |
| 6694 | |
| 6695 | if (wp->w_buffer->b_help |
| 6696 | #ifdef FEAT_QUICKFIX |
| 6697 | || wp->w_p_pvw |
| 6698 | #endif |
| 6699 | || bufIsChanged(wp->w_buffer) |
| 6700 | || wp->w_buffer->b_p_ro) |
| 6701 | *(p + len++) = ' '; |
| 6702 | if (wp->w_buffer->b_help) |
| 6703 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6704 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6705 | len += (int)STRLEN(p + len); |
| 6706 | } |
| 6707 | #ifdef FEAT_QUICKFIX |
| 6708 | if (wp->w_p_pvw) |
| 6709 | { |
| 6710 | STRCPY(p + len, _("[Preview]")); |
| 6711 | len += (int)STRLEN(p + len); |
| 6712 | } |
| 6713 | #endif |
| 6714 | if (bufIsChanged(wp->w_buffer)) |
| 6715 | { |
| 6716 | STRCPY(p + len, "[+]"); |
| 6717 | len += 3; |
| 6718 | } |
| 6719 | if (wp->w_buffer->b_p_ro) |
| 6720 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6721 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6722 | len += 4; |
| 6723 | } |
| 6724 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6725 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6726 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6727 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6728 | if (this_ru_col <= 1) |
| 6729 | { |
| 6730 | p = (char_u *)"<"; /* No room for file name! */ |
| 6731 | len = 1; |
| 6732 | } |
| 6733 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6734 | #ifdef FEAT_MBYTE |
| 6735 | if (has_mbyte) |
| 6736 | { |
| 6737 | int clen = 0, i; |
| 6738 | |
| 6739 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6740 | clen = mb_string2cells(p, -1); |
| 6741 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6742 | /* Find first character that will fit. |
| 6743 | * Going from start to end is much faster for DBCS. */ |
| 6744 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6745 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6746 | clen -= (*mb_ptr2cells)(p + i); |
| 6747 | len = clen; |
| 6748 | if (i > 0) |
| 6749 | { |
| 6750 | p = p + i - 1; |
| 6751 | *p = '<'; |
| 6752 | ++len; |
| 6753 | } |
| 6754 | |
| 6755 | } |
| 6756 | else |
| 6757 | #endif |
| 6758 | if (len > this_ru_col - 1) |
| 6759 | { |
| 6760 | p += len - (this_ru_col - 1); |
| 6761 | *p = '<'; |
| 6762 | len = this_ru_col - 1; |
| 6763 | } |
| 6764 | |
| 6765 | row = W_WINROW(wp) + wp->w_height; |
| 6766 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6767 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6768 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6769 | |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6770 | if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6771 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6772 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6773 | - 1 + W_WINCOL(wp)), attr); |
| 6774 | |
| 6775 | #ifdef FEAT_CMDL_INFO |
| 6776 | win_redr_ruler(wp, TRUE); |
| 6777 | #endif |
| 6778 | } |
| 6779 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6780 | /* |
| 6781 | * May need to draw the character below the vertical separator. |
| 6782 | */ |
| 6783 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6784 | { |
| 6785 | if (stl_connected(wp)) |
| 6786 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6787 | else |
| 6788 | fillchar = fillchar_vsep(&attr); |
| 6789 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6790 | attr); |
| 6791 | } |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6792 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6793 | } |
| 6794 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6795 | #ifdef FEAT_STL_OPT |
| 6796 | /* |
| 6797 | * Redraw the status line according to 'statusline' and take care of any |
| 6798 | * errors encountered. |
| 6799 | */ |
| 6800 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6801 | redraw_custom_statusline(win_T *wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6802 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6803 | static int entered = FALSE; |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6804 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6805 | |
| 6806 | /* When called recursively return. This can happen when the statusline |
| 6807 | * contains an expression that triggers a redraw. */ |
| 6808 | if (entered) |
| 6809 | return; |
| 6810 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6811 | |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6812 | did_emsg = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6813 | win_redr_custom(wp, FALSE); |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6814 | if (did_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6815 | { |
| 6816 | /* When there is an error disable the statusline, otherwise the |
| 6817 | * display is messed up with errors and a redraw triggers the problem |
| 6818 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6819 | set_string_option_direct((char_u *)"statusline", -1, |
| 6820 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6821 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6822 | } |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6823 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6824 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6825 | } |
| 6826 | #endif |
| 6827 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6828 | /* |
| 6829 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6830 | * line of the window right of it. If not, then it's a vertical separator. |
| 6831 | * Only call if (wp->w_vsep_width != 0). |
| 6832 | */ |
| 6833 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6834 | stl_connected(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6835 | { |
| 6836 | frame_T *fr; |
| 6837 | |
| 6838 | fr = wp->w_frame; |
| 6839 | while (fr->fr_parent != NULL) |
| 6840 | { |
| 6841 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6842 | { |
| 6843 | if (fr->fr_next != NULL) |
| 6844 | break; |
| 6845 | } |
| 6846 | else |
| 6847 | { |
| 6848 | if (fr->fr_next != NULL) |
| 6849 | return TRUE; |
| 6850 | } |
| 6851 | fr = fr->fr_parent; |
| 6852 | } |
| 6853 | return FALSE; |
| 6854 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6855 | |
| 6856 | #endif /* FEAT_WINDOWS */ |
| 6857 | |
| 6858 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6859 | /* |
| 6860 | * Get the value to show for the language mappings, active 'keymap'. |
| 6861 | */ |
| 6862 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6863 | get_keymap_str( |
| 6864 | win_T *wp, |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6865 | char_u *fmt, /* format string containing one %s item */ |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6866 | char_u *buf, /* buffer for the result */ |
| 6867 | int len) /* length of buffer */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6868 | { |
| 6869 | char_u *p; |
| 6870 | |
| 6871 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6872 | return FALSE; |
| 6873 | |
| 6874 | { |
| 6875 | #ifdef FEAT_EVAL |
| 6876 | buf_T *old_curbuf = curbuf; |
| 6877 | win_T *old_curwin = curwin; |
| 6878 | char_u *s; |
| 6879 | |
| 6880 | curbuf = wp->w_buffer; |
| 6881 | curwin = wp; |
| 6882 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6883 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6884 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6885 | --emsg_skip; |
| 6886 | curbuf = old_curbuf; |
| 6887 | curwin = old_curwin; |
| 6888 | if (p == NULL || *p == NUL) |
| 6889 | #endif |
| 6890 | { |
| 6891 | #ifdef FEAT_KEYMAP |
| 6892 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6893 | p = wp->w_buffer->b_p_keymap; |
| 6894 | else |
| 6895 | #endif |
| 6896 | p = (char_u *)"lang"; |
| 6897 | } |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6898 | if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6899 | buf[0] = NUL; |
| 6900 | #ifdef FEAT_EVAL |
| 6901 | vim_free(s); |
| 6902 | #endif |
| 6903 | } |
| 6904 | return buf[0] != NUL; |
| 6905 | } |
| 6906 | #endif |
| 6907 | |
| 6908 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6909 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6910 | * Redraw the status line or ruler of window "wp". |
| 6911 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6912 | */ |
| 6913 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6914 | win_redr_custom( |
| 6915 | win_T *wp, |
| 6916 | int draw_ruler) /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6917 | { |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6918 | static int entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6919 | int attr; |
| 6920 | int curattr; |
| 6921 | int row; |
| 6922 | int col = 0; |
| 6923 | int maxwidth; |
| 6924 | int width; |
| 6925 | int n; |
| 6926 | int len; |
| 6927 | int fillchar; |
| 6928 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6929 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6930 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6931 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6932 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6933 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6934 | win_T *ewp; |
| 6935 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6936 | |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6937 | /* There is a tiny chance that this gets called recursively: When |
| 6938 | * redrawing a status line triggers redrawing the ruler or tabline. |
| 6939 | * Avoid trouble by not allowing recursion. */ |
| 6940 | if (entered) |
| 6941 | return; |
| 6942 | entered = TRUE; |
| 6943 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6944 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6945 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6946 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6947 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6948 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6949 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6950 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6951 | attr = hl_attr(HLF_TPF); |
| 6952 | maxwidth = Columns; |
| 6953 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6954 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6955 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6956 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6957 | else |
| 6958 | { |
| 6959 | row = W_WINROW(wp) + wp->w_height; |
| 6960 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6961 | maxwidth = W_WIDTH(wp); |
| 6962 | |
| 6963 | if (draw_ruler) |
| 6964 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6965 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6966 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6967 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6968 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6969 | if (*++stl == '-') |
| 6970 | stl++; |
| 6971 | if (atoi((char *)stl)) |
| 6972 | while (VIM_ISDIGIT(*stl)) |
| 6973 | stl++; |
| 6974 | if (*stl++ != '(') |
| 6975 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6976 | } |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6977 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6978 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6979 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6980 | col = (W_WIDTH(wp) + 1) / 2; |
| 6981 | #else |
| 6982 | col = ru_col; |
| 6983 | if (col > (Columns + 1) / 2) |
| 6984 | col = (Columns + 1) / 2; |
| 6985 | #endif |
| 6986 | maxwidth = W_WIDTH(wp) - col; |
| 6987 | #ifdef FEAT_WINDOWS |
| 6988 | if (!wp->w_status_height) |
| 6989 | #endif |
| 6990 | { |
| 6991 | row = Rows - 1; |
| 6992 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6993 | fillchar = ' '; |
| 6994 | attr = 0; |
| 6995 | } |
| 6996 | |
| 6997 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6998 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6999 | # endif |
| 7000 | } |
| 7001 | else |
| 7002 | { |
| 7003 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7004 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7005 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7006 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7007 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7008 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 7009 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7010 | # endif |
| 7011 | } |
| 7012 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 7013 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7014 | col += W_WINCOL(wp); |
| 7015 | #endif |
| 7016 | } |
| 7017 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7018 | if (maxwidth <= 0) |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7019 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7020 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7021 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 7022 | * the cursor away and back. */ |
| 7023 | ewp = wp == NULL ? curwin : wp; |
| 7024 | p_crb_save = ewp->w_p_crb; |
| 7025 | ewp->w_p_crb = FALSE; |
| 7026 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7027 | /* Make a copy, because the statusline may include a function call that |
| 7028 | * might change the option value and free the memory. */ |
| 7029 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7030 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7031 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7032 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7033 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7034 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7035 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 7036 | /* Make all characters printable. */ |
| 7037 | p = transstr(buf); |
| 7038 | if (p != NULL) |
| 7039 | { |
| 7040 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 7041 | vim_free(p); |
| 7042 | } |
| 7043 | |
| 7044 | /* fill up with "fillchar" */ |
| 7045 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 7046 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7047 | { |
| 7048 | #ifdef FEAT_MBYTE |
| 7049 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 7050 | #else |
| 7051 | buf[len++] = fillchar; |
| 7052 | #endif |
| 7053 | ++width; |
| 7054 | } |
| 7055 | buf[len] = NUL; |
| 7056 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7057 | /* |
| 7058 | * Draw each snippet with the specified highlighting. |
| 7059 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7060 | curattr = attr; |
| 7061 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7062 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7063 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7064 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7065 | screen_puts_len(p, len, row, col, curattr); |
| 7066 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7067 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7068 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7069 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7070 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7071 | else if (hltab[n].userhl < 0) |
| 7072 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7073 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 7074 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7075 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7076 | #endif |
| 7077 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7078 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7079 | } |
| 7080 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7081 | |
| 7082 | if (wp == NULL) |
| 7083 | { |
| 7084 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 7085 | col = 0; |
| 7086 | len = 0; |
| 7087 | p = buf; |
| 7088 | fillchar = 0; |
| 7089 | for (n = 0; tabtab[n].start != NULL; n++) |
| 7090 | { |
| 7091 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 7092 | while (col < len) |
| 7093 | TabPageIdxs[col++] = fillchar; |
| 7094 | p = tabtab[n].start; |
| 7095 | fillchar = tabtab[n].userhl; |
| 7096 | } |
| 7097 | while (col < Columns) |
| 7098 | TabPageIdxs[col++] = fillchar; |
| 7099 | } |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7100 | |
| 7101 | theend: |
| 7102 | entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7103 | } |
| 7104 | |
| 7105 | #endif /* FEAT_STL_OPT */ |
| 7106 | |
| 7107 | /* |
| 7108 | * Output a single character directly to the screen and update ScreenLines. |
| 7109 | */ |
| 7110 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7111 | screen_putchar(int c, int row, int col, int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7112 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7113 | char_u buf[MB_MAXBYTES + 1]; |
| 7114 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7115 | #ifdef FEAT_MBYTE |
| 7116 | if (has_mbyte) |
| 7117 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 7118 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7119 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7120 | { |
| 7121 | buf[0] = c; |
| 7122 | buf[1] = NUL; |
| 7123 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7124 | screen_puts(buf, row, col, attr); |
| 7125 | } |
| 7126 | |
| 7127 | /* |
| 7128 | * Get a single character directly from ScreenLines into "bytes[]". |
| 7129 | * Also return its attribute in *attrp; |
| 7130 | */ |
| 7131 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7132 | screen_getbytes(int row, int col, char_u *bytes, int *attrp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7133 | { |
| 7134 | unsigned off; |
| 7135 | |
| 7136 | /* safety check */ |
| 7137 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 7138 | { |
| 7139 | off = LineOffset[row] + col; |
| 7140 | *attrp = ScreenAttrs[off]; |
| 7141 | bytes[0] = ScreenLines[off]; |
| 7142 | bytes[1] = NUL; |
| 7143 | |
| 7144 | #ifdef FEAT_MBYTE |
| 7145 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7146 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 7147 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7148 | { |
| 7149 | bytes[0] = ScreenLines[off]; |
| 7150 | bytes[1] = ScreenLines2[off]; |
| 7151 | bytes[2] = NUL; |
| 7152 | } |
| 7153 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 7154 | { |
| 7155 | bytes[1] = ScreenLines[off + 1]; |
| 7156 | bytes[2] = NUL; |
| 7157 | } |
| 7158 | #endif |
| 7159 | } |
| 7160 | } |
| 7161 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7162 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 7163 | static int screen_comp_differs(int, int*); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7164 | |
| 7165 | /* |
| 7166 | * Return TRUE if composing characters for screen posn "off" differs from |
| 7167 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7168 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7169 | */ |
| 7170 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7171 | screen_comp_differs(int off, int *u8cc) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7172 | { |
| 7173 | int i; |
| 7174 | |
| 7175 | for (i = 0; i < Screen_mco; ++i) |
| 7176 | { |
| 7177 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 7178 | return TRUE; |
| 7179 | if (u8cc[i] == 0) |
| 7180 | break; |
| 7181 | } |
| 7182 | return FALSE; |
| 7183 | } |
| 7184 | #endif |
| 7185 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7186 | /* |
| 7187 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 7188 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 7189 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 7190 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 7191 | */ |
| 7192 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7193 | screen_puts( |
| 7194 | char_u *text, |
| 7195 | int row, |
| 7196 | int col, |
| 7197 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7198 | { |
| 7199 | screen_puts_len(text, -1, row, col, attr); |
| 7200 | } |
| 7201 | |
| 7202 | /* |
| 7203 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 7204 | * a NUL. |
| 7205 | */ |
| 7206 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7207 | screen_puts_len( |
| 7208 | char_u *text, |
| 7209 | int textlen, |
| 7210 | int row, |
| 7211 | int col, |
| 7212 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7213 | { |
| 7214 | unsigned off; |
| 7215 | char_u *ptr = text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7216 | int len = textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7217 | int c; |
| 7218 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7219 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7220 | int mbyte_blen = 1; |
| 7221 | int mbyte_cells = 1; |
| 7222 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7223 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7224 | int clear_next_cell = FALSE; |
| 7225 | # ifdef FEAT_ARABIC |
| 7226 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7227 | int pc, nc, nc1; |
| 7228 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7229 | # endif |
| 7230 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7231 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7232 | int force_redraw_this; |
| 7233 | int force_redraw_next = FALSE; |
| 7234 | #endif |
| 7235 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7236 | |
| 7237 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 7238 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7239 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7240 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7241 | #ifdef FEAT_MBYTE |
| 7242 | /* When drawing over the right halve of a double-wide char clear out the |
| 7243 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7244 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7245 | # ifdef FEAT_GUI |
| 7246 | && !gui.in_use |
| 7247 | # endif |
| 7248 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7249 | { |
| 7250 | ScreenLines[off - 1] = ' '; |
| 7251 | ScreenAttrs[off - 1] = 0; |
| 7252 | if (enc_utf8) |
| 7253 | { |
| 7254 | ScreenLinesUC[off - 1] = 0; |
| 7255 | ScreenLinesC[0][off - 1] = 0; |
| 7256 | } |
| 7257 | /* redraw the previous cell, make it empty */ |
| 7258 | screen_char(off - 1, row, col - 1); |
| 7259 | /* force the cell at "col" to be redrawn */ |
| 7260 | force_redraw_next = TRUE; |
| 7261 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7262 | #endif |
| 7263 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7264 | #ifdef FEAT_MBYTE |
| 7265 | max_off = LineOffset[row] + screen_Columns; |
| 7266 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 7267 | while (col < screen_Columns |
| 7268 | && (len < 0 || (int)(ptr - text) < len) |
| 7269 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7270 | { |
| 7271 | c = *ptr; |
| 7272 | #ifdef FEAT_MBYTE |
| 7273 | /* check if this is the first byte of a multibyte */ |
| 7274 | if (has_mbyte) |
| 7275 | { |
| 7276 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7277 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7278 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7279 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7280 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7281 | mbyte_cells = 1; |
| 7282 | else if (enc_dbcs != 0) |
| 7283 | mbyte_cells = mbyte_blen; |
| 7284 | else /* enc_utf8 */ |
| 7285 | { |
| 7286 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7287 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | (int)((text + len) - ptr)); |
| 7289 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7290 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7291 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7292 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7293 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 7294 | if (u8c >= 0x10000) |
| 7295 | { |
| 7296 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 7297 | if (attr == 0) |
| 7298 | attr = hl_attr(HLF_8); |
| 7299 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7300 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7301 | # ifdef FEAT_ARABIC |
| 7302 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 7303 | { |
| 7304 | /* Do Arabic shaping. */ |
| 7305 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 7306 | { |
| 7307 | /* Past end of string to be displayed. */ |
| 7308 | nc = NUL; |
| 7309 | nc1 = NUL; |
| 7310 | } |
| 7311 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7312 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 7313 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 7314 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7315 | nc1 = pcc[0]; |
| 7316 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7317 | pc = prev_c; |
| 7318 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7319 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7320 | } |
| 7321 | else |
| 7322 | prev_c = u8c; |
| 7323 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 7324 | if (col + mbyte_cells > screen_Columns) |
| 7325 | { |
| 7326 | /* Only 1 cell left, but character requires 2 cells: |
| 7327 | * display a '>' in the last column to avoid wrapping. */ |
| 7328 | c = '>'; |
| 7329 | mbyte_cells = 1; |
| 7330 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7331 | } |
| 7332 | } |
| 7333 | #endif |
| 7334 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7335 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7336 | force_redraw_this = force_redraw_next; |
| 7337 | force_redraw_next = FALSE; |
| 7338 | #endif |
| 7339 | |
| 7340 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7341 | #ifdef FEAT_MBYTE |
| 7342 | || (mbyte_cells == 2 |
| 7343 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 7344 | || (enc_dbcs == DBCS_JPNU |
| 7345 | && c == 0x8e |
| 7346 | && ScreenLines2[off] != ptr[1]) |
| 7347 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7348 | && (ScreenLinesUC[off] != |
| 7349 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 7350 | || (ScreenLinesUC[off] != 0 |
| 7351 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7352 | #endif |
| 7353 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7354 | || exmode_active; |
| 7355 | |
| 7356 | if (need_redraw |
| 7357 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7358 | || force_redraw_this |
| 7359 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7360 | ) |
| 7361 | { |
| 7362 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7363 | /* The bold trick makes a single row of pixels appear in the next |
| 7364 | * character. When a bold character is removed, the next |
| 7365 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7366 | * and for some xterms. */ |
| 7367 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7368 | # ifdef FEAT_GUI |
| 7369 | gui.in_use |
| 7370 | # endif |
| 7371 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7372 | || |
| 7373 | # endif |
| 7374 | # ifdef UNIX |
| 7375 | term_is_xterm |
| 7376 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7377 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7378 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7379 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7380 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7381 | if (n > HL_ALL) |
| 7382 | n = syn_attr2attr(n); |
| 7383 | if (n & HL_BOLD) |
| 7384 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7385 | } |
| 7386 | #endif |
| 7387 | #ifdef FEAT_MBYTE |
| 7388 | /* When at the end of the text and overwriting a two-cell |
| 7389 | * character with a one-cell character, need to clear the next |
| 7390 | * cell. Also when overwriting the left halve of a two-cell char |
| 7391 | * with the right halve of a two-cell char. Do this only once |
| 7392 | * (mb_off2cells() may return 2 on the right halve). */ |
| 7393 | if (clear_next_cell) |
| 7394 | clear_next_cell = FALSE; |
| 7395 | else if (has_mbyte |
| 7396 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 7397 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7398 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7399 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7400 | && (*mb_off2cells)(off, max_off) == 1 |
| 7401 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7402 | clear_next_cell = TRUE; |
| 7403 | |
| 7404 | /* Make sure we never leave a second byte of a double-byte behind, |
| 7405 | * it confuses mb_off2cells(). */ |
| 7406 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7407 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7408 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7409 | && (*mb_off2cells)(off, max_off) == 1 |
| 7410 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7411 | ScreenLines[off + mbyte_blen] = 0; |
| 7412 | #endif |
| 7413 | ScreenLines[off] = c; |
| 7414 | ScreenAttrs[off] = attr; |
| 7415 | #ifdef FEAT_MBYTE |
| 7416 | if (enc_utf8) |
| 7417 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7418 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7419 | ScreenLinesUC[off] = 0; |
| 7420 | else |
| 7421 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7422 | int i; |
| 7423 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7424 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7425 | for (i = 0; i < Screen_mco; ++i) |
| 7426 | { |
| 7427 | ScreenLinesC[i][off] = u8cc[i]; |
| 7428 | if (u8cc[i] == 0) |
| 7429 | break; |
| 7430 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7431 | } |
| 7432 | if (mbyte_cells == 2) |
| 7433 | { |
| 7434 | ScreenLines[off + 1] = 0; |
| 7435 | ScreenAttrs[off + 1] = attr; |
| 7436 | } |
| 7437 | screen_char(off, row, col); |
| 7438 | } |
| 7439 | else if (mbyte_cells == 2) |
| 7440 | { |
| 7441 | ScreenLines[off + 1] = ptr[1]; |
| 7442 | ScreenAttrs[off + 1] = attr; |
| 7443 | screen_char_2(off, row, col); |
| 7444 | } |
| 7445 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7446 | { |
| 7447 | ScreenLines2[off] = ptr[1]; |
| 7448 | screen_char(off, row, col); |
| 7449 | } |
| 7450 | else |
| 7451 | #endif |
| 7452 | screen_char(off, row, col); |
| 7453 | } |
| 7454 | #ifdef FEAT_MBYTE |
| 7455 | if (has_mbyte) |
| 7456 | { |
| 7457 | off += mbyte_cells; |
| 7458 | col += mbyte_cells; |
| 7459 | ptr += mbyte_blen; |
| 7460 | if (clear_next_cell) |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7461 | { |
| 7462 | /* This only happens at the end, display one space next. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7463 | ptr = (char_u *)" "; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7464 | len = -1; |
| 7465 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7466 | } |
| 7467 | else |
| 7468 | #endif |
| 7469 | { |
| 7470 | ++off; |
| 7471 | ++col; |
| 7472 | ++ptr; |
| 7473 | } |
| 7474 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7475 | |
| 7476 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7477 | /* If we detected the next character needs to be redrawn, but the text |
| 7478 | * doesn't extend up to there, update the character here. */ |
| 7479 | if (force_redraw_next && col < screen_Columns) |
| 7480 | { |
| 7481 | # ifdef FEAT_MBYTE |
| 7482 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7483 | screen_char_2(off, row, col); |
| 7484 | else |
| 7485 | # endif |
| 7486 | screen_char(off, row, col); |
| 7487 | } |
| 7488 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | #ifdef FEAT_SEARCH_EXTRA |
| 7492 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7493 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7494 | */ |
| 7495 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7496 | start_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7497 | { |
| 7498 | if (p_hls && !no_hlsearch) |
| 7499 | { |
| 7500 | last_pat_prog(&search_hl.rm); |
| 7501 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7502 | # ifdef FEAT_RELTIME |
| 7503 | /* Set the time limit to 'redrawtime'. */ |
| 7504 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7505 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7506 | } |
| 7507 | } |
| 7508 | |
| 7509 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7510 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7511 | */ |
| 7512 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7513 | end_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7514 | { |
| 7515 | if (search_hl.rm.regprog != NULL) |
| 7516 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7517 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7518 | search_hl.rm.regprog = NULL; |
| 7519 | } |
| 7520 | } |
| 7521 | |
| 7522 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7523 | * Init for calling prepare_search_hl(). |
| 7524 | */ |
| 7525 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7526 | init_search_hl(win_T *wp) |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7527 | { |
| 7528 | matchitem_T *cur; |
| 7529 | |
| 7530 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7531 | * match */ |
| 7532 | cur = wp->w_match_head; |
| 7533 | while (cur != NULL) |
| 7534 | { |
| 7535 | cur->hl.rm = cur->match; |
| 7536 | if (cur->hlg_id == 0) |
| 7537 | cur->hl.attr = 0; |
| 7538 | else |
| 7539 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7540 | cur->hl.buf = wp->w_buffer; |
| 7541 | cur->hl.lnum = 0; |
| 7542 | cur->hl.first_lnum = 0; |
| 7543 | # ifdef FEAT_RELTIME |
| 7544 | /* Set the time limit to 'redrawtime'. */ |
| 7545 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7546 | # endif |
| 7547 | cur = cur->next; |
| 7548 | } |
| 7549 | search_hl.buf = wp->w_buffer; |
| 7550 | search_hl.lnum = 0; |
| 7551 | search_hl.first_lnum = 0; |
| 7552 | /* time limit is set at the toplevel, for all windows */ |
| 7553 | } |
| 7554 | |
| 7555 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7556 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7557 | */ |
| 7558 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7559 | prepare_search_hl(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7560 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7561 | matchitem_T *cur; /* points to the match list */ |
| 7562 | match_T *shl; /* points to search_hl or a match */ |
| 7563 | int shl_flag; /* flag to indicate whether search_hl |
| 7564 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7565 | int pos_inprogress; /* marks that position match search is |
| 7566 | in progress */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7567 | int n; |
| 7568 | |
| 7569 | /* |
| 7570 | * When using a multi-line pattern, start searching at the top |
| 7571 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7572 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7573 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7574 | cur = wp->w_match_head; |
| 7575 | shl_flag = FALSE; |
| 7576 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7577 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7578 | if (shl_flag == FALSE) |
| 7579 | { |
| 7580 | shl = &search_hl; |
| 7581 | shl_flag = TRUE; |
| 7582 | } |
| 7583 | else |
| 7584 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7585 | if (shl->rm.regprog != NULL |
| 7586 | && shl->lnum == 0 |
| 7587 | && re_multiline(shl->rm.regprog)) |
| 7588 | { |
| 7589 | if (shl->first_lnum == 0) |
| 7590 | { |
| 7591 | # ifdef FEAT_FOLDING |
| 7592 | for (shl->first_lnum = lnum; |
| 7593 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7594 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7595 | NULL, NULL, TRUE, NULL)) |
| 7596 | break; |
| 7597 | # else |
| 7598 | shl->first_lnum = wp->w_topline; |
| 7599 | # endif |
| 7600 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7601 | if (cur != NULL) |
| 7602 | cur->pos.cur = 0; |
| 7603 | pos_inprogress = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7604 | n = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7605 | while (shl->first_lnum < lnum && (shl->rm.regprog != NULL |
| 7606 | || (cur != NULL && pos_inprogress))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7607 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7608 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, cur); |
| 7609 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
| 7610 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7611 | if (shl->lnum != 0) |
| 7612 | { |
| 7613 | shl->first_lnum = shl->lnum |
| 7614 | + shl->rm.endpos[0].lnum |
| 7615 | - shl->rm.startpos[0].lnum; |
| 7616 | n = shl->rm.endpos[0].col; |
| 7617 | } |
| 7618 | else |
| 7619 | { |
| 7620 | ++shl->first_lnum; |
| 7621 | n = 0; |
| 7622 | } |
| 7623 | } |
| 7624 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7625 | if (shl != &search_hl && cur != NULL) |
| 7626 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7627 | } |
| 7628 | } |
| 7629 | |
| 7630 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7631 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7632 | * Uses shl->buf. |
| 7633 | * Sets shl->lnum and shl->rm contents. |
| 7634 | * Note: Assumes a previous match is always before "lnum", unless |
| 7635 | * shl->lnum is zero. |
| 7636 | * Careful: Any pointers for buffer lines will become invalid. |
| 7637 | */ |
| 7638 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7639 | next_search_hl( |
| 7640 | win_T *win, |
| 7641 | match_T *shl, /* points to search_hl or a match */ |
| 7642 | linenr_T lnum, |
| 7643 | colnr_T mincol, /* minimal column for a match */ |
| 7644 | matchitem_T *cur) /* to retrieve match positions if any */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7645 | { |
| 7646 | linenr_T l; |
| 7647 | colnr_T matchcol; |
| 7648 | long nmatched; |
| 7649 | |
| 7650 | if (shl->lnum != 0) |
| 7651 | { |
| 7652 | /* Check for three situations: |
| 7653 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7654 | * 2. If the previous match includes "mincol", use it. |
| 7655 | * 3. Continue after the previous match. |
| 7656 | */ |
| 7657 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7658 | if (lnum > l) |
| 7659 | shl->lnum = 0; |
| 7660 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7661 | return; |
| 7662 | } |
| 7663 | |
| 7664 | /* |
| 7665 | * Repeat searching for a match until one is found that includes "mincol" |
| 7666 | * or none is found in this line. |
| 7667 | */ |
| 7668 | called_emsg = FALSE; |
| 7669 | for (;;) |
| 7670 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7671 | #ifdef FEAT_RELTIME |
| 7672 | /* Stop searching after passing the time limit. */ |
| 7673 | if (profile_passed_limit(&(shl->tm))) |
| 7674 | { |
| 7675 | shl->lnum = 0; /* no match found in time */ |
| 7676 | break; |
| 7677 | } |
| 7678 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7679 | /* Three situations: |
| 7680 | * 1. No useful previous match: search from start of line. |
| 7681 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7682 | * Break the loop if this is beyond the end of the line. |
| 7683 | * 3. Vi compatible searching: continue at end of previous match. |
| 7684 | */ |
| 7685 | if (shl->lnum == 0) |
| 7686 | matchcol = 0; |
| 7687 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7688 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7689 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7690 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7691 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7692 | |
| 7693 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7694 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7695 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7696 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7697 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7698 | shl->lnum = 0; |
| 7699 | break; |
| 7700 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7701 | #ifdef FEAT_MBYTE |
| 7702 | if (has_mbyte) |
| 7703 | matchcol += mb_ptr2len(ml); |
| 7704 | else |
| 7705 | #endif |
| 7706 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7707 | } |
| 7708 | else |
| 7709 | matchcol = shl->rm.endpos[0].col; |
| 7710 | |
| 7711 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7712 | if (shl->rm.regprog != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7713 | { |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7714 | /* Remember whether shl->rm is using a copy of the regprog in |
| 7715 | * cur->match. */ |
| 7716 | int regprog_is_copy = (shl != &search_hl && cur != NULL |
| 7717 | && shl == &cur->hl |
| 7718 | && cur->match.regprog == cur->hl.rm.regprog); |
| 7719 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7720 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, |
| 7721 | matchcol, |
| 7722 | #ifdef FEAT_RELTIME |
| 7723 | &(shl->tm) |
| 7724 | #else |
| 7725 | NULL |
| 7726 | #endif |
| 7727 | ); |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7728 | /* Copy the regprog, in case it got freed and recompiled. */ |
| 7729 | if (regprog_is_copy) |
| 7730 | cur->match.regprog = cur->hl.rm.regprog; |
| 7731 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7732 | if (called_emsg || got_int) |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7733 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7734 | /* Error while handling regexp: stop using this regexp. */ |
| 7735 | if (shl == &search_hl) |
| 7736 | { |
| 7737 | /* don't free regprog in the match list, it's a copy */ |
| 7738 | vim_regfree(shl->rm.regprog); |
| 7739 | SET_NO_HLSEARCH(TRUE); |
| 7740 | } |
| 7741 | shl->rm.regprog = NULL; |
| 7742 | shl->lnum = 0; |
| 7743 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" |
| 7744 | message */ |
| 7745 | break; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7746 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7747 | } |
| 7748 | else if (cur != NULL) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7749 | nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol); |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7750 | else |
| 7751 | nmatched = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7752 | if (nmatched == 0) |
| 7753 | { |
| 7754 | shl->lnum = 0; /* no match found */ |
| 7755 | break; |
| 7756 | } |
| 7757 | if (shl->rm.startpos[0].lnum > 0 |
| 7758 | || shl->rm.startpos[0].col >= mincol |
| 7759 | || nmatched > 1 |
| 7760 | || shl->rm.endpos[0].col > mincol) |
| 7761 | { |
| 7762 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7763 | break; /* useful match found */ |
| 7764 | } |
| 7765 | } |
| 7766 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7767 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7768 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7769 | next_search_hl_pos( |
| 7770 | match_T *shl, /* points to a match */ |
| 7771 | linenr_T lnum, |
| 7772 | posmatch_T *posmatch, /* match positions */ |
| 7773 | colnr_T mincol) /* minimal column for a match */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7774 | { |
| 7775 | int i; |
Bram Moolenaar | b6da44a | 2014-06-25 18:15:22 +0200 | [diff] [blame] | 7776 | int bot = -1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7777 | |
| 7778 | shl->lnum = 0; |
| 7779 | for (i = posmatch->cur; i < MAXPOSMATCH; i++) |
| 7780 | { |
| 7781 | if (posmatch->pos[i].lnum == 0) |
| 7782 | break; |
| 7783 | if (posmatch->pos[i].col < mincol) |
| 7784 | continue; |
| 7785 | if (posmatch->pos[i].lnum == lnum) |
| 7786 | { |
| 7787 | if (shl->lnum == lnum) |
| 7788 | { |
| 7789 | /* partially sort positions by column numbers |
| 7790 | * on the same line */ |
| 7791 | if (posmatch->pos[i].col < posmatch->pos[bot].col) |
| 7792 | { |
| 7793 | llpos_T tmp = posmatch->pos[i]; |
| 7794 | |
| 7795 | posmatch->pos[i] = posmatch->pos[bot]; |
| 7796 | posmatch->pos[bot] = tmp; |
| 7797 | } |
| 7798 | } |
| 7799 | else |
| 7800 | { |
| 7801 | bot = i; |
| 7802 | shl->lnum = lnum; |
| 7803 | } |
| 7804 | } |
| 7805 | } |
| 7806 | posmatch->cur = 0; |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 7807 | if (shl->lnum == lnum && bot >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7808 | { |
| 7809 | colnr_T start = posmatch->pos[bot].col == 0 |
| 7810 | ? 0 : posmatch->pos[bot].col - 1; |
| 7811 | colnr_T end = posmatch->pos[bot].col == 0 |
| 7812 | ? MAXCOL : start + posmatch->pos[bot].len; |
| 7813 | |
| 7814 | shl->rm.startpos[0].lnum = 0; |
| 7815 | shl->rm.startpos[0].col = start; |
| 7816 | shl->rm.endpos[0].lnum = 0; |
| 7817 | shl->rm.endpos[0].col = end; |
| 7818 | posmatch->cur = bot + 1; |
| 7819 | return TRUE; |
| 7820 | } |
| 7821 | return FALSE; |
| 7822 | } |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 7823 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7824 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7825 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7826 | screen_start_highlight(int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7827 | { |
| 7828 | attrentry_T *aep = NULL; |
| 7829 | |
| 7830 | screen_attr = attr; |
| 7831 | if (full_screen |
| 7832 | #ifdef WIN3264 |
| 7833 | && termcap_active |
| 7834 | #endif |
| 7835 | ) |
| 7836 | { |
| 7837 | #ifdef FEAT_GUI |
| 7838 | if (gui.in_use) |
| 7839 | { |
| 7840 | char buf[20]; |
| 7841 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7842 | /* The GUI handles this internally. */ |
| 7843 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7844 | OUT_STR(buf); |
| 7845 | } |
| 7846 | else |
| 7847 | #endif |
| 7848 | { |
| 7849 | if (attr > HL_ALL) /* special HL attr. */ |
| 7850 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7851 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7852 | aep = syn_cterm_attr2entry(attr); |
| 7853 | else |
| 7854 | aep = syn_term_attr2entry(attr); |
| 7855 | if (aep == NULL) /* did ":syntax clear" */ |
| 7856 | attr = 0; |
| 7857 | else |
| 7858 | attr = aep->ae_attr; |
| 7859 | } |
| 7860 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7861 | out_str(T_MD); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7862 | else if (aep != NULL && cterm_normal_fg_bold && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7863 | #ifdef FEAT_TERMGUICOLORS |
| 7864 | (p_tgc ? |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7865 | (aep->ae_u.cterm.fg_rgb != (long_u)INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7866 | #endif |
| 7867 | (t_colors > 1 && aep->ae_u.cterm.fg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7868 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7869 | ) |
| 7870 | #endif |
| 7871 | ) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7872 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7873 | * has a FG color defined, clear BOLD. */ |
| 7874 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7875 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7876 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7877 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7878 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7879 | out_str(T_US); |
| 7880 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7881 | out_str(T_CZH); |
| 7882 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7883 | out_str(T_MR); |
| 7884 | |
| 7885 | /* |
| 7886 | * Output the color or start string after bold etc., in case the |
| 7887 | * bold etc. override the color setting. |
| 7888 | */ |
| 7889 | if (aep != NULL) |
| 7890 | { |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7891 | #ifdef FEAT_TERMGUICOLORS |
| 7892 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7893 | { |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7894 | if (aep->ae_u.cterm.fg_rgb != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7895 | term_fg_rgb_color(aep->ae_u.cterm.fg_rgb); |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7896 | if (aep->ae_u.cterm.bg_rgb != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7897 | term_bg_rgb_color(aep->ae_u.cterm.bg_rgb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7898 | } |
| 7899 | else |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7900 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7901 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7902 | if (t_colors > 1) |
| 7903 | { |
| 7904 | if (aep->ae_u.cterm.fg_color) |
| 7905 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7906 | if (aep->ae_u.cterm.bg_color) |
| 7907 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7908 | } |
| 7909 | else |
| 7910 | { |
| 7911 | if (aep->ae_u.term.start != NULL) |
| 7912 | out_str(aep->ae_u.term.start); |
| 7913 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7914 | } |
| 7915 | } |
| 7916 | } |
| 7917 | } |
| 7918 | } |
| 7919 | |
| 7920 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7921 | screen_stop_highlight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7922 | { |
| 7923 | int do_ME = FALSE; /* output T_ME code */ |
| 7924 | |
| 7925 | if (screen_attr != 0 |
| 7926 | #ifdef WIN3264 |
| 7927 | && termcap_active |
| 7928 | #endif |
| 7929 | ) |
| 7930 | { |
| 7931 | #ifdef FEAT_GUI |
| 7932 | if (gui.in_use) |
| 7933 | { |
| 7934 | char buf[20]; |
| 7935 | |
| 7936 | /* use internal GUI code */ |
| 7937 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7938 | OUT_STR(buf); |
| 7939 | } |
| 7940 | else |
| 7941 | #endif |
| 7942 | { |
| 7943 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7944 | { |
| 7945 | attrentry_T *aep; |
| 7946 | |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7947 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7948 | { |
| 7949 | /* |
| 7950 | * Assume that t_me restores the original colors! |
| 7951 | */ |
| 7952 | aep = syn_cterm_attr2entry(screen_attr); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7953 | if (aep != NULL && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7954 | #ifdef FEAT_TERMGUICOLORS |
| 7955 | (p_tgc ? |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 7956 | (aep->ae_u.cterm.fg_rgb != (long_u)INVALCOLOR || |
| 7957 | aep->ae_u.cterm.bg_rgb != (long_u)INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7958 | #endif |
| 7959 | (aep->ae_u.cterm.fg_color || aep->ae_u.cterm.bg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7960 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7961 | ) |
| 7962 | #endif |
| 7963 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7964 | do_ME = TRUE; |
| 7965 | } |
| 7966 | else |
| 7967 | { |
| 7968 | aep = syn_term_attr2entry(screen_attr); |
| 7969 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7970 | { |
| 7971 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7972 | do_ME = TRUE; |
| 7973 | else |
| 7974 | out_str(aep->ae_u.term.stop); |
| 7975 | } |
| 7976 | } |
| 7977 | if (aep == NULL) /* did ":syntax clear" */ |
| 7978 | screen_attr = 0; |
| 7979 | else |
| 7980 | screen_attr = aep->ae_attr; |
| 7981 | } |
| 7982 | |
| 7983 | /* |
| 7984 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7985 | * same sequence several times. |
| 7986 | */ |
| 7987 | if (screen_attr & HL_STANDOUT) |
| 7988 | { |
| 7989 | if (STRCMP(T_SE, T_ME) == 0) |
| 7990 | do_ME = TRUE; |
| 7991 | else |
| 7992 | out_str(T_SE); |
| 7993 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7994 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7995 | { |
| 7996 | if (STRCMP(T_UE, T_ME) == 0) |
| 7997 | do_ME = TRUE; |
| 7998 | else |
| 7999 | out_str(T_UE); |
| 8000 | } |
| 8001 | if (screen_attr & HL_ITALIC) |
| 8002 | { |
| 8003 | if (STRCMP(T_CZR, T_ME) == 0) |
| 8004 | do_ME = TRUE; |
| 8005 | else |
| 8006 | out_str(T_CZR); |
| 8007 | } |
| 8008 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 8009 | out_str(T_ME); |
| 8010 | |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8011 | #ifdef FEAT_TERMGUICOLORS |
| 8012 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8013 | { |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 8014 | if (cterm_normal_fg_gui_color != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8015 | term_fg_rgb_color(cterm_normal_fg_gui_color); |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 8016 | if (cterm_normal_bg_gui_color != (long_u)INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8017 | term_bg_rgb_color(cterm_normal_bg_gui_color); |
| 8018 | } |
| 8019 | else |
| 8020 | #endif |
| 8021 | { |
| 8022 | if (t_colors > 1) |
| 8023 | { |
| 8024 | /* set Normal cterm colors */ |
| 8025 | if (cterm_normal_fg_color != 0) |
| 8026 | term_fg_color(cterm_normal_fg_color - 1); |
| 8027 | if (cterm_normal_bg_color != 0) |
| 8028 | term_bg_color(cterm_normal_bg_color - 1); |
| 8029 | if (cterm_normal_fg_bold) |
| 8030 | out_str(T_MD); |
| 8031 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8032 | } |
| 8033 | } |
| 8034 | } |
| 8035 | screen_attr = 0; |
| 8036 | } |
| 8037 | |
| 8038 | /* |
| 8039 | * Reset the colors for a cterm. Used when leaving Vim. |
| 8040 | * The machine specific code may override this again. |
| 8041 | */ |
| 8042 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8043 | reset_cterm_colors(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8044 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8045 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8046 | { |
| 8047 | /* set Normal cterm colors */ |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8048 | #ifdef FEAT_TERMGUICOLORS |
| 8049 | if (p_tgc ? |
Bram Moolenaar | 902647d | 2016-04-22 11:49:06 +0200 | [diff] [blame] | 8050 | (cterm_normal_fg_gui_color != (long_u)INVALCOLOR |
| 8051 | || cterm_normal_bg_gui_color != (long_u)INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8052 | (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)) |
| 8053 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8054 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8055 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8056 | { |
| 8057 | out_str(T_OP); |
| 8058 | screen_attr = -1; |
| 8059 | } |
| 8060 | if (cterm_normal_fg_bold) |
| 8061 | { |
| 8062 | out_str(T_ME); |
| 8063 | screen_attr = -1; |
| 8064 | } |
| 8065 | } |
| 8066 | } |
| 8067 | |
| 8068 | /* |
| 8069 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 8070 | * using the attributes from ScreenAttrs["off"]. |
| 8071 | */ |
| 8072 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8073 | screen_char(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8074 | { |
| 8075 | int attr; |
| 8076 | |
| 8077 | /* Check for illegal values, just in case (could happen just after |
| 8078 | * resizing). */ |
| 8079 | if (row >= screen_Rows || col >= screen_Columns) |
| 8080 | return; |
| 8081 | |
Bram Moolenaar | 494838a | 2015-02-10 19:20:37 +0100 | [diff] [blame] | 8082 | /* Outputting a character in the last cell on the screen may scroll the |
| 8083 | * screen up. Only do it when the "xn" termcap property is set, otherwise |
| 8084 | * mark the character invalid (update it when scrolled up). */ |
| 8085 | if (*T_XN == NUL |
| 8086 | && row == screen_Rows - 1 && col == screen_Columns - 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8087 | #ifdef FEAT_RIGHTLEFT |
| 8088 | /* account for first command-line character in rightleft mode */ |
| 8089 | && !cmdmsg_rl |
| 8090 | #endif |
| 8091 | ) |
| 8092 | { |
| 8093 | ScreenAttrs[off] = (sattr_T)-1; |
| 8094 | return; |
| 8095 | } |
| 8096 | |
| 8097 | /* |
| 8098 | * Stop highlighting first, so it's easier to move the cursor. |
| 8099 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8100 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8101 | if (screen_char_attr != 0) |
| 8102 | attr = screen_char_attr; |
| 8103 | else |
| 8104 | #endif |
| 8105 | attr = ScreenAttrs[off]; |
| 8106 | if (screen_attr != attr) |
| 8107 | screen_stop_highlight(); |
| 8108 | |
| 8109 | windgoto(row, col); |
| 8110 | |
| 8111 | if (screen_attr != attr) |
| 8112 | screen_start_highlight(attr); |
| 8113 | |
| 8114 | #ifdef FEAT_MBYTE |
| 8115 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 8116 | { |
| 8117 | char_u buf[MB_MAXBYTES + 1]; |
| 8118 | |
| 8119 | /* Convert UTF-8 character to bytes and write it. */ |
| 8120 | |
| 8121 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 8122 | |
| 8123 | out_str(buf); |
Bram Moolenaar | cb07008 | 2016-04-02 22:14:51 +0200 | [diff] [blame] | 8124 | if (utf_ambiguous_width(ScreenLinesUC[off])) |
| 8125 | screen_cur_col = 9999; |
| 8126 | else if (utf_char2cells(ScreenLinesUC[off]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8127 | ++screen_cur_col; |
| 8128 | } |
| 8129 | else |
| 8130 | #endif |
| 8131 | { |
| 8132 | #ifdef FEAT_MBYTE |
| 8133 | out_flush_check(); |
| 8134 | #endif |
| 8135 | out_char(ScreenLines[off]); |
| 8136 | #ifdef FEAT_MBYTE |
| 8137 | /* double-byte character in single-width cell */ |
| 8138 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 8139 | out_char(ScreenLines2[off]); |
| 8140 | #endif |
| 8141 | } |
| 8142 | |
| 8143 | screen_cur_col++; |
| 8144 | } |
| 8145 | |
| 8146 | #ifdef FEAT_MBYTE |
| 8147 | |
| 8148 | /* |
| 8149 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 8150 | * on the screen at position 'row' and 'col'. |
| 8151 | * The attributes of the first byte is used for all. This is required to |
| 8152 | * output the two bytes of a double-byte character with nothing in between. |
| 8153 | */ |
| 8154 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8155 | screen_char_2(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8156 | { |
| 8157 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 8158 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 8159 | return; |
| 8160 | |
| 8161 | /* Outputting the last character on the screen may scrollup the screen. |
| 8162 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 8163 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 8164 | { |
| 8165 | ScreenAttrs[off] = (sattr_T)-1; |
| 8166 | return; |
| 8167 | } |
| 8168 | |
| 8169 | /* Output the first byte normally (positions the cursor), then write the |
| 8170 | * second byte directly. */ |
| 8171 | screen_char(off, row, col); |
| 8172 | out_char(ScreenLines[off + 1]); |
| 8173 | ++screen_cur_col; |
| 8174 | } |
| 8175 | #endif |
| 8176 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8177 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8178 | /* |
| 8179 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 8180 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 8181 | */ |
| 8182 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8183 | screen_draw_rectangle( |
| 8184 | int row, |
| 8185 | int col, |
| 8186 | int height, |
| 8187 | int width, |
| 8188 | int invert) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8189 | { |
| 8190 | int r, c; |
| 8191 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8192 | #ifdef FEAT_MBYTE |
| 8193 | int max_off; |
| 8194 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8195 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8196 | /* Can't use ScreenLines unless initialized */ |
| 8197 | if (ScreenLines == NULL) |
| 8198 | return; |
| 8199 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8200 | if (invert) |
| 8201 | screen_char_attr = HL_INVERSE; |
| 8202 | for (r = row; r < row + height; ++r) |
| 8203 | { |
| 8204 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8205 | #ifdef FEAT_MBYTE |
| 8206 | max_off = off + screen_Columns; |
| 8207 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8208 | for (c = col; c < col + width; ++c) |
| 8209 | { |
| 8210 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8211 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8212 | { |
| 8213 | screen_char_2(off + c, r, c); |
| 8214 | ++c; |
| 8215 | } |
| 8216 | else |
| 8217 | #endif |
| 8218 | { |
| 8219 | screen_char(off + c, r, c); |
| 8220 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8221 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8222 | ++c; |
| 8223 | #endif |
| 8224 | } |
| 8225 | } |
| 8226 | } |
| 8227 | screen_char_attr = 0; |
| 8228 | } |
| 8229 | #endif |
| 8230 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8231 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8232 | /* |
| 8233 | * Redraw the characters for a vertically split window. |
| 8234 | */ |
| 8235 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8236 | redraw_block(int row, int end, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8237 | { |
| 8238 | int col; |
| 8239 | int width; |
| 8240 | |
| 8241 | # ifdef FEAT_CLIPBOARD |
| 8242 | clip_may_clear_selection(row, end - 1); |
| 8243 | # endif |
| 8244 | |
| 8245 | if (wp == NULL) |
| 8246 | { |
| 8247 | col = 0; |
| 8248 | width = Columns; |
| 8249 | } |
| 8250 | else |
| 8251 | { |
| 8252 | col = wp->w_wincol; |
| 8253 | width = wp->w_width; |
| 8254 | } |
| 8255 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 8256 | } |
| 8257 | #endif |
| 8258 | |
| 8259 | /* |
| 8260 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 8261 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 8262 | * Use attributes 'attr'. |
| 8263 | */ |
| 8264 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8265 | screen_fill( |
| 8266 | int start_row, |
| 8267 | int end_row, |
| 8268 | int start_col, |
| 8269 | int end_col, |
| 8270 | int c1, |
| 8271 | int c2, |
| 8272 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8273 | { |
| 8274 | int row; |
| 8275 | int col; |
| 8276 | int off; |
| 8277 | int end_off; |
| 8278 | int did_delete; |
| 8279 | int c; |
| 8280 | int norm_term; |
| 8281 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8282 | int force_next = FALSE; |
| 8283 | #endif |
| 8284 | |
| 8285 | if (end_row > screen_Rows) /* safety check */ |
| 8286 | end_row = screen_Rows; |
| 8287 | if (end_col > screen_Columns) /* safety check */ |
| 8288 | end_col = screen_Columns; |
| 8289 | if (ScreenLines == NULL |
| 8290 | || start_row >= end_row |
| 8291 | || start_col >= end_col) /* nothing to do */ |
| 8292 | return; |
| 8293 | |
| 8294 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 8295 | norm_term = ( |
| 8296 | #ifdef FEAT_GUI |
| 8297 | !gui.in_use && |
| 8298 | #endif |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8299 | !IS_CTERM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8300 | for (row = start_row; row < end_row; ++row) |
| 8301 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8302 | #ifdef FEAT_MBYTE |
| 8303 | if (has_mbyte |
| 8304 | # ifdef FEAT_GUI |
| 8305 | && !gui.in_use |
| 8306 | # endif |
| 8307 | ) |
| 8308 | { |
| 8309 | /* When drawing over the right halve of a double-wide char clear |
| 8310 | * out the left halve. When drawing over the left halve of a |
| 8311 | * double wide-char clear out the right halve. Only needed in a |
| 8312 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 8313 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8314 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 8315 | 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] | 8316 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8317 | } |
| 8318 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8319 | /* |
| 8320 | * Try to use delete-line termcap code, when no attributes or in a |
| 8321 | * "normal" terminal, where a bold/italic space is just a |
| 8322 | * space. |
| 8323 | */ |
| 8324 | did_delete = FALSE; |
| 8325 | if (c2 == ' ' |
| 8326 | && end_col == Columns |
| 8327 | && can_clear(T_CE) |
| 8328 | && (attr == 0 |
| 8329 | || (norm_term |
| 8330 | && attr <= HL_ALL |
| 8331 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 8332 | { |
| 8333 | /* |
| 8334 | * check if we really need to clear something |
| 8335 | */ |
| 8336 | col = start_col; |
| 8337 | if (c1 != ' ') /* don't clear first char */ |
| 8338 | ++col; |
| 8339 | |
| 8340 | off = LineOffset[row] + col; |
| 8341 | end_off = LineOffset[row] + end_col; |
| 8342 | |
| 8343 | /* skip blanks (used often, keep it fast!) */ |
| 8344 | #ifdef FEAT_MBYTE |
| 8345 | if (enc_utf8) |
| 8346 | while (off < end_off && ScreenLines[off] == ' ' |
| 8347 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 8348 | ++off; |
| 8349 | else |
| 8350 | #endif |
| 8351 | while (off < end_off && ScreenLines[off] == ' ' |
| 8352 | && ScreenAttrs[off] == 0) |
| 8353 | ++off; |
| 8354 | if (off < end_off) /* something to be cleared */ |
| 8355 | { |
| 8356 | col = off - LineOffset[row]; |
| 8357 | screen_stop_highlight(); |
| 8358 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 8359 | out_str(T_CE); |
| 8360 | screen_start(); /* don't know where cursor is now */ |
| 8361 | col = end_col - col; |
| 8362 | while (col--) /* clear chars in ScreenLines */ |
| 8363 | { |
| 8364 | ScreenLines[off] = ' '; |
| 8365 | #ifdef FEAT_MBYTE |
| 8366 | if (enc_utf8) |
| 8367 | ScreenLinesUC[off] = 0; |
| 8368 | #endif |
| 8369 | ScreenAttrs[off] = 0; |
| 8370 | ++off; |
| 8371 | } |
| 8372 | } |
| 8373 | did_delete = TRUE; /* the chars are cleared now */ |
| 8374 | } |
| 8375 | |
| 8376 | off = LineOffset[row] + start_col; |
| 8377 | c = c1; |
| 8378 | for (col = start_col; col < end_col; ++col) |
| 8379 | { |
| 8380 | if (ScreenLines[off] != c |
| 8381 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8382 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 8383 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8384 | #endif |
| 8385 | || ScreenAttrs[off] != attr |
| 8386 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8387 | || force_next |
| 8388 | #endif |
| 8389 | ) |
| 8390 | { |
| 8391 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8392 | /* The bold trick may make a single row of pixels appear in |
| 8393 | * the next character. When a bold character is removed, the |
| 8394 | * next character should be redrawn too. This happens for our |
| 8395 | * own GUI and for some xterms. */ |
| 8396 | if ( |
| 8397 | # ifdef FEAT_GUI |
| 8398 | gui.in_use |
| 8399 | # endif |
| 8400 | # if defined(FEAT_GUI) && defined(UNIX) |
| 8401 | || |
| 8402 | # endif |
| 8403 | # ifdef UNIX |
| 8404 | term_is_xterm |
| 8405 | # endif |
| 8406 | ) |
| 8407 | { |
| 8408 | if (ScreenLines[off] != ' ' |
| 8409 | && (ScreenAttrs[off] > HL_ALL |
| 8410 | || ScreenAttrs[off] & HL_BOLD)) |
| 8411 | force_next = TRUE; |
| 8412 | else |
| 8413 | force_next = FALSE; |
| 8414 | } |
| 8415 | #endif |
| 8416 | ScreenLines[off] = c; |
| 8417 | #ifdef FEAT_MBYTE |
| 8418 | if (enc_utf8) |
| 8419 | { |
| 8420 | if (c >= 0x80) |
| 8421 | { |
| 8422 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8423 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8424 | } |
| 8425 | else |
| 8426 | ScreenLinesUC[off] = 0; |
| 8427 | } |
| 8428 | #endif |
| 8429 | ScreenAttrs[off] = attr; |
| 8430 | if (!did_delete || c != ' ') |
| 8431 | screen_char(off, row, col); |
| 8432 | } |
| 8433 | ++off; |
| 8434 | if (col == start_col) |
| 8435 | { |
| 8436 | if (did_delete) |
| 8437 | break; |
| 8438 | c = c2; |
| 8439 | } |
| 8440 | } |
| 8441 | if (end_col == Columns) |
| 8442 | LineWraps[row] = FALSE; |
| 8443 | if (row == Rows - 1) /* overwritten the command line */ |
| 8444 | { |
| 8445 | redraw_cmdline = TRUE; |
| 8446 | if (c1 == ' ' && c2 == ' ') |
| 8447 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8448 | if (start_col == 0) |
| 8449 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8450 | } |
| 8451 | } |
| 8452 | } |
| 8453 | |
| 8454 | /* |
| 8455 | * Check if there should be a delay. Used before clearing or redrawing the |
| 8456 | * screen or the command line. |
| 8457 | */ |
| 8458 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8459 | check_for_delay(int check_msg_scroll) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8460 | { |
| 8461 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 8462 | && !did_wait_return |
| 8463 | && emsg_silent == 0) |
| 8464 | { |
| 8465 | out_flush(); |
| 8466 | ui_delay(1000L, TRUE); |
| 8467 | emsg_on_display = FALSE; |
| 8468 | if (check_msg_scroll) |
| 8469 | msg_scroll = FALSE; |
| 8470 | } |
| 8471 | } |
| 8472 | |
| 8473 | /* |
| 8474 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8475 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8476 | * Returns TRUE if there is a valid screen to write to. |
| 8477 | * Returns FALSE when starting up and screen not initialized yet. |
| 8478 | */ |
| 8479 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8480 | screen_valid(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8481 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8482 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8483 | return (ScreenLines != NULL); |
| 8484 | } |
| 8485 | |
| 8486 | /* |
| 8487 | * Resize the shell to Rows and Columns. |
| 8488 | * Allocate ScreenLines[] and associated items. |
| 8489 | * |
| 8490 | * There may be some time between setting Rows and Columns and (re)allocating |
| 8491 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 8492 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 8493 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 8494 | * final size of the shell is needed. |
| 8495 | */ |
| 8496 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8497 | screenalloc(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8498 | { |
| 8499 | int new_row, old_row; |
| 8500 | #ifdef FEAT_GUI |
| 8501 | int old_Rows; |
| 8502 | #endif |
| 8503 | win_T *wp; |
| 8504 | int outofmem = FALSE; |
| 8505 | int len; |
| 8506 | schar_T *new_ScreenLines; |
| 8507 | #ifdef FEAT_MBYTE |
| 8508 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8509 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8510 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8511 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8512 | #endif |
| 8513 | sattr_T *new_ScreenAttrs; |
| 8514 | unsigned *new_LineOffset; |
| 8515 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8516 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8517 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8518 | tabpage_T *tp; |
| 8519 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8520 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8521 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8522 | #ifdef FEAT_AUTOCMD |
| 8523 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8524 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8525 | retry: |
| 8526 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8527 | /* |
| 8528 | * Allocation of the screen buffers is done only when the size changes and |
| 8529 | * when Rows and Columns have been set and we have started doing full |
| 8530 | * screen stuff. |
| 8531 | */ |
| 8532 | if ((ScreenLines != NULL |
| 8533 | && Rows == screen_Rows |
| 8534 | && Columns == screen_Columns |
| 8535 | #ifdef FEAT_MBYTE |
| 8536 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 8537 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8538 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8539 | #endif |
| 8540 | ) |
| 8541 | || Rows == 0 |
| 8542 | || Columns == 0 |
| 8543 | || (!full_screen && ScreenLines == NULL)) |
| 8544 | return; |
| 8545 | |
| 8546 | /* |
| 8547 | * It's possible that we produce an out-of-memory message below, which |
| 8548 | * will cause this function to be called again. To break the loop, just |
| 8549 | * return here. |
| 8550 | */ |
| 8551 | if (entered) |
| 8552 | return; |
| 8553 | entered = TRUE; |
| 8554 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8555 | /* |
| 8556 | * Note that the window sizes are updated before reallocating the arrays, |
| 8557 | * thus we must not redraw here! |
| 8558 | */ |
| 8559 | ++RedrawingDisabled; |
| 8560 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8561 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8562 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8563 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8564 | |
| 8565 | /* |
| 8566 | * We're changing the size of the screen. |
| 8567 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8568 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8569 | * lines (unless the screen is going to be cleared). |
| 8570 | * - Free the old arrays. |
| 8571 | * |
| 8572 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8573 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8574 | * size is wrong. |
| 8575 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8576 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8577 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8578 | #ifdef FEAT_AUTOCMD |
| 8579 | if (aucmd_win != NULL) |
| 8580 | win_free_lsize(aucmd_win); |
| 8581 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8582 | |
| 8583 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8584 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8585 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8586 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8587 | if (enc_utf8) |
| 8588 | { |
| 8589 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8590 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8591 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8592 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8593 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8594 | } |
| 8595 | if (enc_dbcs == DBCS_JPNU) |
| 8596 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8597 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8598 | #endif |
| 8599 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8600 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8601 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8602 | Rows * sizeof(unsigned)), FALSE); |
| 8603 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8604 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8605 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8606 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8607 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8608 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8609 | { |
| 8610 | if (win_alloc_lines(wp) == FAIL) |
| 8611 | { |
| 8612 | outofmem = TRUE; |
| 8613 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8614 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8615 | #endif |
| 8616 | } |
| 8617 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8618 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8619 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8620 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8621 | outofmem = TRUE; |
| 8622 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8623 | #ifdef FEAT_WINDOWS |
| 8624 | give_up: |
| 8625 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8626 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8627 | #ifdef FEAT_MBYTE |
| 8628 | for (i = 0; i < p_mco; ++i) |
| 8629 | if (new_ScreenLinesC[i] == NULL) |
| 8630 | break; |
| 8631 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8632 | if (new_ScreenLines == NULL |
| 8633 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8634 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8635 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8636 | #endif |
| 8637 | || new_ScreenAttrs == NULL |
| 8638 | || new_LineOffset == NULL |
| 8639 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8640 | #ifdef FEAT_WINDOWS |
| 8641 | || new_TabPageIdxs == NULL |
| 8642 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8643 | || outofmem) |
| 8644 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8645 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8646 | { |
| 8647 | /* guess the size */ |
| 8648 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8649 | |
| 8650 | /* Remember we did this to avoid getting outofmem messages over |
| 8651 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8652 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8653 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8654 | vim_free(new_ScreenLines); |
| 8655 | new_ScreenLines = NULL; |
| 8656 | #ifdef FEAT_MBYTE |
| 8657 | vim_free(new_ScreenLinesUC); |
| 8658 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8659 | for (i = 0; i < p_mco; ++i) |
| 8660 | { |
| 8661 | vim_free(new_ScreenLinesC[i]); |
| 8662 | new_ScreenLinesC[i] = NULL; |
| 8663 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8664 | vim_free(new_ScreenLines2); |
| 8665 | new_ScreenLines2 = NULL; |
| 8666 | #endif |
| 8667 | vim_free(new_ScreenAttrs); |
| 8668 | new_ScreenAttrs = NULL; |
| 8669 | vim_free(new_LineOffset); |
| 8670 | new_LineOffset = NULL; |
| 8671 | vim_free(new_LineWraps); |
| 8672 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8673 | #ifdef FEAT_WINDOWS |
| 8674 | vim_free(new_TabPageIdxs); |
| 8675 | new_TabPageIdxs = NULL; |
| 8676 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8677 | } |
| 8678 | else |
| 8679 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8680 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8681 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8682 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8683 | { |
| 8684 | new_LineOffset[new_row] = new_row * Columns; |
| 8685 | new_LineWraps[new_row] = FALSE; |
| 8686 | |
| 8687 | /* |
| 8688 | * If the screen is not going to be cleared, copy as much as |
| 8689 | * possible from the old screen to the new one and clear the rest |
| 8690 | * (used when resizing the window at the "--more--" prompt or when |
| 8691 | * executing an external command, for the GUI). |
| 8692 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8693 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8694 | { |
| 8695 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8696 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8697 | #ifdef FEAT_MBYTE |
| 8698 | if (enc_utf8) |
| 8699 | { |
| 8700 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8701 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8702 | for (i = 0; i < p_mco; ++i) |
| 8703 | (void)vim_memset(new_ScreenLinesC[i] |
| 8704 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8705 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8706 | } |
| 8707 | if (enc_dbcs == DBCS_JPNU) |
| 8708 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8709 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8710 | #endif |
| 8711 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8712 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8713 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8714 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8715 | { |
| 8716 | if (screen_Columns < Columns) |
| 8717 | len = screen_Columns; |
| 8718 | else |
| 8719 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8720 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8721 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8722 | * may be invalid now. Also when p_mco changes. */ |
| 8723 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8724 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8725 | #endif |
| 8726 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8727 | ScreenLines + LineOffset[old_row], |
| 8728 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8729 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8730 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8731 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8732 | { |
| 8733 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8734 | ScreenLinesUC + LineOffset[old_row], |
| 8735 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8736 | for (i = 0; i < p_mco; ++i) |
| 8737 | mch_memmove(new_ScreenLinesC[i] |
| 8738 | + new_LineOffset[new_row], |
| 8739 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8740 | (size_t)len * sizeof(u8char_T)); |
| 8741 | } |
| 8742 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8743 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8744 | ScreenLines2 + LineOffset[old_row], |
| 8745 | (size_t)len * sizeof(schar_T)); |
| 8746 | #endif |
| 8747 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8748 | ScreenAttrs + LineOffset[old_row], |
| 8749 | (size_t)len * sizeof(sattr_T)); |
| 8750 | } |
| 8751 | } |
| 8752 | } |
| 8753 | /* Use the last line of the screen for the current line. */ |
| 8754 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8755 | } |
| 8756 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8757 | free_screenlines(); |
| 8758 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8759 | ScreenLines = new_ScreenLines; |
| 8760 | #ifdef FEAT_MBYTE |
| 8761 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8762 | for (i = 0; i < p_mco; ++i) |
| 8763 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8764 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8765 | ScreenLines2 = new_ScreenLines2; |
| 8766 | #endif |
| 8767 | ScreenAttrs = new_ScreenAttrs; |
| 8768 | LineOffset = new_LineOffset; |
| 8769 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8770 | #ifdef FEAT_WINDOWS |
| 8771 | TabPageIdxs = new_TabPageIdxs; |
| 8772 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8773 | |
| 8774 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8775 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8776 | #ifdef FEAT_GUI |
| 8777 | old_Rows = screen_Rows; |
| 8778 | #endif |
| 8779 | screen_Rows = Rows; |
| 8780 | screen_Columns = Columns; |
| 8781 | |
| 8782 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8783 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8784 | screenclear2(); |
| 8785 | |
| 8786 | #ifdef FEAT_GUI |
| 8787 | else if (gui.in_use |
| 8788 | && !gui.starting |
| 8789 | && ScreenLines != NULL |
| 8790 | && old_Rows != Rows) |
| 8791 | { |
| 8792 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8793 | /* |
| 8794 | * Adjust the position of the cursor, for when executing an external |
| 8795 | * command. |
| 8796 | */ |
| 8797 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8798 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8799 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8800 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8801 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8802 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8803 | } |
| 8804 | #endif |
| 8805 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8806 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8807 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8808 | |
| 8809 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8810 | /* |
| 8811 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8812 | * in case applying autocommands always changes Rows or Columns. |
| 8813 | */ |
| 8814 | if (starting == 0 && ++retry_count <= 3) |
| 8815 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8816 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8817 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8818 | * jump back to check if we need to allocate the screen again. */ |
| 8819 | goto retry; |
| 8820 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8821 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8822 | } |
| 8823 | |
| 8824 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8825 | free_screenlines(void) |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8826 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8827 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8828 | int i; |
| 8829 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8830 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8831 | for (i = 0; i < Screen_mco; ++i) |
| 8832 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8833 | vim_free(ScreenLines2); |
| 8834 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8835 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8836 | vim_free(ScreenAttrs); |
| 8837 | vim_free(LineOffset); |
| 8838 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8839 | #ifdef FEAT_WINDOWS |
| 8840 | vim_free(TabPageIdxs); |
| 8841 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8842 | } |
| 8843 | |
| 8844 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8845 | screenclear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8846 | { |
| 8847 | check_for_delay(FALSE); |
| 8848 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8849 | screenclear2(); /* clear the screen */ |
| 8850 | } |
| 8851 | |
| 8852 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8853 | screenclear2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8854 | { |
| 8855 | int i; |
| 8856 | |
| 8857 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8858 | #ifdef FEAT_GUI |
| 8859 | || (gui.in_use && gui.starting) |
| 8860 | #endif |
| 8861 | ) |
| 8862 | return; |
| 8863 | |
| 8864 | #ifdef FEAT_GUI |
| 8865 | if (!gui.in_use) |
| 8866 | #endif |
| 8867 | screen_attr = -1; /* force setting the Normal colors */ |
| 8868 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8869 | |
| 8870 | #ifdef FEAT_CLIPBOARD |
| 8871 | /* disable selection without redrawing it */ |
| 8872 | clip_scroll_selection(9999); |
| 8873 | #endif |
| 8874 | |
| 8875 | /* blank out ScreenLines */ |
| 8876 | for (i = 0; i < Rows; ++i) |
| 8877 | { |
| 8878 | lineclear(LineOffset[i], (int)Columns); |
| 8879 | LineWraps[i] = FALSE; |
| 8880 | } |
| 8881 | |
| 8882 | if (can_clear(T_CL)) |
| 8883 | { |
| 8884 | out_str(T_CL); /* clear the display */ |
| 8885 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8886 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8887 | } |
| 8888 | else |
| 8889 | { |
| 8890 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8891 | for (i = 0; i < Rows; ++i) |
| 8892 | lineinvalid(LineOffset[i], (int)Columns); |
| 8893 | clear_cmdline = TRUE; |
| 8894 | } |
| 8895 | |
| 8896 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8897 | |
| 8898 | win_rest_invalid(firstwin); |
| 8899 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8900 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8901 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8902 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8903 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8904 | must_redraw = NOT_VALID; |
| 8905 | compute_cmdrow(); |
| 8906 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8907 | msg_col = 0; |
| 8908 | screen_start(); /* don't know where cursor is now */ |
| 8909 | msg_scrolled = 0; /* can't scroll back */ |
| 8910 | msg_didany = FALSE; |
| 8911 | msg_didout = FALSE; |
| 8912 | } |
| 8913 | |
| 8914 | /* |
| 8915 | * Clear one line in ScreenLines. |
| 8916 | */ |
| 8917 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8918 | lineclear(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8919 | { |
| 8920 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8921 | #ifdef FEAT_MBYTE |
| 8922 | if (enc_utf8) |
| 8923 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8924 | (size_t)width * sizeof(u8char_T)); |
| 8925 | #endif |
| 8926 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8927 | } |
| 8928 | |
| 8929 | /* |
| 8930 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8931 | * invalid value. |
| 8932 | */ |
| 8933 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8934 | lineinvalid(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8935 | { |
| 8936 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8937 | } |
| 8938 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8939 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8940 | /* |
| 8941 | * Copy part of a Screenline for vertically split window "wp". |
| 8942 | */ |
| 8943 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8944 | linecopy(int to, int from, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8945 | { |
| 8946 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8947 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8948 | |
| 8949 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8950 | wp->w_width * sizeof(schar_T)); |
| 8951 | # ifdef FEAT_MBYTE |
| 8952 | if (enc_utf8) |
| 8953 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8954 | int i; |
| 8955 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8956 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8957 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8958 | for (i = 0; i < p_mco; ++i) |
| 8959 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8960 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8961 | } |
| 8962 | if (enc_dbcs == DBCS_JPNU) |
| 8963 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8964 | wp->w_width * sizeof(schar_T)); |
| 8965 | # endif |
| 8966 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8967 | wp->w_width * sizeof(sattr_T)); |
| 8968 | } |
| 8969 | #endif |
| 8970 | |
| 8971 | /* |
| 8972 | * Return TRUE if clearing with term string "p" would work. |
| 8973 | * It can't work when the string is empty or it won't set the right background. |
| 8974 | */ |
| 8975 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8976 | can_clear(char_u *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8977 | { |
| 8978 | return (*p != NUL && (t_colors <= 1 |
| 8979 | #ifdef FEAT_GUI |
| 8980 | || gui.in_use |
| 8981 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8982 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | d18f672 | 2016-06-17 13:18:49 +0200 | [diff] [blame] | 8983 | || (p_tgc && cterm_normal_bg_gui_color == (long_u)INVALCOLOR) |
| 8984 | || (!p_tgc && cterm_normal_bg_color == 0) |
| 8985 | #else |
| 8986 | || cterm_normal_bg_color == 0 |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8987 | #endif |
Bram Moolenaar | d18f672 | 2016-06-17 13:18:49 +0200 | [diff] [blame] | 8988 | || *T_UT != NUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8989 | } |
| 8990 | |
| 8991 | /* |
| 8992 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8993 | * something directly to the screen (shell commands) or a terminal control |
| 8994 | * code. |
| 8995 | */ |
| 8996 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8997 | screen_start(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8998 | { |
| 8999 | screen_cur_row = screen_cur_col = 9999; |
| 9000 | } |
| 9001 | |
| 9002 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9003 | * Move the cursor to position "row","col" in the screen. |
| 9004 | * This tries to find the most efficient way to move, minimizing the number of |
| 9005 | * characters sent to the terminal. |
| 9006 | */ |
| 9007 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9008 | windgoto(int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9009 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9010 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9011 | int i; |
| 9012 | int plan; |
| 9013 | int cost; |
| 9014 | int wouldbe_col; |
| 9015 | int noinvcurs; |
| 9016 | char_u *bs; |
| 9017 | int goto_cost; |
| 9018 | int attr; |
| 9019 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9020 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9021 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 9022 | |
| 9023 | #define PLAN_LE 1 |
| 9024 | #define PLAN_CR 2 |
| 9025 | #define PLAN_NL 3 |
| 9026 | #define PLAN_WRITE 4 |
| 9027 | /* Can't use ScreenLines unless initialized */ |
| 9028 | if (ScreenLines == NULL) |
| 9029 | return; |
| 9030 | |
| 9031 | if (col != screen_cur_col || row != screen_cur_row) |
| 9032 | { |
| 9033 | /* Check for valid position. */ |
| 9034 | if (row < 0) /* window without text lines? */ |
| 9035 | row = 0; |
| 9036 | if (row >= screen_Rows) |
| 9037 | row = screen_Rows - 1; |
| 9038 | if (col >= screen_Columns) |
| 9039 | col = screen_Columns - 1; |
| 9040 | |
| 9041 | /* check if no cursor movement is allowed in highlight mode */ |
| 9042 | if (screen_attr && *T_MS == NUL) |
| 9043 | noinvcurs = HIGHL_COST; |
| 9044 | else |
| 9045 | noinvcurs = 0; |
| 9046 | goto_cost = GOTO_COST + noinvcurs; |
| 9047 | |
| 9048 | /* |
| 9049 | * Plan how to do the positioning: |
| 9050 | * 1. Use CR to move it to column 0, same row. |
| 9051 | * 2. Use T_LE to move it a few columns to the left. |
| 9052 | * 3. Use NL to move a few lines down, column 0. |
| 9053 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 9054 | * |
| 9055 | * Don't do this if the cursor went beyond the last column, the cursor |
| 9056 | * position is unknown then (some terminals wrap, some don't ) |
| 9057 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9058 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9059 | * characters to move the cursor to the right. |
| 9060 | */ |
| 9061 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 9062 | { |
| 9063 | /* |
| 9064 | * If the cursor is in the same row, bigger col, we can use CR |
| 9065 | * or T_LE. |
| 9066 | */ |
| 9067 | bs = NULL; /* init for GCC */ |
| 9068 | attr = screen_attr; |
| 9069 | if (row == screen_cur_row && col < screen_cur_col) |
| 9070 | { |
| 9071 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 9072 | if (*T_LE) |
| 9073 | bs = T_LE; /* "cursor left" */ |
| 9074 | else |
| 9075 | bs = T_BC; /* "backspace character (old) */ |
| 9076 | if (*bs) |
| 9077 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 9078 | else |
| 9079 | cost = 999; |
| 9080 | if (col + 1 < cost) /* using CR is less characters */ |
| 9081 | { |
| 9082 | plan = PLAN_CR; |
| 9083 | wouldbe_col = 0; |
| 9084 | cost = 1; /* CR is just one character */ |
| 9085 | } |
| 9086 | else |
| 9087 | { |
| 9088 | plan = PLAN_LE; |
| 9089 | wouldbe_col = col; |
| 9090 | } |
| 9091 | if (noinvcurs) /* will stop highlighting */ |
| 9092 | { |
| 9093 | cost += noinvcurs; |
| 9094 | attr = 0; |
| 9095 | } |
| 9096 | } |
| 9097 | |
| 9098 | /* |
| 9099 | * If the cursor is above where we want to be, we can use CR LF. |
| 9100 | */ |
| 9101 | else if (row > screen_cur_row) |
| 9102 | { |
| 9103 | plan = PLAN_NL; |
| 9104 | wouldbe_col = 0; |
| 9105 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 9106 | if (noinvcurs) /* will stop highlighting */ |
| 9107 | { |
| 9108 | cost += noinvcurs; |
| 9109 | attr = 0; |
| 9110 | } |
| 9111 | } |
| 9112 | |
| 9113 | /* |
| 9114 | * If the cursor is in the same row, smaller col, just use write. |
| 9115 | */ |
| 9116 | else |
| 9117 | { |
| 9118 | plan = PLAN_WRITE; |
| 9119 | wouldbe_col = screen_cur_col; |
| 9120 | cost = 0; |
| 9121 | } |
| 9122 | |
| 9123 | /* |
| 9124 | * Check if any characters that need to be written have the |
| 9125 | * correct attributes. Also avoid UTF-8 characters. |
| 9126 | */ |
| 9127 | i = col - wouldbe_col; |
| 9128 | if (i > 0) |
| 9129 | cost += i; |
| 9130 | if (cost < goto_cost && i > 0) |
| 9131 | { |
| 9132 | /* |
| 9133 | * Check if the attributes are correct without additionally |
| 9134 | * stopping highlighting. |
| 9135 | */ |
| 9136 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 9137 | while (i && *p++ == attr) |
| 9138 | --i; |
| 9139 | if (i != 0) |
| 9140 | { |
| 9141 | /* |
| 9142 | * Try if it works when highlighting is stopped here. |
| 9143 | */ |
| 9144 | if (*--p == 0) |
| 9145 | { |
| 9146 | cost += noinvcurs; |
| 9147 | while (i && *p++ == 0) |
| 9148 | --i; |
| 9149 | } |
| 9150 | if (i != 0) |
| 9151 | cost = 999; /* different attributes, don't do it */ |
| 9152 | } |
| 9153 | #ifdef FEAT_MBYTE |
| 9154 | if (enc_utf8) |
| 9155 | { |
| 9156 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 9157 | for (i = wouldbe_col; i < col; ++i) |
| 9158 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 9159 | { |
| 9160 | cost = 999; |
| 9161 | break; |
| 9162 | } |
| 9163 | } |
| 9164 | #endif |
| 9165 | } |
| 9166 | |
| 9167 | /* |
| 9168 | * We can do it without term_windgoto()! |
| 9169 | */ |
| 9170 | if (cost < goto_cost) |
| 9171 | { |
| 9172 | if (plan == PLAN_LE) |
| 9173 | { |
| 9174 | if (noinvcurs) |
| 9175 | screen_stop_highlight(); |
| 9176 | while (screen_cur_col > col) |
| 9177 | { |
| 9178 | out_str(bs); |
| 9179 | --screen_cur_col; |
| 9180 | } |
| 9181 | } |
| 9182 | else if (plan == PLAN_CR) |
| 9183 | { |
| 9184 | if (noinvcurs) |
| 9185 | screen_stop_highlight(); |
| 9186 | out_char('\r'); |
| 9187 | screen_cur_col = 0; |
| 9188 | } |
| 9189 | else if (plan == PLAN_NL) |
| 9190 | { |
| 9191 | if (noinvcurs) |
| 9192 | screen_stop_highlight(); |
| 9193 | while (screen_cur_row < row) |
| 9194 | { |
| 9195 | out_char('\n'); |
| 9196 | ++screen_cur_row; |
| 9197 | } |
| 9198 | screen_cur_col = 0; |
| 9199 | } |
| 9200 | |
| 9201 | i = col - screen_cur_col; |
| 9202 | if (i > 0) |
| 9203 | { |
| 9204 | /* |
| 9205 | * Use cursor-right if it's one character only. Avoids |
| 9206 | * removing a line of pixels from the last bold char, when |
| 9207 | * using the bold trick in the GUI. |
| 9208 | */ |
| 9209 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 9210 | { |
| 9211 | while (i-- > 0) |
| 9212 | out_char(*T_ND); |
| 9213 | } |
| 9214 | else |
| 9215 | { |
| 9216 | int off; |
| 9217 | |
| 9218 | off = LineOffset[row] + screen_cur_col; |
| 9219 | while (i-- > 0) |
| 9220 | { |
| 9221 | if (ScreenAttrs[off] != screen_attr) |
| 9222 | screen_stop_highlight(); |
| 9223 | #ifdef FEAT_MBYTE |
| 9224 | out_flush_check(); |
| 9225 | #endif |
| 9226 | out_char(ScreenLines[off]); |
| 9227 | #ifdef FEAT_MBYTE |
| 9228 | if (enc_dbcs == DBCS_JPNU |
| 9229 | && ScreenLines[off] == 0x8e) |
| 9230 | out_char(ScreenLines2[off]); |
| 9231 | #endif |
| 9232 | ++off; |
| 9233 | } |
| 9234 | } |
| 9235 | } |
| 9236 | } |
| 9237 | } |
| 9238 | else |
| 9239 | cost = 999; |
| 9240 | |
| 9241 | if (cost >= goto_cost) |
| 9242 | { |
| 9243 | if (noinvcurs) |
| 9244 | screen_stop_highlight(); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 9245 | if (row == screen_cur_row && (col > screen_cur_col) |
| 9246 | && *T_CRI != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9247 | term_cursor_right(col - screen_cur_col); |
| 9248 | else |
| 9249 | term_windgoto(row, col); |
| 9250 | } |
| 9251 | screen_cur_row = row; |
| 9252 | screen_cur_col = col; |
| 9253 | } |
| 9254 | } |
| 9255 | |
| 9256 | /* |
| 9257 | * Set cursor to its position in the current window. |
| 9258 | */ |
| 9259 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9260 | setcursor(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9261 | { |
| 9262 | if (redrawing()) |
| 9263 | { |
| 9264 | validate_cursor(); |
| 9265 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 9266 | W_WINCOL(curwin) + ( |
| 9267 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9268 | /* With 'rightleft' set and the cursor on a double-wide |
| 9269 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9270 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 9271 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9272 | (has_mbyte |
| 9273 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 9274 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9275 | # endif |
| 9276 | 1)) : |
| 9277 | #endif |
| 9278 | curwin->w_wcol)); |
| 9279 | } |
| 9280 | } |
| 9281 | |
| 9282 | |
| 9283 | /* |
| 9284 | * insert 'line_count' lines at 'row' in window 'wp' |
| 9285 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 9286 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 9287 | * scrolling. |
| 9288 | * Returns FAIL if the lines are not inserted, OK for success. |
| 9289 | */ |
| 9290 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9291 | win_ins_lines( |
| 9292 | win_T *wp, |
| 9293 | int row, |
| 9294 | int line_count, |
| 9295 | int invalid, |
| 9296 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9297 | { |
| 9298 | int did_delete; |
| 9299 | int nextrow; |
| 9300 | int lastrow; |
| 9301 | int retval; |
| 9302 | |
| 9303 | if (invalid) |
| 9304 | wp->w_lines_valid = 0; |
| 9305 | |
| 9306 | if (wp->w_height < 5) |
| 9307 | return FAIL; |
| 9308 | |
| 9309 | if (line_count > wp->w_height - row) |
| 9310 | line_count = wp->w_height - row; |
| 9311 | |
| 9312 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 9313 | if (retval != MAYBE) |
| 9314 | return retval; |
| 9315 | |
| 9316 | /* |
| 9317 | * If there is a next window or a status line, we first try to delete the |
| 9318 | * lines at the bottom to avoid messing what is after the window. |
| 9319 | * If this fails and there are following windows, don't do anything to avoid |
| 9320 | * messing up those windows, better just redraw. |
| 9321 | */ |
| 9322 | did_delete = FALSE; |
| 9323 | #ifdef FEAT_WINDOWS |
| 9324 | if (wp->w_next != NULL || wp->w_status_height) |
| 9325 | { |
| 9326 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9327 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 9328 | did_delete = TRUE; |
| 9329 | else if (wp->w_next) |
| 9330 | return FAIL; |
| 9331 | } |
| 9332 | #endif |
| 9333 | /* |
| 9334 | * if no lines deleted, blank the lines that will end up below the window |
| 9335 | */ |
| 9336 | if (!did_delete) |
| 9337 | { |
| 9338 | #ifdef FEAT_WINDOWS |
| 9339 | wp->w_redr_status = TRUE; |
| 9340 | #endif |
| 9341 | redraw_cmdline = TRUE; |
| 9342 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 9343 | lastrow = nextrow + line_count; |
| 9344 | if (lastrow > Rows) |
| 9345 | lastrow = Rows; |
| 9346 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 9347 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9348 | ' ', ' ', 0); |
| 9349 | } |
| 9350 | |
| 9351 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 9352 | == FAIL) |
| 9353 | { |
| 9354 | /* deletion will have messed up other windows */ |
| 9355 | if (did_delete) |
| 9356 | { |
| 9357 | #ifdef FEAT_WINDOWS |
| 9358 | wp->w_redr_status = TRUE; |
| 9359 | #endif |
| 9360 | win_rest_invalid(W_NEXT(wp)); |
| 9361 | } |
| 9362 | return FAIL; |
| 9363 | } |
| 9364 | |
| 9365 | return OK; |
| 9366 | } |
| 9367 | |
| 9368 | /* |
| 9369 | * delete "line_count" window lines at "row" in window "wp" |
| 9370 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 9371 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 9372 | * scrolling |
| 9373 | * Return OK for success, FAIL if the lines are not deleted. |
| 9374 | */ |
| 9375 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9376 | win_del_lines( |
| 9377 | win_T *wp, |
| 9378 | int row, |
| 9379 | int line_count, |
| 9380 | int invalid, |
| 9381 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9382 | { |
| 9383 | int retval; |
| 9384 | |
| 9385 | if (invalid) |
| 9386 | wp->w_lines_valid = 0; |
| 9387 | |
| 9388 | if (line_count > wp->w_height - row) |
| 9389 | line_count = wp->w_height - row; |
| 9390 | |
| 9391 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 9392 | if (retval != MAYBE) |
| 9393 | return retval; |
| 9394 | |
| 9395 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 9396 | (int)Rows, FALSE, NULL) == FAIL) |
| 9397 | return FAIL; |
| 9398 | |
| 9399 | #ifdef FEAT_WINDOWS |
| 9400 | /* |
| 9401 | * If there are windows or status lines below, try to put them at the |
| 9402 | * correct place. If we can't do that, they have to be redrawn. |
| 9403 | */ |
| 9404 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 9405 | { |
| 9406 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9407 | line_count, (int)Rows, NULL) == FAIL) |
| 9408 | { |
| 9409 | wp->w_redr_status = TRUE; |
| 9410 | win_rest_invalid(wp->w_next); |
| 9411 | } |
| 9412 | } |
| 9413 | /* |
| 9414 | * If this is the last window and there is no status line, redraw the |
| 9415 | * command line later. |
| 9416 | */ |
| 9417 | else |
| 9418 | #endif |
| 9419 | redraw_cmdline = TRUE; |
| 9420 | return OK; |
| 9421 | } |
| 9422 | |
| 9423 | /* |
| 9424 | * Common code for win_ins_lines() and win_del_lines(). |
| 9425 | * Returns OK or FAIL when the work has been done. |
| 9426 | * Returns MAYBE when not finished yet. |
| 9427 | */ |
| 9428 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9429 | win_do_lines( |
| 9430 | win_T *wp, |
| 9431 | int row, |
| 9432 | int line_count, |
| 9433 | int mayclear, |
| 9434 | int del) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9435 | { |
| 9436 | int retval; |
| 9437 | |
| 9438 | if (!redrawing() || line_count <= 0) |
| 9439 | return FAIL; |
| 9440 | |
| 9441 | /* only a few lines left: redraw is faster */ |
| 9442 | if (mayclear && Rows - line_count < 5 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9443 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9444 | && wp->w_width == Columns |
| 9445 | #endif |
| 9446 | ) |
| 9447 | { |
| 9448 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 9449 | return FAIL; |
| 9450 | } |
| 9451 | |
| 9452 | /* |
| 9453 | * Delete all remaining lines |
| 9454 | */ |
| 9455 | if (row + line_count >= wp->w_height) |
| 9456 | { |
| 9457 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 9458 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9459 | ' ', ' ', 0); |
| 9460 | return OK; |
| 9461 | } |
| 9462 | |
| 9463 | /* |
| 9464 | * when scrolling, the message on the command line should be cleared, |
| 9465 | * otherwise it will stay there forever. |
| 9466 | */ |
| 9467 | clear_cmdline = TRUE; |
| 9468 | |
| 9469 | /* |
| 9470 | * If the terminal can set a scroll region, use that. |
| 9471 | * Always do this in a vertically split window. This will redraw from |
| 9472 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 9473 | * win_line(). |
| 9474 | * 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] | 9475 | * a character in the lower right corner of the scroll region may cause a |
| 9476 | * scroll-up . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9477 | */ |
| 9478 | if (scroll_region |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9479 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9480 | || W_WIDTH(wp) != Columns |
| 9481 | #endif |
| 9482 | ) |
| 9483 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9484 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9485 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9486 | #endif |
| 9487 | scroll_region_set(wp, row); |
| 9488 | if (del) |
| 9489 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 9490 | wp->w_height - row, FALSE, wp); |
| 9491 | else |
| 9492 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 9493 | wp->w_height - row, wp); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9494 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9495 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9496 | #endif |
| 9497 | scroll_region_reset(); |
| 9498 | return retval; |
| 9499 | } |
| 9500 | |
| 9501 | #ifdef FEAT_WINDOWS |
| 9502 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 9503 | return FAIL; |
| 9504 | #endif |
| 9505 | |
| 9506 | return MAYBE; |
| 9507 | } |
| 9508 | |
| 9509 | /* |
| 9510 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 9511 | */ |
| 9512 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9513 | win_rest_invalid(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9514 | { |
| 9515 | #ifdef FEAT_WINDOWS |
| 9516 | while (wp != NULL) |
| 9517 | #else |
| 9518 | if (wp != NULL) |
| 9519 | #endif |
| 9520 | { |
| 9521 | redraw_win_later(wp, NOT_VALID); |
| 9522 | #ifdef FEAT_WINDOWS |
| 9523 | wp->w_redr_status = TRUE; |
| 9524 | wp = wp->w_next; |
| 9525 | #endif |
| 9526 | } |
| 9527 | redraw_cmdline = TRUE; |
| 9528 | } |
| 9529 | |
| 9530 | /* |
| 9531 | * The rest of the routines in this file perform screen manipulations. The |
| 9532 | * given operation is performed physically on the screen. The corresponding |
| 9533 | * change is also made to the internal screen image. In this way, the editor |
| 9534 | * anticipates the effect of editing changes on the appearance of the screen. |
| 9535 | * That way, when we call screenupdate a complete redraw isn't usually |
| 9536 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 9537 | * screen changes, and in the meantime, everything still works. |
| 9538 | */ |
| 9539 | |
| 9540 | /* |
| 9541 | * types for inserting or deleting lines |
| 9542 | */ |
| 9543 | #define USE_T_CAL 1 |
| 9544 | #define USE_T_CDL 2 |
| 9545 | #define USE_T_AL 3 |
| 9546 | #define USE_T_CE 4 |
| 9547 | #define USE_T_DL 5 |
| 9548 | #define USE_T_SR 6 |
| 9549 | #define USE_NL 7 |
| 9550 | #define USE_T_CD 8 |
| 9551 | #define USE_REDRAW 9 |
| 9552 | |
| 9553 | /* |
| 9554 | * insert lines on the screen and update ScreenLines[] |
| 9555 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9556 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9557 | * 'row' and 'end' are relative to the start of the region. |
| 9558 | * |
| 9559 | * return FAIL for failure, OK for success. |
| 9560 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9561 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9562 | screen_ins_lines( |
| 9563 | int off, |
| 9564 | int row, |
| 9565 | int line_count, |
| 9566 | int end, |
| 9567 | win_T *wp) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9568 | { |
| 9569 | int i; |
| 9570 | int j; |
| 9571 | unsigned temp; |
| 9572 | int cursor_row; |
| 9573 | int type; |
| 9574 | int result_empty; |
| 9575 | int can_ce = can_clear(T_CE); |
| 9576 | |
| 9577 | /* |
| 9578 | * FAIL if |
| 9579 | * - there is no valid screen |
| 9580 | * - the screen has to be redrawn completely |
| 9581 | * - the line count is less than one |
| 9582 | * - the line count is more than 'ttyscroll' |
| 9583 | */ |
| 9584 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9585 | return FAIL; |
| 9586 | |
| 9587 | /* |
| 9588 | * There are seven ways to insert lines: |
| 9589 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9590 | * characters from ScreenLines[]. |
| 9591 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9592 | * the insert is just empty lines |
| 9593 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9594 | * present or line_count > 1. It looks better if we do all the inserts |
| 9595 | * at once. |
| 9596 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9597 | * insert is just empty lines and T_CE is not present or line_count > |
| 9598 | * 1. |
| 9599 | * 4. Use T_AL (insert line) if it exists. |
| 9600 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9601 | * just empty lines. |
| 9602 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9603 | * just empty lines. |
| 9604 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9605 | * the 'da' flag is not set or we have clear line capability. |
| 9606 | * 8. redraw the characters from ScreenLines[]. |
| 9607 | * |
| 9608 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9609 | * the scrollbar for the window. It does have insert line, use that if it |
| 9610 | * exists. |
| 9611 | */ |
| 9612 | result_empty = (row + line_count >= end); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9613 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9614 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9615 | type = USE_REDRAW; |
| 9616 | else |
| 9617 | #endif |
| 9618 | if (can_clear(T_CD) && result_empty) |
| 9619 | type = USE_T_CD; |
| 9620 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9621 | type = USE_T_CAL; |
| 9622 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9623 | type = USE_T_CDL; |
| 9624 | else if (*T_AL != NUL) |
| 9625 | type = USE_T_AL; |
| 9626 | else if (can_ce && result_empty) |
| 9627 | type = USE_T_CE; |
| 9628 | else if (*T_DL != NUL && result_empty) |
| 9629 | type = USE_T_DL; |
| 9630 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9631 | type = USE_T_SR; |
| 9632 | else |
| 9633 | return FAIL; |
| 9634 | |
| 9635 | /* |
| 9636 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9637 | * care of t_db if necessary. |
| 9638 | */ |
| 9639 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9640 | type == USE_T_CE || type == USE_T_DL) |
| 9641 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9642 | |
| 9643 | /* |
| 9644 | * If text is retained below the screen, first clear or delete as many |
| 9645 | * lines at the bottom of the window as are about to be inserted so that |
| 9646 | * the deleted lines won't later surface during a screen_del_lines. |
| 9647 | */ |
| 9648 | if (*T_DB) |
| 9649 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9650 | |
| 9651 | #ifdef FEAT_CLIPBOARD |
| 9652 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9653 | * or not the full width of the screen. */ |
| 9654 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9655 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9656 | || (wp != NULL && wp->w_width != Columns) |
| 9657 | # endif |
| 9658 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9659 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9660 | else |
| 9661 | clip_scroll_selection(-line_count); |
| 9662 | #endif |
| 9663 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9664 | #ifdef FEAT_GUI |
| 9665 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9666 | * scrolling is actually carried out. */ |
| 9667 | gui_dont_update_cursor(); |
| 9668 | #endif |
| 9669 | |
| 9670 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9671 | cursor_row = row; |
| 9672 | else |
| 9673 | cursor_row = row + off; |
| 9674 | |
| 9675 | /* |
| 9676 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9677 | * Clear the inserted lines in ScreenLines[]. |
| 9678 | */ |
| 9679 | row += off; |
| 9680 | end += off; |
| 9681 | for (i = 0; i < line_count; ++i) |
| 9682 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9683 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9684 | if (wp != NULL && wp->w_width != Columns) |
| 9685 | { |
| 9686 | /* need to copy part of a line */ |
| 9687 | j = end - 1 - i; |
| 9688 | while ((j -= line_count) >= row) |
| 9689 | linecopy(j + line_count, j, wp); |
| 9690 | j += line_count; |
| 9691 | if (can_clear((char_u *)" ")) |
| 9692 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9693 | else |
| 9694 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9695 | LineWraps[j] = FALSE; |
| 9696 | } |
| 9697 | else |
| 9698 | #endif |
| 9699 | { |
| 9700 | j = end - 1 - i; |
| 9701 | temp = LineOffset[j]; |
| 9702 | while ((j -= line_count) >= row) |
| 9703 | { |
| 9704 | LineOffset[j + line_count] = LineOffset[j]; |
| 9705 | LineWraps[j + line_count] = LineWraps[j]; |
| 9706 | } |
| 9707 | LineOffset[j + line_count] = temp; |
| 9708 | LineWraps[j + line_count] = FALSE; |
| 9709 | if (can_clear((char_u *)" ")) |
| 9710 | lineclear(temp, (int)Columns); |
| 9711 | else |
| 9712 | lineinvalid(temp, (int)Columns); |
| 9713 | } |
| 9714 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9715 | |
| 9716 | screen_stop_highlight(); |
| 9717 | windgoto(cursor_row, 0); |
| 9718 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9719 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9720 | /* redraw the characters */ |
| 9721 | if (type == USE_REDRAW) |
| 9722 | redraw_block(row, end, wp); |
| 9723 | else |
| 9724 | #endif |
| 9725 | if (type == USE_T_CAL) |
| 9726 | { |
| 9727 | term_append_lines(line_count); |
| 9728 | screen_start(); /* don't know where cursor is now */ |
| 9729 | } |
| 9730 | else |
| 9731 | { |
| 9732 | for (i = 0; i < line_count; i++) |
| 9733 | { |
| 9734 | if (type == USE_T_AL) |
| 9735 | { |
| 9736 | if (i && cursor_row != 0) |
| 9737 | windgoto(cursor_row, 0); |
| 9738 | out_str(T_AL); |
| 9739 | } |
| 9740 | else /* type == USE_T_SR */ |
| 9741 | out_str(T_SR); |
| 9742 | screen_start(); /* don't know where cursor is now */ |
| 9743 | } |
| 9744 | } |
| 9745 | |
| 9746 | /* |
| 9747 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9748 | * have been scrolled down into the region. |
| 9749 | */ |
| 9750 | if (type == USE_T_SR && *T_DA) |
| 9751 | { |
| 9752 | for (i = 0; i < line_count; ++i) |
| 9753 | { |
| 9754 | windgoto(off + i, 0); |
| 9755 | out_str(T_CE); |
| 9756 | screen_start(); /* don't know where cursor is now */ |
| 9757 | } |
| 9758 | } |
| 9759 | |
| 9760 | #ifdef FEAT_GUI |
| 9761 | gui_can_update_cursor(); |
| 9762 | if (gui.in_use) |
| 9763 | out_flush(); /* always flush after a scroll */ |
| 9764 | #endif |
| 9765 | return OK; |
| 9766 | } |
| 9767 | |
| 9768 | /* |
| 9769 | * delete lines on the screen and update ScreenLines[] |
| 9770 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9771 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9772 | * 'row' and 'end' are relative to the start of the region. |
| 9773 | * |
| 9774 | * Return OK for success, FAIL if the lines are not deleted. |
| 9775 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9776 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9777 | screen_del_lines( |
| 9778 | int off, |
| 9779 | int row, |
| 9780 | int line_count, |
| 9781 | int end, |
| 9782 | int force, /* even when line_count > p_ttyscroll */ |
| 9783 | win_T *wp UNUSED) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9784 | { |
| 9785 | int j; |
| 9786 | int i; |
| 9787 | unsigned temp; |
| 9788 | int cursor_row; |
| 9789 | int cursor_end; |
| 9790 | int result_empty; /* result is empty until end of region */ |
| 9791 | int can_delete; /* deleting line codes can be used */ |
| 9792 | int type; |
| 9793 | |
| 9794 | /* |
| 9795 | * FAIL if |
| 9796 | * - there is no valid screen |
| 9797 | * - the screen has to be redrawn completely |
| 9798 | * - the line count is less than one |
| 9799 | * - the line count is more than 'ttyscroll' |
| 9800 | */ |
| 9801 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9802 | (!force && line_count > p_ttyscroll)) |
| 9803 | return FAIL; |
| 9804 | |
| 9805 | /* |
| 9806 | * Check if the rest of the current region will become empty. |
| 9807 | */ |
| 9808 | result_empty = row + line_count >= end; |
| 9809 | |
| 9810 | /* |
| 9811 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9812 | * available. |
| 9813 | */ |
| 9814 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9815 | |
| 9816 | /* |
| 9817 | * There are six ways to delete lines: |
| 9818 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9819 | * characters from ScreenLines[]. |
| 9820 | * 1. Use T_CD if it exists and the result is empty. |
| 9821 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9822 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9823 | * none of the other ways work. |
| 9824 | * 4. Use T_CE (erase line) if the result is empty. |
| 9825 | * 5. Use T_DL (delete line) if it exists. |
| 9826 | * 6. redraw the characters from ScreenLines[]. |
| 9827 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9828 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9829 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9830 | type = USE_REDRAW; |
| 9831 | else |
| 9832 | #endif |
| 9833 | if (can_clear(T_CD) && result_empty) |
| 9834 | type = USE_T_CD; |
| 9835 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9836 | /* |
| 9837 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9838 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9839 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9840 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9841 | * the trick... |
| 9842 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9843 | * (Olaf Seibert) |
| 9844 | */ |
| 9845 | else if (row == 0 && T_DB == empty_option |
| 9846 | && (line_count == 1 || *T_CDL == NUL)) |
| 9847 | #else |
| 9848 | else if (row == 0 && ( |
| 9849 | #ifndef AMIGA |
| 9850 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9851 | * up, so use delete-line command */ |
| 9852 | line_count == 1 || |
| 9853 | #endif |
| 9854 | *T_CDL == NUL)) |
| 9855 | #endif |
| 9856 | type = USE_NL; |
| 9857 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9858 | type = USE_T_CDL; |
| 9859 | else if (can_clear(T_CE) && result_empty |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9860 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9861 | && (wp == NULL || wp->w_width == Columns) |
| 9862 | #endif |
| 9863 | ) |
| 9864 | type = USE_T_CE; |
| 9865 | else if (*T_DL != NUL && can_delete) |
| 9866 | type = USE_T_DL; |
| 9867 | else if (*T_CDL != NUL && can_delete) |
| 9868 | type = USE_T_CDL; |
| 9869 | else |
| 9870 | return FAIL; |
| 9871 | |
| 9872 | #ifdef FEAT_CLIPBOARD |
| 9873 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9874 | * not the full width of the screen. */ |
| 9875 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9876 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9877 | || (wp != NULL && wp->w_width != Columns) |
| 9878 | # endif |
| 9879 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9880 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9881 | else |
| 9882 | clip_scroll_selection(line_count); |
| 9883 | #endif |
| 9884 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9885 | #ifdef FEAT_GUI |
| 9886 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9887 | * scrolling is actually carried out. */ |
| 9888 | gui_dont_update_cursor(); |
| 9889 | #endif |
| 9890 | |
| 9891 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9892 | { |
| 9893 | cursor_row = row; |
| 9894 | cursor_end = end; |
| 9895 | } |
| 9896 | else |
| 9897 | { |
| 9898 | cursor_row = row + off; |
| 9899 | cursor_end = end + off; |
| 9900 | } |
| 9901 | |
| 9902 | /* |
| 9903 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9904 | * Clear the inserted lines in ScreenLines[]. |
| 9905 | */ |
| 9906 | row += off; |
| 9907 | end += off; |
| 9908 | for (i = 0; i < line_count; ++i) |
| 9909 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9910 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9911 | if (wp != NULL && wp->w_width != Columns) |
| 9912 | { |
| 9913 | /* need to copy part of a line */ |
| 9914 | j = row + i; |
| 9915 | while ((j += line_count) <= end - 1) |
| 9916 | linecopy(j - line_count, j, wp); |
| 9917 | j -= line_count; |
| 9918 | if (can_clear((char_u *)" ")) |
| 9919 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9920 | else |
| 9921 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9922 | LineWraps[j] = FALSE; |
| 9923 | } |
| 9924 | else |
| 9925 | #endif |
| 9926 | { |
| 9927 | /* whole width, moving the line pointers is faster */ |
| 9928 | j = row + i; |
| 9929 | temp = LineOffset[j]; |
| 9930 | while ((j += line_count) <= end - 1) |
| 9931 | { |
| 9932 | LineOffset[j - line_count] = LineOffset[j]; |
| 9933 | LineWraps[j - line_count] = LineWraps[j]; |
| 9934 | } |
| 9935 | LineOffset[j - line_count] = temp; |
| 9936 | LineWraps[j - line_count] = FALSE; |
| 9937 | if (can_clear((char_u *)" ")) |
| 9938 | lineclear(temp, (int)Columns); |
| 9939 | else |
| 9940 | lineinvalid(temp, (int)Columns); |
| 9941 | } |
| 9942 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9943 | |
| 9944 | screen_stop_highlight(); |
| 9945 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9946 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9947 | /* redraw the characters */ |
| 9948 | if (type == USE_REDRAW) |
| 9949 | redraw_block(row, end, wp); |
| 9950 | else |
| 9951 | #endif |
| 9952 | if (type == USE_T_CD) /* delete the lines */ |
| 9953 | { |
| 9954 | windgoto(cursor_row, 0); |
| 9955 | out_str(T_CD); |
| 9956 | screen_start(); /* don't know where cursor is now */ |
| 9957 | } |
| 9958 | else if (type == USE_T_CDL) |
| 9959 | { |
| 9960 | windgoto(cursor_row, 0); |
| 9961 | term_delete_lines(line_count); |
| 9962 | screen_start(); /* don't know where cursor is now */ |
| 9963 | } |
| 9964 | /* |
| 9965 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9966 | * the whole screen (scroll region) up by outputting newlines on the |
| 9967 | * last line. |
| 9968 | */ |
| 9969 | else if (type == USE_NL) |
| 9970 | { |
| 9971 | windgoto(cursor_end - 1, 0); |
| 9972 | for (i = line_count; --i >= 0; ) |
| 9973 | out_char('\n'); /* cursor will remain on same line */ |
| 9974 | } |
| 9975 | else |
| 9976 | { |
| 9977 | for (i = line_count; --i >= 0; ) |
| 9978 | { |
| 9979 | if (type == USE_T_DL) |
| 9980 | { |
| 9981 | windgoto(cursor_row, 0); |
| 9982 | out_str(T_DL); /* delete a line */ |
| 9983 | } |
| 9984 | else /* type == USE_T_CE */ |
| 9985 | { |
| 9986 | windgoto(cursor_row + i, 0); |
| 9987 | out_str(T_CE); /* erase a line */ |
| 9988 | } |
| 9989 | screen_start(); /* don't know where cursor is now */ |
| 9990 | } |
| 9991 | } |
| 9992 | |
| 9993 | /* |
| 9994 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9995 | * scrolled up at the bottom of the region. |
| 9996 | */ |
| 9997 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9998 | { |
| 9999 | for (i = line_count; i > 0; --i) |
| 10000 | { |
| 10001 | windgoto(cursor_end - i, 0); |
| 10002 | out_str(T_CE); /* erase a line */ |
| 10003 | screen_start(); /* don't know where cursor is now */ |
| 10004 | } |
| 10005 | } |
| 10006 | |
| 10007 | #ifdef FEAT_GUI |
| 10008 | gui_can_update_cursor(); |
| 10009 | if (gui.in_use) |
| 10010 | out_flush(); /* always flush after a scroll */ |
| 10011 | #endif |
| 10012 | |
| 10013 | return OK; |
| 10014 | } |
| 10015 | |
| 10016 | /* |
| 10017 | * show the current mode and ruler |
| 10018 | * |
| 10019 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 10020 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 10021 | * cleared only if a mode is shown. |
| 10022 | * Return the length of the message (0 if no message). |
| 10023 | */ |
| 10024 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10025 | showmode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10026 | { |
| 10027 | int need_clear; |
| 10028 | int length = 0; |
| 10029 | int do_mode; |
| 10030 | int attr; |
| 10031 | int nwr_save; |
| 10032 | #ifdef FEAT_INS_EXPAND |
| 10033 | int sub_attr; |
| 10034 | #endif |
| 10035 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 10036 | do_mode = ((p_smd && msg_silent == 0) |
| 10037 | && ((State & INSERT) |
| 10038 | || restart_edit |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 10039 | || VIsual_active)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10040 | if (do_mode || Recording) |
| 10041 | { |
| 10042 | /* |
| 10043 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 10044 | * Call char_avail() only when we are going to show something, because |
| 10045 | * it takes a bit of time. |
| 10046 | */ |
| 10047 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 10048 | { |
| 10049 | redraw_cmdline = TRUE; /* show mode later */ |
| 10050 | return 0; |
| 10051 | } |
| 10052 | |
| 10053 | nwr_save = need_wait_return; |
| 10054 | |
| 10055 | /* wait a bit before overwriting an important message */ |
| 10056 | check_for_delay(FALSE); |
| 10057 | |
| 10058 | /* if the cmdline is more than one line high, erase top lines */ |
| 10059 | need_clear = clear_cmdline; |
| 10060 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 10061 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 10062 | |
| 10063 | /* Position on the last line in the window, column 0 */ |
| 10064 | msg_pos_mode(); |
| 10065 | cursor_off(); |
| 10066 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 10067 | if (do_mode) |
| 10068 | { |
| 10069 | MSG_PUTS_ATTR("--", attr); |
| 10070 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10071 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10072 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10073 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10074 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10075 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10076 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10077 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 10078 | # 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] | 10079 | MSG_PUTS_ATTR(" IM", attr); |
| 10080 | # else |
| 10081 | MSG_PUTS_ATTR(" XIM", attr); |
| 10082 | # endif |
| 10083 | #endif |
| 10084 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 10085 | if (gui.in_use) |
| 10086 | { |
| 10087 | if (hangul_input_state_get()) |
Bram Moolenaar | 72f4cc4 | 2015-11-10 14:35:18 +0100 | [diff] [blame] | 10088 | { |
| 10089 | /* HANGUL */ |
| 10090 | if (enc_utf8) |
| 10091 | MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr); |
| 10092 | else |
| 10093 | MSG_PUTS_ATTR(" \307\321\261\333", attr); |
| 10094 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10095 | } |
| 10096 | #endif |
| 10097 | #ifdef FEAT_INS_EXPAND |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 10098 | /* CTRL-X in Insert mode */ |
| 10099 | if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10100 | { |
| 10101 | /* These messages can get long, avoid a wrap in a narrow |
| 10102 | * window. Prefer showing edit_submode_extra. */ |
| 10103 | length = (Rows - msg_row) * Columns - 3; |
| 10104 | if (edit_submode_extra != NULL) |
| 10105 | length -= vim_strsize(edit_submode_extra); |
| 10106 | if (length > 0) |
| 10107 | { |
| 10108 | if (edit_submode_pre != NULL) |
| 10109 | length -= vim_strsize(edit_submode_pre); |
| 10110 | if (length - vim_strsize(edit_submode) > 0) |
| 10111 | { |
| 10112 | if (edit_submode_pre != NULL) |
| 10113 | msg_puts_attr(edit_submode_pre, attr); |
| 10114 | msg_puts_attr(edit_submode, attr); |
| 10115 | } |
| 10116 | if (edit_submode_extra != NULL) |
| 10117 | { |
| 10118 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 10119 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 10120 | sub_attr = hl_attr(edit_submode_highl); |
| 10121 | else |
| 10122 | sub_attr = attr; |
| 10123 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 10124 | } |
| 10125 | } |
| 10126 | length = 0; |
| 10127 | } |
| 10128 | else |
| 10129 | #endif |
| 10130 | { |
| 10131 | #ifdef FEAT_VREPLACE |
| 10132 | if (State & VREPLACE_FLAG) |
| 10133 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 10134 | else |
| 10135 | #endif |
| 10136 | if (State & REPLACE_FLAG) |
| 10137 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 10138 | else if (State & INSERT) |
| 10139 | { |
| 10140 | #ifdef FEAT_RIGHTLEFT |
| 10141 | if (p_ri) |
| 10142 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 10143 | #endif |
| 10144 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 10145 | } |
| 10146 | else if (restart_edit == 'I') |
| 10147 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 10148 | else if (restart_edit == 'R') |
| 10149 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 10150 | else if (restart_edit == 'V') |
| 10151 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 10152 | #ifdef FEAT_RIGHTLEFT |
| 10153 | if (p_hkmap) |
| 10154 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 10155 | # ifdef FEAT_FKMAP |
| 10156 | if (p_fkmap) |
| 10157 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 10158 | # endif |
| 10159 | #endif |
| 10160 | #ifdef FEAT_KEYMAP |
| 10161 | if (State & LANGMAP) |
| 10162 | { |
| 10163 | # ifdef FEAT_ARABIC |
| 10164 | if (curwin->w_p_arab) |
| 10165 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 10166 | else |
| 10167 | # endif |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 10168 | if (get_keymap_str(curwin, (char_u *)" (%s)", |
| 10169 | NameBuff, MAXPATHL)) |
| 10170 | MSG_PUTS_ATTR(NameBuff, attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10171 | } |
| 10172 | #endif |
| 10173 | if ((State & INSERT) && p_paste) |
| 10174 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 10175 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10176 | if (VIsual_active) |
| 10177 | { |
| 10178 | char *p; |
| 10179 | |
| 10180 | /* Don't concatenate separate words to avoid translation |
| 10181 | * problems. */ |
| 10182 | switch ((VIsual_select ? 4 : 0) |
| 10183 | + (VIsual_mode == Ctrl_V) * 2 |
| 10184 | + (VIsual_mode == 'V')) |
| 10185 | { |
| 10186 | case 0: p = N_(" VISUAL"); break; |
| 10187 | case 1: p = N_(" VISUAL LINE"); break; |
| 10188 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 10189 | case 4: p = N_(" SELECT"); break; |
| 10190 | case 5: p = N_(" SELECT LINE"); break; |
| 10191 | default: p = N_(" SELECT BLOCK"); break; |
| 10192 | } |
| 10193 | MSG_PUTS_ATTR(_(p), attr); |
| 10194 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10195 | MSG_PUTS_ATTR(" --", attr); |
| 10196 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10197 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10198 | need_clear = TRUE; |
| 10199 | } |
| 10200 | if (Recording |
| 10201 | #ifdef FEAT_INS_EXPAND |
| 10202 | && edit_submode == NULL /* otherwise it gets too long */ |
| 10203 | #endif |
| 10204 | ) |
| 10205 | { |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10206 | recording_mode(attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10207 | need_clear = TRUE; |
| 10208 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10209 | |
| 10210 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10211 | if (need_clear || clear_cmdline) |
| 10212 | msg_clr_eos(); |
| 10213 | msg_didout = FALSE; /* overwrite this message */ |
| 10214 | length = msg_col; |
| 10215 | msg_col = 0; |
| 10216 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 10217 | } |
| 10218 | else if (clear_cmdline && msg_silent == 0) |
| 10219 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 10220 | msg_clr_cmdline(); |
| 10221 | |
| 10222 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10223 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 10224 | if (VIsual_active) |
| 10225 | clear_showcmd(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10226 | |
| 10227 | /* If the last window has no status line, the ruler is after the mode |
| 10228 | * message and must be redrawn */ |
| 10229 | if (redrawing() |
| 10230 | # ifdef FEAT_WINDOWS |
| 10231 | && lastwin->w_status_height == 0 |
| 10232 | # endif |
| 10233 | ) |
| 10234 | win_redr_ruler(lastwin, TRUE); |
| 10235 | #endif |
| 10236 | redraw_cmdline = FALSE; |
| 10237 | clear_cmdline = FALSE; |
| 10238 | |
| 10239 | return length; |
| 10240 | } |
| 10241 | |
| 10242 | /* |
| 10243 | * Position for a mode message. |
| 10244 | */ |
| 10245 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10246 | msg_pos_mode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10247 | { |
| 10248 | msg_col = 0; |
| 10249 | msg_row = Rows - 1; |
| 10250 | } |
| 10251 | |
| 10252 | /* |
| 10253 | * Delete mode message. Used when ESC is typed which is expected to end |
| 10254 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10255 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10256 | */ |
| 10257 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10258 | unshowmode(int force) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10259 | { |
| 10260 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 10261 | * 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] | 10262 | */ |
| 10263 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 10264 | redraw_cmdline = TRUE; /* delete mode later */ |
| 10265 | else |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10266 | clearmode(); |
| 10267 | } |
| 10268 | |
| 10269 | /* |
| 10270 | * Clear the mode message. |
| 10271 | */ |
| 10272 | void |
Bram Moolenaar | cf08946 | 2016-06-12 21:18:43 +0200 | [diff] [blame] | 10273 | clearmode(void) |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10274 | { |
| 10275 | msg_pos_mode(); |
| 10276 | if (Recording) |
| 10277 | recording_mode(hl_attr(HLF_CM)); |
| 10278 | msg_clr_eos(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10279 | } |
| 10280 | |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10281 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10282 | recording_mode(int attr) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10283 | { |
| 10284 | MSG_PUTS_ATTR(_("recording"), attr); |
| 10285 | if (!shortmess(SHM_RECORDING)) |
| 10286 | { |
| 10287 | char_u s[4]; |
| 10288 | sprintf((char *)s, " @%c", Recording); |
| 10289 | MSG_PUTS_ATTR(s, attr); |
| 10290 | } |
| 10291 | } |
| 10292 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10293 | #if defined(FEAT_WINDOWS) |
| 10294 | /* |
| 10295 | * Draw the tab pages line at the top of the Vim window. |
| 10296 | */ |
| 10297 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10298 | draw_tabline(void) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10299 | { |
| 10300 | int tabcount = 0; |
| 10301 | tabpage_T *tp; |
| 10302 | int tabwidth; |
| 10303 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10304 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10305 | int attr; |
| 10306 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10307 | win_T *cwp; |
| 10308 | int wincount; |
| 10309 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10310 | int c; |
| 10311 | int len; |
| 10312 | int attr_sel = hl_attr(HLF_TPS); |
| 10313 | int attr_nosel = hl_attr(HLF_TP); |
| 10314 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10315 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10316 | int room; |
| 10317 | int use_sep_chars = (t_colors < 8 |
| 10318 | #ifdef FEAT_GUI |
| 10319 | && !gui.in_use |
| 10320 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 10321 | #ifdef FEAT_TERMGUICOLORS |
| 10322 | && !p_tgc |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 10323 | #endif |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10324 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10325 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10326 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10327 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10328 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 10329 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10330 | if (gui_use_tabline()) |
| 10331 | { |
| 10332 | gui_update_tabline(); |
| 10333 | return; |
| 10334 | } |
| 10335 | #endif |
| 10336 | |
| 10337 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10338 | return; |
| 10339 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10340 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10341 | |
| 10342 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 10343 | for (scol = 0; scol < Columns; ++scol) |
| 10344 | TabPageIdxs[scol] = 0; |
| 10345 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10346 | /* Use the 'tabline' option if it's set. */ |
| 10347 | if (*p_tal != NUL) |
| 10348 | { |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10349 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10350 | |
| 10351 | /* Check for an error. If there is one we would loop in redrawing the |
| 10352 | * screen. Avoid that by making 'tabline' empty. */ |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10353 | did_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10354 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10355 | if (did_emsg) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10356 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10357 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10358 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10359 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10360 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10361 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10362 | { |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 10363 | FOR_ALL_TABPAGES(tp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10364 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10365 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10366 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 10367 | if (tabwidth < 6) |
| 10368 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10369 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10370 | attr = attr_nosel; |
| 10371 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10372 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10373 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 10374 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10375 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10376 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10377 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10378 | if (tp->tp_topframe == topframe) |
| 10379 | attr = attr_sel; |
| 10380 | if (use_sep_chars && col > 0) |
| 10381 | screen_putchar('|', 0, col++, attr); |
| 10382 | |
| 10383 | if (tp->tp_topframe != topframe) |
| 10384 | attr = attr_nosel; |
| 10385 | |
| 10386 | screen_putchar(' ', 0, col++, attr); |
| 10387 | |
| 10388 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10389 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10390 | cwp = curwin; |
| 10391 | wp = firstwin; |
| 10392 | } |
| 10393 | else |
| 10394 | { |
| 10395 | cwp = tp->tp_curwin; |
| 10396 | wp = tp->tp_firstwin; |
| 10397 | } |
| 10398 | |
| 10399 | modified = FALSE; |
| 10400 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 10401 | if (bufIsChanged(wp->w_buffer)) |
| 10402 | modified = TRUE; |
| 10403 | if (modified || wincount > 1) |
| 10404 | { |
| 10405 | if (wincount > 1) |
| 10406 | { |
| 10407 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10408 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10409 | if (col + len >= Columns - 3) |
| 10410 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10411 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10412 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10413 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10414 | #else |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10415 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10416 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10417 | ); |
| 10418 | col += len; |
| 10419 | } |
| 10420 | if (modified) |
| 10421 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 10422 | screen_putchar(' ', 0, col++, attr); |
| 10423 | } |
| 10424 | |
| 10425 | room = scol - col + tabwidth - 1; |
| 10426 | if (room > 0) |
| 10427 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10428 | /* Get buffer name in NameBuff[] */ |
| 10429 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 10430 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10431 | len = vim_strsize(NameBuff); |
| 10432 | p = NameBuff; |
| 10433 | #ifdef FEAT_MBYTE |
| 10434 | if (has_mbyte) |
| 10435 | while (len > room) |
| 10436 | { |
| 10437 | len -= ptr2cells(p); |
| 10438 | mb_ptr_adv(p); |
| 10439 | } |
| 10440 | else |
| 10441 | #endif |
| 10442 | if (len > room) |
| 10443 | { |
| 10444 | p += len - room; |
| 10445 | len = room; |
| 10446 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10447 | if (len > Columns - col - 1) |
| 10448 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10449 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10450 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10451 | col += len; |
| 10452 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10453 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10454 | |
| 10455 | /* Store the tab page number in TabPageIdxs[], so that |
| 10456 | * jump_to_mouse() knows where each one is. */ |
| 10457 | ++tabcount; |
| 10458 | while (scol < col) |
| 10459 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10460 | } |
| 10461 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10462 | if (use_sep_chars) |
| 10463 | c = '_'; |
| 10464 | else |
| 10465 | c = ' '; |
| 10466 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10467 | |
| 10468 | /* Put an "X" for closing the current tab if there are several. */ |
| 10469 | if (first_tabpage->tp_next != NULL) |
| 10470 | { |
| 10471 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 10472 | TabPageIdxs[Columns - 1] = -999; |
| 10473 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10474 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 10475 | |
| 10476 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 10477 | * set. */ |
| 10478 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10479 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10480 | |
| 10481 | /* |
| 10482 | * Get buffer name for "buf" into NameBuff[]. |
| 10483 | * Takes care of special buffer names and translates special characters. |
| 10484 | */ |
| 10485 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10486 | get_trans_bufname(buf_T *buf) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10487 | { |
| 10488 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 10489 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10490 | else |
| 10491 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 10492 | trans_characters(NameBuff, MAXPATHL); |
| 10493 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10494 | #endif |
| 10495 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10496 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 10497 | /* |
| 10498 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 10499 | */ |
| 10500 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10501 | fillchar_status(int *attr, int is_curwin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10502 | { |
| 10503 | int fill; |
| 10504 | if (is_curwin) |
| 10505 | { |
| 10506 | *attr = hl_attr(HLF_S); |
| 10507 | fill = fill_stl; |
| 10508 | } |
| 10509 | else |
| 10510 | { |
| 10511 | *attr = hl_attr(HLF_SNC); |
| 10512 | fill = fill_stlnc; |
| 10513 | } |
| 10514 | /* Use fill when there is highlighting, and highlighting of current |
| 10515 | * window differs, or the fillchars differ, or this is not the |
| 10516 | * current window */ |
| 10517 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 10518 | || !is_curwin || firstwin == lastwin) |
| 10519 | || (fill_stl != fill_stlnc))) |
| 10520 | return fill; |
| 10521 | if (is_curwin) |
| 10522 | return '^'; |
| 10523 | return '='; |
| 10524 | } |
| 10525 | #endif |
| 10526 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10527 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10528 | /* |
| 10529 | * Get the character to use in a separator between vertically split windows. |
| 10530 | * Get its attributes in "*attr". |
| 10531 | */ |
| 10532 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10533 | fillchar_vsep(int *attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10534 | { |
| 10535 | *attr = hl_attr(HLF_C); |
| 10536 | if (*attr == 0 && fill_vert == ' ') |
| 10537 | return '|'; |
| 10538 | else |
| 10539 | return fill_vert; |
| 10540 | } |
| 10541 | #endif |
| 10542 | |
| 10543 | /* |
| 10544 | * Return TRUE if redrawing should currently be done. |
| 10545 | */ |
| 10546 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10547 | redrawing(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10548 | { |
| 10549 | return (!RedrawingDisabled |
| 10550 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 10551 | } |
| 10552 | |
| 10553 | /* |
| 10554 | * Return TRUE if printing messages should currently be done. |
| 10555 | */ |
| 10556 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10557 | messaging(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10558 | { |
| 10559 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10560 | } |
| 10561 | |
| 10562 | /* |
| 10563 | * Show current status info in ruler and various other places |
| 10564 | * If always is FALSE, only show ruler if position has changed. |
| 10565 | */ |
| 10566 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10567 | showruler(int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10568 | { |
| 10569 | if (!always && !redrawing()) |
| 10570 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10571 | #ifdef FEAT_INS_EXPAND |
| 10572 | if (pum_visible()) |
| 10573 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10574 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10575 | /* Don't redraw right now, do it later. */ |
| 10576 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10577 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10578 | return; |
| 10579 | } |
| 10580 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10581 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10582 | 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] | 10583 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10584 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10585 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10586 | else |
| 10587 | #endif |
| 10588 | #ifdef FEAT_CMDL_INFO |
| 10589 | win_redr_ruler(curwin, always); |
| 10590 | #endif |
| 10591 | |
| 10592 | #ifdef FEAT_TITLE |
| 10593 | if (need_maketitle |
| 10594 | # ifdef FEAT_STL_OPT |
| 10595 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10596 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10597 | # endif |
| 10598 | ) |
| 10599 | maketitle(); |
| 10600 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10601 | #ifdef FEAT_WINDOWS |
| 10602 | /* Redraw the tab pages line if needed. */ |
| 10603 | if (redraw_tabline) |
| 10604 | draw_tabline(); |
| 10605 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10606 | } |
| 10607 | |
| 10608 | #ifdef FEAT_CMDL_INFO |
| 10609 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10610 | win_redr_ruler(win_T *wp, int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10611 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10612 | #define RULER_BUF_LEN 70 |
| 10613 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10614 | int row; |
| 10615 | int fillchar; |
| 10616 | int attr; |
| 10617 | int empty_line = FALSE; |
| 10618 | colnr_T virtcol; |
| 10619 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10620 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10621 | int o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10622 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10623 | int this_ru_col; |
| 10624 | int off = 0; |
| 10625 | int width = Columns; |
| 10626 | # define WITH_OFF(x) x |
| 10627 | # define WITH_WIDTH(x) x |
| 10628 | #else |
| 10629 | # define WITH_OFF(x) 0 |
| 10630 | # define WITH_WIDTH(x) Columns |
| 10631 | # define this_ru_col ru_col |
| 10632 | #endif |
| 10633 | |
| 10634 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10635 | if (!p_ru) |
| 10636 | return; |
| 10637 | |
| 10638 | /* |
| 10639 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10640 | * after deleting lines, before cursor.lnum is corrected. |
| 10641 | */ |
| 10642 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10643 | return; |
| 10644 | |
| 10645 | #ifdef FEAT_INS_EXPAND |
| 10646 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10647 | * the (long) mode message. */ |
| 10648 | # ifdef FEAT_WINDOWS |
| 10649 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10650 | # endif |
| 10651 | if (edit_submode != NULL) |
| 10652 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10653 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10654 | if (pum_visible()) |
| 10655 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10656 | #endif |
| 10657 | |
| 10658 | #ifdef FEAT_STL_OPT |
| 10659 | if (*p_ruf) |
| 10660 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10661 | int save_called_emsg = called_emsg; |
| 10662 | |
| 10663 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10664 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10665 | if (called_emsg) |
| 10666 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10667 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10668 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10669 | return; |
| 10670 | } |
| 10671 | #endif |
| 10672 | |
| 10673 | /* |
| 10674 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10675 | */ |
| 10676 | if (!(State & INSERT) |
| 10677 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10678 | empty_line = TRUE; |
| 10679 | |
| 10680 | /* |
| 10681 | * Only draw the ruler when something changed. |
| 10682 | */ |
| 10683 | validate_virtcol_win(wp); |
| 10684 | if ( redraw_cmdline |
| 10685 | || always |
| 10686 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10687 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10688 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10689 | #ifdef FEAT_VIRTUALEDIT |
| 10690 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10691 | #endif |
| 10692 | || wp->w_topline != wp->w_ru_topline |
| 10693 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10694 | #ifdef FEAT_DIFF |
| 10695 | || wp->w_topfill != wp->w_ru_topfill |
| 10696 | #endif |
| 10697 | || empty_line != wp->w_ru_empty) |
| 10698 | { |
| 10699 | cursor_off(); |
| 10700 | #ifdef FEAT_WINDOWS |
| 10701 | if (wp->w_status_height) |
| 10702 | { |
| 10703 | row = W_WINROW(wp) + wp->w_height; |
| 10704 | fillchar = fillchar_status(&attr, wp == curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10705 | off = W_WINCOL(wp); |
| 10706 | width = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10707 | } |
| 10708 | else |
| 10709 | #endif |
| 10710 | { |
| 10711 | row = Rows - 1; |
| 10712 | fillchar = ' '; |
| 10713 | attr = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10714 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10715 | width = Columns; |
| 10716 | off = 0; |
| 10717 | #endif |
| 10718 | } |
| 10719 | |
| 10720 | /* In list mode virtcol needs to be recomputed */ |
| 10721 | virtcol = wp->w_virtcol; |
| 10722 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10723 | { |
| 10724 | wp->w_p_list = FALSE; |
| 10725 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10726 | wp->w_p_list = TRUE; |
| 10727 | } |
| 10728 | |
| 10729 | /* |
| 10730 | * Some sprintfs return the length, some return a pointer. |
| 10731 | * To avoid portability problems we use strlen() here. |
| 10732 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10733 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10734 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10735 | ? 0L |
| 10736 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10737 | len = STRLEN(buffer); |
| 10738 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10739 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10740 | (int)virtcol + 1); |
| 10741 | |
| 10742 | /* |
| 10743 | * Add a "50%" if there is room for it. |
| 10744 | * On the last line, don't print in the last column (scrolls the |
| 10745 | * screen up on some terminals). |
| 10746 | */ |
| 10747 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10748 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10749 | o = i + vim_strsize(buffer + i + 1); |
| 10750 | #ifdef FEAT_WINDOWS |
| 10751 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10752 | #endif |
| 10753 | ++o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10754 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10755 | this_ru_col = ru_col - (Columns - width); |
| 10756 | if (this_ru_col < 0) |
| 10757 | this_ru_col = 0; |
| 10758 | #endif |
| 10759 | /* Never use more than half the window/screen width, leave the other |
| 10760 | * half for the filename. */ |
| 10761 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10762 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10763 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10764 | { |
Bram Moolenaar | 0027c21 | 2015-01-07 13:31:52 +0100 | [diff] [blame] | 10765 | /* need at least 3 chars left for get_rel_pos() + NUL */ |
| 10766 | 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] | 10767 | { |
| 10768 | #ifdef FEAT_MBYTE |
| 10769 | if (has_mbyte) |
| 10770 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10771 | else |
| 10772 | #endif |
| 10773 | buffer[i++] = fillchar; |
| 10774 | ++o; |
| 10775 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10776 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10777 | } |
| 10778 | /* Truncate at window boundary. */ |
| 10779 | #ifdef FEAT_MBYTE |
| 10780 | if (has_mbyte) |
| 10781 | { |
| 10782 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10783 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10784 | { |
| 10785 | o += (*mb_ptr2cells)(buffer + i); |
| 10786 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10787 | { |
| 10788 | buffer[i] = NUL; |
| 10789 | break; |
| 10790 | } |
| 10791 | } |
| 10792 | } |
| 10793 | else |
| 10794 | #endif |
| 10795 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10796 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10797 | |
| 10798 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10799 | i = redraw_cmdline; |
| 10800 | screen_fill(row, row + 1, |
| 10801 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10802 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10803 | fillchar, fillchar, attr); |
| 10804 | /* don't redraw the cmdline because of showing the ruler */ |
| 10805 | redraw_cmdline = i; |
| 10806 | wp->w_ru_cursor = wp->w_cursor; |
| 10807 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10808 | wp->w_ru_empty = empty_line; |
| 10809 | wp->w_ru_topline = wp->w_topline; |
| 10810 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10811 | #ifdef FEAT_DIFF |
| 10812 | wp->w_ru_topfill = wp->w_topfill; |
| 10813 | #endif |
| 10814 | } |
| 10815 | } |
| 10816 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10817 | |
| 10818 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10819 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10820 | * Return the width of the 'number' and 'relativenumber' column. |
| 10821 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10822 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10823 | */ |
| 10824 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10825 | number_width(win_T *wp) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10826 | { |
| 10827 | int n; |
| 10828 | linenr_T lnum; |
| 10829 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10830 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10831 | /* cursor line shows "0" */ |
| 10832 | lnum = wp->w_height; |
| 10833 | else |
| 10834 | /* cursor line shows absolute line number */ |
| 10835 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10836 | |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10837 | 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] | 10838 | return wp->w_nrwidth_width; |
| 10839 | wp->w_nrwidth_line_count = lnum; |
| 10840 | |
| 10841 | n = 0; |
| 10842 | do |
| 10843 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10844 | lnum /= 10; |
| 10845 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10846 | } while (lnum > 0); |
| 10847 | |
| 10848 | /* 'numberwidth' gives the minimal width plus one */ |
| 10849 | if (n < wp->w_p_nuw - 1) |
| 10850 | n = wp->w_p_nuw - 1; |
| 10851 | |
| 10852 | wp->w_nrwidth_width = n; |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10853 | wp->w_nuw_cached = wp->w_p_nuw; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10854 | return n; |
| 10855 | } |
| 10856 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10857 | |
| 10858 | /* |
| 10859 | * Return the current cursor column. This is the actual position on the |
| 10860 | * screen. First column is 0. |
| 10861 | */ |
| 10862 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10863 | screen_screencol(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10864 | { |
| 10865 | return screen_cur_col; |
| 10866 | } |
| 10867 | |
| 10868 | /* |
| 10869 | * Return the current cursor row. This is the actual position on the screen. |
| 10870 | * First row is 0. |
| 10871 | */ |
| 10872 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10873 | screen_screenrow(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10874 | { |
| 10875 | return screen_cur_row; |
| 10876 | } |