Mercurial > vim
annotate src/screen.c @ 5096:a6ddcab6a240 v7.3.1291
updated for version 7.3.1291
Problem: Compiler warnings for uninitialized variables. (Tony Mechelynck)
Solution: Initialize the variables.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 03 Jul 2013 13:29:58 +0200 |
parents | 8b7baf39a345 |
children | 71859e71b1f9 |
rev | line source |
---|---|
7 | 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 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
28 * character without composing chars ScreenLinesUC[] will be 0 and |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
29 * ScreenLinesC[][] is not used. When the character occupies two display |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
30 * cells the next byte in ScreenLines[] is 0. |
714 | 31 * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
32 * (drawn on top of the first character). There is 0 after the last one used. |
7 | 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 | |
1213 | 41 * called from other places when an immediate screen update is needed. |
7 | 42 * |
43 * The part of the buffer that is displayed in a window is set with: | |
44 * - w_topline (first buffer line in window) | |
45 * - w_topfill (filler line above the first line) | |
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 * | |
743 | 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 * | |
7 | 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 | |
3586 | 92 #define MB_FILLER_CHAR '<' /* character used when a double-width character |
93 * doesn't fit. */ | |
94 | |
7 | 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 | |
107 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
108 #endif | |
109 | |
110 #ifdef FEAT_FOLDING | |
111 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
112 #endif | |
113 | |
114 /* | |
115 * Buffer for one screen line (characters and attributes). | |
116 */ | |
117 static schar_T *current_ScreenLine; | |
118 | |
119 static void win_update __ARGS((win_T *wp)); | |
534 | 120 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 121 #ifdef FEAT_FOLDING |
122 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
123 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
124 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
125 #endif | |
625 | 126 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 127 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
128 #ifdef FEAT_RIGHTLEFT | |
129 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
131 #else | |
132 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
133 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
134 #endif | |
135 #ifdef FEAT_VERTSPLIT | |
136 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
137 #endif | |
680 | 138 #ifdef FEAT_STL_OPT |
1983 | 139 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 140 #endif |
7 | 141 #ifdef FEAT_SEARCH_EXTRA |
1326 | 142 #define SEARCH_HL_PRIORITY 0 |
7 | 143 static void start_search_hl __ARGS((void)); |
144 static void end_search_hl __ARGS((void)); | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
145 static void init_search_hl __ARGS((win_T *wp)); |
7 | 146 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
147 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
148 #endif | |
149 static void screen_start_highlight __ARGS((int attr)); | |
150 static void screen_char __ARGS((unsigned off, int row, int col)); | |
151 #ifdef FEAT_MBYTE | |
152 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
153 #endif | |
154 static void screenclear2 __ARGS((void)); | |
155 static void lineclear __ARGS((unsigned off, int width)); | |
156 static void lineinvalid __ARGS((unsigned off, int width)); | |
157 #ifdef FEAT_VERTSPLIT | |
158 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
159 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
160 #endif | |
161 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
162 static void win_rest_invalid __ARGS((win_T *wp)); | |
163 static void msg_pos_mode __ARGS((void)); | |
667 | 164 #if defined(FEAT_WINDOWS) |
677 | 165 static void draw_tabline __ARGS((void)); |
667 | 166 #endif |
7 | 167 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
168 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
169 #endif | |
170 #ifdef FEAT_VERTSPLIT | |
171 static int fillchar_vsep __ARGS((int *attr)); | |
172 #endif | |
173 #ifdef FEAT_STL_OPT | |
574 | 174 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 175 #endif |
176 #ifdef FEAT_CMDL_INFO | |
177 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
178 #endif | |
179 | |
180 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
181 /* Ugly global: overrule attribute used by screen_char() */ | |
182 static int screen_char_attr = 0; | |
183 #endif | |
184 | |
185 /* | |
186 * Redraw the current window later, with update_screen(type). | |
187 * Set must_redraw only if not already set to a higher value. | |
188 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
189 */ | |
190 void | |
191 redraw_later(type) | |
192 int type; | |
193 { | |
194 redraw_win_later(curwin, type); | |
195 } | |
196 | |
197 void | |
198 redraw_win_later(wp, type) | |
199 win_T *wp; | |
200 int type; | |
201 { | |
202 if (wp->w_redr_type < type) | |
203 { | |
204 wp->w_redr_type = type; | |
205 if (type >= NOT_VALID) | |
206 wp->w_lines_valid = 0; | |
207 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
208 must_redraw = type; | |
209 } | |
210 } | |
211 | |
212 /* | |
213 * Force a complete redraw later. Also resets the highlighting. To be used | |
214 * after executing a shell command that messes up the screen. | |
215 */ | |
216 void | |
217 redraw_later_clear() | |
218 { | |
219 redraw_all_later(CLEAR); | |
826 | 220 #ifdef FEAT_GUI |
221 if (gui.in_use) | |
222 /* Use a code that will reset gui.highlight_mask in | |
223 * gui_stop_highlight(). */ | |
224 screen_attr = HL_ALL + 1; | |
225 else | |
226 #endif | |
227 /* Use attributes that is very unlikely to appear in text. */ | |
228 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 229 } |
230 | |
231 /* | |
232 * Mark all windows to be redrawn later. | |
233 */ | |
234 void | |
235 redraw_all_later(type) | |
236 int type; | |
237 { | |
238 win_T *wp; | |
239 | |
240 FOR_ALL_WINDOWS(wp) | |
241 { | |
242 redraw_win_later(wp, type); | |
243 } | |
244 } | |
245 | |
246 /* | |
301 | 247 * Mark all windows that are editing the current buffer to be updated later. |
7 | 248 */ |
249 void | |
250 redraw_curbuf_later(type) | |
251 int type; | |
252 { | |
253 redraw_buf_later(curbuf, type); | |
254 } | |
255 | |
256 void | |
257 redraw_buf_later(buf, type) | |
258 buf_T *buf; | |
259 int type; | |
260 { | |
261 win_T *wp; | |
262 | |
263 FOR_ALL_WINDOWS(wp) | |
264 { | |
265 if (wp->w_buffer == buf) | |
266 redraw_win_later(wp, type); | |
267 } | |
268 } | |
269 | |
270 /* | |
5090
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
271 * Redraw as soon as possible. When the command line is not scrolled redraw |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
272 * right away and restore what was on the command line. |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
273 * Return a code indicating what happened. |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
274 */ |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
275 int |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
276 redraw_asap(type) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
277 int type; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
278 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
279 int rows; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
280 int r; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
281 int ret = 0; |
5096
a6ddcab6a240
updated for version 7.3.1291
Bram Moolenaar <bram@vim.org>
parents:
5090
diff
changeset
|
282 schar_T *screenline; /* copy from ScreenLines[] */ |
a6ddcab6a240
updated for version 7.3.1291
Bram Moolenaar <bram@vim.org>
parents:
5090
diff
changeset
|
283 sattr_T *screenattr; /* copy from ScreenAttrs[] */ |
5090
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
284 #ifdef FEAT_MBYTE |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
285 int i; |
5096
a6ddcab6a240
updated for version 7.3.1291
Bram Moolenaar <bram@vim.org>
parents:
5090
diff
changeset
|
286 u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */ |
5090
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
287 u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */ |
5096
a6ddcab6a240
updated for version 7.3.1291
Bram Moolenaar <bram@vim.org>
parents:
5090
diff
changeset
|
288 schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */ |
5090
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
289 #endif |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
290 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
291 redraw_later(type); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
292 if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY)) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
293 return ret; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
294 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
295 /* Allocate space to save the text displayed in the command line area. */ |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
296 rows = Rows - cmdline_row; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
297 screenline = (schar_T *)lalloc( |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
298 (long_u)(rows * Columns * sizeof(schar_T)), FALSE); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
299 screenattr = (sattr_T *)lalloc( |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
300 (long_u)(rows * Columns * sizeof(sattr_T)), FALSE); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
301 if (screenline == NULL || screenattr == NULL) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
302 ret = 2; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
303 #ifdef FEAT_MBYTE |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
304 if (enc_utf8) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
305 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
306 screenlineUC = (u8char_T *)lalloc( |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
307 (long_u)(rows * Columns * sizeof(u8char_T)), FALSE); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
308 if (screenlineUC == NULL) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
309 ret = 2; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
310 for (i = 0; i < p_mco; ++i) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
311 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
312 screenlineC[i] = (u8char_T *)lalloc( |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
313 (long_u)(rows * Columns * sizeof(u8char_T)), FALSE); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
314 if (screenlineC[i] == NULL) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
315 ret = 2; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
316 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
317 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
318 if (enc_dbcs == DBCS_JPNU) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
319 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
320 screenline2 = (schar_T *)lalloc( |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
321 (long_u)(rows * Columns * sizeof(schar_T)), FALSE); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
322 if (screenline2 == NULL) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
323 ret = 2; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
324 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
325 #endif |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
326 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
327 if (ret != 2) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
328 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
329 /* Save the text displayed in the command line area. */ |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
330 for (r = 0; r < rows; ++r) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
331 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
332 mch_memmove(screenline + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
333 ScreenLines + LineOffset[cmdline_row + r], |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
334 (size_t)Columns * sizeof(schar_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
335 mch_memmove(screenattr + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
336 ScreenAttrs + LineOffset[cmdline_row + r], |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
337 (size_t)Columns * sizeof(sattr_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
338 #ifdef FEAT_MBYTE |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
339 if (enc_utf8) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
340 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
341 mch_memmove(screenlineUC + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
342 ScreenLinesUC + LineOffset[cmdline_row + r], |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
343 (size_t)Columns * sizeof(u8char_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
344 for (i = 0; i < p_mco; ++i) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
345 mch_memmove(screenlineC[i] + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
346 ScreenLinesC[r] + LineOffset[cmdline_row + r], |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
347 (size_t)Columns * sizeof(u8char_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
348 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
349 if (enc_dbcs == DBCS_JPNU) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
350 mch_memmove(screenline2 + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
351 ScreenLines2 + LineOffset[cmdline_row + r], |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
352 (size_t)Columns * sizeof(schar_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
353 #endif |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
354 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
355 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
356 update_screen(0); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
357 ret = 3; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
358 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
359 if (must_redraw == 0) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
360 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
361 int off = (int)(current_ScreenLine - ScreenLines); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
362 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
363 /* Restore the text displayed in the command line area. */ |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
364 for (r = 0; r < rows; ++r) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
365 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
366 mch_memmove(current_ScreenLine, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
367 screenline + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
368 (size_t)Columns * sizeof(schar_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
369 mch_memmove(ScreenAttrs + off, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
370 screenattr + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
371 (size_t)Columns * sizeof(sattr_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
372 #ifdef FEAT_MBYTE |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
373 if (enc_utf8) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
374 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
375 mch_memmove(ScreenLinesUC + off, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
376 screenlineUC + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
377 (size_t)Columns * sizeof(u8char_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
378 for (i = 0; i < p_mco; ++i) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
379 mch_memmove(ScreenLinesC[i] + off, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
380 screenlineC[i] + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
381 (size_t)Columns * sizeof(u8char_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
382 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
383 if (enc_dbcs == DBCS_JPNU) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
384 mch_memmove(ScreenLines2 + off, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
385 screenline2 + r * Columns, |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
386 (size_t)Columns * sizeof(schar_T)); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
387 #endif |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
388 SCREEN_LINE(cmdline_row + r, 0, Columns, Columns, FALSE); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
389 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
390 ret = 4; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
391 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
392 setcursor(); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
393 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
394 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
395 vim_free(screenline); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
396 vim_free(screenattr); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
397 #ifdef FEAT_MBYTE |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
398 if (enc_utf8) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
399 { |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
400 vim_free(screenlineUC); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
401 for (i = 0; i < p_mco; ++i) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
402 vim_free(screenlineC[i]); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
403 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
404 if (enc_dbcs == DBCS_JPNU) |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
405 vim_free(screenline2); |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
406 #endif |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
407 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
408 return ret; |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
409 } |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
410 |
8b7baf39a345
updated for version 7.3.1288
Bram Moolenaar <bram@vim.org>
parents:
5078
diff
changeset
|
411 /* |
7 | 412 * Changed something in the current window, at buffer line "lnum", that |
413 * requires that line and possibly other lines to be redrawn. | |
414 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
415 * Used to remove the "$" from a change command. | |
416 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
417 * may become invalid and the whole window will have to be redrawn. | |
418 */ | |
419 void | |
420 redrawWinline(lnum, invalid) | |
421 linenr_T lnum; | |
1883 | 422 int invalid UNUSED; /* window line height is invalid now */ |
7 | 423 { |
424 #ifdef FEAT_FOLDING | |
425 int i; | |
426 #endif | |
427 | |
428 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
429 curwin->w_redraw_top = lnum; | |
430 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
431 curwin->w_redraw_bot = lnum; | |
432 redraw_later(VALID); | |
433 | |
434 #ifdef FEAT_FOLDING | |
435 if (invalid) | |
436 { | |
437 /* A w_lines[] entry for this lnum has become invalid. */ | |
438 i = find_wl_entry(curwin, lnum); | |
439 if (i >= 0) | |
440 curwin->w_lines[i].wl_valid = FALSE; | |
441 } | |
442 #endif | |
443 } | |
444 | |
2255 | 445 #if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \ |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
446 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 447 /* |
448 * update all windows that are editing the current buffer | |
449 */ | |
450 void | |
451 update_curbuf(type) | |
452 int type; | |
453 { | |
454 redraw_curbuf_later(type); | |
455 update_screen(type); | |
456 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
457 #endif |
7 | 458 |
459 /* | |
460 * update_screen() | |
461 * | |
462 * Based on the current value of curwin->w_topline, transfer a screenfull | |
463 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
464 */ | |
465 void | |
466 update_screen(type) | |
467 int type; | |
468 { | |
469 win_T *wp; | |
470 static int did_intro = FALSE; | |
471 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
472 int did_one; | |
473 #endif | |
474 | |
2008 | 475 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 476 if (!screen_valid(TRUE)) |
477 return; | |
478 | |
479 if (must_redraw) | |
480 { | |
481 if (type < must_redraw) /* use maximal type */ | |
482 type = must_redraw; | |
1331 | 483 |
484 /* must_redraw is reset here, so that when we run into some weird | |
485 * reason to redraw while busy redrawing (e.g., asynchronous | |
486 * scrolling), or update_topline() in win_update() will cause a | |
487 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 488 must_redraw = 0; |
489 } | |
490 | |
491 /* Need to update w_lines[]. */ | |
492 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
493 type = NOT_VALID; | |
494 | |
2008 | 495 /* Postpone the redrawing when it's not needed and when being called |
496 * recursively. */ | |
497 if (!redrawing() || updating_screen) | |
7 | 498 { |
499 redraw_later(type); /* remember type for next time */ | |
500 must_redraw = type; | |
501 if (type > INVERTED_ALL) | |
502 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
503 return; | |
504 } | |
505 | |
506 updating_screen = TRUE; | |
507 #ifdef FEAT_SYN_HL | |
508 ++display_tick; /* let syntax code know we're in a next round of | |
509 * display updating */ | |
510 #endif | |
511 | |
512 /* | |
513 * if the screen was scrolled up when displaying a message, scroll it down | |
514 */ | |
515 if (msg_scrolled) | |
516 { | |
517 clear_cmdline = TRUE; | |
518 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
519 type = CLEAR; | |
520 else if (type != CLEAR) | |
521 { | |
522 check_for_delay(FALSE); | |
523 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
524 type = CLEAR; | |
525 FOR_ALL_WINDOWS(wp) | |
526 { | |
527 if (W_WINROW(wp) < msg_scrolled) | |
528 { | |
529 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
530 && wp->w_redr_type < REDRAW_TOP | |
531 && wp->w_lines_valid > 0 | |
532 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
533 { | |
534 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
535 wp->w_redr_type = REDRAW_TOP; | |
536 } | |
537 else | |
538 { | |
539 wp->w_redr_type = NOT_VALID; | |
540 #ifdef FEAT_WINDOWS | |
541 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
542 <= msg_scrolled) | |
543 wp->w_redr_status = TRUE; | |
544 #endif | |
545 } | |
546 } | |
547 } | |
548 redraw_cmdline = TRUE; | |
667 | 549 #ifdef FEAT_WINDOWS |
673 | 550 redraw_tabline = TRUE; |
667 | 551 #endif |
7 | 552 } |
553 msg_scrolled = 0; | |
554 need_wait_return = FALSE; | |
555 } | |
556 | |
557 /* reset cmdline_row now (may have been changed temporarily) */ | |
558 compute_cmdrow(); | |
559 | |
560 /* Check for changed highlighting */ | |
561 if (need_highlight_changed) | |
562 highlight_changed(); | |
563 | |
564 if (type == CLEAR) /* first clear screen */ | |
565 { | |
566 screenclear(); /* will reset clear_cmdline */ | |
567 type = NOT_VALID; | |
568 } | |
569 | |
570 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
571 check_for_delay(FALSE); | |
572 | |
13 | 573 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
574 /* Force redraw when width of 'number' or 'relativenumber' column |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
575 * changes. */ |
13 | 576 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
577 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
578 ? number_width(curwin) : 0)) |
13 | 579 curwin->w_redr_type = NOT_VALID; |
580 #endif | |
581 | |
7 | 582 /* |
583 * Only start redrawing if there is really something to do. | |
584 */ | |
585 if (type == INVERTED) | |
586 update_curswant(); | |
587 if (curwin->w_redr_type < type | |
588 && !((type == VALID | |
589 && curwin->w_lines[0].wl_valid | |
590 #ifdef FEAT_DIFF | |
591 && curwin->w_topfill == curwin->w_old_topfill | |
592 && curwin->w_botfill == curwin->w_old_botfill | |
593 #endif | |
594 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
595 #ifdef FEAT_VISUAL | |
596 || (type == INVERTED | |
1043 | 597 && VIsual_active |
7 | 598 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
599 && curwin->w_old_visual_mode == VIsual_mode | |
600 && (curwin->w_valid & VALID_VIRTCOL) | |
601 && curwin->w_old_curswant == curwin->w_curswant) | |
602 #endif | |
603 )) | |
604 curwin->w_redr_type = type; | |
605 | |
849 | 606 #ifdef FEAT_WINDOWS |
607 /* Redraw the tab pages line if needed. */ | |
608 if (redraw_tabline || type >= NOT_VALID) | |
609 draw_tabline(); | |
610 #endif | |
611 | |
7 | 612 #ifdef FEAT_SYN_HL |
613 /* | |
614 * Correct stored syntax highlighting info for changes in each displayed | |
615 * buffer. Each buffer must only be done once. | |
616 */ | |
617 FOR_ALL_WINDOWS(wp) | |
618 { | |
619 if (wp->w_buffer->b_mod_set) | |
620 { | |
621 # ifdef FEAT_WINDOWS | |
622 win_T *wwp; | |
623 | |
624 /* Check if we already did this buffer. */ | |
625 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
626 if (wwp->w_buffer == wp->w_buffer) | |
627 break; | |
628 # endif | |
629 if ( | |
630 # ifdef FEAT_WINDOWS | |
631 wwp == wp && | |
632 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
633 syntax_present(wp)) |
7 | 634 syn_stack_apply_changes(wp->w_buffer); |
635 } | |
636 } | |
637 #endif | |
638 | |
639 /* | |
640 * Go from top to bottom through the windows, redrawing the ones that need | |
641 * it. | |
642 */ | |
643 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
644 did_one = FALSE; | |
645 #endif | |
646 #ifdef FEAT_SEARCH_EXTRA | |
647 search_hl.rm.regprog = NULL; | |
648 #endif | |
649 FOR_ALL_WINDOWS(wp) | |
650 { | |
651 if (wp->w_redr_type != 0) | |
652 { | |
653 cursor_off(); | |
654 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
655 if (!did_one) | |
656 { | |
657 did_one = TRUE; | |
658 # ifdef FEAT_SEARCH_EXTRA | |
659 start_search_hl(); | |
660 # endif | |
661 # ifdef FEAT_CLIPBOARD | |
662 /* When Visual area changed, may have to update selection. */ | |
3674 | 663 if (clip_star.available && clip_isautosel_star()) |
664 clip_update_selection(&clip_star); | |
665 if (clip_plus.available && clip_isautosel_plus()) | |
666 clip_update_selection(&clip_plus); | |
7 | 667 # endif |
668 #ifdef FEAT_GUI | |
669 /* Remove the cursor before starting to do anything, because | |
670 * scrolling may make it difficult to redraw the text under | |
671 * it. */ | |
672 if (gui.in_use) | |
673 gui_undraw_cursor(); | |
674 #endif | |
675 } | |
676 #endif | |
677 win_update(wp); | |
678 } | |
679 | |
680 #ifdef FEAT_WINDOWS | |
681 /* redraw status line after the window to minimize cursor movement */ | |
682 if (wp->w_redr_status) | |
683 { | |
684 cursor_off(); | |
685 win_redr_status(wp); | |
686 } | |
687 #endif | |
688 } | |
689 #if defined(FEAT_SEARCH_EXTRA) | |
690 end_search_hl(); | |
691 #endif | |
4107 | 692 #ifdef FEAT_INS_EXPAND |
693 /* May need to redraw the popup menu. */ | |
694 if (pum_visible()) | |
695 pum_redraw(); | |
696 #endif | |
7 | 697 |
698 #ifdef FEAT_WINDOWS | |
699 /* Reset b_mod_set flags. Going through all windows is probably faster | |
700 * than going through all buffers (there could be many buffers). */ | |
701 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
702 wp->w_buffer->b_mod_set = FALSE; | |
703 #else | |
704 curbuf->b_mod_set = FALSE; | |
705 #endif | |
706 | |
707 updating_screen = FALSE; | |
708 #ifdef FEAT_GUI | |
709 gui_may_resize_shell(); | |
710 #endif | |
711 | |
712 /* Clear or redraw the command line. Done last, because scrolling may | |
713 * mess up the command line. */ | |
714 if (clear_cmdline || redraw_cmdline) | |
715 showmode(); | |
716 | |
717 /* May put up an introductory message when not editing a file */ | |
718 if (!did_intro && bufempty() | |
719 && curbuf->b_fname == NULL | |
720 #ifdef FEAT_WINDOWS | |
721 && firstwin->w_next == NULL | |
722 #endif | |
723 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
724 intro_message(FALSE); | |
725 did_intro = TRUE; | |
726 | |
727 #ifdef FEAT_GUI | |
728 /* Redraw the cursor and update the scrollbars when all screen updating is | |
729 * done. */ | |
730 if (gui.in_use) | |
731 { | |
732 out_flush(); /* required before updating the cursor */ | |
733 if (did_one) | |
734 gui_update_cursor(FALSE, FALSE); | |
735 gui_update_scrollbars(FALSE); | |
736 } | |
737 #endif | |
738 } | |
739 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
740 #if defined(FEAT_CONCEAL) || defined(PROTO) |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
741 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
742 * Return TRUE if the cursor line in window "wp" may be concealed, according |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
743 * to the 'concealcursor' option. |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
744 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
745 int |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
746 conceal_cursor_line(wp) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
747 win_T *wp; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
748 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
749 int c; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
750 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
751 if (*wp->w_p_cocu == NUL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
752 return FALSE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
753 if (get_real_state() & VISUAL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
754 c = 'v'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
755 else if (State & INSERT) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
756 c = 'i'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
757 else if (State & NORMAL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
758 c = 'n'; |
2382
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
759 else if (State & CMDLINE) |
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
760 c = 'c'; |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
761 else |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
762 return FALSE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
763 return vim_strchr(wp->w_p_cocu, c) != NULL; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
764 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
765 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
766 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
767 * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
768 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
769 void |
2428
33148c37f3c9
Changes for VMS. Mostly by Zoltan Arpadffy.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
770 conceal_check_cursur_line() |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
771 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
772 if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
773 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
774 need_cursor_line_redraw = TRUE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
775 /* Need to recompute cursor column, e.g., when starting Visual mode |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
776 * without concealing. */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
777 curs_columns(TRUE); |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
778 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
779 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
780 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
781 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
782 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
783 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
784 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
785 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
786 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
787 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
788 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
789 if (lnum >= wp->w_topline && lnum < wp->w_botline |
2269
fb627e94e6c6
Couple of small fixes for conceal feature. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
790 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
791 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
792 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
793 /* Remove the cursor before starting to do anything, because scrolling |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
794 * may make it difficult to redraw the text under it. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
795 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
796 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
797 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
798 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
799 for (j = 0; j < wp->w_lines_valid; ++j) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
800 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
801 if (lnum == wp->w_lines[j].wl_lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
802 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
803 screen_start(); /* not sure of screen cursor */ |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
804 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
805 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
806 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
807 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
808 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
809 win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
810 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
811 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
812 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
813 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
814 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
815 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
816 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
817 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
818 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
819 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
820 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
821 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
822 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
823 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
824 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
825 } |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
826 need_cursor_line_redraw = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
827 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
828 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
829 |
7 | 830 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
831 static void update_prepare __ARGS((void)); | |
832 static void update_finish __ARGS((void)); | |
833 | |
834 /* | |
835 * Prepare for updating one or more windows. | |
2008 | 836 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 837 */ |
838 static void | |
839 update_prepare() | |
840 { | |
841 cursor_off(); | |
842 updating_screen = TRUE; | |
843 #ifdef FEAT_GUI | |
844 /* Remove the cursor before starting to do anything, because scrolling may | |
845 * make it difficult to redraw the text under it. */ | |
846 if (gui.in_use) | |
847 gui_undraw_cursor(); | |
848 #endif | |
849 #ifdef FEAT_SEARCH_EXTRA | |
850 start_search_hl(); | |
851 #endif | |
852 } | |
853 | |
854 /* | |
855 * Finish updating one or more windows. | |
856 */ | |
857 static void | |
858 update_finish() | |
859 { | |
860 if (redraw_cmdline) | |
861 showmode(); | |
862 | |
863 # ifdef FEAT_SEARCH_EXTRA | |
864 end_search_hl(); | |
865 # endif | |
866 | |
867 updating_screen = FALSE; | |
868 | |
869 # ifdef FEAT_GUI | |
870 gui_may_resize_shell(); | |
871 | |
872 /* Redraw the cursor and update the scrollbars when all screen updating is | |
873 * done. */ | |
874 if (gui.in_use) | |
875 { | |
876 out_flush(); /* required before updating the cursor */ | |
877 gui_update_cursor(FALSE, FALSE); | |
878 gui_update_scrollbars(FALSE); | |
879 } | |
880 # endif | |
881 } | |
882 #endif | |
883 | |
884 #if defined(FEAT_SIGNS) || defined(PROTO) | |
885 void | |
886 update_debug_sign(buf, lnum) | |
887 buf_T *buf; | |
888 linenr_T lnum; | |
889 { | |
890 win_T *wp; | |
891 int doit = FALSE; | |
892 | |
893 # ifdef FEAT_FOLDING | |
894 win_foldinfo.fi_level = 0; | |
895 # endif | |
896 | |
897 /* update/delete a specific mark */ | |
898 FOR_ALL_WINDOWS(wp) | |
899 { | |
900 if (buf != NULL && lnum > 0) | |
901 { | |
902 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
903 && lnum < wp->w_botline) | |
904 { | |
905 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
906 wp->w_redraw_top = lnum; | |
907 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
908 wp->w_redraw_bot = lnum; | |
909 redraw_win_later(wp, VALID); | |
910 } | |
911 } | |
912 else | |
913 redraw_win_later(wp, VALID); | |
914 if (wp->w_redr_type != 0) | |
915 doit = TRUE; | |
916 } | |
917 | |
3250 | 918 /* Return when there is nothing to do, screen updating is already |
919 * happening (recursive call) or still starting up. */ | |
920 if (!doit || updating_screen | |
921 #ifdef FEAT_GUI | |
922 || gui.starting | |
923 #endif | |
924 || starting) | |
7 | 925 return; |
926 | |
927 /* update all windows that need updating */ | |
928 update_prepare(); | |
929 | |
930 # ifdef FEAT_WINDOWS | |
931 for (wp = firstwin; wp; wp = wp->w_next) | |
932 { | |
933 if (wp->w_redr_type != 0) | |
934 win_update(wp); | |
935 if (wp->w_redr_status) | |
936 win_redr_status(wp); | |
937 } | |
938 # else | |
939 if (curwin->w_redr_type != 0) | |
940 win_update(curwin); | |
941 # endif | |
942 | |
943 update_finish(); | |
944 } | |
945 #endif | |
946 | |
947 | |
948 #if defined(FEAT_GUI) || defined(PROTO) | |
949 /* | |
950 * Update a single window, its status line and maybe the command line msg. | |
951 * Used for the GUI scrollbar. | |
952 */ | |
953 void | |
954 updateWindow(wp) | |
955 win_T *wp; | |
956 { | |
2008 | 957 /* return if already busy updating */ |
958 if (updating_screen) | |
959 return; | |
960 | |
7 | 961 update_prepare(); |
962 | |
963 #ifdef FEAT_CLIPBOARD | |
964 /* When Visual area changed, may have to update selection. */ | |
3674 | 965 if (clip_star.available && clip_isautosel_star()) |
966 clip_update_selection(&clip_star); | |
967 if (clip_plus.available && clip_isautosel_plus()) | |
968 clip_update_selection(&clip_plus); | |
7 | 969 #endif |
670 | 970 |
7 | 971 win_update(wp); |
670 | 972 |
7 | 973 #ifdef FEAT_WINDOWS |
670 | 974 /* When the screen was cleared redraw the tab pages line. */ |
673 | 975 if (redraw_tabline) |
677 | 976 draw_tabline(); |
670 | 977 |
7 | 978 if (wp->w_redr_status |
979 # ifdef FEAT_CMDL_INFO | |
980 || p_ru | |
981 # endif | |
982 # ifdef FEAT_STL_OPT | |
40 | 983 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 984 # endif |
985 ) | |
986 win_redr_status(wp); | |
987 #endif | |
988 | |
989 update_finish(); | |
990 } | |
991 #endif | |
992 | |
993 /* | |
994 * Update a single window. | |
995 * | |
996 * This may cause the windows below it also to be redrawn (when clearing the | |
997 * screen or scrolling lines). | |
998 * | |
999 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
1000 * implies the one below it. | |
1001 * NOT_VALID redraw the whole window | |
743 | 1002 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 1003 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
1004 * INVERTED redraw the changed part of the Visual area | |
1005 * INVERTED_ALL redraw the whole Visual area | |
1006 * VALID 1. scroll up/down to adjust for a changed w_topline | |
1007 * 2. update lines at the top when scrolled down | |
1008 * 3. redraw changed text: | |
301 | 1009 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 1010 * b_mod_top and b_mod_bot. |
1011 * - if wp->w_redraw_top non-zero, redraw lines between | |
1012 * wp->w_redraw_top and wp->w_redr_bot. | |
1013 * - continue redrawing when syntax status is invalid. | |
1014 * 4. if scrolled up, update lines at the bottom. | |
1015 * This results in three areas that may need updating: | |
1016 * top: from first row to top_end (when scrolled down) | |
1017 * mid: from mid_start to mid_end (update inversion or changed text) | |
1018 * bot: from bot_start to last row (when scrolled up) | |
1019 */ | |
1020 static void | |
1021 win_update(wp) | |
1022 win_T *wp; | |
1023 { | |
1024 buf_T *buf = wp->w_buffer; | |
1025 int type; | |
1026 int top_end = 0; /* Below last row of the top area that needs | |
1027 updating. 0 when no top area updating. */ | |
1028 int mid_start = 999;/* first row of the mid area that needs | |
1029 updating. 999 when no mid area updating. */ | |
1030 int mid_end = 0; /* Below last row of the mid area that needs | |
1031 updating. 0 when no mid area updating. */ | |
1032 int bot_start = 999;/* first row of the bot area that needs | |
1033 updating. 999 when no bot area updating */ | |
1034 #ifdef FEAT_VISUAL | |
1035 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
1036 w_topline got smaller a bit */ | |
1037 #endif | |
1038 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 1039 matchitem_T *cur; /* points to the match list */ |
7 | 1040 int top_to_mod = FALSE; /* redraw above mod_top */ |
1041 #endif | |
1042 | |
1043 int row; /* current window row to display */ | |
1044 linenr_T lnum; /* current buffer lnum to display */ | |
1045 int idx; /* current index in w_lines[] */ | |
1046 int srow; /* starting row of the current line */ | |
1047 | |
1048 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
1049 int didline = FALSE; /* if TRUE, we finished the last line */ | |
1050 int i; | |
1051 long j; | |
1052 static int recursive = FALSE; /* being called recursively */ | |
1053 int old_botline = wp->w_botline; | |
1054 #ifdef FEAT_FOLDING | |
1055 long fold_count; | |
1056 #endif | |
1057 #ifdef FEAT_SYN_HL | |
1058 /* remember what happened to the previous line, to know if | |
1059 * check_visual_highlight() can be used */ | |
1060 #define DID_NONE 1 /* didn't update a line */ | |
1061 #define DID_LINE 2 /* updated a normal line */ | |
1062 #define DID_FOLD 3 /* updated a folded line */ | |
1063 int did_update = DID_NONE; | |
1064 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
1065 #endif | |
1066 linenr_T mod_top = 0; | |
1067 linenr_T mod_bot = 0; | |
1068 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1069 int save_got_int; | |
1070 #endif | |
1071 | |
1072 type = wp->w_redr_type; | |
1073 | |
1074 if (type == NOT_VALID) | |
1075 { | |
1076 #ifdef FEAT_WINDOWS | |
1077 wp->w_redr_status = TRUE; | |
1078 #endif | |
1079 wp->w_lines_valid = 0; | |
1080 } | |
1081 | |
1082 /* Window is zero-height: nothing to draw. */ | |
1083 if (wp->w_height == 0) | |
1084 { | |
1085 wp->w_redr_type = 0; | |
1086 return; | |
1087 } | |
1088 | |
1089 #ifdef FEAT_VERTSPLIT | |
1090 /* Window is zero-width: Only need to draw the separator. */ | |
1091 if (wp->w_width == 0) | |
1092 { | |
1093 /* draw the vertical separator right of this window */ | |
1094 draw_vsep_win(wp, 0); | |
1095 wp->w_redr_type = 0; | |
1096 return; | |
1097 } | |
1098 #endif | |
1099 | |
1100 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
1101 init_search_hl(wp); |
7 | 1102 #endif |
1103 | |
13 | 1104 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
1105 /* Force redraw when width of 'number' or 'relativenumber' column |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
1106 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
1107 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 1108 if (wp->w_nrwidth != i) |
13 | 1109 { |
1110 type = NOT_VALID; | |
677 | 1111 wp->w_nrwidth = i; |
13 | 1112 } |
1113 else | |
1114 #endif | |
1115 | |
7 | 1116 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
1117 { | |
1118 /* | |
1119 * When there are both inserted/deleted lines and specific lines to be | |
1120 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
1121 * everything (only happens when redrawing is off for while). | |
1122 */ | |
1123 type = NOT_VALID; | |
1124 } | |
1125 else | |
1126 { | |
1127 /* | |
1128 * Set mod_top to the first line that needs displaying because of | |
1129 * changes. Set mod_bot to the first line after the changes. | |
1130 */ | |
1131 mod_top = wp->w_redraw_top; | |
1132 if (wp->w_redraw_bot != 0) | |
1133 mod_bot = wp->w_redraw_bot + 1; | |
1134 else | |
1135 mod_bot = 0; | |
1136 wp->w_redraw_top = 0; /* reset for next time */ | |
1137 wp->w_redraw_bot = 0; | |
1138 if (buf->b_mod_set) | |
1139 { | |
1140 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
1141 { | |
1142 mod_top = buf->b_mod_top; | |
1143 #ifdef FEAT_SYN_HL | |
1144 /* Need to redraw lines above the change that may be included | |
1145 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1146 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1147 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1148 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 1149 if (mod_top < 1) |
1150 mod_top = 1; | |
1151 } | |
1152 #endif | |
1153 } | |
1154 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
1155 mod_bot = buf->b_mod_bot; | |
1156 | |
1157 #ifdef FEAT_SEARCH_EXTRA | |
1158 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
1159 * change in one line may make the Search highlighting in a | |
1160 * previous line invalid. Simple solution: redraw all visible | |
1161 * lines above the change. | |
1326 | 1162 * Same for a match pattern. |
7 | 1163 */ |
699 | 1164 if (search_hl.rm.regprog != NULL |
1165 && re_multiline(search_hl.rm.regprog)) | |
7 | 1166 top_to_mod = TRUE; |
699 | 1167 else |
1326 | 1168 { |
1169 cur = wp->w_match_head; | |
1170 while (cur != NULL) | |
1171 { | |
1172 if (cur->match.regprog != NULL | |
1173 && re_multiline(cur->match.regprog)) | |
699 | 1174 { |
1175 top_to_mod = TRUE; | |
1176 break; | |
1177 } | |
1326 | 1178 cur = cur->next; |
1179 } | |
1180 } | |
7 | 1181 #endif |
1182 } | |
1183 #ifdef FEAT_FOLDING | |
1184 if (mod_top != 0 && hasAnyFolding(wp)) | |
1185 { | |
1186 linenr_T lnumt, lnumb; | |
1187 | |
1188 /* | |
1189 * A change in a line can cause lines above it to become folded or | |
1190 * unfolded. Find the top most buffer line that may be affected. | |
1191 * If the line was previously folded and displayed, get the first | |
1192 * line of that fold. If the line is folded now, get the first | |
1193 * folded line. Use the minimum of these two. | |
1194 */ | |
1195 | |
1196 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
1197 * the line below it. If there is no valid entry, use w_topline. | |
1198 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1199 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1200 lnumt = wp->w_topline; | |
1201 lnumb = MAXLNUM; | |
1202 for (i = 0; i < wp->w_lines_valid; ++i) | |
1203 if (wp->w_lines[i].wl_valid) | |
1204 { | |
1205 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1206 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1207 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1208 { | |
1209 lnumb = wp->w_lines[i].wl_lnum; | |
1210 /* When there is a fold column it might need updating | |
1211 * in the next line ("J" just above an open fold). */ | |
1212 if (wp->w_p_fdc > 0) | |
1213 ++lnumb; | |
1214 } | |
1215 } | |
1216 | |
1217 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1218 if (mod_top > lnumt) | |
1219 mod_top = lnumt; | |
1220 | |
1221 /* Now do the same for the bottom line (one above mod_bot). */ | |
1222 --mod_bot; | |
1223 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1224 ++mod_bot; | |
1225 if (mod_bot < lnumb) | |
1226 mod_bot = lnumb; | |
1227 } | |
1228 #endif | |
1229 | |
1230 /* When a change starts above w_topline and the end is below | |
1231 * w_topline, start redrawing at w_topline. | |
36 | 1232 * If the end of the change is above w_topline: do like no change was |
1233 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1234 if (mod_top != 0 && mod_top < wp->w_topline) |
1235 { | |
1236 if (mod_bot > wp->w_topline) | |
1237 mod_top = wp->w_topline; | |
1238 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1239 else if (syntax_present(wp)) |
7 | 1240 top_end = 1; |
1241 #endif | |
1242 } | |
36 | 1243 |
1244 /* When line numbers are displayed need to redraw all lines below | |
1245 * inserted/deleted lines. */ | |
1246 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1247 mod_bot = MAXLNUM; | |
7 | 1248 } |
1249 | |
1250 /* | |
1251 * When only displaying the lines at the top, set top_end. Used when | |
1252 * window has scrolled down for msg_scrolled. | |
1253 */ | |
1254 if (type == REDRAW_TOP) | |
1255 { | |
1256 j = 0; | |
1257 for (i = 0; i < wp->w_lines_valid; ++i) | |
1258 { | |
1259 j += wp->w_lines[i].wl_size; | |
1260 if (j >= wp->w_upd_rows) | |
1261 { | |
1262 top_end = j; | |
1263 break; | |
1264 } | |
1265 } | |
1266 if (top_end == 0) | |
1267 /* not found (cannot happen?): redraw everything */ | |
1268 type = NOT_VALID; | |
1269 else | |
1270 /* top area defined, the rest is VALID */ | |
1271 type = VALID; | |
1272 } | |
1273 | |
1378 | 1274 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1275 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1276 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1277 * called. */ | |
1278 if (screen_cleared) | |
1279 screen_cleared = MAYBE; | |
1280 | |
7 | 1281 /* |
1282 * If there are no changes on the screen that require a complete redraw, | |
1283 * handle three cases: | |
1284 * 1: we are off the top of the screen by a few lines: scroll down | |
1285 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1286 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1287 * w_lines[] that needs updating. | |
1288 */ | |
743 | 1289 if ((type == VALID || type == SOME_VALID |
1290 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1291 #ifdef FEAT_DIFF |
1292 && !wp->w_botfill && !wp->w_old_botfill | |
1293 #endif | |
1294 ) | |
1295 { | |
1296 if (mod_top != 0 && wp->w_topline == mod_top) | |
1297 { | |
1298 /* | |
1299 * w_topline is the first changed line, the scrolling will be done | |
1300 * further down. | |
1301 */ | |
1302 } | |
1303 else if (wp->w_lines[0].wl_valid | |
1304 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1305 #ifdef FEAT_DIFF | |
1306 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1307 && wp->w_topfill > wp->w_old_topfill) | |
1308 #endif | |
1309 )) | |
1310 { | |
1311 /* | |
1312 * New topline is above old topline: May scroll down. | |
1313 */ | |
1314 #ifdef FEAT_FOLDING | |
1315 if (hasAnyFolding(wp)) | |
1316 { | |
1317 linenr_T ln; | |
1318 | |
1319 /* count the number of lines we are off, counting a sequence | |
1320 * of folded lines as one */ | |
1321 j = 0; | |
1322 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1323 { | |
1324 ++j; | |
1325 if (j >= wp->w_height - 2) | |
1326 break; | |
1327 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1328 } | |
1329 } | |
1330 else | |
1331 #endif | |
1332 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1333 if (j < wp->w_height - 2) /* not too far off */ | |
1334 { | |
1335 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1336 #ifdef FEAT_DIFF | |
1337 /* insert extra lines for previously invisible filler lines */ | |
1338 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1339 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1340 - wp->w_old_topfill; | |
1341 #endif | |
1342 if (i < wp->w_height - 2) /* less than a screen off */ | |
1343 { | |
1344 /* | |
1345 * Try to insert the correct number of lines. | |
1346 * If not the last window, delete the lines at the bottom. | |
1347 * win_ins_lines may fail when the terminal can't do it. | |
1348 */ | |
1349 if (i > 0) | |
1350 check_for_delay(FALSE); | |
1351 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1352 { | |
1353 if (wp->w_lines_valid != 0) | |
1354 { | |
1355 /* Need to update rows that are new, stop at the | |
1356 * first one that scrolled down. */ | |
1357 top_end = i; | |
1358 #ifdef FEAT_VISUAL | |
1359 scrolled_down = TRUE; | |
1360 #endif | |
1361 | |
1362 /* Move the entries that were scrolled, disable | |
1363 * the entries for the lines to be redrawn. */ | |
1364 if ((wp->w_lines_valid += j) > wp->w_height) | |
1365 wp->w_lines_valid = wp->w_height; | |
1366 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1367 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1368 while (idx >= 0) | |
1369 wp->w_lines[idx--].wl_valid = FALSE; | |
1370 } | |
1371 } | |
1372 else | |
1373 mid_start = 0; /* redraw all lines */ | |
1374 } | |
1375 else | |
1376 mid_start = 0; /* redraw all lines */ | |
1377 } | |
1378 else | |
1379 mid_start = 0; /* redraw all lines */ | |
1380 } | |
1381 else | |
1382 { | |
1383 /* | |
1384 * New topline is at or below old topline: May scroll up. | |
1385 * When topline didn't change, find first entry in w_lines[] that | |
1386 * needs updating. | |
1387 */ | |
1388 | |
1389 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1390 j = -1; | |
1391 row = 0; | |
1392 for (i = 0; i < wp->w_lines_valid; i++) | |
1393 { | |
1394 if (wp->w_lines[i].wl_valid | |
1395 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1396 { | |
1397 j = i; | |
1398 break; | |
1399 } | |
1400 row += wp->w_lines[i].wl_size; | |
1401 } | |
1402 if (j == -1) | |
1403 { | |
1404 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1405 * lines */ | |
1406 mid_start = 0; | |
1407 } | |
1408 else | |
1409 { | |
1410 /* | |
1411 * Try to delete the correct number of lines. | |
1412 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1413 */ | |
1414 #ifdef FEAT_DIFF | |
1415 /* If the topline didn't change, delete old filler lines, | |
1416 * otherwise delete filler lines of the new topline... */ | |
1417 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1418 row += wp->w_old_topfill; | |
1419 else | |
1420 row += diff_check_fill(wp, wp->w_topline); | |
1421 /* ... but don't delete new filler lines. */ | |
1422 row -= wp->w_topfill; | |
1423 #endif | |
1424 if (row > 0) | |
1425 { | |
1426 check_for_delay(FALSE); | |
1427 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1428 bot_start = wp->w_height - row; | |
1429 else | |
1430 mid_start = 0; /* redraw all lines */ | |
1431 } | |
1432 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1433 { | |
1434 /* | |
1435 * Skip the lines (below the deleted lines) that are still | |
1436 * valid and don't need redrawing. Copy their info | |
1437 * upwards, to compensate for the deleted lines. Set | |
1438 * bot_start to the first row that needs redrawing. | |
1439 */ | |
1440 bot_start = 0; | |
1441 idx = 0; | |
1442 for (;;) | |
1443 { | |
1444 wp->w_lines[idx] = wp->w_lines[j]; | |
1445 /* stop at line that didn't fit, unless it is still | |
1446 * valid (no lines deleted) */ | |
1447 if (row > 0 && bot_start + row | |
1448 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1449 { | |
1450 wp->w_lines_valid = idx + 1; | |
1451 break; | |
1452 } | |
1453 bot_start += wp->w_lines[idx++].wl_size; | |
1454 | |
1455 /* stop at the last valid entry in w_lines[].wl_size */ | |
1456 if (++j >= wp->w_lines_valid) | |
1457 { | |
1458 wp->w_lines_valid = idx; | |
1459 break; | |
1460 } | |
1461 } | |
1462 #ifdef FEAT_DIFF | |
1463 /* Correct the first entry for filler lines at the top | |
1464 * when it won't get updated below. */ | |
1465 if (wp->w_p_diff && bot_start > 0) | |
1466 wp->w_lines[0].wl_size = | |
1467 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1468 + wp->w_topfill; | |
1469 #endif | |
1470 } | |
1471 } | |
1472 } | |
1473 | |
1474 /* When starting redraw in the first line, redraw all lines. When | |
1475 * there is only one window it's probably faster to clear the screen | |
1476 * first. */ | |
1477 if (mid_start == 0) | |
1478 { | |
1479 mid_end = wp->w_height; | |
1480 if (lastwin == firstwin) | |
981 | 1481 { |
1331 | 1482 /* Clear the screen when it was not done by win_del_lines() or |
1483 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1484 * then. */ | |
1485 if (screen_cleared != TRUE) | |
1486 screenclear(); | |
981 | 1487 #ifdef FEAT_WINDOWS |
1488 /* The screen was cleared, redraw the tab pages line. */ | |
1489 if (redraw_tabline) | |
1490 draw_tabline(); | |
1491 #endif | |
1492 } | |
7 | 1493 } |
1331 | 1494 |
1495 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1496 * cleared (only happens for the first window) or when screenclear() | |
1497 * was called directly above, "must_redraw" will have been set to | |
1498 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1499 if (screen_cleared == TRUE) | |
1500 must_redraw = 0; | |
7 | 1501 } |
1502 else | |
1503 { | |
1504 /* Not VALID or INVERTED: redraw all lines. */ | |
1505 mid_start = 0; | |
1506 mid_end = wp->w_height; | |
1507 } | |
1508 | |
743 | 1509 if (type == SOME_VALID) |
1510 { | |
1511 /* SOME_VALID: redraw all lines. */ | |
1512 mid_start = 0; | |
1513 mid_end = wp->w_height; | |
1514 type = NOT_VALID; | |
1515 } | |
1516 | |
7 | 1517 #ifdef FEAT_VISUAL |
1518 /* check if we are updating or removing the inverted part */ | |
1519 if ((VIsual_active && buf == curwin->w_buffer) | |
1520 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1521 { | |
1522 linenr_T from, to; | |
1523 | |
1524 if (VIsual_active) | |
1525 { | |
1526 if (VIsual_active | |
1527 && (VIsual_mode != wp->w_old_visual_mode | |
1528 || type == INVERTED_ALL)) | |
1529 { | |
1530 /* | |
1531 * If the type of Visual selection changed, redraw the whole | |
1532 * selection. Also when the ownership of the X selection is | |
1533 * gained or lost. | |
1534 */ | |
1535 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1536 { | |
1537 from = curwin->w_cursor.lnum; | |
1538 to = VIsual.lnum; | |
1539 } | |
1540 else | |
1541 { | |
1542 from = VIsual.lnum; | |
1543 to = curwin->w_cursor.lnum; | |
1544 } | |
1545 /* redraw more when the cursor moved as well */ | |
1546 if (wp->w_old_cursor_lnum < from) | |
1547 from = wp->w_old_cursor_lnum; | |
1548 if (wp->w_old_cursor_lnum > to) | |
1549 to = wp->w_old_cursor_lnum; | |
1550 if (wp->w_old_visual_lnum < from) | |
1551 from = wp->w_old_visual_lnum; | |
1552 if (wp->w_old_visual_lnum > to) | |
1553 to = wp->w_old_visual_lnum; | |
1554 } | |
1555 else | |
1556 { | |
1557 /* | |
1558 * Find the line numbers that need to be updated: The lines | |
1559 * between the old cursor position and the current cursor | |
1560 * position. Also check if the Visual position changed. | |
1561 */ | |
1562 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1563 { | |
1564 from = curwin->w_cursor.lnum; | |
1565 to = wp->w_old_cursor_lnum; | |
1566 } | |
1567 else | |
1568 { | |
1569 from = wp->w_old_cursor_lnum; | |
1570 to = curwin->w_cursor.lnum; | |
1571 if (from == 0) /* Visual mode just started */ | |
1572 from = to; | |
1573 } | |
1574 | |
422 | 1575 if (VIsual.lnum != wp->w_old_visual_lnum |
1576 || VIsual.col != wp->w_old_visual_col) | |
7 | 1577 { |
1578 if (wp->w_old_visual_lnum < from | |
1579 && wp->w_old_visual_lnum != 0) | |
1580 from = wp->w_old_visual_lnum; | |
1581 if (wp->w_old_visual_lnum > to) | |
1582 to = wp->w_old_visual_lnum; | |
1583 if (VIsual.lnum < from) | |
1584 from = VIsual.lnum; | |
1585 if (VIsual.lnum > to) | |
1586 to = VIsual.lnum; | |
1587 } | |
1588 } | |
1589 | |
1590 /* | |
1591 * If in block mode and changed column or curwin->w_curswant: | |
1592 * update all lines. | |
1593 * First compute the actual start and end column. | |
1594 */ | |
1595 if (VIsual_mode == Ctrl_V) | |
1596 { | |
1597 colnr_T fromc, toc; | |
1598 | |
1599 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1600 ++toc; | |
1601 if (curwin->w_curswant == MAXCOL) | |
1602 toc = MAXCOL; | |
1603 | |
1604 if (fromc != wp->w_old_cursor_fcol | |
1605 || toc != wp->w_old_cursor_lcol) | |
1606 { | |
1607 if (from > VIsual.lnum) | |
1608 from = VIsual.lnum; | |
1609 if (to < VIsual.lnum) | |
1610 to = VIsual.lnum; | |
1611 } | |
1612 wp->w_old_cursor_fcol = fromc; | |
1613 wp->w_old_cursor_lcol = toc; | |
1614 } | |
1615 } | |
1616 else | |
1617 { | |
1618 /* Use the line numbers of the old Visual area. */ | |
1619 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1620 { | |
1621 from = wp->w_old_cursor_lnum; | |
1622 to = wp->w_old_visual_lnum; | |
1623 } | |
1624 else | |
1625 { | |
1626 from = wp->w_old_visual_lnum; | |
1627 to = wp->w_old_cursor_lnum; | |
1628 } | |
1629 } | |
1630 | |
1631 /* | |
1632 * There is no need to update lines above the top of the window. | |
1633 */ | |
1634 if (from < wp->w_topline) | |
1635 from = wp->w_topline; | |
1636 | |
1637 /* | |
1638 * If we know the value of w_botline, use it to restrict the update to | |
1639 * the lines that are visible in the window. | |
1640 */ | |
1641 if (wp->w_valid & VALID_BOTLINE) | |
1642 { | |
1643 if (from >= wp->w_botline) | |
1644 from = wp->w_botline - 1; | |
1645 if (to >= wp->w_botline) | |
1646 to = wp->w_botline - 1; | |
1647 } | |
1648 | |
1649 /* | |
1650 * Find the minimal part to be updated. | |
1651 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1652 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1653 * top_end; need to redraw from top_end to the "to" line. | |
1654 * A middle mouse click with a Visual selection may change the text | |
1655 * above the Visual area and reset wl_valid, do count these for | |
1656 * mid_end (in srow). | |
1657 */ | |
1658 if (mid_start > 0) | |
1659 { | |
1660 lnum = wp->w_topline; | |
1661 idx = 0; | |
1662 srow = 0; | |
1663 if (scrolled_down) | |
1664 mid_start = top_end; | |
1665 else | |
1666 mid_start = 0; | |
1667 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1668 { | |
1669 if (wp->w_lines[idx].wl_valid) | |
1670 mid_start += wp->w_lines[idx].wl_size; | |
1671 else if (!scrolled_down) | |
1672 srow += wp->w_lines[idx].wl_size; | |
1673 ++idx; | |
1674 # ifdef FEAT_FOLDING | |
1675 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1676 lnum = wp->w_lines[idx].wl_lnum; | |
1677 else | |
1678 # endif | |
1679 ++lnum; | |
1680 } | |
1681 srow += mid_start; | |
1682 mid_end = wp->w_height; | |
1683 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1684 { | |
1685 if (wp->w_lines[idx].wl_valid | |
1686 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1687 { | |
1688 /* Only update until first row of this line */ | |
1689 mid_end = srow; | |
1690 break; | |
1691 } | |
1692 srow += wp->w_lines[idx].wl_size; | |
1693 } | |
1694 } | |
1695 } | |
1696 | |
1697 if (VIsual_active && buf == curwin->w_buffer) | |
1698 { | |
1699 wp->w_old_visual_mode = VIsual_mode; | |
1700 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1701 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1702 wp->w_old_visual_col = VIsual.col; |
7 | 1703 wp->w_old_curswant = curwin->w_curswant; |
1704 } | |
1705 else | |
1706 { | |
1707 wp->w_old_visual_mode = 0; | |
1708 wp->w_old_cursor_lnum = 0; | |
1709 wp->w_old_visual_lnum = 0; | |
422 | 1710 wp->w_old_visual_col = 0; |
7 | 1711 } |
1712 #endif /* FEAT_VISUAL */ | |
1713 | |
1714 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1715 /* reset got_int, otherwise regexp won't work */ | |
1716 save_got_int = got_int; | |
1717 got_int = 0; | |
1718 #endif | |
1719 #ifdef FEAT_FOLDING | |
1720 win_foldinfo.fi_level = 0; | |
1721 #endif | |
1722 | |
1723 /* | |
1724 * Update all the window rows. | |
1725 */ | |
1726 idx = 0; /* first entry in w_lines[].wl_size */ | |
1727 row = 0; | |
1728 srow = 0; | |
1729 lnum = wp->w_topline; /* first line shown in window */ | |
1730 for (;;) | |
1731 { | |
1732 /* stop updating when reached the end of the window (check for _past_ | |
1733 * the end of the window is at the end of the loop) */ | |
1734 if (row == wp->w_height) | |
1735 { | |
1736 didline = TRUE; | |
1737 break; | |
1738 } | |
1739 | |
1740 /* stop updating when hit the end of the file */ | |
1741 if (lnum > buf->b_ml.ml_line_count) | |
1742 { | |
1743 eof = TRUE; | |
1744 break; | |
1745 } | |
1746 | |
1747 /* Remember the starting row of the line that is going to be dealt | |
1748 * with. It is used further down when the line doesn't fit. */ | |
1749 srow = row; | |
1750 | |
1751 /* | |
1752 * Update a line when it is in an area that needs updating, when it | |
1753 * has changes or w_lines[idx] is invalid. | |
1754 * bot_start may be halfway a wrapped line after using | |
1755 * win_del_lines(), check if the current line includes it. | |
1756 * When syntax folding is being used, the saved syntax states will | |
1757 * already have been updated, we can't see where the syntax state is | |
1758 * the same again, just update until the end of the window. | |
1759 */ | |
1760 if (row < top_end | |
1761 || (row >= mid_start && row < mid_end) | |
1762 #ifdef FEAT_SEARCH_EXTRA | |
1763 || top_to_mod | |
1764 #endif | |
1765 || idx >= wp->w_lines_valid | |
1766 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1767 || (mod_top != 0 | |
1768 && (lnum == mod_top | |
1769 || (lnum >= mod_top | |
1770 && (lnum < mod_bot | |
1771 #ifdef FEAT_SYN_HL | |
1772 || did_update == DID_FOLD | |
1773 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1774 && syntax_present(wp) |
7 | 1775 && ( |
1776 # ifdef FEAT_FOLDING | |
1777 (foldmethodIsSyntax(wp) | |
1778 && hasAnyFolding(wp)) || | |
1779 # endif | |
1780 syntax_check_changed(lnum))) | |
1781 #endif | |
4916
ba328b4a990e
updated for version 7.3.1203
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1782 #ifdef FEAT_SEARCH_EXTRA |
ba328b4a990e
updated for version 7.3.1203
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1783 /* match in fixed position might need redraw */ |
ba328b4a990e
updated for version 7.3.1203
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1784 || wp->w_match_head != NULL |
ba328b4a990e
updated for version 7.3.1203
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1785 #endif |
7 | 1786 ))))) |
1787 { | |
1788 #ifdef FEAT_SEARCH_EXTRA | |
1789 if (lnum == mod_top) | |
1790 top_to_mod = FALSE; | |
1791 #endif | |
1792 | |
1793 /* | |
1794 * When at start of changed lines: May scroll following lines | |
1795 * up or down to minimize redrawing. | |
1796 * Don't do this when the change continues until the end. | |
3318 | 1797 * Don't scroll when dollar_vcol >= 0, keep the "$". |
7 | 1798 */ |
1799 if (lnum == mod_top | |
1800 && mod_bot != MAXLNUM | |
3318 | 1801 && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
7 | 1802 { |
1803 int old_rows = 0; | |
1804 int new_rows = 0; | |
1805 int xtra_rows; | |
1806 linenr_T l; | |
1807 | |
1808 /* Count the old number of window rows, using w_lines[], which | |
1809 * should still contain the sizes for the lines as they are | |
1810 * currently displayed. */ | |
1811 for (i = idx; i < wp->w_lines_valid; ++i) | |
1812 { | |
1813 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1814 * lines are part of the changed area. */ | |
1815 if (wp->w_lines[i].wl_valid | |
1816 && wp->w_lines[i].wl_lnum == mod_bot) | |
1817 break; | |
1818 old_rows += wp->w_lines[i].wl_size; | |
1819 #ifdef FEAT_FOLDING | |
1820 if (wp->w_lines[i].wl_valid | |
1821 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1822 { | |
1823 /* Must have found the last valid entry above mod_bot. | |
1824 * Add following invalid entries. */ | |
1825 ++i; | |
1826 while (i < wp->w_lines_valid | |
1827 && !wp->w_lines[i].wl_valid) | |
1828 old_rows += wp->w_lines[i++].wl_size; | |
1829 break; | |
1830 } | |
1831 #endif | |
1832 } | |
1833 | |
1834 if (i >= wp->w_lines_valid) | |
1835 { | |
1836 /* We can't find a valid line below the changed lines, | |
1837 * need to redraw until the end of the window. | |
1838 * Inserting/deleting lines has no use. */ | |
1839 bot_start = 0; | |
1840 } | |
1841 else | |
1842 { | |
1843 /* Able to count old number of rows: Count new window | |
1844 * rows, and may insert/delete lines */ | |
1845 j = idx; | |
1846 for (l = lnum; l < mod_bot; ++l) | |
1847 { | |
1848 #ifdef FEAT_FOLDING | |
1849 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1850 ++new_rows; | |
1851 else | |
1852 #endif | |
1853 #ifdef FEAT_DIFF | |
1854 if (l == wp->w_topline) | |
1855 new_rows += plines_win_nofill(wp, l, TRUE) | |
1856 + wp->w_topfill; | |
1857 else | |
1858 #endif | |
1859 new_rows += plines_win(wp, l, TRUE); | |
1860 ++j; | |
1861 if (new_rows > wp->w_height - row - 2) | |
1862 { | |
1863 /* it's getting too much, must redraw the rest */ | |
1864 new_rows = 9999; | |
1865 break; | |
1866 } | |
1867 } | |
1868 xtra_rows = new_rows - old_rows; | |
1869 if (xtra_rows < 0) | |
1870 { | |
1871 /* May scroll text up. If there is not enough | |
1872 * remaining text or scrolling fails, must redraw the | |
1873 * rest. If scrolling works, must redraw the text | |
1874 * below the scrolled text. */ | |
1875 if (row - xtra_rows >= wp->w_height - 2) | |
1876 mod_bot = MAXLNUM; | |
1877 else | |
1878 { | |
1879 check_for_delay(FALSE); | |
1880 if (win_del_lines(wp, row, | |
1881 -xtra_rows, FALSE, FALSE) == FAIL) | |
1882 mod_bot = MAXLNUM; | |
1883 else | |
1884 bot_start = wp->w_height + xtra_rows; | |
1885 } | |
1886 } | |
1887 else if (xtra_rows > 0) | |
1888 { | |
1889 /* May scroll text down. If there is not enough | |
1890 * remaining text of scrolling fails, must redraw the | |
1891 * rest. */ | |
1892 if (row + xtra_rows >= wp->w_height - 2) | |
1893 mod_bot = MAXLNUM; | |
1894 else | |
1895 { | |
1896 check_for_delay(FALSE); | |
1897 if (win_ins_lines(wp, row + old_rows, | |
1898 xtra_rows, FALSE, FALSE) == FAIL) | |
1899 mod_bot = MAXLNUM; | |
1900 else if (top_end > row + old_rows) | |
1901 /* Scrolled the part at the top that requires | |
1902 * updating down. */ | |
1903 top_end += xtra_rows; | |
1904 } | |
1905 } | |
1906 | |
1907 /* When not updating the rest, may need to move w_lines[] | |
1908 * entries. */ | |
1909 if (mod_bot != MAXLNUM && i != j) | |
1910 { | |
1911 if (j < i) | |
1912 { | |
1913 int x = row + new_rows; | |
1914 | |
1915 /* move entries in w_lines[] upwards */ | |
1916 for (;;) | |
1917 { | |
1918 /* stop at last valid entry in w_lines[] */ | |
1919 if (i >= wp->w_lines_valid) | |
1920 { | |
1921 wp->w_lines_valid = j; | |
1922 break; | |
1923 } | |
1924 wp->w_lines[j] = wp->w_lines[i]; | |
1925 /* stop at a line that won't fit */ | |
1926 if (x + (int)wp->w_lines[j].wl_size | |
1927 > wp->w_height) | |
1928 { | |
1929 wp->w_lines_valid = j + 1; | |
1930 break; | |
1931 } | |
1932 x += wp->w_lines[j++].wl_size; | |
1933 ++i; | |
1934 } | |
1935 if (bot_start > x) | |
1936 bot_start = x; | |
1937 } | |
1938 else /* j > i */ | |
1939 { | |
1940 /* move entries in w_lines[] downwards */ | |
1941 j -= i; | |
1942 wp->w_lines_valid += j; | |
1943 if (wp->w_lines_valid > wp->w_height) | |
1944 wp->w_lines_valid = wp->w_height; | |
1945 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1946 wp->w_lines[i] = wp->w_lines[i - j]; | |
1947 | |
1948 /* The w_lines[] entries for inserted lines are | |
1949 * now invalid, but wl_size may be used above. | |
1950 * Reset to zero. */ | |
1951 while (i >= idx) | |
1952 { | |
1953 wp->w_lines[i].wl_size = 0; | |
1954 wp->w_lines[i--].wl_valid = FALSE; | |
1955 } | |
1956 } | |
1957 } | |
1958 } | |
1959 } | |
1960 | |
1961 #ifdef FEAT_FOLDING | |
1962 /* | |
1963 * When lines are folded, display one line for all of them. | |
1964 * Otherwise, display normally (can be several display lines when | |
1965 * 'wrap' is on). | |
1966 */ | |
1967 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1968 if (fold_count != 0) | |
1969 { | |
1970 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1971 ++row; | |
1972 --fold_count; | |
1973 wp->w_lines[idx].wl_folded = TRUE; | |
1974 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1975 # ifdef FEAT_SYN_HL | |
1976 did_update = DID_FOLD; | |
1977 # endif | |
1978 } | |
1979 else | |
1980 #endif | |
1981 if (idx < wp->w_lines_valid | |
1982 && wp->w_lines[idx].wl_valid | |
1983 && wp->w_lines[idx].wl_lnum == lnum | |
1984 && lnum > wp->w_topline | |
1985 && !(dy_flags & DY_LASTLINE) | |
1986 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1987 #ifdef FEAT_DIFF | |
1988 && diff_check_fill(wp, lnum) == 0 | |
1989 #endif | |
1990 ) | |
1991 { | |
1992 /* This line is not going to fit. Don't draw anything here, | |
1993 * will draw "@ " lines below. */ | |
1994 row = wp->w_height + 1; | |
1995 } | |
1996 else | |
1997 { | |
1998 #ifdef FEAT_SEARCH_EXTRA | |
1999 prepare_search_hl(wp, lnum); | |
2000 #endif | |
2001 #ifdef FEAT_SYN_HL | |
2002 /* Let the syntax stuff know we skipped a few lines. */ | |
2003 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2004 && syntax_present(wp)) |
7 | 2005 syntax_end_parsing(syntax_last_parsed + 1); |
2006 #endif | |
2007 | |
2008 /* | |
2009 * Display one line. | |
2010 */ | |
625 | 2011 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 2012 |
2013 #ifdef FEAT_FOLDING | |
2014 wp->w_lines[idx].wl_folded = FALSE; | |
2015 wp->w_lines[idx].wl_lastlnum = lnum; | |
2016 #endif | |
2017 #ifdef FEAT_SYN_HL | |
2018 did_update = DID_LINE; | |
2019 syntax_last_parsed = lnum; | |
2020 #endif | |
2021 } | |
2022 | |
2023 wp->w_lines[idx].wl_lnum = lnum; | |
2024 wp->w_lines[idx].wl_valid = TRUE; | |
2025 if (row > wp->w_height) /* past end of screen */ | |
2026 { | |
2027 /* we may need the size of that too long line later on */ | |
3318 | 2028 if (dollar_vcol == -1) |
7 | 2029 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
2030 ++idx; | |
2031 break; | |
2032 } | |
3318 | 2033 if (dollar_vcol == -1) |
7 | 2034 wp->w_lines[idx].wl_size = row - srow; |
2035 ++idx; | |
2036 #ifdef FEAT_FOLDING | |
2037 lnum += fold_count + 1; | |
2038 #else | |
2039 ++lnum; | |
2040 #endif | |
2041 } | |
2042 else | |
2043 { | |
2044 /* This line does not need updating, advance to the next one */ | |
2045 row += wp->w_lines[idx++].wl_size; | |
2046 if (row > wp->w_height) /* past end of screen */ | |
2047 break; | |
2048 #ifdef FEAT_FOLDING | |
2049 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
2050 #else | |
2051 ++lnum; | |
2052 #endif | |
2053 #ifdef FEAT_SYN_HL | |
2054 did_update = DID_NONE; | |
2055 #endif | |
2056 } | |
2057 | |
2058 if (lnum > buf->b_ml.ml_line_count) | |
2059 { | |
2060 eof = TRUE; | |
2061 break; | |
2062 } | |
2063 } | |
2064 /* | |
2065 * End of loop over all window lines. | |
2066 */ | |
2067 | |
2068 | |
2069 if (idx > wp->w_lines_valid) | |
2070 wp->w_lines_valid = idx; | |
2071 | |
2072 #ifdef FEAT_SYN_HL | |
2073 /* | |
2074 * Let the syntax stuff know we stop parsing here. | |
2075 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2076 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 2077 syntax_end_parsing(syntax_last_parsed + 1); |
2078 #endif | |
2079 | |
2080 /* | |
2081 * If we didn't hit the end of the file, and we didn't finish the last | |
2082 * line we were working on, then the line didn't fit. | |
2083 */ | |
2084 wp->w_empty_rows = 0; | |
2085 #ifdef FEAT_DIFF | |
2086 wp->w_filler_rows = 0; | |
2087 #endif | |
2088 if (!eof && !didline) | |
2089 { | |
2090 if (lnum == wp->w_topline) | |
2091 { | |
2092 /* | |
2093 * Single line that does not fit! | |
2094 * Don't overwrite it, it can be edited. | |
2095 */ | |
2096 wp->w_botline = lnum + 1; | |
2097 } | |
2098 #ifdef FEAT_DIFF | |
2099 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
2100 { | |
2101 /* Window ends in filler lines. */ | |
2102 wp->w_botline = lnum; | |
2103 wp->w_filler_rows = wp->w_height - srow; | |
2104 } | |
2105 #endif | |
2106 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
2107 { | |
2108 /* | |
2109 * Last line isn't finished: Display "@@@" at the end. | |
2110 */ | |
2111 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
2112 W_WINROW(wp) + wp->w_height, | |
2113 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
2114 '@', '@', hl_attr(HLF_AT)); | |
2115 set_empty_rows(wp, srow); | |
2116 wp->w_botline = lnum; | |
2117 } | |
2118 else | |
2119 { | |
2120 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
2121 wp->w_botline = lnum; | |
2122 } | |
2123 } | |
2124 else | |
2125 { | |
2126 #ifdef FEAT_VERTSPLIT | |
2127 draw_vsep_win(wp, row); | |
2128 #endif | |
2129 if (eof) /* we hit the end of the file */ | |
2130 { | |
2131 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
2132 #ifdef FEAT_DIFF | |
2133 j = diff_check_fill(wp, wp->w_botline); | |
2134 if (j > 0 && !wp->w_botfill) | |
2135 { | |
2136 /* | |
2137 * Display filler lines at the end of the file | |
2138 */ | |
2139 if (char2cells(fill_diff) > 1) | |
2140 i = '-'; | |
2141 else | |
2142 i = fill_diff; | |
2143 if (row + j > wp->w_height) | |
2144 j = wp->w_height - row; | |
2145 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
2146 row += j; | |
2147 } | |
2148 #endif | |
2149 } | |
3318 | 2150 else if (dollar_vcol == -1) |
7 | 2151 wp->w_botline = lnum; |
2152 | |
2153 /* make sure the rest of the screen is blank */ | |
2154 /* put '~'s on rows that aren't part of the file. */ | |
2155 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
2156 } | |
2157 | |
2158 /* Reset the type of redrawing required, the window has been updated. */ | |
2159 wp->w_redr_type = 0; | |
2160 #ifdef FEAT_DIFF | |
2161 wp->w_old_topfill = wp->w_topfill; | |
2162 wp->w_old_botfill = wp->w_botfill; | |
2163 #endif | |
2164 | |
3318 | 2165 if (dollar_vcol == -1) |
7 | 2166 { |
2167 /* | |
2168 * There is a trick with w_botline. If we invalidate it on each | |
2169 * change that might modify it, this will cause a lot of expensive | |
2170 * calls to plines() in update_topline() each time. Therefore the | |
2171 * value of w_botline is often approximated, and this value is used to | |
2172 * compute the value of w_topline. If the value of w_botline was | |
2173 * wrong, check that the value of w_topline is correct (cursor is on | |
2174 * the visible part of the text). If it's not, we need to redraw | |
2175 * again. Mostly this just means scrolling up a few lines, so it | |
2176 * doesn't look too bad. Only do this for the current window (where | |
2177 * changes are relevant). | |
2178 */ | |
2179 wp->w_valid |= VALID_BOTLINE; | |
2180 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
2181 { | |
2182 recursive = TRUE; | |
2183 curwin->w_valid &= ~VALID_TOPLINE; | |
2184 update_topline(); /* may invalidate w_botline again */ | |
2185 if (must_redraw != 0) | |
2186 { | |
2187 /* Don't update for changes in buffer again. */ | |
2188 i = curbuf->b_mod_set; | |
2189 curbuf->b_mod_set = FALSE; | |
2190 win_update(curwin); | |
2191 must_redraw = 0; | |
2192 curbuf->b_mod_set = i; | |
2193 } | |
2194 recursive = FALSE; | |
2195 } | |
2196 } | |
2197 | |
2198 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
2199 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
2200 if (!got_int) | |
2201 got_int = save_got_int; | |
2202 #endif | |
2203 } | |
2204 | |
2205 #ifdef FEAT_SIGNS | |
2206 static int draw_signcolumn __ARGS((win_T *wp)); | |
2207 | |
2208 /* | |
2209 * Return TRUE when window "wp" has a column to draw signs in. | |
2210 */ | |
2211 static int | |
2212 draw_signcolumn(wp) | |
2213 win_T *wp; | |
2214 { | |
2215 return (wp->w_buffer->b_signlist != NULL | |
2216 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2217 || netbeans_active() |
7 | 2218 # endif |
2219 ); | |
2220 } | |
2221 #endif | |
2222 | |
2223 /* | |
2224 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2225 * as the filler character. | |
2226 */ | |
2227 static void | |
2228 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2229 win_T *wp; | |
2230 int c1; | |
2231 int c2; | |
2232 int row; | |
2233 int endrow; | |
534 | 2234 hlf_T hl; |
7 | 2235 { |
2236 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2237 int n = 0; | |
2238 # define FDC_OFF n | |
2239 #else | |
2240 # define FDC_OFF 0 | |
2241 #endif | |
2242 | |
2243 #ifdef FEAT_RIGHTLEFT | |
2244 if (wp->w_p_rl) | |
2245 { | |
2246 /* No check for cmdline window: should never be right-left. */ | |
2247 # ifdef FEAT_FOLDING | |
2248 n = wp->w_p_fdc; | |
2249 | |
2250 if (n > 0) | |
2251 { | |
2252 /* draw the fold column at the right */ | |
119 | 2253 if (n > W_WIDTH(wp)) |
2254 n = W_WIDTH(wp); | |
7 | 2255 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2256 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2257 ' ', ' ', hl_attr(HLF_FC)); | |
2258 } | |
2259 # endif | |
2260 # ifdef FEAT_SIGNS | |
2261 if (draw_signcolumn(wp)) | |
2262 { | |
2263 int nn = n + 2; | |
2264 | |
2265 /* draw the sign column left of the fold column */ | |
119 | 2266 if (nn > W_WIDTH(wp)) |
2267 nn = W_WIDTH(wp); | |
7 | 2268 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2269 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2270 ' ', ' ', hl_attr(HLF_SC)); | |
2271 n = nn; | |
2272 } | |
2273 # endif | |
2274 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2275 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2276 c2, c2, hl_attr(hl)); | |
2277 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2278 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2279 c1, c2, hl_attr(hl)); | |
2280 } | |
2281 else | |
2282 #endif | |
2283 { | |
2284 #ifdef FEAT_CMDWIN | |
2285 if (cmdwin_type != 0 && wp == curwin) | |
2286 { | |
2287 /* draw the cmdline character in the leftmost column */ | |
2288 n = 1; | |
2289 if (n > wp->w_width) | |
2290 n = wp->w_width; | |
2291 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2292 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2293 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2294 } | |
2295 #endif | |
2296 #ifdef FEAT_FOLDING | |
2297 if (wp->w_p_fdc > 0) | |
2298 { | |
2299 int nn = n + wp->w_p_fdc; | |
2300 | |
2301 /* draw the fold column at the left */ | |
2302 if (nn > W_WIDTH(wp)) | |
2303 nn = W_WIDTH(wp); | |
2304 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2305 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2306 ' ', ' ', hl_attr(HLF_FC)); | |
2307 n = nn; | |
2308 } | |
2309 #endif | |
2310 #ifdef FEAT_SIGNS | |
2311 if (draw_signcolumn(wp)) | |
2312 { | |
2313 int nn = n + 2; | |
2314 | |
2315 /* draw the sign column after the fold column */ | |
2316 if (nn > W_WIDTH(wp)) | |
2317 nn = W_WIDTH(wp); | |
2318 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2319 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2320 ' ', ' ', hl_attr(HLF_SC)); | |
2321 n = nn; | |
2322 } | |
2323 #endif | |
2324 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2325 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2326 c1, c2, hl_attr(hl)); | |
2327 } | |
2328 set_empty_rows(wp, row); | |
2329 } | |
2330 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2331 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2332 static int advance_color_col __ARGS((int vcol, int **color_cols)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2333 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2334 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2335 * Advance **color_cols and return TRUE when there are columns to draw. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2336 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2337 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2338 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2339 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2340 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2341 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2342 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2343 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2344 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2345 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2346 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2347 |
7 | 2348 #ifdef FEAT_FOLDING |
2349 /* | |
2350 * Display one folded line. | |
2351 */ | |
2352 static void | |
2353 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2354 win_T *wp; | |
2355 long fold_count; | |
2356 foldinfo_T *foldinfo; | |
2357 linenr_T lnum; | |
2358 int row; | |
2359 { | |
2360 char_u buf[51]; | |
2361 pos_T *top, *bot; | |
2362 linenr_T lnume = lnum + fold_count - 1; | |
2363 int len; | |
29 | 2364 char_u *text; |
7 | 2365 int fdc; |
2366 int col; | |
2367 int txtcol; | |
2368 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2369 int ri; |
7 | 2370 |
2371 /* Build the fold line: | |
2372 * 1. Add the cmdwin_type for the command-line window | |
2373 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2374 * 3. Add the 'number' or 'relativenumber' column |
7 | 2375 * 4. Compose the text |
2376 * 5. Add the text | |
2377 * 6. set highlighting for the Visual area an other text | |
2378 */ | |
2379 col = 0; | |
2380 | |
2381 /* | |
2382 * 1. Add the cmdwin_type for the command-line window | |
2383 * Ignores 'rightleft', this window is never right-left. | |
2384 */ | |
2385 #ifdef FEAT_CMDWIN | |
2386 if (cmdwin_type != 0 && wp == curwin) | |
2387 { | |
2388 ScreenLines[off] = cmdwin_type; | |
2389 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2390 #ifdef FEAT_MBYTE | |
2391 if (enc_utf8) | |
2392 ScreenLinesUC[off] = 0; | |
2393 #endif | |
2394 ++col; | |
2395 } | |
2396 #endif | |
2397 | |
2398 /* | |
2399 * 2. Add the 'foldcolumn' | |
2400 */ | |
2401 fdc = wp->w_p_fdc; | |
2402 if (fdc > W_WIDTH(wp) - col) | |
2403 fdc = W_WIDTH(wp) - col; | |
2404 if (fdc > 0) | |
2405 { | |
2406 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2407 #ifdef FEAT_RIGHTLEFT | |
2408 if (wp->w_p_rl) | |
2409 { | |
2410 int i; | |
2411 | |
2412 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2413 hl_attr(HLF_FC)); | |
2414 /* reverse the fold column */ | |
2415 for (i = 0; i < fdc; ++i) | |
2416 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2417 } | |
2418 else | |
2419 #endif | |
2420 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2421 col += fdc; | |
2422 } | |
2423 | |
2424 #ifdef FEAT_RIGHTLEFT | |
216 | 2425 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2426 for (ri = 0; ri < l; ++ri) \ | |
2427 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2428 else \ | |
2429 for (ri = 0; ri < l; ++ri) \ | |
2430 ScreenAttrs[off + (p) + ri] = v | |
7 | 2431 #else |
216 | 2432 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2433 ScreenAttrs[off + (p) + ri] = v | |
7 | 2434 #endif |
2435 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2436 /* Set all attributes of the 'number' or 'relativenumber' column and the |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2437 * text */ |
216 | 2438 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2439 |
2440 #ifdef FEAT_SIGNS | |
2441 /* If signs are being displayed, add two spaces. */ | |
2442 if (draw_signcolumn(wp)) | |
2443 { | |
2444 len = W_WIDTH(wp) - col; | |
2445 if (len > 0) | |
2446 { | |
2447 if (len > 2) | |
2448 len = 2; | |
2449 # ifdef FEAT_RIGHTLEFT | |
2450 if (wp->w_p_rl) | |
2451 /* the line number isn't reversed */ | |
2452 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2453 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2454 else | |
2455 # endif | |
2456 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2457 col += len; | |
2458 } | |
2459 } | |
2460 #endif | |
2461 | |
2462 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2463 * 3. Add the 'number' or 'relativenumber' column |
7 | 2464 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2465 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2466 { |
2467 len = W_WIDTH(wp) - col; | |
2468 if (len > 0) | |
2469 { | |
13 | 2470 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2471 long num; |
4065 | 2472 char *fmt = "%*ld "; |
13 | 2473 |
2474 if (len > w + 1) | |
2475 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2476 |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2477 if (wp->w_p_nu && !wp->w_p_rnu) |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2478 /* 'number' + 'norelativenumber' */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2479 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2480 else |
4065 | 2481 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2482 /* 'relativenumber', don't use negative numbers */ |
2675 | 2483 num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2484 if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2485 { |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2486 /* 'number' + 'relativenumber': cursor line shows absolute |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2487 * line number */ |
4065 | 2488 num = lnum; |
2489 fmt = "%-*ld "; | |
2490 } | |
2491 } | |
2492 | |
2493 sprintf((char *)buf, fmt, w, num); | |
7 | 2494 #ifdef FEAT_RIGHTLEFT |
2495 if (wp->w_p_rl) | |
2496 /* the line number isn't reversed */ | |
2497 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2498 hl_attr(HLF_FL)); | |
2499 else | |
2500 #endif | |
2501 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2502 col += len; | |
2503 } | |
2504 } | |
2505 | |
2506 /* | |
2507 * 4. Compose the folded-line string with 'foldtext', if set. | |
2508 */ | |
29 | 2509 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2510 |
2511 txtcol = col; /* remember where text starts */ | |
2512 | |
2513 /* | |
2514 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2515 * Right-left text is put in columns 0 - number-col, normal text is put | |
2516 * in columns number-col - window-width. | |
2517 */ | |
2518 #ifdef FEAT_MBYTE | |
2519 if (has_mbyte) | |
2520 { | |
2521 int cells; | |
714 | 2522 int u8c, u8cc[MAX_MCO]; |
2523 int i; | |
7 | 2524 int idx; |
2525 int c_len; | |
33 | 2526 char_u *p; |
7 | 2527 # ifdef FEAT_ARABIC |
2528 int prev_c = 0; /* previous Arabic character */ | |
2529 int prev_c1 = 0; /* first composing char for prev_c */ | |
2530 # endif | |
2531 | |
2532 # ifdef FEAT_RIGHTLEFT | |
2533 if (wp->w_p_rl) | |
2534 idx = off; | |
2535 else | |
2536 # endif | |
2537 idx = off + col; | |
2538 | |
2539 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2540 for (p = text; *p != NUL; ) | |
2541 { | |
2542 cells = (*mb_ptr2cells)(p); | |
474 | 2543 c_len = (*mb_ptr2len)(p); |
7 | 2544 if (col + cells > W_WIDTH(wp) |
2545 # ifdef FEAT_RIGHTLEFT | |
2546 - (wp->w_p_rl ? col : 0) | |
2547 # endif | |
2548 ) | |
2549 break; | |
2550 ScreenLines[idx] = *p; | |
2551 if (enc_utf8) | |
2552 { | |
714 | 2553 u8c = utfc_ptr2char(p, u8cc); |
2554 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2555 { |
2556 ScreenLinesUC[idx] = 0; | |
2557 #ifdef FEAT_ARABIC | |
2558 prev_c = u8c; | |
2559 #endif | |
2560 } | |
2561 else | |
2562 { | |
2563 #ifdef FEAT_ARABIC | |
2564 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2565 { | |
2566 /* Do Arabic shaping. */ | |
714 | 2567 int pc, pc1, nc; |
2568 int pcc[MAX_MCO]; | |
7 | 2569 int firstbyte = *p; |
2570 | |
2571 /* The idea of what is the previous and next | |
2572 * character depends on 'rightleft'. */ | |
2573 if (wp->w_p_rl) | |
2574 { | |
2575 pc = prev_c; | |
2576 pc1 = prev_c1; | |
2577 nc = utf_ptr2char(p + c_len); | |
714 | 2578 prev_c1 = u8cc[0]; |
7 | 2579 } |
2580 else | |
2581 { | |
714 | 2582 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2583 nc = prev_c; |
714 | 2584 pc1 = pcc[0]; |
7 | 2585 } |
2586 prev_c = u8c; | |
2587 | |
714 | 2588 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2589 pc, pc1, nc); |
2590 ScreenLines[idx] = firstbyte; | |
2591 } | |
2592 else | |
2593 prev_c = u8c; | |
2594 #endif | |
2595 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2596 #ifdef UNICODE16 |
7 | 2597 if (u8c >= 0x10000) |
2598 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2599 else | |
1401 | 2600 #endif |
7 | 2601 ScreenLinesUC[idx] = u8c; |
714 | 2602 for (i = 0; i < Screen_mco; ++i) |
2603 { | |
2604 ScreenLinesC[i][idx] = u8cc[i]; | |
2605 if (u8cc[i] == 0) | |
2606 break; | |
2607 } | |
7 | 2608 } |
2609 if (cells > 1) | |
2610 ScreenLines[idx + 1] = 0; | |
2611 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2612 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2613 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2614 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2615 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2616 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2617 ScreenLines[idx + 1] = p[1]; |
7 | 2618 col += cells; |
2619 idx += cells; | |
2620 p += c_len; | |
2621 } | |
2622 } | |
2623 else | |
2624 #endif | |
2625 { | |
2626 len = (int)STRLEN(text); | |
2627 if (len > W_WIDTH(wp) - col) | |
2628 len = W_WIDTH(wp) - col; | |
2629 if (len > 0) | |
2630 { | |
2631 #ifdef FEAT_RIGHTLEFT | |
2632 if (wp->w_p_rl) | |
2633 STRNCPY(current_ScreenLine, text, len); | |
2634 else | |
2635 #endif | |
2636 STRNCPY(current_ScreenLine + col, text, len); | |
2637 col += len; | |
2638 } | |
2639 } | |
2640 | |
2641 /* Fill the rest of the line with the fold filler */ | |
2642 #ifdef FEAT_RIGHTLEFT | |
2643 if (wp->w_p_rl) | |
2644 col -= txtcol; | |
2645 #endif | |
2646 while (col < W_WIDTH(wp) | |
2647 #ifdef FEAT_RIGHTLEFT | |
2648 - (wp->w_p_rl ? txtcol : 0) | |
2649 #endif | |
2650 ) | |
2651 { | |
2652 #ifdef FEAT_MBYTE | |
2653 if (enc_utf8) | |
2654 { | |
2655 if (fill_fold >= 0x80) | |
2656 { | |
2657 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2658 ScreenLinesC[0][off + col] = 0; |
7 | 2659 } |
2660 else | |
2661 ScreenLinesUC[off + col] = 0; | |
2662 } | |
2663 #endif | |
2664 ScreenLines[off + col++] = fill_fold; | |
2665 } | |
2666 | |
2667 if (text != buf) | |
2668 vim_free(text); | |
2669 | |
2670 /* | |
2671 * 6. set highlighting for the Visual area an other text. | |
2672 * If all folded lines are in the Visual area, highlight the line. | |
2673 */ | |
2674 #ifdef FEAT_VISUAL | |
2675 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2676 { | |
2677 if (ltoreq(curwin->w_cursor, VIsual)) | |
2678 { | |
2679 /* Visual is after curwin->w_cursor */ | |
2680 top = &curwin->w_cursor; | |
2681 bot = &VIsual; | |
2682 } | |
2683 else | |
2684 { | |
2685 /* Visual is before curwin->w_cursor */ | |
2686 top = &VIsual; | |
2687 bot = &curwin->w_cursor; | |
2688 } | |
2689 if (lnum >= top->lnum | |
2690 && lnume <= bot->lnum | |
2691 && (VIsual_mode != 'v' | |
2692 || ((lnum > top->lnum | |
2693 || (lnum == top->lnum | |
2694 && top->col == 0)) | |
2695 && (lnume < bot->lnum | |
2696 || (lnume == bot->lnum | |
2697 && (bot->col - (*p_sel == 'e')) | |
1883 | 2698 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2699 { |
2700 if (VIsual_mode == Ctrl_V) | |
2701 { | |
2702 /* Visual block mode: highlight the chars part of the block */ | |
2703 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2704 { | |
3040 | 2705 if (wp->w_old_cursor_lcol != MAXCOL |
2706 && wp->w_old_cursor_lcol + txtcol | |
2707 < (colnr_T)W_WIDTH(wp)) | |
7 | 2708 len = wp->w_old_cursor_lcol; |
2709 else | |
2710 len = W_WIDTH(wp) - txtcol; | |
2711 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2712 len - (int)wp->w_old_cursor_fcol); |
7 | 2713 } |
2714 } | |
2715 else | |
216 | 2716 { |
7 | 2717 /* Set all attributes of the text */ |
216 | 2718 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2719 } | |
7 | 2720 } |
2721 } | |
2722 #endif | |
2723 | |
743 | 2724 #ifdef FEAT_SYN_HL |
2725 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2726 if (wp->w_p_cuc) |
2727 { | |
2728 txtcol += wp->w_virtcol; | |
2729 if (wp->w_p_wrap) | |
2730 txtcol -= wp->w_skipcol; | |
2731 else | |
2732 txtcol -= wp->w_leftcol; | |
2733 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2734 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2735 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2736 } | |
743 | 2737 #endif |
7 | 2738 |
2739 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2740 (int)W_WIDTH(wp), FALSE); | |
2741 | |
2742 /* | |
2743 * Update w_cline_height and w_cline_folded if the cursor line was | |
2744 * updated (saves a call to plines() later). | |
2745 */ | |
2746 if (wp == curwin | |
2747 && lnum <= curwin->w_cursor.lnum | |
2748 && lnume >= curwin->w_cursor.lnum) | |
2749 { | |
2750 curwin->w_cline_row = row; | |
2751 curwin->w_cline_height = 1; | |
2752 curwin->w_cline_folded = TRUE; | |
2753 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2754 } | |
2755 } | |
2756 | |
2757 /* | |
2758 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2759 */ | |
2760 static void | |
2761 copy_text_attr(off, buf, len, attr) | |
2762 int off; | |
2763 char_u *buf; | |
2764 int len; | |
2765 int attr; | |
2766 { | |
216 | 2767 int i; |
2768 | |
7 | 2769 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2770 # ifdef FEAT_MBYTE | |
2771 if (enc_utf8) | |
2772 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2773 # endif | |
216 | 2774 for (i = 0; i < len; ++i) |
2775 ScreenAttrs[off + i] = attr; | |
7 | 2776 } |
2777 | |
2778 /* | |
2779 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2780 * Only to be called when 'foldcolumn' > 0. |
7 | 2781 */ |
2782 static void | |
2783 fill_foldcolumn(p, wp, closed, lnum) | |
2784 char_u *p; | |
2785 win_T *wp; | |
2786 int closed; /* TRUE of FALSE */ | |
2787 linenr_T lnum; /* current line number */ | |
2788 { | |
2789 int i = 0; | |
2790 int level; | |
2791 int first_level; | |
519 | 2792 int empty; |
7 | 2793 |
2794 /* Init to all spaces. */ | |
2795 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2796 | |
2797 level = win_foldinfo.fi_level; | |
2798 if (level > 0) | |
2799 { | |
519 | 2800 /* If there is only one column put more info in it. */ |
2801 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2802 | |
7 | 2803 /* If the column is too narrow, we start at the lowest level that |
2804 * fits and use numbers to indicated the depth. */ | |
519 | 2805 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2806 if (first_level < 1) |
2807 first_level = 1; | |
2808 | |
519 | 2809 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2810 { |
2811 if (win_foldinfo.fi_lnum == lnum | |
2812 && first_level + i >= win_foldinfo.fi_low_level) | |
2813 p[i] = '-'; | |
2814 else if (first_level == 1) | |
2815 p[i] = '|'; | |
2816 else if (first_level + i <= 9) | |
2817 p[i] = '0' + first_level + i; | |
2818 else | |
2819 p[i] = '>'; | |
2820 if (first_level + i == level) | |
2821 break; | |
2822 } | |
2823 } | |
2824 if (closed) | |
548 | 2825 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2826 } |
2827 #endif /* FEAT_FOLDING */ | |
2828 | |
2829 /* | |
2830 * Display line "lnum" of window 'wp' on the screen. | |
2831 * Start at row "startrow", stop when "endrow" is reached. | |
2832 * wp->w_virtcol needs to be valid. | |
2833 * | |
2834 * Return the number of last row the line occupies. | |
2835 */ | |
2836 static int | |
625 | 2837 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2838 win_T *wp; |
2839 linenr_T lnum; | |
2840 int startrow; | |
2841 int endrow; | |
1883 | 2842 int nochange UNUSED; /* not updating for changed text */ |
7 | 2843 { |
2844 int col; /* visual column on screen */ | |
2845 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2846 int c = 0; /* init for GCC */ | |
2847 long vcol = 0; /* virtual column (for tabs) */ | |
2848 long vcol_prev = -1; /* "vcol" of previous character */ | |
2849 char_u *line; /* current line */ | |
2850 char_u *ptr; /* current position in "line" */ | |
2851 int row; /* row in the window, excl w_winrow */ | |
2852 int screen_row; /* row on the screen, incl w_winrow */ | |
2853 | |
2854 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2855 int n_extra = 0; /* number of extra chars */ | |
1340 | 2856 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2857 int c_extra = NUL; /* extra chars, all the same */ |
2858 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2859 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2860 displaying lcs_eol at end-of-line */ | |
2861 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2862 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2863 | |
2864 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2865 int saved_n_extra = 0; | |
2866 char_u *saved_p_extra = NULL; | |
2867 int saved_c_extra = 0; | |
2868 int saved_char_attr = 0; | |
2869 | |
2870 int n_attr = 0; /* chars with special attr */ | |
2871 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2872 int n_attr3 = 0; /* chars with overruling special attr */ | |
2873 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2874 | |
2875 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2876 | |
2877 int fromcol, tocol; /* start/end of inverting */ | |
2878 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2879 int noinvcur = FALSE; /* don't invert the cursor */ | |
2880 #ifdef FEAT_VISUAL | |
2881 pos_T *top, *bot; | |
1813 | 2882 int lnum_in_visual_area = FALSE; |
7 | 2883 #endif |
2884 pos_T pos; | |
2885 long v; | |
2886 | |
2887 int char_attr = 0; /* attributes for next character */ | |
674 | 2888 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2889 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2890 in this line */ | |
2891 int attr = 0; /* attributes for area highlighting */ | |
2892 int area_attr = 0; /* attributes desired by highlighting */ | |
2893 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2894 #ifdef FEAT_SYN_HL | |
743 | 2895 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2896 int syntax_attr = 0; /* attributes desired by syntax */ |
2897 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2898 int save_did_emsg; | |
1437 | 2899 int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2900 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2901 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2902 #endif |
2903 #ifdef FEAT_SPELL | |
221 | 2904 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2905 # define SPWORDLEN 150 |
2906 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2907 int nextlinecol = 0; /* column where nextline[] starts */ |
2908 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2909 starts */ |
221 | 2910 int spell_attr = 0; /* attributes desired by spelling */ |
2911 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2912 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2913 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2914 * there are no spell errors */ |
386 | 2915 static int cap_col = -1; /* column to check for Cap word */ |
2916 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2917 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2918 #endif |
2919 int extra_check; /* has syntax or linebreak */ | |
2920 #ifdef FEAT_MBYTE | |
2921 int multi_attr = 0; /* attributes desired by multibyte */ | |
2922 int mb_l = 1; /* multi-byte byte length */ | |
2923 int mb_c = 0; /* decoded multi-byte character */ | |
2924 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2925 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2926 #endif |
2927 #ifdef FEAT_DIFF | |
2928 int filler_lines; /* nr of filler lines to be drawn */ | |
2929 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2930 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2931 int change_start = MAXCOL; /* first col of changed area */ |
2932 int change_end = -1; /* last col of changed area */ | |
2933 #endif | |
2934 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2935 #ifdef FEAT_LINEBREAK | |
2936 int need_showbreak = FALSE; | |
2937 #endif | |
910 | 2938 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2939 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2940 # define LINE_ATTR |
1536 | 2941 int line_attr = 0; /* attribute for the whole line */ |
7 | 2942 #endif |
2943 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2944 matchitem_T *cur; /* points to the match list */ |
2945 match_T *shl; /* points to search_hl or a match */ | |
2946 int shl_flag; /* flag to indicate whether search_hl | |
2947 has been processed or not */ | |
2948 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2949 equals startcol of search_hl or one | |
2950 of the matches */ | |
7 | 2951 #endif |
2952 #ifdef FEAT_ARABIC | |
2953 int prev_c = 0; /* previous Arabic character */ | |
2954 int prev_c1 = 0; /* first composing char for prev_c */ | |
2955 #endif | |
910 | 2956 #if defined(LINE_ATTR) |
867 | 2957 int did_line_attr = 0; |
2958 #endif | |
7 | 2959 |
2960 /* draw_state: items that are drawn in sequence: */ | |
2961 #define WL_START 0 /* nothing done yet */ | |
2962 #ifdef FEAT_CMDWIN | |
2963 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2964 #else | |
2965 # define WL_CMDLINE WL_START | |
2966 #endif | |
2967 #ifdef FEAT_FOLDING | |
2968 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2969 #else | |
2970 # define WL_FOLD WL_CMDLINE | |
2971 #endif | |
2972 #ifdef FEAT_SIGNS | |
2973 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2974 #else | |
2975 # define WL_SIGN WL_FOLD /* column for signs */ | |
2976 #endif | |
2977 #define WL_NR WL_SIGN + 1 /* line number */ | |
2978 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2979 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2980 #else | |
2981 # define WL_SBR WL_NR | |
2982 #endif | |
2983 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2984 int draw_state = WL_START; /* what to draw next */ | |
574 | 2985 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2986 int feedback_col = 0; |
2987 int feedback_old_attr = -1; | |
2988 #endif | |
2989 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2990 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2991 int syntax_flags = 0; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
2992 int syntax_seqnr = 0; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
2993 int prev_syntax_id = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2994 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2995 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2996 int boguscols = 0; /* nonexistent columns added to force |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2997 wrapping */ |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2400
diff
changeset
|
2998 int vcol_off = 0; /* offset for concealed characters */ |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2999 int did_wcol = FALSE; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
3000 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
3001 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
3002 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3003 #endif |
7 | 3004 |
3005 if (startrow > endrow) /* past the end already! */ | |
3006 return startrow; | |
3007 | |
3008 row = startrow; | |
3009 screen_row = row + W_WINROW(wp); | |
3010 | |
3011 /* | |
3012 * To speed up the loop below, set extra_check when there is linebreak, | |
3013 * trailing white space and/or syntax processing to be done. | |
3014 */ | |
3015 #ifdef FEAT_LINEBREAK | |
3016 extra_check = wp->w_p_lbr; | |
3017 #else | |
3018 extra_check = 0; | |
3019 #endif | |
3020 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3021 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 3022 { |
3023 /* Prepare for syntax highlighting in this line. When there is an | |
3024 * error, stop syntax highlighting. */ | |
3025 save_did_emsg = did_emsg; | |
3026 did_emsg = FALSE; | |
3027 syntax_start(wp, lnum); | |
3028 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3029 wp->w_s->b_syn_error = TRUE; |
7 | 3030 else |
3031 { | |
3032 did_emsg = save_did_emsg; | |
3033 has_syntax = TRUE; | |
3034 extra_check = TRUE; | |
3035 } | |
3036 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3037 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3038 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3039 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3040 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
3041 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 3042 #endif |
3043 | |
3044 #ifdef FEAT_SPELL | |
258 | 3045 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3046 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3047 && wp->w_s->b_langp.ga_len > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3048 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 3049 { |
3050 /* Prepare for spell checking. */ | |
3051 has_spell = TRUE; | |
3052 extra_check = TRUE; | |
348 | 3053 |
3054 /* Get the start of the next line, so that words that wrap to the next | |
3055 * line are found too: "et<line-break>al.". | |
3056 * Trick: skip a few chars for C/shell/Vim comments */ | |
3057 nextline[SPWORDLEN] = NUL; | |
3058 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
3059 { | |
3060 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
3061 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
3062 } | |
3063 | |
3064 /* When a word wrapped from the previous line the start of the current | |
3065 * line is valid. */ | |
3066 if (lnum == checked_lnum) | |
3067 cur_checked_col = checked_col; | |
3068 checked_lnum = 0; | |
386 | 3069 |
3070 /* When there was a sentence end in the previous line may require a | |
3071 * word starting with capital in this line. In line 1 always check | |
3072 * the first word. */ | |
3073 if (lnum != capcol_lnum) | |
3074 cap_col = -1; | |
3075 if (lnum == 1) | |
3076 cap_col = 0; | |
3077 capcol_lnum = 0; | |
221 | 3078 } |
7 | 3079 #endif |
3080 | |
3081 /* | |
3082 * handle visual active in this window | |
3083 */ | |
3084 fromcol = -10; | |
3085 tocol = MAXCOL; | |
3086 #ifdef FEAT_VISUAL | |
3087 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3088 { | |
3089 /* Visual is after curwin->w_cursor */ | |
3090 if (ltoreq(curwin->w_cursor, VIsual)) | |
3091 { | |
3092 top = &curwin->w_cursor; | |
3093 bot = &VIsual; | |
3094 } | |
3095 else /* Visual is before curwin->w_cursor */ | |
3096 { | |
3097 top = &VIsual; | |
3098 bot = &curwin->w_cursor; | |
3099 } | |
1813 | 3100 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 3101 if (VIsual_mode == Ctrl_V) /* block mode */ |
3102 { | |
1813 | 3103 if (lnum_in_visual_area) |
7 | 3104 { |
3105 fromcol = wp->w_old_cursor_fcol; | |
3106 tocol = wp->w_old_cursor_lcol; | |
3107 } | |
3108 } | |
3109 else /* non-block mode */ | |
3110 { | |
3111 if (lnum > top->lnum && lnum <= bot->lnum) | |
3112 fromcol = 0; | |
3113 else if (lnum == top->lnum) | |
3114 { | |
3115 if (VIsual_mode == 'V') /* linewise */ | |
3116 fromcol = 0; | |
3117 else | |
3118 { | |
3119 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
3120 if (gchar_pos(top) == NUL) | |
3121 tocol = fromcol + 1; | |
3122 } | |
3123 } | |
3124 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
3125 { | |
3126 if (*p_sel == 'e' && bot->col == 0 | |
3127 #ifdef FEAT_VIRTUALEDIT | |
3128 && bot->coladd == 0 | |
3129 #endif | |
3130 ) | |
3131 { | |
3132 fromcol = -10; | |
3133 tocol = MAXCOL; | |
3134 } | |
36 | 3135 else if (bot->col == MAXCOL) |
3136 tocol = MAXCOL; | |
7 | 3137 else |
3138 { | |
3139 pos = *bot; | |
3140 if (*p_sel == 'e') | |
3141 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3142 else | |
3143 { | |
3144 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
3145 ++tocol; | |
3146 } | |
3147 } | |
3148 } | |
3149 } | |
3150 | |
3151 #ifndef MSDOS | |
3152 /* Check if the character under the cursor should not be inverted */ | |
3153 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
3154 # ifdef FEAT_GUI | |
3155 && !gui.in_use | |
3156 # endif | |
3157 ) | |
3158 noinvcur = TRUE; | |
3159 #endif | |
3160 | |
3161 /* if inverting in this line set area_highlighting */ | |
3162 if (fromcol >= 0) | |
3163 { | |
3164 area_highlighting = TRUE; | |
3165 attr = hl_attr(HLF_V); | |
3166 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
3674 | 3167 if ((clip_star.available && !clip_star.owned |
3168 && clip_isautosel_star()) | |
3169 || (clip_plus.available && !clip_plus.owned | |
3170 && clip_isautosel_plus())) | |
7 | 3171 attr = hl_attr(HLF_VNC); |
3172 #endif | |
3173 } | |
3174 } | |
3175 | |
3176 /* | |
674 | 3177 * handle 'incsearch' and ":s///c" highlighting |
7 | 3178 */ |
3179 else | |
3180 #endif /* FEAT_VISUAL */ | |
3181 if (highlight_match | |
3182 && wp == curwin | |
3183 && lnum >= curwin->w_cursor.lnum | |
3184 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
3185 { | |
3186 if (lnum == curwin->w_cursor.lnum) | |
3187 getvcol(curwin, &(curwin->w_cursor), | |
3188 (colnr_T *)&fromcol, NULL, NULL); | |
3189 else | |
3190 fromcol = 0; | |
3191 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
3192 { | |
3193 pos.lnum = lnum; | |
3194 pos.col = search_match_endcol; | |
3195 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3196 } | |
3197 else | |
3198 tocol = MAXCOL; | |
1850 | 3199 /* do at least one character; happens when past end of line */ |
3200 if (fromcol == tocol) | |
3201 tocol = fromcol + 1; | |
7 | 3202 area_highlighting = TRUE; |
3203 attr = hl_attr(HLF_I); | |
3204 } | |
3205 | |
3206 #ifdef FEAT_DIFF | |
3207 filler_lines = diff_check(wp, lnum); | |
3208 if (filler_lines < 0) | |
3209 { | |
3210 if (filler_lines == -1) | |
3211 { | |
3212 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
3213 diff_hlf = HLF_ADD; /* added line */ | |
3214 else if (change_start == 0) | |
3215 diff_hlf = HLF_TXD; /* changed text */ | |
3216 else | |
3217 diff_hlf = HLF_CHD; /* changed line */ | |
3218 } | |
3219 else | |
3220 diff_hlf = HLF_ADD; /* added line */ | |
3221 filler_lines = 0; | |
3222 area_highlighting = TRUE; | |
3223 } | |
3224 if (lnum == wp->w_topline) | |
3225 filler_lines = wp->w_topfill; | |
3226 filler_todo = filler_lines; | |
3227 #endif | |
3228 | |
3229 #ifdef LINE_ATTR | |
3230 # ifdef FEAT_SIGNS | |
3231 /* If this line has a sign with line highlighting set line_attr. */ | |
3232 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3233 if (v != 0) | |
3234 line_attr = sign_get_attr((int)v, TRUE); | |
3235 # endif | |
3236 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3237 /* Highlight the current line in the quickfix window. */ | |
644 | 3238 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3239 line_attr = hl_attr(HLF_L); |
3240 # endif | |
3241 if (line_attr != 0) | |
3242 area_highlighting = TRUE; | |
3243 #endif | |
3244 | |
3245 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3246 ptr = line; | |
3247 | |
743 | 3248 #ifdef FEAT_SPELL |
348 | 3249 if (has_spell) |
3250 { | |
386 | 3251 /* For checking first word with a capital skip white space. */ |
3252 if (cap_col == 0) | |
835 | 3253 cap_col = (int)(skipwhite(line) - line); |
386 | 3254 |
348 | 3255 /* To be able to spell-check over line boundaries copy the end of the |
3256 * current line into nextline[]. Above the start of the next line was | |
3257 * copied to nextline[SPWORDLEN]. */ | |
3258 if (nextline[SPWORDLEN] == NUL) | |
3259 { | |
3260 /* No next line or it is empty. */ | |
3261 nextlinecol = MAXCOL; | |
3262 nextline_idx = 0; | |
3263 } | |
3264 else | |
3265 { | |
835 | 3266 v = (long)STRLEN(line); |
348 | 3267 if (v < SPWORDLEN) |
3268 { | |
3269 /* Short line, use it completely and append the start of the | |
3270 * next line. */ | |
3271 nextlinecol = 0; | |
3272 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3273 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3274 nextline_idx = v + 1; |
3275 } | |
3276 else | |
3277 { | |
3278 /* Long line, use only the last SPWORDLEN bytes. */ | |
3279 nextlinecol = v - SPWORDLEN; | |
3280 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3281 nextline_idx = SPWORDLEN + 1; | |
3282 } | |
3283 } | |
3284 } | |
3285 #endif | |
3286 | |
7 | 3287 /* find start of trailing whitespace */ |
3288 if (wp->w_p_list && lcs_trail) | |
3289 { | |
3290 trailcol = (colnr_T)STRLEN(ptr); | |
3291 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3292 --trailcol; | |
3293 trailcol += (colnr_T) (ptr - line); | |
3294 extra_check = TRUE; | |
3295 } | |
3296 | |
3297 /* | |
3298 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3299 * first character to be displayed. | |
3300 */ | |
3301 if (wp->w_p_wrap) | |
3302 v = wp->w_skipcol; | |
3303 else | |
3304 v = wp->w_leftcol; | |
3305 if (v > 0) | |
3306 { | |
3307 #ifdef FEAT_MBYTE | |
3308 char_u *prev_ptr = ptr; | |
3309 #endif | |
3310 while (vcol < v && *ptr != NUL) | |
3311 { | |
3312 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3313 vcol += c; | |
3314 #ifdef FEAT_MBYTE | |
3315 prev_ptr = ptr; | |
39 | 3316 #endif |
3317 mb_ptr_adv(ptr); | |
7 | 3318 } |
3319 | |
1984 | 3320 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3321 /* When: | |
3322 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3323 * - 'colorcolumn' is set, or |
1984 | 3324 * - 'virtualedit' is set, or |
3325 * - the visual mode is active, | |
3326 * the end of the line may be before the start of the displayed part. | |
3327 */ | |
3328 if (vcol < v && ( | |
3329 # ifdef FEAT_SYN_HL | |
3330 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3331 || draw_color_col |
1984 | 3332 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3333 || | |
3334 # endif | |
3335 # endif | |
3336 # ifdef FEAT_VIRTUALEDIT | |
3337 virtual_active() | |
3338 # ifdef FEAT_VISUAL | |
3339 || | |
3340 # endif | |
3341 # endif | |
3342 # ifdef FEAT_VISUAL | |
3343 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3344 # endif | |
3345 )) | |
3346 { | |
7 | 3347 vcol = v; |
1984 | 3348 } |
7 | 3349 #endif |
3350 | |
3351 /* Handle a character that's not completely on the screen: Put ptr at | |
3352 * that character but skip the first few screen characters. */ | |
3353 if (vcol > v) | |
3354 { | |
3355 vcol -= c; | |
3356 #ifdef FEAT_MBYTE | |
3357 ptr = prev_ptr; | |
3358 #else | |
3359 --ptr; | |
3360 #endif | |
3361 n_skip = v - vcol; | |
3362 } | |
3363 | |
3364 /* | |
3365 * Adjust for when the inverted text is before the screen, | |
3366 * and when the start of the inverted text is before the screen. | |
3367 */ | |
3368 if (tocol <= vcol) | |
3369 fromcol = 0; | |
3370 else if (fromcol >= 0 && fromcol < vcol) | |
3371 fromcol = vcol; | |
3372 | |
3373 #ifdef FEAT_LINEBREAK | |
3374 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3375 if (wp->w_p_wrap) | |
3376 need_showbreak = TRUE; | |
3377 #endif | |
743 | 3378 #ifdef FEAT_SPELL |
499 | 3379 /* When spell checking a word we need to figure out the start of the |
3380 * word and if it's badly spelled or not. */ | |
3381 if (has_spell) | |
3382 { | |
3383 int len; | |
1536 | 3384 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3385 hlf_T spell_hlf = HLF_COUNT; |
499 | 3386 |
3387 pos = wp->w_cursor; | |
3388 wp->w_cursor.lnum = lnum; | |
1536 | 3389 wp->w_cursor.col = linecol; |
534 | 3390 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3391 |
3392 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3393 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3394 ptr = line + linecol; | |
3395 | |
530 | 3396 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3397 { |
3398 /* no bad word found at line start, don't check until end of a | |
3399 * word */ | |
534 | 3400 spell_hlf = HLF_COUNT; |
3572 | 3401 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
499 | 3402 } |
3403 else | |
534 | 3404 { |
499 | 3405 /* bad word found, use attributes until end of word */ |
3406 word_end = wp->w_cursor.col + len + 1; | |
3407 | |
534 | 3408 /* Turn index into actual attributes. */ |
3409 if (spell_hlf != HLF_COUNT) | |
3410 spell_attr = highlight_attr[spell_hlf]; | |
3411 } | |
499 | 3412 wp->w_cursor = pos; |
501 | 3413 |
743 | 3414 # ifdef FEAT_SYN_HL |
501 | 3415 /* Need to restart syntax highlighting for this line. */ |
3416 if (has_syntax) | |
3417 syntax_start(wp, lnum); | |
743 | 3418 # endif |
499 | 3419 } |
3420 #endif | |
7 | 3421 } |
3422 | |
3423 /* | |
3424 * Correct highlighting for cursor that can't be disabled. | |
3425 * Avoids having to check this for each character. | |
3426 */ | |
3427 if (fromcol >= 0) | |
3428 { | |
3429 if (noinvcur) | |
3430 { | |
3431 if ((colnr_T)fromcol == wp->w_virtcol) | |
3432 { | |
3433 /* highlighting starts at cursor, let it start just after the | |
3434 * cursor */ | |
3435 fromcol_prev = fromcol; | |
3436 fromcol = -1; | |
3437 } | |
3438 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3439 /* restart highlighting after the cursor */ | |
3440 fromcol_prev = wp->w_virtcol; | |
3441 } | |
3442 if (fromcol >= tocol) | |
3443 fromcol = -1; | |
3444 } | |
3445 | |
3446 #ifdef FEAT_SEARCH_EXTRA | |
3447 /* | |
1326 | 3448 * Handle highlighting the last used search pattern and matches. |
3449 * Do this for both search_hl and the match list. | |
7 | 3450 */ |
1326 | 3451 cur = wp->w_match_head; |
3452 shl_flag = FALSE; | |
3453 while (cur != NULL || shl_flag == FALSE) | |
3454 { | |
3455 if (shl_flag == FALSE) | |
3456 { | |
3457 shl = &search_hl; | |
3458 shl_flag = TRUE; | |
3459 } | |
3460 else | |
3461 shl = &cur->hl; | |
36 | 3462 shl->startcol = MAXCOL; |
3463 shl->endcol = MAXCOL; | |
7 | 3464 shl->attr_cur = 0; |
3465 if (shl->rm.regprog != NULL) | |
3466 { | |
3467 v = (long)(ptr - line); | |
3468 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3469 | |
3470 /* Need to get the line again, a multi-line regexp may have made it | |
3471 * invalid. */ | |
3472 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3473 ptr = line + v; | |
3474 | |
3475 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3476 { | |
3477 if (shl->lnum == lnum) | |
36 | 3478 shl->startcol = shl->rm.startpos[0].col; |
7 | 3479 else |
36 | 3480 shl->startcol = 0; |
7 | 3481 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3482 - shl->rm.startpos[0].lnum) | |
36 | 3483 shl->endcol = shl->rm.endpos[0].col; |
7 | 3484 else |
36 | 3485 shl->endcol = MAXCOL; |
7 | 3486 /* Highlight one character for an empty match. */ |
36 | 3487 if (shl->startcol == shl->endcol) |
7 | 3488 { |
3489 #ifdef FEAT_MBYTE | |
36 | 3490 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3491 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3492 else |
3493 #endif | |
36 | 3494 ++shl->endcol; |
7 | 3495 } |
36 | 3496 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3497 { |
3498 shl->attr_cur = shl->attr; | |
3499 search_attr = shl->attr; | |
3500 } | |
3501 area_highlighting = TRUE; | |
3502 } | |
3503 } | |
1326 | 3504 if (shl != &search_hl && cur != NULL) |
3505 cur = cur->next; | |
7 | 3506 } |
3507 #endif | |
3508 | |
743 | 3509 #ifdef FEAT_SYN_HL |
5068
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3510 /* Cursor line highlighting for 'cursorline' in the current window. Not |
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3511 * when Visual mode is active, because it's not clear what is selected |
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3512 * then. */ |
5078
22ac43fb6d30
updated for version 7.3.1282
Bram Moolenaar <bram@vim.org>
parents:
5068
diff
changeset
|
3513 if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
22ac43fb6d30
updated for version 7.3.1282
Bram Moolenaar <bram@vim.org>
parents:
5068
diff
changeset
|
3514 && !(wp == curwin && VIsual_active)) |
743 | 3515 { |
3516 line_attr = hl_attr(HLF_CUL); | |
3517 area_highlighting = TRUE; | |
3518 } | |
3519 #endif | |
3520 | |
504 | 3521 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3522 col = 0; |
3523 #ifdef FEAT_RIGHTLEFT | |
3524 if (wp->w_p_rl) | |
3525 { | |
3526 /* Rightleft window: process the text in the normal direction, but put | |
3527 * it in current_ScreenLine[] from right to left. Start at the | |
3528 * rightmost column of the window. */ | |
3529 col = W_WIDTH(wp) - 1; | |
3530 off += col; | |
3531 } | |
3532 #endif | |
3533 | |
3534 /* | |
3535 * Repeat for the whole displayed line. | |
3536 */ | |
3537 for (;;) | |
3538 { | |
3539 /* Skip this quickly when working on the text. */ | |
3540 if (draw_state != WL_LINE) | |
3541 { | |
3542 #ifdef FEAT_CMDWIN | |
3543 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3544 { | |
3545 draw_state = WL_CMDLINE; | |
3546 if (cmdwin_type != 0 && wp == curwin) | |
3547 { | |
3548 /* Draw the cmdline character. */ | |
3549 n_extra = 1; | |
1340 | 3550 c_extra = cmdwin_type; |
7 | 3551 char_attr = hl_attr(HLF_AT); |
3552 } | |
3553 } | |
3554 #endif | |
3555 | |
3556 #ifdef FEAT_FOLDING | |
3557 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3558 { | |
3559 draw_state = WL_FOLD; | |
3560 if (wp->w_p_fdc > 0) | |
3561 { | |
3562 /* Draw the 'foldcolumn'. */ | |
3563 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3564 n_extra = wp->w_p_fdc; | |
3565 p_extra = extra; | |
1340 | 3566 p_extra[n_extra] = NUL; |
7 | 3567 c_extra = NUL; |
3568 char_attr = hl_attr(HLF_FC); | |
3569 } | |
3570 } | |
3571 #endif | |
3572 | |
3573 #ifdef FEAT_SIGNS | |
3574 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3575 { | |
3576 draw_state = WL_SIGN; | |
3577 /* Show the sign column when there are any signs in this | |
3578 * buffer or when using Netbeans. */ | |
3579 if (draw_signcolumn(wp) | |
3580 # ifdef FEAT_DIFF | |
3581 && filler_todo <= 0 | |
3582 # endif | |
3583 ) | |
3584 { | |
2661 | 3585 int text_sign; |
7 | 3586 # ifdef FEAT_SIGN_ICONS |
2661 | 3587 int icon_sign; |
7 | 3588 # endif |
3589 | |
3590 /* Draw two cells with the sign value or blank. */ | |
3591 c_extra = ' '; | |
3592 char_attr = hl_attr(HLF_SC); | |
3593 n_extra = 2; | |
3594 | |
3595 if (row == startrow) | |
3596 { | |
3597 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3598 SIGN_TEXT); | |
3599 # ifdef FEAT_SIGN_ICONS | |
3600 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3601 SIGN_ICON); | |
3602 if (gui.in_use && icon_sign != 0) | |
3603 { | |
3604 /* Use the image in this position. */ | |
3605 c_extra = SIGN_BYTE; | |
3606 # ifdef FEAT_NETBEANS_INTG | |
3607 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3608 c_extra = MULTISIGN_BYTE; | |
3609 # endif | |
3610 char_attr = icon_sign; | |
3611 } | |
3612 else | |
3613 # endif | |
3614 if (text_sign != 0) | |
3615 { | |
3616 p_extra = sign_get_text(text_sign); | |
3617 if (p_extra != NULL) | |
3618 { | |
3619 c_extra = NUL; | |
835 | 3620 n_extra = (int)STRLEN(p_extra); |
7 | 3621 } |
3622 char_attr = sign_get_attr(text_sign, FALSE); | |
3623 } | |
3624 } | |
3625 } | |
3626 } | |
3627 #endif | |
3628 | |
3629 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3630 { | |
3631 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3632 /* Display the absolute or relative line number. After the |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3633 * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3634 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3635 && (row == startrow |
3636 #ifdef FEAT_DIFF | |
3637 + filler_lines | |
3638 #endif | |
3639 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3640 { | |
3641 /* Draw the line number (empty space after wrapping). */ | |
3642 if (row == startrow | |
3643 #ifdef FEAT_DIFF | |
3644 + filler_lines | |
3645 #endif | |
3646 ) | |
3647 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3648 long num; |
4065 | 3649 char *fmt = "%*ld "; |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3650 |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3651 if (wp->w_p_nu && !wp->w_p_rnu) |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3652 /* 'number' + 'norelativenumber' */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3653 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3654 else |
4065 | 3655 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3656 /* 'relativenumber', don't use negative numbers */ |
2675 | 3657 num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3658 if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
4065 | 3659 { |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3660 /* 'number' + 'relativenumber' */ |
4065 | 3661 num = lnum; |
3662 fmt = "%-*ld "; | |
3663 } | |
3664 } | |
3665 | |
3666 sprintf((char *)extra, fmt, | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3667 number_width(wp), num); |
7 | 3668 if (wp->w_skipcol > 0) |
3669 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3670 *p_extra = '-'; | |
3671 #ifdef FEAT_RIGHTLEFT | |
3672 if (wp->w_p_rl) /* reverse line numbers */ | |
3673 rl_mirror(extra); | |
3674 #endif | |
3675 p_extra = extra; | |
3676 c_extra = NUL; | |
3677 } | |
3678 else | |
3679 c_extra = ' '; | |
13 | 3680 n_extra = number_width(wp) + 1; |
7 | 3681 char_attr = hl_attr(HLF_N); |
743 | 3682 #ifdef FEAT_SYN_HL |
3683 /* When 'cursorline' is set highlight the line number of | |
3427 | 3684 * the current line differently. |
3685 * TODO: Can we use CursorLine instead of CursorLineNr | |
3686 * when CursorLineNr isn't set? */ | |
5078
22ac43fb6d30
updated for version 7.3.1282
Bram Moolenaar <bram@vim.org>
parents:
5068
diff
changeset
|
3687 if ((wp->w_p_cul || wp->w_p_rnu) |
4065 | 3688 && lnum == wp->w_cursor.lnum) |
3427 | 3689 char_attr = hl_attr(HLF_CLN); |
743 | 3690 #endif |
7 | 3691 } |
3692 } | |
3693 | |
3694 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3695 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3696 { | |
3697 draw_state = WL_SBR; | |
3698 # ifdef FEAT_DIFF | |
3699 if (filler_todo > 0) | |
3700 { | |
3701 /* Draw "deleted" diff line(s). */ | |
3702 if (char2cells(fill_diff) > 1) | |
3703 c_extra = '-'; | |
3704 else | |
3705 c_extra = fill_diff; | |
3706 # ifdef FEAT_RIGHTLEFT | |
3707 if (wp->w_p_rl) | |
3708 n_extra = col + 1; | |
3709 else | |
3710 # endif | |
3711 n_extra = W_WIDTH(wp) - col; | |
3712 char_attr = hl_attr(HLF_DED); | |
3713 } | |
3714 # endif | |
3715 # ifdef FEAT_LINEBREAK | |
3716 if (*p_sbr != NUL && need_showbreak) | |
3717 { | |
3718 /* Draw 'showbreak' at the start of each broken line. */ | |
3719 p_extra = p_sbr; | |
3720 c_extra = NUL; | |
3721 n_extra = (int)STRLEN(p_sbr); | |
3722 char_attr = hl_attr(HLF_AT); | |
3723 need_showbreak = FALSE; | |
3724 /* Correct end of highlighted area for 'showbreak', | |
3725 * required when 'linebreak' is also set. */ | |
3726 if (tocol == vcol) | |
3727 tocol += n_extra; | |
5068
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3728 #ifdef FEAT_SYN_HL |
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3729 /* combine 'showbreak' with 'cursorline' */ |
5078
22ac43fb6d30
updated for version 7.3.1282
Bram Moolenaar <bram@vim.org>
parents:
5068
diff
changeset
|
3730 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
5068
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3731 char_attr = hl_combine_attr(char_attr, HLF_CLN); |
6a7ae677d6a1
updated for version 7.3.1277
Bram Moolenaar <bram@vim.org>
parents:
4916
diff
changeset
|
3732 #endif |
7 | 3733 } |
3734 # endif | |
3735 } | |
3736 #endif | |
3737 | |
3738 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3739 { | |
3740 draw_state = WL_LINE; | |
3741 if (saved_n_extra) | |
3742 { | |
3743 /* Continue item from end of wrapped line. */ | |
3744 n_extra = saved_n_extra; | |
3745 c_extra = saved_c_extra; | |
3746 p_extra = saved_p_extra; | |
3747 char_attr = saved_char_attr; | |
3748 } | |
3749 else | |
3750 char_attr = 0; | |
3751 } | |
3752 } | |
3753 | |
3754 /* When still displaying '$' of change command, stop at cursor */ | |
3318 | 3755 if (dollar_vcol >= 0 && wp == curwin |
819 | 3756 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
7 | 3757 #ifdef FEAT_DIFF |
3758 && filler_todo <= 0 | |
3759 #endif | |
3760 ) | |
3761 { | |
3762 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3763 wp->w_p_rl); | |
819 | 3764 /* Pretend we have finished updating the window. Except when |
3765 * 'cursorcolumn' is set. */ | |
3766 #ifdef FEAT_SYN_HL | |
3767 if (wp->w_p_cuc) | |
3768 row = wp->w_cline_row + wp->w_cline_height; | |
3769 else | |
3770 #endif | |
3771 row = wp->w_height; | |
7 | 3772 break; |
3773 } | |
3774 | |
3775 if (draw_state == WL_LINE && area_highlighting) | |
3776 { | |
3777 /* handle Visual or match highlighting in this line */ | |
3778 if (vcol == fromcol | |
3779 #ifdef FEAT_MBYTE | |
3780 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3781 && (*mb_ptr2cells)(ptr) > 1) | |
3782 #endif | |
3783 || ((int)vcol_prev == fromcol_prev | |
1814 | 3784 && vcol_prev < vcol /* not at margin */ |
7 | 3785 && vcol < tocol)) |
3786 area_attr = attr; /* start highlighting */ | |
3787 else if (area_attr != 0 | |
3788 && (vcol == tocol | |
3789 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3790 area_attr = 0; /* stop highlighting */ | |
3791 | |
3792 #ifdef FEAT_SEARCH_EXTRA | |
3793 if (!n_extra) | |
3794 { | |
3795 /* | |
3796 * Check for start/end of search pattern match. | |
3797 * After end, check for start/end of next match. | |
3798 * When another match, have to check for start again. | |
3799 * Watch out for matching an empty string! | |
1326 | 3800 * Do this for 'search_hl' and the match list (ordered by |
3801 * priority). | |
7 | 3802 */ |
36 | 3803 v = (long)(ptr - line); |
1326 | 3804 cur = wp->w_match_head; |
3805 shl_flag = FALSE; | |
3806 while (cur != NULL || shl_flag == FALSE) | |
3807 { | |
3808 if (shl_flag == FALSE | |
3809 && ((cur != NULL | |
3810 && cur->priority > SEARCH_HL_PRIORITY) | |
3811 || cur == NULL)) | |
3812 { | |
3813 shl = &search_hl; | |
3814 shl_flag = TRUE; | |
3815 } | |
3816 else | |
3817 shl = &cur->hl; | |
7 | 3818 while (shl->rm.regprog != NULL) |
3819 { | |
36 | 3820 if (shl->startcol != MAXCOL |
3821 && v >= (long)shl->startcol | |
3822 && v < (long)shl->endcol) | |
7 | 3823 { |
3824 shl->attr_cur = shl->attr; | |
3825 } | |
36 | 3826 else if (v == (long)shl->endcol) |
7 | 3827 { |
3828 shl->attr_cur = 0; | |
3829 | |
3830 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3831 | |
3832 /* Need to get the line again, a multi-line regexp | |
3833 * may have made it invalid. */ | |
3834 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3835 ptr = line + v; | |
3836 | |
3837 if (shl->lnum == lnum) | |
3838 { | |
36 | 3839 shl->startcol = shl->rm.startpos[0].col; |
7 | 3840 if (shl->rm.endpos[0].lnum == 0) |
36 | 3841 shl->endcol = shl->rm.endpos[0].col; |
7 | 3842 else |
36 | 3843 shl->endcol = MAXCOL; |
3844 | |
3845 if (shl->startcol == shl->endcol) | |
7 | 3846 { |
3847 /* highlight empty match, try again after | |
3848 * it */ | |
3849 #ifdef FEAT_MBYTE | |
3850 if (has_mbyte) | |
474 | 3851 shl->endcol += (*mb_ptr2len)(line |
36 | 3852 + shl->endcol); |
7 | 3853 else |
3854 #endif | |
36 | 3855 ++shl->endcol; |
7 | 3856 } |
3857 | |
3858 /* Loop to check if the match starts at the | |
3859 * current position */ | |
3860 continue; | |
3861 } | |
3862 } | |
3863 break; | |
3864 } | |
1326 | 3865 if (shl != &search_hl && cur != NULL) |
3866 cur = cur->next; | |
3867 } | |
3868 | |
3869 /* Use attributes from match with highest priority among | |
3870 * 'search_hl' and the match list. */ | |
3871 search_attr = search_hl.attr_cur; | |
3872 cur = wp->w_match_head; | |
3873 shl_flag = FALSE; | |
3874 while (cur != NULL || shl_flag == FALSE) | |
3875 { | |
3876 if (shl_flag == FALSE | |
3877 && ((cur != NULL | |
3878 && cur->priority > SEARCH_HL_PRIORITY) | |
3879 || cur == NULL)) | |
699 | 3880 { |
1326 | 3881 shl = &search_hl; |
3882 shl_flag = TRUE; | |
699 | 3883 } |
1326 | 3884 else |
3885 shl = &cur->hl; | |
3886 if (shl->attr_cur != 0) | |
3887 search_attr = shl->attr_cur; | |
3888 if (shl != &search_hl && cur != NULL) | |
3889 cur = cur->next; | |
3890 } | |
7 | 3891 } |
3892 #endif | |
3893 | |
3894 #ifdef FEAT_DIFF | |
674 | 3895 if (diff_hlf != (hlf_T)0) |
7 | 3896 { |
1295 | 3897 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3898 && n_extra == 0) | |
7 | 3899 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3900 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3901 && n_extra == 0) | |
7 | 3902 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3903 line_attr = hl_attr(diff_hlf); |
3904 } | |
3905 #endif | |
3906 | |
3907 /* Decide which of the highlight attributes to use. */ | |
3908 attr_pri = TRUE; | |
3909 if (area_attr != 0) | |
3910 char_attr = area_attr; | |
3911 else if (search_attr != 0) | |
3912 char_attr = search_attr; | |
3913 #ifdef LINE_ATTR | |
3914 /* Use line_attr when not in the Visual or 'incsearch' area | |
3915 * (area_attr may be 0 when "noinvcur" is set). */ | |
3916 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3917 || vcol < fromcol || vcol_prev < fromcol_prev |
3918 || vcol >= tocol)) | |
674 | 3919 char_attr = line_attr; |
3920 #endif | |
3921 else | |
3922 { | |
3923 attr_pri = FALSE; | |
3924 #ifdef FEAT_SYN_HL | |
3925 if (has_syntax) | |
3926 char_attr = syntax_attr; | |
3927 else | |
3928 #endif | |
3929 char_attr = 0; | |
3930 } | |
7 | 3931 } |
3932 | |
3933 /* | |
3934 * Get the next character to put on the screen. | |
3935 */ | |
3936 /* | |
1340 | 3937 * The "p_extra" points to the extra stuff that is inserted to |
3938 * represent special characters (non-printable stuff) and other | |
3939 * things. When all characters are the same, c_extra is used. | |
3940 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3941 * "p_extra[n_extra]". | |
7 | 3942 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3943 */ | |
3944 if (n_extra > 0) | |
3945 { | |
3946 if (c_extra != NUL) | |
3947 { | |
3948 c = c_extra; | |
3949 #ifdef FEAT_MBYTE | |
3950 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3951 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3952 { | |
3953 mb_utf8 = TRUE; | |
714 | 3954 u8cc[0] = 0; |
819 | 3955 c = 0xc0; |
7 | 3956 } |
3957 else | |
3958 mb_utf8 = FALSE; | |
3959 #endif | |
3960 } | |
3961 else | |
3962 { | |
3963 c = *p_extra; | |
3964 #ifdef FEAT_MBYTE | |
3965 if (has_mbyte) | |
3966 { | |
3967 mb_c = c; | |
3968 if (enc_utf8) | |
3969 { | |
3970 /* If the UTF-8 character is more than one byte: | |
3971 * Decode it into "mb_c". */ | |
474 | 3972 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3973 mb_utf8 = FALSE; |
3974 if (mb_l > n_extra) | |
3975 mb_l = 1; | |
3976 else if (mb_l > 1) | |
3977 { | |
714 | 3978 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3979 mb_utf8 = TRUE; |
819 | 3980 c = 0xc0; |
7 | 3981 } |
3982 } | |
3983 else | |
3984 { | |
3985 /* if this is a DBCS character, put it in "mb_c" */ | |
3986 mb_l = MB_BYTE2LEN(c); | |
3987 if (mb_l >= n_extra) | |
3988 mb_l = 1; | |
3989 else if (mb_l > 1) | |
3990 mb_c = (c << 8) + p_extra[1]; | |
3991 } | |
504 | 3992 if (mb_l == 0) /* at the NUL at end-of-line */ |
3993 mb_l = 1; | |
3994 | |
7 | 3995 /* If a double-width char doesn't fit display a '>' in the |
3996 * last column. */ | |
504 | 3997 if (( |
7 | 3998 # ifdef FEAT_RIGHTLEFT |
3999 wp->w_p_rl ? (col <= 0) : | |
4000 # endif | |
504 | 4001 (col >= W_WIDTH(wp) - 1)) |
7 | 4002 && (*mb_char2cells)(mb_c) == 2) |
4003 { | |
4004 c = '>'; | |
4005 mb_c = c; | |
4006 mb_l = 1; | |
4007 mb_utf8 = FALSE; | |
4008 multi_attr = hl_attr(HLF_AT); | |
4009 /* put the pointer back to output the double-width | |
4010 * character at the start of the next line. */ | |
4011 ++n_extra; | |
4012 --p_extra; | |
4013 } | |
4014 else | |
4015 { | |
4016 n_extra -= mb_l - 1; | |
4017 p_extra += mb_l - 1; | |
4018 } | |
4019 } | |
4020 #endif | |
4021 ++p_extra; | |
4022 } | |
4023 --n_extra; | |
4024 } | |
4025 else | |
4026 { | |
4027 /* | |
4028 * Get a character from the line itself. | |
4029 */ | |
4030 c = *ptr; | |
4031 #ifdef FEAT_MBYTE | |
4032 if (has_mbyte) | |
4033 { | |
4034 mb_c = c; | |
4035 if (enc_utf8) | |
4036 { | |
4037 /* If the UTF-8 character is more than one byte: Decode it | |
4038 * into "mb_c". */ | |
474 | 4039 mb_l = (*mb_ptr2len)(ptr); |
7 | 4040 mb_utf8 = FALSE; |
4041 if (mb_l > 1) | |
4042 { | |
714 | 4043 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 4044 /* Overlong encoded ASCII or ASCII with composing char |
4045 * is displayed normally, except a NUL. */ | |
4046 if (mb_c < 0x80) | |
4047 c = mb_c; | |
4048 mb_utf8 = TRUE; | |
507 | 4049 |
4050 /* At start of the line we can have a composing char. | |
4051 * Draw it as a space with a composing char. */ | |
4052 if (utf_iscomposing(mb_c)) | |
4053 { | |
1326 | 4054 int i; |
4055 | |
714 | 4056 for (i = Screen_mco - 1; i > 0; --i) |
4057 u8cc[i] = u8cc[i - 1]; | |
4058 u8cc[0] = mb_c; | |
507 | 4059 mb_c = ' '; |
4060 } | |
7 | 4061 } |
4062 | |
4063 if ((mb_l == 1 && c >= 0x80) | |
4064 || (mb_l >= 1 && mb_c == 0) | |
4065 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 4066 # ifdef UNICODE16 |
4067 || mb_c >= 0x10000 | |
4068 # endif | |
4069 ))) | |
7 | 4070 { |
4071 /* | |
4072 * Illegal UTF-8 byte: display as <xx>. | |
4073 * Non-BMP character : display as ? or fullwidth ?. | |
4074 */ | |
1401 | 4075 # ifdef UNICODE16 |
7 | 4076 if (mb_c < 0x10000) |
1401 | 4077 # endif |
7 | 4078 { |
4079 transchar_hex(extra, mb_c); | |
714 | 4080 # ifdef FEAT_RIGHTLEFT |
7 | 4081 if (wp->w_p_rl) /* reverse */ |
4082 rl_mirror(extra); | |
714 | 4083 # endif |
7 | 4084 } |
1401 | 4085 # ifdef UNICODE16 |
7 | 4086 else if (utf_char2cells(mb_c) != 2) |
4087 STRCPY(extra, "?"); | |
4088 else | |
4089 /* 0xff1f in UTF-8: full-width '?' */ | |
4090 STRCPY(extra, "\357\274\237"); | |
1401 | 4091 # endif |
7 | 4092 |
4093 p_extra = extra; | |
4094 c = *p_extra; | |
4095 mb_c = mb_ptr2char_adv(&p_extra); | |
4096 mb_utf8 = (c >= 0x80); | |
4097 n_extra = (int)STRLEN(p_extra); | |
4098 c_extra = NUL; | |
4099 if (area_attr == 0 && search_attr == 0) | |
4100 { | |
4101 n_attr = n_extra + 1; | |
4102 extra_attr = hl_attr(HLF_8); | |
4103 saved_attr2 = char_attr; /* save current attr */ | |
4104 } | |
4105 } | |
4106 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
4107 mb_l = 1; | |
4108 #ifdef FEAT_ARABIC | |
4109 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
4110 { | |
4111 /* Do Arabic shaping. */ | |
714 | 4112 int pc, pc1, nc; |
4113 int pcc[MAX_MCO]; | |
7 | 4114 |
4115 /* The idea of what is the previous and next | |
4116 * character depends on 'rightleft'. */ | |
4117 if (wp->w_p_rl) | |
4118 { | |
4119 pc = prev_c; | |
4120 pc1 = prev_c1; | |
4121 nc = utf_ptr2char(ptr + mb_l); | |
714 | 4122 prev_c1 = u8cc[0]; |
7 | 4123 } |
4124 else | |
4125 { | |
714 | 4126 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 4127 nc = prev_c; |
714 | 4128 pc1 = pcc[0]; |
7 | 4129 } |
4130 prev_c = mb_c; | |
4131 | |
714 | 4132 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 4133 } |
4134 else | |
4135 prev_c = mb_c; | |
4136 #endif | |
4137 } | |
4138 else /* enc_dbcs */ | |
4139 { | |
4140 mb_l = MB_BYTE2LEN(c); | |
4141 if (mb_l == 0) /* at the NUL at end-of-line */ | |
4142 mb_l = 1; | |
4143 else if (mb_l > 1) | |
4144 { | |
4145 /* We assume a second byte below 32 is illegal. | |
4146 * Hopefully this is OK for all double-byte encodings! | |
4147 */ | |
4148 if (ptr[1] >= 32) | |
4149 mb_c = (c << 8) + ptr[1]; | |
4150 else | |
4151 { | |
4152 if (ptr[1] == NUL) | |
4153 { | |
4154 /* head byte at end of line */ | |
4155 mb_l = 1; | |
4156 transchar_nonprint(extra, c); | |
4157 } | |
4158 else | |
4159 { | |
4160 /* illegal tail byte */ | |
4161 mb_l = 2; | |
4162 STRCPY(extra, "XX"); | |
4163 } | |
4164 p_extra = extra; | |
4165 n_extra = (int)STRLEN(extra) - 1; | |
4166 c_extra = NUL; | |
4167 c = *p_extra++; | |
4168 if (area_attr == 0 && search_attr == 0) | |
4169 { | |
4170 n_attr = n_extra + 1; | |
4171 extra_attr = hl_attr(HLF_8); | |
4172 saved_attr2 = char_attr; /* save current attr */ | |
4173 } | |
4174 mb_c = c; | |
4175 } | |
4176 } | |
4177 } | |
4178 /* If a double-width char doesn't fit display a '>' in the | |
4179 * last column; the character is displayed at the start of the | |
4180 * next line. */ | |
4181 if (( | |
4182 # ifdef FEAT_RIGHTLEFT | |
4183 wp->w_p_rl ? (col <= 0) : | |
4184 # endif | |
4185 (col >= W_WIDTH(wp) - 1)) | |
4186 && (*mb_char2cells)(mb_c) == 2) | |
4187 { | |
4188 c = '>'; | |
4189 mb_c = c; | |
4190 mb_utf8 = FALSE; | |
4191 mb_l = 1; | |
4192 multi_attr = hl_attr(HLF_AT); | |
4193 /* Put pointer back so that the character will be | |
4194 * displayed at the start of the next line. */ | |
4195 --ptr; | |
4196 } | |
4197 else if (*ptr != NUL) | |
4198 ptr += mb_l - 1; | |
4199 | |
4200 /* If a double-width char doesn't fit at the left side display | |
2509
6d6378ba18cb
Fix: An unprintable multi-byte character at the start of the screen line
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
4201 * a '<' in the first column. Don't do this for unprintable |
4352 | 4202 * characters. */ |
2509
6d6378ba18cb
Fix: An unprintable multi-byte character at the start of the screen line
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
4203 if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
7 | 4204 { |
4205 n_extra = 1; | |
3586 | 4206 c_extra = MB_FILLER_CHAR; |
7 | 4207 c = ' '; |
4208 if (area_attr == 0 && search_attr == 0) | |
4209 { | |
4210 n_attr = n_extra + 1; | |
4211 extra_attr = hl_attr(HLF_AT); | |
4212 saved_attr2 = char_attr; /* save current attr */ | |
4213 } | |
4214 mb_c = c; | |
4215 mb_utf8 = FALSE; | |
4216 mb_l = 1; | |
4217 } | |
4218 | |
4219 } | |
4220 #endif | |
4221 ++ptr; | |
4222 | |
12 | 4223 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 4224 if (wp->w_p_list && (c == 160 |
4225 #ifdef FEAT_MBYTE | |
4226 || (mb_utf8 && mb_c == 160) | |
4227 #endif | |
4228 ) && lcs_nbsp) | |
12 | 4229 { |
4230 c = lcs_nbsp; | |
4231 if (area_attr == 0 && search_attr == 0) | |
4232 { | |
4233 n_attr = 1; | |
4234 extra_attr = hl_attr(HLF_8); | |
4235 saved_attr2 = char_attr; /* save current attr */ | |
4236 } | |
4237 #ifdef FEAT_MBYTE | |
4238 mb_c = c; | |
4239 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4240 { | |
4241 mb_utf8 = TRUE; | |
714 | 4242 u8cc[0] = 0; |
819 | 4243 c = 0xc0; |
12 | 4244 } |
4245 else | |
4246 mb_utf8 = FALSE; | |
4247 #endif | |
4248 } | |
4249 | |
7 | 4250 if (extra_check) |
4251 { | |
743 | 4252 #ifdef FEAT_SPELL |
221 | 4253 int can_spell = TRUE; |
743 | 4254 #endif |
4255 | |
4256 #ifdef FEAT_SYN_HL | |
7 | 4257 /* Get syntax attribute, unless still at the start of the line |
4258 * (double-wide char that doesn't fit). */ | |
221 | 4259 v = (long)(ptr - line); |
4260 if (has_syntax && v > 0) | |
7 | 4261 { |
4262 /* Get the syntax attribute for the character. If there | |
4263 * is an error, disable syntax highlighting. */ | |
4264 save_did_emsg = did_emsg; | |
4265 did_emsg = FALSE; | |
4266 | |
221 | 4267 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 4268 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4269 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4270 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4271 NULL, FALSE); |
7 | 4272 |
4273 if (did_emsg) | |
482 | 4274 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4275 wp->w_s->b_syn_error = TRUE; |
482 | 4276 has_syntax = FALSE; |
4277 } | |
7 | 4278 else |
4279 did_emsg = save_did_emsg; | |
4280 | |
4281 /* Need to get the line again, a multi-line regexp may | |
4282 * have made it invalid. */ | |
4283 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4284 ptr = line + v; | |
4285 | |
674 | 4286 if (!attr_pri) |
7 | 4287 char_attr = syntax_attr; |
301 | 4288 else |
303 | 4289 char_attr = hl_combine_attr(syntax_attr, char_attr); |
2364
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4290 # ifdef FEAT_CONCEAL |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4291 /* no concealing past the end of the line, it interferes |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4292 * with line highlighting */ |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4293 if (c == NUL) |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4294 syntax_flags = 0; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4295 else |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
4296 syntax_flags = get_syntax_info(&syntax_seqnr); |
2364
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4297 # endif |
7 | 4298 } |
743 | 4299 #endif |
4300 | |
4301 #ifdef FEAT_SPELL | |
301 | 4302 /* Check spelling (unless at the end of the line). |
319 | 4303 * Only do this when there is no syntax highlighting, the |
4304 * @Spell cluster is not used or the current syntax item | |
4305 * contains the @Spell cluster. */ | |
348 | 4306 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4307 { |
230 | 4308 spell_attr = 0; |
743 | 4309 # ifdef FEAT_SYN_HL |
674 | 4310 if (!attr_pri) |
230 | 4311 char_attr = syntax_attr; |
743 | 4312 # endif |
4313 if (c != 0 && ( | |
4314 # ifdef FEAT_SYN_HL | |
4315 !has_syntax || | |
4316 # endif | |
4317 can_spell)) | |
221 | 4318 { |
348 | 4319 char_u *prev_ptr, *p; |
4320 int len; | |
534 | 4321 hlf_T spell_hlf = HLF_COUNT; |
221 | 4322 # ifdef FEAT_MBYTE |
336 | 4323 if (has_mbyte) |
4324 { | |
4325 prev_ptr = ptr - mb_l; | |
4326 v -= mb_l - 1; | |
4327 } | |
4328 else | |
221 | 4329 # endif |
336 | 4330 prev_ptr = ptr - 1; |
348 | 4331 |
4332 /* Use nextline[] if possible, it has the start of the | |
4333 * next line concatenated. */ | |
4334 if ((prev_ptr - line) - nextlinecol >= 0) | |
4335 p = nextline + (prev_ptr - line) - nextlinecol; | |
4336 else | |
4337 p = prev_ptr; | |
835 | 4338 cap_col -= (int)(prev_ptr - line); |
625 | 4339 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4340 nochange); | |
348 | 4341 word_end = v + len; |
301 | 4342 |
4343 /* In Insert mode only highlight a word that | |
4344 * doesn't touch the cursor. */ | |
534 | 4345 if (spell_hlf != HLF_COUNT |
301 | 4346 && (State & INSERT) != 0 |
4347 && wp->w_cursor.lnum == lnum | |
4348 && wp->w_cursor.col >= | |
4349 (colnr_T)(prev_ptr - line) | |
4350 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4351 { |
534 | 4352 spell_hlf = HLF_COUNT; |
301 | 4353 spell_redraw_lnum = lnum; |
221 | 4354 } |
348 | 4355 |
534 | 4356 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4357 && (p - nextline) + len > nextline_idx) |
4358 { | |
4359 /* Remember that the good word continues at the | |
4360 * start of the next line. */ | |
4361 checked_lnum = lnum + 1; | |
835 | 4362 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4363 } |
386 | 4364 |
534 | 4365 /* Turn index into actual attributes. */ |
4366 if (spell_hlf != HLF_COUNT) | |
4367 spell_attr = highlight_attr[spell_hlf]; | |
4368 | |
386 | 4369 if (cap_col > 0) |
4370 { | |
4371 if (p != prev_ptr | |
4372 && (p - nextline) + cap_col >= nextline_idx) | |
4373 { | |
4374 /* Remember that the word in the next line | |
4375 * must start with a capital. */ | |
4376 capcol_lnum = lnum + 1; | |
835 | 4377 cap_col = (int)((p - nextline) + cap_col |
4378 - nextline_idx); | |
386 | 4379 } |
4380 else | |
4381 /* Compute the actual column. */ | |
835 | 4382 cap_col += (int)(prev_ptr - line); |
386 | 4383 } |
221 | 4384 } |
4385 } | |
4386 if (spell_attr != 0) | |
348 | 4387 { |
674 | 4388 if (!attr_pri) |
348 | 4389 char_attr = hl_combine_attr(char_attr, spell_attr); |
4390 else | |
4391 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4392 } | |
7 | 4393 #endif |
4394 #ifdef FEAT_LINEBREAK | |
4395 /* | |
221 | 4396 * Found last space before word: check for line break. |
7 | 4397 */ |
4398 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4399 && !wp->w_p_list) |
7 | 4400 { |
4401 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4402 # ifdef FEAT_MBYTE | |
4403 has_mbyte ? mb_l : | |
4404 # endif | |
4405 1), (colnr_T)vcol, NULL) - 1; | |
4406 c_extra = ' '; | |
4407 if (vim_iswhite(c)) | |
4408 c = ' '; | |
4409 } | |
4410 #endif | |
4411 | |
4412 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4413 { | |
4414 c = lcs_trail; | |
674 | 4415 if (!attr_pri) |
7 | 4416 { |
4417 n_attr = 1; | |
4418 extra_attr = hl_attr(HLF_8); | |
4419 saved_attr2 = char_attr; /* save current attr */ | |
4420 } | |
4421 #ifdef FEAT_MBYTE | |
4422 mb_c = c; | |
4423 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4424 { | |
4425 mb_utf8 = TRUE; | |
714 | 4426 u8cc[0] = 0; |
819 | 4427 c = 0xc0; |
7 | 4428 } |
4429 else | |
4430 mb_utf8 = FALSE; | |
4431 #endif | |
4432 } | |
4433 } | |
4434 | |
4435 /* | |
4436 * Handling of non-printable characters. | |
4437 */ | |
819 | 4438 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4439 { |
4440 /* | |
4441 * when getting a character from the file, we may have to | |
4442 * turn it into something else on the way to putting it | |
4443 * into "ScreenLines". | |
4444 */ | |
4445 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4446 { | |
4447 /* tab amount depends on current column */ | |
4448 n_extra = (int)wp->w_buffer->b_p_ts | |
3984 | 4449 - vcol % (int)wp->w_buffer->b_p_ts - 1; |
4450 #ifdef FEAT_CONCEAL | |
4451 /* Tab alignment should be identical regardless of | |
4452 * 'conceallevel' value. So tab compensates of all | |
4453 * previous concealed characters, and thus resets vcol_off | |
4454 * and boguscols accumulated so far in the line. Note that | |
4455 * the tab can be longer than 'tabstop' when there | |
4456 * are concealed characters. */ | |
4457 n_extra += vcol_off; | |
4458 vcol -= vcol_off; | |
4459 vcol_off = 0; | |
4460 col -= boguscols; | |
4461 boguscols = 0; | |
4462 #endif | |
7 | 4463 #ifdef FEAT_MBYTE |
4464 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4465 #endif | |
4466 if (wp->w_p_list) | |
4467 { | |
4468 c = lcs_tab1; | |
4469 c_extra = lcs_tab2; | |
4470 n_attr = n_extra + 1; | |
4471 extra_attr = hl_attr(HLF_8); | |
4472 saved_attr2 = char_attr; /* save current attr */ | |
4473 #ifdef FEAT_MBYTE | |
4474 mb_c = c; | |
4475 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4476 { | |
4477 mb_utf8 = TRUE; | |
714 | 4478 u8cc[0] = 0; |
819 | 4479 c = 0xc0; |
7 | 4480 } |
4481 #endif | |
4482 } | |
4483 else | |
4484 { | |
4485 c_extra = ' '; | |
4486 c = ' '; | |
4487 } | |
4488 } | |
36 | 4489 else if (c == NUL |
4490 && ((wp->w_p_list && lcs_eol > 0) | |
4491 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4492 && tocol > vcol | |
39 | 4493 #ifdef FEAT_VISUAL |
36 | 4494 && VIsual_mode != Ctrl_V |
39 | 4495 #endif |
36 | 4496 && ( |
4497 # ifdef FEAT_RIGHTLEFT | |
4498 wp->w_p_rl ? (col >= 0) : | |
4499 # endif | |
4500 (col < W_WIDTH(wp))) | |
4501 && !(noinvcur | |
1850 | 4502 && lnum == wp->w_cursor.lnum |
36 | 4503 && (colnr_T)vcol == wp->w_virtcol))) |
4504 && lcs_eol_one >= 0) | |
7 | 4505 { |
36 | 4506 /* Display a '$' after the line or highlight an extra |
4507 * character if the line break is included. */ | |
7 | 4508 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4509 /* For a diff line the highlighting continues after the | |
4510 * "$". */ | |
4511 if ( | |
4512 # ifdef FEAT_DIFF | |
534 | 4513 diff_hlf == (hlf_T)0 |
7 | 4514 # ifdef LINE_ATTR |
4515 && | |
4516 # endif | |
4517 # endif | |
4518 # ifdef LINE_ATTR | |
4519 line_attr == 0 | |
4520 # endif | |
4521 ) | |
4522 #endif | |
4523 { | |
4524 #ifdef FEAT_VIRTUALEDIT | |
4525 /* In virtualedit, visual selections may extend | |
4526 * beyond end of line. */ | |
4527 if (area_highlighting && virtual_active() | |
4528 && tocol != MAXCOL && vcol < tocol) | |
4529 n_extra = 0; | |
4530 else | |
4531 #endif | |
4532 { | |
4533 p_extra = at_end_str; | |
4534 n_extra = 1; | |
4535 c_extra = NUL; | |
4536 } | |
4537 } | |
36 | 4538 if (wp->w_p_list) |
4539 c = lcs_eol; | |
4540 else | |
4541 c = ' '; | |
7 | 4542 lcs_eol_one = -1; |
4543 --ptr; /* put it back at the NUL */ | |
674 | 4544 if (!attr_pri) |
7 | 4545 { |
4546 extra_attr = hl_attr(HLF_AT); | |
4547 n_attr = 1; | |
4548 } | |
4549 #ifdef FEAT_MBYTE | |
4550 mb_c = c; | |
4551 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4552 { | |
4553 mb_utf8 = TRUE; | |
714 | 4554 u8cc[0] = 0; |
819 | 4555 c = 0xc0; |
7 | 4556 } |
4557 else | |
4558 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4559 #endif | |
4560 } | |
4561 else if (c != NUL) | |
4562 { | |
4563 p_extra = transchar(c); | |
4564 #ifdef FEAT_RIGHTLEFT | |
4565 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4566 rl_mirror(p_extra); /* reverse "<12>" */ | |
4567 #endif | |
4568 n_extra = byte2cells(c) - 1; | |
4569 c_extra = NUL; | |
4570 c = *p_extra++; | |
674 | 4571 if (!attr_pri) |
7 | 4572 { |
4573 n_attr = n_extra + 1; | |
4574 extra_attr = hl_attr(HLF_8); | |
4575 saved_attr2 = char_attr; /* save current attr */ | |
4576 } | |
4577 #ifdef FEAT_MBYTE | |
4578 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4579 #endif | |
4580 } | |
4581 #ifdef FEAT_VIRTUALEDIT | |
4582 else if (VIsual_active | |
4583 && (VIsual_mode == Ctrl_V | |
4584 || VIsual_mode == 'v') | |
4585 && virtual_active() | |
4586 && tocol != MAXCOL | |
4587 && vcol < tocol | |
4588 && ( | |
4589 # ifdef FEAT_RIGHTLEFT | |
4590 wp->w_p_rl ? (col >= 0) : | |
4591 # endif | |
4592 (col < W_WIDTH(wp)))) | |
4593 { | |
4594 c = ' '; | |
4595 --ptr; /* put it back at the NUL */ | |
4596 } | |
4597 #endif | |
910 | 4598 #if defined(LINE_ATTR) |
7 | 4599 else if (( |
4600 # ifdef FEAT_DIFF | |
910 | 4601 diff_hlf != (hlf_T)0 || |
7 | 4602 # endif |
4603 line_attr != 0 | |
4604 ) && ( | |
4605 # ifdef FEAT_RIGHTLEFT | |
4606 wp->w_p_rl ? (col >= 0) : | |
4607 # endif | |
2553
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4608 (col |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4609 # ifdef FEAT_CONCEAL |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4610 - boguscols |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4611 # endif |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4612 < W_WIDTH(wp)))) |
7 | 4613 { |
4614 /* Highlight until the right side of the window */ | |
4615 c = ' '; | |
4616 --ptr; /* put it back at the NUL */ | |
867 | 4617 |
4618 /* Remember we do the char for line highlighting. */ | |
4619 ++did_line_attr; | |
4620 | |
4621 /* don't do search HL for the rest of the line */ | |
4622 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4623 char_attr = line_attr; | |
7 | 4624 # ifdef FEAT_DIFF |
4625 if (diff_hlf == HLF_TXD) | |
4626 { | |
4627 diff_hlf = HLF_CHD; | |
4628 if (attr == 0 || char_attr != attr) | |
4629 char_attr = hl_attr(diff_hlf); | |
4630 } | |
4631 # endif | |
4632 } | |
4633 #endif | |
4634 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4635 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4636 #ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4637 if ( wp->w_p_cole > 0 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4638 && (wp != curwin || lnum != wp->w_cursor.lnum || |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4639 conceal_cursor_line(wp)) |
2380
b47748aa3236
Don't conceal text in lines inside the Visual area.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4640 && (syntax_flags & HL_CONCEAL) != 0 |
2400
e6f1424dd66a
Let 'v' flag in 'concealcursor' apply to all lines in the Visual area.
Bram Moolenaar <bram@vim.org>
parents:
2393
diff
changeset
|
4641 && !(lnum_in_visual_area |
e6f1424dd66a
Let 'v' flag in 'concealcursor' apply to all lines in the Visual area.
Bram Moolenaar <bram@vim.org>
parents:
2393
diff
changeset
|
4642 && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4643 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4644 char_attr = conceal_attr; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
4645 if (prev_syntax_id != syntax_seqnr |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4646 && (syn_get_sub_char() != NUL || wp->w_p_cole == 1) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4647 && wp->w_p_cole != 3) |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4648 { |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4649 /* First time at this concealed item: display one |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4650 * character. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4651 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4652 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4653 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4654 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4655 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4656 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4657 |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
4658 prev_syntax_id = syntax_seqnr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4659 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4660 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4661 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4662 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4663 if (wp->w_p_wrap && n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4664 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4665 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4666 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4667 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4668 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4669 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4670 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4671 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4672 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4673 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4674 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4675 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4676 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4677 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4678 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4679 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4680 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4681 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4682 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4683 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4684 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4685 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4686 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4687 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4688 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4689 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4690 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4691 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4692 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4693 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4694 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4695 mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4696 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4697 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4698 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4699 { |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4700 prev_syntax_id = 0; |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4701 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4702 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4703 #endif /* FEAT_CONCEAL */ |
7 | 4704 } |
4705 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4706 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4707 /* In the cursor line and we may be concealing characters: correct |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4708 * the cursor column when we reach its position. */ |
2381
17bbb52ae218
Another conceal fix: cursor in wrong column when 'number' set.
Bram Moolenaar <bram@vim.org>
parents:
2380
diff
changeset
|
4709 if (!did_wcol && draw_state == WL_LINE |
17bbb52ae218
Another conceal fix: cursor in wrong column when 'number' set.
Bram Moolenaar <bram@vim.org>
parents:
2380
diff
changeset
|
4710 && wp == curwin && lnum == wp->w_cursor.lnum |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4711 && conceal_cursor_line(wp) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4712 && (int)wp->w_virtcol <= vcol + n_skip) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4713 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4714 wp->w_wcol = col - boguscols; |
2393
210a5605e126
Fix for cursor position in wrapped line with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
4715 wp->w_wrow = row; |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4716 did_wcol = TRUE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4717 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4718 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4719 |
7 | 4720 /* Don't override visual selection highlighting. */ |
4721 if (n_attr > 0 | |
4722 && draw_state == WL_LINE | |
674 | 4723 && !attr_pri) |
7 | 4724 char_attr = extra_attr; |
4725 | |
42 | 4726 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4727 /* XIM don't send preedit_start and preedit_end, but they send |
4728 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4729 * im_is_preediting() here. */ | |
4730 if (xic != NULL | |
1850 | 4731 && lnum == wp->w_cursor.lnum |
7 | 4732 && (State & INSERT) |
4733 && !p_imdisable | |
4734 && im_is_preediting() | |
4735 && draw_state == WL_LINE) | |
4736 { | |
4737 colnr_T tcol; | |
4738 | |
4739 if (preedit_end_col == MAXCOL) | |
1850 | 4740 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4741 else |
4742 tcol = preedit_end_col; | |
4743 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4744 { | |
4745 if (feedback_old_attr < 0) | |
4746 { | |
4747 feedback_col = 0; | |
4748 feedback_old_attr = char_attr; | |
4749 } | |
4750 char_attr = im_get_feedback_attr(feedback_col); | |
4751 if (char_attr < 0) | |
4752 char_attr = feedback_old_attr; | |
4753 feedback_col++; | |
4754 } | |
4755 else if (feedback_old_attr >= 0) | |
4756 { | |
4757 char_attr = feedback_old_attr; | |
4758 feedback_old_attr = -1; | |
4759 feedback_col = 0; | |
4760 } | |
4761 } | |
4762 #endif | |
4763 /* | |
4764 * Handle the case where we are in column 0 but not on the first | |
4765 * character of the line and the user wants us to show us a | |
4766 * special character (via 'listchars' option "precedes:<char>". | |
4767 */ | |
4768 if (lcs_prec_todo != NUL | |
4769 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4770 #ifdef FEAT_DIFF | |
4771 && filler_todo <= 0 | |
4772 #endif | |
4773 && draw_state > WL_NR | |
4774 && c != NUL) | |
4775 { | |
4776 c = lcs_prec; | |
4777 lcs_prec_todo = NUL; | |
4778 #ifdef FEAT_MBYTE | |
3586 | 4779 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
4780 { | |
4781 /* Double-width character being overwritten by the "precedes" | |
4782 * character, need to fill up half the character. */ | |
4783 c_extra = MB_FILLER_CHAR; | |
4784 n_extra = 1; | |
4785 n_attr = 2; | |
4786 extra_attr = hl_attr(HLF_AT); | |
4787 } | |
7 | 4788 mb_c = c; |
4789 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4790 { | |
4791 mb_utf8 = TRUE; | |
714 | 4792 u8cc[0] = 0; |
819 | 4793 c = 0xc0; |
7 | 4794 } |
4795 else | |
4796 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4797 #endif | |
674 | 4798 if (!attr_pri) |
7 | 4799 { |
4800 saved_attr3 = char_attr; /* save current attr */ | |
4801 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4802 n_attr3 = 1; | |
4803 } | |
4804 } | |
4805 | |
4806 /* | |
867 | 4807 * At end of the text line or just after the last character. |
7 | 4808 */ |
867 | 4809 if (c == NUL |
910 | 4810 #if defined(LINE_ATTR) |
867 | 4811 || did_line_attr == 1 |
4812 #endif | |
4813 ) | |
4814 { | |
4815 #ifdef FEAT_SEARCH_EXTRA | |
4816 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4817 |
4818 /* we're not really at that column when skipping some text */ | |
1439 | 4819 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4820 ++prevcol; |
867 | 4821 #endif |
4822 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4823 /* Invert at least one char, used for Visual and empty line or |
7 | 4824 * highlight match at end of line. If it's beyond the last |
4825 * char on the screen, just overwrite that one (tricky!) Not | |
4826 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4827 #ifdef FEAT_SEARCH_EXTRA |
4828 prevcol_hl_flag = FALSE; | |
4829 if (prevcol == (long)search_hl.startcol) | |
4830 prevcol_hl_flag = TRUE; | |
4831 else | |
4832 { | |
4833 cur = wp->w_match_head; | |
4834 while (cur != NULL) | |
4835 { | |
4836 if (prevcol == (long)cur->hl.startcol) | |
4837 { | |
4838 prevcol_hl_flag = TRUE; | |
4839 break; | |
4840 } | |
4841 cur = cur->next; | |
4842 } | |
4843 } | |
4844 #endif | |
7 | 4845 if (lcs_eol == lcs_eol_one |
1850 | 4846 && ((area_attr != 0 && vcol == fromcol |
4847 #ifdef FEAT_VISUAL | |
4848 && (VIsual_mode != Ctrl_V | |
4849 || lnum == VIsual.lnum | |
4850 || lnum == curwin->w_cursor.lnum) | |
4851 #endif | |
4852 && c == NUL) | |
7 | 4853 #ifdef FEAT_SEARCH_EXTRA |
4854 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4855 || (prevcol_hl_flag == TRUE |
910 | 4856 # if defined(LINE_ATTR) |
867 | 4857 && did_line_attr <= 1 |
4858 # endif | |
4859 ) | |
7 | 4860 #endif |
4861 )) | |
4862 { | |
4863 int n = 0; | |
4864 | |
4865 #ifdef FEAT_RIGHTLEFT | |
4866 if (wp->w_p_rl) | |
4867 { | |
4868 if (col < 0) | |
4869 n = 1; | |
4870 } | |
4871 else | |
4872 #endif | |
4873 { | |
4874 if (col >= W_WIDTH(wp)) | |
4875 n = -1; | |
4876 } | |
4877 if (n != 0) | |
4878 { | |
4879 /* At the window boundary, highlight the last character | |
4880 * instead (better than nothing). */ | |
4881 off += n; | |
4882 col += n; | |
4883 } | |
4884 else | |
4885 { | |
4886 /* Add a blank character to highlight. */ | |
4887 ScreenLines[off] = ' '; | |
4888 #ifdef FEAT_MBYTE | |
4889 if (enc_utf8) | |
4890 ScreenLinesUC[off] = 0; | |
4891 #endif | |
4892 } | |
4893 #ifdef FEAT_SEARCH_EXTRA | |
4894 if (area_attr == 0) | |
4895 { | |
1326 | 4896 /* Use attributes from match with highest priority among |
4897 * 'search_hl' and the match list. */ | |
4898 char_attr = search_hl.attr; | |
4899 cur = wp->w_match_head; | |
4900 shl_flag = FALSE; | |
4901 while (cur != NULL || shl_flag == FALSE) | |
699 | 4902 { |
1326 | 4903 if (shl_flag == FALSE |
4904 && ((cur != NULL | |
4905 && cur->priority > SEARCH_HL_PRIORITY) | |
4906 || cur == NULL)) | |
699 | 4907 { |
1326 | 4908 shl = &search_hl; |
4909 shl_flag = TRUE; | |
699 | 4910 } |
1326 | 4911 else |
4912 shl = &cur->hl; | |
4913 if ((ptr - line) - 1 == (long)shl->startcol) | |
4914 char_attr = shl->attr; | |
4915 if (shl != &search_hl && cur != NULL) | |
4916 cur = cur->next; | |
699 | 4917 } |
7 | 4918 } |
4919 #endif | |
4920 ScreenAttrs[off] = char_attr; | |
4921 #ifdef FEAT_RIGHTLEFT | |
4922 if (wp->w_p_rl) | |
1437 | 4923 { |
7 | 4924 --col; |
1437 | 4925 --off; |
4926 } | |
7 | 4927 else |
4928 #endif | |
1437 | 4929 { |
7 | 4930 ++col; |
1437 | 4931 ++off; |
4932 } | |
743 | 4933 ++vcol; |
1437 | 4934 #ifdef FEAT_SYN_HL |
4935 eol_hl_off = 1; | |
4936 #endif | |
743 | 4937 } |
867 | 4938 } |
4939 | |
4940 /* | |
4941 * At end of the text line. | |
4942 */ | |
4943 if (c == NUL) | |
4944 { | |
743 | 4945 #ifdef FEAT_SYN_HL |
1850 | 4946 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4947 && lnum == wp->w_cursor.lnum) | |
1437 | 4948 { |
4949 /* highlight last char after line */ | |
4950 --col; | |
4951 --off; | |
4952 --vcol; | |
4953 } | |
4954 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4955 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4956 if (wp->w_p_wrap) |
4957 v = wp->w_skipcol; | |
4958 else | |
4959 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4960 |
820 | 4961 /* check if line ends before left margin */ |
4962 if (vcol < v + col - win_col_off(wp)) | |
4963 vcol = v + col - win_col_off(wp); | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4964 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4965 /* Get rid of the boguscols now, we want to draw until the right |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4966 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4967 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4968 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4969 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4970 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4971 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4972 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4973 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4974 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4975 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4976 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4977 W_WIDTH(wp) * (row - startrow + 1) + v |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4978 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4979 || draw_color_col) |
743 | 4980 # ifdef FEAT_RIGHTLEFT |
4981 && !wp->w_p_rl | |
4982 # endif | |
4983 ) | |
4984 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4985 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4986 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4987 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4988 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4989 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4990 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4991 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4992 for (i = 0; color_cols[i] >= 0; ++i) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4993 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4994 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4995 |
743 | 4996 while (col < W_WIDTH(wp)) |
4997 { | |
4998 ScreenLines[off] = ' '; | |
4999 #ifdef FEAT_MBYTE | |
5000 if (enc_utf8) | |
5001 ScreenLinesUC[off] = 0; | |
5002 #endif | |
5003 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
5004 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
5005 draw_color_col = advance_color_col(VCOL_HLC, |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
5006 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
5007 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5008 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5009 ScreenAttrs[off++] = hl_attr(HLF_CUC); |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5010 else if (draw_color_col && VCOL_HLC == *color_cols) |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5011 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5012 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5013 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5014 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5015 if (VCOL_HLC >= rightmost_vcol) |
743 | 5016 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5017 |
743 | 5018 ++vcol; |
5019 } | |
5020 } | |
5021 #endif | |
7 | 5022 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5023 SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5024 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 5025 row++; |
5026 | |
5027 /* | |
5028 * Update w_cline_height and w_cline_folded if the cursor line was | |
5029 * updated (saves a call to plines() later). | |
5030 */ | |
5031 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
5032 { | |
5033 curwin->w_cline_row = startrow; | |
5034 curwin->w_cline_height = row - startrow; | |
5035 #ifdef FEAT_FOLDING | |
5036 curwin->w_cline_folded = FALSE; | |
5037 #endif | |
5038 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
5039 } | |
5040 | |
5041 break; | |
5042 } | |
5043 | |
5044 /* line continues beyond line end */ | |
5045 if (lcs_ext | |
5046 && !wp->w_p_wrap | |
5047 #ifdef FEAT_DIFF | |
5048 && filler_todo <= 0 | |
5049 #endif | |
5050 && ( | |
5051 #ifdef FEAT_RIGHTLEFT | |
5052 wp->w_p_rl ? col == 0 : | |
5053 #endif | |
5054 col == W_WIDTH(wp) - 1) | |
5055 && (*ptr != NUL | |
1555 | 5056 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 5057 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
5058 { | |
5059 c = lcs_ext; | |
5060 char_attr = hl_attr(HLF_AT); | |
5061 #ifdef FEAT_MBYTE | |
5062 mb_c = c; | |
5063 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
5064 { | |
5065 mb_utf8 = TRUE; | |
714 | 5066 u8cc[0] = 0; |
819 | 5067 c = 0xc0; |
7 | 5068 } |
5069 else | |
5070 mb_utf8 = FALSE; | |
5071 #endif | |
5072 } | |
5073 | |
743 | 5074 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5075 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5076 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5077 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5078 |
743 | 5079 /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5080 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5081 * Also highlight the 'colorcolumn' if it is different than |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5082 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5083 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5084 if (draw_state == WL_LINE && !lnum_in_visual_area) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5085 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5086 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5087 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5088 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5089 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5090 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5091 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
5092 else if (draw_color_col && VCOL_HLC == *color_cols) |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5093 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5094 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5095 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5096 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
5097 } |
743 | 5098 #endif |
5099 | |
7 | 5100 /* |
5101 * Store character to be displayed. | |
5102 * Skip characters that are left of the screen for 'nowrap'. | |
5103 */ | |
5104 vcol_prev = vcol; | |
5105 if (draw_state < WL_LINE || n_skip <= 0) | |
5106 { | |
5107 /* | |
5108 * Store the character. | |
5109 */ | |
5110 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
5111 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
5112 { | |
5113 /* A double-wide character is: put first halve in left cell. */ | |
5114 --off; | |
5115 --col; | |
5116 } | |
5117 #endif | |
5118 ScreenLines[off] = c; | |
5119 #ifdef FEAT_MBYTE | |
5120 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
5121 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
5122 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
5123 ScreenLines[off] = 0x8e; |
7 | 5124 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
5125 } |
7 | 5126 else if (enc_utf8) |
5127 { | |
5128 if (mb_utf8) | |
5129 { | |
1326 | 5130 int i; |
5131 | |
7 | 5132 ScreenLinesUC[off] = mb_c; |
819 | 5133 if ((c & 0xff) == 0) |
5134 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 5135 for (i = 0; i < Screen_mco; ++i) |
5136 { | |
5137 ScreenLinesC[i][off] = u8cc[i]; | |
5138 if (u8cc[i] == 0) | |
5139 break; | |
5140 } | |
7 | 5141 } |
5142 else | |
5143 ScreenLinesUC[off] = 0; | |
5144 } | |
5145 if (multi_attr) | |
5146 { | |
5147 ScreenAttrs[off] = multi_attr; | |
5148 multi_attr = 0; | |
5149 } | |
5150 else | |
5151 #endif | |
5152 ScreenAttrs[off] = char_attr; | |
5153 | |
5154 #ifdef FEAT_MBYTE | |
5155 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
5156 { | |
5157 /* Need to fill two screen columns. */ | |
5158 ++off; | |
5159 ++col; | |
5160 if (enc_utf8) | |
5161 /* UTF-8: Put a 0 in the second screen char. */ | |
5162 ScreenLines[off] = 0; | |
5163 else | |
5164 /* DBCS: Put second byte in the second screen char. */ | |
5165 ScreenLines[off] = mb_c & 0xff; | |
5166 ++vcol; | |
5167 /* When "tocol" is halfway a character, set it to the end of | |
5168 * the character, otherwise highlighting won't stop. */ | |
5169 if (tocol == vcol) | |
5170 ++tocol; | |
5171 #ifdef FEAT_RIGHTLEFT | |
5172 if (wp->w_p_rl) | |
5173 { | |
5174 /* now it's time to backup one cell */ | |
5175 --off; | |
5176 --col; | |
5177 } | |
5178 #endif | |
5179 } | |
5180 #endif | |
5181 #ifdef FEAT_RIGHTLEFT | |
5182 if (wp->w_p_rl) | |
5183 { | |
5184 --off; | |
5185 --col; | |
5186 } | |
5187 else | |
5188 #endif | |
5189 { | |
5190 ++off; | |
5191 ++col; | |
5192 } | |
5193 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5194 #ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
5195 else if (wp->w_p_cole > 0 && is_concealing) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5196 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5197 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5198 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5199 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5200 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5201 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5202 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5203 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5204 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5205 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5206 * Advance the column indicator to force the line |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5207 * drawing to wrap early. This will make the line |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5208 * take up the same screen space when parts are concealed, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5209 * so that cursor line computations aren't messed up. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5210 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5211 * To avoid the fictitious advance of 'col' causing |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5212 * trailing junk to be written out of the screen line |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5213 * we are building, 'boguscols' keeps track of the number |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5214 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5215 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5216 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5217 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5218 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5219 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5220 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5221 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5222 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5223 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5224 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5225 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5226 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5227 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5228 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5229 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5230 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5231 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5232 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5233 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5234 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5235 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5236 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5237 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5238 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5239 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5240 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5241 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5242 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5243 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5244 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5245 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5246 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5247 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5248 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5249 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5250 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5251 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5252 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5253 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5254 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5255 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5256 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5257 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5258 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5259 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5260 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5261 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5262 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5263 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5264 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5265 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5266 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5267 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5268 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5269 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5270 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5271 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5272 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5273 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5274 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5275 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5276 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5277 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5278 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5279 #endif /* FEAT_CONCEAL */ |
7 | 5280 else |
5281 --n_skip; | |
5282 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5283 /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5284 * column. */ |
1849 | 5285 if (draw_state > WL_NR |
7 | 5286 #ifdef FEAT_DIFF |
5287 && filler_todo <= 0 | |
5288 #endif | |
5289 ) | |
5290 ++vcol; | |
5291 | |
743 | 5292 #ifdef FEAT_SYN_HL |
5293 if (vcol_save_attr >= 0) | |
5294 char_attr = vcol_save_attr; | |
5295 #endif | |
5296 | |
7 | 5297 /* restore attributes after "predeces" in 'listchars' */ |
5298 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5299 char_attr = saved_attr3; | |
5300 | |
5301 /* restore attributes after last 'listchars' or 'number' char */ | |
5302 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5303 char_attr = saved_attr2; | |
5304 | |
5305 /* | |
5306 * At end of screen line and there is more to come: Display the line | |
1378 | 5307 * so far. If there is no more to display it is caught above. |
7 | 5308 */ |
5309 if (( | |
5310 #ifdef FEAT_RIGHTLEFT | |
5311 wp->w_p_rl ? (col < 0) : | |
5312 #endif | |
5313 (col >= W_WIDTH(wp))) | |
5314 && (*ptr != NUL | |
5315 #ifdef FEAT_DIFF | |
5316 || filler_todo > 0 | |
5317 #endif | |
2724 | 5318 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
7 | 5319 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
5320 ) | |
5321 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5322 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5323 SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5324 (int)W_WIDTH(wp), wp->w_p_rl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5325 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5326 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5327 SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5328 (int)W_WIDTH(wp), wp->w_p_rl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5329 #endif |
7 | 5330 ++row; |
5331 ++screen_row; | |
5332 | |
5333 /* When not wrapping and finished diff lines, or when displayed | |
5334 * '$' and highlighting until last column, break here. */ | |
5335 if ((!wp->w_p_wrap | |
5336 #ifdef FEAT_DIFF | |
5337 && filler_todo <= 0 | |
5338 #endif | |
5339 ) || lcs_eol_one == -1) | |
5340 break; | |
5341 | |
5342 /* When the window is too narrow draw all "@" lines. */ | |
5343 if (draw_state != WL_LINE | |
5344 #ifdef FEAT_DIFF | |
5345 && filler_todo <= 0 | |
5346 #endif | |
5347 ) | |
5348 { | |
5349 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5350 #ifdef FEAT_VERTSPLIT | |
5351 draw_vsep_win(wp, row); | |
5352 #endif | |
5353 row = endrow; | |
5354 } | |
5355 | |
5356 /* When line got too long for screen break here. */ | |
5357 if (row == endrow) | |
5358 { | |
5359 ++row; | |
5360 break; | |
5361 } | |
5362 | |
5363 if (screen_cur_row == screen_row - 1 | |
5364 #ifdef FEAT_DIFF | |
5365 && filler_todo <= 0 | |
5366 #endif | |
5367 && W_WIDTH(wp) == Columns) | |
5368 { | |
5369 /* Remember that the line wraps, used for modeless copy. */ | |
5370 LineWraps[screen_row - 1] = TRUE; | |
5371 | |
5372 /* | |
5373 * Special trick to make copy/paste of wrapped lines work with | |
5374 * xterm/screen: write an extra character beyond the end of | |
5375 * the line. This will work with all terminal types | |
5376 * (regardless of the xn,am settings). | |
5377 * Only do this on a fast tty. | |
5378 * Only do this if the cursor is on the current line | |
5379 * (something has been written in it). | |
5380 * Don't do this for the GUI. | |
5381 * Don't do this for double-width characters. | |
5382 * Don't do this for a window not at the right screen border. | |
5383 */ | |
5384 if (p_tf | |
5385 #ifdef FEAT_GUI | |
5386 && !gui.in_use | |
5387 #endif | |
5388 #ifdef FEAT_MBYTE | |
5389 && !(has_mbyte | |
1378 | 5390 && ((*mb_off2cells)(LineOffset[screen_row], |
5391 LineOffset[screen_row] + screen_Columns) | |
5392 == 2 | |
7 | 5393 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5394 + (int)Columns - 2, |
5395 LineOffset[screen_row] + screen_Columns) | |
5396 == 2)) | |
7 | 5397 #endif |
5398 ) | |
5399 { | |
5400 /* First make sure we are at the end of the screen line, | |
5401 * then output the same character again to let the | |
5402 * terminal know about the wrap. If the terminal doesn't | |
5403 * auto-wrap, we overwrite the character. */ | |
5404 if (screen_cur_col != W_WIDTH(wp)) | |
5405 screen_char(LineOffset[screen_row - 1] | |
5406 + (unsigned)Columns - 1, | |
5407 screen_row - 1, (int)(Columns - 1)); | |
5408 | |
5409 #ifdef FEAT_MBYTE | |
5410 /* When there is a multi-byte character, just output a | |
5411 * space to keep it simple. */ | |
148 | 5412 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5413 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5414 out_char(' '); |
5415 else | |
5416 #endif | |
5417 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5418 + (Columns - 1)]); | |
5419 /* force a redraw of the first char on the next line */ | |
5420 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5421 screen_start(); /* don't know where cursor is now */ | |
5422 } | |
5423 } | |
5424 | |
5425 col = 0; | |
5426 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5427 #ifdef FEAT_RIGHTLEFT | |
5428 if (wp->w_p_rl) | |
5429 { | |
5430 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5431 off += col; | |
5432 } | |
5433 #endif | |
5434 | |
5435 /* reset the drawing state for the start of a wrapped line */ | |
5436 draw_state = WL_START; | |
5437 saved_n_extra = n_extra; | |
5438 saved_p_extra = p_extra; | |
5439 saved_c_extra = c_extra; | |
5440 saved_char_attr = char_attr; | |
5441 n_extra = 0; | |
5442 lcs_prec_todo = lcs_prec; | |
5443 #ifdef FEAT_LINEBREAK | |
5444 # ifdef FEAT_DIFF | |
5445 if (filler_todo <= 0) | |
5446 # endif | |
5447 need_showbreak = TRUE; | |
5448 #endif | |
5449 #ifdef FEAT_DIFF | |
5450 --filler_todo; | |
5451 /* When the filler lines are actually below the last line of the | |
5452 * file, don't draw the line itself, break here. */ | |
5453 if (filler_todo == 0 && wp->w_botfill) | |
5454 break; | |
5455 #endif | |
5456 } | |
5457 | |
5458 } /* for every character in the line */ | |
5459 | |
743 | 5460 #ifdef FEAT_SPELL |
386 | 5461 /* After an empty line check first word for capital. */ |
5462 if (*skipwhite(line) == NUL) | |
5463 { | |
5464 capcol_lnum = lnum + 1; | |
5465 cap_col = 0; | |
5466 } | |
5467 #endif | |
5468 | |
7 | 5469 return row; |
5470 } | |
5471 | |
714 | 5472 #ifdef FEAT_MBYTE |
5473 static int comp_char_differs __ARGS((int, int)); | |
5474 | |
5475 /* | |
5476 * Return if the composing characters at "off_from" and "off_to" differ. | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
5477 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5478 */ |
5479 static int | |
5480 comp_char_differs(off_from, off_to) | |
5481 int off_from; | |
5482 int off_to; | |
5483 { | |
5484 int i; | |
5485 | |
5486 for (i = 0; i < Screen_mco; ++i) | |
5487 { | |
5488 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5489 return TRUE; | |
5490 if (ScreenLinesC[i][off_from] == 0) | |
5491 break; | |
5492 } | |
5493 return FALSE; | |
5494 } | |
5495 #endif | |
5496 | |
7 | 5497 /* |
5498 * Check whether the given character needs redrawing: | |
5499 * - the (first byte of the) character is different | |
5500 * - the attributes are different | |
5501 * - the character is multi-byte and the next byte is different | |
1616 | 5502 * - the character is two cells wide and the second cell differs. |
7 | 5503 */ |
5504 static int | |
5505 char_needs_redraw(off_from, off_to, cols) | |
5506 int off_from; | |
5507 int off_to; | |
5508 int cols; | |
5509 { | |
5510 if (cols > 0 | |
5511 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5512 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5513 | |
5514 #ifdef FEAT_MBYTE | |
5515 || (enc_dbcs != 0 | |
5516 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5517 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5518 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5519 : (cols > 1 && ScreenLines[off_from + 1] | |
5520 != ScreenLines[off_to + 1]))) | |
5521 || (enc_utf8 | |
5522 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5523 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5524 && comp_char_differs(off_from, off_to)) |
3759 | 5525 || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
5526 && ScreenLines[off_from + 1] | |
5527 != ScreenLines[off_to + 1]))) | |
7 | 5528 #endif |
5529 )) | |
5530 return TRUE; | |
5531 return FALSE; | |
5532 } | |
5533 | |
5534 /* | |
5535 * Move one "cooked" screen line to the screen, but only the characters that | |
5536 * have actually changed. Handle insert/delete character. | |
5537 * "coloff" gives the first column on the screen for this line. | |
5538 * "endcol" gives the columns where valid characters are. | |
5539 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5540 * needs to be cleared, negative otherwise. | |
5541 * "rlflag" is TRUE in a rightleft window: | |
5542 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5543 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5544 */ | |
5545 static void | |
5546 screen_line(row, coloff, endcol, clear_width | |
5547 #ifdef FEAT_RIGHTLEFT | |
5548 , rlflag | |
5549 #endif | |
5550 ) | |
5551 int row; | |
5552 int coloff; | |
5553 int endcol; | |
5554 int clear_width; | |
5555 #ifdef FEAT_RIGHTLEFT | |
5556 int rlflag; | |
5557 #endif | |
5558 { | |
5559 unsigned off_from; | |
5560 unsigned off_to; | |
1378 | 5561 #ifdef FEAT_MBYTE |
5562 unsigned max_off_from; | |
5563 unsigned max_off_to; | |
5564 #endif | |
7 | 5565 int col = 0; |
5566 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5567 int hl; | |
5568 #endif | |
5569 int force = FALSE; /* force update rest of the line */ | |
5570 int redraw_this /* bool: does character need redraw? */ | |
5571 #ifdef FEAT_GUI | |
5572 = TRUE /* For GUI when while-loop empty */ | |
5573 #endif | |
5574 ; | |
5575 int redraw_next; /* redraw_this for next character */ | |
5576 #ifdef FEAT_MBYTE | |
5577 int clear_next = FALSE; | |
5578 int char_cells; /* 1: normal char */ | |
5579 /* 2: occupies two display cells */ | |
5580 # define CHAR_CELLS char_cells | |
5581 #else | |
5582 # define CHAR_CELLS 1 | |
5583 #endif | |
5584 | |
3413 | 5585 /* Check for illegal row and col, just in case. */ |
5586 if (row >= Rows) | |
5587 row = Rows - 1; | |
5588 if (endcol > Columns) | |
5589 endcol = Columns; | |
5590 | |
7 | 5591 # ifdef FEAT_CLIPBOARD |
5592 clip_may_clear_selection(row, row); | |
5593 # endif | |
5594 | |
5595 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5596 off_to = LineOffset[row] + coloff; | |
1378 | 5597 #ifdef FEAT_MBYTE |
5598 max_off_from = off_from + screen_Columns; | |
5599 max_off_to = LineOffset[row] + screen_Columns; | |
5600 #endif | |
7 | 5601 |
5602 #ifdef FEAT_RIGHTLEFT | |
5603 if (rlflag) | |
5604 { | |
5605 /* Clear rest first, because it's left of the text. */ | |
5606 if (clear_width > 0) | |
5607 { | |
5608 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5609 && ScreenAttrs[off_to] == 0 | |
5610 # ifdef FEAT_MBYTE | |
5611 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5612 # endif | |
5613 ) | |
5614 { | |
5615 ++off_to; | |
5616 ++col; | |
5617 } | |
5618 if (col <= endcol) | |
5619 screen_fill(row, row + 1, col + coloff, | |
5620 endcol + coloff + 1, ' ', ' ', 0); | |
5621 } | |
5622 col = endcol + 1; | |
5623 off_to = LineOffset[row] + col + coloff; | |
5624 off_from += col; | |
5625 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5626 } | |
5627 #endif /* FEAT_RIGHTLEFT */ | |
5628 | |
5629 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5630 | |
5631 while (col < endcol) | |
5632 { | |
5633 #ifdef FEAT_MBYTE | |
5634 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5635 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5636 else |
5637 char_cells = 1; | |
5638 #endif | |
5639 | |
5640 redraw_this = redraw_next; | |
5641 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5642 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5643 | |
5644 #ifdef FEAT_GUI | |
5645 /* If the next character was bold, then redraw the current character to | |
5646 * remove any pixels that might have spilt over into us. This only | |
5647 * happens in the GUI. | |
5648 */ | |
5649 if (redraw_next && gui.in_use) | |
5650 { | |
5651 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5652 if (hl > HL_ALL) |
5653 hl = syn_attr2attr(hl); | |
5654 if (hl & HL_BOLD) | |
7 | 5655 redraw_this = TRUE; |
5656 } | |
5657 #endif | |
5658 | |
5659 if (redraw_this) | |
5660 { | |
5661 /* | |
5662 * Special handling when 'xs' termcap flag set (hpterm): | |
5663 * Attributes for characters are stored at the position where the | |
5664 * cursor is when writing the highlighting code. The | |
5665 * start-highlighting code must be written with the cursor on the | |
5666 * first highlighted character. The stop-highlighting code must | |
5667 * be written with the cursor just after the last highlighted | |
5668 * character. | |
5669 * Overwriting a character doesn't remove it's highlighting. Need | |
5670 * to clear the rest of the line, and force redrawing it | |
5671 * completely. | |
5672 */ | |
5673 if ( p_wiv | |
5674 && !force | |
5675 #ifdef FEAT_GUI | |
5676 && !gui.in_use | |
5677 #endif | |
5678 && ScreenAttrs[off_to] != 0 | |
5679 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5680 { | |
5681 /* | |
5682 * Need to remove highlighting attributes here. | |
5683 */ | |
5684 windgoto(row, col + coloff); | |
5685 out_str(T_CE); /* clear rest of this screen line */ | |
5686 screen_start(); /* don't know where cursor is now */ | |
5687 force = TRUE; /* force redraw of rest of the line */ | |
5688 redraw_next = TRUE; /* or else next char would miss out */ | |
5689 | |
5690 /* | |
5691 * If the previous character was highlighted, need to stop | |
5692 * highlighting at this character. | |
5693 */ | |
5694 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5695 { | |
5696 screen_attr = ScreenAttrs[off_to - 1]; | |
5697 term_windgoto(row, col + coloff); | |
5698 screen_stop_highlight(); | |
5699 } | |
5700 else | |
5701 screen_attr = 0; /* highlighting has stopped */ | |
5702 } | |
5703 #ifdef FEAT_MBYTE | |
5704 if (enc_dbcs != 0) | |
5705 { | |
5706 /* Check if overwriting a double-byte with a single-byte or | |
5707 * the other way around requires another character to be | |
5708 * redrawn. For UTF-8 this isn't needed, because comparing | |
5709 * ScreenLinesUC[] is sufficient. */ | |
5710 if (char_cells == 1 | |
5711 && col + 1 < endcol | |
1378 | 5712 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5713 { |
5714 /* Writing a single-cell character over a double-cell | |
5715 * character: need to redraw the next cell. */ | |
5716 ScreenLines[off_to + 1] = 0; | |
5717 redraw_next = TRUE; | |
5718 } | |
5719 else if (char_cells == 2 | |
5720 && col + 2 < endcol | |
1378 | 5721 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5722 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5723 { |
5724 /* Writing the second half of a double-cell character over | |
5725 * a double-cell character: need to redraw the second | |
5726 * cell. */ | |
5727 ScreenLines[off_to + 2] = 0; | |
5728 redraw_next = TRUE; | |
5729 } | |
5730 | |
5731 if (enc_dbcs == DBCS_JPNU) | |
5732 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5733 } | |
5734 /* When writing a single-width character over a double-width | |
5735 * character and at the end of the redrawn text, need to clear out | |
5736 * the right halve of the old character. | |
5737 * Also required when writing the right halve of a double-width | |
5738 * char over the left halve of an existing one. */ | |
5739 if (has_mbyte && col + char_cells == endcol | |
5740 && ((char_cells == 1 | |
1378 | 5741 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5742 || (char_cells == 2 |
1378 | 5743 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5744 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5745 clear_next = TRUE; |
5746 #endif | |
5747 | |
5748 ScreenLines[off_to] = ScreenLines[off_from]; | |
5749 #ifdef FEAT_MBYTE | |
5750 if (enc_utf8) | |
5751 { | |
5752 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5753 if (ScreenLinesUC[off_from] != 0) | |
5754 { | |
714 | 5755 int i; |
5756 | |
5757 for (i = 0; i < Screen_mco; ++i) | |
5758 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5759 } |
5760 } | |
5761 if (char_cells == 2) | |
5762 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5763 #endif | |
5764 | |
5765 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5766 /* The bold trick makes a single column of pixels appear in the |
5767 * next character. When a bold character is removed, the next | |
7 | 5768 * character should be redrawn too. This happens for our own GUI |
5769 * and for some xterms. */ | |
5770 if ( | |
5771 # ifdef FEAT_GUI | |
5772 gui.in_use | |
5773 # endif | |
5774 # if defined(FEAT_GUI) && defined(UNIX) | |
5775 || | |
5776 # endif | |
5777 # ifdef UNIX | |
5778 term_is_xterm | |
5779 # endif | |
5780 ) | |
5781 { | |
5782 hl = ScreenAttrs[off_to]; | |
743 | 5783 if (hl > HL_ALL) |
5784 hl = syn_attr2attr(hl); | |
5785 if (hl & HL_BOLD) | |
7 | 5786 redraw_next = TRUE; |
5787 } | |
5788 #endif | |
5789 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5790 #ifdef FEAT_MBYTE | |
819 | 5791 /* For simplicity set the attributes of second half of a |
5792 * double-wide character equal to the first half. */ | |
5793 if (char_cells == 2) | |
5794 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5795 | |
7 | 5796 if (enc_dbcs != 0 && char_cells == 2) |
5797 screen_char_2(off_to, row, col + coloff); | |
5798 else | |
5799 #endif | |
5800 screen_char(off_to, row, col + coloff); | |
5801 } | |
5802 else if ( p_wiv | |
5803 #ifdef FEAT_GUI | |
5804 && !gui.in_use | |
5805 #endif | |
5806 && col + coloff > 0) | |
5807 { | |
5808 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5809 { | |
5810 /* | |
5811 * Don't output stop-highlight when moving the cursor, it will | |
5812 * stop the highlighting when it should continue. | |
5813 */ | |
5814 screen_attr = 0; | |
5815 } | |
5816 else if (screen_attr != 0) | |
5817 screen_stop_highlight(); | |
5818 } | |
5819 | |
5820 off_to += CHAR_CELLS; | |
5821 off_from += CHAR_CELLS; | |
5822 col += CHAR_CELLS; | |
5823 } | |
5824 | |
5825 #ifdef FEAT_MBYTE | |
5826 if (clear_next) | |
5827 { | |
5828 /* Clear the second half of a double-wide character of which the left | |
5829 * half was overwritten with a single-wide character. */ | |
5830 ScreenLines[off_to] = ' '; | |
5831 if (enc_utf8) | |
5832 ScreenLinesUC[off_to] = 0; | |
5833 screen_char(off_to, row, col + coloff); | |
5834 } | |
5835 #endif | |
5836 | |
5837 if (clear_width > 0 | |
5838 #ifdef FEAT_RIGHTLEFT | |
5839 && !rlflag | |
5840 #endif | |
5841 ) | |
5842 { | |
5843 #ifdef FEAT_GUI | |
5844 int startCol = col; | |
5845 #endif | |
5846 | |
5847 /* blank out the rest of the line */ | |
5848 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5849 && ScreenAttrs[off_to] == 0 | |
5850 #ifdef FEAT_MBYTE | |
5851 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5852 #endif | |
5853 ) | |
5854 { | |
5855 ++off_to; | |
5856 ++col; | |
5857 } | |
5858 if (col < clear_width) | |
5859 { | |
5860 #ifdef FEAT_GUI | |
5861 /* | |
5862 * In the GUI, clearing the rest of the line may leave pixels | |
5863 * behind if the first character cleared was bold. Some bold | |
5864 * fonts spill over the left. In this case we redraw the previous | |
5865 * character too. If we didn't skip any blanks above, then we | |
5866 * only redraw if the character wasn't already redrawn anyway. | |
5867 */ | |
996 | 5868 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5869 { |
5870 hl = ScreenAttrs[off_to]; | |
5871 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5872 { |
5873 int prev_cells = 1; | |
5874 # ifdef FEAT_MBYTE | |
5875 if (enc_utf8) | |
5876 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5877 * that its width is 2. */ | |
5878 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5879 else if (enc_dbcs != 0) | |
5880 { | |
5881 /* find previous character by counting from first | |
5882 * column and get its width. */ | |
5883 unsigned off = LineOffset[row]; | |
1378 | 5884 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5885 |
5886 while (off < off_to) | |
5887 { | |
1378 | 5888 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5889 off += prev_cells; |
5890 } | |
5891 } | |
5892 | |
5893 if (enc_dbcs != 0 && prev_cells > 1) | |
5894 screen_char_2(off_to - prev_cells, row, | |
5895 col + coloff - prev_cells); | |
5896 else | |
5897 # endif | |
5898 screen_char(off_to - prev_cells, row, | |
5899 col + coloff - prev_cells); | |
5900 } | |
7 | 5901 } |
5902 #endif | |
5903 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5904 ' ', ' ', 0); | |
5905 #ifdef FEAT_VERTSPLIT | |
5906 off_to += clear_width - col; | |
5907 col = clear_width; | |
5908 #endif | |
5909 } | |
5910 } | |
5911 | |
5912 if (clear_width > 0) | |
5913 { | |
5914 #ifdef FEAT_VERTSPLIT | |
5915 /* For a window that's left of another, draw the separator char. */ | |
5916 if (col + coloff < Columns) | |
5917 { | |
5918 int c; | |
5919 | |
5920 c = fillchar_vsep(&hl); | |
5921 if (ScreenLines[off_to] != c | |
5922 # ifdef FEAT_MBYTE | |
714 | 5923 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5924 != (c >= 0x80 ? c : 0)) | |
7 | 5925 # endif |
5926 || ScreenAttrs[off_to] != hl) | |
5927 { | |
5928 ScreenLines[off_to] = c; | |
5929 ScreenAttrs[off_to] = hl; | |
5930 # ifdef FEAT_MBYTE | |
5931 if (enc_utf8) | |
5932 { | |
5933 if (c >= 0x80) | |
5934 { | |
5935 ScreenLinesUC[off_to] = c; | |
714 | 5936 ScreenLinesC[0][off_to] = 0; |
7 | 5937 } |
5938 else | |
5939 ScreenLinesUC[off_to] = 0; | |
5940 } | |
5941 # endif | |
5942 screen_char(off_to, row, col + coloff); | |
5943 } | |
5944 } | |
5945 else | |
5946 #endif | |
5947 LineWraps[row] = FALSE; | |
5948 } | |
5949 } | |
5950 | |
474 | 5951 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5952 /* |
474 | 5953 * Mirror text "str" for right-left displaying. |
5954 * Only works for single-byte characters (e.g., numbers). | |
7 | 5955 */ |
474 | 5956 void |
7 | 5957 rl_mirror(str) |
5958 char_u *str; | |
5959 { | |
5960 char_u *p1, *p2; | |
5961 int t; | |
5962 | |
5963 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5964 { | |
5965 t = *p1; | |
5966 *p1 = *p2; | |
5967 *p2 = t; | |
5968 } | |
5969 } | |
5970 #endif | |
5971 | |
5972 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5973 /* | |
5974 * mark all status lines for redraw; used after first :cd | |
5975 */ | |
5976 void | |
5977 status_redraw_all() | |
5978 { | |
5979 win_T *wp; | |
5980 | |
5981 for (wp = firstwin; wp; wp = wp->w_next) | |
5982 if (wp->w_status_height) | |
5983 { | |
5984 wp->w_redr_status = TRUE; | |
5985 redraw_later(VALID); | |
5986 } | |
5987 } | |
5988 | |
5989 /* | |
5990 * mark all status lines of the current buffer for redraw | |
5991 */ | |
5992 void | |
5993 status_redraw_curbuf() | |
5994 { | |
5995 win_T *wp; | |
5996 | |
5997 for (wp = firstwin; wp; wp = wp->w_next) | |
5998 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5999 { | |
6000 wp->w_redr_status = TRUE; | |
6001 redraw_later(VALID); | |
6002 } | |
6003 } | |
6004 | |
6005 /* | |
6006 * Redraw all status lines that need to be redrawn. | |
6007 */ | |
6008 void | |
6009 redraw_statuslines() | |
6010 { | |
6011 win_T *wp; | |
6012 | |
6013 for (wp = firstwin; wp; wp = wp->w_next) | |
6014 if (wp->w_redr_status) | |
6015 win_redr_status(wp); | |
673 | 6016 if (redraw_tabline) |
677 | 6017 draw_tabline(); |
7 | 6018 } |
6019 #endif | |
6020 | |
6021 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
6022 /* | |
6023 * Redraw all status lines at the bottom of frame "frp". | |
6024 */ | |
6025 void | |
6026 win_redraw_last_status(frp) | |
6027 frame_T *frp; | |
6028 { | |
6029 if (frp->fr_layout == FR_LEAF) | |
6030 frp->fr_win->w_redr_status = TRUE; | |
6031 else if (frp->fr_layout == FR_ROW) | |
6032 { | |
6033 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
6034 win_redraw_last_status(frp); | |
6035 } | |
6036 else /* frp->fr_layout == FR_COL */ | |
6037 { | |
6038 frp = frp->fr_child; | |
6039 while (frp->fr_next != NULL) | |
6040 frp = frp->fr_next; | |
6041 win_redraw_last_status(frp); | |
6042 } | |
6043 } | |
6044 #endif | |
6045 | |
6046 #ifdef FEAT_VERTSPLIT | |
6047 /* | |
6048 * Draw the verticap separator right of window "wp" starting with line "row". | |
6049 */ | |
6050 static void | |
6051 draw_vsep_win(wp, row) | |
6052 win_T *wp; | |
6053 int row; | |
6054 { | |
6055 int hl; | |
6056 int c; | |
6057 | |
6058 if (wp->w_vsep_width) | |
6059 { | |
6060 /* draw the vertical separator right of this window */ | |
6061 c = fillchar_vsep(&hl); | |
6062 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
6063 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
6064 c, ' ', hl); | |
6065 } | |
6066 } | |
6067 #endif | |
6068 | |
6069 #ifdef FEAT_WILDMENU | |
6070 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 6071 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 6072 |
6073 /* | |
1378 | 6074 * Get the length of an item as it will be shown in the status line. |
7 | 6075 */ |
6076 static int | |
6077 status_match_len(xp, s) | |
6078 expand_T *xp; | |
6079 char_u *s; | |
6080 { | |
6081 int len = 0; | |
6082 | |
6083 #ifdef FEAT_MENU | |
6084 int emenu = (xp->xp_context == EXPAND_MENUS | |
6085 || xp->xp_context == EXPAND_MENUNAMES); | |
6086 | |
6087 /* Check for menu separators - replace with '|'. */ | |
6088 if (emenu && menu_is_separator(s)) | |
6089 return 1; | |
6090 #endif | |
6091 | |
6092 while (*s != NUL) | |
6093 { | |
1685 | 6094 s += skip_status_match_char(xp, s); |
42 | 6095 len += ptr2cells(s); |
39 | 6096 mb_ptr_adv(s); |
7 | 6097 } |
6098 | |
6099 return len; | |
6100 } | |
6101 | |
6102 /* | |
1685 | 6103 * Return the number of characters that should be skipped in a status match. |
277 | 6104 * These are backslashes used for escaping. Do show backslashes in help tags. |
6105 */ | |
6106 static int | |
6107 skip_status_match_char(xp, s) | |
6108 expand_T *xp; | |
6109 char_u *s; | |
6110 { | |
1685 | 6111 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 6112 #ifdef FEAT_MENU |
6113 || ((xp->xp_context == EXPAND_MENUS | |
6114 || xp->xp_context == EXPAND_MENUNAMES) | |
6115 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
6116 #endif | |
1685 | 6117 ) |
6118 { | |
6119 #ifndef BACKSLASH_IN_FILENAME | |
6120 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
6121 return 2; | |
6122 #endif | |
6123 return 1; | |
6124 } | |
6125 return 0; | |
277 | 6126 } |
6127 | |
6128 /* | |
7 | 6129 * Show wildchar matches in the status line. |
6130 * Show at least the "match" item. | |
6131 * We start at item 'first_match' in the list and show all matches that fit. | |
6132 * | |
6133 * If inversion is possible we use it. Else '=' characters are used. | |
6134 */ | |
6135 void | |
6136 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
6137 expand_T *xp; | |
6138 int num_matches; | |
6139 char_u **matches; /* list of matches */ | |
6140 int match; | |
6141 int showtail; | |
6142 { | |
6143 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
6144 int row; | |
6145 char_u *buf; | |
6146 int len; | |
1378 | 6147 int clen; /* length in screen cells */ |
7 | 6148 int fillchar; |
6149 int attr; | |
6150 int i; | |
6151 int highlight = TRUE; | |
6152 char_u *selstart = NULL; | |
6153 int selstart_col = 0; | |
6154 char_u *selend = NULL; | |
6155 static int first_match = 0; | |
6156 int add_left = FALSE; | |
6157 char_u *s; | |
6158 #ifdef FEAT_MENU | |
6159 int emenu; | |
6160 #endif | |
6161 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
6162 int l; | |
6163 #endif | |
6164 | |
6165 if (matches == NULL) /* interrupted completion? */ | |
6166 return; | |
6167 | |
39 | 6168 #ifdef FEAT_MBYTE |
6169 if (has_mbyte) | |
6170 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
6171 else | |
6172 #endif | |
6173 buf = alloc((unsigned)Columns + 1); | |
7 | 6174 if (buf == NULL) |
6175 return; | |
6176 | |
6177 if (match == -1) /* don't show match but original text */ | |
6178 { | |
6179 match = 0; | |
6180 highlight = FALSE; | |
6181 } | |
6182 /* count 1 for the ending ">" */ | |
6183 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
6184 if (match == 0) | |
6185 first_match = 0; | |
6186 else if (match < first_match) | |
6187 { | |
6188 /* jumping left, as far as we can go */ | |
6189 first_match = match; | |
6190 add_left = TRUE; | |
6191 } | |
6192 else | |
6193 { | |
6194 /* check if match fits on the screen */ | |
6195 for (i = first_match; i < match; ++i) | |
6196 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
6197 if (first_match > 0) | |
6198 clen += 2; | |
6199 /* jumping right, put match at the left */ | |
6200 if ((long)clen > Columns) | |
6201 { | |
6202 first_match = match; | |
6203 /* if showing the last match, we can add some on the left */ | |
6204 clen = 2; | |
6205 for (i = match; i < num_matches; ++i) | |
6206 { | |
6207 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
6208 if ((long)clen >= Columns) | |
6209 break; | |
6210 } | |
6211 if (i == num_matches) | |
6212 add_left = TRUE; | |
6213 } | |
6214 } | |
6215 if (add_left) | |
6216 while (first_match > 0) | |
6217 { | |
6218 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
6219 if ((long)clen >= Columns) | |
6220 break; | |
6221 --first_match; | |
6222 } | |
6223 | |
6224 fillchar = fillchar_status(&attr, TRUE); | |
6225 | |
6226 if (first_match == 0) | |
6227 { | |
6228 *buf = NUL; | |
6229 len = 0; | |
6230 } | |
6231 else | |
6232 { | |
6233 STRCPY(buf, "< "); | |
6234 len = 2; | |
6235 } | |
6236 clen = len; | |
6237 | |
6238 i = first_match; | |
6239 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
6240 { | |
6241 if (i == match) | |
6242 { | |
6243 selstart = buf + len; | |
6244 selstart_col = clen; | |
6245 } | |
6246 | |
6247 s = L_MATCH(i); | |
6248 /* Check for menu separators - replace with '|' */ | |
6249 #ifdef FEAT_MENU | |
6250 emenu = (xp->xp_context == EXPAND_MENUS | |
6251 || xp->xp_context == EXPAND_MENUNAMES); | |
6252 if (emenu && menu_is_separator(s)) | |
6253 { | |
6254 STRCPY(buf + len, transchar('|')); | |
6255 l = (int)STRLEN(buf + len); | |
6256 len += l; | |
6257 clen += l; | |
6258 } | |
6259 else | |
6260 #endif | |
6261 for ( ; *s != NUL; ++s) | |
6262 { | |
1685 | 6263 s += skip_status_match_char(xp, s); |
7 | 6264 clen += ptr2cells(s); |
6265 #ifdef FEAT_MBYTE | |
474 | 6266 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 6267 { |
6268 STRNCPY(buf + len, s, l); | |
6269 s += l - 1; | |
6270 len += l; | |
6271 } | |
6272 else | |
6273 #endif | |
6274 { | |
6275 STRCPY(buf + len, transchar_byte(*s)); | |
6276 len += (int)STRLEN(buf + len); | |
6277 } | |
6278 } | |
6279 if (i == match) | |
6280 selend = buf + len; | |
6281 | |
6282 *(buf + len++) = ' '; | |
6283 *(buf + len++) = ' '; | |
6284 clen += 2; | |
6285 if (++i == num_matches) | |
6286 break; | |
6287 } | |
6288 | |
6289 if (i != num_matches) | |
6290 { | |
6291 *(buf + len++) = '>'; | |
6292 ++clen; | |
6293 } | |
6294 | |
6295 buf[len] = NUL; | |
6296 | |
6297 row = cmdline_row - 1; | |
6298 if (row >= 0) | |
6299 { | |
6300 if (wild_menu_showing == 0) | |
6301 { | |
6302 if (msg_scrolled > 0) | |
6303 { | |
6304 /* Put the wildmenu just above the command line. If there is | |
6305 * no room, scroll the screen one line up. */ | |
6306 if (cmdline_row == Rows - 1) | |
6307 { | |
6308 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6309 ++msg_scrolled; | |
6310 } | |
6311 else | |
6312 { | |
6313 ++cmdline_row; | |
6314 ++row; | |
6315 } | |
6316 wild_menu_showing = WM_SCROLLED; | |
6317 } | |
6318 else | |
6319 { | |
6320 /* Create status line if needed by setting 'laststatus' to 2. | |
6321 * Set 'winminheight' to zero to avoid that the window is | |
6322 * resized. */ | |
6323 if (lastwin->w_status_height == 0) | |
6324 { | |
6325 save_p_ls = p_ls; | |
6326 save_p_wmh = p_wmh; | |
6327 p_ls = 2; | |
6328 p_wmh = 0; | |
6329 last_status(FALSE); | |
6330 } | |
6331 wild_menu_showing = WM_SHOWN; | |
6332 } | |
6333 } | |
6334 | |
6335 screen_puts(buf, row, 0, attr); | |
6336 if (selstart != NULL && highlight) | |
6337 { | |
6338 *selend = NUL; | |
6339 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6340 } | |
6341 | |
6342 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6343 } | |
6344 | |
6345 #ifdef FEAT_VERTSPLIT | |
6346 win_redraw_last_status(topframe); | |
6347 #else | |
6348 lastwin->w_redr_status = TRUE; | |
6349 #endif | |
6350 vim_free(buf); | |
6351 } | |
6352 #endif | |
6353 | |
6354 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6355 /* | |
6356 * Redraw the status line of window wp. | |
6357 * | |
6358 * If inversion is possible we use it. Else '=' characters are used. | |
6359 */ | |
6360 void | |
6361 win_redr_status(wp) | |
6362 win_T *wp; | |
6363 { | |
6364 int row; | |
6365 char_u *p; | |
6366 int len; | |
6367 int fillchar; | |
6368 int attr; | |
6369 int this_ru_col; | |
1910 | 6370 static int busy = FALSE; |
6371 | |
6372 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6373 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6374 if (busy) | |
6375 return; | |
6376 busy = TRUE; | |
7 | 6377 |
6378 wp->w_redr_status = FALSE; | |
6379 if (wp->w_status_height == 0) | |
6380 { | |
6381 /* no status line, can only be last window */ | |
6382 redraw_cmdline = TRUE; | |
6383 } | |
540 | 6384 else if (!redrawing() |
6385 #ifdef FEAT_INS_EXPAND | |
6386 /* don't update status line when popup menu is visible and may be | |
6387 * drawn over it */ | |
6388 || pum_visible() | |
6389 #endif | |
6390 ) | |
7 | 6391 { |
6392 /* Don't redraw right now, do it later. */ | |
6393 wp->w_redr_status = TRUE; | |
6394 } | |
6395 #ifdef FEAT_STL_OPT | |
40 | 6396 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6397 { |
6398 /* redraw custom status line */ | |
1983 | 6399 redraw_custom_statusline(wp); |
7 | 6400 } |
6401 #endif | |
6402 else | |
6403 { | |
6404 fillchar = fillchar_status(&attr, wp == curwin); | |
6405 | |
685 | 6406 get_trans_bufname(wp->w_buffer); |
7 | 6407 p = NameBuff; |
6408 len = (int)STRLEN(p); | |
6409 | |
6410 if (wp->w_buffer->b_help | |
6411 #ifdef FEAT_QUICKFIX | |
6412 || wp->w_p_pvw | |
6413 #endif | |
6414 || bufIsChanged(wp->w_buffer) | |
6415 || wp->w_buffer->b_p_ro) | |
6416 *(p + len++) = ' '; | |
6417 if (wp->w_buffer->b_help) | |
6418 { | |
809 | 6419 STRCPY(p + len, _("[Help]")); |
7 | 6420 len += (int)STRLEN(p + len); |
6421 } | |
6422 #ifdef FEAT_QUICKFIX | |
6423 if (wp->w_p_pvw) | |
6424 { | |
6425 STRCPY(p + len, _("[Preview]")); | |
6426 len += (int)STRLEN(p + len); | |
6427 } | |
6428 #endif | |
6429 if (bufIsChanged(wp->w_buffer)) | |
6430 { | |
6431 STRCPY(p + len, "[+]"); | |
6432 len += 3; | |
6433 } | |
6434 if (wp->w_buffer->b_p_ro) | |
6435 { | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4736
diff
changeset
|
6436 STRCPY(p + len, _("[RO]")); |
7 | 6437 len += 4; |
6438 } | |
6439 | |
6440 #ifndef FEAT_VERTSPLIT | |
6441 this_ru_col = ru_col; | |
6442 if (this_ru_col < (Columns + 1) / 2) | |
6443 this_ru_col = (Columns + 1) / 2; | |
6444 #else | |
6445 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6446 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6447 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6448 if (this_ru_col <= 1) | |
6449 { | |
6450 p = (char_u *)"<"; /* No room for file name! */ | |
6451 len = 1; | |
6452 } | |
6453 else | |
6454 #endif | |
6455 #ifdef FEAT_MBYTE | |
6456 if (has_mbyte) | |
6457 { | |
6458 int clen = 0, i; | |
6459 | |
6460 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6461 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6462 |
7 | 6463 /* Find first character that will fit. |
6464 * Going from start to end is much faster for DBCS. */ | |
6465 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6466 i += (*mb_ptr2len)(p + i)) |
7 | 6467 clen -= (*mb_ptr2cells)(p + i); |
6468 len = clen; | |
6469 if (i > 0) | |
6470 { | |
6471 p = p + i - 1; | |
6472 *p = '<'; | |
6473 ++len; | |
6474 } | |
6475 | |
6476 } | |
6477 else | |
6478 #endif | |
6479 if (len > this_ru_col - 1) | |
6480 { | |
6481 p += len - (this_ru_col - 1); | |
6482 *p = '<'; | |
6483 len = this_ru_col - 1; | |
6484 } | |
6485 | |
6486 row = W_WINROW(wp) + wp->w_height; | |
6487 screen_puts(p, row, W_WINCOL(wp), attr); | |
6488 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6489 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6490 | |
6491 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6492 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6493 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6494 - 1 + W_WINCOL(wp)), attr); | |
6495 | |
6496 #ifdef FEAT_CMDL_INFO | |
6497 win_redr_ruler(wp, TRUE); | |
6498 #endif | |
6499 } | |
6500 | |
6501 #ifdef FEAT_VERTSPLIT | |
6502 /* | |
6503 * May need to draw the character below the vertical separator. | |
6504 */ | |
6505 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6506 { | |
6507 if (stl_connected(wp)) | |
6508 fillchar = fillchar_status(&attr, wp == curwin); | |
6509 else | |
6510 fillchar = fillchar_vsep(&attr); | |
6511 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6512 attr); | |
6513 } | |
6514 #endif | |
1910 | 6515 busy = FALSE; |
7 | 6516 } |
6517 | |
680 | 6518 #ifdef FEAT_STL_OPT |
6519 /* | |
6520 * Redraw the status line according to 'statusline' and take care of any | |
6521 * errors encountered. | |
6522 */ | |
6523 static void | |
1983 | 6524 redraw_custom_statusline(wp) |
680 | 6525 win_T *wp; |
6526 { | |
1983 | 6527 static int entered = FALSE; |
6528 int save_called_emsg = called_emsg; | |
6529 | |
6530 /* When called recursively return. This can happen when the statusline | |
6531 * contains an expression that triggers a redraw. */ | |
6532 if (entered) | |
6533 return; | |
6534 entered = TRUE; | |
680 | 6535 |
6536 called_emsg = FALSE; | |
6537 win_redr_custom(wp, FALSE); | |
6538 if (called_emsg) | |
1983 | 6539 { |
6540 /* When there is an error disable the statusline, otherwise the | |
6541 * display is messed up with errors and a redraw triggers the problem | |
6542 * again and again. */ | |
680 | 6543 set_string_option_direct((char_u *)"statusline", -1, |
6544 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6545 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6546 } |
680 | 6547 called_emsg |= save_called_emsg; |
1983 | 6548 entered = FALSE; |
680 | 6549 } |
6550 #endif | |
6551 | |
7 | 6552 # ifdef FEAT_VERTSPLIT |
6553 /* | |
6554 * Return TRUE if the status line of window "wp" is connected to the status | |
6555 * line of the window right of it. If not, then it's a vertical separator. | |
6556 * Only call if (wp->w_vsep_width != 0). | |
6557 */ | |
6558 int | |
6559 stl_connected(wp) | |
6560 win_T *wp; | |
6561 { | |
6562 frame_T *fr; | |
6563 | |
6564 fr = wp->w_frame; | |
6565 while (fr->fr_parent != NULL) | |
6566 { | |
6567 if (fr->fr_parent->fr_layout == FR_COL) | |
6568 { | |
6569 if (fr->fr_next != NULL) | |
6570 break; | |
6571 } | |
6572 else | |
6573 { | |
6574 if (fr->fr_next != NULL) | |
6575 return TRUE; | |
6576 } | |
6577 fr = fr->fr_parent; | |
6578 } | |
6579 return FALSE; | |
6580 } | |
6581 # endif | |
6582 | |
6583 #endif /* FEAT_WINDOWS */ | |
6584 | |
6585 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6586 /* | |
6587 * Get the value to show for the language mappings, active 'keymap'. | |
6588 */ | |
6589 int | |
6590 get_keymap_str(wp, buf, len) | |
6591 win_T *wp; | |
6592 char_u *buf; /* buffer for the result */ | |
6593 int len; /* length of buffer */ | |
6594 { | |
6595 char_u *p; | |
6596 | |
6597 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6598 return FALSE; | |
6599 | |
6600 { | |
6601 #ifdef FEAT_EVAL | |
6602 buf_T *old_curbuf = curbuf; | |
6603 win_T *old_curwin = curwin; | |
6604 char_u *s; | |
6605 | |
6606 curbuf = wp->w_buffer; | |
6607 curwin = wp; | |
6608 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6609 ++emsg_skip; | |
714 | 6610 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6611 --emsg_skip; |
6612 curbuf = old_curbuf; | |
6613 curwin = old_curwin; | |
6614 if (p == NULL || *p == NUL) | |
6615 #endif | |
6616 { | |
6617 #ifdef FEAT_KEYMAP | |
6618 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6619 p = wp->w_buffer->b_p_keymap; | |
6620 else | |
6621 #endif | |
6622 p = (char_u *)"lang"; | |
6623 } | |
6624 if ((int)(STRLEN(p) + 3) < len) | |
6625 sprintf((char *)buf, "<%s>", p); | |
6626 else | |
6627 buf[0] = NUL; | |
6628 #ifdef FEAT_EVAL | |
6629 vim_free(s); | |
6630 #endif | |
6631 } | |
6632 return buf[0] != NUL; | |
6633 } | |
6634 #endif | |
6635 | |
6636 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6637 /* | |
677 | 6638 * Redraw the status line or ruler of window "wp". |
6639 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6640 */ |
6641 static void | |
574 | 6642 win_redr_custom(wp, draw_ruler) |
7 | 6643 win_T *wp; |
574 | 6644 int draw_ruler; /* TRUE or FALSE */ |
7 | 6645 { |
6646 int attr; | |
6647 int curattr; | |
6648 int row; | |
6649 int col = 0; | |
6650 int maxwidth; | |
6651 int width; | |
6652 int n; | |
6653 int len; | |
6654 int fillchar; | |
6655 char_u buf[MAXPATHL]; | |
1983 | 6656 char_u *stl; |
7 | 6657 char_u *p; |
681 | 6658 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6659 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6660 int use_sandbox = FALSE; |
2693 | 6661 win_T *ewp; |
6662 int p_crb_save; | |
7 | 6663 |
6664 /* setup environment for the task at hand */ | |
677 | 6665 if (wp == NULL) |
6666 { | |
6667 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6668 stl = p_tal; |
677 | 6669 row = 0; |
707 | 6670 fillchar = ' '; |
677 | 6671 attr = hl_attr(HLF_TPF); |
6672 maxwidth = Columns; | |
6673 # ifdef FEAT_EVAL | |
681 | 6674 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6675 # endif |
6676 } | |
40 | 6677 else |
677 | 6678 { |
6679 row = W_WINROW(wp) + wp->w_height; | |
6680 fillchar = fillchar_status(&attr, wp == curwin); | |
6681 maxwidth = W_WIDTH(wp); | |
6682 | |
6683 if (draw_ruler) | |
6684 { | |
1983 | 6685 stl = p_ruf; |
677 | 6686 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6687 if (*stl == '%') |
6688 { | |
6689 if (*++stl == '-') | |
6690 stl++; | |
6691 if (atoi((char *)stl)) | |
6692 while (VIM_ISDIGIT(*stl)) | |
6693 stl++; | |
6694 if (*stl++ != '(') | |
6695 stl = p_ruf; | |
677 | 6696 } |
7 | 6697 #ifdef FEAT_VERTSPLIT |
677 | 6698 col = ru_col - (Columns - W_WIDTH(wp)); |
6699 if (col < (W_WIDTH(wp) + 1) / 2) | |
6700 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6701 #else |
677 | 6702 col = ru_col; |
6703 if (col > (Columns + 1) / 2) | |
6704 col = (Columns + 1) / 2; | |
6705 #endif | |
6706 maxwidth = W_WIDTH(wp) - col; | |
7 | 6707 #ifdef FEAT_WINDOWS |
677 | 6708 if (!wp->w_status_height) |
6709 #endif | |
6710 { | |
6711 row = Rows - 1; | |
6712 --maxwidth; /* writing in last column may cause scrolling */ | |
6713 fillchar = ' '; | |
6714 attr = 0; | |
6715 } | |
6716 | |
6717 # ifdef FEAT_EVAL | |
681 | 6718 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6719 # endif |
6720 } | |
6721 else | |
6722 { | |
6723 if (*wp->w_p_stl != NUL) | |
1983 | 6724 stl = wp->w_p_stl; |
677 | 6725 else |
1983 | 6726 stl = p_stl; |
677 | 6727 # ifdef FEAT_EVAL |
681 | 6728 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6729 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6730 # endif |
6731 } | |
6732 | |
6733 #ifdef FEAT_VERTSPLIT | |
6734 col += W_WINCOL(wp); | |
6735 #endif | |
6736 } | |
6737 | |
7 | 6738 if (maxwidth <= 0) |
6739 return; | |
677 | 6740 |
2693 | 6741 /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
6742 * the cursor away and back. */ | |
6743 ewp = wp == NULL ? curwin : wp; | |
6744 p_crb_save = ewp->w_p_crb; | |
6745 ewp->w_p_crb = FALSE; | |
6746 | |
1983 | 6747 /* Make a copy, because the statusline may include a function call that |
6748 * might change the option value and free the memory. */ | |
6749 stl = vim_strsave(stl); | |
2693 | 6750 width = build_stl_str_hl(ewp, buf, sizeof(buf), |
1983 | 6751 stl, use_sandbox, |
681 | 6752 fillchar, maxwidth, hltab, tabtab); |
1983 | 6753 vim_free(stl); |
2693 | 6754 ewp->w_p_crb = p_crb_save; |
2661 | 6755 |
6756 /* Make all characters printable. */ | |
6757 p = transstr(buf); | |
6758 if (p != NULL) | |
6759 { | |
6760 vim_strncpy(buf, p, sizeof(buf) - 1); | |
6761 vim_free(p); | |
6762 } | |
6763 | |
6764 /* fill up with "fillchar" */ | |
835 | 6765 len = (int)STRLEN(buf); |
1883 | 6766 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6767 { |
6768 #ifdef FEAT_MBYTE | |
6769 len += (*mb_char2bytes)(fillchar, buf + len); | |
6770 #else | |
6771 buf[len++] = fillchar; | |
6772 #endif | |
6773 ++width; | |
6774 } | |
6775 buf[len] = NUL; | |
6776 | |
681 | 6777 /* |
6778 * Draw each snippet with the specified highlighting. | |
6779 */ | |
7 | 6780 curattr = attr; |
6781 p = buf; | |
681 | 6782 for (n = 0; hltab[n].start != NULL; n++) |
6783 { | |
6784 len = (int)(hltab[n].start - p); | |
7 | 6785 screen_puts_len(p, len, row, col, curattr); |
6786 col += vim_strnsize(p, len); | |
681 | 6787 p = hltab[n].start; |
6788 | |
6789 if (hltab[n].userhl == 0) | |
7 | 6790 curattr = attr; |
681 | 6791 else if (hltab[n].userhl < 0) |
6792 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6793 #ifdef FEAT_WINDOWS |
680 | 6794 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6795 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6796 #endif |
6797 else | |
681 | 6798 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6799 } |
6800 screen_puts(p, row, col, curattr); | |
681 | 6801 |
6802 if (wp == NULL) | |
6803 { | |
6804 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6805 col = 0; | |
6806 len = 0; | |
6807 p = buf; | |
6808 fillchar = 0; | |
6809 for (n = 0; tabtab[n].start != NULL; n++) | |
6810 { | |
6811 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6812 while (col < len) | |
6813 TabPageIdxs[col++] = fillchar; | |
6814 p = tabtab[n].start; | |
6815 fillchar = tabtab[n].userhl; | |
6816 } | |
6817 while (col < Columns) | |
6818 TabPageIdxs[col++] = fillchar; | |
6819 } | |
7 | 6820 } |
6821 | |
6822 #endif /* FEAT_STL_OPT */ | |
6823 | |
6824 /* | |
6825 * Output a single character directly to the screen and update ScreenLines. | |
6826 */ | |
6827 void | |
6828 screen_putchar(c, row, col, attr) | |
6829 int c; | |
6830 int row, col; | |
6831 int attr; | |
6832 { | |
3549 | 6833 char_u buf[MB_MAXBYTES + 1]; |
6834 | |
7 | 6835 #ifdef FEAT_MBYTE |
3549 | 6836 if (has_mbyte) |
6837 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6838 else | |
6839 #endif | |
6840 { | |
6841 buf[0] = c; | |
6842 buf[1] = NUL; | |
6843 } | |
7 | 6844 screen_puts(buf, row, col, attr); |
6845 } | |
6846 | |
6847 /* | |
6848 * Get a single character directly from ScreenLines into "bytes[]". | |
6849 * Also return its attribute in *attrp; | |
6850 */ | |
6851 void | |
6852 screen_getbytes(row, col, bytes, attrp) | |
6853 int row, col; | |
6854 char_u *bytes; | |
6855 int *attrp; | |
6856 { | |
6857 unsigned off; | |
6858 | |
6859 /* safety check */ | |
6860 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6861 { | |
6862 off = LineOffset[row] + col; | |
6863 *attrp = ScreenAttrs[off]; | |
6864 bytes[0] = ScreenLines[off]; | |
6865 bytes[1] = NUL; | |
6866 | |
6867 #ifdef FEAT_MBYTE | |
6868 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6869 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6870 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6871 { | |
6872 bytes[0] = ScreenLines[off]; | |
6873 bytes[1] = ScreenLines2[off]; | |
6874 bytes[2] = NUL; | |
6875 } | |
6876 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6877 { | |
6878 bytes[1] = ScreenLines[off + 1]; | |
6879 bytes[2] = NUL; | |
6880 } | |
6881 #endif | |
6882 } | |
6883 } | |
6884 | |
714 | 6885 #ifdef FEAT_MBYTE |
6886 static int screen_comp_differs __ARGS((int, int*)); | |
6887 | |
6888 /* | |
6889 * Return TRUE if composing characters for screen posn "off" differs from | |
6890 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6891 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6892 */ |
6893 static int | |
6894 screen_comp_differs(off, u8cc) | |
6895 int off; | |
6896 int *u8cc; | |
6897 { | |
6898 int i; | |
6899 | |
6900 for (i = 0; i < Screen_mco; ++i) | |
6901 { | |
6902 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6903 return TRUE; | |
6904 if (u8cc[i] == 0) | |
6905 break; | |
6906 } | |
6907 return FALSE; | |
6908 } | |
6909 #endif | |
6910 | |
7 | 6911 /* |
6912 * Put string '*text' on the screen at position 'row' and 'col', with | |
6913 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6914 * Note: only outputs within one row, message is truncated at screen boundary! | |
6915 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6916 */ | |
6917 void | |
6918 screen_puts(text, row, col, attr) | |
6919 char_u *text; | |
6920 int row; | |
6921 int col; | |
6922 int attr; | |
6923 { | |
6924 screen_puts_len(text, -1, row, col, attr); | |
6925 } | |
6926 | |
6927 /* | |
6928 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6929 * a NUL. | |
6930 */ | |
6931 void | |
6932 screen_puts_len(text, len, row, col, attr) | |
6933 char_u *text; | |
6934 int len; | |
6935 int row; | |
6936 int col; | |
6937 int attr; | |
6938 { | |
6939 unsigned off; | |
6940 char_u *ptr = text; | |
6941 int c; | |
6942 #ifdef FEAT_MBYTE | |
1378 | 6943 unsigned max_off; |
7 | 6944 int mbyte_blen = 1; |
6945 int mbyte_cells = 1; | |
6946 int u8c = 0; | |
714 | 6947 int u8cc[MAX_MCO]; |
7 | 6948 int clear_next_cell = FALSE; |
6949 # ifdef FEAT_ARABIC | |
6950 int prev_c = 0; /* previous Arabic character */ | |
714 | 6951 int pc, nc, nc1; |
6952 int pcc[MAX_MCO]; | |
7 | 6953 # endif |
6954 #endif | |
1843 | 6955 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6956 int force_redraw_this; | |
6957 int force_redraw_next = FALSE; | |
6958 #endif | |
6959 int need_redraw; | |
7 | 6960 |
6961 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6962 return; | |
1843 | 6963 off = LineOffset[row] + col; |
7 | 6964 |
1668 | 6965 #ifdef FEAT_MBYTE |
6966 /* When drawing over the right halve of a double-wide char clear out the | |
6967 * left halve. Only needed in a terminal. */ | |
1685 | 6968 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6969 # ifdef FEAT_GUI |
6970 && !gui.in_use | |
6971 # endif | |
6972 && mb_fix_col(col, row) != col) | |
1843 | 6973 { |
6974 ScreenLines[off - 1] = ' '; | |
6975 ScreenAttrs[off - 1] = 0; | |
6976 if (enc_utf8) | |
6977 { | |
6978 ScreenLinesUC[off - 1] = 0; | |
6979 ScreenLinesC[0][off - 1] = 0; | |
6980 } | |
6981 /* redraw the previous cell, make it empty */ | |
6982 screen_char(off - 1, row, col - 1); | |
6983 /* force the cell at "col" to be redrawn */ | |
6984 force_redraw_next = TRUE; | |
6985 } | |
6986 #endif | |
6987 | |
1378 | 6988 #ifdef FEAT_MBYTE |
6989 max_off = LineOffset[row] + screen_Columns; | |
6990 #endif | |
1340 | 6991 while (col < screen_Columns |
6992 && (len < 0 || (int)(ptr - text) < len) | |
6993 && *ptr != NUL) | |
7 | 6994 { |
6995 c = *ptr; | |
6996 #ifdef FEAT_MBYTE | |
6997 /* check if this is the first byte of a multibyte */ | |
6998 if (has_mbyte) | |
6999 { | |
7000 if (enc_utf8 && len > 0) | |
474 | 7001 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 7002 else |
474 | 7003 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 7004 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
7005 mbyte_cells = 1; | |
7006 else if (enc_dbcs != 0) | |
7007 mbyte_cells = mbyte_blen; | |
7008 else /* enc_utf8 */ | |
7009 { | |
7010 if (len >= 0) | |
714 | 7011 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 7012 (int)((text + len) - ptr)); |
7013 else | |
714 | 7014 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 7015 mbyte_cells = utf_char2cells(u8c); |
1401 | 7016 # ifdef UNICODE16 |
7 | 7017 /* Non-BMP character: display as ? or fullwidth ?. */ |
7018 if (u8c >= 0x10000) | |
7019 { | |
7020 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
7021 if (attr == 0) | |
7022 attr = hl_attr(HLF_8); | |
7023 } | |
1401 | 7024 # endif |
7 | 7025 # ifdef FEAT_ARABIC |
7026 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
7027 { | |
7028 /* Do Arabic shaping. */ | |
7029 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
7030 { | |
7031 /* Past end of string to be displayed. */ | |
7032 nc = NUL; | |
7033 nc1 = NUL; | |
7034 } | |
7035 else | |
714 | 7036 { |
1994 | 7037 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
7038 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 7039 nc1 = pcc[0]; |
7040 } | |
7 | 7041 pc = prev_c; |
7042 prev_c = u8c; | |
714 | 7043 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 7044 } |
7045 else | |
7046 prev_c = u8c; | |
7047 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7048 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7049 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7050 /* Only 1 cell left, but character requires 2 cells: |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7051 * display a '>' in the last column to avoid wrapping. */ |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7052 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7053 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
7054 } |
7 | 7055 } |
7056 } | |
7057 #endif | |
7058 | |
1843 | 7059 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
7060 force_redraw_this = force_redraw_next; | |
7061 force_redraw_next = FALSE; | |
7062 #endif | |
7063 | |
7064 need_redraw = ScreenLines[off] != c | |
7 | 7065 #ifdef FEAT_MBYTE |
7066 || (mbyte_cells == 2 | |
7067 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
7068 || (enc_dbcs == DBCS_JPNU | |
7069 && c == 0x8e | |
7070 && ScreenLines2[off] != ptr[1]) | |
7071 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7072 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7073 (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7074 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7075 && screen_comp_differs(off, u8cc)))) |
7 | 7076 #endif |
7077 || ScreenAttrs[off] != attr | |
1843 | 7078 || exmode_active; |
7079 | |
7080 if (need_redraw | |
7081 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
7082 || force_redraw_this | |
7083 #endif | |
7 | 7084 ) |
7085 { | |
7086 #if defined(FEAT_GUI) || defined(UNIX) | |
7087 /* The bold trick makes a single row of pixels appear in the next | |
7088 * character. When a bold character is removed, the next | |
7089 * character should be redrawn too. This happens for our own GUI | |
1843 | 7090 * and for some xterms. */ |
7091 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 7092 # ifdef FEAT_GUI |
7093 gui.in_use | |
7094 # endif | |
7095 # if defined(FEAT_GUI) && defined(UNIX) | |
7096 || | |
7097 # endif | |
7098 # ifdef UNIX | |
7099 term_is_xterm | |
7100 # endif | |
1843 | 7101 )) |
7102 { | |
7103 int n = ScreenAttrs[off]; | |
7104 | |
7105 if (n > HL_ALL) | |
7106 n = syn_attr2attr(n); | |
7107 if (n & HL_BOLD) | |
7108 force_redraw_next = TRUE; | |
7 | 7109 } |
7110 #endif | |
7111 #ifdef FEAT_MBYTE | |
7112 /* When at the end of the text and overwriting a two-cell | |
7113 * character with a one-cell character, need to clear the next | |
7114 * cell. Also when overwriting the left halve of a two-cell char | |
7115 * with the right halve of a two-cell char. Do this only once | |
7116 * (mb_off2cells() may return 2 on the right halve). */ | |
7117 if (clear_next_cell) | |
7118 clear_next_cell = FALSE; | |
7119 else if (has_mbyte | |
7120 && (len < 0 ? ptr[mbyte_blen] == NUL | |
7121 : ptr + mbyte_blen >= text + len) | |
1378 | 7122 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 7123 || (mbyte_cells == 2 |
1378 | 7124 && (*mb_off2cells)(off, max_off) == 1 |
7125 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 7126 clear_next_cell = TRUE; |
7127 | |
7128 /* Make sure we never leave a second byte of a double-byte behind, | |
7129 * it confuses mb_off2cells(). */ | |
7130 if (enc_dbcs | |
1378 | 7131 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 7132 || (mbyte_cells == 2 |
1378 | 7133 && (*mb_off2cells)(off, max_off) == 1 |
7134 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 7135 ScreenLines[off + mbyte_blen] = 0; |
7136 #endif | |
7137 ScreenLines[off] = c; | |
7138 ScreenAttrs[off] = attr; | |
7139 #ifdef FEAT_MBYTE | |
7140 if (enc_utf8) | |
7141 { | |
714 | 7142 if (c < 0x80 && u8cc[0] == 0) |
7 | 7143 ScreenLinesUC[off] = 0; |
7144 else | |
7145 { | |
714 | 7146 int i; |
7147 | |
7 | 7148 ScreenLinesUC[off] = u8c; |
714 | 7149 for (i = 0; i < Screen_mco; ++i) |
7150 { | |
7151 ScreenLinesC[i][off] = u8cc[i]; | |
7152 if (u8cc[i] == 0) | |
7153 break; | |
7154 } | |
7 | 7155 } |
7156 if (mbyte_cells == 2) | |
7157 { | |
7158 ScreenLines[off + 1] = 0; | |
7159 ScreenAttrs[off + 1] = attr; | |
7160 } | |
7161 screen_char(off, row, col); | |
7162 } | |
7163 else if (mbyte_cells == 2) | |
7164 { | |
7165 ScreenLines[off + 1] = ptr[1]; | |
7166 ScreenAttrs[off + 1] = attr; | |
7167 screen_char_2(off, row, col); | |
7168 } | |
7169 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
7170 { | |
7171 ScreenLines2[off] = ptr[1]; | |
7172 screen_char(off, row, col); | |
7173 } | |
7174 else | |
7175 #endif | |
7176 screen_char(off, row, col); | |
7177 } | |
7178 #ifdef FEAT_MBYTE | |
7179 if (has_mbyte) | |
7180 { | |
7181 off += mbyte_cells; | |
7182 col += mbyte_cells; | |
7183 ptr += mbyte_blen; | |
7184 if (clear_next_cell) | |
7185 ptr = (char_u *)" "; | |
7186 } | |
7187 else | |
7188 #endif | |
7189 { | |
7190 ++off; | |
7191 ++col; | |
7192 ++ptr; | |
7193 } | |
7194 } | |
1843 | 7195 |
7196 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
7197 /* If we detected the next character needs to be redrawn, but the text | |
7198 * doesn't extend up to there, update the character here. */ | |
7199 if (force_redraw_next && col < screen_Columns) | |
7200 { | |
7201 # ifdef FEAT_MBYTE | |
7202 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
7203 screen_char_2(off, row, col); | |
7204 else | |
7205 # endif | |
7206 screen_char(off, row, col); | |
7207 } | |
7208 #endif | |
7 | 7209 } |
7210 | |
7211 #ifdef FEAT_SEARCH_EXTRA | |
7212 /* | |
1326 | 7213 * Prepare for 'hlsearch' highlighting. |
7 | 7214 */ |
7215 static void | |
7216 start_search_hl() | |
7217 { | |
7218 if (p_hls && !no_hlsearch) | |
7219 { | |
7220 last_pat_prog(&search_hl.rm); | |
7221 search_hl.attr = hl_attr(HLF_L); | |
1521 | 7222 # ifdef FEAT_RELTIME |
7223 /* Set the time limit to 'redrawtime'. */ | |
7224 profile_setlimit(p_rdt, &search_hl.tm); | |
7225 # endif | |
7 | 7226 } |
7227 } | |
7228 | |
7229 /* | |
1326 | 7230 * Clean up for 'hlsearch' highlighting. |
7 | 7231 */ |
7232 static void | |
7233 end_search_hl() | |
7234 { | |
7235 if (search_hl.rm.regprog != NULL) | |
7236 { | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4795
diff
changeset
|
7237 vim_regfree(search_hl.rm.regprog); |
7 | 7238 search_hl.rm.regprog = NULL; |
7239 } | |
7240 } | |
7241 | |
7242 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7243 * Init for calling prepare_search_hl(). |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7244 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7245 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7246 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7247 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7248 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7249 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7250 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7251 /* Setup for match and 'hlsearch' highlighting. Disable any previous |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7252 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7253 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7254 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7255 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7256 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7257 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7258 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7259 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7260 cur->hl.attr = syn_id2attr(cur->hlg_id); |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7261 cur->hl.buf = wp->w_buffer; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7262 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7263 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7264 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7265 /* Set the time limit to 'redrawtime'. */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7266 profile_setlimit(p_rdt, &(cur->hl.tm)); |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7267 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7268 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7269 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7270 search_hl.buf = wp->w_buffer; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7271 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7272 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7273 /* time limit is set at the toplevel, for all windows */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7274 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7275 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7276 /* |
7 | 7277 * Advance to the match in window "wp" line "lnum" or past it. |
7278 */ | |
7279 static void | |
7280 prepare_search_hl(wp, lnum) | |
7281 win_T *wp; | |
7282 linenr_T lnum; | |
7283 { | |
1326 | 7284 matchitem_T *cur; /* points to the match list */ |
7285 match_T *shl; /* points to search_hl or a match */ | |
7286 int shl_flag; /* flag to indicate whether search_hl | |
7287 has been processed or not */ | |
7 | 7288 int n; |
7289 | |
7290 /* | |
7291 * When using a multi-line pattern, start searching at the top | |
7292 * of the window or just after a closed fold. | |
1326 | 7293 * Do this both for search_hl and the match list. |
7 | 7294 */ |
1326 | 7295 cur = wp->w_match_head; |
7296 shl_flag = FALSE; | |
7297 while (cur != NULL || shl_flag == FALSE) | |
7298 { | |
7299 if (shl_flag == FALSE) | |
7300 { | |
7301 shl = &search_hl; | |
7302 shl_flag = TRUE; | |
7303 } | |
7304 else | |
7305 shl = &cur->hl; | |
7 | 7306 if (shl->rm.regprog != NULL |
7307 && shl->lnum == 0 | |
7308 && re_multiline(shl->rm.regprog)) | |
7309 { | |
7310 if (shl->first_lnum == 0) | |
7311 { | |
7312 # ifdef FEAT_FOLDING | |
7313 for (shl->first_lnum = lnum; | |
7314 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7315 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7316 NULL, NULL, TRUE, NULL)) | |
7317 break; | |
7318 # else | |
7319 shl->first_lnum = wp->w_topline; | |
7320 # endif | |
7321 } | |
7322 n = 0; | |
7323 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7324 { | |
7325 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7326 if (shl->lnum != 0) | |
7327 { | |
7328 shl->first_lnum = shl->lnum | |
7329 + shl->rm.endpos[0].lnum | |
7330 - shl->rm.startpos[0].lnum; | |
7331 n = shl->rm.endpos[0].col; | |
7332 } | |
7333 else | |
7334 { | |
7335 ++shl->first_lnum; | |
7336 n = 0; | |
7337 } | |
7338 } | |
7339 } | |
1326 | 7340 if (shl != &search_hl && cur != NULL) |
7341 cur = cur->next; | |
7 | 7342 } |
7343 } | |
7344 | |
7345 /* | |
1326 | 7346 * Search for a next 'hlsearch' or match. |
7 | 7347 * Uses shl->buf. |
7348 * Sets shl->lnum and shl->rm contents. | |
7349 * Note: Assumes a previous match is always before "lnum", unless | |
7350 * shl->lnum is zero. | |
7351 * Careful: Any pointers for buffer lines will become invalid. | |
7352 */ | |
7353 static void | |
7354 next_search_hl(win, shl, lnum, mincol) | |
7355 win_T *win; | |
1326 | 7356 match_T *shl; /* points to search_hl or a match */ |
7 | 7357 linenr_T lnum; |
7358 colnr_T mincol; /* minimal column for a match */ | |
7359 { | |
7360 linenr_T l; | |
7361 colnr_T matchcol; | |
7362 long nmatched; | |
7363 | |
7364 if (shl->lnum != 0) | |
7365 { | |
7366 /* Check for three situations: | |
7367 * 1. If the "lnum" is below a previous match, start a new search. | |
7368 * 2. If the previous match includes "mincol", use it. | |
7369 * 3. Continue after the previous match. | |
7370 */ | |
7371 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7372 if (lnum > l) | |
7373 shl->lnum = 0; | |
7374 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7375 return; | |
7376 } | |
7377 | |
7378 /* | |
7379 * Repeat searching for a match until one is found that includes "mincol" | |
7380 * or none is found in this line. | |
7381 */ | |
7382 called_emsg = FALSE; | |
7383 for (;;) | |
7384 { | |
1521 | 7385 #ifdef FEAT_RELTIME |
7386 /* Stop searching after passing the time limit. */ | |
7387 if (profile_passed_limit(&(shl->tm))) | |
7388 { | |
7389 shl->lnum = 0; /* no match found in time */ | |
7390 break; | |
7391 } | |
7392 #endif | |
7 | 7393 /* Three situations: |
7394 * 1. No useful previous match: search from start of line. | |
7395 * 2. Not Vi compatible or empty match: continue at next character. | |
7396 * Break the loop if this is beyond the end of the line. | |
7397 * 3. Vi compatible searching: continue at end of previous match. | |
7398 */ | |
7399 if (shl->lnum == 0) | |
7400 matchcol = 0; | |
7401 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7402 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7403 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7404 { | |
688 | 7405 char_u *ml; |
685 | 7406 |
7407 matchcol = shl->rm.startpos[0].col; | |
688 | 7408 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7409 if (*ml == NUL) |
7410 { | |
7411 ++matchcol; | |
7 | 7412 shl->lnum = 0; |
7413 break; | |
7414 } | |
685 | 7415 #ifdef FEAT_MBYTE |
7416 if (has_mbyte) | |
7417 matchcol += mb_ptr2len(ml); | |
7418 else | |
7419 #endif | |
7420 ++matchcol; | |
7 | 7421 } |
7422 else | |
7423 matchcol = shl->rm.endpos[0].col; | |
7424 | |
7425 shl->lnum = lnum; | |
1521 | 7426 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7427 #ifdef FEAT_RELTIME | |
7428 &(shl->tm) | |
7429 #else | |
7430 NULL | |
7431 #endif | |
7432 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7433 if (called_emsg || got_int) |
7 | 7434 { |
7435 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7436 if (shl == &search_hl) |
7437 { | |
1326 | 7438 /* don't free regprog in the match list, it's a copy */ |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4795
diff
changeset
|
7439 vim_regfree(shl->rm.regprog); |
1112 | 7440 no_hlsearch = TRUE; |
7441 } | |
7 | 7442 shl->rm.regprog = NULL; |
1112 | 7443 shl->lnum = 0; |
7444 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7445 break; |
7446 } | |
7447 if (nmatched == 0) | |
7448 { | |
7449 shl->lnum = 0; /* no match found */ | |
7450 break; | |
7451 } | |
7452 if (shl->rm.startpos[0].lnum > 0 | |
7453 || shl->rm.startpos[0].col >= mincol | |
7454 || nmatched > 1 | |
7455 || shl->rm.endpos[0].col > mincol) | |
7456 { | |
7457 shl->lnum += shl->rm.startpos[0].lnum; | |
7458 break; /* useful match found */ | |
7459 } | |
7460 } | |
7461 } | |
7462 #endif | |
7463 | |
7464 static void | |
7465 screen_start_highlight(attr) | |
7466 int attr; | |
7467 { | |
7468 attrentry_T *aep = NULL; | |
7469 | |
7470 screen_attr = attr; | |
7471 if (full_screen | |
7472 #ifdef WIN3264 | |
7473 && termcap_active | |
7474 #endif | |
7475 ) | |
7476 { | |
7477 #ifdef FEAT_GUI | |
7478 if (gui.in_use) | |
7479 { | |
7480 char buf[20]; | |
7481 | |
681 | 7482 /* The GUI handles this internally. */ |
7483 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7484 OUT_STR(buf); |
7485 } | |
7486 else | |
7487 #endif | |
7488 { | |
7489 if (attr > HL_ALL) /* special HL attr. */ | |
7490 { | |
7491 if (t_colors > 1) | |
7492 aep = syn_cterm_attr2entry(attr); | |
7493 else | |
7494 aep = syn_term_attr2entry(attr); | |
7495 if (aep == NULL) /* did ":syntax clear" */ | |
7496 attr = 0; | |
7497 else | |
7498 attr = aep->ae_attr; | |
7499 } | |
7500 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7501 out_str(T_MD); | |
681 | 7502 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7503 && cterm_normal_fg_bold) | |
7504 /* If the Normal FG color has BOLD attribute and the new HL | |
7505 * has a FG color defined, clear BOLD. */ | |
7506 out_str(T_ME); | |
7 | 7507 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7508 out_str(T_SO); | |
205 | 7509 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7510 /* underline or undercurl */ | |
7 | 7511 out_str(T_US); |
7512 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7513 out_str(T_CZH); | |
7514 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7515 out_str(T_MR); | |
7516 | |
7517 /* | |
7518 * Output the color or start string after bold etc., in case the | |
7519 * bold etc. override the color setting. | |
7520 */ | |
7521 if (aep != NULL) | |
7522 { | |
7523 if (t_colors > 1) | |
7524 { | |
7525 if (aep->ae_u.cterm.fg_color) | |
7526 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7527 if (aep->ae_u.cterm.bg_color) | |
7528 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7529 } | |
7530 else | |
7531 { | |
7532 if (aep->ae_u.term.start != NULL) | |
7533 out_str(aep->ae_u.term.start); | |
7534 } | |
7535 } | |
7536 } | |
7537 } | |
7538 } | |
7539 | |
7540 void | |
7541 screen_stop_highlight() | |
7542 { | |
7543 int do_ME = FALSE; /* output T_ME code */ | |
7544 | |
7545 if (screen_attr != 0 | |
7546 #ifdef WIN3264 | |
7547 && termcap_active | |
7548 #endif | |
7549 ) | |
7550 { | |
7551 #ifdef FEAT_GUI | |
7552 if (gui.in_use) | |
7553 { | |
7554 char buf[20]; | |
7555 | |
7556 /* use internal GUI code */ | |
7557 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7558 OUT_STR(buf); | |
7559 } | |
7560 else | |
7561 #endif | |
7562 { | |
7563 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7564 { | |
7565 attrentry_T *aep; | |
7566 | |
7567 if (t_colors > 1) | |
7568 { | |
7569 /* | |
7570 * Assume that t_me restores the original colors! | |
7571 */ | |
7572 aep = syn_cterm_attr2entry(screen_attr); | |
7573 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7574 || aep->ae_u.cterm.bg_color)) | |
7575 do_ME = TRUE; | |
7576 } | |
7577 else | |
7578 { | |
7579 aep = syn_term_attr2entry(screen_attr); | |
7580 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7581 { | |
7582 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7583 do_ME = TRUE; | |
7584 else | |
7585 out_str(aep->ae_u.term.stop); | |
7586 } | |
7587 } | |
7588 if (aep == NULL) /* did ":syntax clear" */ | |
7589 screen_attr = 0; | |
7590 else | |
7591 screen_attr = aep->ae_attr; | |
7592 } | |
7593 | |
7594 /* | |
7595 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7596 * same sequence several times. | |
7597 */ | |
7598 if (screen_attr & HL_STANDOUT) | |
7599 { | |
7600 if (STRCMP(T_SE, T_ME) == 0) | |
7601 do_ME = TRUE; | |
7602 else | |
7603 out_str(T_SE); | |
7604 } | |
205 | 7605 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7606 { |
7607 if (STRCMP(T_UE, T_ME) == 0) | |
7608 do_ME = TRUE; | |
7609 else | |
7610 out_str(T_UE); | |
7611 } | |
7612 if (screen_attr & HL_ITALIC) | |
7613 { | |
7614 if (STRCMP(T_CZR, T_ME) == 0) | |
7615 do_ME = TRUE; | |
7616 else | |
7617 out_str(T_CZR); | |
7618 } | |
7619 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7620 out_str(T_ME); | |
7621 | |
7622 if (t_colors > 1) | |
7623 { | |
7624 /* set Normal cterm colors */ | |
7625 if (cterm_normal_fg_color != 0) | |
7626 term_fg_color(cterm_normal_fg_color - 1); | |
7627 if (cterm_normal_bg_color != 0) | |
7628 term_bg_color(cterm_normal_bg_color - 1); | |
7629 if (cterm_normal_fg_bold) | |
7630 out_str(T_MD); | |
7631 } | |
7632 } | |
7633 } | |
7634 screen_attr = 0; | |
7635 } | |
7636 | |
7637 /* | |
7638 * Reset the colors for a cterm. Used when leaving Vim. | |
7639 * The machine specific code may override this again. | |
7640 */ | |
7641 void | |
7642 reset_cterm_colors() | |
7643 { | |
7644 if (t_colors > 1) | |
7645 { | |
7646 /* set Normal cterm colors */ | |
7647 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7648 { | |
7649 out_str(T_OP); | |
7650 screen_attr = -1; | |
7651 } | |
7652 if (cterm_normal_fg_bold) | |
7653 { | |
7654 out_str(T_ME); | |
7655 screen_attr = -1; | |
7656 } | |
7657 } | |
7658 } | |
7659 | |
7660 /* | |
7661 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7662 * using the attributes from ScreenAttrs["off"]. | |
7663 */ | |
7664 static void | |
7665 screen_char(off, row, col) | |
7666 unsigned off; | |
7667 int row; | |
7668 int col; | |
7669 { | |
7670 int attr; | |
7671 | |
7672 /* Check for illegal values, just in case (could happen just after | |
7673 * resizing). */ | |
7674 if (row >= screen_Rows || col >= screen_Columns) | |
7675 return; | |
7676 | |
7677 /* Outputting the last character on the screen may scrollup the screen. | |
7678 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7679 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7680 #ifdef FEAT_RIGHTLEFT | |
7681 /* account for first command-line character in rightleft mode */ | |
7682 && !cmdmsg_rl | |
7683 #endif | |
7684 ) | |
7685 { | |
7686 ScreenAttrs[off] = (sattr_T)-1; | |
7687 return; | |
7688 } | |
7689 | |
7690 /* | |
7691 * Stop highlighting first, so it's easier to move the cursor. | |
7692 */ | |
7693 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7694 if (screen_char_attr != 0) | |
7695 attr = screen_char_attr; | |
7696 else | |
7697 #endif | |
7698 attr = ScreenAttrs[off]; | |
7699 if (screen_attr != attr) | |
7700 screen_stop_highlight(); | |
7701 | |
7702 windgoto(row, col); | |
7703 | |
7704 if (screen_attr != attr) | |
7705 screen_start_highlight(attr); | |
7706 | |
7707 #ifdef FEAT_MBYTE | |
7708 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7709 { | |
7710 char_u buf[MB_MAXBYTES + 1]; | |
7711 | |
7712 /* Convert UTF-8 character to bytes and write it. */ | |
7713 | |
7714 buf[utfc_char2bytes(off, buf)] = NUL; | |
7715 | |
7716 out_str(buf); | |
7717 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7718 ++screen_cur_col; | |
7719 } | |
7720 else | |
7721 #endif | |
7722 { | |
7723 #ifdef FEAT_MBYTE | |
7724 out_flush_check(); | |
7725 #endif | |
7726 out_char(ScreenLines[off]); | |
7727 #ifdef FEAT_MBYTE | |
7728 /* double-byte character in single-width cell */ | |
7729 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7730 out_char(ScreenLines2[off]); | |
7731 #endif | |
7732 } | |
7733 | |
7734 screen_cur_col++; | |
7735 } | |
7736 | |
7737 #ifdef FEAT_MBYTE | |
7738 | |
7739 /* | |
7740 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7741 * on the screen at position 'row' and 'col'. | |
7742 * The attributes of the first byte is used for all. This is required to | |
7743 * output the two bytes of a double-byte character with nothing in between. | |
7744 */ | |
7745 static void | |
7746 screen_char_2(off, row, col) | |
7747 unsigned off; | |
7748 int row; | |
7749 int col; | |
7750 { | |
7751 /* Check for illegal values (could be wrong when screen was resized). */ | |
7752 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7753 return; | |
7754 | |
7755 /* Outputting the last character on the screen may scrollup the screen. | |
7756 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7757 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7758 { | |
7759 ScreenAttrs[off] = (sattr_T)-1; | |
7760 return; | |
7761 } | |
7762 | |
7763 /* Output the first byte normally (positions the cursor), then write the | |
7764 * second byte directly. */ | |
7765 screen_char(off, row, col); | |
7766 out_char(ScreenLines[off + 1]); | |
7767 ++screen_cur_col; | |
7768 } | |
7769 #endif | |
7770 | |
7771 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7772 /* | |
7773 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7774 * This uses the contents of ScreenLines[] and doesn't change it. | |
7775 */ | |
7776 void | |
7777 screen_draw_rectangle(row, col, height, width, invert) | |
7778 int row; | |
7779 int col; | |
7780 int height; | |
7781 int width; | |
7782 int invert; | |
7783 { | |
7784 int r, c; | |
7785 int off; | |
1378 | 7786 #ifdef FEAT_MBYTE |
7787 int max_off; | |
7788 #endif | |
7 | 7789 |
534 | 7790 /* Can't use ScreenLines unless initialized */ |
7791 if (ScreenLines == NULL) | |
7792 return; | |
7793 | |
7 | 7794 if (invert) |
7795 screen_char_attr = HL_INVERSE; | |
7796 for (r = row; r < row + height; ++r) | |
7797 { | |
7798 off = LineOffset[r]; | |
1378 | 7799 #ifdef FEAT_MBYTE |
7800 max_off = off + screen_Columns; | |
7801 #endif | |
7 | 7802 for (c = col; c < col + width; ++c) |
7803 { | |
7804 #ifdef FEAT_MBYTE | |
1378 | 7805 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7806 { |
7807 screen_char_2(off + c, r, c); | |
7808 ++c; | |
7809 } | |
7810 else | |
7811 #endif | |
7812 { | |
7813 screen_char(off + c, r, c); | |
7814 #ifdef FEAT_MBYTE | |
1378 | 7815 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7816 ++c; |
7817 #endif | |
7818 } | |
7819 } | |
7820 } | |
7821 screen_char_attr = 0; | |
7822 } | |
7823 #endif | |
7824 | |
7825 #ifdef FEAT_VERTSPLIT | |
7826 /* | |
7827 * Redraw the characters for a vertically split window. | |
7828 */ | |
7829 static void | |
7830 redraw_block(row, end, wp) | |
7831 int row; | |
7832 int end; | |
7833 win_T *wp; | |
7834 { | |
7835 int col; | |
7836 int width; | |
7837 | |
7838 # ifdef FEAT_CLIPBOARD | |
7839 clip_may_clear_selection(row, end - 1); | |
7840 # endif | |
7841 | |
7842 if (wp == NULL) | |
7843 { | |
7844 col = 0; | |
7845 width = Columns; | |
7846 } | |
7847 else | |
7848 { | |
7849 col = wp->w_wincol; | |
7850 width = wp->w_width; | |
7851 } | |
7852 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7853 } | |
7854 #endif | |
7855 | |
7856 /* | |
7857 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7858 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7859 * Use attributes 'attr'. | |
7860 */ | |
7861 void | |
7862 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7863 int start_row, end_row; | |
7864 int start_col, end_col; | |
7865 int c1, c2; | |
7866 int attr; | |
7867 { | |
7868 int row; | |
7869 int col; | |
7870 int off; | |
7871 int end_off; | |
7872 int did_delete; | |
7873 int c; | |
7874 int norm_term; | |
7875 #if defined(FEAT_GUI) || defined(UNIX) | |
7876 int force_next = FALSE; | |
7877 #endif | |
7878 | |
7879 if (end_row > screen_Rows) /* safety check */ | |
7880 end_row = screen_Rows; | |
7881 if (end_col > screen_Columns) /* safety check */ | |
7882 end_col = screen_Columns; | |
7883 if (ScreenLines == NULL | |
7884 || start_row >= end_row | |
7885 || start_col >= end_col) /* nothing to do */ | |
7886 return; | |
7887 | |
7888 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7889 norm_term = ( | |
7890 #ifdef FEAT_GUI | |
7891 !gui.in_use && | |
7892 #endif | |
7893 t_colors <= 1); | |
7894 for (row = start_row; row < end_row; ++row) | |
7895 { | |
1668 | 7896 #ifdef FEAT_MBYTE |
7897 if (has_mbyte | |
7898 # ifdef FEAT_GUI | |
7899 && !gui.in_use | |
7900 # endif | |
7901 ) | |
7902 { | |
7903 /* When drawing over the right halve of a double-wide char clear | |
7904 * out the left halve. When drawing over the left halve of a | |
7905 * double wide-char clear out the right halve. Only needed in a | |
7906 * terminal. */ | |
1685 | 7907 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7908 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7909 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7910 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7911 } |
7912 #endif | |
7 | 7913 /* |
7914 * Try to use delete-line termcap code, when no attributes or in a | |
7915 * "normal" terminal, where a bold/italic space is just a | |
7916 * space. | |
7917 */ | |
7918 did_delete = FALSE; | |
7919 if (c2 == ' ' | |
7920 && end_col == Columns | |
7921 && can_clear(T_CE) | |
7922 && (attr == 0 | |
7923 || (norm_term | |
7924 && attr <= HL_ALL | |
7925 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7926 { | |
7927 /* | |
7928 * check if we really need to clear something | |
7929 */ | |
7930 col = start_col; | |
7931 if (c1 != ' ') /* don't clear first char */ | |
7932 ++col; | |
7933 | |
7934 off = LineOffset[row] + col; | |
7935 end_off = LineOffset[row] + end_col; | |
7936 | |
7937 /* skip blanks (used often, keep it fast!) */ | |
7938 #ifdef FEAT_MBYTE | |
7939 if (enc_utf8) | |
7940 while (off < end_off && ScreenLines[off] == ' ' | |
7941 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7942 ++off; | |
7943 else | |
7944 #endif | |
7945 while (off < end_off && ScreenLines[off] == ' ' | |
7946 && ScreenAttrs[off] == 0) | |
7947 ++off; | |
7948 if (off < end_off) /* something to be cleared */ | |
7949 { | |
7950 col = off - LineOffset[row]; | |
7951 screen_stop_highlight(); | |
7952 term_windgoto(row, col);/* clear rest of this screen line */ | |
7953 out_str(T_CE); | |
7954 screen_start(); /* don't know where cursor is now */ | |
7955 col = end_col - col; | |
7956 while (col--) /* clear chars in ScreenLines */ | |
7957 { | |
7958 ScreenLines[off] = ' '; | |
7959 #ifdef FEAT_MBYTE | |
7960 if (enc_utf8) | |
7961 ScreenLinesUC[off] = 0; | |
7962 #endif | |
7963 ScreenAttrs[off] = 0; | |
7964 ++off; | |
7965 } | |
7966 } | |
7967 did_delete = TRUE; /* the chars are cleared now */ | |
7968 } | |
7969 | |
7970 off = LineOffset[row] + start_col; | |
7971 c = c1; | |
7972 for (col = start_col; col < end_col; ++col) | |
7973 { | |
7974 if (ScreenLines[off] != c | |
7975 #ifdef FEAT_MBYTE | |
714 | 7976 || (enc_utf8 && (int)ScreenLinesUC[off] |
7977 != (c >= 0x80 ? c : 0)) | |
7 | 7978 #endif |
7979 || ScreenAttrs[off] != attr | |
7980 #if defined(FEAT_GUI) || defined(UNIX) | |
7981 || force_next | |
7982 #endif | |
7983 ) | |
7984 { | |
7985 #if defined(FEAT_GUI) || defined(UNIX) | |
7986 /* The bold trick may make a single row of pixels appear in | |
7987 * the next character. When a bold character is removed, the | |
7988 * next character should be redrawn too. This happens for our | |
7989 * own GUI and for some xterms. */ | |
7990 if ( | |
7991 # ifdef FEAT_GUI | |
7992 gui.in_use | |
7993 # endif | |
7994 # if defined(FEAT_GUI) && defined(UNIX) | |
7995 || | |
7996 # endif | |
7997 # ifdef UNIX | |
7998 term_is_xterm | |
7999 # endif | |
8000 ) | |
8001 { | |
8002 if (ScreenLines[off] != ' ' | |
8003 && (ScreenAttrs[off] > HL_ALL | |
8004 || ScreenAttrs[off] & HL_BOLD)) | |
8005 force_next = TRUE; | |
8006 else | |
8007 force_next = FALSE; | |
8008 } | |
8009 #endif | |
8010 ScreenLines[off] = c; | |
8011 #ifdef FEAT_MBYTE | |
8012 if (enc_utf8) | |
8013 { | |
8014 if (c >= 0x80) | |
8015 { | |
8016 ScreenLinesUC[off] = c; | |
714 | 8017 ScreenLinesC[0][off] = 0; |
7 | 8018 } |
8019 else | |
8020 ScreenLinesUC[off] = 0; | |
8021 } | |
8022 #endif | |
8023 ScreenAttrs[off] = attr; | |
8024 if (!did_delete || c != ' ') | |
8025 screen_char(off, row, col); | |
8026 } | |
8027 ++off; | |
8028 if (col == start_col) | |
8029 { | |
8030 if (did_delete) | |
8031 break; | |
8032 c = c2; | |
8033 } | |
8034 } | |
8035 if (end_col == Columns) | |
8036 LineWraps[row] = FALSE; | |
8037 if (row == Rows - 1) /* overwritten the command line */ | |
8038 { | |
8039 redraw_cmdline = TRUE; | |
8040 if (c1 == ' ' && c2 == ' ') | |
8041 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 8042 if (start_col == 0) |
8043 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 8044 } |
8045 } | |
8046 } | |
8047 | |
8048 /* | |
8049 * Check if there should be a delay. Used before clearing or redrawing the | |
8050 * screen or the command line. | |
8051 */ | |
8052 void | |
8053 check_for_delay(check_msg_scroll) | |
8054 int check_msg_scroll; | |
8055 { | |
8056 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
8057 && !did_wait_return | |
8058 && emsg_silent == 0) | |
8059 { | |
8060 out_flush(); | |
8061 ui_delay(1000L, TRUE); | |
8062 emsg_on_display = FALSE; | |
8063 if (check_msg_scroll) | |
8064 msg_scroll = FALSE; | |
8065 } | |
8066 } | |
8067 | |
8068 /* | |
8069 * screen_valid - allocate screen buffers if size changed | |
3263 | 8070 * If "doclear" is TRUE: clear screen if it has been resized. |
7 | 8071 * Returns TRUE if there is a valid screen to write to. |
8072 * Returns FALSE when starting up and screen not initialized yet. | |
8073 */ | |
8074 int | |
3263 | 8075 screen_valid(doclear) |
8076 int doclear; | |
7 | 8077 { |
3263 | 8078 screenalloc(doclear); /* allocate screen buffers if size changed */ |
7 | 8079 return (ScreenLines != NULL); |
8080 } | |
8081 | |
8082 /* | |
8083 * Resize the shell to Rows and Columns. | |
8084 * Allocate ScreenLines[] and associated items. | |
8085 * | |
8086 * There may be some time between setting Rows and Columns and (re)allocating | |
8087 * ScreenLines[]. This happens when starting up and when (manually) changing | |
8088 * the shell size. Always use screen_Rows and screen_Columns to access items | |
8089 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
8090 * final size of the shell is needed. | |
8091 */ | |
8092 void | |
3263 | 8093 screenalloc(doclear) |
8094 int doclear; | |
7 | 8095 { |
8096 int new_row, old_row; | |
8097 #ifdef FEAT_GUI | |
8098 int old_Rows; | |
8099 #endif | |
8100 win_T *wp; | |
8101 int outofmem = FALSE; | |
8102 int len; | |
8103 schar_T *new_ScreenLines; | |
8104 #ifdef FEAT_MBYTE | |
8105 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 8106 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 8107 schar_T *new_ScreenLines2 = NULL; |
714 | 8108 int i; |
7 | 8109 #endif |
8110 sattr_T *new_ScreenAttrs; | |
8111 unsigned *new_LineOffset; | |
8112 char_u *new_LineWraps; | |
671 | 8113 #ifdef FEAT_WINDOWS |
681 | 8114 short *new_TabPageIdxs; |
671 | 8115 tabpage_T *tp; |
8116 #endif | |
7 | 8117 static int entered = FALSE; /* avoid recursiveness */ |
944 | 8118 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 8119 #ifdef FEAT_AUTOCMD |
8120 int retry_count = 0; | |
8121 | |
8122 retry: | |
8123 #endif | |
7 | 8124 /* |
8125 * Allocation of the screen buffers is done only when the size changes and | |
8126 * when Rows and Columns have been set and we have started doing full | |
8127 * screen stuff. | |
8128 */ | |
8129 if ((ScreenLines != NULL | |
8130 && Rows == screen_Rows | |
8131 && Columns == screen_Columns | |
8132 #ifdef FEAT_MBYTE | |
8133 && enc_utf8 == (ScreenLinesUC != NULL) | |
8134 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 8135 && p_mco == Screen_mco |
7 | 8136 #endif |
8137 ) | |
8138 || Rows == 0 | |
8139 || Columns == 0 | |
8140 || (!full_screen && ScreenLines == NULL)) | |
8141 return; | |
8142 | |
8143 /* | |
8144 * It's possible that we produce an out-of-memory message below, which | |
8145 * will cause this function to be called again. To break the loop, just | |
8146 * return here. | |
8147 */ | |
8148 if (entered) | |
8149 return; | |
8150 entered = TRUE; | |
8151 | |
911 | 8152 /* |
8153 * Note that the window sizes are updated before reallocating the arrays, | |
8154 * thus we must not redraw here! | |
8155 */ | |
8156 ++RedrawingDisabled; | |
8157 | |
7 | 8158 win_new_shellsize(); /* fit the windows in the new sized shell */ |
8159 | |
8160 comp_col(); /* recompute columns for shown command and ruler */ | |
8161 | |
8162 /* | |
8163 * We're changing the size of the screen. | |
8164 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
8165 * - Move lines from the old arrays into the new arrays, clear extra | |
8166 * lines (unless the screen is going to be cleared). | |
8167 * - Free the old arrays. | |
8168 * | |
8169 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
8170 * Continuing with the old ScreenLines may result in a crash, because the | |
8171 * size is wrong. | |
8172 */ | |
671 | 8173 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 8174 win_free_lsize(wp); |
1946 | 8175 #ifdef FEAT_AUTOCMD |
8176 if (aucmd_win != NULL) | |
8177 win_free_lsize(aucmd_win); | |
8178 #endif | |
7 | 8179 |
8180 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
8181 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
8182 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
8183 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 8184 if (enc_utf8) |
8185 { | |
8186 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
8187 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 8188 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
8189 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 8190 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
8191 } | |
8192 if (enc_dbcs == DBCS_JPNU) | |
8193 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
8194 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
8195 #endif | |
8196 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
8197 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
8198 new_LineOffset = (unsigned *)lalloc((long_u)( | |
8199 Rows * sizeof(unsigned)), FALSE); | |
8200 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 8201 #ifdef FEAT_WINDOWS |
681 | 8202 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 8203 #endif |
7 | 8204 |
677 | 8205 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 8206 { |
8207 if (win_alloc_lines(wp) == FAIL) | |
8208 { | |
8209 outofmem = TRUE; | |
8210 #ifdef FEAT_WINDOWS | |
1819 | 8211 goto give_up; |
8212 #endif | |
8213 } | |
8214 } | |
1906 | 8215 #ifdef FEAT_AUTOCMD |
1946 | 8216 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
8217 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 8218 outofmem = TRUE; |
8219 #endif | |
1819 | 8220 #ifdef FEAT_WINDOWS |
8221 give_up: | |
8222 #endif | |
7 | 8223 |
714 | 8224 #ifdef FEAT_MBYTE |
8225 for (i = 0; i < p_mco; ++i) | |
8226 if (new_ScreenLinesC[i] == NULL) | |
8227 break; | |
8228 #endif | |
7 | 8229 if (new_ScreenLines == NULL |
8230 #ifdef FEAT_MBYTE | |
714 | 8231 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 8232 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
8233 #endif | |
8234 || new_ScreenAttrs == NULL | |
8235 || new_LineOffset == NULL | |
8236 || new_LineWraps == NULL | |
671 | 8237 #ifdef FEAT_WINDOWS |
8238 || new_TabPageIdxs == NULL | |
8239 #endif | |
7 | 8240 || outofmem) |
8241 { | |
944 | 8242 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 8243 { |
8244 /* guess the size */ | |
8245 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
8246 | |
8247 /* Remember we did this to avoid getting outofmem messages over | |
8248 * and over again. */ | |
944 | 8249 done_outofmem_msg = TRUE; |
534 | 8250 } |
7 | 8251 vim_free(new_ScreenLines); |
8252 new_ScreenLines = NULL; | |
8253 #ifdef FEAT_MBYTE | |
8254 vim_free(new_ScreenLinesUC); | |
8255 new_ScreenLinesUC = NULL; | |
714 | 8256 for (i = 0; i < p_mco; ++i) |
8257 { | |
8258 vim_free(new_ScreenLinesC[i]); | |
8259 new_ScreenLinesC[i] = NULL; | |
8260 } | |
7 | 8261 vim_free(new_ScreenLines2); |
8262 new_ScreenLines2 = NULL; | |
8263 #endif | |
8264 vim_free(new_ScreenAttrs); | |
8265 new_ScreenAttrs = NULL; | |
8266 vim_free(new_LineOffset); | |
8267 new_LineOffset = NULL; | |
8268 vim_free(new_LineWraps); | |
8269 new_LineWraps = NULL; | |
671 | 8270 #ifdef FEAT_WINDOWS |
8271 vim_free(new_TabPageIdxs); | |
8272 new_TabPageIdxs = NULL; | |
8273 #endif | |
7 | 8274 } |
8275 else | |
8276 { | |
944 | 8277 done_outofmem_msg = FALSE; |
534 | 8278 |
7 | 8279 for (new_row = 0; new_row < Rows; ++new_row) |
8280 { | |
8281 new_LineOffset[new_row] = new_row * Columns; | |
8282 new_LineWraps[new_row] = FALSE; | |
8283 | |
8284 /* | |
8285 * If the screen is not going to be cleared, copy as much as | |
8286 * possible from the old screen to the new one and clear the rest | |
8287 * (used when resizing the window at the "--more--" prompt or when | |
8288 * executing an external command, for the GUI). | |
8289 */ | |
3263 | 8290 if (!doclear) |
7 | 8291 { |
8292 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
8293 ' ', (size_t)Columns * sizeof(schar_T)); | |
8294 #ifdef FEAT_MBYTE | |
8295 if (enc_utf8) | |
8296 { | |
8297 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
8298 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 8299 for (i = 0; i < p_mco; ++i) |
8300 (void)vim_memset(new_ScreenLinesC[i] | |
8301 + new_row * Columns, | |
7 | 8302 0, (size_t)Columns * sizeof(u8char_T)); |
8303 } | |
8304 if (enc_dbcs == DBCS_JPNU) | |
8305 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8306 0, (size_t)Columns * sizeof(schar_T)); | |
8307 #endif | |
8308 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8309 0, (size_t)Columns * sizeof(sattr_T)); | |
8310 old_row = new_row + (screen_Rows - Rows); | |
534 | 8311 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8312 { |
8313 if (screen_Columns < Columns) | |
8314 len = screen_Columns; | |
8315 else | |
8316 len = Columns; | |
26 | 8317 #ifdef FEAT_MBYTE |
571 | 8318 /* When switching to utf-8 don't copy characters, they |
714 | 8319 * may be invalid now. Also when p_mco changes. */ |
8320 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8321 && p_mco == Screen_mco) | |
26 | 8322 #endif |
8323 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8324 ScreenLines + LineOffset[old_row], | |
8325 (size_t)len * sizeof(schar_T)); | |
7 | 8326 #ifdef FEAT_MBYTE |
714 | 8327 if (enc_utf8 && ScreenLinesUC != NULL |
8328 && p_mco == Screen_mco) | |
7 | 8329 { |
8330 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8331 ScreenLinesUC + LineOffset[old_row], | |
8332 (size_t)len * sizeof(u8char_T)); | |
714 | 8333 for (i = 0; i < p_mco; ++i) |
8334 mch_memmove(new_ScreenLinesC[i] | |
8335 + new_LineOffset[new_row], | |
8336 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8337 (size_t)len * sizeof(u8char_T)); |
8338 } | |
8339 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8340 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8341 ScreenLines2 + LineOffset[old_row], | |
8342 (size_t)len * sizeof(schar_T)); | |
8343 #endif | |
8344 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8345 ScreenAttrs + LineOffset[old_row], | |
8346 (size_t)len * sizeof(sattr_T)); | |
8347 } | |
8348 } | |
8349 } | |
8350 /* Use the last line of the screen for the current line. */ | |
8351 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8352 } | |
8353 | |
356 | 8354 free_screenlines(); |
8355 | |
7 | 8356 ScreenLines = new_ScreenLines; |
8357 #ifdef FEAT_MBYTE | |
8358 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8359 for (i = 0; i < p_mco; ++i) |
8360 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8361 Screen_mco = p_mco; | |
7 | 8362 ScreenLines2 = new_ScreenLines2; |
8363 #endif | |
8364 ScreenAttrs = new_ScreenAttrs; | |
8365 LineOffset = new_LineOffset; | |
8366 LineWraps = new_LineWraps; | |
671 | 8367 #ifdef FEAT_WINDOWS |
8368 TabPageIdxs = new_TabPageIdxs; | |
8369 #endif | |
7 | 8370 |
8371 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8372 * size of ScreenLines[]. Set them before calling anything. */ | |
8373 #ifdef FEAT_GUI | |
8374 old_Rows = screen_Rows; | |
8375 #endif | |
8376 screen_Rows = Rows; | |
8377 screen_Columns = Columns; | |
8378 | |
8379 must_redraw = CLEAR; /* need to clear the screen later */ | |
3263 | 8380 if (doclear) |
7 | 8381 screenclear2(); |
8382 | |
8383 #ifdef FEAT_GUI | |
8384 else if (gui.in_use | |
8385 && !gui.starting | |
8386 && ScreenLines != NULL | |
8387 && old_Rows != Rows) | |
8388 { | |
8389 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8390 /* | |
8391 * Adjust the position of the cursor, for when executing an external | |
8392 * command. | |
8393 */ | |
8394 if (msg_row >= Rows) /* Rows got smaller */ | |
8395 msg_row = Rows - 1; /* put cursor at last row */ | |
8396 else if (Rows > old_Rows) /* Rows got bigger */ | |
8397 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8398 if (msg_col >= Columns) /* Columns got smaller */ | |
8399 msg_col = Columns - 1; /* put cursor at last column */ | |
8400 } | |
8401 #endif | |
8402 | |
8403 entered = FALSE; | |
911 | 8404 --RedrawingDisabled; |
766 | 8405 |
8406 #ifdef FEAT_AUTOCMD | |
1824 | 8407 /* |
8408 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8409 * in case applying autocommands always changes Rows or Columns. | |
8410 */ | |
8411 if (starting == 0 && ++retry_count <= 3) | |
8412 { | |
766 | 8413 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8414 /* In rare cases, autocommands may have altered Rows or Columns, |
8415 * jump back to check if we need to allocate the screen again. */ | |
8416 goto retry; | |
8417 } | |
766 | 8418 #endif |
7 | 8419 } |
8420 | |
8421 void | |
356 | 8422 free_screenlines() |
8423 { | |
8424 #ifdef FEAT_MBYTE | |
714 | 8425 int i; |
8426 | |
356 | 8427 vim_free(ScreenLinesUC); |
714 | 8428 for (i = 0; i < Screen_mco; ++i) |
8429 vim_free(ScreenLinesC[i]); | |
356 | 8430 vim_free(ScreenLines2); |
8431 #endif | |
714 | 8432 vim_free(ScreenLines); |
356 | 8433 vim_free(ScreenAttrs); |
8434 vim_free(LineOffset); | |
8435 vim_free(LineWraps); | |
671 | 8436 #ifdef FEAT_WINDOWS |
8437 vim_free(TabPageIdxs); | |
8438 #endif | |
356 | 8439 } |
8440 | |
8441 void | |
7 | 8442 screenclear() |
8443 { | |
8444 check_for_delay(FALSE); | |
8445 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8446 screenclear2(); /* clear the screen */ | |
8447 } | |
8448 | |
8449 static void | |
8450 screenclear2() | |
8451 { | |
8452 int i; | |
8453 | |
8454 if (starting == NO_SCREEN || ScreenLines == NULL | |
8455 #ifdef FEAT_GUI | |
8456 || (gui.in_use && gui.starting) | |
8457 #endif | |
8458 ) | |
8459 return; | |
8460 | |
8461 #ifdef FEAT_GUI | |
8462 if (!gui.in_use) | |
8463 #endif | |
8464 screen_attr = -1; /* force setting the Normal colors */ | |
8465 screen_stop_highlight(); /* don't want highlighting here */ | |
8466 | |
8467 #ifdef FEAT_CLIPBOARD | |
8468 /* disable selection without redrawing it */ | |
8469 clip_scroll_selection(9999); | |
8470 #endif | |
8471 | |
8472 /* blank out ScreenLines */ | |
8473 for (i = 0; i < Rows; ++i) | |
8474 { | |
8475 lineclear(LineOffset[i], (int)Columns); | |
8476 LineWraps[i] = FALSE; | |
8477 } | |
8478 | |
8479 if (can_clear(T_CL)) | |
8480 { | |
8481 out_str(T_CL); /* clear the display */ | |
8482 clear_cmdline = FALSE; | |
644 | 8483 mode_displayed = FALSE; |
7 | 8484 } |
8485 else | |
8486 { | |
8487 /* can't clear the screen, mark all chars with invalid attributes */ | |
8488 for (i = 0; i < Rows; ++i) | |
8489 lineinvalid(LineOffset[i], (int)Columns); | |
8490 clear_cmdline = TRUE; | |
8491 } | |
8492 | |
8493 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8494 | |
8495 win_rest_invalid(firstwin); | |
8496 redraw_cmdline = TRUE; | |
670 | 8497 #ifdef FEAT_WINDOWS |
673 | 8498 redraw_tabline = TRUE; |
670 | 8499 #endif |
7 | 8500 if (must_redraw == CLEAR) /* no need to clear again */ |
8501 must_redraw = NOT_VALID; | |
8502 compute_cmdrow(); | |
8503 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8504 msg_col = 0; | |
8505 screen_start(); /* don't know where cursor is now */ | |
8506 msg_scrolled = 0; /* can't scroll back */ | |
8507 msg_didany = FALSE; | |
8508 msg_didout = FALSE; | |
8509 } | |
8510 | |
8511 /* | |
8512 * Clear one line in ScreenLines. | |
8513 */ | |
8514 static void | |
8515 lineclear(off, width) | |
8516 unsigned off; | |
8517 int width; | |
8518 { | |
8519 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8520 #ifdef FEAT_MBYTE | |
8521 if (enc_utf8) | |
8522 (void)vim_memset(ScreenLinesUC + off, 0, | |
8523 (size_t)width * sizeof(u8char_T)); | |
8524 #endif | |
8525 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8526 } | |
8527 | |
8528 /* | |
8529 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8530 * invalid value. | |
8531 */ | |
8532 static void | |
8533 lineinvalid(off, width) | |
8534 unsigned off; | |
8535 int width; | |
8536 { | |
8537 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8538 } | |
8539 | |
8540 #ifdef FEAT_VERTSPLIT | |
8541 /* | |
8542 * Copy part of a Screenline for vertically split window "wp". | |
8543 */ | |
8544 static void | |
8545 linecopy(to, from, wp) | |
8546 int to; | |
8547 int from; | |
8548 win_T *wp; | |
8549 { | |
8550 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8551 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8552 | |
8553 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8554 wp->w_width * sizeof(schar_T)); | |
8555 # ifdef FEAT_MBYTE | |
8556 if (enc_utf8) | |
8557 { | |
714 | 8558 int i; |
8559 | |
7 | 8560 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8561 wp->w_width * sizeof(u8char_T)); | |
714 | 8562 for (i = 0; i < p_mco; ++i) |
8563 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8564 wp->w_width * sizeof(u8char_T)); | |
7 | 8565 } |
8566 if (enc_dbcs == DBCS_JPNU) | |
8567 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8568 wp->w_width * sizeof(schar_T)); | |
8569 # endif | |
8570 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8571 wp->w_width * sizeof(sattr_T)); | |
8572 } | |
8573 #endif | |
8574 | |
8575 /* | |
8576 * Return TRUE if clearing with term string "p" would work. | |
8577 * It can't work when the string is empty or it won't set the right background. | |
8578 */ | |
8579 int | |
8580 can_clear(p) | |
8581 char_u *p; | |
8582 { | |
8583 return (*p != NUL && (t_colors <= 1 | |
8584 #ifdef FEAT_GUI | |
8585 || gui.in_use | |
8586 #endif | |
8587 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8588 } | |
8589 | |
8590 /* | |
8591 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8592 * something directly to the screen (shell commands) or a terminal control | |
8593 * code. | |
8594 */ | |
8595 void | |
8596 screen_start() | |
8597 { | |
8598 screen_cur_row = screen_cur_col = 9999; | |
8599 } | |
8600 | |
8601 /* | |
8602 * Move the cursor to position "row","col" in the screen. | |
8603 * This tries to find the most efficient way to move, minimizing the number of | |
8604 * characters sent to the terminal. | |
8605 */ | |
8606 void | |
8607 windgoto(row, col) | |
8608 int row; | |
8609 int col; | |
8610 { | |
205 | 8611 sattr_T *p; |
7 | 8612 int i; |
8613 int plan; | |
8614 int cost; | |
8615 int wouldbe_col; | |
8616 int noinvcurs; | |
8617 char_u *bs; | |
8618 int goto_cost; | |
8619 int attr; | |
8620 | |
1213 | 8621 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8622 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8623 | |
8624 #define PLAN_LE 1 | |
8625 #define PLAN_CR 2 | |
8626 #define PLAN_NL 3 | |
8627 #define PLAN_WRITE 4 | |
8628 /* Can't use ScreenLines unless initialized */ | |
8629 if (ScreenLines == NULL) | |
8630 return; | |
8631 | |
8632 if (col != screen_cur_col || row != screen_cur_row) | |
8633 { | |
8634 /* Check for valid position. */ | |
8635 if (row < 0) /* window without text lines? */ | |
8636 row = 0; | |
8637 if (row >= screen_Rows) | |
8638 row = screen_Rows - 1; | |
8639 if (col >= screen_Columns) | |
8640 col = screen_Columns - 1; | |
8641 | |
8642 /* check if no cursor movement is allowed in highlight mode */ | |
8643 if (screen_attr && *T_MS == NUL) | |
8644 noinvcurs = HIGHL_COST; | |
8645 else | |
8646 noinvcurs = 0; | |
8647 goto_cost = GOTO_COST + noinvcurs; | |
8648 | |
8649 /* | |
8650 * Plan how to do the positioning: | |
8651 * 1. Use CR to move it to column 0, same row. | |
8652 * 2. Use T_LE to move it a few columns to the left. | |
8653 * 3. Use NL to move a few lines down, column 0. | |
8654 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8655 * | |
8656 * Don't do this if the cursor went beyond the last column, the cursor | |
8657 * position is unknown then (some terminals wrap, some don't ) | |
8658 * | |
1213 | 8659 * First check if the highlighting attributes allow us to write |
7 | 8660 * characters to move the cursor to the right. |
8661 */ | |
8662 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8663 { | |
8664 /* | |
8665 * If the cursor is in the same row, bigger col, we can use CR | |
8666 * or T_LE. | |
8667 */ | |
8668 bs = NULL; /* init for GCC */ | |
8669 attr = screen_attr; | |
8670 if (row == screen_cur_row && col < screen_cur_col) | |
8671 { | |
8672 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8673 if (*T_LE) | |
8674 bs = T_LE; /* "cursor left" */ | |
8675 else | |
8676 bs = T_BC; /* "backspace character (old) */ | |
8677 if (*bs) | |
8678 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8679 else | |
8680 cost = 999; | |
8681 if (col + 1 < cost) /* using CR is less characters */ | |
8682 { | |
8683 plan = PLAN_CR; | |
8684 wouldbe_col = 0; | |
8685 cost = 1; /* CR is just one character */ | |
8686 } | |
8687 else | |
8688 { | |
8689 plan = PLAN_LE; | |
8690 wouldbe_col = col; | |
8691 } | |
8692 if (noinvcurs) /* will stop highlighting */ | |
8693 { | |
8694 cost += noinvcurs; | |
8695 attr = 0; | |
8696 } | |
8697 } | |
8698 | |
8699 /* | |
8700 * If the cursor is above where we want to be, we can use CR LF. | |
8701 */ | |
8702 else if (row > screen_cur_row) | |
8703 { | |
8704 plan = PLAN_NL; | |
8705 wouldbe_col = 0; | |
8706 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8707 if (noinvcurs) /* will stop highlighting */ | |
8708 { | |
8709 cost += noinvcurs; | |
8710 attr = 0; | |
8711 } | |
8712 } | |
8713 | |
8714 /* | |
8715 * If the cursor is in the same row, smaller col, just use write. | |
8716 */ | |
8717 else | |
8718 { | |
8719 plan = PLAN_WRITE; | |
8720 wouldbe_col = screen_cur_col; | |
8721 cost = 0; | |
8722 } | |
8723 | |
8724 /* | |
8725 * Check if any characters that need to be written have the | |
8726 * correct attributes. Also avoid UTF-8 characters. | |
8727 */ | |
8728 i = col - wouldbe_col; | |
8729 if (i > 0) | |
8730 cost += i; | |
8731 if (cost < goto_cost && i > 0) | |
8732 { | |
8733 /* | |
8734 * Check if the attributes are correct without additionally | |
8735 * stopping highlighting. | |
8736 */ | |
8737 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8738 while (i && *p++ == attr) | |
8739 --i; | |
8740 if (i != 0) | |
8741 { | |
8742 /* | |
8743 * Try if it works when highlighting is stopped here. | |
8744 */ | |
8745 if (*--p == 0) | |
8746 { | |
8747 cost += noinvcurs; | |
8748 while (i && *p++ == 0) | |
8749 --i; | |
8750 } | |
8751 if (i != 0) | |
8752 cost = 999; /* different attributes, don't do it */ | |
8753 } | |
8754 #ifdef FEAT_MBYTE | |
8755 if (enc_utf8) | |
8756 { | |
8757 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8758 for (i = wouldbe_col; i < col; ++i) | |
8759 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8760 { | |
8761 cost = 999; | |
8762 break; | |
8763 } | |
8764 } | |
8765 #endif | |
8766 } | |
8767 | |
8768 /* | |
8769 * We can do it without term_windgoto()! | |
8770 */ | |
8771 if (cost < goto_cost) | |
8772 { | |
8773 if (plan == PLAN_LE) | |
8774 { | |
8775 if (noinvcurs) | |
8776 screen_stop_highlight(); | |
8777 while (screen_cur_col > col) | |
8778 { | |
8779 out_str(bs); | |
8780 --screen_cur_col; | |
8781 } | |
8782 } | |
8783 else if (plan == PLAN_CR) | |
8784 { | |
8785 if (noinvcurs) | |
8786 screen_stop_highlight(); | |
8787 out_char('\r'); | |
8788 screen_cur_col = 0; | |
8789 } | |
8790 else if (plan == PLAN_NL) | |
8791 { | |
8792 if (noinvcurs) | |
8793 screen_stop_highlight(); | |
8794 while (screen_cur_row < row) | |
8795 { | |
8796 out_char('\n'); | |
8797 ++screen_cur_row; | |
8798 } | |
8799 screen_cur_col = 0; | |
8800 } | |
8801 | |
8802 i = col - screen_cur_col; | |
8803 if (i > 0) | |
8804 { | |
8805 /* | |
8806 * Use cursor-right if it's one character only. Avoids | |
8807 * removing a line of pixels from the last bold char, when | |
8808 * using the bold trick in the GUI. | |
8809 */ | |
8810 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8811 { | |
8812 while (i-- > 0) | |
8813 out_char(*T_ND); | |
8814 } | |
8815 else | |
8816 { | |
8817 int off; | |
8818 | |
8819 off = LineOffset[row] + screen_cur_col; | |
8820 while (i-- > 0) | |
8821 { | |
8822 if (ScreenAttrs[off] != screen_attr) | |
8823 screen_stop_highlight(); | |
8824 #ifdef FEAT_MBYTE | |
8825 out_flush_check(); | |
8826 #endif | |
8827 out_char(ScreenLines[off]); | |
8828 #ifdef FEAT_MBYTE | |
8829 if (enc_dbcs == DBCS_JPNU | |
8830 && ScreenLines[off] == 0x8e) | |
8831 out_char(ScreenLines2[off]); | |
8832 #endif | |
8833 ++off; | |
8834 } | |
8835 } | |
8836 } | |
8837 } | |
8838 } | |
8839 else | |
8840 cost = 999; | |
8841 | |
8842 if (cost >= goto_cost) | |
8843 { | |
8844 if (noinvcurs) | |
8845 screen_stop_highlight(); | |
8846 if (row == screen_cur_row && (col > screen_cur_col) && | |
8847 *T_CRI != NUL) | |
8848 term_cursor_right(col - screen_cur_col); | |
8849 else | |
8850 term_windgoto(row, col); | |
8851 } | |
8852 screen_cur_row = row; | |
8853 screen_cur_col = col; | |
8854 } | |
8855 } | |
8856 | |
8857 /* | |
8858 * Set cursor to its position in the current window. | |
8859 */ | |
8860 void | |
8861 setcursor() | |
8862 { | |
8863 if (redrawing()) | |
8864 { | |
8865 validate_cursor(); | |
8866 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8867 W_WINCOL(curwin) + ( | |
8868 #ifdef FEAT_RIGHTLEFT | |
1545 | 8869 /* With 'rightleft' set and the cursor on a double-wide |
8870 * character, position it on the leftmost column. */ | |
7 | 8871 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8872 # ifdef FEAT_MBYTE | |
1545 | 8873 (has_mbyte |
8874 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8875 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8876 # endif |
8877 1)) : | |
8878 #endif | |
8879 curwin->w_wcol)); | |
8880 } | |
8881 } | |
8882 | |
8883 | |
8884 /* | |
8885 * insert 'line_count' lines at 'row' in window 'wp' | |
8886 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8887 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8888 * scrolling. | |
8889 * Returns FAIL if the lines are not inserted, OK for success. | |
8890 */ | |
8891 int | |
8892 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8893 win_T *wp; | |
8894 int row; | |
8895 int line_count; | |
8896 int invalid; | |
8897 int mayclear; | |
8898 { | |
8899 int did_delete; | |
8900 int nextrow; | |
8901 int lastrow; | |
8902 int retval; | |
8903 | |
8904 if (invalid) | |
8905 wp->w_lines_valid = 0; | |
8906 | |
8907 if (wp->w_height < 5) | |
8908 return FAIL; | |
8909 | |
8910 if (line_count > wp->w_height - row) | |
8911 line_count = wp->w_height - row; | |
8912 | |
8913 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8914 if (retval != MAYBE) | |
8915 return retval; | |
8916 | |
8917 /* | |
8918 * If there is a next window or a status line, we first try to delete the | |
8919 * lines at the bottom to avoid messing what is after the window. | |
8920 * If this fails and there are following windows, don't do anything to avoid | |
8921 * messing up those windows, better just redraw. | |
8922 */ | |
8923 did_delete = FALSE; | |
8924 #ifdef FEAT_WINDOWS | |
8925 if (wp->w_next != NULL || wp->w_status_height) | |
8926 { | |
8927 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8928 line_count, (int)Rows, FALSE, NULL) == OK) | |
8929 did_delete = TRUE; | |
8930 else if (wp->w_next) | |
8931 return FAIL; | |
8932 } | |
8933 #endif | |
8934 /* | |
8935 * if no lines deleted, blank the lines that will end up below the window | |
8936 */ | |
8937 if (!did_delete) | |
8938 { | |
8939 #ifdef FEAT_WINDOWS | |
8940 wp->w_redr_status = TRUE; | |
8941 #endif | |
8942 redraw_cmdline = TRUE; | |
8943 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8944 lastrow = nextrow + line_count; | |
8945 if (lastrow > Rows) | |
8946 lastrow = Rows; | |
8947 screen_fill(nextrow - line_count, lastrow - line_count, | |
8948 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8949 ' ', ' ', 0); | |
8950 } | |
8951 | |
8952 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8953 == FAIL) | |
8954 { | |
8955 /* deletion will have messed up other windows */ | |
8956 if (did_delete) | |
8957 { | |
8958 #ifdef FEAT_WINDOWS | |
8959 wp->w_redr_status = TRUE; | |
8960 #endif | |
8961 win_rest_invalid(W_NEXT(wp)); | |
8962 } | |
8963 return FAIL; | |
8964 } | |
8965 | |
8966 return OK; | |
8967 } | |
8968 | |
8969 /* | |
8970 * delete "line_count" window lines at "row" in window "wp" | |
8971 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8972 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8973 * scrolling | |
8974 * Return OK for success, FAIL if the lines are not deleted. | |
8975 */ | |
8976 int | |
8977 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8978 win_T *wp; | |
8979 int row; | |
8980 int line_count; | |
8981 int invalid; | |
8982 int mayclear; | |
8983 { | |
8984 int retval; | |
8985 | |
8986 if (invalid) | |
8987 wp->w_lines_valid = 0; | |
8988 | |
8989 if (line_count > wp->w_height - row) | |
8990 line_count = wp->w_height - row; | |
8991 | |
8992 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8993 if (retval != MAYBE) | |
8994 return retval; | |
8995 | |
8996 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8997 (int)Rows, FALSE, NULL) == FAIL) | |
8998 return FAIL; | |
8999 | |
9000 #ifdef FEAT_WINDOWS | |
9001 /* | |
9002 * If there are windows or status lines below, try to put them at the | |
9003 * correct place. If we can't do that, they have to be redrawn. | |
9004 */ | |
9005 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
9006 { | |
9007 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
9008 line_count, (int)Rows, NULL) == FAIL) | |
9009 { | |
9010 wp->w_redr_status = TRUE; | |
9011 win_rest_invalid(wp->w_next); | |
9012 } | |
9013 } | |
9014 /* | |
9015 * If this is the last window and there is no status line, redraw the | |
9016 * command line later. | |
9017 */ | |
9018 else | |
9019 #endif | |
9020 redraw_cmdline = TRUE; | |
9021 return OK; | |
9022 } | |
9023 | |
9024 /* | |
9025 * Common code for win_ins_lines() and win_del_lines(). | |
9026 * Returns OK or FAIL when the work has been done. | |
9027 * Returns MAYBE when not finished yet. | |
9028 */ | |
9029 static int | |
9030 win_do_lines(wp, row, line_count, mayclear, del) | |
9031 win_T *wp; | |
9032 int row; | |
9033 int line_count; | |
9034 int mayclear; | |
9035 int del; | |
9036 { | |
9037 int retval; | |
9038 | |
9039 if (!redrawing() || line_count <= 0) | |
9040 return FAIL; | |
9041 | |
9042 /* only a few lines left: redraw is faster */ | |
9043 if (mayclear && Rows - line_count < 5 | |
9044 #ifdef FEAT_VERTSPLIT | |
9045 && wp->w_width == Columns | |
9046 #endif | |
9047 ) | |
9048 { | |
9049 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
9050 return FAIL; | |
9051 } | |
9052 | |
9053 /* | |
9054 * Delete all remaining lines | |
9055 */ | |
9056 if (row + line_count >= wp->w_height) | |
9057 { | |
9058 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
9059 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
9060 ' ', ' ', 0); | |
9061 return OK; | |
9062 } | |
9063 | |
9064 /* | |
9065 * when scrolling, the message on the command line should be cleared, | |
9066 * otherwise it will stay there forever. | |
9067 */ | |
9068 clear_cmdline = TRUE; | |
9069 | |
9070 /* | |
9071 * If the terminal can set a scroll region, use that. | |
9072 * Always do this in a vertically split window. This will redraw from | |
9073 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
9074 * win_line(). | |
9075 * Don't use a scroll region when we are going to redraw the text, writing | |
9076 * a character in the lower right corner of the scroll region causes a | |
9077 * scroll-up in the DJGPP version. | |
9078 */ | |
9079 if (scroll_region | |
9080 #ifdef FEAT_VERTSPLIT | |
9081 || W_WIDTH(wp) != Columns | |
9082 #endif | |
9083 ) | |
9084 { | |
9085 #ifdef FEAT_VERTSPLIT | |
9086 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
9087 #endif | |
9088 scroll_region_set(wp, row); | |
9089 if (del) | |
9090 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
9091 wp->w_height - row, FALSE, wp); | |
9092 else | |
9093 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
9094 wp->w_height - row, wp); | |
9095 #ifdef FEAT_VERTSPLIT | |
9096 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
9097 #endif | |
9098 scroll_region_reset(); | |
9099 return retval; | |
9100 } | |
9101 | |
9102 #ifdef FEAT_WINDOWS | |
9103 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
9104 return FAIL; | |
9105 #endif | |
9106 | |
9107 return MAYBE; | |
9108 } | |
9109 | |
9110 /* | |
9111 * window 'wp' and everything after it is messed up, mark it for redraw | |
9112 */ | |
9113 static void | |
9114 win_rest_invalid(wp) | |
9115 win_T *wp; | |
9116 { | |
9117 #ifdef FEAT_WINDOWS | |
9118 while (wp != NULL) | |
9119 #else | |
9120 if (wp != NULL) | |
9121 #endif | |
9122 { | |
9123 redraw_win_later(wp, NOT_VALID); | |
9124 #ifdef FEAT_WINDOWS | |
9125 wp->w_redr_status = TRUE; | |
9126 wp = wp->w_next; | |
9127 #endif | |
9128 } | |
9129 redraw_cmdline = TRUE; | |
9130 } | |
9131 | |
9132 /* | |
9133 * The rest of the routines in this file perform screen manipulations. The | |
9134 * given operation is performed physically on the screen. The corresponding | |
9135 * change is also made to the internal screen image. In this way, the editor | |
9136 * anticipates the effect of editing changes on the appearance of the screen. | |
9137 * That way, when we call screenupdate a complete redraw isn't usually | |
9138 * necessary. Another advantage is that we can keep adding code to anticipate | |
9139 * screen changes, and in the meantime, everything still works. | |
9140 */ | |
9141 | |
9142 /* | |
9143 * types for inserting or deleting lines | |
9144 */ | |
9145 #define USE_T_CAL 1 | |
9146 #define USE_T_CDL 2 | |
9147 #define USE_T_AL 3 | |
9148 #define USE_T_CE 4 | |
9149 #define USE_T_DL 5 | |
9150 #define USE_T_SR 6 | |
9151 #define USE_NL 7 | |
9152 #define USE_T_CD 8 | |
9153 #define USE_REDRAW 9 | |
9154 | |
9155 /* | |
9156 * insert lines on the screen and update ScreenLines[] | |
9157 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9158 * When scrolling region used 'off' is the offset from the top for the region. | |
9159 * 'row' and 'end' are relative to the start of the region. | |
9160 * | |
9161 * return FAIL for failure, OK for success. | |
9162 */ | |
446 | 9163 int |
7 | 9164 screen_ins_lines(off, row, line_count, end, wp) |
9165 int off; | |
9166 int row; | |
9167 int line_count; | |
9168 int end; | |
9169 win_T *wp; /* NULL or window to use width from */ | |
9170 { | |
9171 int i; | |
9172 int j; | |
9173 unsigned temp; | |
9174 int cursor_row; | |
9175 int type; | |
9176 int result_empty; | |
9177 int can_ce = can_clear(T_CE); | |
9178 | |
9179 /* | |
9180 * FAIL if | |
9181 * - there is no valid screen | |
9182 * - the screen has to be redrawn completely | |
9183 * - the line count is less than one | |
9184 * - the line count is more than 'ttyscroll' | |
9185 */ | |
9186 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
9187 return FAIL; | |
9188 | |
9189 /* | |
9190 * There are seven ways to insert lines: | |
9191 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9192 * characters from ScreenLines[]. | |
9193 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
9194 * the insert is just empty lines | |
9195 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
9196 * present or line_count > 1. It looks better if we do all the inserts | |
9197 * at once. | |
9198 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
9199 * insert is just empty lines and T_CE is not present or line_count > | |
9200 * 1. | |
9201 * 4. Use T_AL (insert line) if it exists. | |
9202 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
9203 * just empty lines. | |
9204 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
9205 * just empty lines. | |
9206 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
9207 * the 'da' flag is not set or we have clear line capability. | |
9208 * 8. redraw the characters from ScreenLines[]. | |
9209 * | |
9210 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
9211 * the scrollbar for the window. It does have insert line, use that if it | |
9212 * exists. | |
9213 */ | |
9214 result_empty = (row + line_count >= end); | |
9215 #ifdef FEAT_VERTSPLIT | |
9216 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9217 type = USE_REDRAW; | |
9218 else | |
9219 #endif | |
9220 if (can_clear(T_CD) && result_empty) | |
9221 type = USE_T_CD; | |
9222 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
9223 type = USE_T_CAL; | |
9224 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
9225 type = USE_T_CDL; | |
9226 else if (*T_AL != NUL) | |
9227 type = USE_T_AL; | |
9228 else if (can_ce && result_empty) | |
9229 type = USE_T_CE; | |
9230 else if (*T_DL != NUL && result_empty) | |
9231 type = USE_T_DL; | |
9232 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
9233 type = USE_T_SR; | |
9234 else | |
9235 return FAIL; | |
9236 | |
9237 /* | |
9238 * For clearing the lines screen_del_lines() is used. This will also take | |
9239 * care of t_db if necessary. | |
9240 */ | |
9241 if (type == USE_T_CD || type == USE_T_CDL || | |
9242 type == USE_T_CE || type == USE_T_DL) | |
9243 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
9244 | |
9245 /* | |
9246 * If text is retained below the screen, first clear or delete as many | |
9247 * lines at the bottom of the window as are about to be inserted so that | |
9248 * the deleted lines won't later surface during a screen_del_lines. | |
9249 */ | |
9250 if (*T_DB) | |
9251 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
9252 | |
9253 #ifdef FEAT_CLIPBOARD | |
9254 /* Remove a modeless selection when inserting lines halfway the screen | |
9255 * or not the full width of the screen. */ | |
9256 if (off + row > 0 | |
9257 # ifdef FEAT_VERTSPLIT | |
9258 || (wp != NULL && wp->w_width != Columns) | |
9259 # endif | |
9260 ) | |
3674 | 9261 clip_clear_selection(&clip_star); |
7 | 9262 else |
9263 clip_scroll_selection(-line_count); | |
9264 #endif | |
9265 | |
9266 #ifdef FEAT_GUI | |
9267 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9268 * scrolling is actually carried out. */ | |
9269 gui_dont_update_cursor(); | |
9270 #endif | |
9271 | |
9272 if (*T_CCS != NUL) /* cursor relative to region */ | |
9273 cursor_row = row; | |
9274 else | |
9275 cursor_row = row + off; | |
9276 | |
9277 /* | |
9278 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
9279 * Clear the inserted lines in ScreenLines[]. | |
9280 */ | |
9281 row += off; | |
9282 end += off; | |
9283 for (i = 0; i < line_count; ++i) | |
9284 { | |
9285 #ifdef FEAT_VERTSPLIT | |
9286 if (wp != NULL && wp->w_width != Columns) | |
9287 { | |
9288 /* need to copy part of a line */ | |
9289 j = end - 1 - i; | |
9290 while ((j -= line_count) >= row) | |
9291 linecopy(j + line_count, j, wp); | |
9292 j += line_count; | |
9293 if (can_clear((char_u *)" ")) | |
9294 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9295 else | |
9296 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9297 LineWraps[j] = FALSE; | |
9298 } | |
9299 else | |
9300 #endif | |
9301 { | |
9302 j = end - 1 - i; | |
9303 temp = LineOffset[j]; | |
9304 while ((j -= line_count) >= row) | |
9305 { | |
9306 LineOffset[j + line_count] = LineOffset[j]; | |
9307 LineWraps[j + line_count] = LineWraps[j]; | |
9308 } | |
9309 LineOffset[j + line_count] = temp; | |
9310 LineWraps[j + line_count] = FALSE; | |
9311 if (can_clear((char_u *)" ")) | |
9312 lineclear(temp, (int)Columns); | |
9313 else | |
9314 lineinvalid(temp, (int)Columns); | |
9315 } | |
9316 } | |
9317 | |
9318 screen_stop_highlight(); | |
9319 windgoto(cursor_row, 0); | |
9320 | |
9321 #ifdef FEAT_VERTSPLIT | |
9322 /* redraw the characters */ | |
9323 if (type == USE_REDRAW) | |
9324 redraw_block(row, end, wp); | |
9325 else | |
9326 #endif | |
9327 if (type == USE_T_CAL) | |
9328 { | |
9329 term_append_lines(line_count); | |
9330 screen_start(); /* don't know where cursor is now */ | |
9331 } | |
9332 else | |
9333 { | |
9334 for (i = 0; i < line_count; i++) | |
9335 { | |
9336 if (type == USE_T_AL) | |
9337 { | |
9338 if (i && cursor_row != 0) | |
9339 windgoto(cursor_row, 0); | |
9340 out_str(T_AL); | |
9341 } | |
9342 else /* type == USE_T_SR */ | |
9343 out_str(T_SR); | |
9344 screen_start(); /* don't know where cursor is now */ | |
9345 } | |
9346 } | |
9347 | |
9348 /* | |
9349 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9350 * have been scrolled down into the region. | |
9351 */ | |
9352 if (type == USE_T_SR && *T_DA) | |
9353 { | |
9354 for (i = 0; i < line_count; ++i) | |
9355 { | |
9356 windgoto(off + i, 0); | |
9357 out_str(T_CE); | |
9358 screen_start(); /* don't know where cursor is now */ | |
9359 } | |
9360 } | |
9361 | |
9362 #ifdef FEAT_GUI | |
9363 gui_can_update_cursor(); | |
9364 if (gui.in_use) | |
9365 out_flush(); /* always flush after a scroll */ | |
9366 #endif | |
9367 return OK; | |
9368 } | |
9369 | |
9370 /* | |
9371 * delete lines on the screen and update ScreenLines[] | |
9372 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9373 * When scrolling region used 'off' is the offset from the top for the region. | |
9374 * 'row' and 'end' are relative to the start of the region. | |
9375 * | |
9376 * Return OK for success, FAIL if the lines are not deleted. | |
9377 */ | |
9378 int | |
9379 screen_del_lines(off, row, line_count, end, force, wp) | |
9380 int off; | |
9381 int row; | |
9382 int line_count; | |
9383 int end; | |
9384 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9385 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9386 { |
9387 int j; | |
9388 int i; | |
9389 unsigned temp; | |
9390 int cursor_row; | |
9391 int cursor_end; | |
9392 int result_empty; /* result is empty until end of region */ | |
9393 int can_delete; /* deleting line codes can be used */ | |
9394 int type; | |
9395 | |
9396 /* | |
9397 * FAIL if | |
9398 * - there is no valid screen | |
9399 * - the screen has to be redrawn completely | |
9400 * - the line count is less than one | |
9401 * - the line count is more than 'ttyscroll' | |
9402 */ | |
9403 if (!screen_valid(TRUE) || line_count <= 0 || | |
9404 (!force && line_count > p_ttyscroll)) | |
9405 return FAIL; | |
9406 | |
9407 /* | |
9408 * Check if the rest of the current region will become empty. | |
9409 */ | |
9410 result_empty = row + line_count >= end; | |
9411 | |
9412 /* | |
9413 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9414 * available. | |
9415 */ | |
9416 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9417 | |
9418 /* | |
9419 * There are six ways to delete lines: | |
9420 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9421 * characters from ScreenLines[]. | |
9422 * 1. Use T_CD if it exists and the result is empty. | |
9423 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9424 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9425 * none of the other ways work. | |
9426 * 4. Use T_CE (erase line) if the result is empty. | |
9427 * 5. Use T_DL (delete line) if it exists. | |
9428 * 6. redraw the characters from ScreenLines[]. | |
9429 */ | |
9430 #ifdef FEAT_VERTSPLIT | |
9431 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9432 type = USE_REDRAW; | |
9433 else | |
9434 #endif | |
9435 if (can_clear(T_CD) && result_empty) | |
9436 type = USE_T_CD; | |
9437 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9438 /* | |
9439 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9440 * its internal termcap... this works okay for tests which test *T_DB != | |
9441 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9442 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9443 * the trick... | |
9444 * Anyway, this hack will hopefully go away with the next OS release. | |
9445 * (Olaf Seibert) | |
9446 */ | |
9447 else if (row == 0 && T_DB == empty_option | |
9448 && (line_count == 1 || *T_CDL == NUL)) | |
9449 #else | |
9450 else if (row == 0 && ( | |
9451 #ifndef AMIGA | |
9452 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9453 * up, so use delete-line command */ | |
9454 line_count == 1 || | |
9455 #endif | |
9456 *T_CDL == NUL)) | |
9457 #endif | |
9458 type = USE_NL; | |
9459 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9460 type = USE_T_CDL; | |
9461 else if (can_clear(T_CE) && result_empty | |
9462 #ifdef FEAT_VERTSPLIT | |
9463 && (wp == NULL || wp->w_width == Columns) | |
9464 #endif | |
9465 ) | |
9466 type = USE_T_CE; | |
9467 else if (*T_DL != NUL && can_delete) | |
9468 type = USE_T_DL; | |
9469 else if (*T_CDL != NUL && can_delete) | |
9470 type = USE_T_CDL; | |
9471 else | |
9472 return FAIL; | |
9473 | |
9474 #ifdef FEAT_CLIPBOARD | |
9475 /* Remove a modeless selection when deleting lines halfway the screen or | |
9476 * not the full width of the screen. */ | |
9477 if (off + row > 0 | |
9478 # ifdef FEAT_VERTSPLIT | |
9479 || (wp != NULL && wp->w_width != Columns) | |
9480 # endif | |
9481 ) | |
3674 | 9482 clip_clear_selection(&clip_star); |
7 | 9483 else |
9484 clip_scroll_selection(line_count); | |
9485 #endif | |
9486 | |
9487 #ifdef FEAT_GUI | |
9488 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9489 * scrolling is actually carried out. */ | |
9490 gui_dont_update_cursor(); | |
9491 #endif | |
9492 | |
9493 if (*T_CCS != NUL) /* cursor relative to region */ | |
9494 { | |
9495 cursor_row = row; | |
9496 cursor_end = end; | |
9497 } | |
9498 else | |
9499 { | |
9500 cursor_row = row + off; | |
9501 cursor_end = end + off; | |
9502 } | |
9503 | |
9504 /* | |
9505 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9506 * Clear the inserted lines in ScreenLines[]. | |
9507 */ | |
9508 row += off; | |
9509 end += off; | |
9510 for (i = 0; i < line_count; ++i) | |
9511 { | |
9512 #ifdef FEAT_VERTSPLIT | |
9513 if (wp != NULL && wp->w_width != Columns) | |
9514 { | |
9515 /* need to copy part of a line */ | |
9516 j = row + i; | |
9517 while ((j += line_count) <= end - 1) | |
9518 linecopy(j - line_count, j, wp); | |
9519 j -= line_count; | |
9520 if (can_clear((char_u *)" ")) | |
9521 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9522 else | |
9523 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9524 LineWraps[j] = FALSE; | |
9525 } | |
9526 else | |
9527 #endif | |
9528 { | |
9529 /* whole width, moving the line pointers is faster */ | |
9530 j = row + i; | |
9531 temp = LineOffset[j]; | |
9532 while ((j += line_count) <= end - 1) | |
9533 { | |
9534 LineOffset[j - line_count] = LineOffset[j]; | |
9535 LineWraps[j - line_count] = LineWraps[j]; | |
9536 } | |
9537 LineOffset[j - line_count] = temp; | |
9538 LineWraps[j - line_count] = FALSE; | |
9539 if (can_clear((char_u *)" ")) | |
9540 lineclear(temp, (int)Columns); | |
9541 else | |
9542 lineinvalid(temp, (int)Columns); | |
9543 } | |
9544 } | |
9545 | |
9546 screen_stop_highlight(); | |
9547 | |
9548 #ifdef FEAT_VERTSPLIT | |
9549 /* redraw the characters */ | |
9550 if (type == USE_REDRAW) | |
9551 redraw_block(row, end, wp); | |
9552 else | |
9553 #endif | |
9554 if (type == USE_T_CD) /* delete the lines */ | |
9555 { | |
9556 windgoto(cursor_row, 0); | |
9557 out_str(T_CD); | |
9558 screen_start(); /* don't know where cursor is now */ | |
9559 } | |
9560 else if (type == USE_T_CDL) | |
9561 { | |
9562 windgoto(cursor_row, 0); | |
9563 term_delete_lines(line_count); | |
9564 screen_start(); /* don't know where cursor is now */ | |
9565 } | |
9566 /* | |
9567 * Deleting lines at top of the screen or scroll region: Just scroll | |
9568 * the whole screen (scroll region) up by outputting newlines on the | |
9569 * last line. | |
9570 */ | |
9571 else if (type == USE_NL) | |
9572 { | |
9573 windgoto(cursor_end - 1, 0); | |
9574 for (i = line_count; --i >= 0; ) | |
9575 out_char('\n'); /* cursor will remain on same line */ | |
9576 } | |
9577 else | |
9578 { | |
9579 for (i = line_count; --i >= 0; ) | |
9580 { | |
9581 if (type == USE_T_DL) | |
9582 { | |
9583 windgoto(cursor_row, 0); | |
9584 out_str(T_DL); /* delete a line */ | |
9585 } | |
9586 else /* type == USE_T_CE */ | |
9587 { | |
9588 windgoto(cursor_row + i, 0); | |
9589 out_str(T_CE); /* erase a line */ | |
9590 } | |
9591 screen_start(); /* don't know where cursor is now */ | |
9592 } | |
9593 } | |
9594 | |
9595 /* | |
9596 * If the 'db' flag is set, we need to clear the lines that have been | |
9597 * scrolled up at the bottom of the region. | |
9598 */ | |
9599 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9600 { | |
9601 for (i = line_count; i > 0; --i) | |
9602 { | |
9603 windgoto(cursor_end - i, 0); | |
9604 out_str(T_CE); /* erase a line */ | |
9605 screen_start(); /* don't know where cursor is now */ | |
9606 } | |
9607 } | |
9608 | |
9609 #ifdef FEAT_GUI | |
9610 gui_can_update_cursor(); | |
9611 if (gui.in_use) | |
9612 out_flush(); /* always flush after a scroll */ | |
9613 #endif | |
9614 | |
9615 return OK; | |
9616 } | |
9617 | |
9618 /* | |
9619 * show the current mode and ruler | |
9620 * | |
9621 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9622 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9623 * cleared only if a mode is shown. | |
9624 * Return the length of the message (0 if no message). | |
9625 */ | |
9626 int | |
9627 showmode() | |
9628 { | |
9629 int need_clear; | |
9630 int length = 0; | |
9631 int do_mode; | |
9632 int attr; | |
9633 int nwr_save; | |
9634 #ifdef FEAT_INS_EXPAND | |
9635 int sub_attr; | |
9636 #endif | |
9637 | |
642 | 9638 do_mode = ((p_smd && msg_silent == 0) |
9639 && ((State & INSERT) | |
9640 || restart_edit | |
7 | 9641 #ifdef FEAT_VISUAL |
9642 || VIsual_active | |
9643 #endif | |
9644 )); | |
9645 if (do_mode || Recording) | |
9646 { | |
9647 /* | |
9648 * Don't show mode right now, when not redrawing or inside a mapping. | |
9649 * Call char_avail() only when we are going to show something, because | |
9650 * it takes a bit of time. | |
9651 */ | |
9652 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9653 { | |
9654 redraw_cmdline = TRUE; /* show mode later */ | |
9655 return 0; | |
9656 } | |
9657 | |
9658 nwr_save = need_wait_return; | |
9659 | |
9660 /* wait a bit before overwriting an important message */ | |
9661 check_for_delay(FALSE); | |
9662 | |
9663 /* if the cmdline is more than one line high, erase top lines */ | |
9664 need_clear = clear_cmdline; | |
9665 if (clear_cmdline && cmdline_row < Rows - 1) | |
9666 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9667 | |
9668 /* Position on the last line in the window, column 0 */ | |
9669 msg_pos_mode(); | |
9670 cursor_off(); | |
9671 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9672 if (do_mode) | |
9673 { | |
9674 MSG_PUTS_ATTR("--", attr); | |
9675 #if defined(FEAT_XIM) | |
2520 | 9676 if ( |
9677 # ifdef FEAT_GUI_GTK | |
9678 preedit_get_status() | |
1668 | 9679 # else |
9680 im_get_status() | |
2520 | 9681 # endif |
1668 | 9682 ) |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9683 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9684 MSG_PUTS_ATTR(" IM", attr); |
9685 # else | |
9686 MSG_PUTS_ATTR(" XIM", attr); | |
9687 # endif | |
9688 #endif | |
9689 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9690 if (gui.in_use) | |
9691 { | |
9692 if (hangul_input_state_get()) | |
236 | 9693 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9694 } |
9695 #endif | |
9696 #ifdef FEAT_INS_EXPAND | |
9697 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9698 { | |
9699 /* These messages can get long, avoid a wrap in a narrow | |
9700 * window. Prefer showing edit_submode_extra. */ | |
9701 length = (Rows - msg_row) * Columns - 3; | |
9702 if (edit_submode_extra != NULL) | |
9703 length -= vim_strsize(edit_submode_extra); | |
9704 if (length > 0) | |
9705 { | |
9706 if (edit_submode_pre != NULL) | |
9707 length -= vim_strsize(edit_submode_pre); | |
9708 if (length - vim_strsize(edit_submode) > 0) | |
9709 { | |
9710 if (edit_submode_pre != NULL) | |
9711 msg_puts_attr(edit_submode_pre, attr); | |
9712 msg_puts_attr(edit_submode, attr); | |
9713 } | |
9714 if (edit_submode_extra != NULL) | |
9715 { | |
9716 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9717 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9718 sub_attr = hl_attr(edit_submode_highl); | |
9719 else | |
9720 sub_attr = attr; | |
9721 msg_puts_attr(edit_submode_extra, sub_attr); | |
9722 } | |
9723 } | |
9724 length = 0; | |
9725 } | |
9726 else | |
9727 #endif | |
9728 { | |
9729 #ifdef FEAT_VREPLACE | |
9730 if (State & VREPLACE_FLAG) | |
9731 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9732 else | |
9733 #endif | |
9734 if (State & REPLACE_FLAG) | |
9735 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9736 else if (State & INSERT) | |
9737 { | |
9738 #ifdef FEAT_RIGHTLEFT | |
9739 if (p_ri) | |
9740 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9741 #endif | |
9742 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9743 } | |
9744 else if (restart_edit == 'I') | |
9745 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9746 else if (restart_edit == 'R') | |
9747 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9748 else if (restart_edit == 'V') | |
9749 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9750 #ifdef FEAT_RIGHTLEFT | |
9751 if (p_hkmap) | |
9752 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9753 # ifdef FEAT_FKMAP | |
9754 if (p_fkmap) | |
9755 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9756 # endif | |
9757 #endif | |
9758 #ifdef FEAT_KEYMAP | |
9759 if (State & LANGMAP) | |
9760 { | |
9761 # ifdef FEAT_ARABIC | |
9762 if (curwin->w_p_arab) | |
9763 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9764 else | |
9765 # endif | |
9766 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9767 } | |
9768 #endif | |
9769 if ((State & INSERT) && p_paste) | |
9770 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9771 | |
9772 #ifdef FEAT_VISUAL | |
9773 if (VIsual_active) | |
9774 { | |
9775 char *p; | |
9776 | |
9777 /* Don't concatenate separate words to avoid translation | |
9778 * problems. */ | |
9779 switch ((VIsual_select ? 4 : 0) | |
9780 + (VIsual_mode == Ctrl_V) * 2 | |
9781 + (VIsual_mode == 'V')) | |
9782 { | |
9783 case 0: p = N_(" VISUAL"); break; | |
9784 case 1: p = N_(" VISUAL LINE"); break; | |
9785 case 2: p = N_(" VISUAL BLOCK"); break; | |
9786 case 4: p = N_(" SELECT"); break; | |
9787 case 5: p = N_(" SELECT LINE"); break; | |
9788 default: p = N_(" SELECT BLOCK"); break; | |
9789 } | |
9790 MSG_PUTS_ATTR(_(p), attr); | |
9791 } | |
9792 #endif | |
9793 MSG_PUTS_ATTR(" --", attr); | |
9794 } | |
644 | 9795 |
7 | 9796 need_clear = TRUE; |
9797 } | |
9798 if (Recording | |
9799 #ifdef FEAT_INS_EXPAND | |
9800 && edit_submode == NULL /* otherwise it gets too long */ | |
9801 #endif | |
9802 ) | |
9803 { | |
9804 MSG_PUTS_ATTR(_("recording"), attr); | |
9805 need_clear = TRUE; | |
9806 } | |
644 | 9807 |
9808 mode_displayed = TRUE; | |
7 | 9809 if (need_clear || clear_cmdline) |
9810 msg_clr_eos(); | |
9811 msg_didout = FALSE; /* overwrite this message */ | |
9812 length = msg_col; | |
9813 msg_col = 0; | |
9814 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9815 } | |
9816 else if (clear_cmdline && msg_silent == 0) | |
9817 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9818 msg_clr_cmdline(); | |
9819 | |
9820 #ifdef FEAT_CMDL_INFO | |
9821 # ifdef FEAT_VISUAL | |
9822 /* In Visual mode the size of the selected area must be redrawn. */ | |
9823 if (VIsual_active) | |
9824 clear_showcmd(); | |
9825 # endif | |
9826 | |
9827 /* If the last window has no status line, the ruler is after the mode | |
9828 * message and must be redrawn */ | |
9829 if (redrawing() | |
9830 # ifdef FEAT_WINDOWS | |
9831 && lastwin->w_status_height == 0 | |
9832 # endif | |
9833 ) | |
9834 win_redr_ruler(lastwin, TRUE); | |
9835 #endif | |
9836 redraw_cmdline = FALSE; | |
9837 clear_cmdline = FALSE; | |
9838 | |
9839 return length; | |
9840 } | |
9841 | |
9842 /* | |
9843 * Position for a mode message. | |
9844 */ | |
9845 static void | |
9846 msg_pos_mode() | |
9847 { | |
9848 msg_col = 0; | |
9849 msg_row = Rows - 1; | |
9850 } | |
9851 | |
9852 /* | |
9853 * Delete mode message. Used when ESC is typed which is expected to end | |
9854 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9855 * Caller should check "mode_displayed". |
7 | 9856 */ |
9857 void | |
9858 unshowmode(force) | |
9859 int force; | |
9860 { | |
9861 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9862 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9863 */ |
9864 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9865 redraw_cmdline = TRUE; /* delete mode later */ | |
9866 else | |
9867 { | |
9868 msg_pos_mode(); | |
9869 if (Recording) | |
9870 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9871 msg_clr_eos(); | |
9872 } | |
9873 } | |
9874 | |
667 | 9875 #if defined(FEAT_WINDOWS) |
9876 /* | |
9877 * Draw the tab pages line at the top of the Vim window. | |
9878 */ | |
9879 static void | |
677 | 9880 draw_tabline() |
667 | 9881 { |
9882 int tabcount = 0; | |
9883 tabpage_T *tp; | |
9884 int tabwidth; | |
9885 int col = 0; | |
673 | 9886 int scol = 0; |
667 | 9887 int attr; |
9888 win_T *wp; | |
671 | 9889 win_T *cwp; |
9890 int wincount; | |
9891 int modified; | |
667 | 9892 int c; |
9893 int len; | |
9894 int attr_sel = hl_attr(HLF_TPS); | |
9895 int attr_nosel = hl_attr(HLF_TP); | |
9896 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9897 char_u *p; |
677 | 9898 int room; |
9899 int use_sep_chars = (t_colors < 8 | |
9900 #ifdef FEAT_GUI | |
9901 && !gui.in_use | |
9902 #endif | |
9903 ); | |
673 | 9904 |
9905 redraw_tabline = FALSE; | |
667 | 9906 |
685 | 9907 #ifdef FEAT_GUI_TABLINE |
798 | 9908 /* Take care of a GUI tabline. */ |
685 | 9909 if (gui_use_tabline()) |
9910 { | |
9911 gui_update_tabline(); | |
9912 return; | |
9913 } | |
9914 #endif | |
9915 | |
9916 if (tabline_height() < 1) | |
667 | 9917 return; |
9918 | |
677 | 9919 #if defined(FEAT_STL_OPT) |
681 | 9920 |
9921 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9922 for (scol = 0; scol < Columns; ++scol) | |
9923 TabPageIdxs[scol] = 0; | |
9924 | |
677 | 9925 /* Use the 'tabline' option if it's set. */ |
9926 if (*p_tal != NUL) | |
9927 { | |
680 | 9928 int save_called_emsg = called_emsg; |
9929 | |
9930 /* Check for an error. If there is one we would loop in redrawing the | |
9931 * screen. Avoid that by making 'tabline' empty. */ | |
9932 called_emsg = FALSE; | |
677 | 9933 win_redr_custom(NULL, FALSE); |
680 | 9934 if (called_emsg) |
9935 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9936 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9937 called_emsg |= save_called_emsg; |
9938 } | |
9939 else | |
9940 #endif | |
9941 { | |
9942 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9943 ++tabcount; | |
9944 | |
9945 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9946 if (tabwidth < 6) | |
9947 tabwidth = 6; | |
9948 | |
9949 attr = attr_nosel; | |
9950 tabcount = 0; | |
681 | 9951 scol = 0; |
699 | 9952 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9953 tp = tp->tp_next) | |
680 | 9954 { |
9955 scol = col; | |
9956 | |
9957 if (tp->tp_topframe == topframe) | |
9958 attr = attr_sel; | |
9959 if (use_sep_chars && col > 0) | |
9960 screen_putchar('|', 0, col++, attr); | |
9961 | |
9962 if (tp->tp_topframe != topframe) | |
9963 attr = attr_nosel; | |
9964 | |
9965 screen_putchar(' ', 0, col++, attr); | |
9966 | |
9967 if (tp == curtab) | |
9968 { | |
9969 cwp = curwin; | |
9970 wp = firstwin; | |
9971 } | |
9972 else | |
9973 { | |
9974 cwp = tp->tp_curwin; | |
9975 wp = tp->tp_firstwin; | |
9976 } | |
9977 | |
9978 modified = FALSE; | |
9979 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9980 if (bufIsChanged(wp->w_buffer)) | |
9981 modified = TRUE; | |
9982 if (modified || wincount > 1) | |
9983 { | |
9984 if (wincount > 1) | |
9985 { | |
9986 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9987 len = (int)STRLEN(NameBuff); |
699 | 9988 if (col + len >= Columns - 3) |
9989 break; | |
680 | 9990 screen_puts_len(NameBuff, len, 0, col, |
677 | 9991 #if defined(FEAT_SYN_HL) |
680 | 9992 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9993 #else |
680 | 9994 attr |
9995 #endif | |
9996 ); | |
9997 col += len; | |
9998 } | |
9999 if (modified) | |
10000 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
10001 screen_putchar(' ', 0, col++, attr); | |
10002 } | |
10003 | |
10004 room = scol - col + tabwidth - 1; | |
10005 if (room > 0) | |
10006 { | |
685 | 10007 /* Get buffer name in NameBuff[] */ |
10008 get_trans_bufname(cwp->w_buffer); | |
819 | 10009 shorten_dir(NameBuff); |
680 | 10010 len = vim_strsize(NameBuff); |
10011 p = NameBuff; | |
677 | 10012 #ifdef FEAT_MBYTE |
680 | 10013 if (has_mbyte) |
10014 while (len > room) | |
10015 { | |
10016 len -= ptr2cells(p); | |
10017 mb_ptr_adv(p); | |
10018 } | |
10019 else | |
10020 #endif | |
10021 if (len > room) | |
677 | 10022 { |
680 | 10023 p += len - room; |
10024 len = room; | |
677 | 10025 } |
699 | 10026 if (len > Columns - col - 1) |
10027 len = Columns - col - 1; | |
680 | 10028 |
835 | 10029 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 10030 col += len; |
10031 } | |
10032 screen_putchar(' ', 0, col++, attr); | |
10033 | |
10034 /* Store the tab page number in TabPageIdxs[], so that | |
10035 * jump_to_mouse() knows where each one is. */ | |
10036 ++tabcount; | |
10037 while (scol < col) | |
10038 TabPageIdxs[scol++] = tabcount; | |
10039 } | |
10040 | |
10041 if (use_sep_chars) | |
10042 c = '_'; | |
10043 else | |
10044 c = ' '; | |
10045 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 10046 |
10047 /* Put an "X" for closing the current tab if there are several. */ | |
10048 if (first_tabpage->tp_next != NULL) | |
10049 { | |
10050 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
10051 TabPageIdxs[Columns - 1] = -999; | |
10052 } | |
10053 } | |
834 | 10054 |
10055 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
10056 * set. */ | |
10057 redraw_tabline = FALSE; | |
667 | 10058 } |
685 | 10059 |
10060 /* | |
10061 * Get buffer name for "buf" into NameBuff[]. | |
10062 * Takes care of special buffer names and translates special characters. | |
10063 */ | |
10064 void | |
10065 get_trans_bufname(buf) | |
10066 buf_T *buf; | |
10067 { | |
10068 if (buf_spname(buf) != NULL) | |
3839 | 10069 vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
685 | 10070 else |
10071 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
10072 trans_characters(NameBuff, MAXPATHL); | |
10073 } | |
667 | 10074 #endif |
10075 | |
7 | 10076 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
10077 /* | |
10078 * Get the character to use in a status line. Get its attributes in "*attr". | |
10079 */ | |
10080 static int | |
10081 fillchar_status(attr, is_curwin) | |
10082 int *attr; | |
10083 int is_curwin; | |
10084 { | |
10085 int fill; | |
10086 if (is_curwin) | |
10087 { | |
10088 *attr = hl_attr(HLF_S); | |
10089 fill = fill_stl; | |
10090 } | |
10091 else | |
10092 { | |
10093 *attr = hl_attr(HLF_SNC); | |
10094 fill = fill_stlnc; | |
10095 } | |
10096 /* Use fill when there is highlighting, and highlighting of current | |
10097 * window differs, or the fillchars differ, or this is not the | |
10098 * current window */ | |
10099 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
10100 || !is_curwin || firstwin == lastwin) | |
10101 || (fill_stl != fill_stlnc))) | |
10102 return fill; | |
10103 if (is_curwin) | |
10104 return '^'; | |
10105 return '='; | |
10106 } | |
10107 #endif | |
10108 | |
10109 #ifdef FEAT_VERTSPLIT | |
10110 /* | |
10111 * Get the character to use in a separator between vertically split windows. | |
10112 * Get its attributes in "*attr". | |
10113 */ | |
10114 static int | |
10115 fillchar_vsep(attr) | |
10116 int *attr; | |
10117 { | |
10118 *attr = hl_attr(HLF_C); | |
10119 if (*attr == 0 && fill_vert == ' ') | |
10120 return '|'; | |
10121 else | |
10122 return fill_vert; | |
10123 } | |
10124 #endif | |
10125 | |
10126 /* | |
10127 * Return TRUE if redrawing should currently be done. | |
10128 */ | |
10129 int | |
10130 redrawing() | |
10131 { | |
10132 return (!RedrawingDisabled | |
10133 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
10134 } | |
10135 | |
10136 /* | |
10137 * Return TRUE if printing messages should currently be done. | |
10138 */ | |
10139 int | |
10140 messaging() | |
10141 { | |
10142 return (!(p_lz && char_avail() && !KeyTyped)); | |
10143 } | |
10144 | |
10145 /* | |
10146 * Show current status info in ruler and various other places | |
10147 * If always is FALSE, only show ruler if position has changed. | |
10148 */ | |
10149 void | |
10150 showruler(always) | |
10151 int always; | |
10152 { | |
10153 if (!always && !redrawing()) | |
10154 return; | |
574 | 10155 #ifdef FEAT_INS_EXPAND |
10156 if (pum_visible()) | |
10157 { | |
639 | 10158 # ifdef FEAT_WINDOWS |
574 | 10159 /* Don't redraw right now, do it later. */ |
10160 curwin->w_redr_status = TRUE; | |
639 | 10161 # endif |
574 | 10162 return; |
10163 } | |
10164 #endif | |
7 | 10165 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 10166 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 10167 { |
1983 | 10168 redraw_custom_statusline(curwin); |
680 | 10169 } |
7 | 10170 else |
10171 #endif | |
10172 #ifdef FEAT_CMDL_INFO | |
10173 win_redr_ruler(curwin, always); | |
10174 #endif | |
10175 | |
10176 #ifdef FEAT_TITLE | |
10177 if (need_maketitle | |
10178 # ifdef FEAT_STL_OPT | |
10179 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
10180 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
10181 # endif | |
10182 ) | |
10183 maketitle(); | |
10184 #endif | |
1588 | 10185 #ifdef FEAT_WINDOWS |
10186 /* Redraw the tab pages line if needed. */ | |
10187 if (redraw_tabline) | |
10188 draw_tabline(); | |
10189 #endif | |
7 | 10190 } |
10191 | |
10192 #ifdef FEAT_CMDL_INFO | |
10193 static void | |
10194 win_redr_ruler(wp, always) | |
10195 win_T *wp; | |
10196 int always; | |
10197 { | |
1869 | 10198 #define RULER_BUF_LEN 70 |
10199 char_u buffer[RULER_BUF_LEN]; | |
7 | 10200 int row; |
10201 int fillchar; | |
10202 int attr; | |
10203 int empty_line = FALSE; | |
10204 colnr_T virtcol; | |
10205 int i; | |
1869 | 10206 size_t len; |
7 | 10207 int o; |
10208 #ifdef FEAT_VERTSPLIT | |
10209 int this_ru_col; | |
10210 int off = 0; | |
10211 int width = Columns; | |
10212 # define WITH_OFF(x) x | |
10213 # define WITH_WIDTH(x) x | |
10214 #else | |
10215 # define WITH_OFF(x) 0 | |
10216 # define WITH_WIDTH(x) Columns | |
10217 # define this_ru_col ru_col | |
10218 #endif | |
10219 | |
10220 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
10221 if (!p_ru) | |
10222 return; | |
10223 | |
10224 /* | |
10225 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
10226 * after deleting lines, before cursor.lnum is corrected. | |
10227 */ | |
10228 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
10229 return; | |
10230 | |
10231 #ifdef FEAT_INS_EXPAND | |
10232 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
10233 * the (long) mode message. */ | |
10234 # ifdef FEAT_WINDOWS | |
10235 if (wp == lastwin && lastwin->w_status_height == 0) | |
10236 # endif | |
10237 if (edit_submode != NULL) | |
10238 return; | |
540 | 10239 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
10240 if (pum_visible()) | |
10241 return; | |
7 | 10242 #endif |
10243 | |
10244 #ifdef FEAT_STL_OPT | |
10245 if (*p_ruf) | |
10246 { | |
680 | 10247 int save_called_emsg = called_emsg; |
10248 | |
10249 called_emsg = FALSE; | |
7 | 10250 win_redr_custom(wp, TRUE); |
680 | 10251 if (called_emsg) |
10252 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 10253 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 10254 called_emsg |= save_called_emsg; |
7 | 10255 return; |
10256 } | |
10257 #endif | |
10258 | |
10259 /* | |
10260 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
10261 */ | |
10262 if (!(State & INSERT) | |
10263 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
10264 empty_line = TRUE; | |
10265 | |
10266 /* | |
10267 * Only draw the ruler when something changed. | |
10268 */ | |
10269 validate_virtcol_win(wp); | |
10270 if ( redraw_cmdline | |
10271 || always | |
10272 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
10273 || wp->w_cursor.col != wp->w_ru_cursor.col | |
10274 || wp->w_virtcol != wp->w_ru_virtcol | |
10275 #ifdef FEAT_VIRTUALEDIT | |
10276 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
10277 #endif | |
10278 || wp->w_topline != wp->w_ru_topline | |
10279 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
10280 #ifdef FEAT_DIFF | |
10281 || wp->w_topfill != wp->w_ru_topfill | |
10282 #endif | |
10283 || empty_line != wp->w_ru_empty) | |
10284 { | |
10285 cursor_off(); | |
10286 #ifdef FEAT_WINDOWS | |
10287 if (wp->w_status_height) | |
10288 { | |
10289 row = W_WINROW(wp) + wp->w_height; | |
10290 fillchar = fillchar_status(&attr, wp == curwin); | |
10291 # ifdef FEAT_VERTSPLIT | |
10292 off = W_WINCOL(wp); | |
10293 width = W_WIDTH(wp); | |
10294 # endif | |
10295 } | |
10296 else | |
10297 #endif | |
10298 { | |
10299 row = Rows - 1; | |
10300 fillchar = ' '; | |
10301 attr = 0; | |
10302 #ifdef FEAT_VERTSPLIT | |
10303 width = Columns; | |
10304 off = 0; | |
10305 #endif | |
10306 } | |
10307 | |
10308 /* In list mode virtcol needs to be recomputed */ | |
10309 virtcol = wp->w_virtcol; | |
10310 if (wp->w_p_list && lcs_tab1 == NUL) | |
10311 { | |
10312 wp->w_p_list = FALSE; | |
10313 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10314 wp->w_p_list = TRUE; | |
10315 } | |
10316 | |
10317 /* | |
10318 * Some sprintfs return the length, some return a pointer. | |
10319 * To avoid portability problems we use strlen() here. | |
10320 */ | |
1869 | 10321 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10322 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10323 ? 0L | |
10324 : (long)(wp->w_cursor.lnum)); | |
1869 | 10325 len = STRLEN(buffer); |
10326 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10327 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10328 (int)virtcol + 1); | |
10329 | |
10330 /* | |
10331 * Add a "50%" if there is room for it. | |
10332 * On the last line, don't print in the last column (scrolls the | |
10333 * screen up on some terminals). | |
10334 */ | |
10335 i = (int)STRLEN(buffer); | |
1869 | 10336 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10337 o = i + vim_strsize(buffer + i + 1); |
10338 #ifdef FEAT_WINDOWS | |
10339 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10340 #endif | |
10341 ++o; | |
10342 #ifdef FEAT_VERTSPLIT | |
10343 this_ru_col = ru_col - (Columns - width); | |
10344 if (this_ru_col < 0) | |
10345 this_ru_col = 0; | |
10346 #endif | |
10347 /* Never use more than half the window/screen width, leave the other | |
10348 * half for the filename. */ | |
10349 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10350 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10351 if (this_ru_col + o < WITH_WIDTH(width)) | |
10352 { | |
10353 while (this_ru_col + o < WITH_WIDTH(width)) | |
10354 { | |
10355 #ifdef FEAT_MBYTE | |
10356 if (has_mbyte) | |
10357 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10358 else | |
10359 #endif | |
10360 buffer[i++] = fillchar; | |
10361 ++o; | |
10362 } | |
1869 | 10363 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10364 } |
10365 /* Truncate at window boundary. */ | |
10366 #ifdef FEAT_MBYTE | |
10367 if (has_mbyte) | |
10368 { | |
10369 o = 0; | |
474 | 10370 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10371 { |
10372 o += (*mb_ptr2cells)(buffer + i); | |
10373 if (this_ru_col + o > WITH_WIDTH(width)) | |
10374 { | |
10375 buffer[i] = NUL; | |
10376 break; | |
10377 } | |
10378 } | |
10379 } | |
10380 else | |
10381 #endif | |
10382 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10383 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10384 | |
10385 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10386 i = redraw_cmdline; | |
10387 screen_fill(row, row + 1, | |
10388 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10389 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10390 fillchar, fillchar, attr); | |
10391 /* don't redraw the cmdline because of showing the ruler */ | |
10392 redraw_cmdline = i; | |
10393 wp->w_ru_cursor = wp->w_cursor; | |
10394 wp->w_ru_virtcol = wp->w_virtcol; | |
10395 wp->w_ru_empty = empty_line; | |
10396 wp->w_ru_topline = wp->w_topline; | |
10397 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10398 #ifdef FEAT_DIFF | |
10399 wp->w_ru_topfill = wp->w_topfill; | |
10400 #endif | |
10401 } | |
10402 } | |
10403 #endif | |
13 | 10404 |
10405 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10406 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10407 * Return the width of the 'number' and 'relativenumber' column. |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10408 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10409 * Otherwise it depends on 'numberwidth' and the line count. |
10410 */ | |
10411 int | |
10412 number_width(wp) | |
10413 win_T *wp; | |
10414 { | |
10415 int n; | |
10416 linenr_T lnum; | |
10417 | |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10418 if (wp->w_p_rnu && !wp->w_p_nu) |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10419 /* cursor line shows "0" */ |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10420 lnum = wp->w_height; |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10421 else |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10422 /* cursor line shows absolute line number */ |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10423 lnum = wp->w_buffer->b_ml.ml_line_count; |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10424 |
13 | 10425 if (lnum == wp->w_nrwidth_line_count) |
10426 return wp->w_nrwidth_width; | |
10427 wp->w_nrwidth_line_count = lnum; | |
10428 | |
10429 n = 0; | |
10430 do | |
10431 { | |
856 | 10432 lnum /= 10; |
10433 ++n; | |
13 | 10434 } while (lnum > 0); |
10435 | |
10436 /* 'numberwidth' gives the minimal width plus one */ | |
10437 if (n < wp->w_p_nuw - 1) | |
10438 n = wp->w_p_nuw - 1; | |
10439 | |
10440 wp->w_nrwidth_width = n; | |
10441 return n; | |
10442 } | |
10443 #endif | |
3986 | 10444 |
10445 /* | |
10446 * Return the current cursor column. This is the actual position on the | |
10447 * screen. First column is 0. | |
10448 */ | |
10449 int | |
10450 screen_screencol() | |
10451 { | |
10452 return screen_cur_col; | |
10453 } | |
10454 | |
10455 /* | |
10456 * Return the current cursor row. This is the actual position on the screen. | |
10457 * First row is 0. | |
10458 */ | |
10459 int | |
10460 screen_screenrow() | |
10461 { | |
10462 return screen_cur_row; | |
10463 } |