Mercurial > vim
annotate src/screen.c @ 4795:8360a59aa04b v7.3.1144
updated for version 7.3.1144
Problem: "RO" is not translated everywhere.
Solution: Put inside _(). (Sergey Alyoshin)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 07 Jun 2013 20:17:11 +0200 |
parents | 3f2319a953b3 |
children | 66803af09906 |
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 /* | |
271 * Changed something in the current window, at buffer line "lnum", that | |
272 * requires that line and possibly other lines to be redrawn. | |
273 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
274 * Used to remove the "$" from a change command. | |
275 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
276 * may become invalid and the whole window will have to be redrawn. | |
277 */ | |
278 void | |
279 redrawWinline(lnum, invalid) | |
280 linenr_T lnum; | |
1883 | 281 int invalid UNUSED; /* window line height is invalid now */ |
7 | 282 { |
283 #ifdef FEAT_FOLDING | |
284 int i; | |
285 #endif | |
286 | |
287 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
288 curwin->w_redraw_top = lnum; | |
289 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
290 curwin->w_redraw_bot = lnum; | |
291 redraw_later(VALID); | |
292 | |
293 #ifdef FEAT_FOLDING | |
294 if (invalid) | |
295 { | |
296 /* A w_lines[] entry for this lnum has become invalid. */ | |
297 i = find_wl_entry(curwin, lnum); | |
298 if (i >= 0) | |
299 curwin->w_lines[i].wl_valid = FALSE; | |
300 } | |
301 #endif | |
302 } | |
303 | |
2255 | 304 #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
|
305 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 306 /* |
307 * update all windows that are editing the current buffer | |
308 */ | |
309 void | |
310 update_curbuf(type) | |
311 int type; | |
312 { | |
313 redraw_curbuf_later(type); | |
314 update_screen(type); | |
315 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
316 #endif |
7 | 317 |
318 /* | |
319 * update_screen() | |
320 * | |
321 * Based on the current value of curwin->w_topline, transfer a screenfull | |
322 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
323 */ | |
324 void | |
325 update_screen(type) | |
326 int type; | |
327 { | |
328 win_T *wp; | |
329 static int did_intro = FALSE; | |
330 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
331 int did_one; | |
332 #endif | |
333 | |
2008 | 334 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 335 if (!screen_valid(TRUE)) |
336 return; | |
337 | |
338 if (must_redraw) | |
339 { | |
340 if (type < must_redraw) /* use maximal type */ | |
341 type = must_redraw; | |
1331 | 342 |
343 /* must_redraw is reset here, so that when we run into some weird | |
344 * reason to redraw while busy redrawing (e.g., asynchronous | |
345 * scrolling), or update_topline() in win_update() will cause a | |
346 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 347 must_redraw = 0; |
348 } | |
349 | |
350 /* Need to update w_lines[]. */ | |
351 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
352 type = NOT_VALID; | |
353 | |
2008 | 354 /* Postpone the redrawing when it's not needed and when being called |
355 * recursively. */ | |
356 if (!redrawing() || updating_screen) | |
7 | 357 { |
358 redraw_later(type); /* remember type for next time */ | |
359 must_redraw = type; | |
360 if (type > INVERTED_ALL) | |
361 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
362 return; | |
363 } | |
364 | |
365 updating_screen = TRUE; | |
366 #ifdef FEAT_SYN_HL | |
367 ++display_tick; /* let syntax code know we're in a next round of | |
368 * display updating */ | |
369 #endif | |
370 | |
371 /* | |
372 * if the screen was scrolled up when displaying a message, scroll it down | |
373 */ | |
374 if (msg_scrolled) | |
375 { | |
376 clear_cmdline = TRUE; | |
377 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
378 type = CLEAR; | |
379 else if (type != CLEAR) | |
380 { | |
381 check_for_delay(FALSE); | |
382 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
383 type = CLEAR; | |
384 FOR_ALL_WINDOWS(wp) | |
385 { | |
386 if (W_WINROW(wp) < msg_scrolled) | |
387 { | |
388 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
389 && wp->w_redr_type < REDRAW_TOP | |
390 && wp->w_lines_valid > 0 | |
391 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
392 { | |
393 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
394 wp->w_redr_type = REDRAW_TOP; | |
395 } | |
396 else | |
397 { | |
398 wp->w_redr_type = NOT_VALID; | |
399 #ifdef FEAT_WINDOWS | |
400 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
401 <= msg_scrolled) | |
402 wp->w_redr_status = TRUE; | |
403 #endif | |
404 } | |
405 } | |
406 } | |
407 redraw_cmdline = TRUE; | |
667 | 408 #ifdef FEAT_WINDOWS |
673 | 409 redraw_tabline = TRUE; |
667 | 410 #endif |
7 | 411 } |
412 msg_scrolled = 0; | |
413 need_wait_return = FALSE; | |
414 } | |
415 | |
416 /* reset cmdline_row now (may have been changed temporarily) */ | |
417 compute_cmdrow(); | |
418 | |
419 /* Check for changed highlighting */ | |
420 if (need_highlight_changed) | |
421 highlight_changed(); | |
422 | |
423 if (type == CLEAR) /* first clear screen */ | |
424 { | |
425 screenclear(); /* will reset clear_cmdline */ | |
426 type = NOT_VALID; | |
427 } | |
428 | |
429 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
430 check_for_delay(FALSE); | |
431 | |
13 | 432 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
433 /* 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
|
434 * changes. */ |
13 | 435 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
436 && 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
|
437 ? number_width(curwin) : 0)) |
13 | 438 curwin->w_redr_type = NOT_VALID; |
439 #endif | |
440 | |
7 | 441 /* |
442 * Only start redrawing if there is really something to do. | |
443 */ | |
444 if (type == INVERTED) | |
445 update_curswant(); | |
446 if (curwin->w_redr_type < type | |
447 && !((type == VALID | |
448 && curwin->w_lines[0].wl_valid | |
449 #ifdef FEAT_DIFF | |
450 && curwin->w_topfill == curwin->w_old_topfill | |
451 && curwin->w_botfill == curwin->w_old_botfill | |
452 #endif | |
453 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
454 #ifdef FEAT_VISUAL | |
455 || (type == INVERTED | |
1043 | 456 && VIsual_active |
7 | 457 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
458 && curwin->w_old_visual_mode == VIsual_mode | |
459 && (curwin->w_valid & VALID_VIRTCOL) | |
460 && curwin->w_old_curswant == curwin->w_curswant) | |
461 #endif | |
462 )) | |
463 curwin->w_redr_type = type; | |
464 | |
849 | 465 #ifdef FEAT_WINDOWS |
466 /* Redraw the tab pages line if needed. */ | |
467 if (redraw_tabline || type >= NOT_VALID) | |
468 draw_tabline(); | |
469 #endif | |
470 | |
7 | 471 #ifdef FEAT_SYN_HL |
472 /* | |
473 * Correct stored syntax highlighting info for changes in each displayed | |
474 * buffer. Each buffer must only be done once. | |
475 */ | |
476 FOR_ALL_WINDOWS(wp) | |
477 { | |
478 if (wp->w_buffer->b_mod_set) | |
479 { | |
480 # ifdef FEAT_WINDOWS | |
481 win_T *wwp; | |
482 | |
483 /* Check if we already did this buffer. */ | |
484 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
485 if (wwp->w_buffer == wp->w_buffer) | |
486 break; | |
487 # endif | |
488 if ( | |
489 # ifdef FEAT_WINDOWS | |
490 wwp == wp && | |
491 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
492 syntax_present(wp)) |
7 | 493 syn_stack_apply_changes(wp->w_buffer); |
494 } | |
495 } | |
496 #endif | |
497 | |
498 /* | |
499 * Go from top to bottom through the windows, redrawing the ones that need | |
500 * it. | |
501 */ | |
502 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
503 did_one = FALSE; | |
504 #endif | |
505 #ifdef FEAT_SEARCH_EXTRA | |
506 search_hl.rm.regprog = NULL; | |
507 #endif | |
508 FOR_ALL_WINDOWS(wp) | |
509 { | |
510 if (wp->w_redr_type != 0) | |
511 { | |
512 cursor_off(); | |
513 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
514 if (!did_one) | |
515 { | |
516 did_one = TRUE; | |
517 # ifdef FEAT_SEARCH_EXTRA | |
518 start_search_hl(); | |
519 # endif | |
520 # ifdef FEAT_CLIPBOARD | |
521 /* When Visual area changed, may have to update selection. */ | |
3674 | 522 if (clip_star.available && clip_isautosel_star()) |
523 clip_update_selection(&clip_star); | |
524 if (clip_plus.available && clip_isautosel_plus()) | |
525 clip_update_selection(&clip_plus); | |
7 | 526 # endif |
527 #ifdef FEAT_GUI | |
528 /* Remove the cursor before starting to do anything, because | |
529 * scrolling may make it difficult to redraw the text under | |
530 * it. */ | |
531 if (gui.in_use) | |
532 gui_undraw_cursor(); | |
533 #endif | |
534 } | |
535 #endif | |
536 win_update(wp); | |
537 } | |
538 | |
539 #ifdef FEAT_WINDOWS | |
540 /* redraw status line after the window to minimize cursor movement */ | |
541 if (wp->w_redr_status) | |
542 { | |
543 cursor_off(); | |
544 win_redr_status(wp); | |
545 } | |
546 #endif | |
547 } | |
548 #if defined(FEAT_SEARCH_EXTRA) | |
549 end_search_hl(); | |
550 #endif | |
4107 | 551 #ifdef FEAT_INS_EXPAND |
552 /* May need to redraw the popup menu. */ | |
553 if (pum_visible()) | |
554 pum_redraw(); | |
555 #endif | |
7 | 556 |
557 #ifdef FEAT_WINDOWS | |
558 /* Reset b_mod_set flags. Going through all windows is probably faster | |
559 * than going through all buffers (there could be many buffers). */ | |
560 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
561 wp->w_buffer->b_mod_set = FALSE; | |
562 #else | |
563 curbuf->b_mod_set = FALSE; | |
564 #endif | |
565 | |
566 updating_screen = FALSE; | |
567 #ifdef FEAT_GUI | |
568 gui_may_resize_shell(); | |
569 #endif | |
570 | |
571 /* Clear or redraw the command line. Done last, because scrolling may | |
572 * mess up the command line. */ | |
573 if (clear_cmdline || redraw_cmdline) | |
574 showmode(); | |
575 | |
576 /* May put up an introductory message when not editing a file */ | |
577 if (!did_intro && bufempty() | |
578 && curbuf->b_fname == NULL | |
579 #ifdef FEAT_WINDOWS | |
580 && firstwin->w_next == NULL | |
581 #endif | |
582 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
583 intro_message(FALSE); | |
584 did_intro = TRUE; | |
585 | |
586 #ifdef FEAT_GUI | |
587 /* Redraw the cursor and update the scrollbars when all screen updating is | |
588 * done. */ | |
589 if (gui.in_use) | |
590 { | |
591 out_flush(); /* required before updating the cursor */ | |
592 if (did_one) | |
593 gui_update_cursor(FALSE, FALSE); | |
594 gui_update_scrollbars(FALSE); | |
595 } | |
596 #endif | |
597 } | |
598 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
599 #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
|
600 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
601 * 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
|
602 * 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
|
603 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
604 int |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
605 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
|
606 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
|
607 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
608 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
|
609 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 c = 'n'; |
2382
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
618 else if (State & CMDLINE) |
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
619 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
|
620 else |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
621 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
|
622 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
|
623 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
624 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
625 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
626 * 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
|
627 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
628 void |
2428
33148c37f3c9
Changes for VMS. Mostly by Zoltan Arpadffy.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
629 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
|
630 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
631 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
|
632 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
633 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
|
634 /* 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
|
635 * 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
|
636 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
|
637 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
638 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
639 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
640 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
641 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
642 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
643 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
644 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
645 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
646 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
647 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
648 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
|
649 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
650 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
651 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
652 /* 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
|
653 * 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
|
654 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
655 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
656 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
657 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
658 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
|
659 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
660 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
|
661 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
662 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
|
663 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
664 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
665 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
666 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
667 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
668 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
|
669 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
670 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
671 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
672 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
673 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
674 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
675 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
676 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
677 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
678 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
679 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
680 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
681 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
682 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
683 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
684 } |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
685 need_cursor_line_redraw = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
686 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
687 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
688 |
7 | 689 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
690 static void update_prepare __ARGS((void)); | |
691 static void update_finish __ARGS((void)); | |
692 | |
693 /* | |
694 * Prepare for updating one or more windows. | |
2008 | 695 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 696 */ |
697 static void | |
698 update_prepare() | |
699 { | |
700 cursor_off(); | |
701 updating_screen = TRUE; | |
702 #ifdef FEAT_GUI | |
703 /* Remove the cursor before starting to do anything, because scrolling may | |
704 * make it difficult to redraw the text under it. */ | |
705 if (gui.in_use) | |
706 gui_undraw_cursor(); | |
707 #endif | |
708 #ifdef FEAT_SEARCH_EXTRA | |
709 start_search_hl(); | |
710 #endif | |
711 } | |
712 | |
713 /* | |
714 * Finish updating one or more windows. | |
715 */ | |
716 static void | |
717 update_finish() | |
718 { | |
719 if (redraw_cmdline) | |
720 showmode(); | |
721 | |
722 # ifdef FEAT_SEARCH_EXTRA | |
723 end_search_hl(); | |
724 # endif | |
725 | |
726 updating_screen = FALSE; | |
727 | |
728 # ifdef FEAT_GUI | |
729 gui_may_resize_shell(); | |
730 | |
731 /* Redraw the cursor and update the scrollbars when all screen updating is | |
732 * done. */ | |
733 if (gui.in_use) | |
734 { | |
735 out_flush(); /* required before updating the cursor */ | |
736 gui_update_cursor(FALSE, FALSE); | |
737 gui_update_scrollbars(FALSE); | |
738 } | |
739 # endif | |
740 } | |
741 #endif | |
742 | |
743 #if defined(FEAT_SIGNS) || defined(PROTO) | |
744 void | |
745 update_debug_sign(buf, lnum) | |
746 buf_T *buf; | |
747 linenr_T lnum; | |
748 { | |
749 win_T *wp; | |
750 int doit = FALSE; | |
751 | |
752 # ifdef FEAT_FOLDING | |
753 win_foldinfo.fi_level = 0; | |
754 # endif | |
755 | |
756 /* update/delete a specific mark */ | |
757 FOR_ALL_WINDOWS(wp) | |
758 { | |
759 if (buf != NULL && lnum > 0) | |
760 { | |
761 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
762 && lnum < wp->w_botline) | |
763 { | |
764 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
765 wp->w_redraw_top = lnum; | |
766 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
767 wp->w_redraw_bot = lnum; | |
768 redraw_win_later(wp, VALID); | |
769 } | |
770 } | |
771 else | |
772 redraw_win_later(wp, VALID); | |
773 if (wp->w_redr_type != 0) | |
774 doit = TRUE; | |
775 } | |
776 | |
3250 | 777 /* Return when there is nothing to do, screen updating is already |
778 * happening (recursive call) or still starting up. */ | |
779 if (!doit || updating_screen | |
780 #ifdef FEAT_GUI | |
781 || gui.starting | |
782 #endif | |
783 || starting) | |
7 | 784 return; |
785 | |
786 /* update all windows that need updating */ | |
787 update_prepare(); | |
788 | |
789 # ifdef FEAT_WINDOWS | |
790 for (wp = firstwin; wp; wp = wp->w_next) | |
791 { | |
792 if (wp->w_redr_type != 0) | |
793 win_update(wp); | |
794 if (wp->w_redr_status) | |
795 win_redr_status(wp); | |
796 } | |
797 # else | |
798 if (curwin->w_redr_type != 0) | |
799 win_update(curwin); | |
800 # endif | |
801 | |
802 update_finish(); | |
803 } | |
804 #endif | |
805 | |
806 | |
807 #if defined(FEAT_GUI) || defined(PROTO) | |
808 /* | |
809 * Update a single window, its status line and maybe the command line msg. | |
810 * Used for the GUI scrollbar. | |
811 */ | |
812 void | |
813 updateWindow(wp) | |
814 win_T *wp; | |
815 { | |
2008 | 816 /* return if already busy updating */ |
817 if (updating_screen) | |
818 return; | |
819 | |
7 | 820 update_prepare(); |
821 | |
822 #ifdef FEAT_CLIPBOARD | |
823 /* When Visual area changed, may have to update selection. */ | |
3674 | 824 if (clip_star.available && clip_isautosel_star()) |
825 clip_update_selection(&clip_star); | |
826 if (clip_plus.available && clip_isautosel_plus()) | |
827 clip_update_selection(&clip_plus); | |
7 | 828 #endif |
670 | 829 |
7 | 830 win_update(wp); |
670 | 831 |
7 | 832 #ifdef FEAT_WINDOWS |
670 | 833 /* When the screen was cleared redraw the tab pages line. */ |
673 | 834 if (redraw_tabline) |
677 | 835 draw_tabline(); |
670 | 836 |
7 | 837 if (wp->w_redr_status |
838 # ifdef FEAT_CMDL_INFO | |
839 || p_ru | |
840 # endif | |
841 # ifdef FEAT_STL_OPT | |
40 | 842 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 843 # endif |
844 ) | |
845 win_redr_status(wp); | |
846 #endif | |
847 | |
848 update_finish(); | |
849 } | |
850 #endif | |
851 | |
852 /* | |
853 * Update a single window. | |
854 * | |
855 * This may cause the windows below it also to be redrawn (when clearing the | |
856 * screen or scrolling lines). | |
857 * | |
858 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
859 * implies the one below it. | |
860 * NOT_VALID redraw the whole window | |
743 | 861 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 862 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
863 * INVERTED redraw the changed part of the Visual area | |
864 * INVERTED_ALL redraw the whole Visual area | |
865 * VALID 1. scroll up/down to adjust for a changed w_topline | |
866 * 2. update lines at the top when scrolled down | |
867 * 3. redraw changed text: | |
301 | 868 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 869 * b_mod_top and b_mod_bot. |
870 * - if wp->w_redraw_top non-zero, redraw lines between | |
871 * wp->w_redraw_top and wp->w_redr_bot. | |
872 * - continue redrawing when syntax status is invalid. | |
873 * 4. if scrolled up, update lines at the bottom. | |
874 * This results in three areas that may need updating: | |
875 * top: from first row to top_end (when scrolled down) | |
876 * mid: from mid_start to mid_end (update inversion or changed text) | |
877 * bot: from bot_start to last row (when scrolled up) | |
878 */ | |
879 static void | |
880 win_update(wp) | |
881 win_T *wp; | |
882 { | |
883 buf_T *buf = wp->w_buffer; | |
884 int type; | |
885 int top_end = 0; /* Below last row of the top area that needs | |
886 updating. 0 when no top area updating. */ | |
887 int mid_start = 999;/* first row of the mid area that needs | |
888 updating. 999 when no mid area updating. */ | |
889 int mid_end = 0; /* Below last row of the mid area that needs | |
890 updating. 0 when no mid area updating. */ | |
891 int bot_start = 999;/* first row of the bot area that needs | |
892 updating. 999 when no bot area updating */ | |
893 #ifdef FEAT_VISUAL | |
894 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
895 w_topline got smaller a bit */ | |
896 #endif | |
897 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 898 matchitem_T *cur; /* points to the match list */ |
7 | 899 int top_to_mod = FALSE; /* redraw above mod_top */ |
900 #endif | |
901 | |
902 int row; /* current window row to display */ | |
903 linenr_T lnum; /* current buffer lnum to display */ | |
904 int idx; /* current index in w_lines[] */ | |
905 int srow; /* starting row of the current line */ | |
906 | |
907 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
908 int didline = FALSE; /* if TRUE, we finished the last line */ | |
909 int i; | |
910 long j; | |
911 static int recursive = FALSE; /* being called recursively */ | |
912 int old_botline = wp->w_botline; | |
913 #ifdef FEAT_FOLDING | |
914 long fold_count; | |
915 #endif | |
916 #ifdef FEAT_SYN_HL | |
917 /* remember what happened to the previous line, to know if | |
918 * check_visual_highlight() can be used */ | |
919 #define DID_NONE 1 /* didn't update a line */ | |
920 #define DID_LINE 2 /* updated a normal line */ | |
921 #define DID_FOLD 3 /* updated a folded line */ | |
922 int did_update = DID_NONE; | |
923 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
924 #endif | |
925 linenr_T mod_top = 0; | |
926 linenr_T mod_bot = 0; | |
927 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
928 int save_got_int; | |
929 #endif | |
930 | |
931 type = wp->w_redr_type; | |
932 | |
933 if (type == NOT_VALID) | |
934 { | |
935 #ifdef FEAT_WINDOWS | |
936 wp->w_redr_status = TRUE; | |
937 #endif | |
938 wp->w_lines_valid = 0; | |
939 } | |
940 | |
941 /* Window is zero-height: nothing to draw. */ | |
942 if (wp->w_height == 0) | |
943 { | |
944 wp->w_redr_type = 0; | |
945 return; | |
946 } | |
947 | |
948 #ifdef FEAT_VERTSPLIT | |
949 /* Window is zero-width: Only need to draw the separator. */ | |
950 if (wp->w_width == 0) | |
951 { | |
952 /* draw the vertical separator right of this window */ | |
953 draw_vsep_win(wp, 0); | |
954 wp->w_redr_type = 0; | |
955 return; | |
956 } | |
957 #endif | |
958 | |
959 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
960 init_search_hl(wp); |
7 | 961 #endif |
962 | |
13 | 963 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
964 /* 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
|
965 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
966 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 967 if (wp->w_nrwidth != i) |
13 | 968 { |
969 type = NOT_VALID; | |
677 | 970 wp->w_nrwidth = i; |
13 | 971 } |
972 else | |
973 #endif | |
974 | |
7 | 975 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
976 { | |
977 /* | |
978 * When there are both inserted/deleted lines and specific lines to be | |
979 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
980 * everything (only happens when redrawing is off for while). | |
981 */ | |
982 type = NOT_VALID; | |
983 } | |
984 else | |
985 { | |
986 /* | |
987 * Set mod_top to the first line that needs displaying because of | |
988 * changes. Set mod_bot to the first line after the changes. | |
989 */ | |
990 mod_top = wp->w_redraw_top; | |
991 if (wp->w_redraw_bot != 0) | |
992 mod_bot = wp->w_redraw_bot + 1; | |
993 else | |
994 mod_bot = 0; | |
995 wp->w_redraw_top = 0; /* reset for next time */ | |
996 wp->w_redraw_bot = 0; | |
997 if (buf->b_mod_set) | |
998 { | |
999 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
1000 { | |
1001 mod_top = buf->b_mod_top; | |
1002 #ifdef FEAT_SYN_HL | |
1003 /* Need to redraw lines above the change that may be included | |
1004 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1005 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1006 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1007 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 1008 if (mod_top < 1) |
1009 mod_top = 1; | |
1010 } | |
1011 #endif | |
1012 } | |
1013 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
1014 mod_bot = buf->b_mod_bot; | |
1015 | |
1016 #ifdef FEAT_SEARCH_EXTRA | |
1017 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
1018 * change in one line may make the Search highlighting in a | |
1019 * previous line invalid. Simple solution: redraw all visible | |
1020 * lines above the change. | |
1326 | 1021 * Same for a match pattern. |
7 | 1022 */ |
699 | 1023 if (search_hl.rm.regprog != NULL |
1024 && re_multiline(search_hl.rm.regprog)) | |
7 | 1025 top_to_mod = TRUE; |
699 | 1026 else |
1326 | 1027 { |
1028 cur = wp->w_match_head; | |
1029 while (cur != NULL) | |
1030 { | |
1031 if (cur->match.regprog != NULL | |
1032 && re_multiline(cur->match.regprog)) | |
699 | 1033 { |
1034 top_to_mod = TRUE; | |
1035 break; | |
1036 } | |
1326 | 1037 cur = cur->next; |
1038 } | |
1039 } | |
7 | 1040 #endif |
1041 } | |
1042 #ifdef FEAT_FOLDING | |
1043 if (mod_top != 0 && hasAnyFolding(wp)) | |
1044 { | |
1045 linenr_T lnumt, lnumb; | |
1046 | |
1047 /* | |
1048 * A change in a line can cause lines above it to become folded or | |
1049 * unfolded. Find the top most buffer line that may be affected. | |
1050 * If the line was previously folded and displayed, get the first | |
1051 * line of that fold. If the line is folded now, get the first | |
1052 * folded line. Use the minimum of these two. | |
1053 */ | |
1054 | |
1055 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
1056 * the line below it. If there is no valid entry, use w_topline. | |
1057 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1058 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1059 lnumt = wp->w_topline; | |
1060 lnumb = MAXLNUM; | |
1061 for (i = 0; i < wp->w_lines_valid; ++i) | |
1062 if (wp->w_lines[i].wl_valid) | |
1063 { | |
1064 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1065 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1066 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1067 { | |
1068 lnumb = wp->w_lines[i].wl_lnum; | |
1069 /* When there is a fold column it might need updating | |
1070 * in the next line ("J" just above an open fold). */ | |
1071 if (wp->w_p_fdc > 0) | |
1072 ++lnumb; | |
1073 } | |
1074 } | |
1075 | |
1076 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1077 if (mod_top > lnumt) | |
1078 mod_top = lnumt; | |
1079 | |
1080 /* Now do the same for the bottom line (one above mod_bot). */ | |
1081 --mod_bot; | |
1082 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1083 ++mod_bot; | |
1084 if (mod_bot < lnumb) | |
1085 mod_bot = lnumb; | |
1086 } | |
1087 #endif | |
1088 | |
1089 /* When a change starts above w_topline and the end is below | |
1090 * w_topline, start redrawing at w_topline. | |
36 | 1091 * If the end of the change is above w_topline: do like no change was |
1092 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1093 if (mod_top != 0 && mod_top < wp->w_topline) |
1094 { | |
1095 if (mod_bot > wp->w_topline) | |
1096 mod_top = wp->w_topline; | |
1097 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1098 else if (syntax_present(wp)) |
7 | 1099 top_end = 1; |
1100 #endif | |
1101 } | |
36 | 1102 |
1103 /* When line numbers are displayed need to redraw all lines below | |
1104 * inserted/deleted lines. */ | |
1105 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1106 mod_bot = MAXLNUM; | |
7 | 1107 } |
1108 | |
1109 /* | |
1110 * When only displaying the lines at the top, set top_end. Used when | |
1111 * window has scrolled down for msg_scrolled. | |
1112 */ | |
1113 if (type == REDRAW_TOP) | |
1114 { | |
1115 j = 0; | |
1116 for (i = 0; i < wp->w_lines_valid; ++i) | |
1117 { | |
1118 j += wp->w_lines[i].wl_size; | |
1119 if (j >= wp->w_upd_rows) | |
1120 { | |
1121 top_end = j; | |
1122 break; | |
1123 } | |
1124 } | |
1125 if (top_end == 0) | |
1126 /* not found (cannot happen?): redraw everything */ | |
1127 type = NOT_VALID; | |
1128 else | |
1129 /* top area defined, the rest is VALID */ | |
1130 type = VALID; | |
1131 } | |
1132 | |
1378 | 1133 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1134 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1135 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1136 * called. */ | |
1137 if (screen_cleared) | |
1138 screen_cleared = MAYBE; | |
1139 | |
7 | 1140 /* |
1141 * If there are no changes on the screen that require a complete redraw, | |
1142 * handle three cases: | |
1143 * 1: we are off the top of the screen by a few lines: scroll down | |
1144 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1145 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1146 * w_lines[] that needs updating. | |
1147 */ | |
743 | 1148 if ((type == VALID || type == SOME_VALID |
1149 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1150 #ifdef FEAT_DIFF |
1151 && !wp->w_botfill && !wp->w_old_botfill | |
1152 #endif | |
1153 ) | |
1154 { | |
1155 if (mod_top != 0 && wp->w_topline == mod_top) | |
1156 { | |
1157 /* | |
1158 * w_topline is the first changed line, the scrolling will be done | |
1159 * further down. | |
1160 */ | |
1161 } | |
1162 else if (wp->w_lines[0].wl_valid | |
1163 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1164 #ifdef FEAT_DIFF | |
1165 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1166 && wp->w_topfill > wp->w_old_topfill) | |
1167 #endif | |
1168 )) | |
1169 { | |
1170 /* | |
1171 * New topline is above old topline: May scroll down. | |
1172 */ | |
1173 #ifdef FEAT_FOLDING | |
1174 if (hasAnyFolding(wp)) | |
1175 { | |
1176 linenr_T ln; | |
1177 | |
1178 /* count the number of lines we are off, counting a sequence | |
1179 * of folded lines as one */ | |
1180 j = 0; | |
1181 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1182 { | |
1183 ++j; | |
1184 if (j >= wp->w_height - 2) | |
1185 break; | |
1186 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1187 } | |
1188 } | |
1189 else | |
1190 #endif | |
1191 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1192 if (j < wp->w_height - 2) /* not too far off */ | |
1193 { | |
1194 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1195 #ifdef FEAT_DIFF | |
1196 /* insert extra lines for previously invisible filler lines */ | |
1197 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1198 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1199 - wp->w_old_topfill; | |
1200 #endif | |
1201 if (i < wp->w_height - 2) /* less than a screen off */ | |
1202 { | |
1203 /* | |
1204 * Try to insert the correct number of lines. | |
1205 * If not the last window, delete the lines at the bottom. | |
1206 * win_ins_lines may fail when the terminal can't do it. | |
1207 */ | |
1208 if (i > 0) | |
1209 check_for_delay(FALSE); | |
1210 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1211 { | |
1212 if (wp->w_lines_valid != 0) | |
1213 { | |
1214 /* Need to update rows that are new, stop at the | |
1215 * first one that scrolled down. */ | |
1216 top_end = i; | |
1217 #ifdef FEAT_VISUAL | |
1218 scrolled_down = TRUE; | |
1219 #endif | |
1220 | |
1221 /* Move the entries that were scrolled, disable | |
1222 * the entries for the lines to be redrawn. */ | |
1223 if ((wp->w_lines_valid += j) > wp->w_height) | |
1224 wp->w_lines_valid = wp->w_height; | |
1225 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1226 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1227 while (idx >= 0) | |
1228 wp->w_lines[idx--].wl_valid = FALSE; | |
1229 } | |
1230 } | |
1231 else | |
1232 mid_start = 0; /* redraw all lines */ | |
1233 } | |
1234 else | |
1235 mid_start = 0; /* redraw all lines */ | |
1236 } | |
1237 else | |
1238 mid_start = 0; /* redraw all lines */ | |
1239 } | |
1240 else | |
1241 { | |
1242 /* | |
1243 * New topline is at or below old topline: May scroll up. | |
1244 * When topline didn't change, find first entry in w_lines[] that | |
1245 * needs updating. | |
1246 */ | |
1247 | |
1248 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1249 j = -1; | |
1250 row = 0; | |
1251 for (i = 0; i < wp->w_lines_valid; i++) | |
1252 { | |
1253 if (wp->w_lines[i].wl_valid | |
1254 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1255 { | |
1256 j = i; | |
1257 break; | |
1258 } | |
1259 row += wp->w_lines[i].wl_size; | |
1260 } | |
1261 if (j == -1) | |
1262 { | |
1263 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1264 * lines */ | |
1265 mid_start = 0; | |
1266 } | |
1267 else | |
1268 { | |
1269 /* | |
1270 * Try to delete the correct number of lines. | |
1271 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1272 */ | |
1273 #ifdef FEAT_DIFF | |
1274 /* If the topline didn't change, delete old filler lines, | |
1275 * otherwise delete filler lines of the new topline... */ | |
1276 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1277 row += wp->w_old_topfill; | |
1278 else | |
1279 row += diff_check_fill(wp, wp->w_topline); | |
1280 /* ... but don't delete new filler lines. */ | |
1281 row -= wp->w_topfill; | |
1282 #endif | |
1283 if (row > 0) | |
1284 { | |
1285 check_for_delay(FALSE); | |
1286 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1287 bot_start = wp->w_height - row; | |
1288 else | |
1289 mid_start = 0; /* redraw all lines */ | |
1290 } | |
1291 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1292 { | |
1293 /* | |
1294 * Skip the lines (below the deleted lines) that are still | |
1295 * valid and don't need redrawing. Copy their info | |
1296 * upwards, to compensate for the deleted lines. Set | |
1297 * bot_start to the first row that needs redrawing. | |
1298 */ | |
1299 bot_start = 0; | |
1300 idx = 0; | |
1301 for (;;) | |
1302 { | |
1303 wp->w_lines[idx] = wp->w_lines[j]; | |
1304 /* stop at line that didn't fit, unless it is still | |
1305 * valid (no lines deleted) */ | |
1306 if (row > 0 && bot_start + row | |
1307 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1308 { | |
1309 wp->w_lines_valid = idx + 1; | |
1310 break; | |
1311 } | |
1312 bot_start += wp->w_lines[idx++].wl_size; | |
1313 | |
1314 /* stop at the last valid entry in w_lines[].wl_size */ | |
1315 if (++j >= wp->w_lines_valid) | |
1316 { | |
1317 wp->w_lines_valid = idx; | |
1318 break; | |
1319 } | |
1320 } | |
1321 #ifdef FEAT_DIFF | |
1322 /* Correct the first entry for filler lines at the top | |
1323 * when it won't get updated below. */ | |
1324 if (wp->w_p_diff && bot_start > 0) | |
1325 wp->w_lines[0].wl_size = | |
1326 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1327 + wp->w_topfill; | |
1328 #endif | |
1329 } | |
1330 } | |
1331 } | |
1332 | |
1333 /* When starting redraw in the first line, redraw all lines. When | |
1334 * there is only one window it's probably faster to clear the screen | |
1335 * first. */ | |
1336 if (mid_start == 0) | |
1337 { | |
1338 mid_end = wp->w_height; | |
1339 if (lastwin == firstwin) | |
981 | 1340 { |
1331 | 1341 /* Clear the screen when it was not done by win_del_lines() or |
1342 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1343 * then. */ | |
1344 if (screen_cleared != TRUE) | |
1345 screenclear(); | |
981 | 1346 #ifdef FEAT_WINDOWS |
1347 /* The screen was cleared, redraw the tab pages line. */ | |
1348 if (redraw_tabline) | |
1349 draw_tabline(); | |
1350 #endif | |
1351 } | |
7 | 1352 } |
1331 | 1353 |
1354 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1355 * cleared (only happens for the first window) or when screenclear() | |
1356 * was called directly above, "must_redraw" will have been set to | |
1357 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1358 if (screen_cleared == TRUE) | |
1359 must_redraw = 0; | |
7 | 1360 } |
1361 else | |
1362 { | |
1363 /* Not VALID or INVERTED: redraw all lines. */ | |
1364 mid_start = 0; | |
1365 mid_end = wp->w_height; | |
1366 } | |
1367 | |
743 | 1368 if (type == SOME_VALID) |
1369 { | |
1370 /* SOME_VALID: redraw all lines. */ | |
1371 mid_start = 0; | |
1372 mid_end = wp->w_height; | |
1373 type = NOT_VALID; | |
1374 } | |
1375 | |
7 | 1376 #ifdef FEAT_VISUAL |
1377 /* check if we are updating or removing the inverted part */ | |
1378 if ((VIsual_active && buf == curwin->w_buffer) | |
1379 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1380 { | |
1381 linenr_T from, to; | |
1382 | |
1383 if (VIsual_active) | |
1384 { | |
1385 if (VIsual_active | |
1386 && (VIsual_mode != wp->w_old_visual_mode | |
1387 || type == INVERTED_ALL)) | |
1388 { | |
1389 /* | |
1390 * If the type of Visual selection changed, redraw the whole | |
1391 * selection. Also when the ownership of the X selection is | |
1392 * gained or lost. | |
1393 */ | |
1394 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1395 { | |
1396 from = curwin->w_cursor.lnum; | |
1397 to = VIsual.lnum; | |
1398 } | |
1399 else | |
1400 { | |
1401 from = VIsual.lnum; | |
1402 to = curwin->w_cursor.lnum; | |
1403 } | |
1404 /* redraw more when the cursor moved as well */ | |
1405 if (wp->w_old_cursor_lnum < from) | |
1406 from = wp->w_old_cursor_lnum; | |
1407 if (wp->w_old_cursor_lnum > to) | |
1408 to = wp->w_old_cursor_lnum; | |
1409 if (wp->w_old_visual_lnum < from) | |
1410 from = wp->w_old_visual_lnum; | |
1411 if (wp->w_old_visual_lnum > to) | |
1412 to = wp->w_old_visual_lnum; | |
1413 } | |
1414 else | |
1415 { | |
1416 /* | |
1417 * Find the line numbers that need to be updated: The lines | |
1418 * between the old cursor position and the current cursor | |
1419 * position. Also check if the Visual position changed. | |
1420 */ | |
1421 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1422 { | |
1423 from = curwin->w_cursor.lnum; | |
1424 to = wp->w_old_cursor_lnum; | |
1425 } | |
1426 else | |
1427 { | |
1428 from = wp->w_old_cursor_lnum; | |
1429 to = curwin->w_cursor.lnum; | |
1430 if (from == 0) /* Visual mode just started */ | |
1431 from = to; | |
1432 } | |
1433 | |
422 | 1434 if (VIsual.lnum != wp->w_old_visual_lnum |
1435 || VIsual.col != wp->w_old_visual_col) | |
7 | 1436 { |
1437 if (wp->w_old_visual_lnum < from | |
1438 && wp->w_old_visual_lnum != 0) | |
1439 from = wp->w_old_visual_lnum; | |
1440 if (wp->w_old_visual_lnum > to) | |
1441 to = wp->w_old_visual_lnum; | |
1442 if (VIsual.lnum < from) | |
1443 from = VIsual.lnum; | |
1444 if (VIsual.lnum > to) | |
1445 to = VIsual.lnum; | |
1446 } | |
1447 } | |
1448 | |
1449 /* | |
1450 * If in block mode and changed column or curwin->w_curswant: | |
1451 * update all lines. | |
1452 * First compute the actual start and end column. | |
1453 */ | |
1454 if (VIsual_mode == Ctrl_V) | |
1455 { | |
1456 colnr_T fromc, toc; | |
1457 | |
1458 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1459 ++toc; | |
1460 if (curwin->w_curswant == MAXCOL) | |
1461 toc = MAXCOL; | |
1462 | |
1463 if (fromc != wp->w_old_cursor_fcol | |
1464 || toc != wp->w_old_cursor_lcol) | |
1465 { | |
1466 if (from > VIsual.lnum) | |
1467 from = VIsual.lnum; | |
1468 if (to < VIsual.lnum) | |
1469 to = VIsual.lnum; | |
1470 } | |
1471 wp->w_old_cursor_fcol = fromc; | |
1472 wp->w_old_cursor_lcol = toc; | |
1473 } | |
1474 } | |
1475 else | |
1476 { | |
1477 /* Use the line numbers of the old Visual area. */ | |
1478 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1479 { | |
1480 from = wp->w_old_cursor_lnum; | |
1481 to = wp->w_old_visual_lnum; | |
1482 } | |
1483 else | |
1484 { | |
1485 from = wp->w_old_visual_lnum; | |
1486 to = wp->w_old_cursor_lnum; | |
1487 } | |
1488 } | |
1489 | |
1490 /* | |
1491 * There is no need to update lines above the top of the window. | |
1492 */ | |
1493 if (from < wp->w_topline) | |
1494 from = wp->w_topline; | |
1495 | |
1496 /* | |
1497 * If we know the value of w_botline, use it to restrict the update to | |
1498 * the lines that are visible in the window. | |
1499 */ | |
1500 if (wp->w_valid & VALID_BOTLINE) | |
1501 { | |
1502 if (from >= wp->w_botline) | |
1503 from = wp->w_botline - 1; | |
1504 if (to >= wp->w_botline) | |
1505 to = wp->w_botline - 1; | |
1506 } | |
1507 | |
1508 /* | |
1509 * Find the minimal part to be updated. | |
1510 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1511 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1512 * top_end; need to redraw from top_end to the "to" line. | |
1513 * A middle mouse click with a Visual selection may change the text | |
1514 * above the Visual area and reset wl_valid, do count these for | |
1515 * mid_end (in srow). | |
1516 */ | |
1517 if (mid_start > 0) | |
1518 { | |
1519 lnum = wp->w_topline; | |
1520 idx = 0; | |
1521 srow = 0; | |
1522 if (scrolled_down) | |
1523 mid_start = top_end; | |
1524 else | |
1525 mid_start = 0; | |
1526 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1527 { | |
1528 if (wp->w_lines[idx].wl_valid) | |
1529 mid_start += wp->w_lines[idx].wl_size; | |
1530 else if (!scrolled_down) | |
1531 srow += wp->w_lines[idx].wl_size; | |
1532 ++idx; | |
1533 # ifdef FEAT_FOLDING | |
1534 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1535 lnum = wp->w_lines[idx].wl_lnum; | |
1536 else | |
1537 # endif | |
1538 ++lnum; | |
1539 } | |
1540 srow += mid_start; | |
1541 mid_end = wp->w_height; | |
1542 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1543 { | |
1544 if (wp->w_lines[idx].wl_valid | |
1545 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1546 { | |
1547 /* Only update until first row of this line */ | |
1548 mid_end = srow; | |
1549 break; | |
1550 } | |
1551 srow += wp->w_lines[idx].wl_size; | |
1552 } | |
1553 } | |
1554 } | |
1555 | |
1556 if (VIsual_active && buf == curwin->w_buffer) | |
1557 { | |
1558 wp->w_old_visual_mode = VIsual_mode; | |
1559 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1560 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1561 wp->w_old_visual_col = VIsual.col; |
7 | 1562 wp->w_old_curswant = curwin->w_curswant; |
1563 } | |
1564 else | |
1565 { | |
1566 wp->w_old_visual_mode = 0; | |
1567 wp->w_old_cursor_lnum = 0; | |
1568 wp->w_old_visual_lnum = 0; | |
422 | 1569 wp->w_old_visual_col = 0; |
7 | 1570 } |
1571 #endif /* FEAT_VISUAL */ | |
1572 | |
1573 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1574 /* reset got_int, otherwise regexp won't work */ | |
1575 save_got_int = got_int; | |
1576 got_int = 0; | |
1577 #endif | |
1578 #ifdef FEAT_FOLDING | |
1579 win_foldinfo.fi_level = 0; | |
1580 #endif | |
1581 | |
1582 /* | |
1583 * Update all the window rows. | |
1584 */ | |
1585 idx = 0; /* first entry in w_lines[].wl_size */ | |
1586 row = 0; | |
1587 srow = 0; | |
1588 lnum = wp->w_topline; /* first line shown in window */ | |
1589 for (;;) | |
1590 { | |
1591 /* stop updating when reached the end of the window (check for _past_ | |
1592 * the end of the window is at the end of the loop) */ | |
1593 if (row == wp->w_height) | |
1594 { | |
1595 didline = TRUE; | |
1596 break; | |
1597 } | |
1598 | |
1599 /* stop updating when hit the end of the file */ | |
1600 if (lnum > buf->b_ml.ml_line_count) | |
1601 { | |
1602 eof = TRUE; | |
1603 break; | |
1604 } | |
1605 | |
1606 /* Remember the starting row of the line that is going to be dealt | |
1607 * with. It is used further down when the line doesn't fit. */ | |
1608 srow = row; | |
1609 | |
1610 /* | |
1611 * Update a line when it is in an area that needs updating, when it | |
1612 * has changes or w_lines[idx] is invalid. | |
1613 * bot_start may be halfway a wrapped line after using | |
1614 * win_del_lines(), check if the current line includes it. | |
1615 * When syntax folding is being used, the saved syntax states will | |
1616 * already have been updated, we can't see where the syntax state is | |
1617 * the same again, just update until the end of the window. | |
1618 */ | |
1619 if (row < top_end | |
1620 || (row >= mid_start && row < mid_end) | |
1621 #ifdef FEAT_SEARCH_EXTRA | |
1622 || top_to_mod | |
1623 #endif | |
1624 || idx >= wp->w_lines_valid | |
1625 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1626 || (mod_top != 0 | |
1627 && (lnum == mod_top | |
1628 || (lnum >= mod_top | |
1629 && (lnum < mod_bot | |
1630 #ifdef FEAT_SYN_HL | |
1631 || did_update == DID_FOLD | |
1632 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1633 && syntax_present(wp) |
7 | 1634 && ( |
1635 # ifdef FEAT_FOLDING | |
1636 (foldmethodIsSyntax(wp) | |
1637 && hasAnyFolding(wp)) || | |
1638 # endif | |
1639 syntax_check_changed(lnum))) | |
1640 #endif | |
1641 ))))) | |
1642 { | |
1643 #ifdef FEAT_SEARCH_EXTRA | |
1644 if (lnum == mod_top) | |
1645 top_to_mod = FALSE; | |
1646 #endif | |
1647 | |
1648 /* | |
1649 * When at start of changed lines: May scroll following lines | |
1650 * up or down to minimize redrawing. | |
1651 * Don't do this when the change continues until the end. | |
3318 | 1652 * Don't scroll when dollar_vcol >= 0, keep the "$". |
7 | 1653 */ |
1654 if (lnum == mod_top | |
1655 && mod_bot != MAXLNUM | |
3318 | 1656 && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
7 | 1657 { |
1658 int old_rows = 0; | |
1659 int new_rows = 0; | |
1660 int xtra_rows; | |
1661 linenr_T l; | |
1662 | |
1663 /* Count the old number of window rows, using w_lines[], which | |
1664 * should still contain the sizes for the lines as they are | |
1665 * currently displayed. */ | |
1666 for (i = idx; i < wp->w_lines_valid; ++i) | |
1667 { | |
1668 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1669 * lines are part of the changed area. */ | |
1670 if (wp->w_lines[i].wl_valid | |
1671 && wp->w_lines[i].wl_lnum == mod_bot) | |
1672 break; | |
1673 old_rows += wp->w_lines[i].wl_size; | |
1674 #ifdef FEAT_FOLDING | |
1675 if (wp->w_lines[i].wl_valid | |
1676 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1677 { | |
1678 /* Must have found the last valid entry above mod_bot. | |
1679 * Add following invalid entries. */ | |
1680 ++i; | |
1681 while (i < wp->w_lines_valid | |
1682 && !wp->w_lines[i].wl_valid) | |
1683 old_rows += wp->w_lines[i++].wl_size; | |
1684 break; | |
1685 } | |
1686 #endif | |
1687 } | |
1688 | |
1689 if (i >= wp->w_lines_valid) | |
1690 { | |
1691 /* We can't find a valid line below the changed lines, | |
1692 * need to redraw until the end of the window. | |
1693 * Inserting/deleting lines has no use. */ | |
1694 bot_start = 0; | |
1695 } | |
1696 else | |
1697 { | |
1698 /* Able to count old number of rows: Count new window | |
1699 * rows, and may insert/delete lines */ | |
1700 j = idx; | |
1701 for (l = lnum; l < mod_bot; ++l) | |
1702 { | |
1703 #ifdef FEAT_FOLDING | |
1704 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1705 ++new_rows; | |
1706 else | |
1707 #endif | |
1708 #ifdef FEAT_DIFF | |
1709 if (l == wp->w_topline) | |
1710 new_rows += plines_win_nofill(wp, l, TRUE) | |
1711 + wp->w_topfill; | |
1712 else | |
1713 #endif | |
1714 new_rows += plines_win(wp, l, TRUE); | |
1715 ++j; | |
1716 if (new_rows > wp->w_height - row - 2) | |
1717 { | |
1718 /* it's getting too much, must redraw the rest */ | |
1719 new_rows = 9999; | |
1720 break; | |
1721 } | |
1722 } | |
1723 xtra_rows = new_rows - old_rows; | |
1724 if (xtra_rows < 0) | |
1725 { | |
1726 /* May scroll text up. If there is not enough | |
1727 * remaining text or scrolling fails, must redraw the | |
1728 * rest. If scrolling works, must redraw the text | |
1729 * below the scrolled text. */ | |
1730 if (row - xtra_rows >= wp->w_height - 2) | |
1731 mod_bot = MAXLNUM; | |
1732 else | |
1733 { | |
1734 check_for_delay(FALSE); | |
1735 if (win_del_lines(wp, row, | |
1736 -xtra_rows, FALSE, FALSE) == FAIL) | |
1737 mod_bot = MAXLNUM; | |
1738 else | |
1739 bot_start = wp->w_height + xtra_rows; | |
1740 } | |
1741 } | |
1742 else if (xtra_rows > 0) | |
1743 { | |
1744 /* May scroll text down. If there is not enough | |
1745 * remaining text of scrolling fails, must redraw the | |
1746 * rest. */ | |
1747 if (row + xtra_rows >= wp->w_height - 2) | |
1748 mod_bot = MAXLNUM; | |
1749 else | |
1750 { | |
1751 check_for_delay(FALSE); | |
1752 if (win_ins_lines(wp, row + old_rows, | |
1753 xtra_rows, FALSE, FALSE) == FAIL) | |
1754 mod_bot = MAXLNUM; | |
1755 else if (top_end > row + old_rows) | |
1756 /* Scrolled the part at the top that requires | |
1757 * updating down. */ | |
1758 top_end += xtra_rows; | |
1759 } | |
1760 } | |
1761 | |
1762 /* When not updating the rest, may need to move w_lines[] | |
1763 * entries. */ | |
1764 if (mod_bot != MAXLNUM && i != j) | |
1765 { | |
1766 if (j < i) | |
1767 { | |
1768 int x = row + new_rows; | |
1769 | |
1770 /* move entries in w_lines[] upwards */ | |
1771 for (;;) | |
1772 { | |
1773 /* stop at last valid entry in w_lines[] */ | |
1774 if (i >= wp->w_lines_valid) | |
1775 { | |
1776 wp->w_lines_valid = j; | |
1777 break; | |
1778 } | |
1779 wp->w_lines[j] = wp->w_lines[i]; | |
1780 /* stop at a line that won't fit */ | |
1781 if (x + (int)wp->w_lines[j].wl_size | |
1782 > wp->w_height) | |
1783 { | |
1784 wp->w_lines_valid = j + 1; | |
1785 break; | |
1786 } | |
1787 x += wp->w_lines[j++].wl_size; | |
1788 ++i; | |
1789 } | |
1790 if (bot_start > x) | |
1791 bot_start = x; | |
1792 } | |
1793 else /* j > i */ | |
1794 { | |
1795 /* move entries in w_lines[] downwards */ | |
1796 j -= i; | |
1797 wp->w_lines_valid += j; | |
1798 if (wp->w_lines_valid > wp->w_height) | |
1799 wp->w_lines_valid = wp->w_height; | |
1800 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1801 wp->w_lines[i] = wp->w_lines[i - j]; | |
1802 | |
1803 /* The w_lines[] entries for inserted lines are | |
1804 * now invalid, but wl_size may be used above. | |
1805 * Reset to zero. */ | |
1806 while (i >= idx) | |
1807 { | |
1808 wp->w_lines[i].wl_size = 0; | |
1809 wp->w_lines[i--].wl_valid = FALSE; | |
1810 } | |
1811 } | |
1812 } | |
1813 } | |
1814 } | |
1815 | |
1816 #ifdef FEAT_FOLDING | |
1817 /* | |
1818 * When lines are folded, display one line for all of them. | |
1819 * Otherwise, display normally (can be several display lines when | |
1820 * 'wrap' is on). | |
1821 */ | |
1822 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1823 if (fold_count != 0) | |
1824 { | |
1825 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1826 ++row; | |
1827 --fold_count; | |
1828 wp->w_lines[idx].wl_folded = TRUE; | |
1829 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1830 # ifdef FEAT_SYN_HL | |
1831 did_update = DID_FOLD; | |
1832 # endif | |
1833 } | |
1834 else | |
1835 #endif | |
1836 if (idx < wp->w_lines_valid | |
1837 && wp->w_lines[idx].wl_valid | |
1838 && wp->w_lines[idx].wl_lnum == lnum | |
1839 && lnum > wp->w_topline | |
1840 && !(dy_flags & DY_LASTLINE) | |
1841 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1842 #ifdef FEAT_DIFF | |
1843 && diff_check_fill(wp, lnum) == 0 | |
1844 #endif | |
1845 ) | |
1846 { | |
1847 /* This line is not going to fit. Don't draw anything here, | |
1848 * will draw "@ " lines below. */ | |
1849 row = wp->w_height + 1; | |
1850 } | |
1851 else | |
1852 { | |
1853 #ifdef FEAT_SEARCH_EXTRA | |
1854 prepare_search_hl(wp, lnum); | |
1855 #endif | |
1856 #ifdef FEAT_SYN_HL | |
1857 /* Let the syntax stuff know we skipped a few lines. */ | |
1858 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
|
1859 && syntax_present(wp)) |
7 | 1860 syntax_end_parsing(syntax_last_parsed + 1); |
1861 #endif | |
1862 | |
1863 /* | |
1864 * Display one line. | |
1865 */ | |
625 | 1866 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1867 |
1868 #ifdef FEAT_FOLDING | |
1869 wp->w_lines[idx].wl_folded = FALSE; | |
1870 wp->w_lines[idx].wl_lastlnum = lnum; | |
1871 #endif | |
1872 #ifdef FEAT_SYN_HL | |
1873 did_update = DID_LINE; | |
1874 syntax_last_parsed = lnum; | |
1875 #endif | |
1876 } | |
1877 | |
1878 wp->w_lines[idx].wl_lnum = lnum; | |
1879 wp->w_lines[idx].wl_valid = TRUE; | |
1880 if (row > wp->w_height) /* past end of screen */ | |
1881 { | |
1882 /* we may need the size of that too long line later on */ | |
3318 | 1883 if (dollar_vcol == -1) |
7 | 1884 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
1885 ++idx; | |
1886 break; | |
1887 } | |
3318 | 1888 if (dollar_vcol == -1) |
7 | 1889 wp->w_lines[idx].wl_size = row - srow; |
1890 ++idx; | |
1891 #ifdef FEAT_FOLDING | |
1892 lnum += fold_count + 1; | |
1893 #else | |
1894 ++lnum; | |
1895 #endif | |
1896 } | |
1897 else | |
1898 { | |
1899 /* This line does not need updating, advance to the next one */ | |
1900 row += wp->w_lines[idx++].wl_size; | |
1901 if (row > wp->w_height) /* past end of screen */ | |
1902 break; | |
1903 #ifdef FEAT_FOLDING | |
1904 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1905 #else | |
1906 ++lnum; | |
1907 #endif | |
1908 #ifdef FEAT_SYN_HL | |
1909 did_update = DID_NONE; | |
1910 #endif | |
1911 } | |
1912 | |
1913 if (lnum > buf->b_ml.ml_line_count) | |
1914 { | |
1915 eof = TRUE; | |
1916 break; | |
1917 } | |
1918 } | |
1919 /* | |
1920 * End of loop over all window lines. | |
1921 */ | |
1922 | |
1923 | |
1924 if (idx > wp->w_lines_valid) | |
1925 wp->w_lines_valid = idx; | |
1926 | |
1927 #ifdef FEAT_SYN_HL | |
1928 /* | |
1929 * Let the syntax stuff know we stop parsing here. | |
1930 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1931 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1932 syntax_end_parsing(syntax_last_parsed + 1); |
1933 #endif | |
1934 | |
1935 /* | |
1936 * If we didn't hit the end of the file, and we didn't finish the last | |
1937 * line we were working on, then the line didn't fit. | |
1938 */ | |
1939 wp->w_empty_rows = 0; | |
1940 #ifdef FEAT_DIFF | |
1941 wp->w_filler_rows = 0; | |
1942 #endif | |
1943 if (!eof && !didline) | |
1944 { | |
1945 if (lnum == wp->w_topline) | |
1946 { | |
1947 /* | |
1948 * Single line that does not fit! | |
1949 * Don't overwrite it, it can be edited. | |
1950 */ | |
1951 wp->w_botline = lnum + 1; | |
1952 } | |
1953 #ifdef FEAT_DIFF | |
1954 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1955 { | |
1956 /* Window ends in filler lines. */ | |
1957 wp->w_botline = lnum; | |
1958 wp->w_filler_rows = wp->w_height - srow; | |
1959 } | |
1960 #endif | |
1961 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1962 { | |
1963 /* | |
1964 * Last line isn't finished: Display "@@@" at the end. | |
1965 */ | |
1966 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1967 W_WINROW(wp) + wp->w_height, | |
1968 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1969 '@', '@', hl_attr(HLF_AT)); | |
1970 set_empty_rows(wp, srow); | |
1971 wp->w_botline = lnum; | |
1972 } | |
1973 else | |
1974 { | |
1975 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1976 wp->w_botline = lnum; | |
1977 } | |
1978 } | |
1979 else | |
1980 { | |
1981 #ifdef FEAT_VERTSPLIT | |
1982 draw_vsep_win(wp, row); | |
1983 #endif | |
1984 if (eof) /* we hit the end of the file */ | |
1985 { | |
1986 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1987 #ifdef FEAT_DIFF | |
1988 j = diff_check_fill(wp, wp->w_botline); | |
1989 if (j > 0 && !wp->w_botfill) | |
1990 { | |
1991 /* | |
1992 * Display filler lines at the end of the file | |
1993 */ | |
1994 if (char2cells(fill_diff) > 1) | |
1995 i = '-'; | |
1996 else | |
1997 i = fill_diff; | |
1998 if (row + j > wp->w_height) | |
1999 j = wp->w_height - row; | |
2000 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
2001 row += j; | |
2002 } | |
2003 #endif | |
2004 } | |
3318 | 2005 else if (dollar_vcol == -1) |
7 | 2006 wp->w_botline = lnum; |
2007 | |
2008 /* make sure the rest of the screen is blank */ | |
2009 /* put '~'s on rows that aren't part of the file. */ | |
2010 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
2011 } | |
2012 | |
2013 /* Reset the type of redrawing required, the window has been updated. */ | |
2014 wp->w_redr_type = 0; | |
2015 #ifdef FEAT_DIFF | |
2016 wp->w_old_topfill = wp->w_topfill; | |
2017 wp->w_old_botfill = wp->w_botfill; | |
2018 #endif | |
2019 | |
3318 | 2020 if (dollar_vcol == -1) |
7 | 2021 { |
2022 /* | |
2023 * There is a trick with w_botline. If we invalidate it on each | |
2024 * change that might modify it, this will cause a lot of expensive | |
2025 * calls to plines() in update_topline() each time. Therefore the | |
2026 * value of w_botline is often approximated, and this value is used to | |
2027 * compute the value of w_topline. If the value of w_botline was | |
2028 * wrong, check that the value of w_topline is correct (cursor is on | |
2029 * the visible part of the text). If it's not, we need to redraw | |
2030 * again. Mostly this just means scrolling up a few lines, so it | |
2031 * doesn't look too bad. Only do this for the current window (where | |
2032 * changes are relevant). | |
2033 */ | |
2034 wp->w_valid |= VALID_BOTLINE; | |
2035 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
2036 { | |
2037 recursive = TRUE; | |
2038 curwin->w_valid &= ~VALID_TOPLINE; | |
2039 update_topline(); /* may invalidate w_botline again */ | |
2040 if (must_redraw != 0) | |
2041 { | |
2042 /* Don't update for changes in buffer again. */ | |
2043 i = curbuf->b_mod_set; | |
2044 curbuf->b_mod_set = FALSE; | |
2045 win_update(curwin); | |
2046 must_redraw = 0; | |
2047 curbuf->b_mod_set = i; | |
2048 } | |
2049 recursive = FALSE; | |
2050 } | |
2051 } | |
2052 | |
2053 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
2054 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
2055 if (!got_int) | |
2056 got_int = save_got_int; | |
2057 #endif | |
2058 } | |
2059 | |
2060 #ifdef FEAT_SIGNS | |
2061 static int draw_signcolumn __ARGS((win_T *wp)); | |
2062 | |
2063 /* | |
2064 * Return TRUE when window "wp" has a column to draw signs in. | |
2065 */ | |
2066 static int | |
2067 draw_signcolumn(wp) | |
2068 win_T *wp; | |
2069 { | |
2070 return (wp->w_buffer->b_signlist != NULL | |
2071 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2072 || netbeans_active() |
7 | 2073 # endif |
2074 ); | |
2075 } | |
2076 #endif | |
2077 | |
2078 /* | |
2079 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2080 * as the filler character. | |
2081 */ | |
2082 static void | |
2083 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2084 win_T *wp; | |
2085 int c1; | |
2086 int c2; | |
2087 int row; | |
2088 int endrow; | |
534 | 2089 hlf_T hl; |
7 | 2090 { |
2091 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2092 int n = 0; | |
2093 # define FDC_OFF n | |
2094 #else | |
2095 # define FDC_OFF 0 | |
2096 #endif | |
2097 | |
2098 #ifdef FEAT_RIGHTLEFT | |
2099 if (wp->w_p_rl) | |
2100 { | |
2101 /* No check for cmdline window: should never be right-left. */ | |
2102 # ifdef FEAT_FOLDING | |
2103 n = wp->w_p_fdc; | |
2104 | |
2105 if (n > 0) | |
2106 { | |
2107 /* draw the fold column at the right */ | |
119 | 2108 if (n > W_WIDTH(wp)) |
2109 n = W_WIDTH(wp); | |
7 | 2110 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2111 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2112 ' ', ' ', hl_attr(HLF_FC)); | |
2113 } | |
2114 # endif | |
2115 # ifdef FEAT_SIGNS | |
2116 if (draw_signcolumn(wp)) | |
2117 { | |
2118 int nn = n + 2; | |
2119 | |
2120 /* draw the sign column left of the fold column */ | |
119 | 2121 if (nn > W_WIDTH(wp)) |
2122 nn = W_WIDTH(wp); | |
7 | 2123 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2124 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2125 ' ', ' ', hl_attr(HLF_SC)); | |
2126 n = nn; | |
2127 } | |
2128 # endif | |
2129 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2130 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2131 c2, c2, hl_attr(hl)); | |
2132 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2133 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2134 c1, c2, hl_attr(hl)); | |
2135 } | |
2136 else | |
2137 #endif | |
2138 { | |
2139 #ifdef FEAT_CMDWIN | |
2140 if (cmdwin_type != 0 && wp == curwin) | |
2141 { | |
2142 /* draw the cmdline character in the leftmost column */ | |
2143 n = 1; | |
2144 if (n > wp->w_width) | |
2145 n = wp->w_width; | |
2146 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2147 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2148 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2149 } | |
2150 #endif | |
2151 #ifdef FEAT_FOLDING | |
2152 if (wp->w_p_fdc > 0) | |
2153 { | |
2154 int nn = n + wp->w_p_fdc; | |
2155 | |
2156 /* draw the fold column at the left */ | |
2157 if (nn > W_WIDTH(wp)) | |
2158 nn = W_WIDTH(wp); | |
2159 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2160 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2161 ' ', ' ', hl_attr(HLF_FC)); | |
2162 n = nn; | |
2163 } | |
2164 #endif | |
2165 #ifdef FEAT_SIGNS | |
2166 if (draw_signcolumn(wp)) | |
2167 { | |
2168 int nn = n + 2; | |
2169 | |
2170 /* draw the sign column after the fold column */ | |
2171 if (nn > W_WIDTH(wp)) | |
2172 nn = W_WIDTH(wp); | |
2173 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2174 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2175 ' ', ' ', hl_attr(HLF_SC)); | |
2176 n = nn; | |
2177 } | |
2178 #endif | |
2179 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2180 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2181 c1, c2, hl_attr(hl)); | |
2182 } | |
2183 set_empty_rows(wp, row); | |
2184 } | |
2185 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2186 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2187 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
|
2188 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2189 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2190 * 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
|
2191 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2192 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2193 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2194 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2195 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2196 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2197 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2198 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2199 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2200 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2201 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2202 |
7 | 2203 #ifdef FEAT_FOLDING |
2204 /* | |
2205 * Display one folded line. | |
2206 */ | |
2207 static void | |
2208 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2209 win_T *wp; | |
2210 long fold_count; | |
2211 foldinfo_T *foldinfo; | |
2212 linenr_T lnum; | |
2213 int row; | |
2214 { | |
2215 char_u buf[51]; | |
2216 pos_T *top, *bot; | |
2217 linenr_T lnume = lnum + fold_count - 1; | |
2218 int len; | |
29 | 2219 char_u *text; |
7 | 2220 int fdc; |
2221 int col; | |
2222 int txtcol; | |
2223 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2224 int ri; |
7 | 2225 |
2226 /* Build the fold line: | |
2227 * 1. Add the cmdwin_type for the command-line window | |
2228 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2229 * 3. Add the 'number' or 'relativenumber' column |
7 | 2230 * 4. Compose the text |
2231 * 5. Add the text | |
2232 * 6. set highlighting for the Visual area an other text | |
2233 */ | |
2234 col = 0; | |
2235 | |
2236 /* | |
2237 * 1. Add the cmdwin_type for the command-line window | |
2238 * Ignores 'rightleft', this window is never right-left. | |
2239 */ | |
2240 #ifdef FEAT_CMDWIN | |
2241 if (cmdwin_type != 0 && wp == curwin) | |
2242 { | |
2243 ScreenLines[off] = cmdwin_type; | |
2244 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2245 #ifdef FEAT_MBYTE | |
2246 if (enc_utf8) | |
2247 ScreenLinesUC[off] = 0; | |
2248 #endif | |
2249 ++col; | |
2250 } | |
2251 #endif | |
2252 | |
2253 /* | |
2254 * 2. Add the 'foldcolumn' | |
2255 */ | |
2256 fdc = wp->w_p_fdc; | |
2257 if (fdc > W_WIDTH(wp) - col) | |
2258 fdc = W_WIDTH(wp) - col; | |
2259 if (fdc > 0) | |
2260 { | |
2261 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2262 #ifdef FEAT_RIGHTLEFT | |
2263 if (wp->w_p_rl) | |
2264 { | |
2265 int i; | |
2266 | |
2267 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2268 hl_attr(HLF_FC)); | |
2269 /* reverse the fold column */ | |
2270 for (i = 0; i < fdc; ++i) | |
2271 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2272 } | |
2273 else | |
2274 #endif | |
2275 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2276 col += fdc; | |
2277 } | |
2278 | |
2279 #ifdef FEAT_RIGHTLEFT | |
216 | 2280 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2281 for (ri = 0; ri < l; ++ri) \ | |
2282 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2283 else \ | |
2284 for (ri = 0; ri < l; ++ri) \ | |
2285 ScreenAttrs[off + (p) + ri] = v | |
7 | 2286 #else |
216 | 2287 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2288 ScreenAttrs[off + (p) + ri] = v | |
7 | 2289 #endif |
2290 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2291 /* 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
|
2292 * text */ |
216 | 2293 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2294 |
2295 #ifdef FEAT_SIGNS | |
2296 /* If signs are being displayed, add two spaces. */ | |
2297 if (draw_signcolumn(wp)) | |
2298 { | |
2299 len = W_WIDTH(wp) - col; | |
2300 if (len > 0) | |
2301 { | |
2302 if (len > 2) | |
2303 len = 2; | |
2304 # ifdef FEAT_RIGHTLEFT | |
2305 if (wp->w_p_rl) | |
2306 /* the line number isn't reversed */ | |
2307 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2308 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2309 else | |
2310 # endif | |
2311 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2312 col += len; | |
2313 } | |
2314 } | |
2315 #endif | |
2316 | |
2317 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2318 * 3. Add the 'number' or 'relativenumber' column |
7 | 2319 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2320 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2321 { |
2322 len = W_WIDTH(wp) - col; | |
2323 if (len > 0) | |
2324 { | |
13 | 2325 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2326 long num; |
4065 | 2327 char *fmt = "%*ld "; |
13 | 2328 |
2329 if (len > w + 1) | |
2330 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2331 |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2332 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
|
2333 /* 'number' + 'norelativenumber' */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2334 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2335 else |
4065 | 2336 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2337 /* 'relativenumber', don't use negative numbers */ |
2675 | 2338 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
|
2339 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
|
2340 { |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2341 /* 'number' + 'relativenumber': cursor line shows absolute |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2342 * line number */ |
4065 | 2343 num = lnum; |
2344 fmt = "%-*ld "; | |
2345 } | |
2346 } | |
2347 | |
2348 sprintf((char *)buf, fmt, w, num); | |
7 | 2349 #ifdef FEAT_RIGHTLEFT |
2350 if (wp->w_p_rl) | |
2351 /* the line number isn't reversed */ | |
2352 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2353 hl_attr(HLF_FL)); | |
2354 else | |
2355 #endif | |
2356 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2357 col += len; | |
2358 } | |
2359 } | |
2360 | |
2361 /* | |
2362 * 4. Compose the folded-line string with 'foldtext', if set. | |
2363 */ | |
29 | 2364 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2365 |
2366 txtcol = col; /* remember where text starts */ | |
2367 | |
2368 /* | |
2369 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2370 * Right-left text is put in columns 0 - number-col, normal text is put | |
2371 * in columns number-col - window-width. | |
2372 */ | |
2373 #ifdef FEAT_MBYTE | |
2374 if (has_mbyte) | |
2375 { | |
2376 int cells; | |
714 | 2377 int u8c, u8cc[MAX_MCO]; |
2378 int i; | |
7 | 2379 int idx; |
2380 int c_len; | |
33 | 2381 char_u *p; |
7 | 2382 # ifdef FEAT_ARABIC |
2383 int prev_c = 0; /* previous Arabic character */ | |
2384 int prev_c1 = 0; /* first composing char for prev_c */ | |
2385 # endif | |
2386 | |
2387 # ifdef FEAT_RIGHTLEFT | |
2388 if (wp->w_p_rl) | |
2389 idx = off; | |
2390 else | |
2391 # endif | |
2392 idx = off + col; | |
2393 | |
2394 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2395 for (p = text; *p != NUL; ) | |
2396 { | |
2397 cells = (*mb_ptr2cells)(p); | |
474 | 2398 c_len = (*mb_ptr2len)(p); |
7 | 2399 if (col + cells > W_WIDTH(wp) |
2400 # ifdef FEAT_RIGHTLEFT | |
2401 - (wp->w_p_rl ? col : 0) | |
2402 # endif | |
2403 ) | |
2404 break; | |
2405 ScreenLines[idx] = *p; | |
2406 if (enc_utf8) | |
2407 { | |
714 | 2408 u8c = utfc_ptr2char(p, u8cc); |
2409 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2410 { |
2411 ScreenLinesUC[idx] = 0; | |
2412 #ifdef FEAT_ARABIC | |
2413 prev_c = u8c; | |
2414 #endif | |
2415 } | |
2416 else | |
2417 { | |
2418 #ifdef FEAT_ARABIC | |
2419 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2420 { | |
2421 /* Do Arabic shaping. */ | |
714 | 2422 int pc, pc1, nc; |
2423 int pcc[MAX_MCO]; | |
7 | 2424 int firstbyte = *p; |
2425 | |
2426 /* The idea of what is the previous and next | |
2427 * character depends on 'rightleft'. */ | |
2428 if (wp->w_p_rl) | |
2429 { | |
2430 pc = prev_c; | |
2431 pc1 = prev_c1; | |
2432 nc = utf_ptr2char(p + c_len); | |
714 | 2433 prev_c1 = u8cc[0]; |
7 | 2434 } |
2435 else | |
2436 { | |
714 | 2437 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2438 nc = prev_c; |
714 | 2439 pc1 = pcc[0]; |
7 | 2440 } |
2441 prev_c = u8c; | |
2442 | |
714 | 2443 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2444 pc, pc1, nc); |
2445 ScreenLines[idx] = firstbyte; | |
2446 } | |
2447 else | |
2448 prev_c = u8c; | |
2449 #endif | |
2450 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2451 #ifdef UNICODE16 |
7 | 2452 if (u8c >= 0x10000) |
2453 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2454 else | |
1401 | 2455 #endif |
7 | 2456 ScreenLinesUC[idx] = u8c; |
714 | 2457 for (i = 0; i < Screen_mco; ++i) |
2458 { | |
2459 ScreenLinesC[i][idx] = u8cc[i]; | |
2460 if (u8cc[i] == 0) | |
2461 break; | |
2462 } | |
7 | 2463 } |
2464 if (cells > 1) | |
2465 ScreenLines[idx + 1] = 0; | |
2466 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2467 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2468 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2469 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2470 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2471 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2472 ScreenLines[idx + 1] = p[1]; |
7 | 2473 col += cells; |
2474 idx += cells; | |
2475 p += c_len; | |
2476 } | |
2477 } | |
2478 else | |
2479 #endif | |
2480 { | |
2481 len = (int)STRLEN(text); | |
2482 if (len > W_WIDTH(wp) - col) | |
2483 len = W_WIDTH(wp) - col; | |
2484 if (len > 0) | |
2485 { | |
2486 #ifdef FEAT_RIGHTLEFT | |
2487 if (wp->w_p_rl) | |
2488 STRNCPY(current_ScreenLine, text, len); | |
2489 else | |
2490 #endif | |
2491 STRNCPY(current_ScreenLine + col, text, len); | |
2492 col += len; | |
2493 } | |
2494 } | |
2495 | |
2496 /* Fill the rest of the line with the fold filler */ | |
2497 #ifdef FEAT_RIGHTLEFT | |
2498 if (wp->w_p_rl) | |
2499 col -= txtcol; | |
2500 #endif | |
2501 while (col < W_WIDTH(wp) | |
2502 #ifdef FEAT_RIGHTLEFT | |
2503 - (wp->w_p_rl ? txtcol : 0) | |
2504 #endif | |
2505 ) | |
2506 { | |
2507 #ifdef FEAT_MBYTE | |
2508 if (enc_utf8) | |
2509 { | |
2510 if (fill_fold >= 0x80) | |
2511 { | |
2512 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2513 ScreenLinesC[0][off + col] = 0; |
7 | 2514 } |
2515 else | |
2516 ScreenLinesUC[off + col] = 0; | |
2517 } | |
2518 #endif | |
2519 ScreenLines[off + col++] = fill_fold; | |
2520 } | |
2521 | |
2522 if (text != buf) | |
2523 vim_free(text); | |
2524 | |
2525 /* | |
2526 * 6. set highlighting for the Visual area an other text. | |
2527 * If all folded lines are in the Visual area, highlight the line. | |
2528 */ | |
2529 #ifdef FEAT_VISUAL | |
2530 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2531 { | |
2532 if (ltoreq(curwin->w_cursor, VIsual)) | |
2533 { | |
2534 /* Visual is after curwin->w_cursor */ | |
2535 top = &curwin->w_cursor; | |
2536 bot = &VIsual; | |
2537 } | |
2538 else | |
2539 { | |
2540 /* Visual is before curwin->w_cursor */ | |
2541 top = &VIsual; | |
2542 bot = &curwin->w_cursor; | |
2543 } | |
2544 if (lnum >= top->lnum | |
2545 && lnume <= bot->lnum | |
2546 && (VIsual_mode != 'v' | |
2547 || ((lnum > top->lnum | |
2548 || (lnum == top->lnum | |
2549 && top->col == 0)) | |
2550 && (lnume < bot->lnum | |
2551 || (lnume == bot->lnum | |
2552 && (bot->col - (*p_sel == 'e')) | |
1883 | 2553 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2554 { |
2555 if (VIsual_mode == Ctrl_V) | |
2556 { | |
2557 /* Visual block mode: highlight the chars part of the block */ | |
2558 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2559 { | |
3040 | 2560 if (wp->w_old_cursor_lcol != MAXCOL |
2561 && wp->w_old_cursor_lcol + txtcol | |
2562 < (colnr_T)W_WIDTH(wp)) | |
7 | 2563 len = wp->w_old_cursor_lcol; |
2564 else | |
2565 len = W_WIDTH(wp) - txtcol; | |
2566 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2567 len - (int)wp->w_old_cursor_fcol); |
7 | 2568 } |
2569 } | |
2570 else | |
216 | 2571 { |
7 | 2572 /* Set all attributes of the text */ |
216 | 2573 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2574 } | |
7 | 2575 } |
2576 } | |
2577 #endif | |
2578 | |
743 | 2579 #ifdef FEAT_SYN_HL |
2580 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2581 if (wp->w_p_cuc) |
2582 { | |
2583 txtcol += wp->w_virtcol; | |
2584 if (wp->w_p_wrap) | |
2585 txtcol -= wp->w_skipcol; | |
2586 else | |
2587 txtcol -= wp->w_leftcol; | |
2588 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2589 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2590 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2591 } | |
743 | 2592 #endif |
7 | 2593 |
2594 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2595 (int)W_WIDTH(wp), FALSE); | |
2596 | |
2597 /* | |
2598 * Update w_cline_height and w_cline_folded if the cursor line was | |
2599 * updated (saves a call to plines() later). | |
2600 */ | |
2601 if (wp == curwin | |
2602 && lnum <= curwin->w_cursor.lnum | |
2603 && lnume >= curwin->w_cursor.lnum) | |
2604 { | |
2605 curwin->w_cline_row = row; | |
2606 curwin->w_cline_height = 1; | |
2607 curwin->w_cline_folded = TRUE; | |
2608 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2609 } | |
2610 } | |
2611 | |
2612 /* | |
2613 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2614 */ | |
2615 static void | |
2616 copy_text_attr(off, buf, len, attr) | |
2617 int off; | |
2618 char_u *buf; | |
2619 int len; | |
2620 int attr; | |
2621 { | |
216 | 2622 int i; |
2623 | |
7 | 2624 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2625 # ifdef FEAT_MBYTE | |
2626 if (enc_utf8) | |
2627 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2628 # endif | |
216 | 2629 for (i = 0; i < len; ++i) |
2630 ScreenAttrs[off + i] = attr; | |
7 | 2631 } |
2632 | |
2633 /* | |
2634 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2635 * Only to be called when 'foldcolumn' > 0. |
7 | 2636 */ |
2637 static void | |
2638 fill_foldcolumn(p, wp, closed, lnum) | |
2639 char_u *p; | |
2640 win_T *wp; | |
2641 int closed; /* TRUE of FALSE */ | |
2642 linenr_T lnum; /* current line number */ | |
2643 { | |
2644 int i = 0; | |
2645 int level; | |
2646 int first_level; | |
519 | 2647 int empty; |
7 | 2648 |
2649 /* Init to all spaces. */ | |
2650 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2651 | |
2652 level = win_foldinfo.fi_level; | |
2653 if (level > 0) | |
2654 { | |
519 | 2655 /* If there is only one column put more info in it. */ |
2656 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2657 | |
7 | 2658 /* If the column is too narrow, we start at the lowest level that |
2659 * fits and use numbers to indicated the depth. */ | |
519 | 2660 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2661 if (first_level < 1) |
2662 first_level = 1; | |
2663 | |
519 | 2664 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2665 { |
2666 if (win_foldinfo.fi_lnum == lnum | |
2667 && first_level + i >= win_foldinfo.fi_low_level) | |
2668 p[i] = '-'; | |
2669 else if (first_level == 1) | |
2670 p[i] = '|'; | |
2671 else if (first_level + i <= 9) | |
2672 p[i] = '0' + first_level + i; | |
2673 else | |
2674 p[i] = '>'; | |
2675 if (first_level + i == level) | |
2676 break; | |
2677 } | |
2678 } | |
2679 if (closed) | |
548 | 2680 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2681 } |
2682 #endif /* FEAT_FOLDING */ | |
2683 | |
2684 /* | |
2685 * Display line "lnum" of window 'wp' on the screen. | |
2686 * Start at row "startrow", stop when "endrow" is reached. | |
2687 * wp->w_virtcol needs to be valid. | |
2688 * | |
2689 * Return the number of last row the line occupies. | |
2690 */ | |
2691 static int | |
625 | 2692 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2693 win_T *wp; |
2694 linenr_T lnum; | |
2695 int startrow; | |
2696 int endrow; | |
1883 | 2697 int nochange UNUSED; /* not updating for changed text */ |
7 | 2698 { |
2699 int col; /* visual column on screen */ | |
2700 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2701 int c = 0; /* init for GCC */ | |
2702 long vcol = 0; /* virtual column (for tabs) */ | |
2703 long vcol_prev = -1; /* "vcol" of previous character */ | |
2704 char_u *line; /* current line */ | |
2705 char_u *ptr; /* current position in "line" */ | |
2706 int row; /* row in the window, excl w_winrow */ | |
2707 int screen_row; /* row on the screen, incl w_winrow */ | |
2708 | |
2709 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2710 int n_extra = 0; /* number of extra chars */ | |
1340 | 2711 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2712 int c_extra = NUL; /* extra chars, all the same */ |
2713 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2714 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2715 displaying lcs_eol at end-of-line */ | |
2716 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2717 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2718 | |
2719 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2720 int saved_n_extra = 0; | |
2721 char_u *saved_p_extra = NULL; | |
2722 int saved_c_extra = 0; | |
2723 int saved_char_attr = 0; | |
2724 | |
2725 int n_attr = 0; /* chars with special attr */ | |
2726 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2727 int n_attr3 = 0; /* chars with overruling special attr */ | |
2728 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2729 | |
2730 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2731 | |
2732 int fromcol, tocol; /* start/end of inverting */ | |
2733 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2734 int noinvcur = FALSE; /* don't invert the cursor */ | |
2735 #ifdef FEAT_VISUAL | |
2736 pos_T *top, *bot; | |
1813 | 2737 int lnum_in_visual_area = FALSE; |
7 | 2738 #endif |
2739 pos_T pos; | |
2740 long v; | |
2741 | |
2742 int char_attr = 0; /* attributes for next character */ | |
674 | 2743 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2744 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2745 in this line */ | |
2746 int attr = 0; /* attributes for area highlighting */ | |
2747 int area_attr = 0; /* attributes desired by highlighting */ | |
2748 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2749 #ifdef FEAT_SYN_HL | |
743 | 2750 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2751 int syntax_attr = 0; /* attributes desired by syntax */ |
2752 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2753 int save_did_emsg; | |
1437 | 2754 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
|
2755 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2756 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2757 #endif |
2758 #ifdef FEAT_SPELL | |
221 | 2759 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2760 # define SPWORDLEN 150 |
2761 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2762 int nextlinecol = 0; /* column where nextline[] starts */ |
2763 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2764 starts */ |
221 | 2765 int spell_attr = 0; /* attributes desired by spelling */ |
2766 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2767 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2768 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2769 * there are no spell errors */ |
386 | 2770 static int cap_col = -1; /* column to check for Cap word */ |
2771 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2772 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2773 #endif |
2774 int extra_check; /* has syntax or linebreak */ | |
2775 #ifdef FEAT_MBYTE | |
2776 int multi_attr = 0; /* attributes desired by multibyte */ | |
2777 int mb_l = 1; /* multi-byte byte length */ | |
2778 int mb_c = 0; /* decoded multi-byte character */ | |
2779 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2780 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2781 #endif |
2782 #ifdef FEAT_DIFF | |
2783 int filler_lines; /* nr of filler lines to be drawn */ | |
2784 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2785 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2786 int change_start = MAXCOL; /* first col of changed area */ |
2787 int change_end = -1; /* last col of changed area */ | |
2788 #endif | |
2789 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2790 #ifdef FEAT_LINEBREAK | |
2791 int need_showbreak = FALSE; | |
2792 #endif | |
910 | 2793 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2794 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2795 # define LINE_ATTR |
1536 | 2796 int line_attr = 0; /* attribute for the whole line */ |
7 | 2797 #endif |
2798 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2799 matchitem_T *cur; /* points to the match list */ |
2800 match_T *shl; /* points to search_hl or a match */ | |
2801 int shl_flag; /* flag to indicate whether search_hl | |
2802 has been processed or not */ | |
2803 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2804 equals startcol of search_hl or one | |
2805 of the matches */ | |
7 | 2806 #endif |
2807 #ifdef FEAT_ARABIC | |
2808 int prev_c = 0; /* previous Arabic character */ | |
2809 int prev_c1 = 0; /* first composing char for prev_c */ | |
2810 #endif | |
910 | 2811 #if defined(LINE_ATTR) |
867 | 2812 int did_line_attr = 0; |
2813 #endif | |
7 | 2814 |
2815 /* draw_state: items that are drawn in sequence: */ | |
2816 #define WL_START 0 /* nothing done yet */ | |
2817 #ifdef FEAT_CMDWIN | |
2818 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2819 #else | |
2820 # define WL_CMDLINE WL_START | |
2821 #endif | |
2822 #ifdef FEAT_FOLDING | |
2823 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2824 #else | |
2825 # define WL_FOLD WL_CMDLINE | |
2826 #endif | |
2827 #ifdef FEAT_SIGNS | |
2828 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2829 #else | |
2830 # define WL_SIGN WL_FOLD /* column for signs */ | |
2831 #endif | |
2832 #define WL_NR WL_SIGN + 1 /* line number */ | |
2833 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2834 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2835 #else | |
2836 # define WL_SBR WL_NR | |
2837 #endif | |
2838 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2839 int draw_state = WL_START; /* what to draw next */ | |
574 | 2840 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2841 int feedback_col = 0; |
2842 int feedback_old_attr = -1; | |
2843 #endif | |
2844 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2845 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2846 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
|
2847 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
|
2848 int prev_syntax_id = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2849 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2850 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2851 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
|
2852 wrapping */ |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2400
diff
changeset
|
2853 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
|
2854 int did_wcol = FALSE; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2855 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2856 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2857 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2858 #endif |
7 | 2859 |
2860 if (startrow > endrow) /* past the end already! */ | |
2861 return startrow; | |
2862 | |
2863 row = startrow; | |
2864 screen_row = row + W_WINROW(wp); | |
2865 | |
2866 /* | |
2867 * To speed up the loop below, set extra_check when there is linebreak, | |
2868 * trailing white space and/or syntax processing to be done. | |
2869 */ | |
2870 #ifdef FEAT_LINEBREAK | |
2871 extra_check = wp->w_p_lbr; | |
2872 #else | |
2873 extra_check = 0; | |
2874 #endif | |
2875 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2876 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2877 { |
2878 /* Prepare for syntax highlighting in this line. When there is an | |
2879 * error, stop syntax highlighting. */ | |
2880 save_did_emsg = did_emsg; | |
2881 did_emsg = FALSE; | |
2882 syntax_start(wp, lnum); | |
2883 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2884 wp->w_s->b_syn_error = TRUE; |
7 | 2885 else |
2886 { | |
2887 did_emsg = save_did_emsg; | |
2888 has_syntax = TRUE; | |
2889 extra_check = TRUE; | |
2890 } | |
2891 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2892 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2893 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2894 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2895 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2896 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 2897 #endif |
2898 | |
2899 #ifdef FEAT_SPELL | |
258 | 2900 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2901 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2902 && 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
|
2903 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2904 { |
2905 /* Prepare for spell checking. */ | |
2906 has_spell = TRUE; | |
2907 extra_check = TRUE; | |
348 | 2908 |
2909 /* Get the start of the next line, so that words that wrap to the next | |
2910 * line are found too: "et<line-break>al.". | |
2911 * Trick: skip a few chars for C/shell/Vim comments */ | |
2912 nextline[SPWORDLEN] = NUL; | |
2913 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2914 { | |
2915 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2916 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2917 } | |
2918 | |
2919 /* When a word wrapped from the previous line the start of the current | |
2920 * line is valid. */ | |
2921 if (lnum == checked_lnum) | |
2922 cur_checked_col = checked_col; | |
2923 checked_lnum = 0; | |
386 | 2924 |
2925 /* When there was a sentence end in the previous line may require a | |
2926 * word starting with capital in this line. In line 1 always check | |
2927 * the first word. */ | |
2928 if (lnum != capcol_lnum) | |
2929 cap_col = -1; | |
2930 if (lnum == 1) | |
2931 cap_col = 0; | |
2932 capcol_lnum = 0; | |
221 | 2933 } |
7 | 2934 #endif |
2935 | |
2936 /* | |
2937 * handle visual active in this window | |
2938 */ | |
2939 fromcol = -10; | |
2940 tocol = MAXCOL; | |
2941 #ifdef FEAT_VISUAL | |
2942 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2943 { | |
2944 /* Visual is after curwin->w_cursor */ | |
2945 if (ltoreq(curwin->w_cursor, VIsual)) | |
2946 { | |
2947 top = &curwin->w_cursor; | |
2948 bot = &VIsual; | |
2949 } | |
2950 else /* Visual is before curwin->w_cursor */ | |
2951 { | |
2952 top = &VIsual; | |
2953 bot = &curwin->w_cursor; | |
2954 } | |
1813 | 2955 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2956 if (VIsual_mode == Ctrl_V) /* block mode */ |
2957 { | |
1813 | 2958 if (lnum_in_visual_area) |
7 | 2959 { |
2960 fromcol = wp->w_old_cursor_fcol; | |
2961 tocol = wp->w_old_cursor_lcol; | |
2962 } | |
2963 } | |
2964 else /* non-block mode */ | |
2965 { | |
2966 if (lnum > top->lnum && lnum <= bot->lnum) | |
2967 fromcol = 0; | |
2968 else if (lnum == top->lnum) | |
2969 { | |
2970 if (VIsual_mode == 'V') /* linewise */ | |
2971 fromcol = 0; | |
2972 else | |
2973 { | |
2974 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2975 if (gchar_pos(top) == NUL) | |
2976 tocol = fromcol + 1; | |
2977 } | |
2978 } | |
2979 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2980 { | |
2981 if (*p_sel == 'e' && bot->col == 0 | |
2982 #ifdef FEAT_VIRTUALEDIT | |
2983 && bot->coladd == 0 | |
2984 #endif | |
2985 ) | |
2986 { | |
2987 fromcol = -10; | |
2988 tocol = MAXCOL; | |
2989 } | |
36 | 2990 else if (bot->col == MAXCOL) |
2991 tocol = MAXCOL; | |
7 | 2992 else |
2993 { | |
2994 pos = *bot; | |
2995 if (*p_sel == 'e') | |
2996 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2997 else | |
2998 { | |
2999 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
3000 ++tocol; | |
3001 } | |
3002 } | |
3003 } | |
3004 } | |
3005 | |
3006 #ifndef MSDOS | |
3007 /* Check if the character under the cursor should not be inverted */ | |
3008 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
3009 # ifdef FEAT_GUI | |
3010 && !gui.in_use | |
3011 # endif | |
3012 ) | |
3013 noinvcur = TRUE; | |
3014 #endif | |
3015 | |
3016 /* if inverting in this line set area_highlighting */ | |
3017 if (fromcol >= 0) | |
3018 { | |
3019 area_highlighting = TRUE; | |
3020 attr = hl_attr(HLF_V); | |
3021 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
3674 | 3022 if ((clip_star.available && !clip_star.owned |
3023 && clip_isautosel_star()) | |
3024 || (clip_plus.available && !clip_plus.owned | |
3025 && clip_isautosel_plus())) | |
7 | 3026 attr = hl_attr(HLF_VNC); |
3027 #endif | |
3028 } | |
3029 } | |
3030 | |
3031 /* | |
674 | 3032 * handle 'incsearch' and ":s///c" highlighting |
7 | 3033 */ |
3034 else | |
3035 #endif /* FEAT_VISUAL */ | |
3036 if (highlight_match | |
3037 && wp == curwin | |
3038 && lnum >= curwin->w_cursor.lnum | |
3039 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
3040 { | |
3041 if (lnum == curwin->w_cursor.lnum) | |
3042 getvcol(curwin, &(curwin->w_cursor), | |
3043 (colnr_T *)&fromcol, NULL, NULL); | |
3044 else | |
3045 fromcol = 0; | |
3046 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
3047 { | |
3048 pos.lnum = lnum; | |
3049 pos.col = search_match_endcol; | |
3050 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3051 } | |
3052 else | |
3053 tocol = MAXCOL; | |
1850 | 3054 /* do at least one character; happens when past end of line */ |
3055 if (fromcol == tocol) | |
3056 tocol = fromcol + 1; | |
7 | 3057 area_highlighting = TRUE; |
3058 attr = hl_attr(HLF_I); | |
3059 } | |
3060 | |
3061 #ifdef FEAT_DIFF | |
3062 filler_lines = diff_check(wp, lnum); | |
3063 if (filler_lines < 0) | |
3064 { | |
3065 if (filler_lines == -1) | |
3066 { | |
3067 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
3068 diff_hlf = HLF_ADD; /* added line */ | |
3069 else if (change_start == 0) | |
3070 diff_hlf = HLF_TXD; /* changed text */ | |
3071 else | |
3072 diff_hlf = HLF_CHD; /* changed line */ | |
3073 } | |
3074 else | |
3075 diff_hlf = HLF_ADD; /* added line */ | |
3076 filler_lines = 0; | |
3077 area_highlighting = TRUE; | |
3078 } | |
3079 if (lnum == wp->w_topline) | |
3080 filler_lines = wp->w_topfill; | |
3081 filler_todo = filler_lines; | |
3082 #endif | |
3083 | |
3084 #ifdef LINE_ATTR | |
3085 # ifdef FEAT_SIGNS | |
3086 /* If this line has a sign with line highlighting set line_attr. */ | |
3087 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3088 if (v != 0) | |
3089 line_attr = sign_get_attr((int)v, TRUE); | |
3090 # endif | |
3091 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3092 /* Highlight the current line in the quickfix window. */ | |
644 | 3093 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3094 line_attr = hl_attr(HLF_L); |
3095 # endif | |
3096 if (line_attr != 0) | |
3097 area_highlighting = TRUE; | |
3098 #endif | |
3099 | |
3100 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3101 ptr = line; | |
3102 | |
743 | 3103 #ifdef FEAT_SPELL |
348 | 3104 if (has_spell) |
3105 { | |
386 | 3106 /* For checking first word with a capital skip white space. */ |
3107 if (cap_col == 0) | |
835 | 3108 cap_col = (int)(skipwhite(line) - line); |
386 | 3109 |
348 | 3110 /* To be able to spell-check over line boundaries copy the end of the |
3111 * current line into nextline[]. Above the start of the next line was | |
3112 * copied to nextline[SPWORDLEN]. */ | |
3113 if (nextline[SPWORDLEN] == NUL) | |
3114 { | |
3115 /* No next line or it is empty. */ | |
3116 nextlinecol = MAXCOL; | |
3117 nextline_idx = 0; | |
3118 } | |
3119 else | |
3120 { | |
835 | 3121 v = (long)STRLEN(line); |
348 | 3122 if (v < SPWORDLEN) |
3123 { | |
3124 /* Short line, use it completely and append the start of the | |
3125 * next line. */ | |
3126 nextlinecol = 0; | |
3127 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3128 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3129 nextline_idx = v + 1; |
3130 } | |
3131 else | |
3132 { | |
3133 /* Long line, use only the last SPWORDLEN bytes. */ | |
3134 nextlinecol = v - SPWORDLEN; | |
3135 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3136 nextline_idx = SPWORDLEN + 1; | |
3137 } | |
3138 } | |
3139 } | |
3140 #endif | |
3141 | |
7 | 3142 /* find start of trailing whitespace */ |
3143 if (wp->w_p_list && lcs_trail) | |
3144 { | |
3145 trailcol = (colnr_T)STRLEN(ptr); | |
3146 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3147 --trailcol; | |
3148 trailcol += (colnr_T) (ptr - line); | |
3149 extra_check = TRUE; | |
3150 } | |
3151 | |
3152 /* | |
3153 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3154 * first character to be displayed. | |
3155 */ | |
3156 if (wp->w_p_wrap) | |
3157 v = wp->w_skipcol; | |
3158 else | |
3159 v = wp->w_leftcol; | |
3160 if (v > 0) | |
3161 { | |
3162 #ifdef FEAT_MBYTE | |
3163 char_u *prev_ptr = ptr; | |
3164 #endif | |
3165 while (vcol < v && *ptr != NUL) | |
3166 { | |
3167 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3168 vcol += c; | |
3169 #ifdef FEAT_MBYTE | |
3170 prev_ptr = ptr; | |
39 | 3171 #endif |
3172 mb_ptr_adv(ptr); | |
7 | 3173 } |
3174 | |
1984 | 3175 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3176 /* When: | |
3177 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3178 * - 'colorcolumn' is set, or |
1984 | 3179 * - 'virtualedit' is set, or |
3180 * - the visual mode is active, | |
3181 * the end of the line may be before the start of the displayed part. | |
3182 */ | |
3183 if (vcol < v && ( | |
3184 # ifdef FEAT_SYN_HL | |
3185 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3186 || draw_color_col |
1984 | 3187 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3188 || | |
3189 # endif | |
3190 # endif | |
3191 # ifdef FEAT_VIRTUALEDIT | |
3192 virtual_active() | |
3193 # ifdef FEAT_VISUAL | |
3194 || | |
3195 # endif | |
3196 # endif | |
3197 # ifdef FEAT_VISUAL | |
3198 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3199 # endif | |
3200 )) | |
3201 { | |
7 | 3202 vcol = v; |
1984 | 3203 } |
7 | 3204 #endif |
3205 | |
3206 /* Handle a character that's not completely on the screen: Put ptr at | |
3207 * that character but skip the first few screen characters. */ | |
3208 if (vcol > v) | |
3209 { | |
3210 vcol -= c; | |
3211 #ifdef FEAT_MBYTE | |
3212 ptr = prev_ptr; | |
3213 #else | |
3214 --ptr; | |
3215 #endif | |
3216 n_skip = v - vcol; | |
3217 } | |
3218 | |
3219 /* | |
3220 * Adjust for when the inverted text is before the screen, | |
3221 * and when the start of the inverted text is before the screen. | |
3222 */ | |
3223 if (tocol <= vcol) | |
3224 fromcol = 0; | |
3225 else if (fromcol >= 0 && fromcol < vcol) | |
3226 fromcol = vcol; | |
3227 | |
3228 #ifdef FEAT_LINEBREAK | |
3229 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3230 if (wp->w_p_wrap) | |
3231 need_showbreak = TRUE; | |
3232 #endif | |
743 | 3233 #ifdef FEAT_SPELL |
499 | 3234 /* When spell checking a word we need to figure out the start of the |
3235 * word and if it's badly spelled or not. */ | |
3236 if (has_spell) | |
3237 { | |
3238 int len; | |
1536 | 3239 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3240 hlf_T spell_hlf = HLF_COUNT; |
499 | 3241 |
3242 pos = wp->w_cursor; | |
3243 wp->w_cursor.lnum = lnum; | |
1536 | 3244 wp->w_cursor.col = linecol; |
534 | 3245 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3246 |
3247 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3248 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3249 ptr = line + linecol; | |
3250 | |
530 | 3251 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3252 { |
3253 /* no bad word found at line start, don't check until end of a | |
3254 * word */ | |
534 | 3255 spell_hlf = HLF_COUNT; |
3572 | 3256 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
499 | 3257 } |
3258 else | |
534 | 3259 { |
499 | 3260 /* bad word found, use attributes until end of word */ |
3261 word_end = wp->w_cursor.col + len + 1; | |
3262 | |
534 | 3263 /* Turn index into actual attributes. */ |
3264 if (spell_hlf != HLF_COUNT) | |
3265 spell_attr = highlight_attr[spell_hlf]; | |
3266 } | |
499 | 3267 wp->w_cursor = pos; |
501 | 3268 |
743 | 3269 # ifdef FEAT_SYN_HL |
501 | 3270 /* Need to restart syntax highlighting for this line. */ |
3271 if (has_syntax) | |
3272 syntax_start(wp, lnum); | |
743 | 3273 # endif |
499 | 3274 } |
3275 #endif | |
7 | 3276 } |
3277 | |
3278 /* | |
3279 * Correct highlighting for cursor that can't be disabled. | |
3280 * Avoids having to check this for each character. | |
3281 */ | |
3282 if (fromcol >= 0) | |
3283 { | |
3284 if (noinvcur) | |
3285 { | |
3286 if ((colnr_T)fromcol == wp->w_virtcol) | |
3287 { | |
3288 /* highlighting starts at cursor, let it start just after the | |
3289 * cursor */ | |
3290 fromcol_prev = fromcol; | |
3291 fromcol = -1; | |
3292 } | |
3293 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3294 /* restart highlighting after the cursor */ | |
3295 fromcol_prev = wp->w_virtcol; | |
3296 } | |
3297 if (fromcol >= tocol) | |
3298 fromcol = -1; | |
3299 } | |
3300 | |
3301 #ifdef FEAT_SEARCH_EXTRA | |
3302 /* | |
1326 | 3303 * Handle highlighting the last used search pattern and matches. |
3304 * Do this for both search_hl and the match list. | |
7 | 3305 */ |
1326 | 3306 cur = wp->w_match_head; |
3307 shl_flag = FALSE; | |
3308 while (cur != NULL || shl_flag == FALSE) | |
3309 { | |
3310 if (shl_flag == FALSE) | |
3311 { | |
3312 shl = &search_hl; | |
3313 shl_flag = TRUE; | |
3314 } | |
3315 else | |
3316 shl = &cur->hl; | |
36 | 3317 shl->startcol = MAXCOL; |
3318 shl->endcol = MAXCOL; | |
7 | 3319 shl->attr_cur = 0; |
3320 if (shl->rm.regprog != NULL) | |
3321 { | |
3322 v = (long)(ptr - line); | |
3323 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3324 | |
3325 /* Need to get the line again, a multi-line regexp may have made it | |
3326 * invalid. */ | |
3327 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3328 ptr = line + v; | |
3329 | |
3330 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3331 { | |
3332 if (shl->lnum == lnum) | |
36 | 3333 shl->startcol = shl->rm.startpos[0].col; |
7 | 3334 else |
36 | 3335 shl->startcol = 0; |
7 | 3336 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3337 - shl->rm.startpos[0].lnum) | |
36 | 3338 shl->endcol = shl->rm.endpos[0].col; |
7 | 3339 else |
36 | 3340 shl->endcol = MAXCOL; |
7 | 3341 /* Highlight one character for an empty match. */ |
36 | 3342 if (shl->startcol == shl->endcol) |
7 | 3343 { |
3344 #ifdef FEAT_MBYTE | |
36 | 3345 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3346 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3347 else |
3348 #endif | |
36 | 3349 ++shl->endcol; |
7 | 3350 } |
36 | 3351 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3352 { |
3353 shl->attr_cur = shl->attr; | |
3354 search_attr = shl->attr; | |
3355 } | |
3356 area_highlighting = TRUE; | |
3357 } | |
3358 } | |
1326 | 3359 if (shl != &search_hl && cur != NULL) |
3360 cur = cur->next; | |
7 | 3361 } |
3362 #endif | |
3363 | |
743 | 3364 #ifdef FEAT_SYN_HL |
818 | 3365 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3366 * active, because it's not clear what is selected then. */ | |
3367 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3368 { |
3369 line_attr = hl_attr(HLF_CUL); | |
3370 area_highlighting = TRUE; | |
3371 } | |
3372 #endif | |
3373 | |
504 | 3374 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3375 col = 0; |
3376 #ifdef FEAT_RIGHTLEFT | |
3377 if (wp->w_p_rl) | |
3378 { | |
3379 /* Rightleft window: process the text in the normal direction, but put | |
3380 * it in current_ScreenLine[] from right to left. Start at the | |
3381 * rightmost column of the window. */ | |
3382 col = W_WIDTH(wp) - 1; | |
3383 off += col; | |
3384 } | |
3385 #endif | |
3386 | |
3387 /* | |
3388 * Repeat for the whole displayed line. | |
3389 */ | |
3390 for (;;) | |
3391 { | |
3392 /* Skip this quickly when working on the text. */ | |
3393 if (draw_state != WL_LINE) | |
3394 { | |
3395 #ifdef FEAT_CMDWIN | |
3396 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3397 { | |
3398 draw_state = WL_CMDLINE; | |
3399 if (cmdwin_type != 0 && wp == curwin) | |
3400 { | |
3401 /* Draw the cmdline character. */ | |
3402 n_extra = 1; | |
1340 | 3403 c_extra = cmdwin_type; |
7 | 3404 char_attr = hl_attr(HLF_AT); |
3405 } | |
3406 } | |
3407 #endif | |
3408 | |
3409 #ifdef FEAT_FOLDING | |
3410 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3411 { | |
3412 draw_state = WL_FOLD; | |
3413 if (wp->w_p_fdc > 0) | |
3414 { | |
3415 /* Draw the 'foldcolumn'. */ | |
3416 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3417 n_extra = wp->w_p_fdc; | |
3418 p_extra = extra; | |
1340 | 3419 p_extra[n_extra] = NUL; |
7 | 3420 c_extra = NUL; |
3421 char_attr = hl_attr(HLF_FC); | |
3422 } | |
3423 } | |
3424 #endif | |
3425 | |
3426 #ifdef FEAT_SIGNS | |
3427 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3428 { | |
3429 draw_state = WL_SIGN; | |
3430 /* Show the sign column when there are any signs in this | |
3431 * buffer or when using Netbeans. */ | |
3432 if (draw_signcolumn(wp) | |
3433 # ifdef FEAT_DIFF | |
3434 && filler_todo <= 0 | |
3435 # endif | |
3436 ) | |
3437 { | |
2661 | 3438 int text_sign; |
7 | 3439 # ifdef FEAT_SIGN_ICONS |
2661 | 3440 int icon_sign; |
7 | 3441 # endif |
3442 | |
3443 /* Draw two cells with the sign value or blank. */ | |
3444 c_extra = ' '; | |
3445 char_attr = hl_attr(HLF_SC); | |
3446 n_extra = 2; | |
3447 | |
3448 if (row == startrow) | |
3449 { | |
3450 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3451 SIGN_TEXT); | |
3452 # ifdef FEAT_SIGN_ICONS | |
3453 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3454 SIGN_ICON); | |
3455 if (gui.in_use && icon_sign != 0) | |
3456 { | |
3457 /* Use the image in this position. */ | |
3458 c_extra = SIGN_BYTE; | |
3459 # ifdef FEAT_NETBEANS_INTG | |
3460 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3461 c_extra = MULTISIGN_BYTE; | |
3462 # endif | |
3463 char_attr = icon_sign; | |
3464 } | |
3465 else | |
3466 # endif | |
3467 if (text_sign != 0) | |
3468 { | |
3469 p_extra = sign_get_text(text_sign); | |
3470 if (p_extra != NULL) | |
3471 { | |
3472 c_extra = NUL; | |
835 | 3473 n_extra = (int)STRLEN(p_extra); |
7 | 3474 } |
3475 char_attr = sign_get_attr(text_sign, FALSE); | |
3476 } | |
3477 } | |
3478 } | |
3479 } | |
3480 #endif | |
3481 | |
3482 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3483 { | |
3484 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3485 /* 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
|
3486 * 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
|
3487 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3488 && (row == startrow |
3489 #ifdef FEAT_DIFF | |
3490 + filler_lines | |
3491 #endif | |
3492 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3493 { | |
3494 /* Draw the line number (empty space after wrapping). */ | |
3495 if (row == startrow | |
3496 #ifdef FEAT_DIFF | |
3497 + filler_lines | |
3498 #endif | |
3499 ) | |
3500 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3501 long num; |
4065 | 3502 char *fmt = "%*ld "; |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3503 |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3504 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
|
3505 /* 'number' + 'norelativenumber' */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3506 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3507 else |
4065 | 3508 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3509 /* 'relativenumber', don't use negative numbers */ |
2675 | 3510 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
|
3511 if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
4065 | 3512 { |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3513 /* 'number' + 'relativenumber' */ |
4065 | 3514 num = lnum; |
3515 fmt = "%-*ld "; | |
3516 } | |
3517 } | |
3518 | |
3519 sprintf((char *)extra, fmt, | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3520 number_width(wp), num); |
7 | 3521 if (wp->w_skipcol > 0) |
3522 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3523 *p_extra = '-'; | |
3524 #ifdef FEAT_RIGHTLEFT | |
3525 if (wp->w_p_rl) /* reverse line numbers */ | |
3526 rl_mirror(extra); | |
3527 #endif | |
3528 p_extra = extra; | |
3529 c_extra = NUL; | |
3530 } | |
3531 else | |
3532 c_extra = ' '; | |
13 | 3533 n_extra = number_width(wp) + 1; |
7 | 3534 char_attr = hl_attr(HLF_N); |
743 | 3535 #ifdef FEAT_SYN_HL |
3536 /* When 'cursorline' is set highlight the line number of | |
3427 | 3537 * the current line differently. |
3538 * TODO: Can we use CursorLine instead of CursorLineNr | |
3539 * when CursorLineNr isn't set? */ | |
4065 | 3540 if ((wp->w_p_cul || wp->w_p_rnu) |
3541 && lnum == wp->w_cursor.lnum) | |
3427 | 3542 char_attr = hl_attr(HLF_CLN); |
743 | 3543 #endif |
7 | 3544 } |
3545 } | |
3546 | |
3547 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3548 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3549 { | |
3550 draw_state = WL_SBR; | |
3551 # ifdef FEAT_DIFF | |
3552 if (filler_todo > 0) | |
3553 { | |
3554 /* Draw "deleted" diff line(s). */ | |
3555 if (char2cells(fill_diff) > 1) | |
3556 c_extra = '-'; | |
3557 else | |
3558 c_extra = fill_diff; | |
3559 # ifdef FEAT_RIGHTLEFT | |
3560 if (wp->w_p_rl) | |
3561 n_extra = col + 1; | |
3562 else | |
3563 # endif | |
3564 n_extra = W_WIDTH(wp) - col; | |
3565 char_attr = hl_attr(HLF_DED); | |
3566 } | |
3567 # endif | |
3568 # ifdef FEAT_LINEBREAK | |
3569 if (*p_sbr != NUL && need_showbreak) | |
3570 { | |
3571 /* Draw 'showbreak' at the start of each broken line. */ | |
3572 p_extra = p_sbr; | |
3573 c_extra = NUL; | |
3574 n_extra = (int)STRLEN(p_sbr); | |
3575 char_attr = hl_attr(HLF_AT); | |
3576 need_showbreak = FALSE; | |
3577 /* Correct end of highlighted area for 'showbreak', | |
3578 * required when 'linebreak' is also set. */ | |
3579 if (tocol == vcol) | |
3580 tocol += n_extra; | |
3581 } | |
3582 # endif | |
3583 } | |
3584 #endif | |
3585 | |
3586 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3587 { | |
3588 draw_state = WL_LINE; | |
3589 if (saved_n_extra) | |
3590 { | |
3591 /* Continue item from end of wrapped line. */ | |
3592 n_extra = saved_n_extra; | |
3593 c_extra = saved_c_extra; | |
3594 p_extra = saved_p_extra; | |
3595 char_attr = saved_char_attr; | |
3596 } | |
3597 else | |
3598 char_attr = 0; | |
3599 } | |
3600 } | |
3601 | |
3602 /* When still displaying '$' of change command, stop at cursor */ | |
3318 | 3603 if (dollar_vcol >= 0 && wp == curwin |
819 | 3604 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
7 | 3605 #ifdef FEAT_DIFF |
3606 && filler_todo <= 0 | |
3607 #endif | |
3608 ) | |
3609 { | |
3610 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3611 wp->w_p_rl); | |
819 | 3612 /* Pretend we have finished updating the window. Except when |
3613 * 'cursorcolumn' is set. */ | |
3614 #ifdef FEAT_SYN_HL | |
3615 if (wp->w_p_cuc) | |
3616 row = wp->w_cline_row + wp->w_cline_height; | |
3617 else | |
3618 #endif | |
3619 row = wp->w_height; | |
7 | 3620 break; |
3621 } | |
3622 | |
3623 if (draw_state == WL_LINE && area_highlighting) | |
3624 { | |
3625 /* handle Visual or match highlighting in this line */ | |
3626 if (vcol == fromcol | |
3627 #ifdef FEAT_MBYTE | |
3628 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3629 && (*mb_ptr2cells)(ptr) > 1) | |
3630 #endif | |
3631 || ((int)vcol_prev == fromcol_prev | |
1814 | 3632 && vcol_prev < vcol /* not at margin */ |
7 | 3633 && vcol < tocol)) |
3634 area_attr = attr; /* start highlighting */ | |
3635 else if (area_attr != 0 | |
3636 && (vcol == tocol | |
3637 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3638 area_attr = 0; /* stop highlighting */ | |
3639 | |
3640 #ifdef FEAT_SEARCH_EXTRA | |
3641 if (!n_extra) | |
3642 { | |
3643 /* | |
3644 * Check for start/end of search pattern match. | |
3645 * After end, check for start/end of next match. | |
3646 * When another match, have to check for start again. | |
3647 * Watch out for matching an empty string! | |
1326 | 3648 * Do this for 'search_hl' and the match list (ordered by |
3649 * priority). | |
7 | 3650 */ |
36 | 3651 v = (long)(ptr - line); |
1326 | 3652 cur = wp->w_match_head; |
3653 shl_flag = FALSE; | |
3654 while (cur != NULL || shl_flag == FALSE) | |
3655 { | |
3656 if (shl_flag == FALSE | |
3657 && ((cur != NULL | |
3658 && cur->priority > SEARCH_HL_PRIORITY) | |
3659 || cur == NULL)) | |
3660 { | |
3661 shl = &search_hl; | |
3662 shl_flag = TRUE; | |
3663 } | |
3664 else | |
3665 shl = &cur->hl; | |
7 | 3666 while (shl->rm.regprog != NULL) |
3667 { | |
36 | 3668 if (shl->startcol != MAXCOL |
3669 && v >= (long)shl->startcol | |
3670 && v < (long)shl->endcol) | |
7 | 3671 { |
3672 shl->attr_cur = shl->attr; | |
3673 } | |
36 | 3674 else if (v == (long)shl->endcol) |
7 | 3675 { |
3676 shl->attr_cur = 0; | |
3677 | |
3678 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3679 | |
3680 /* Need to get the line again, a multi-line regexp | |
3681 * may have made it invalid. */ | |
3682 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3683 ptr = line + v; | |
3684 | |
3685 if (shl->lnum == lnum) | |
3686 { | |
36 | 3687 shl->startcol = shl->rm.startpos[0].col; |
7 | 3688 if (shl->rm.endpos[0].lnum == 0) |
36 | 3689 shl->endcol = shl->rm.endpos[0].col; |
7 | 3690 else |
36 | 3691 shl->endcol = MAXCOL; |
3692 | |
3693 if (shl->startcol == shl->endcol) | |
7 | 3694 { |
3695 /* highlight empty match, try again after | |
3696 * it */ | |
3697 #ifdef FEAT_MBYTE | |
3698 if (has_mbyte) | |
474 | 3699 shl->endcol += (*mb_ptr2len)(line |
36 | 3700 + shl->endcol); |
7 | 3701 else |
3702 #endif | |
36 | 3703 ++shl->endcol; |
7 | 3704 } |
3705 | |
3706 /* Loop to check if the match starts at the | |
3707 * current position */ | |
3708 continue; | |
3709 } | |
3710 } | |
3711 break; | |
3712 } | |
1326 | 3713 if (shl != &search_hl && cur != NULL) |
3714 cur = cur->next; | |
3715 } | |
3716 | |
3717 /* Use attributes from match with highest priority among | |
3718 * 'search_hl' and the match list. */ | |
3719 search_attr = search_hl.attr_cur; | |
3720 cur = wp->w_match_head; | |
3721 shl_flag = FALSE; | |
3722 while (cur != NULL || shl_flag == FALSE) | |
3723 { | |
3724 if (shl_flag == FALSE | |
3725 && ((cur != NULL | |
3726 && cur->priority > SEARCH_HL_PRIORITY) | |
3727 || cur == NULL)) | |
699 | 3728 { |
1326 | 3729 shl = &search_hl; |
3730 shl_flag = TRUE; | |
699 | 3731 } |
1326 | 3732 else |
3733 shl = &cur->hl; | |
3734 if (shl->attr_cur != 0) | |
3735 search_attr = shl->attr_cur; | |
3736 if (shl != &search_hl && cur != NULL) | |
3737 cur = cur->next; | |
3738 } | |
7 | 3739 } |
3740 #endif | |
3741 | |
3742 #ifdef FEAT_DIFF | |
674 | 3743 if (diff_hlf != (hlf_T)0) |
7 | 3744 { |
1295 | 3745 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3746 && n_extra == 0) | |
7 | 3747 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3748 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3749 && n_extra == 0) | |
7 | 3750 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3751 line_attr = hl_attr(diff_hlf); |
3752 } | |
3753 #endif | |
3754 | |
3755 /* Decide which of the highlight attributes to use. */ | |
3756 attr_pri = TRUE; | |
3757 if (area_attr != 0) | |
3758 char_attr = area_attr; | |
3759 else if (search_attr != 0) | |
3760 char_attr = search_attr; | |
3761 #ifdef LINE_ATTR | |
3762 /* Use line_attr when not in the Visual or 'incsearch' area | |
3763 * (area_attr may be 0 when "noinvcur" is set). */ | |
3764 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3765 || vcol < fromcol || vcol_prev < fromcol_prev |
3766 || vcol >= tocol)) | |
674 | 3767 char_attr = line_attr; |
3768 #endif | |
3769 else | |
3770 { | |
3771 attr_pri = FALSE; | |
3772 #ifdef FEAT_SYN_HL | |
3773 if (has_syntax) | |
3774 char_attr = syntax_attr; | |
3775 else | |
3776 #endif | |
3777 char_attr = 0; | |
3778 } | |
7 | 3779 } |
3780 | |
3781 /* | |
3782 * Get the next character to put on the screen. | |
3783 */ | |
3784 /* | |
1340 | 3785 * The "p_extra" points to the extra stuff that is inserted to |
3786 * represent special characters (non-printable stuff) and other | |
3787 * things. When all characters are the same, c_extra is used. | |
3788 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3789 * "p_extra[n_extra]". | |
7 | 3790 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3791 */ | |
3792 if (n_extra > 0) | |
3793 { | |
3794 if (c_extra != NUL) | |
3795 { | |
3796 c = c_extra; | |
3797 #ifdef FEAT_MBYTE | |
3798 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3799 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3800 { | |
3801 mb_utf8 = TRUE; | |
714 | 3802 u8cc[0] = 0; |
819 | 3803 c = 0xc0; |
7 | 3804 } |
3805 else | |
3806 mb_utf8 = FALSE; | |
3807 #endif | |
3808 } | |
3809 else | |
3810 { | |
3811 c = *p_extra; | |
3812 #ifdef FEAT_MBYTE | |
3813 if (has_mbyte) | |
3814 { | |
3815 mb_c = c; | |
3816 if (enc_utf8) | |
3817 { | |
3818 /* If the UTF-8 character is more than one byte: | |
3819 * Decode it into "mb_c". */ | |
474 | 3820 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3821 mb_utf8 = FALSE; |
3822 if (mb_l > n_extra) | |
3823 mb_l = 1; | |
3824 else if (mb_l > 1) | |
3825 { | |
714 | 3826 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3827 mb_utf8 = TRUE; |
819 | 3828 c = 0xc0; |
7 | 3829 } |
3830 } | |
3831 else | |
3832 { | |
3833 /* if this is a DBCS character, put it in "mb_c" */ | |
3834 mb_l = MB_BYTE2LEN(c); | |
3835 if (mb_l >= n_extra) | |
3836 mb_l = 1; | |
3837 else if (mb_l > 1) | |
3838 mb_c = (c << 8) + p_extra[1]; | |
3839 } | |
504 | 3840 if (mb_l == 0) /* at the NUL at end-of-line */ |
3841 mb_l = 1; | |
3842 | |
7 | 3843 /* If a double-width char doesn't fit display a '>' in the |
3844 * last column. */ | |
504 | 3845 if (( |
7 | 3846 # ifdef FEAT_RIGHTLEFT |
3847 wp->w_p_rl ? (col <= 0) : | |
3848 # endif | |
504 | 3849 (col >= W_WIDTH(wp) - 1)) |
7 | 3850 && (*mb_char2cells)(mb_c) == 2) |
3851 { | |
3852 c = '>'; | |
3853 mb_c = c; | |
3854 mb_l = 1; | |
3855 mb_utf8 = FALSE; | |
3856 multi_attr = hl_attr(HLF_AT); | |
3857 /* put the pointer back to output the double-width | |
3858 * character at the start of the next line. */ | |
3859 ++n_extra; | |
3860 --p_extra; | |
3861 } | |
3862 else | |
3863 { | |
3864 n_extra -= mb_l - 1; | |
3865 p_extra += mb_l - 1; | |
3866 } | |
3867 } | |
3868 #endif | |
3869 ++p_extra; | |
3870 } | |
3871 --n_extra; | |
3872 } | |
3873 else | |
3874 { | |
3875 /* | |
3876 * Get a character from the line itself. | |
3877 */ | |
3878 c = *ptr; | |
3879 #ifdef FEAT_MBYTE | |
3880 if (has_mbyte) | |
3881 { | |
3882 mb_c = c; | |
3883 if (enc_utf8) | |
3884 { | |
3885 /* If the UTF-8 character is more than one byte: Decode it | |
3886 * into "mb_c". */ | |
474 | 3887 mb_l = (*mb_ptr2len)(ptr); |
7 | 3888 mb_utf8 = FALSE; |
3889 if (mb_l > 1) | |
3890 { | |
714 | 3891 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3892 /* Overlong encoded ASCII or ASCII with composing char |
3893 * is displayed normally, except a NUL. */ | |
3894 if (mb_c < 0x80) | |
3895 c = mb_c; | |
3896 mb_utf8 = TRUE; | |
507 | 3897 |
3898 /* At start of the line we can have a composing char. | |
3899 * Draw it as a space with a composing char. */ | |
3900 if (utf_iscomposing(mb_c)) | |
3901 { | |
1326 | 3902 int i; |
3903 | |
714 | 3904 for (i = Screen_mco - 1; i > 0; --i) |
3905 u8cc[i] = u8cc[i - 1]; | |
3906 u8cc[0] = mb_c; | |
507 | 3907 mb_c = ' '; |
3908 } | |
7 | 3909 } |
3910 | |
3911 if ((mb_l == 1 && c >= 0x80) | |
3912 || (mb_l >= 1 && mb_c == 0) | |
3913 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3914 # ifdef UNICODE16 |
3915 || mb_c >= 0x10000 | |
3916 # endif | |
3917 ))) | |
7 | 3918 { |
3919 /* | |
3920 * Illegal UTF-8 byte: display as <xx>. | |
3921 * Non-BMP character : display as ? or fullwidth ?. | |
3922 */ | |
1401 | 3923 # ifdef UNICODE16 |
7 | 3924 if (mb_c < 0x10000) |
1401 | 3925 # endif |
7 | 3926 { |
3927 transchar_hex(extra, mb_c); | |
714 | 3928 # ifdef FEAT_RIGHTLEFT |
7 | 3929 if (wp->w_p_rl) /* reverse */ |
3930 rl_mirror(extra); | |
714 | 3931 # endif |
7 | 3932 } |
1401 | 3933 # ifdef UNICODE16 |
7 | 3934 else if (utf_char2cells(mb_c) != 2) |
3935 STRCPY(extra, "?"); | |
3936 else | |
3937 /* 0xff1f in UTF-8: full-width '?' */ | |
3938 STRCPY(extra, "\357\274\237"); | |
1401 | 3939 # endif |
7 | 3940 |
3941 p_extra = extra; | |
3942 c = *p_extra; | |
3943 mb_c = mb_ptr2char_adv(&p_extra); | |
3944 mb_utf8 = (c >= 0x80); | |
3945 n_extra = (int)STRLEN(p_extra); | |
3946 c_extra = NUL; | |
3947 if (area_attr == 0 && search_attr == 0) | |
3948 { | |
3949 n_attr = n_extra + 1; | |
3950 extra_attr = hl_attr(HLF_8); | |
3951 saved_attr2 = char_attr; /* save current attr */ | |
3952 } | |
3953 } | |
3954 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3955 mb_l = 1; | |
3956 #ifdef FEAT_ARABIC | |
3957 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3958 { | |
3959 /* Do Arabic shaping. */ | |
714 | 3960 int pc, pc1, nc; |
3961 int pcc[MAX_MCO]; | |
7 | 3962 |
3963 /* The idea of what is the previous and next | |
3964 * character depends on 'rightleft'. */ | |
3965 if (wp->w_p_rl) | |
3966 { | |
3967 pc = prev_c; | |
3968 pc1 = prev_c1; | |
3969 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3970 prev_c1 = u8cc[0]; |
7 | 3971 } |
3972 else | |
3973 { | |
714 | 3974 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3975 nc = prev_c; |
714 | 3976 pc1 = pcc[0]; |
7 | 3977 } |
3978 prev_c = mb_c; | |
3979 | |
714 | 3980 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3981 } |
3982 else | |
3983 prev_c = mb_c; | |
3984 #endif | |
3985 } | |
3986 else /* enc_dbcs */ | |
3987 { | |
3988 mb_l = MB_BYTE2LEN(c); | |
3989 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3990 mb_l = 1; | |
3991 else if (mb_l > 1) | |
3992 { | |
3993 /* We assume a second byte below 32 is illegal. | |
3994 * Hopefully this is OK for all double-byte encodings! | |
3995 */ | |
3996 if (ptr[1] >= 32) | |
3997 mb_c = (c << 8) + ptr[1]; | |
3998 else | |
3999 { | |
4000 if (ptr[1] == NUL) | |
4001 { | |
4002 /* head byte at end of line */ | |
4003 mb_l = 1; | |
4004 transchar_nonprint(extra, c); | |
4005 } | |
4006 else | |
4007 { | |
4008 /* illegal tail byte */ | |
4009 mb_l = 2; | |
4010 STRCPY(extra, "XX"); | |
4011 } | |
4012 p_extra = extra; | |
4013 n_extra = (int)STRLEN(extra) - 1; | |
4014 c_extra = NUL; | |
4015 c = *p_extra++; | |
4016 if (area_attr == 0 && search_attr == 0) | |
4017 { | |
4018 n_attr = n_extra + 1; | |
4019 extra_attr = hl_attr(HLF_8); | |
4020 saved_attr2 = char_attr; /* save current attr */ | |
4021 } | |
4022 mb_c = c; | |
4023 } | |
4024 } | |
4025 } | |
4026 /* If a double-width char doesn't fit display a '>' in the | |
4027 * last column; the character is displayed at the start of the | |
4028 * next line. */ | |
4029 if (( | |
4030 # ifdef FEAT_RIGHTLEFT | |
4031 wp->w_p_rl ? (col <= 0) : | |
4032 # endif | |
4033 (col >= W_WIDTH(wp) - 1)) | |
4034 && (*mb_char2cells)(mb_c) == 2) | |
4035 { | |
4036 c = '>'; | |
4037 mb_c = c; | |
4038 mb_utf8 = FALSE; | |
4039 mb_l = 1; | |
4040 multi_attr = hl_attr(HLF_AT); | |
4041 /* Put pointer back so that the character will be | |
4042 * displayed at the start of the next line. */ | |
4043 --ptr; | |
4044 } | |
4045 else if (*ptr != NUL) | |
4046 ptr += mb_l - 1; | |
4047 | |
4048 /* 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
|
4049 * a '<' in the first column. Don't do this for unprintable |
4352 | 4050 * 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
|
4051 if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
7 | 4052 { |
4053 n_extra = 1; | |
3586 | 4054 c_extra = MB_FILLER_CHAR; |
7 | 4055 c = ' '; |
4056 if (area_attr == 0 && search_attr == 0) | |
4057 { | |
4058 n_attr = n_extra + 1; | |
4059 extra_attr = hl_attr(HLF_AT); | |
4060 saved_attr2 = char_attr; /* save current attr */ | |
4061 } | |
4062 mb_c = c; | |
4063 mb_utf8 = FALSE; | |
4064 mb_l = 1; | |
4065 } | |
4066 | |
4067 } | |
4068 #endif | |
4069 ++ptr; | |
4070 | |
12 | 4071 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 4072 if (wp->w_p_list && (c == 160 |
4073 #ifdef FEAT_MBYTE | |
4074 || (mb_utf8 && mb_c == 160) | |
4075 #endif | |
4076 ) && lcs_nbsp) | |
12 | 4077 { |
4078 c = lcs_nbsp; | |
4079 if (area_attr == 0 && search_attr == 0) | |
4080 { | |
4081 n_attr = 1; | |
4082 extra_attr = hl_attr(HLF_8); | |
4083 saved_attr2 = char_attr; /* save current attr */ | |
4084 } | |
4085 #ifdef FEAT_MBYTE | |
4086 mb_c = c; | |
4087 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4088 { | |
4089 mb_utf8 = TRUE; | |
714 | 4090 u8cc[0] = 0; |
819 | 4091 c = 0xc0; |
12 | 4092 } |
4093 else | |
4094 mb_utf8 = FALSE; | |
4095 #endif | |
4096 } | |
4097 | |
7 | 4098 if (extra_check) |
4099 { | |
743 | 4100 #ifdef FEAT_SPELL |
221 | 4101 int can_spell = TRUE; |
743 | 4102 #endif |
4103 | |
4104 #ifdef FEAT_SYN_HL | |
7 | 4105 /* Get syntax attribute, unless still at the start of the line |
4106 * (double-wide char that doesn't fit). */ | |
221 | 4107 v = (long)(ptr - line); |
4108 if (has_syntax && v > 0) | |
7 | 4109 { |
4110 /* Get the syntax attribute for the character. If there | |
4111 * is an error, disable syntax highlighting. */ | |
4112 save_did_emsg = did_emsg; | |
4113 did_emsg = FALSE; | |
4114 | |
221 | 4115 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 4116 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4117 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4118 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4119 NULL, FALSE); |
7 | 4120 |
4121 if (did_emsg) | |
482 | 4122 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4123 wp->w_s->b_syn_error = TRUE; |
482 | 4124 has_syntax = FALSE; |
4125 } | |
7 | 4126 else |
4127 did_emsg = save_did_emsg; | |
4128 | |
4129 /* Need to get the line again, a multi-line regexp may | |
4130 * have made it invalid. */ | |
4131 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4132 ptr = line + v; | |
4133 | |
674 | 4134 if (!attr_pri) |
7 | 4135 char_attr = syntax_attr; |
301 | 4136 else |
303 | 4137 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
|
4138 # 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
|
4139 /* 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
|
4140 * 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
|
4141 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
|
4142 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
|
4143 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
|
4144 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
|
4145 # endif |
7 | 4146 } |
743 | 4147 #endif |
4148 | |
4149 #ifdef FEAT_SPELL | |
301 | 4150 /* Check spelling (unless at the end of the line). |
319 | 4151 * Only do this when there is no syntax highlighting, the |
4152 * @Spell cluster is not used or the current syntax item | |
4153 * contains the @Spell cluster. */ | |
348 | 4154 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4155 { |
230 | 4156 spell_attr = 0; |
743 | 4157 # ifdef FEAT_SYN_HL |
674 | 4158 if (!attr_pri) |
230 | 4159 char_attr = syntax_attr; |
743 | 4160 # endif |
4161 if (c != 0 && ( | |
4162 # ifdef FEAT_SYN_HL | |
4163 !has_syntax || | |
4164 # endif | |
4165 can_spell)) | |
221 | 4166 { |
348 | 4167 char_u *prev_ptr, *p; |
4168 int len; | |
534 | 4169 hlf_T spell_hlf = HLF_COUNT; |
221 | 4170 # ifdef FEAT_MBYTE |
336 | 4171 if (has_mbyte) |
4172 { | |
4173 prev_ptr = ptr - mb_l; | |
4174 v -= mb_l - 1; | |
4175 } | |
4176 else | |
221 | 4177 # endif |
336 | 4178 prev_ptr = ptr - 1; |
348 | 4179 |
4180 /* Use nextline[] if possible, it has the start of the | |
4181 * next line concatenated. */ | |
4182 if ((prev_ptr - line) - nextlinecol >= 0) | |
4183 p = nextline + (prev_ptr - line) - nextlinecol; | |
4184 else | |
4185 p = prev_ptr; | |
835 | 4186 cap_col -= (int)(prev_ptr - line); |
625 | 4187 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4188 nochange); | |
348 | 4189 word_end = v + len; |
301 | 4190 |
4191 /* In Insert mode only highlight a word that | |
4192 * doesn't touch the cursor. */ | |
534 | 4193 if (spell_hlf != HLF_COUNT |
301 | 4194 && (State & INSERT) != 0 |
4195 && wp->w_cursor.lnum == lnum | |
4196 && wp->w_cursor.col >= | |
4197 (colnr_T)(prev_ptr - line) | |
4198 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4199 { |
534 | 4200 spell_hlf = HLF_COUNT; |
301 | 4201 spell_redraw_lnum = lnum; |
221 | 4202 } |
348 | 4203 |
534 | 4204 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4205 && (p - nextline) + len > nextline_idx) |
4206 { | |
4207 /* Remember that the good word continues at the | |
4208 * start of the next line. */ | |
4209 checked_lnum = lnum + 1; | |
835 | 4210 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4211 } |
386 | 4212 |
534 | 4213 /* Turn index into actual attributes. */ |
4214 if (spell_hlf != HLF_COUNT) | |
4215 spell_attr = highlight_attr[spell_hlf]; | |
4216 | |
386 | 4217 if (cap_col > 0) |
4218 { | |
4219 if (p != prev_ptr | |
4220 && (p - nextline) + cap_col >= nextline_idx) | |
4221 { | |
4222 /* Remember that the word in the next line | |
4223 * must start with a capital. */ | |
4224 capcol_lnum = lnum + 1; | |
835 | 4225 cap_col = (int)((p - nextline) + cap_col |
4226 - nextline_idx); | |
386 | 4227 } |
4228 else | |
4229 /* Compute the actual column. */ | |
835 | 4230 cap_col += (int)(prev_ptr - line); |
386 | 4231 } |
221 | 4232 } |
4233 } | |
4234 if (spell_attr != 0) | |
348 | 4235 { |
674 | 4236 if (!attr_pri) |
348 | 4237 char_attr = hl_combine_attr(char_attr, spell_attr); |
4238 else | |
4239 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4240 } | |
7 | 4241 #endif |
4242 #ifdef FEAT_LINEBREAK | |
4243 /* | |
221 | 4244 * Found last space before word: check for line break. |
7 | 4245 */ |
4246 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4247 && !wp->w_p_list) |
7 | 4248 { |
4249 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4250 # ifdef FEAT_MBYTE | |
4251 has_mbyte ? mb_l : | |
4252 # endif | |
4253 1), (colnr_T)vcol, NULL) - 1; | |
4254 c_extra = ' '; | |
4255 if (vim_iswhite(c)) | |
4256 c = ' '; | |
4257 } | |
4258 #endif | |
4259 | |
4260 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4261 { | |
4262 c = lcs_trail; | |
674 | 4263 if (!attr_pri) |
7 | 4264 { |
4265 n_attr = 1; | |
4266 extra_attr = hl_attr(HLF_8); | |
4267 saved_attr2 = char_attr; /* save current attr */ | |
4268 } | |
4269 #ifdef FEAT_MBYTE | |
4270 mb_c = c; | |
4271 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4272 { | |
4273 mb_utf8 = TRUE; | |
714 | 4274 u8cc[0] = 0; |
819 | 4275 c = 0xc0; |
7 | 4276 } |
4277 else | |
4278 mb_utf8 = FALSE; | |
4279 #endif | |
4280 } | |
4281 } | |
4282 | |
4283 /* | |
4284 * Handling of non-printable characters. | |
4285 */ | |
819 | 4286 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4287 { |
4288 /* | |
4289 * when getting a character from the file, we may have to | |
4290 * turn it into something else on the way to putting it | |
4291 * into "ScreenLines". | |
4292 */ | |
4293 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4294 { | |
4295 /* tab amount depends on current column */ | |
4296 n_extra = (int)wp->w_buffer->b_p_ts | |
3984 | 4297 - vcol % (int)wp->w_buffer->b_p_ts - 1; |
4298 #ifdef FEAT_CONCEAL | |
4299 /* Tab alignment should be identical regardless of | |
4300 * 'conceallevel' value. So tab compensates of all | |
4301 * previous concealed characters, and thus resets vcol_off | |
4302 * and boguscols accumulated so far in the line. Note that | |
4303 * the tab can be longer than 'tabstop' when there | |
4304 * are concealed characters. */ | |
4305 n_extra += vcol_off; | |
4306 vcol -= vcol_off; | |
4307 vcol_off = 0; | |
4308 col -= boguscols; | |
4309 boguscols = 0; | |
4310 #endif | |
7 | 4311 #ifdef FEAT_MBYTE |
4312 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4313 #endif | |
4314 if (wp->w_p_list) | |
4315 { | |
4316 c = lcs_tab1; | |
4317 c_extra = lcs_tab2; | |
4318 n_attr = n_extra + 1; | |
4319 extra_attr = hl_attr(HLF_8); | |
4320 saved_attr2 = char_attr; /* save current attr */ | |
4321 #ifdef FEAT_MBYTE | |
4322 mb_c = c; | |
4323 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4324 { | |
4325 mb_utf8 = TRUE; | |
714 | 4326 u8cc[0] = 0; |
819 | 4327 c = 0xc0; |
7 | 4328 } |
4329 #endif | |
4330 } | |
4331 else | |
4332 { | |
4333 c_extra = ' '; | |
4334 c = ' '; | |
4335 } | |
4336 } | |
36 | 4337 else if (c == NUL |
4338 && ((wp->w_p_list && lcs_eol > 0) | |
4339 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4340 && tocol > vcol | |
39 | 4341 #ifdef FEAT_VISUAL |
36 | 4342 && VIsual_mode != Ctrl_V |
39 | 4343 #endif |
36 | 4344 && ( |
4345 # ifdef FEAT_RIGHTLEFT | |
4346 wp->w_p_rl ? (col >= 0) : | |
4347 # endif | |
4348 (col < W_WIDTH(wp))) | |
4349 && !(noinvcur | |
1850 | 4350 && lnum == wp->w_cursor.lnum |
36 | 4351 && (colnr_T)vcol == wp->w_virtcol))) |
4352 && lcs_eol_one >= 0) | |
7 | 4353 { |
36 | 4354 /* Display a '$' after the line or highlight an extra |
4355 * character if the line break is included. */ | |
7 | 4356 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4357 /* For a diff line the highlighting continues after the | |
4358 * "$". */ | |
4359 if ( | |
4360 # ifdef FEAT_DIFF | |
534 | 4361 diff_hlf == (hlf_T)0 |
7 | 4362 # ifdef LINE_ATTR |
4363 && | |
4364 # endif | |
4365 # endif | |
4366 # ifdef LINE_ATTR | |
4367 line_attr == 0 | |
4368 # endif | |
4369 ) | |
4370 #endif | |
4371 { | |
4372 #ifdef FEAT_VIRTUALEDIT | |
4373 /* In virtualedit, visual selections may extend | |
4374 * beyond end of line. */ | |
4375 if (area_highlighting && virtual_active() | |
4376 && tocol != MAXCOL && vcol < tocol) | |
4377 n_extra = 0; | |
4378 else | |
4379 #endif | |
4380 { | |
4381 p_extra = at_end_str; | |
4382 n_extra = 1; | |
4383 c_extra = NUL; | |
4384 } | |
4385 } | |
36 | 4386 if (wp->w_p_list) |
4387 c = lcs_eol; | |
4388 else | |
4389 c = ' '; | |
7 | 4390 lcs_eol_one = -1; |
4391 --ptr; /* put it back at the NUL */ | |
674 | 4392 if (!attr_pri) |
7 | 4393 { |
4394 extra_attr = hl_attr(HLF_AT); | |
4395 n_attr = 1; | |
4396 } | |
4397 #ifdef FEAT_MBYTE | |
4398 mb_c = c; | |
4399 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4400 { | |
4401 mb_utf8 = TRUE; | |
714 | 4402 u8cc[0] = 0; |
819 | 4403 c = 0xc0; |
7 | 4404 } |
4405 else | |
4406 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4407 #endif | |
4408 } | |
4409 else if (c != NUL) | |
4410 { | |
4411 p_extra = transchar(c); | |
4412 #ifdef FEAT_RIGHTLEFT | |
4413 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4414 rl_mirror(p_extra); /* reverse "<12>" */ | |
4415 #endif | |
4416 n_extra = byte2cells(c) - 1; | |
4417 c_extra = NUL; | |
4418 c = *p_extra++; | |
674 | 4419 if (!attr_pri) |
7 | 4420 { |
4421 n_attr = n_extra + 1; | |
4422 extra_attr = hl_attr(HLF_8); | |
4423 saved_attr2 = char_attr; /* save current attr */ | |
4424 } | |
4425 #ifdef FEAT_MBYTE | |
4426 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4427 #endif | |
4428 } | |
4429 #ifdef FEAT_VIRTUALEDIT | |
4430 else if (VIsual_active | |
4431 && (VIsual_mode == Ctrl_V | |
4432 || VIsual_mode == 'v') | |
4433 && virtual_active() | |
4434 && tocol != MAXCOL | |
4435 && vcol < tocol | |
4436 && ( | |
4437 # ifdef FEAT_RIGHTLEFT | |
4438 wp->w_p_rl ? (col >= 0) : | |
4439 # endif | |
4440 (col < W_WIDTH(wp)))) | |
4441 { | |
4442 c = ' '; | |
4443 --ptr; /* put it back at the NUL */ | |
4444 } | |
4445 #endif | |
910 | 4446 #if defined(LINE_ATTR) |
7 | 4447 else if (( |
4448 # ifdef FEAT_DIFF | |
910 | 4449 diff_hlf != (hlf_T)0 || |
7 | 4450 # endif |
4451 line_attr != 0 | |
4452 ) && ( | |
4453 # ifdef FEAT_RIGHTLEFT | |
4454 wp->w_p_rl ? (col >= 0) : | |
4455 # endif | |
2553
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4456 (col |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4457 # ifdef FEAT_CONCEAL |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4458 - boguscols |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4459 # endif |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4460 < W_WIDTH(wp)))) |
7 | 4461 { |
4462 /* Highlight until the right side of the window */ | |
4463 c = ' '; | |
4464 --ptr; /* put it back at the NUL */ | |
867 | 4465 |
4466 /* Remember we do the char for line highlighting. */ | |
4467 ++did_line_attr; | |
4468 | |
4469 /* don't do search HL for the rest of the line */ | |
4470 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4471 char_attr = line_attr; | |
7 | 4472 # ifdef FEAT_DIFF |
4473 if (diff_hlf == HLF_TXD) | |
4474 { | |
4475 diff_hlf = HLF_CHD; | |
4476 if (attr == 0 || char_attr != attr) | |
4477 char_attr = hl_attr(diff_hlf); | |
4478 } | |
4479 # endif | |
4480 } | |
4481 #endif | |
4482 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4483 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4484 #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
|
4485 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
|
4486 && (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
|
4487 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
|
4488 && (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
|
4489 && !(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
|
4490 && 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
|
4491 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4492 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
|
4493 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
|
4494 && (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
|
4495 && 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
|
4496 { |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4497 /* 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
|
4498 * character. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4499 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4500 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4501 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4502 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4503 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4504 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4505 |
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
|
4506 prev_syntax_id = syntax_seqnr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4507 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4508 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4509 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4510 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4511 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
|
4512 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4513 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4514 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4515 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4516 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4517 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4518 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4519 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4520 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4521 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4522 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4523 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4524 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4525 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4526 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4527 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4528 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4529 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4530 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4531 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4532 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4533 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4534 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4535 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4536 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4537 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4538 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4539 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4540 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4541 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4542 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4543 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
|
4544 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4545 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4546 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4547 { |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4548 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
|
4549 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4550 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4551 #endif /* FEAT_CONCEAL */ |
7 | 4552 } |
4553 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4554 #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
|
4555 /* 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
|
4556 * 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
|
4557 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
|
4558 && 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
|
4559 && 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
|
4560 && (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
|
4561 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4562 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
|
4563 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
|
4564 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
|
4565 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4566 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4567 |
7 | 4568 /* Don't override visual selection highlighting. */ |
4569 if (n_attr > 0 | |
4570 && draw_state == WL_LINE | |
674 | 4571 && !attr_pri) |
7 | 4572 char_attr = extra_attr; |
4573 | |
42 | 4574 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4575 /* XIM don't send preedit_start and preedit_end, but they send |
4576 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4577 * im_is_preediting() here. */ | |
4578 if (xic != NULL | |
1850 | 4579 && lnum == wp->w_cursor.lnum |
7 | 4580 && (State & INSERT) |
4581 && !p_imdisable | |
4582 && im_is_preediting() | |
4583 && draw_state == WL_LINE) | |
4584 { | |
4585 colnr_T tcol; | |
4586 | |
4587 if (preedit_end_col == MAXCOL) | |
1850 | 4588 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4589 else |
4590 tcol = preedit_end_col; | |
4591 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4592 { | |
4593 if (feedback_old_attr < 0) | |
4594 { | |
4595 feedback_col = 0; | |
4596 feedback_old_attr = char_attr; | |
4597 } | |
4598 char_attr = im_get_feedback_attr(feedback_col); | |
4599 if (char_attr < 0) | |
4600 char_attr = feedback_old_attr; | |
4601 feedback_col++; | |
4602 } | |
4603 else if (feedback_old_attr >= 0) | |
4604 { | |
4605 char_attr = feedback_old_attr; | |
4606 feedback_old_attr = -1; | |
4607 feedback_col = 0; | |
4608 } | |
4609 } | |
4610 #endif | |
4611 /* | |
4612 * Handle the case where we are in column 0 but not on the first | |
4613 * character of the line and the user wants us to show us a | |
4614 * special character (via 'listchars' option "precedes:<char>". | |
4615 */ | |
4616 if (lcs_prec_todo != NUL | |
4617 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4618 #ifdef FEAT_DIFF | |
4619 && filler_todo <= 0 | |
4620 #endif | |
4621 && draw_state > WL_NR | |
4622 && c != NUL) | |
4623 { | |
4624 c = lcs_prec; | |
4625 lcs_prec_todo = NUL; | |
4626 #ifdef FEAT_MBYTE | |
3586 | 4627 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
4628 { | |
4629 /* Double-width character being overwritten by the "precedes" | |
4630 * character, need to fill up half the character. */ | |
4631 c_extra = MB_FILLER_CHAR; | |
4632 n_extra = 1; | |
4633 n_attr = 2; | |
4634 extra_attr = hl_attr(HLF_AT); | |
4635 } | |
7 | 4636 mb_c = c; |
4637 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4638 { | |
4639 mb_utf8 = TRUE; | |
714 | 4640 u8cc[0] = 0; |
819 | 4641 c = 0xc0; |
7 | 4642 } |
4643 else | |
4644 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4645 #endif | |
674 | 4646 if (!attr_pri) |
7 | 4647 { |
4648 saved_attr3 = char_attr; /* save current attr */ | |
4649 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4650 n_attr3 = 1; | |
4651 } | |
4652 } | |
4653 | |
4654 /* | |
867 | 4655 * At end of the text line or just after the last character. |
7 | 4656 */ |
867 | 4657 if (c == NUL |
910 | 4658 #if defined(LINE_ATTR) |
867 | 4659 || did_line_attr == 1 |
4660 #endif | |
4661 ) | |
4662 { | |
4663 #ifdef FEAT_SEARCH_EXTRA | |
4664 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4665 |
4666 /* we're not really at that column when skipping some text */ | |
1439 | 4667 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4668 ++prevcol; |
867 | 4669 #endif |
4670 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4671 /* Invert at least one char, used for Visual and empty line or |
7 | 4672 * highlight match at end of line. If it's beyond the last |
4673 * char on the screen, just overwrite that one (tricky!) Not | |
4674 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4675 #ifdef FEAT_SEARCH_EXTRA |
4676 prevcol_hl_flag = FALSE; | |
4677 if (prevcol == (long)search_hl.startcol) | |
4678 prevcol_hl_flag = TRUE; | |
4679 else | |
4680 { | |
4681 cur = wp->w_match_head; | |
4682 while (cur != NULL) | |
4683 { | |
4684 if (prevcol == (long)cur->hl.startcol) | |
4685 { | |
4686 prevcol_hl_flag = TRUE; | |
4687 break; | |
4688 } | |
4689 cur = cur->next; | |
4690 } | |
4691 } | |
4692 #endif | |
7 | 4693 if (lcs_eol == lcs_eol_one |
1850 | 4694 && ((area_attr != 0 && vcol == fromcol |
4695 #ifdef FEAT_VISUAL | |
4696 && (VIsual_mode != Ctrl_V | |
4697 || lnum == VIsual.lnum | |
4698 || lnum == curwin->w_cursor.lnum) | |
4699 #endif | |
4700 && c == NUL) | |
7 | 4701 #ifdef FEAT_SEARCH_EXTRA |
4702 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4703 || (prevcol_hl_flag == TRUE |
910 | 4704 # if defined(LINE_ATTR) |
867 | 4705 && did_line_attr <= 1 |
4706 # endif | |
4707 ) | |
7 | 4708 #endif |
4709 )) | |
4710 { | |
4711 int n = 0; | |
4712 | |
4713 #ifdef FEAT_RIGHTLEFT | |
4714 if (wp->w_p_rl) | |
4715 { | |
4716 if (col < 0) | |
4717 n = 1; | |
4718 } | |
4719 else | |
4720 #endif | |
4721 { | |
4722 if (col >= W_WIDTH(wp)) | |
4723 n = -1; | |
4724 } | |
4725 if (n != 0) | |
4726 { | |
4727 /* At the window boundary, highlight the last character | |
4728 * instead (better than nothing). */ | |
4729 off += n; | |
4730 col += n; | |
4731 } | |
4732 else | |
4733 { | |
4734 /* Add a blank character to highlight. */ | |
4735 ScreenLines[off] = ' '; | |
4736 #ifdef FEAT_MBYTE | |
4737 if (enc_utf8) | |
4738 ScreenLinesUC[off] = 0; | |
4739 #endif | |
4740 } | |
4741 #ifdef FEAT_SEARCH_EXTRA | |
4742 if (area_attr == 0) | |
4743 { | |
1326 | 4744 /* Use attributes from match with highest priority among |
4745 * 'search_hl' and the match list. */ | |
4746 char_attr = search_hl.attr; | |
4747 cur = wp->w_match_head; | |
4748 shl_flag = FALSE; | |
4749 while (cur != NULL || shl_flag == FALSE) | |
699 | 4750 { |
1326 | 4751 if (shl_flag == FALSE |
4752 && ((cur != NULL | |
4753 && cur->priority > SEARCH_HL_PRIORITY) | |
4754 || cur == NULL)) | |
699 | 4755 { |
1326 | 4756 shl = &search_hl; |
4757 shl_flag = TRUE; | |
699 | 4758 } |
1326 | 4759 else |
4760 shl = &cur->hl; | |
4761 if ((ptr - line) - 1 == (long)shl->startcol) | |
4762 char_attr = shl->attr; | |
4763 if (shl != &search_hl && cur != NULL) | |
4764 cur = cur->next; | |
699 | 4765 } |
7 | 4766 } |
4767 #endif | |
4768 ScreenAttrs[off] = char_attr; | |
4769 #ifdef FEAT_RIGHTLEFT | |
4770 if (wp->w_p_rl) | |
1437 | 4771 { |
7 | 4772 --col; |
1437 | 4773 --off; |
4774 } | |
7 | 4775 else |
4776 #endif | |
1437 | 4777 { |
7 | 4778 ++col; |
1437 | 4779 ++off; |
4780 } | |
743 | 4781 ++vcol; |
1437 | 4782 #ifdef FEAT_SYN_HL |
4783 eol_hl_off = 1; | |
4784 #endif | |
743 | 4785 } |
867 | 4786 } |
4787 | |
4788 /* | |
4789 * At end of the text line. | |
4790 */ | |
4791 if (c == NUL) | |
4792 { | |
743 | 4793 #ifdef FEAT_SYN_HL |
1850 | 4794 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4795 && lnum == wp->w_cursor.lnum) | |
1437 | 4796 { |
4797 /* highlight last char after line */ | |
4798 --col; | |
4799 --off; | |
4800 --vcol; | |
4801 } | |
4802 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4803 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4804 if (wp->w_p_wrap) |
4805 v = wp->w_skipcol; | |
4806 else | |
4807 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4808 |
820 | 4809 /* check if line ends before left margin */ |
4810 if (vcol < v + col - win_col_off(wp)) | |
4811 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
|
4812 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4813 /* 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
|
4814 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4815 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4816 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4817 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4818 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4819 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4820 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
|
4821 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4822 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4823 && (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
|
4824 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4825 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
|
4826 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4827 || draw_color_col) |
743 | 4828 # ifdef FEAT_RIGHTLEFT |
4829 && !wp->w_p_rl | |
4830 # endif | |
4831 ) | |
4832 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4833 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4834 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4835 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4836 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4837 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4838 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4839 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4840 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
|
4841 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4842 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4843 |
743 | 4844 while (col < W_WIDTH(wp)) |
4845 { | |
4846 ScreenLines[off] = ' '; | |
4847 #ifdef FEAT_MBYTE | |
4848 if (enc_utf8) | |
4849 ScreenLinesUC[off] = 0; | |
4850 #endif | |
4851 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4852 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4853 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
|
4854 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4855 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4856 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
|
4857 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
|
4858 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
|
4859 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4860 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4861 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4862 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4863 if (VCOL_HLC >= rightmost_vcol) |
743 | 4864 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4865 |
743 | 4866 ++vcol; |
4867 } | |
4868 } | |
4869 #endif | |
7 | 4870 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4871 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
|
4872 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4873 row++; |
4874 | |
4875 /* | |
4876 * Update w_cline_height and w_cline_folded if the cursor line was | |
4877 * updated (saves a call to plines() later). | |
4878 */ | |
4879 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4880 { | |
4881 curwin->w_cline_row = startrow; | |
4882 curwin->w_cline_height = row - startrow; | |
4883 #ifdef FEAT_FOLDING | |
4884 curwin->w_cline_folded = FALSE; | |
4885 #endif | |
4886 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4887 } | |
4888 | |
4889 break; | |
4890 } | |
4891 | |
4892 /* line continues beyond line end */ | |
4893 if (lcs_ext | |
4894 && !wp->w_p_wrap | |
4895 #ifdef FEAT_DIFF | |
4896 && filler_todo <= 0 | |
4897 #endif | |
4898 && ( | |
4899 #ifdef FEAT_RIGHTLEFT | |
4900 wp->w_p_rl ? col == 0 : | |
4901 #endif | |
4902 col == W_WIDTH(wp) - 1) | |
4903 && (*ptr != NUL | |
1555 | 4904 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4905 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4906 { | |
4907 c = lcs_ext; | |
4908 char_attr = hl_attr(HLF_AT); | |
4909 #ifdef FEAT_MBYTE | |
4910 mb_c = c; | |
4911 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4912 { | |
4913 mb_utf8 = TRUE; | |
714 | 4914 u8cc[0] = 0; |
819 | 4915 c = 0xc0; |
7 | 4916 } |
4917 else | |
4918 mb_utf8 = FALSE; | |
4919 #endif | |
4920 } | |
4921 | |
743 | 4922 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4923 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4924 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4925 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
|
4926 |
743 | 4927 /* 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
|
4928 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4929 * 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
|
4930 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4931 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4932 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
|
4933 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4934 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
|
4935 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4936 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4937 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4938 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
|
4939 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4940 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
|
4941 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4942 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4943 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
|
4944 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4945 } |
743 | 4946 #endif |
4947 | |
7 | 4948 /* |
4949 * Store character to be displayed. | |
4950 * Skip characters that are left of the screen for 'nowrap'. | |
4951 */ | |
4952 vcol_prev = vcol; | |
4953 if (draw_state < WL_LINE || n_skip <= 0) | |
4954 { | |
4955 /* | |
4956 * Store the character. | |
4957 */ | |
4958 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4959 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4960 { | |
4961 /* A double-wide character is: put first halve in left cell. */ | |
4962 --off; | |
4963 --col; | |
4964 } | |
4965 #endif | |
4966 ScreenLines[off] = c; | |
4967 #ifdef FEAT_MBYTE | |
4968 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4969 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4970 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4971 ScreenLines[off] = 0x8e; |
7 | 4972 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4973 } |
7 | 4974 else if (enc_utf8) |
4975 { | |
4976 if (mb_utf8) | |
4977 { | |
1326 | 4978 int i; |
4979 | |
7 | 4980 ScreenLinesUC[off] = mb_c; |
819 | 4981 if ((c & 0xff) == 0) |
4982 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4983 for (i = 0; i < Screen_mco; ++i) |
4984 { | |
4985 ScreenLinesC[i][off] = u8cc[i]; | |
4986 if (u8cc[i] == 0) | |
4987 break; | |
4988 } | |
7 | 4989 } |
4990 else | |
4991 ScreenLinesUC[off] = 0; | |
4992 } | |
4993 if (multi_attr) | |
4994 { | |
4995 ScreenAttrs[off] = multi_attr; | |
4996 multi_attr = 0; | |
4997 } | |
4998 else | |
4999 #endif | |
5000 ScreenAttrs[off] = char_attr; | |
5001 | |
5002 #ifdef FEAT_MBYTE | |
5003 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
5004 { | |
5005 /* Need to fill two screen columns. */ | |
5006 ++off; | |
5007 ++col; | |
5008 if (enc_utf8) | |
5009 /* UTF-8: Put a 0 in the second screen char. */ | |
5010 ScreenLines[off] = 0; | |
5011 else | |
5012 /* DBCS: Put second byte in the second screen char. */ | |
5013 ScreenLines[off] = mb_c & 0xff; | |
5014 ++vcol; | |
5015 /* When "tocol" is halfway a character, set it to the end of | |
5016 * the character, otherwise highlighting won't stop. */ | |
5017 if (tocol == vcol) | |
5018 ++tocol; | |
5019 #ifdef FEAT_RIGHTLEFT | |
5020 if (wp->w_p_rl) | |
5021 { | |
5022 /* now it's time to backup one cell */ | |
5023 --off; | |
5024 --col; | |
5025 } | |
5026 #endif | |
5027 } | |
5028 #endif | |
5029 #ifdef FEAT_RIGHTLEFT | |
5030 if (wp->w_p_rl) | |
5031 { | |
5032 --off; | |
5033 --col; | |
5034 } | |
5035 else | |
5036 #endif | |
5037 { | |
5038 ++off; | |
5039 ++col; | |
5040 } | |
5041 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 #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
|
5043 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
|
5044 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5045 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5046 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5047 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5048 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5049 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5050 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5051 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5052 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5053 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5054 * 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
|
5055 * 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
|
5056 * 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
|
5057 * 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
|
5058 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5059 * 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
|
5060 * 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
|
5061 * 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
|
5062 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5063 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5064 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5065 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5066 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5067 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5068 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5069 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5070 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5071 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5072 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5073 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5074 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5075 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5076 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5077 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5078 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5079 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5080 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5081 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5082 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5083 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5084 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5085 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
|
5086 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5087 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5088 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5089 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5090 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5091 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5092 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5093 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5094 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5095 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5096 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5097 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5098 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5099 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5100 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5101 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5102 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5103 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5104 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5105 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5106 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5107 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5108 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5109 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5110 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5111 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5112 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5113 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5114 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5115 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5116 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5117 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5118 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5119 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5120 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5121 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5122 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5123 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5124 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5125 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5126 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5127 #endif /* FEAT_CONCEAL */ |
7 | 5128 else |
5129 --n_skip; | |
5130 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5131 /* 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
|
5132 * column. */ |
1849 | 5133 if (draw_state > WL_NR |
7 | 5134 #ifdef FEAT_DIFF |
5135 && filler_todo <= 0 | |
5136 #endif | |
5137 ) | |
5138 ++vcol; | |
5139 | |
743 | 5140 #ifdef FEAT_SYN_HL |
5141 if (vcol_save_attr >= 0) | |
5142 char_attr = vcol_save_attr; | |
5143 #endif | |
5144 | |
7 | 5145 /* restore attributes after "predeces" in 'listchars' */ |
5146 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5147 char_attr = saved_attr3; | |
5148 | |
5149 /* restore attributes after last 'listchars' or 'number' char */ | |
5150 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5151 char_attr = saved_attr2; | |
5152 | |
5153 /* | |
5154 * At end of screen line and there is more to come: Display the line | |
1378 | 5155 * so far. If there is no more to display it is caught above. |
7 | 5156 */ |
5157 if (( | |
5158 #ifdef FEAT_RIGHTLEFT | |
5159 wp->w_p_rl ? (col < 0) : | |
5160 #endif | |
5161 (col >= W_WIDTH(wp))) | |
5162 && (*ptr != NUL | |
5163 #ifdef FEAT_DIFF | |
5164 || filler_todo > 0 | |
5165 #endif | |
2724 | 5166 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
7 | 5167 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
5168 ) | |
5169 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5170 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5171 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
|
5172 (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
|
5173 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5174 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5175 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
|
5176 (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
|
5177 #endif |
7 | 5178 ++row; |
5179 ++screen_row; | |
5180 | |
5181 /* When not wrapping and finished diff lines, or when displayed | |
5182 * '$' and highlighting until last column, break here. */ | |
5183 if ((!wp->w_p_wrap | |
5184 #ifdef FEAT_DIFF | |
5185 && filler_todo <= 0 | |
5186 #endif | |
5187 ) || lcs_eol_one == -1) | |
5188 break; | |
5189 | |
5190 /* When the window is too narrow draw all "@" lines. */ | |
5191 if (draw_state != WL_LINE | |
5192 #ifdef FEAT_DIFF | |
5193 && filler_todo <= 0 | |
5194 #endif | |
5195 ) | |
5196 { | |
5197 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5198 #ifdef FEAT_VERTSPLIT | |
5199 draw_vsep_win(wp, row); | |
5200 #endif | |
5201 row = endrow; | |
5202 } | |
5203 | |
5204 /* When line got too long for screen break here. */ | |
5205 if (row == endrow) | |
5206 { | |
5207 ++row; | |
5208 break; | |
5209 } | |
5210 | |
5211 if (screen_cur_row == screen_row - 1 | |
5212 #ifdef FEAT_DIFF | |
5213 && filler_todo <= 0 | |
5214 #endif | |
5215 && W_WIDTH(wp) == Columns) | |
5216 { | |
5217 /* Remember that the line wraps, used for modeless copy. */ | |
5218 LineWraps[screen_row - 1] = TRUE; | |
5219 | |
5220 /* | |
5221 * Special trick to make copy/paste of wrapped lines work with | |
5222 * xterm/screen: write an extra character beyond the end of | |
5223 * the line. This will work with all terminal types | |
5224 * (regardless of the xn,am settings). | |
5225 * Only do this on a fast tty. | |
5226 * Only do this if the cursor is on the current line | |
5227 * (something has been written in it). | |
5228 * Don't do this for the GUI. | |
5229 * Don't do this for double-width characters. | |
5230 * Don't do this for a window not at the right screen border. | |
5231 */ | |
5232 if (p_tf | |
5233 #ifdef FEAT_GUI | |
5234 && !gui.in_use | |
5235 #endif | |
5236 #ifdef FEAT_MBYTE | |
5237 && !(has_mbyte | |
1378 | 5238 && ((*mb_off2cells)(LineOffset[screen_row], |
5239 LineOffset[screen_row] + screen_Columns) | |
5240 == 2 | |
7 | 5241 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5242 + (int)Columns - 2, |
5243 LineOffset[screen_row] + screen_Columns) | |
5244 == 2)) | |
7 | 5245 #endif |
5246 ) | |
5247 { | |
5248 /* First make sure we are at the end of the screen line, | |
5249 * then output the same character again to let the | |
5250 * terminal know about the wrap. If the terminal doesn't | |
5251 * auto-wrap, we overwrite the character. */ | |
5252 if (screen_cur_col != W_WIDTH(wp)) | |
5253 screen_char(LineOffset[screen_row - 1] | |
5254 + (unsigned)Columns - 1, | |
5255 screen_row - 1, (int)(Columns - 1)); | |
5256 | |
5257 #ifdef FEAT_MBYTE | |
5258 /* When there is a multi-byte character, just output a | |
5259 * space to keep it simple. */ | |
148 | 5260 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5261 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5262 out_char(' '); |
5263 else | |
5264 #endif | |
5265 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5266 + (Columns - 1)]); | |
5267 /* force a redraw of the first char on the next line */ | |
5268 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5269 screen_start(); /* don't know where cursor is now */ | |
5270 } | |
5271 } | |
5272 | |
5273 col = 0; | |
5274 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5275 #ifdef FEAT_RIGHTLEFT | |
5276 if (wp->w_p_rl) | |
5277 { | |
5278 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5279 off += col; | |
5280 } | |
5281 #endif | |
5282 | |
5283 /* reset the drawing state for the start of a wrapped line */ | |
5284 draw_state = WL_START; | |
5285 saved_n_extra = n_extra; | |
5286 saved_p_extra = p_extra; | |
5287 saved_c_extra = c_extra; | |
5288 saved_char_attr = char_attr; | |
5289 n_extra = 0; | |
5290 lcs_prec_todo = lcs_prec; | |
5291 #ifdef FEAT_LINEBREAK | |
5292 # ifdef FEAT_DIFF | |
5293 if (filler_todo <= 0) | |
5294 # endif | |
5295 need_showbreak = TRUE; | |
5296 #endif | |
5297 #ifdef FEAT_DIFF | |
5298 --filler_todo; | |
5299 /* When the filler lines are actually below the last line of the | |
5300 * file, don't draw the line itself, break here. */ | |
5301 if (filler_todo == 0 && wp->w_botfill) | |
5302 break; | |
5303 #endif | |
5304 } | |
5305 | |
5306 } /* for every character in the line */ | |
5307 | |
743 | 5308 #ifdef FEAT_SPELL |
386 | 5309 /* After an empty line check first word for capital. */ |
5310 if (*skipwhite(line) == NUL) | |
5311 { | |
5312 capcol_lnum = lnum + 1; | |
5313 cap_col = 0; | |
5314 } | |
5315 #endif | |
5316 | |
7 | 5317 return row; |
5318 } | |
5319 | |
714 | 5320 #ifdef FEAT_MBYTE |
5321 static int comp_char_differs __ARGS((int, int)); | |
5322 | |
5323 /* | |
5324 * 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
|
5325 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5326 */ |
5327 static int | |
5328 comp_char_differs(off_from, off_to) | |
5329 int off_from; | |
5330 int off_to; | |
5331 { | |
5332 int i; | |
5333 | |
5334 for (i = 0; i < Screen_mco; ++i) | |
5335 { | |
5336 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5337 return TRUE; | |
5338 if (ScreenLinesC[i][off_from] == 0) | |
5339 break; | |
5340 } | |
5341 return FALSE; | |
5342 } | |
5343 #endif | |
5344 | |
7 | 5345 /* |
5346 * Check whether the given character needs redrawing: | |
5347 * - the (first byte of the) character is different | |
5348 * - the attributes are different | |
5349 * - the character is multi-byte and the next byte is different | |
1616 | 5350 * - the character is two cells wide and the second cell differs. |
7 | 5351 */ |
5352 static int | |
5353 char_needs_redraw(off_from, off_to, cols) | |
5354 int off_from; | |
5355 int off_to; | |
5356 int cols; | |
5357 { | |
5358 if (cols > 0 | |
5359 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5360 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5361 | |
5362 #ifdef FEAT_MBYTE | |
5363 || (enc_dbcs != 0 | |
5364 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5365 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5366 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5367 : (cols > 1 && ScreenLines[off_from + 1] | |
5368 != ScreenLines[off_to + 1]))) | |
5369 || (enc_utf8 | |
5370 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5371 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5372 && comp_char_differs(off_from, off_to)) |
3759 | 5373 || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
5374 && ScreenLines[off_from + 1] | |
5375 != ScreenLines[off_to + 1]))) | |
7 | 5376 #endif |
5377 )) | |
5378 return TRUE; | |
5379 return FALSE; | |
5380 } | |
5381 | |
5382 /* | |
5383 * Move one "cooked" screen line to the screen, but only the characters that | |
5384 * have actually changed. Handle insert/delete character. | |
5385 * "coloff" gives the first column on the screen for this line. | |
5386 * "endcol" gives the columns where valid characters are. | |
5387 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5388 * needs to be cleared, negative otherwise. | |
5389 * "rlflag" is TRUE in a rightleft window: | |
5390 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5391 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5392 */ | |
5393 static void | |
5394 screen_line(row, coloff, endcol, clear_width | |
5395 #ifdef FEAT_RIGHTLEFT | |
5396 , rlflag | |
5397 #endif | |
5398 ) | |
5399 int row; | |
5400 int coloff; | |
5401 int endcol; | |
5402 int clear_width; | |
5403 #ifdef FEAT_RIGHTLEFT | |
5404 int rlflag; | |
5405 #endif | |
5406 { | |
5407 unsigned off_from; | |
5408 unsigned off_to; | |
1378 | 5409 #ifdef FEAT_MBYTE |
5410 unsigned max_off_from; | |
5411 unsigned max_off_to; | |
5412 #endif | |
7 | 5413 int col = 0; |
5414 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5415 int hl; | |
5416 #endif | |
5417 int force = FALSE; /* force update rest of the line */ | |
5418 int redraw_this /* bool: does character need redraw? */ | |
5419 #ifdef FEAT_GUI | |
5420 = TRUE /* For GUI when while-loop empty */ | |
5421 #endif | |
5422 ; | |
5423 int redraw_next; /* redraw_this for next character */ | |
5424 #ifdef FEAT_MBYTE | |
5425 int clear_next = FALSE; | |
5426 int char_cells; /* 1: normal char */ | |
5427 /* 2: occupies two display cells */ | |
5428 # define CHAR_CELLS char_cells | |
5429 #else | |
5430 # define CHAR_CELLS 1 | |
5431 #endif | |
5432 | |
3413 | 5433 /* Check for illegal row and col, just in case. */ |
5434 if (row >= Rows) | |
5435 row = Rows - 1; | |
5436 if (endcol > Columns) | |
5437 endcol = Columns; | |
5438 | |
7 | 5439 # ifdef FEAT_CLIPBOARD |
5440 clip_may_clear_selection(row, row); | |
5441 # endif | |
5442 | |
5443 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5444 off_to = LineOffset[row] + coloff; | |
1378 | 5445 #ifdef FEAT_MBYTE |
5446 max_off_from = off_from + screen_Columns; | |
5447 max_off_to = LineOffset[row] + screen_Columns; | |
5448 #endif | |
7 | 5449 |
5450 #ifdef FEAT_RIGHTLEFT | |
5451 if (rlflag) | |
5452 { | |
5453 /* Clear rest first, because it's left of the text. */ | |
5454 if (clear_width > 0) | |
5455 { | |
5456 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5457 && ScreenAttrs[off_to] == 0 | |
5458 # ifdef FEAT_MBYTE | |
5459 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5460 # endif | |
5461 ) | |
5462 { | |
5463 ++off_to; | |
5464 ++col; | |
5465 } | |
5466 if (col <= endcol) | |
5467 screen_fill(row, row + 1, col + coloff, | |
5468 endcol + coloff + 1, ' ', ' ', 0); | |
5469 } | |
5470 col = endcol + 1; | |
5471 off_to = LineOffset[row] + col + coloff; | |
5472 off_from += col; | |
5473 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5474 } | |
5475 #endif /* FEAT_RIGHTLEFT */ | |
5476 | |
5477 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5478 | |
5479 while (col < endcol) | |
5480 { | |
5481 #ifdef FEAT_MBYTE | |
5482 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5483 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5484 else |
5485 char_cells = 1; | |
5486 #endif | |
5487 | |
5488 redraw_this = redraw_next; | |
5489 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5490 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5491 | |
5492 #ifdef FEAT_GUI | |
5493 /* If the next character was bold, then redraw the current character to | |
5494 * remove any pixels that might have spilt over into us. This only | |
5495 * happens in the GUI. | |
5496 */ | |
5497 if (redraw_next && gui.in_use) | |
5498 { | |
5499 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5500 if (hl > HL_ALL) |
5501 hl = syn_attr2attr(hl); | |
5502 if (hl & HL_BOLD) | |
7 | 5503 redraw_this = TRUE; |
5504 } | |
5505 #endif | |
5506 | |
5507 if (redraw_this) | |
5508 { | |
5509 /* | |
5510 * Special handling when 'xs' termcap flag set (hpterm): | |
5511 * Attributes for characters are stored at the position where the | |
5512 * cursor is when writing the highlighting code. The | |
5513 * start-highlighting code must be written with the cursor on the | |
5514 * first highlighted character. The stop-highlighting code must | |
5515 * be written with the cursor just after the last highlighted | |
5516 * character. | |
5517 * Overwriting a character doesn't remove it's highlighting. Need | |
5518 * to clear the rest of the line, and force redrawing it | |
5519 * completely. | |
5520 */ | |
5521 if ( p_wiv | |
5522 && !force | |
5523 #ifdef FEAT_GUI | |
5524 && !gui.in_use | |
5525 #endif | |
5526 && ScreenAttrs[off_to] != 0 | |
5527 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5528 { | |
5529 /* | |
5530 * Need to remove highlighting attributes here. | |
5531 */ | |
5532 windgoto(row, col + coloff); | |
5533 out_str(T_CE); /* clear rest of this screen line */ | |
5534 screen_start(); /* don't know where cursor is now */ | |
5535 force = TRUE; /* force redraw of rest of the line */ | |
5536 redraw_next = TRUE; /* or else next char would miss out */ | |
5537 | |
5538 /* | |
5539 * If the previous character was highlighted, need to stop | |
5540 * highlighting at this character. | |
5541 */ | |
5542 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5543 { | |
5544 screen_attr = ScreenAttrs[off_to - 1]; | |
5545 term_windgoto(row, col + coloff); | |
5546 screen_stop_highlight(); | |
5547 } | |
5548 else | |
5549 screen_attr = 0; /* highlighting has stopped */ | |
5550 } | |
5551 #ifdef FEAT_MBYTE | |
5552 if (enc_dbcs != 0) | |
5553 { | |
5554 /* Check if overwriting a double-byte with a single-byte or | |
5555 * the other way around requires another character to be | |
5556 * redrawn. For UTF-8 this isn't needed, because comparing | |
5557 * ScreenLinesUC[] is sufficient. */ | |
5558 if (char_cells == 1 | |
5559 && col + 1 < endcol | |
1378 | 5560 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5561 { |
5562 /* Writing a single-cell character over a double-cell | |
5563 * character: need to redraw the next cell. */ | |
5564 ScreenLines[off_to + 1] = 0; | |
5565 redraw_next = TRUE; | |
5566 } | |
5567 else if (char_cells == 2 | |
5568 && col + 2 < endcol | |
1378 | 5569 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5570 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5571 { |
5572 /* Writing the second half of a double-cell character over | |
5573 * a double-cell character: need to redraw the second | |
5574 * cell. */ | |
5575 ScreenLines[off_to + 2] = 0; | |
5576 redraw_next = TRUE; | |
5577 } | |
5578 | |
5579 if (enc_dbcs == DBCS_JPNU) | |
5580 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5581 } | |
5582 /* When writing a single-width character over a double-width | |
5583 * character and at the end of the redrawn text, need to clear out | |
5584 * the right halve of the old character. | |
5585 * Also required when writing the right halve of a double-width | |
5586 * char over the left halve of an existing one. */ | |
5587 if (has_mbyte && col + char_cells == endcol | |
5588 && ((char_cells == 1 | |
1378 | 5589 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5590 || (char_cells == 2 |
1378 | 5591 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5592 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5593 clear_next = TRUE; |
5594 #endif | |
5595 | |
5596 ScreenLines[off_to] = ScreenLines[off_from]; | |
5597 #ifdef FEAT_MBYTE | |
5598 if (enc_utf8) | |
5599 { | |
5600 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5601 if (ScreenLinesUC[off_from] != 0) | |
5602 { | |
714 | 5603 int i; |
5604 | |
5605 for (i = 0; i < Screen_mco; ++i) | |
5606 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5607 } |
5608 } | |
5609 if (char_cells == 2) | |
5610 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5611 #endif | |
5612 | |
5613 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5614 /* The bold trick makes a single column of pixels appear in the |
5615 * next character. When a bold character is removed, the next | |
7 | 5616 * character should be redrawn too. This happens for our own GUI |
5617 * and for some xterms. */ | |
5618 if ( | |
5619 # ifdef FEAT_GUI | |
5620 gui.in_use | |
5621 # endif | |
5622 # if defined(FEAT_GUI) && defined(UNIX) | |
5623 || | |
5624 # endif | |
5625 # ifdef UNIX | |
5626 term_is_xterm | |
5627 # endif | |
5628 ) | |
5629 { | |
5630 hl = ScreenAttrs[off_to]; | |
743 | 5631 if (hl > HL_ALL) |
5632 hl = syn_attr2attr(hl); | |
5633 if (hl & HL_BOLD) | |
7 | 5634 redraw_next = TRUE; |
5635 } | |
5636 #endif | |
5637 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5638 #ifdef FEAT_MBYTE | |
819 | 5639 /* For simplicity set the attributes of second half of a |
5640 * double-wide character equal to the first half. */ | |
5641 if (char_cells == 2) | |
5642 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5643 | |
7 | 5644 if (enc_dbcs != 0 && char_cells == 2) |
5645 screen_char_2(off_to, row, col + coloff); | |
5646 else | |
5647 #endif | |
5648 screen_char(off_to, row, col + coloff); | |
5649 } | |
5650 else if ( p_wiv | |
5651 #ifdef FEAT_GUI | |
5652 && !gui.in_use | |
5653 #endif | |
5654 && col + coloff > 0) | |
5655 { | |
5656 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5657 { | |
5658 /* | |
5659 * Don't output stop-highlight when moving the cursor, it will | |
5660 * stop the highlighting when it should continue. | |
5661 */ | |
5662 screen_attr = 0; | |
5663 } | |
5664 else if (screen_attr != 0) | |
5665 screen_stop_highlight(); | |
5666 } | |
5667 | |
5668 off_to += CHAR_CELLS; | |
5669 off_from += CHAR_CELLS; | |
5670 col += CHAR_CELLS; | |
5671 } | |
5672 | |
5673 #ifdef FEAT_MBYTE | |
5674 if (clear_next) | |
5675 { | |
5676 /* Clear the second half of a double-wide character of which the left | |
5677 * half was overwritten with a single-wide character. */ | |
5678 ScreenLines[off_to] = ' '; | |
5679 if (enc_utf8) | |
5680 ScreenLinesUC[off_to] = 0; | |
5681 screen_char(off_to, row, col + coloff); | |
5682 } | |
5683 #endif | |
5684 | |
5685 if (clear_width > 0 | |
5686 #ifdef FEAT_RIGHTLEFT | |
5687 && !rlflag | |
5688 #endif | |
5689 ) | |
5690 { | |
5691 #ifdef FEAT_GUI | |
5692 int startCol = col; | |
5693 #endif | |
5694 | |
5695 /* blank out the rest of the line */ | |
5696 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5697 && ScreenAttrs[off_to] == 0 | |
5698 #ifdef FEAT_MBYTE | |
5699 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5700 #endif | |
5701 ) | |
5702 { | |
5703 ++off_to; | |
5704 ++col; | |
5705 } | |
5706 if (col < clear_width) | |
5707 { | |
5708 #ifdef FEAT_GUI | |
5709 /* | |
5710 * In the GUI, clearing the rest of the line may leave pixels | |
5711 * behind if the first character cleared was bold. Some bold | |
5712 * fonts spill over the left. In this case we redraw the previous | |
5713 * character too. If we didn't skip any blanks above, then we | |
5714 * only redraw if the character wasn't already redrawn anyway. | |
5715 */ | |
996 | 5716 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5717 { |
5718 hl = ScreenAttrs[off_to]; | |
5719 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5720 { |
5721 int prev_cells = 1; | |
5722 # ifdef FEAT_MBYTE | |
5723 if (enc_utf8) | |
5724 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5725 * that its width is 2. */ | |
5726 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5727 else if (enc_dbcs != 0) | |
5728 { | |
5729 /* find previous character by counting from first | |
5730 * column and get its width. */ | |
5731 unsigned off = LineOffset[row]; | |
1378 | 5732 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5733 |
5734 while (off < off_to) | |
5735 { | |
1378 | 5736 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5737 off += prev_cells; |
5738 } | |
5739 } | |
5740 | |
5741 if (enc_dbcs != 0 && prev_cells > 1) | |
5742 screen_char_2(off_to - prev_cells, row, | |
5743 col + coloff - prev_cells); | |
5744 else | |
5745 # endif | |
5746 screen_char(off_to - prev_cells, row, | |
5747 col + coloff - prev_cells); | |
5748 } | |
7 | 5749 } |
5750 #endif | |
5751 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5752 ' ', ' ', 0); | |
5753 #ifdef FEAT_VERTSPLIT | |
5754 off_to += clear_width - col; | |
5755 col = clear_width; | |
5756 #endif | |
5757 } | |
5758 } | |
5759 | |
5760 if (clear_width > 0) | |
5761 { | |
5762 #ifdef FEAT_VERTSPLIT | |
5763 /* For a window that's left of another, draw the separator char. */ | |
5764 if (col + coloff < Columns) | |
5765 { | |
5766 int c; | |
5767 | |
5768 c = fillchar_vsep(&hl); | |
5769 if (ScreenLines[off_to] != c | |
5770 # ifdef FEAT_MBYTE | |
714 | 5771 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5772 != (c >= 0x80 ? c : 0)) | |
7 | 5773 # endif |
5774 || ScreenAttrs[off_to] != hl) | |
5775 { | |
5776 ScreenLines[off_to] = c; | |
5777 ScreenAttrs[off_to] = hl; | |
5778 # ifdef FEAT_MBYTE | |
5779 if (enc_utf8) | |
5780 { | |
5781 if (c >= 0x80) | |
5782 { | |
5783 ScreenLinesUC[off_to] = c; | |
714 | 5784 ScreenLinesC[0][off_to] = 0; |
7 | 5785 } |
5786 else | |
5787 ScreenLinesUC[off_to] = 0; | |
5788 } | |
5789 # endif | |
5790 screen_char(off_to, row, col + coloff); | |
5791 } | |
5792 } | |
5793 else | |
5794 #endif | |
5795 LineWraps[row] = FALSE; | |
5796 } | |
5797 } | |
5798 | |
474 | 5799 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5800 /* |
474 | 5801 * Mirror text "str" for right-left displaying. |
5802 * Only works for single-byte characters (e.g., numbers). | |
7 | 5803 */ |
474 | 5804 void |
7 | 5805 rl_mirror(str) |
5806 char_u *str; | |
5807 { | |
5808 char_u *p1, *p2; | |
5809 int t; | |
5810 | |
5811 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5812 { | |
5813 t = *p1; | |
5814 *p1 = *p2; | |
5815 *p2 = t; | |
5816 } | |
5817 } | |
5818 #endif | |
5819 | |
5820 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5821 /* | |
5822 * mark all status lines for redraw; used after first :cd | |
5823 */ | |
5824 void | |
5825 status_redraw_all() | |
5826 { | |
5827 win_T *wp; | |
5828 | |
5829 for (wp = firstwin; wp; wp = wp->w_next) | |
5830 if (wp->w_status_height) | |
5831 { | |
5832 wp->w_redr_status = TRUE; | |
5833 redraw_later(VALID); | |
5834 } | |
5835 } | |
5836 | |
5837 /* | |
5838 * mark all status lines of the current buffer for redraw | |
5839 */ | |
5840 void | |
5841 status_redraw_curbuf() | |
5842 { | |
5843 win_T *wp; | |
5844 | |
5845 for (wp = firstwin; wp; wp = wp->w_next) | |
5846 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5847 { | |
5848 wp->w_redr_status = TRUE; | |
5849 redraw_later(VALID); | |
5850 } | |
5851 } | |
5852 | |
5853 /* | |
5854 * Redraw all status lines that need to be redrawn. | |
5855 */ | |
5856 void | |
5857 redraw_statuslines() | |
5858 { | |
5859 win_T *wp; | |
5860 | |
5861 for (wp = firstwin; wp; wp = wp->w_next) | |
5862 if (wp->w_redr_status) | |
5863 win_redr_status(wp); | |
673 | 5864 if (redraw_tabline) |
677 | 5865 draw_tabline(); |
7 | 5866 } |
5867 #endif | |
5868 | |
5869 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5870 /* | |
5871 * Redraw all status lines at the bottom of frame "frp". | |
5872 */ | |
5873 void | |
5874 win_redraw_last_status(frp) | |
5875 frame_T *frp; | |
5876 { | |
5877 if (frp->fr_layout == FR_LEAF) | |
5878 frp->fr_win->w_redr_status = TRUE; | |
5879 else if (frp->fr_layout == FR_ROW) | |
5880 { | |
5881 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5882 win_redraw_last_status(frp); | |
5883 } | |
5884 else /* frp->fr_layout == FR_COL */ | |
5885 { | |
5886 frp = frp->fr_child; | |
5887 while (frp->fr_next != NULL) | |
5888 frp = frp->fr_next; | |
5889 win_redraw_last_status(frp); | |
5890 } | |
5891 } | |
5892 #endif | |
5893 | |
5894 #ifdef FEAT_VERTSPLIT | |
5895 /* | |
5896 * Draw the verticap separator right of window "wp" starting with line "row". | |
5897 */ | |
5898 static void | |
5899 draw_vsep_win(wp, row) | |
5900 win_T *wp; | |
5901 int row; | |
5902 { | |
5903 int hl; | |
5904 int c; | |
5905 | |
5906 if (wp->w_vsep_width) | |
5907 { | |
5908 /* draw the vertical separator right of this window */ | |
5909 c = fillchar_vsep(&hl); | |
5910 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5911 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5912 c, ' ', hl); | |
5913 } | |
5914 } | |
5915 #endif | |
5916 | |
5917 #ifdef FEAT_WILDMENU | |
5918 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5919 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5920 |
5921 /* | |
1378 | 5922 * Get the length of an item as it will be shown in the status line. |
7 | 5923 */ |
5924 static int | |
5925 status_match_len(xp, s) | |
5926 expand_T *xp; | |
5927 char_u *s; | |
5928 { | |
5929 int len = 0; | |
5930 | |
5931 #ifdef FEAT_MENU | |
5932 int emenu = (xp->xp_context == EXPAND_MENUS | |
5933 || xp->xp_context == EXPAND_MENUNAMES); | |
5934 | |
5935 /* Check for menu separators - replace with '|'. */ | |
5936 if (emenu && menu_is_separator(s)) | |
5937 return 1; | |
5938 #endif | |
5939 | |
5940 while (*s != NUL) | |
5941 { | |
1685 | 5942 s += skip_status_match_char(xp, s); |
42 | 5943 len += ptr2cells(s); |
39 | 5944 mb_ptr_adv(s); |
7 | 5945 } |
5946 | |
5947 return len; | |
5948 } | |
5949 | |
5950 /* | |
1685 | 5951 * Return the number of characters that should be skipped in a status match. |
277 | 5952 * These are backslashes used for escaping. Do show backslashes in help tags. |
5953 */ | |
5954 static int | |
5955 skip_status_match_char(xp, s) | |
5956 expand_T *xp; | |
5957 char_u *s; | |
5958 { | |
1685 | 5959 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5960 #ifdef FEAT_MENU |
5961 || ((xp->xp_context == EXPAND_MENUS | |
5962 || xp->xp_context == EXPAND_MENUNAMES) | |
5963 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5964 #endif | |
1685 | 5965 ) |
5966 { | |
5967 #ifndef BACKSLASH_IN_FILENAME | |
5968 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5969 return 2; | |
5970 #endif | |
5971 return 1; | |
5972 } | |
5973 return 0; | |
277 | 5974 } |
5975 | |
5976 /* | |
7 | 5977 * Show wildchar matches in the status line. |
5978 * Show at least the "match" item. | |
5979 * We start at item 'first_match' in the list and show all matches that fit. | |
5980 * | |
5981 * If inversion is possible we use it. Else '=' characters are used. | |
5982 */ | |
5983 void | |
5984 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5985 expand_T *xp; | |
5986 int num_matches; | |
5987 char_u **matches; /* list of matches */ | |
5988 int match; | |
5989 int showtail; | |
5990 { | |
5991 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5992 int row; | |
5993 char_u *buf; | |
5994 int len; | |
1378 | 5995 int clen; /* length in screen cells */ |
7 | 5996 int fillchar; |
5997 int attr; | |
5998 int i; | |
5999 int highlight = TRUE; | |
6000 char_u *selstart = NULL; | |
6001 int selstart_col = 0; | |
6002 char_u *selend = NULL; | |
6003 static int first_match = 0; | |
6004 int add_left = FALSE; | |
6005 char_u *s; | |
6006 #ifdef FEAT_MENU | |
6007 int emenu; | |
6008 #endif | |
6009 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
6010 int l; | |
6011 #endif | |
6012 | |
6013 if (matches == NULL) /* interrupted completion? */ | |
6014 return; | |
6015 | |
39 | 6016 #ifdef FEAT_MBYTE |
6017 if (has_mbyte) | |
6018 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
6019 else | |
6020 #endif | |
6021 buf = alloc((unsigned)Columns + 1); | |
7 | 6022 if (buf == NULL) |
6023 return; | |
6024 | |
6025 if (match == -1) /* don't show match but original text */ | |
6026 { | |
6027 match = 0; | |
6028 highlight = FALSE; | |
6029 } | |
6030 /* count 1 for the ending ">" */ | |
6031 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
6032 if (match == 0) | |
6033 first_match = 0; | |
6034 else if (match < first_match) | |
6035 { | |
6036 /* jumping left, as far as we can go */ | |
6037 first_match = match; | |
6038 add_left = TRUE; | |
6039 } | |
6040 else | |
6041 { | |
6042 /* check if match fits on the screen */ | |
6043 for (i = first_match; i < match; ++i) | |
6044 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
6045 if (first_match > 0) | |
6046 clen += 2; | |
6047 /* jumping right, put match at the left */ | |
6048 if ((long)clen > Columns) | |
6049 { | |
6050 first_match = match; | |
6051 /* if showing the last match, we can add some on the left */ | |
6052 clen = 2; | |
6053 for (i = match; i < num_matches; ++i) | |
6054 { | |
6055 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
6056 if ((long)clen >= Columns) | |
6057 break; | |
6058 } | |
6059 if (i == num_matches) | |
6060 add_left = TRUE; | |
6061 } | |
6062 } | |
6063 if (add_left) | |
6064 while (first_match > 0) | |
6065 { | |
6066 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
6067 if ((long)clen >= Columns) | |
6068 break; | |
6069 --first_match; | |
6070 } | |
6071 | |
6072 fillchar = fillchar_status(&attr, TRUE); | |
6073 | |
6074 if (first_match == 0) | |
6075 { | |
6076 *buf = NUL; | |
6077 len = 0; | |
6078 } | |
6079 else | |
6080 { | |
6081 STRCPY(buf, "< "); | |
6082 len = 2; | |
6083 } | |
6084 clen = len; | |
6085 | |
6086 i = first_match; | |
6087 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
6088 { | |
6089 if (i == match) | |
6090 { | |
6091 selstart = buf + len; | |
6092 selstart_col = clen; | |
6093 } | |
6094 | |
6095 s = L_MATCH(i); | |
6096 /* Check for menu separators - replace with '|' */ | |
6097 #ifdef FEAT_MENU | |
6098 emenu = (xp->xp_context == EXPAND_MENUS | |
6099 || xp->xp_context == EXPAND_MENUNAMES); | |
6100 if (emenu && menu_is_separator(s)) | |
6101 { | |
6102 STRCPY(buf + len, transchar('|')); | |
6103 l = (int)STRLEN(buf + len); | |
6104 len += l; | |
6105 clen += l; | |
6106 } | |
6107 else | |
6108 #endif | |
6109 for ( ; *s != NUL; ++s) | |
6110 { | |
1685 | 6111 s += skip_status_match_char(xp, s); |
7 | 6112 clen += ptr2cells(s); |
6113 #ifdef FEAT_MBYTE | |
474 | 6114 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 6115 { |
6116 STRNCPY(buf + len, s, l); | |
6117 s += l - 1; | |
6118 len += l; | |
6119 } | |
6120 else | |
6121 #endif | |
6122 { | |
6123 STRCPY(buf + len, transchar_byte(*s)); | |
6124 len += (int)STRLEN(buf + len); | |
6125 } | |
6126 } | |
6127 if (i == match) | |
6128 selend = buf + len; | |
6129 | |
6130 *(buf + len++) = ' '; | |
6131 *(buf + len++) = ' '; | |
6132 clen += 2; | |
6133 if (++i == num_matches) | |
6134 break; | |
6135 } | |
6136 | |
6137 if (i != num_matches) | |
6138 { | |
6139 *(buf + len++) = '>'; | |
6140 ++clen; | |
6141 } | |
6142 | |
6143 buf[len] = NUL; | |
6144 | |
6145 row = cmdline_row - 1; | |
6146 if (row >= 0) | |
6147 { | |
6148 if (wild_menu_showing == 0) | |
6149 { | |
6150 if (msg_scrolled > 0) | |
6151 { | |
6152 /* Put the wildmenu just above the command line. If there is | |
6153 * no room, scroll the screen one line up. */ | |
6154 if (cmdline_row == Rows - 1) | |
6155 { | |
6156 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6157 ++msg_scrolled; | |
6158 } | |
6159 else | |
6160 { | |
6161 ++cmdline_row; | |
6162 ++row; | |
6163 } | |
6164 wild_menu_showing = WM_SCROLLED; | |
6165 } | |
6166 else | |
6167 { | |
6168 /* Create status line if needed by setting 'laststatus' to 2. | |
6169 * Set 'winminheight' to zero to avoid that the window is | |
6170 * resized. */ | |
6171 if (lastwin->w_status_height == 0) | |
6172 { | |
6173 save_p_ls = p_ls; | |
6174 save_p_wmh = p_wmh; | |
6175 p_ls = 2; | |
6176 p_wmh = 0; | |
6177 last_status(FALSE); | |
6178 } | |
6179 wild_menu_showing = WM_SHOWN; | |
6180 } | |
6181 } | |
6182 | |
6183 screen_puts(buf, row, 0, attr); | |
6184 if (selstart != NULL && highlight) | |
6185 { | |
6186 *selend = NUL; | |
6187 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6188 } | |
6189 | |
6190 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6191 } | |
6192 | |
6193 #ifdef FEAT_VERTSPLIT | |
6194 win_redraw_last_status(topframe); | |
6195 #else | |
6196 lastwin->w_redr_status = TRUE; | |
6197 #endif | |
6198 vim_free(buf); | |
6199 } | |
6200 #endif | |
6201 | |
6202 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6203 /* | |
6204 * Redraw the status line of window wp. | |
6205 * | |
6206 * If inversion is possible we use it. Else '=' characters are used. | |
6207 */ | |
6208 void | |
6209 win_redr_status(wp) | |
6210 win_T *wp; | |
6211 { | |
6212 int row; | |
6213 char_u *p; | |
6214 int len; | |
6215 int fillchar; | |
6216 int attr; | |
6217 int this_ru_col; | |
1910 | 6218 static int busy = FALSE; |
6219 | |
6220 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6221 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6222 if (busy) | |
6223 return; | |
6224 busy = TRUE; | |
7 | 6225 |
6226 wp->w_redr_status = FALSE; | |
6227 if (wp->w_status_height == 0) | |
6228 { | |
6229 /* no status line, can only be last window */ | |
6230 redraw_cmdline = TRUE; | |
6231 } | |
540 | 6232 else if (!redrawing() |
6233 #ifdef FEAT_INS_EXPAND | |
6234 /* don't update status line when popup menu is visible and may be | |
6235 * drawn over it */ | |
6236 || pum_visible() | |
6237 #endif | |
6238 ) | |
7 | 6239 { |
6240 /* Don't redraw right now, do it later. */ | |
6241 wp->w_redr_status = TRUE; | |
6242 } | |
6243 #ifdef FEAT_STL_OPT | |
40 | 6244 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6245 { |
6246 /* redraw custom status line */ | |
1983 | 6247 redraw_custom_statusline(wp); |
7 | 6248 } |
6249 #endif | |
6250 else | |
6251 { | |
6252 fillchar = fillchar_status(&attr, wp == curwin); | |
6253 | |
685 | 6254 get_trans_bufname(wp->w_buffer); |
7 | 6255 p = NameBuff; |
6256 len = (int)STRLEN(p); | |
6257 | |
6258 if (wp->w_buffer->b_help | |
6259 #ifdef FEAT_QUICKFIX | |
6260 || wp->w_p_pvw | |
6261 #endif | |
6262 || bufIsChanged(wp->w_buffer) | |
6263 || wp->w_buffer->b_p_ro) | |
6264 *(p + len++) = ' '; | |
6265 if (wp->w_buffer->b_help) | |
6266 { | |
809 | 6267 STRCPY(p + len, _("[Help]")); |
7 | 6268 len += (int)STRLEN(p + len); |
6269 } | |
6270 #ifdef FEAT_QUICKFIX | |
6271 if (wp->w_p_pvw) | |
6272 { | |
6273 STRCPY(p + len, _("[Preview]")); | |
6274 len += (int)STRLEN(p + len); | |
6275 } | |
6276 #endif | |
6277 if (bufIsChanged(wp->w_buffer)) | |
6278 { | |
6279 STRCPY(p + len, "[+]"); | |
6280 len += 3; | |
6281 } | |
6282 if (wp->w_buffer->b_p_ro) | |
6283 { | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4736
diff
changeset
|
6284 STRCPY(p + len, _("[RO]")); |
7 | 6285 len += 4; |
6286 } | |
6287 | |
6288 #ifndef FEAT_VERTSPLIT | |
6289 this_ru_col = ru_col; | |
6290 if (this_ru_col < (Columns + 1) / 2) | |
6291 this_ru_col = (Columns + 1) / 2; | |
6292 #else | |
6293 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6294 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6295 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6296 if (this_ru_col <= 1) | |
6297 { | |
6298 p = (char_u *)"<"; /* No room for file name! */ | |
6299 len = 1; | |
6300 } | |
6301 else | |
6302 #endif | |
6303 #ifdef FEAT_MBYTE | |
6304 if (has_mbyte) | |
6305 { | |
6306 int clen = 0, i; | |
6307 | |
6308 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6309 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6310 |
7 | 6311 /* Find first character that will fit. |
6312 * Going from start to end is much faster for DBCS. */ | |
6313 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6314 i += (*mb_ptr2len)(p + i)) |
7 | 6315 clen -= (*mb_ptr2cells)(p + i); |
6316 len = clen; | |
6317 if (i > 0) | |
6318 { | |
6319 p = p + i - 1; | |
6320 *p = '<'; | |
6321 ++len; | |
6322 } | |
6323 | |
6324 } | |
6325 else | |
6326 #endif | |
6327 if (len > this_ru_col - 1) | |
6328 { | |
6329 p += len - (this_ru_col - 1); | |
6330 *p = '<'; | |
6331 len = this_ru_col - 1; | |
6332 } | |
6333 | |
6334 row = W_WINROW(wp) + wp->w_height; | |
6335 screen_puts(p, row, W_WINCOL(wp), attr); | |
6336 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6337 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6338 | |
6339 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6340 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6341 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6342 - 1 + W_WINCOL(wp)), attr); | |
6343 | |
6344 #ifdef FEAT_CMDL_INFO | |
6345 win_redr_ruler(wp, TRUE); | |
6346 #endif | |
6347 } | |
6348 | |
6349 #ifdef FEAT_VERTSPLIT | |
6350 /* | |
6351 * May need to draw the character below the vertical separator. | |
6352 */ | |
6353 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6354 { | |
6355 if (stl_connected(wp)) | |
6356 fillchar = fillchar_status(&attr, wp == curwin); | |
6357 else | |
6358 fillchar = fillchar_vsep(&attr); | |
6359 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6360 attr); | |
6361 } | |
6362 #endif | |
1910 | 6363 busy = FALSE; |
7 | 6364 } |
6365 | |
680 | 6366 #ifdef FEAT_STL_OPT |
6367 /* | |
6368 * Redraw the status line according to 'statusline' and take care of any | |
6369 * errors encountered. | |
6370 */ | |
6371 static void | |
1983 | 6372 redraw_custom_statusline(wp) |
680 | 6373 win_T *wp; |
6374 { | |
1983 | 6375 static int entered = FALSE; |
6376 int save_called_emsg = called_emsg; | |
6377 | |
6378 /* When called recursively return. This can happen when the statusline | |
6379 * contains an expression that triggers a redraw. */ | |
6380 if (entered) | |
6381 return; | |
6382 entered = TRUE; | |
680 | 6383 |
6384 called_emsg = FALSE; | |
6385 win_redr_custom(wp, FALSE); | |
6386 if (called_emsg) | |
1983 | 6387 { |
6388 /* When there is an error disable the statusline, otherwise the | |
6389 * display is messed up with errors and a redraw triggers the problem | |
6390 * again and again. */ | |
680 | 6391 set_string_option_direct((char_u *)"statusline", -1, |
6392 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6393 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6394 } |
680 | 6395 called_emsg |= save_called_emsg; |
1983 | 6396 entered = FALSE; |
680 | 6397 } |
6398 #endif | |
6399 | |
7 | 6400 # ifdef FEAT_VERTSPLIT |
6401 /* | |
6402 * Return TRUE if the status line of window "wp" is connected to the status | |
6403 * line of the window right of it. If not, then it's a vertical separator. | |
6404 * Only call if (wp->w_vsep_width != 0). | |
6405 */ | |
6406 int | |
6407 stl_connected(wp) | |
6408 win_T *wp; | |
6409 { | |
6410 frame_T *fr; | |
6411 | |
6412 fr = wp->w_frame; | |
6413 while (fr->fr_parent != NULL) | |
6414 { | |
6415 if (fr->fr_parent->fr_layout == FR_COL) | |
6416 { | |
6417 if (fr->fr_next != NULL) | |
6418 break; | |
6419 } | |
6420 else | |
6421 { | |
6422 if (fr->fr_next != NULL) | |
6423 return TRUE; | |
6424 } | |
6425 fr = fr->fr_parent; | |
6426 } | |
6427 return FALSE; | |
6428 } | |
6429 # endif | |
6430 | |
6431 #endif /* FEAT_WINDOWS */ | |
6432 | |
6433 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6434 /* | |
6435 * Get the value to show for the language mappings, active 'keymap'. | |
6436 */ | |
6437 int | |
6438 get_keymap_str(wp, buf, len) | |
6439 win_T *wp; | |
6440 char_u *buf; /* buffer for the result */ | |
6441 int len; /* length of buffer */ | |
6442 { | |
6443 char_u *p; | |
6444 | |
6445 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6446 return FALSE; | |
6447 | |
6448 { | |
6449 #ifdef FEAT_EVAL | |
6450 buf_T *old_curbuf = curbuf; | |
6451 win_T *old_curwin = curwin; | |
6452 char_u *s; | |
6453 | |
6454 curbuf = wp->w_buffer; | |
6455 curwin = wp; | |
6456 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6457 ++emsg_skip; | |
714 | 6458 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6459 --emsg_skip; |
6460 curbuf = old_curbuf; | |
6461 curwin = old_curwin; | |
6462 if (p == NULL || *p == NUL) | |
6463 #endif | |
6464 { | |
6465 #ifdef FEAT_KEYMAP | |
6466 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6467 p = wp->w_buffer->b_p_keymap; | |
6468 else | |
6469 #endif | |
6470 p = (char_u *)"lang"; | |
6471 } | |
6472 if ((int)(STRLEN(p) + 3) < len) | |
6473 sprintf((char *)buf, "<%s>", p); | |
6474 else | |
6475 buf[0] = NUL; | |
6476 #ifdef FEAT_EVAL | |
6477 vim_free(s); | |
6478 #endif | |
6479 } | |
6480 return buf[0] != NUL; | |
6481 } | |
6482 #endif | |
6483 | |
6484 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6485 /* | |
677 | 6486 * Redraw the status line or ruler of window "wp". |
6487 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6488 */ |
6489 static void | |
574 | 6490 win_redr_custom(wp, draw_ruler) |
7 | 6491 win_T *wp; |
574 | 6492 int draw_ruler; /* TRUE or FALSE */ |
7 | 6493 { |
6494 int attr; | |
6495 int curattr; | |
6496 int row; | |
6497 int col = 0; | |
6498 int maxwidth; | |
6499 int width; | |
6500 int n; | |
6501 int len; | |
6502 int fillchar; | |
6503 char_u buf[MAXPATHL]; | |
1983 | 6504 char_u *stl; |
7 | 6505 char_u *p; |
681 | 6506 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6507 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6508 int use_sandbox = FALSE; |
2693 | 6509 win_T *ewp; |
6510 int p_crb_save; | |
7 | 6511 |
6512 /* setup environment for the task at hand */ | |
677 | 6513 if (wp == NULL) |
6514 { | |
6515 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6516 stl = p_tal; |
677 | 6517 row = 0; |
707 | 6518 fillchar = ' '; |
677 | 6519 attr = hl_attr(HLF_TPF); |
6520 maxwidth = Columns; | |
6521 # ifdef FEAT_EVAL | |
681 | 6522 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6523 # endif |
6524 } | |
40 | 6525 else |
677 | 6526 { |
6527 row = W_WINROW(wp) + wp->w_height; | |
6528 fillchar = fillchar_status(&attr, wp == curwin); | |
6529 maxwidth = W_WIDTH(wp); | |
6530 | |
6531 if (draw_ruler) | |
6532 { | |
1983 | 6533 stl = p_ruf; |
677 | 6534 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6535 if (*stl == '%') |
6536 { | |
6537 if (*++stl == '-') | |
6538 stl++; | |
6539 if (atoi((char *)stl)) | |
6540 while (VIM_ISDIGIT(*stl)) | |
6541 stl++; | |
6542 if (*stl++ != '(') | |
6543 stl = p_ruf; | |
677 | 6544 } |
7 | 6545 #ifdef FEAT_VERTSPLIT |
677 | 6546 col = ru_col - (Columns - W_WIDTH(wp)); |
6547 if (col < (W_WIDTH(wp) + 1) / 2) | |
6548 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6549 #else |
677 | 6550 col = ru_col; |
6551 if (col > (Columns + 1) / 2) | |
6552 col = (Columns + 1) / 2; | |
6553 #endif | |
6554 maxwidth = W_WIDTH(wp) - col; | |
7 | 6555 #ifdef FEAT_WINDOWS |
677 | 6556 if (!wp->w_status_height) |
6557 #endif | |
6558 { | |
6559 row = Rows - 1; | |
6560 --maxwidth; /* writing in last column may cause scrolling */ | |
6561 fillchar = ' '; | |
6562 attr = 0; | |
6563 } | |
6564 | |
6565 # ifdef FEAT_EVAL | |
681 | 6566 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6567 # endif |
6568 } | |
6569 else | |
6570 { | |
6571 if (*wp->w_p_stl != NUL) | |
1983 | 6572 stl = wp->w_p_stl; |
677 | 6573 else |
1983 | 6574 stl = p_stl; |
677 | 6575 # ifdef FEAT_EVAL |
681 | 6576 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6577 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6578 # endif |
6579 } | |
6580 | |
6581 #ifdef FEAT_VERTSPLIT | |
6582 col += W_WINCOL(wp); | |
6583 #endif | |
6584 } | |
6585 | |
7 | 6586 if (maxwidth <= 0) |
6587 return; | |
677 | 6588 |
2693 | 6589 /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
6590 * the cursor away and back. */ | |
6591 ewp = wp == NULL ? curwin : wp; | |
6592 p_crb_save = ewp->w_p_crb; | |
6593 ewp->w_p_crb = FALSE; | |
6594 | |
1983 | 6595 /* Make a copy, because the statusline may include a function call that |
6596 * might change the option value and free the memory. */ | |
6597 stl = vim_strsave(stl); | |
2693 | 6598 width = build_stl_str_hl(ewp, buf, sizeof(buf), |
1983 | 6599 stl, use_sandbox, |
681 | 6600 fillchar, maxwidth, hltab, tabtab); |
1983 | 6601 vim_free(stl); |
2693 | 6602 ewp->w_p_crb = p_crb_save; |
2661 | 6603 |
6604 /* Make all characters printable. */ | |
6605 p = transstr(buf); | |
6606 if (p != NULL) | |
6607 { | |
6608 vim_strncpy(buf, p, sizeof(buf) - 1); | |
6609 vim_free(p); | |
6610 } | |
6611 | |
6612 /* fill up with "fillchar" */ | |
835 | 6613 len = (int)STRLEN(buf); |
1883 | 6614 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6615 { |
6616 #ifdef FEAT_MBYTE | |
6617 len += (*mb_char2bytes)(fillchar, buf + len); | |
6618 #else | |
6619 buf[len++] = fillchar; | |
6620 #endif | |
6621 ++width; | |
6622 } | |
6623 buf[len] = NUL; | |
6624 | |
681 | 6625 /* |
6626 * Draw each snippet with the specified highlighting. | |
6627 */ | |
7 | 6628 curattr = attr; |
6629 p = buf; | |
681 | 6630 for (n = 0; hltab[n].start != NULL; n++) |
6631 { | |
6632 len = (int)(hltab[n].start - p); | |
7 | 6633 screen_puts_len(p, len, row, col, curattr); |
6634 col += vim_strnsize(p, len); | |
681 | 6635 p = hltab[n].start; |
6636 | |
6637 if (hltab[n].userhl == 0) | |
7 | 6638 curattr = attr; |
681 | 6639 else if (hltab[n].userhl < 0) |
6640 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6641 #ifdef FEAT_WINDOWS |
680 | 6642 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6643 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6644 #endif |
6645 else | |
681 | 6646 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6647 } |
6648 screen_puts(p, row, col, curattr); | |
681 | 6649 |
6650 if (wp == NULL) | |
6651 { | |
6652 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6653 col = 0; | |
6654 len = 0; | |
6655 p = buf; | |
6656 fillchar = 0; | |
6657 for (n = 0; tabtab[n].start != NULL; n++) | |
6658 { | |
6659 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6660 while (col < len) | |
6661 TabPageIdxs[col++] = fillchar; | |
6662 p = tabtab[n].start; | |
6663 fillchar = tabtab[n].userhl; | |
6664 } | |
6665 while (col < Columns) | |
6666 TabPageIdxs[col++] = fillchar; | |
6667 } | |
7 | 6668 } |
6669 | |
6670 #endif /* FEAT_STL_OPT */ | |
6671 | |
6672 /* | |
6673 * Output a single character directly to the screen and update ScreenLines. | |
6674 */ | |
6675 void | |
6676 screen_putchar(c, row, col, attr) | |
6677 int c; | |
6678 int row, col; | |
6679 int attr; | |
6680 { | |
3549 | 6681 char_u buf[MB_MAXBYTES + 1]; |
6682 | |
7 | 6683 #ifdef FEAT_MBYTE |
3549 | 6684 if (has_mbyte) |
6685 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6686 else | |
6687 #endif | |
6688 { | |
6689 buf[0] = c; | |
6690 buf[1] = NUL; | |
6691 } | |
7 | 6692 screen_puts(buf, row, col, attr); |
6693 } | |
6694 | |
6695 /* | |
6696 * Get a single character directly from ScreenLines into "bytes[]". | |
6697 * Also return its attribute in *attrp; | |
6698 */ | |
6699 void | |
6700 screen_getbytes(row, col, bytes, attrp) | |
6701 int row, col; | |
6702 char_u *bytes; | |
6703 int *attrp; | |
6704 { | |
6705 unsigned off; | |
6706 | |
6707 /* safety check */ | |
6708 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6709 { | |
6710 off = LineOffset[row] + col; | |
6711 *attrp = ScreenAttrs[off]; | |
6712 bytes[0] = ScreenLines[off]; | |
6713 bytes[1] = NUL; | |
6714 | |
6715 #ifdef FEAT_MBYTE | |
6716 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6717 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6718 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6719 { | |
6720 bytes[0] = ScreenLines[off]; | |
6721 bytes[1] = ScreenLines2[off]; | |
6722 bytes[2] = NUL; | |
6723 } | |
6724 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6725 { | |
6726 bytes[1] = ScreenLines[off + 1]; | |
6727 bytes[2] = NUL; | |
6728 } | |
6729 #endif | |
6730 } | |
6731 } | |
6732 | |
714 | 6733 #ifdef FEAT_MBYTE |
6734 static int screen_comp_differs __ARGS((int, int*)); | |
6735 | |
6736 /* | |
6737 * Return TRUE if composing characters for screen posn "off" differs from | |
6738 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6739 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6740 */ |
6741 static int | |
6742 screen_comp_differs(off, u8cc) | |
6743 int off; | |
6744 int *u8cc; | |
6745 { | |
6746 int i; | |
6747 | |
6748 for (i = 0; i < Screen_mco; ++i) | |
6749 { | |
6750 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6751 return TRUE; | |
6752 if (u8cc[i] == 0) | |
6753 break; | |
6754 } | |
6755 return FALSE; | |
6756 } | |
6757 #endif | |
6758 | |
7 | 6759 /* |
6760 * Put string '*text' on the screen at position 'row' and 'col', with | |
6761 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6762 * Note: only outputs within one row, message is truncated at screen boundary! | |
6763 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6764 */ | |
6765 void | |
6766 screen_puts(text, row, col, attr) | |
6767 char_u *text; | |
6768 int row; | |
6769 int col; | |
6770 int attr; | |
6771 { | |
6772 screen_puts_len(text, -1, row, col, attr); | |
6773 } | |
6774 | |
6775 /* | |
6776 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6777 * a NUL. | |
6778 */ | |
6779 void | |
6780 screen_puts_len(text, len, row, col, attr) | |
6781 char_u *text; | |
6782 int len; | |
6783 int row; | |
6784 int col; | |
6785 int attr; | |
6786 { | |
6787 unsigned off; | |
6788 char_u *ptr = text; | |
6789 int c; | |
6790 #ifdef FEAT_MBYTE | |
1378 | 6791 unsigned max_off; |
7 | 6792 int mbyte_blen = 1; |
6793 int mbyte_cells = 1; | |
6794 int u8c = 0; | |
714 | 6795 int u8cc[MAX_MCO]; |
7 | 6796 int clear_next_cell = FALSE; |
6797 # ifdef FEAT_ARABIC | |
6798 int prev_c = 0; /* previous Arabic character */ | |
714 | 6799 int pc, nc, nc1; |
6800 int pcc[MAX_MCO]; | |
7 | 6801 # endif |
6802 #endif | |
1843 | 6803 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6804 int force_redraw_this; | |
6805 int force_redraw_next = FALSE; | |
6806 #endif | |
6807 int need_redraw; | |
7 | 6808 |
6809 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6810 return; | |
1843 | 6811 off = LineOffset[row] + col; |
7 | 6812 |
1668 | 6813 #ifdef FEAT_MBYTE |
6814 /* When drawing over the right halve of a double-wide char clear out the | |
6815 * left halve. Only needed in a terminal. */ | |
1685 | 6816 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6817 # ifdef FEAT_GUI |
6818 && !gui.in_use | |
6819 # endif | |
6820 && mb_fix_col(col, row) != col) | |
1843 | 6821 { |
6822 ScreenLines[off - 1] = ' '; | |
6823 ScreenAttrs[off - 1] = 0; | |
6824 if (enc_utf8) | |
6825 { | |
6826 ScreenLinesUC[off - 1] = 0; | |
6827 ScreenLinesC[0][off - 1] = 0; | |
6828 } | |
6829 /* redraw the previous cell, make it empty */ | |
6830 screen_char(off - 1, row, col - 1); | |
6831 /* force the cell at "col" to be redrawn */ | |
6832 force_redraw_next = TRUE; | |
6833 } | |
6834 #endif | |
6835 | |
1378 | 6836 #ifdef FEAT_MBYTE |
6837 max_off = LineOffset[row] + screen_Columns; | |
6838 #endif | |
1340 | 6839 while (col < screen_Columns |
6840 && (len < 0 || (int)(ptr - text) < len) | |
6841 && *ptr != NUL) | |
7 | 6842 { |
6843 c = *ptr; | |
6844 #ifdef FEAT_MBYTE | |
6845 /* check if this is the first byte of a multibyte */ | |
6846 if (has_mbyte) | |
6847 { | |
6848 if (enc_utf8 && len > 0) | |
474 | 6849 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6850 else |
474 | 6851 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6852 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6853 mbyte_cells = 1; | |
6854 else if (enc_dbcs != 0) | |
6855 mbyte_cells = mbyte_blen; | |
6856 else /* enc_utf8 */ | |
6857 { | |
6858 if (len >= 0) | |
714 | 6859 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6860 (int)((text + len) - ptr)); |
6861 else | |
714 | 6862 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6863 mbyte_cells = utf_char2cells(u8c); |
1401 | 6864 # ifdef UNICODE16 |
7 | 6865 /* Non-BMP character: display as ? or fullwidth ?. */ |
6866 if (u8c >= 0x10000) | |
6867 { | |
6868 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6869 if (attr == 0) | |
6870 attr = hl_attr(HLF_8); | |
6871 } | |
1401 | 6872 # endif |
7 | 6873 # ifdef FEAT_ARABIC |
6874 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6875 { | |
6876 /* Do Arabic shaping. */ | |
6877 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6878 { | |
6879 /* Past end of string to be displayed. */ | |
6880 nc = NUL; | |
6881 nc1 = NUL; | |
6882 } | |
6883 else | |
714 | 6884 { |
1994 | 6885 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6886 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6887 nc1 = pcc[0]; |
6888 } | |
7 | 6889 pc = prev_c; |
6890 prev_c = u8c; | |
714 | 6891 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6892 } |
6893 else | |
6894 prev_c = u8c; | |
6895 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6896 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6897 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6898 /* 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
|
6899 * 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
|
6900 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6901 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6902 } |
7 | 6903 } |
6904 } | |
6905 #endif | |
6906 | |
1843 | 6907 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6908 force_redraw_this = force_redraw_next; | |
6909 force_redraw_next = FALSE; | |
6910 #endif | |
6911 | |
6912 need_redraw = ScreenLines[off] != c | |
7 | 6913 #ifdef FEAT_MBYTE |
6914 || (mbyte_cells == 2 | |
6915 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6916 || (enc_dbcs == DBCS_JPNU | |
6917 && c == 0x8e | |
6918 && ScreenLines2[off] != ptr[1]) | |
6919 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6920 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6921 (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
|
6922 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6923 && screen_comp_differs(off, u8cc)))) |
7 | 6924 #endif |
6925 || ScreenAttrs[off] != attr | |
1843 | 6926 || exmode_active; |
6927 | |
6928 if (need_redraw | |
6929 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6930 || force_redraw_this | |
6931 #endif | |
7 | 6932 ) |
6933 { | |
6934 #if defined(FEAT_GUI) || defined(UNIX) | |
6935 /* The bold trick makes a single row of pixels appear in the next | |
6936 * character. When a bold character is removed, the next | |
6937 * character should be redrawn too. This happens for our own GUI | |
1843 | 6938 * and for some xterms. */ |
6939 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6940 # ifdef FEAT_GUI |
6941 gui.in_use | |
6942 # endif | |
6943 # if defined(FEAT_GUI) && defined(UNIX) | |
6944 || | |
6945 # endif | |
6946 # ifdef UNIX | |
6947 term_is_xterm | |
6948 # endif | |
1843 | 6949 )) |
6950 { | |
6951 int n = ScreenAttrs[off]; | |
6952 | |
6953 if (n > HL_ALL) | |
6954 n = syn_attr2attr(n); | |
6955 if (n & HL_BOLD) | |
6956 force_redraw_next = TRUE; | |
7 | 6957 } |
6958 #endif | |
6959 #ifdef FEAT_MBYTE | |
6960 /* When at the end of the text and overwriting a two-cell | |
6961 * character with a one-cell character, need to clear the next | |
6962 * cell. Also when overwriting the left halve of a two-cell char | |
6963 * with the right halve of a two-cell char. Do this only once | |
6964 * (mb_off2cells() may return 2 on the right halve). */ | |
6965 if (clear_next_cell) | |
6966 clear_next_cell = FALSE; | |
6967 else if (has_mbyte | |
6968 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6969 : ptr + mbyte_blen >= text + len) | |
1378 | 6970 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6971 || (mbyte_cells == 2 |
1378 | 6972 && (*mb_off2cells)(off, max_off) == 1 |
6973 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6974 clear_next_cell = TRUE; |
6975 | |
6976 /* Make sure we never leave a second byte of a double-byte behind, | |
6977 * it confuses mb_off2cells(). */ | |
6978 if (enc_dbcs | |
1378 | 6979 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6980 || (mbyte_cells == 2 |
1378 | 6981 && (*mb_off2cells)(off, max_off) == 1 |
6982 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6983 ScreenLines[off + mbyte_blen] = 0; |
6984 #endif | |
6985 ScreenLines[off] = c; | |
6986 ScreenAttrs[off] = attr; | |
6987 #ifdef FEAT_MBYTE | |
6988 if (enc_utf8) | |
6989 { | |
714 | 6990 if (c < 0x80 && u8cc[0] == 0) |
7 | 6991 ScreenLinesUC[off] = 0; |
6992 else | |
6993 { | |
714 | 6994 int i; |
6995 | |
7 | 6996 ScreenLinesUC[off] = u8c; |
714 | 6997 for (i = 0; i < Screen_mco; ++i) |
6998 { | |
6999 ScreenLinesC[i][off] = u8cc[i]; | |
7000 if (u8cc[i] == 0) | |
7001 break; | |
7002 } | |
7 | 7003 } |
7004 if (mbyte_cells == 2) | |
7005 { | |
7006 ScreenLines[off + 1] = 0; | |
7007 ScreenAttrs[off + 1] = attr; | |
7008 } | |
7009 screen_char(off, row, col); | |
7010 } | |
7011 else if (mbyte_cells == 2) | |
7012 { | |
7013 ScreenLines[off + 1] = ptr[1]; | |
7014 ScreenAttrs[off + 1] = attr; | |
7015 screen_char_2(off, row, col); | |
7016 } | |
7017 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
7018 { | |
7019 ScreenLines2[off] = ptr[1]; | |
7020 screen_char(off, row, col); | |
7021 } | |
7022 else | |
7023 #endif | |
7024 screen_char(off, row, col); | |
7025 } | |
7026 #ifdef FEAT_MBYTE | |
7027 if (has_mbyte) | |
7028 { | |
7029 off += mbyte_cells; | |
7030 col += mbyte_cells; | |
7031 ptr += mbyte_blen; | |
7032 if (clear_next_cell) | |
7033 ptr = (char_u *)" "; | |
7034 } | |
7035 else | |
7036 #endif | |
7037 { | |
7038 ++off; | |
7039 ++col; | |
7040 ++ptr; | |
7041 } | |
7042 } | |
1843 | 7043 |
7044 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
7045 /* If we detected the next character needs to be redrawn, but the text | |
7046 * doesn't extend up to there, update the character here. */ | |
7047 if (force_redraw_next && col < screen_Columns) | |
7048 { | |
7049 # ifdef FEAT_MBYTE | |
7050 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
7051 screen_char_2(off, row, col); | |
7052 else | |
7053 # endif | |
7054 screen_char(off, row, col); | |
7055 } | |
7056 #endif | |
7 | 7057 } |
7058 | |
7059 #ifdef FEAT_SEARCH_EXTRA | |
7060 /* | |
1326 | 7061 * Prepare for 'hlsearch' highlighting. |
7 | 7062 */ |
7063 static void | |
7064 start_search_hl() | |
7065 { | |
7066 if (p_hls && !no_hlsearch) | |
7067 { | |
7068 last_pat_prog(&search_hl.rm); | |
7069 search_hl.attr = hl_attr(HLF_L); | |
1521 | 7070 # ifdef FEAT_RELTIME |
7071 /* Set the time limit to 'redrawtime'. */ | |
7072 profile_setlimit(p_rdt, &search_hl.tm); | |
7073 # endif | |
7 | 7074 } |
7075 } | |
7076 | |
7077 /* | |
1326 | 7078 * Clean up for 'hlsearch' highlighting. |
7 | 7079 */ |
7080 static void | |
7081 end_search_hl() | |
7082 { | |
7083 if (search_hl.rm.regprog != NULL) | |
7084 { | |
7085 vim_free(search_hl.rm.regprog); | |
7086 search_hl.rm.regprog = NULL; | |
7087 } | |
7088 } | |
7089 | |
7090 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7091 * 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
|
7092 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7093 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7094 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7095 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7096 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7097 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7098 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7099 /* 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
|
7100 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7101 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7102 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7103 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7104 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7105 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7106 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7107 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7108 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
|
7109 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
|
7110 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7111 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7112 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7113 /* 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
|
7114 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
|
7115 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7116 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7117 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7118 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
|
7119 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7120 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7121 /* 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
|
7122 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7123 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7124 /* |
7 | 7125 * Advance to the match in window "wp" line "lnum" or past it. |
7126 */ | |
7127 static void | |
7128 prepare_search_hl(wp, lnum) | |
7129 win_T *wp; | |
7130 linenr_T lnum; | |
7131 { | |
1326 | 7132 matchitem_T *cur; /* points to the match list */ |
7133 match_T *shl; /* points to search_hl or a match */ | |
7134 int shl_flag; /* flag to indicate whether search_hl | |
7135 has been processed or not */ | |
7 | 7136 int n; |
7137 | |
7138 /* | |
7139 * When using a multi-line pattern, start searching at the top | |
7140 * of the window or just after a closed fold. | |
1326 | 7141 * Do this both for search_hl and the match list. |
7 | 7142 */ |
1326 | 7143 cur = wp->w_match_head; |
7144 shl_flag = FALSE; | |
7145 while (cur != NULL || shl_flag == FALSE) | |
7146 { | |
7147 if (shl_flag == FALSE) | |
7148 { | |
7149 shl = &search_hl; | |
7150 shl_flag = TRUE; | |
7151 } | |
7152 else | |
7153 shl = &cur->hl; | |
7 | 7154 if (shl->rm.regprog != NULL |
7155 && shl->lnum == 0 | |
7156 && re_multiline(shl->rm.regprog)) | |
7157 { | |
7158 if (shl->first_lnum == 0) | |
7159 { | |
7160 # ifdef FEAT_FOLDING | |
7161 for (shl->first_lnum = lnum; | |
7162 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7163 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7164 NULL, NULL, TRUE, NULL)) | |
7165 break; | |
7166 # else | |
7167 shl->first_lnum = wp->w_topline; | |
7168 # endif | |
7169 } | |
7170 n = 0; | |
7171 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7172 { | |
7173 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7174 if (shl->lnum != 0) | |
7175 { | |
7176 shl->first_lnum = shl->lnum | |
7177 + shl->rm.endpos[0].lnum | |
7178 - shl->rm.startpos[0].lnum; | |
7179 n = shl->rm.endpos[0].col; | |
7180 } | |
7181 else | |
7182 { | |
7183 ++shl->first_lnum; | |
7184 n = 0; | |
7185 } | |
7186 } | |
7187 } | |
1326 | 7188 if (shl != &search_hl && cur != NULL) |
7189 cur = cur->next; | |
7 | 7190 } |
7191 } | |
7192 | |
7193 /* | |
1326 | 7194 * Search for a next 'hlsearch' or match. |
7 | 7195 * Uses shl->buf. |
7196 * Sets shl->lnum and shl->rm contents. | |
7197 * Note: Assumes a previous match is always before "lnum", unless | |
7198 * shl->lnum is zero. | |
7199 * Careful: Any pointers for buffer lines will become invalid. | |
7200 */ | |
7201 static void | |
7202 next_search_hl(win, shl, lnum, mincol) | |
7203 win_T *win; | |
1326 | 7204 match_T *shl; /* points to search_hl or a match */ |
7 | 7205 linenr_T lnum; |
7206 colnr_T mincol; /* minimal column for a match */ | |
7207 { | |
7208 linenr_T l; | |
7209 colnr_T matchcol; | |
7210 long nmatched; | |
7211 | |
7212 if (shl->lnum != 0) | |
7213 { | |
7214 /* Check for three situations: | |
7215 * 1. If the "lnum" is below a previous match, start a new search. | |
7216 * 2. If the previous match includes "mincol", use it. | |
7217 * 3. Continue after the previous match. | |
7218 */ | |
7219 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7220 if (lnum > l) | |
7221 shl->lnum = 0; | |
7222 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7223 return; | |
7224 } | |
7225 | |
7226 /* | |
7227 * Repeat searching for a match until one is found that includes "mincol" | |
7228 * or none is found in this line. | |
7229 */ | |
7230 called_emsg = FALSE; | |
7231 for (;;) | |
7232 { | |
1521 | 7233 #ifdef FEAT_RELTIME |
7234 /* Stop searching after passing the time limit. */ | |
7235 if (profile_passed_limit(&(shl->tm))) | |
7236 { | |
7237 shl->lnum = 0; /* no match found in time */ | |
7238 break; | |
7239 } | |
7240 #endif | |
7 | 7241 /* Three situations: |
7242 * 1. No useful previous match: search from start of line. | |
7243 * 2. Not Vi compatible or empty match: continue at next character. | |
7244 * Break the loop if this is beyond the end of the line. | |
7245 * 3. Vi compatible searching: continue at end of previous match. | |
7246 */ | |
7247 if (shl->lnum == 0) | |
7248 matchcol = 0; | |
7249 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7250 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7251 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7252 { | |
688 | 7253 char_u *ml; |
685 | 7254 |
7255 matchcol = shl->rm.startpos[0].col; | |
688 | 7256 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7257 if (*ml == NUL) |
7258 { | |
7259 ++matchcol; | |
7 | 7260 shl->lnum = 0; |
7261 break; | |
7262 } | |
685 | 7263 #ifdef FEAT_MBYTE |
7264 if (has_mbyte) | |
7265 matchcol += mb_ptr2len(ml); | |
7266 else | |
7267 #endif | |
7268 ++matchcol; | |
7 | 7269 } |
7270 else | |
7271 matchcol = shl->rm.endpos[0].col; | |
7272 | |
7273 shl->lnum = lnum; | |
1521 | 7274 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7275 #ifdef FEAT_RELTIME | |
7276 &(shl->tm) | |
7277 #else | |
7278 NULL | |
7279 #endif | |
7280 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7281 if (called_emsg || got_int) |
7 | 7282 { |
7283 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7284 if (shl == &search_hl) |
7285 { | |
1326 | 7286 /* don't free regprog in the match list, it's a copy */ |
1112 | 7287 vim_free(shl->rm.regprog); |
7288 no_hlsearch = TRUE; | |
7289 } | |
7 | 7290 shl->rm.regprog = NULL; |
1112 | 7291 shl->lnum = 0; |
7292 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7293 break; |
7294 } | |
7295 if (nmatched == 0) | |
7296 { | |
7297 shl->lnum = 0; /* no match found */ | |
7298 break; | |
7299 } | |
7300 if (shl->rm.startpos[0].lnum > 0 | |
7301 || shl->rm.startpos[0].col >= mincol | |
7302 || nmatched > 1 | |
7303 || shl->rm.endpos[0].col > mincol) | |
7304 { | |
7305 shl->lnum += shl->rm.startpos[0].lnum; | |
7306 break; /* useful match found */ | |
7307 } | |
7308 } | |
7309 } | |
7310 #endif | |
7311 | |
7312 static void | |
7313 screen_start_highlight(attr) | |
7314 int attr; | |
7315 { | |
7316 attrentry_T *aep = NULL; | |
7317 | |
7318 screen_attr = attr; | |
7319 if (full_screen | |
7320 #ifdef WIN3264 | |
7321 && termcap_active | |
7322 #endif | |
7323 ) | |
7324 { | |
7325 #ifdef FEAT_GUI | |
7326 if (gui.in_use) | |
7327 { | |
7328 char buf[20]; | |
7329 | |
681 | 7330 /* The GUI handles this internally. */ |
7331 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7332 OUT_STR(buf); |
7333 } | |
7334 else | |
7335 #endif | |
7336 { | |
7337 if (attr > HL_ALL) /* special HL attr. */ | |
7338 { | |
7339 if (t_colors > 1) | |
7340 aep = syn_cterm_attr2entry(attr); | |
7341 else | |
7342 aep = syn_term_attr2entry(attr); | |
7343 if (aep == NULL) /* did ":syntax clear" */ | |
7344 attr = 0; | |
7345 else | |
7346 attr = aep->ae_attr; | |
7347 } | |
7348 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7349 out_str(T_MD); | |
681 | 7350 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7351 && cterm_normal_fg_bold) | |
7352 /* If the Normal FG color has BOLD attribute and the new HL | |
7353 * has a FG color defined, clear BOLD. */ | |
7354 out_str(T_ME); | |
7 | 7355 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7356 out_str(T_SO); | |
205 | 7357 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7358 /* underline or undercurl */ | |
7 | 7359 out_str(T_US); |
7360 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7361 out_str(T_CZH); | |
7362 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7363 out_str(T_MR); | |
7364 | |
7365 /* | |
7366 * Output the color or start string after bold etc., in case the | |
7367 * bold etc. override the color setting. | |
7368 */ | |
7369 if (aep != NULL) | |
7370 { | |
7371 if (t_colors > 1) | |
7372 { | |
7373 if (aep->ae_u.cterm.fg_color) | |
7374 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7375 if (aep->ae_u.cterm.bg_color) | |
7376 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7377 } | |
7378 else | |
7379 { | |
7380 if (aep->ae_u.term.start != NULL) | |
7381 out_str(aep->ae_u.term.start); | |
7382 } | |
7383 } | |
7384 } | |
7385 } | |
7386 } | |
7387 | |
7388 void | |
7389 screen_stop_highlight() | |
7390 { | |
7391 int do_ME = FALSE; /* output T_ME code */ | |
7392 | |
7393 if (screen_attr != 0 | |
7394 #ifdef WIN3264 | |
7395 && termcap_active | |
7396 #endif | |
7397 ) | |
7398 { | |
7399 #ifdef FEAT_GUI | |
7400 if (gui.in_use) | |
7401 { | |
7402 char buf[20]; | |
7403 | |
7404 /* use internal GUI code */ | |
7405 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7406 OUT_STR(buf); | |
7407 } | |
7408 else | |
7409 #endif | |
7410 { | |
7411 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7412 { | |
7413 attrentry_T *aep; | |
7414 | |
7415 if (t_colors > 1) | |
7416 { | |
7417 /* | |
7418 * Assume that t_me restores the original colors! | |
7419 */ | |
7420 aep = syn_cterm_attr2entry(screen_attr); | |
7421 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7422 || aep->ae_u.cterm.bg_color)) | |
7423 do_ME = TRUE; | |
7424 } | |
7425 else | |
7426 { | |
7427 aep = syn_term_attr2entry(screen_attr); | |
7428 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7429 { | |
7430 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7431 do_ME = TRUE; | |
7432 else | |
7433 out_str(aep->ae_u.term.stop); | |
7434 } | |
7435 } | |
7436 if (aep == NULL) /* did ":syntax clear" */ | |
7437 screen_attr = 0; | |
7438 else | |
7439 screen_attr = aep->ae_attr; | |
7440 } | |
7441 | |
7442 /* | |
7443 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7444 * same sequence several times. | |
7445 */ | |
7446 if (screen_attr & HL_STANDOUT) | |
7447 { | |
7448 if (STRCMP(T_SE, T_ME) == 0) | |
7449 do_ME = TRUE; | |
7450 else | |
7451 out_str(T_SE); | |
7452 } | |
205 | 7453 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7454 { |
7455 if (STRCMP(T_UE, T_ME) == 0) | |
7456 do_ME = TRUE; | |
7457 else | |
7458 out_str(T_UE); | |
7459 } | |
7460 if (screen_attr & HL_ITALIC) | |
7461 { | |
7462 if (STRCMP(T_CZR, T_ME) == 0) | |
7463 do_ME = TRUE; | |
7464 else | |
7465 out_str(T_CZR); | |
7466 } | |
7467 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7468 out_str(T_ME); | |
7469 | |
7470 if (t_colors > 1) | |
7471 { | |
7472 /* set Normal cterm colors */ | |
7473 if (cterm_normal_fg_color != 0) | |
7474 term_fg_color(cterm_normal_fg_color - 1); | |
7475 if (cterm_normal_bg_color != 0) | |
7476 term_bg_color(cterm_normal_bg_color - 1); | |
7477 if (cterm_normal_fg_bold) | |
7478 out_str(T_MD); | |
7479 } | |
7480 } | |
7481 } | |
7482 screen_attr = 0; | |
7483 } | |
7484 | |
7485 /* | |
7486 * Reset the colors for a cterm. Used when leaving Vim. | |
7487 * The machine specific code may override this again. | |
7488 */ | |
7489 void | |
7490 reset_cterm_colors() | |
7491 { | |
7492 if (t_colors > 1) | |
7493 { | |
7494 /* set Normal cterm colors */ | |
7495 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7496 { | |
7497 out_str(T_OP); | |
7498 screen_attr = -1; | |
7499 } | |
7500 if (cterm_normal_fg_bold) | |
7501 { | |
7502 out_str(T_ME); | |
7503 screen_attr = -1; | |
7504 } | |
7505 } | |
7506 } | |
7507 | |
7508 /* | |
7509 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7510 * using the attributes from ScreenAttrs["off"]. | |
7511 */ | |
7512 static void | |
7513 screen_char(off, row, col) | |
7514 unsigned off; | |
7515 int row; | |
7516 int col; | |
7517 { | |
7518 int attr; | |
7519 | |
7520 /* Check for illegal values, just in case (could happen just after | |
7521 * resizing). */ | |
7522 if (row >= screen_Rows || col >= screen_Columns) | |
7523 return; | |
7524 | |
7525 /* Outputting the last character on the screen may scrollup the screen. | |
7526 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7527 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7528 #ifdef FEAT_RIGHTLEFT | |
7529 /* account for first command-line character in rightleft mode */ | |
7530 && !cmdmsg_rl | |
7531 #endif | |
7532 ) | |
7533 { | |
7534 ScreenAttrs[off] = (sattr_T)-1; | |
7535 return; | |
7536 } | |
7537 | |
7538 /* | |
7539 * Stop highlighting first, so it's easier to move the cursor. | |
7540 */ | |
7541 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7542 if (screen_char_attr != 0) | |
7543 attr = screen_char_attr; | |
7544 else | |
7545 #endif | |
7546 attr = ScreenAttrs[off]; | |
7547 if (screen_attr != attr) | |
7548 screen_stop_highlight(); | |
7549 | |
7550 windgoto(row, col); | |
7551 | |
7552 if (screen_attr != attr) | |
7553 screen_start_highlight(attr); | |
7554 | |
7555 #ifdef FEAT_MBYTE | |
7556 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7557 { | |
7558 char_u buf[MB_MAXBYTES + 1]; | |
7559 | |
7560 /* Convert UTF-8 character to bytes and write it. */ | |
7561 | |
7562 buf[utfc_char2bytes(off, buf)] = NUL; | |
7563 | |
7564 out_str(buf); | |
7565 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7566 ++screen_cur_col; | |
7567 } | |
7568 else | |
7569 #endif | |
7570 { | |
7571 #ifdef FEAT_MBYTE | |
7572 out_flush_check(); | |
7573 #endif | |
7574 out_char(ScreenLines[off]); | |
7575 #ifdef FEAT_MBYTE | |
7576 /* double-byte character in single-width cell */ | |
7577 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7578 out_char(ScreenLines2[off]); | |
7579 #endif | |
7580 } | |
7581 | |
7582 screen_cur_col++; | |
7583 } | |
7584 | |
7585 #ifdef FEAT_MBYTE | |
7586 | |
7587 /* | |
7588 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7589 * on the screen at position 'row' and 'col'. | |
7590 * The attributes of the first byte is used for all. This is required to | |
7591 * output the two bytes of a double-byte character with nothing in between. | |
7592 */ | |
7593 static void | |
7594 screen_char_2(off, row, col) | |
7595 unsigned off; | |
7596 int row; | |
7597 int col; | |
7598 { | |
7599 /* Check for illegal values (could be wrong when screen was resized). */ | |
7600 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7601 return; | |
7602 | |
7603 /* Outputting the last character on the screen may scrollup the screen. | |
7604 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7605 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7606 { | |
7607 ScreenAttrs[off] = (sattr_T)-1; | |
7608 return; | |
7609 } | |
7610 | |
7611 /* Output the first byte normally (positions the cursor), then write the | |
7612 * second byte directly. */ | |
7613 screen_char(off, row, col); | |
7614 out_char(ScreenLines[off + 1]); | |
7615 ++screen_cur_col; | |
7616 } | |
7617 #endif | |
7618 | |
7619 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7620 /* | |
7621 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7622 * This uses the contents of ScreenLines[] and doesn't change it. | |
7623 */ | |
7624 void | |
7625 screen_draw_rectangle(row, col, height, width, invert) | |
7626 int row; | |
7627 int col; | |
7628 int height; | |
7629 int width; | |
7630 int invert; | |
7631 { | |
7632 int r, c; | |
7633 int off; | |
1378 | 7634 #ifdef FEAT_MBYTE |
7635 int max_off; | |
7636 #endif | |
7 | 7637 |
534 | 7638 /* Can't use ScreenLines unless initialized */ |
7639 if (ScreenLines == NULL) | |
7640 return; | |
7641 | |
7 | 7642 if (invert) |
7643 screen_char_attr = HL_INVERSE; | |
7644 for (r = row; r < row + height; ++r) | |
7645 { | |
7646 off = LineOffset[r]; | |
1378 | 7647 #ifdef FEAT_MBYTE |
7648 max_off = off + screen_Columns; | |
7649 #endif | |
7 | 7650 for (c = col; c < col + width; ++c) |
7651 { | |
7652 #ifdef FEAT_MBYTE | |
1378 | 7653 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7654 { |
7655 screen_char_2(off + c, r, c); | |
7656 ++c; | |
7657 } | |
7658 else | |
7659 #endif | |
7660 { | |
7661 screen_char(off + c, r, c); | |
7662 #ifdef FEAT_MBYTE | |
1378 | 7663 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7664 ++c; |
7665 #endif | |
7666 } | |
7667 } | |
7668 } | |
7669 screen_char_attr = 0; | |
7670 } | |
7671 #endif | |
7672 | |
7673 #ifdef FEAT_VERTSPLIT | |
7674 /* | |
7675 * Redraw the characters for a vertically split window. | |
7676 */ | |
7677 static void | |
7678 redraw_block(row, end, wp) | |
7679 int row; | |
7680 int end; | |
7681 win_T *wp; | |
7682 { | |
7683 int col; | |
7684 int width; | |
7685 | |
7686 # ifdef FEAT_CLIPBOARD | |
7687 clip_may_clear_selection(row, end - 1); | |
7688 # endif | |
7689 | |
7690 if (wp == NULL) | |
7691 { | |
7692 col = 0; | |
7693 width = Columns; | |
7694 } | |
7695 else | |
7696 { | |
7697 col = wp->w_wincol; | |
7698 width = wp->w_width; | |
7699 } | |
7700 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7701 } | |
7702 #endif | |
7703 | |
7704 /* | |
7705 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7706 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7707 * Use attributes 'attr'. | |
7708 */ | |
7709 void | |
7710 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7711 int start_row, end_row; | |
7712 int start_col, end_col; | |
7713 int c1, c2; | |
7714 int attr; | |
7715 { | |
7716 int row; | |
7717 int col; | |
7718 int off; | |
7719 int end_off; | |
7720 int did_delete; | |
7721 int c; | |
7722 int norm_term; | |
7723 #if defined(FEAT_GUI) || defined(UNIX) | |
7724 int force_next = FALSE; | |
7725 #endif | |
7726 | |
7727 if (end_row > screen_Rows) /* safety check */ | |
7728 end_row = screen_Rows; | |
7729 if (end_col > screen_Columns) /* safety check */ | |
7730 end_col = screen_Columns; | |
7731 if (ScreenLines == NULL | |
7732 || start_row >= end_row | |
7733 || start_col >= end_col) /* nothing to do */ | |
7734 return; | |
7735 | |
7736 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7737 norm_term = ( | |
7738 #ifdef FEAT_GUI | |
7739 !gui.in_use && | |
7740 #endif | |
7741 t_colors <= 1); | |
7742 for (row = start_row; row < end_row; ++row) | |
7743 { | |
1668 | 7744 #ifdef FEAT_MBYTE |
7745 if (has_mbyte | |
7746 # ifdef FEAT_GUI | |
7747 && !gui.in_use | |
7748 # endif | |
7749 ) | |
7750 { | |
7751 /* When drawing over the right halve of a double-wide char clear | |
7752 * out the left halve. When drawing over the left halve of a | |
7753 * double wide-char clear out the right halve. Only needed in a | |
7754 * terminal. */ | |
1685 | 7755 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7756 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7757 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7758 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7759 } |
7760 #endif | |
7 | 7761 /* |
7762 * Try to use delete-line termcap code, when no attributes or in a | |
7763 * "normal" terminal, where a bold/italic space is just a | |
7764 * space. | |
7765 */ | |
7766 did_delete = FALSE; | |
7767 if (c2 == ' ' | |
7768 && end_col == Columns | |
7769 && can_clear(T_CE) | |
7770 && (attr == 0 | |
7771 || (norm_term | |
7772 && attr <= HL_ALL | |
7773 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7774 { | |
7775 /* | |
7776 * check if we really need to clear something | |
7777 */ | |
7778 col = start_col; | |
7779 if (c1 != ' ') /* don't clear first char */ | |
7780 ++col; | |
7781 | |
7782 off = LineOffset[row] + col; | |
7783 end_off = LineOffset[row] + end_col; | |
7784 | |
7785 /* skip blanks (used often, keep it fast!) */ | |
7786 #ifdef FEAT_MBYTE | |
7787 if (enc_utf8) | |
7788 while (off < end_off && ScreenLines[off] == ' ' | |
7789 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7790 ++off; | |
7791 else | |
7792 #endif | |
7793 while (off < end_off && ScreenLines[off] == ' ' | |
7794 && ScreenAttrs[off] == 0) | |
7795 ++off; | |
7796 if (off < end_off) /* something to be cleared */ | |
7797 { | |
7798 col = off - LineOffset[row]; | |
7799 screen_stop_highlight(); | |
7800 term_windgoto(row, col);/* clear rest of this screen line */ | |
7801 out_str(T_CE); | |
7802 screen_start(); /* don't know where cursor is now */ | |
7803 col = end_col - col; | |
7804 while (col--) /* clear chars in ScreenLines */ | |
7805 { | |
7806 ScreenLines[off] = ' '; | |
7807 #ifdef FEAT_MBYTE | |
7808 if (enc_utf8) | |
7809 ScreenLinesUC[off] = 0; | |
7810 #endif | |
7811 ScreenAttrs[off] = 0; | |
7812 ++off; | |
7813 } | |
7814 } | |
7815 did_delete = TRUE; /* the chars are cleared now */ | |
7816 } | |
7817 | |
7818 off = LineOffset[row] + start_col; | |
7819 c = c1; | |
7820 for (col = start_col; col < end_col; ++col) | |
7821 { | |
7822 if (ScreenLines[off] != c | |
7823 #ifdef FEAT_MBYTE | |
714 | 7824 || (enc_utf8 && (int)ScreenLinesUC[off] |
7825 != (c >= 0x80 ? c : 0)) | |
7 | 7826 #endif |
7827 || ScreenAttrs[off] != attr | |
7828 #if defined(FEAT_GUI) || defined(UNIX) | |
7829 || force_next | |
7830 #endif | |
7831 ) | |
7832 { | |
7833 #if defined(FEAT_GUI) || defined(UNIX) | |
7834 /* The bold trick may make a single row of pixels appear in | |
7835 * the next character. When a bold character is removed, the | |
7836 * next character should be redrawn too. This happens for our | |
7837 * own GUI and for some xterms. */ | |
7838 if ( | |
7839 # ifdef FEAT_GUI | |
7840 gui.in_use | |
7841 # endif | |
7842 # if defined(FEAT_GUI) && defined(UNIX) | |
7843 || | |
7844 # endif | |
7845 # ifdef UNIX | |
7846 term_is_xterm | |
7847 # endif | |
7848 ) | |
7849 { | |
7850 if (ScreenLines[off] != ' ' | |
7851 && (ScreenAttrs[off] > HL_ALL | |
7852 || ScreenAttrs[off] & HL_BOLD)) | |
7853 force_next = TRUE; | |
7854 else | |
7855 force_next = FALSE; | |
7856 } | |
7857 #endif | |
7858 ScreenLines[off] = c; | |
7859 #ifdef FEAT_MBYTE | |
7860 if (enc_utf8) | |
7861 { | |
7862 if (c >= 0x80) | |
7863 { | |
7864 ScreenLinesUC[off] = c; | |
714 | 7865 ScreenLinesC[0][off] = 0; |
7 | 7866 } |
7867 else | |
7868 ScreenLinesUC[off] = 0; | |
7869 } | |
7870 #endif | |
7871 ScreenAttrs[off] = attr; | |
7872 if (!did_delete || c != ' ') | |
7873 screen_char(off, row, col); | |
7874 } | |
7875 ++off; | |
7876 if (col == start_col) | |
7877 { | |
7878 if (did_delete) | |
7879 break; | |
7880 c = c2; | |
7881 } | |
7882 } | |
7883 if (end_col == Columns) | |
7884 LineWraps[row] = FALSE; | |
7885 if (row == Rows - 1) /* overwritten the command line */ | |
7886 { | |
7887 redraw_cmdline = TRUE; | |
7888 if (c1 == ' ' && c2 == ' ') | |
7889 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7890 if (start_col == 0) |
7891 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7892 } |
7893 } | |
7894 } | |
7895 | |
7896 /* | |
7897 * Check if there should be a delay. Used before clearing or redrawing the | |
7898 * screen or the command line. | |
7899 */ | |
7900 void | |
7901 check_for_delay(check_msg_scroll) | |
7902 int check_msg_scroll; | |
7903 { | |
7904 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7905 && !did_wait_return | |
7906 && emsg_silent == 0) | |
7907 { | |
7908 out_flush(); | |
7909 ui_delay(1000L, TRUE); | |
7910 emsg_on_display = FALSE; | |
7911 if (check_msg_scroll) | |
7912 msg_scroll = FALSE; | |
7913 } | |
7914 } | |
7915 | |
7916 /* | |
7917 * screen_valid - allocate screen buffers if size changed | |
3263 | 7918 * If "doclear" is TRUE: clear screen if it has been resized. |
7 | 7919 * Returns TRUE if there is a valid screen to write to. |
7920 * Returns FALSE when starting up and screen not initialized yet. | |
7921 */ | |
7922 int | |
3263 | 7923 screen_valid(doclear) |
7924 int doclear; | |
7 | 7925 { |
3263 | 7926 screenalloc(doclear); /* allocate screen buffers if size changed */ |
7 | 7927 return (ScreenLines != NULL); |
7928 } | |
7929 | |
7930 /* | |
7931 * Resize the shell to Rows and Columns. | |
7932 * Allocate ScreenLines[] and associated items. | |
7933 * | |
7934 * There may be some time between setting Rows and Columns and (re)allocating | |
7935 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7936 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7937 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7938 * final size of the shell is needed. | |
7939 */ | |
7940 void | |
3263 | 7941 screenalloc(doclear) |
7942 int doclear; | |
7 | 7943 { |
7944 int new_row, old_row; | |
7945 #ifdef FEAT_GUI | |
7946 int old_Rows; | |
7947 #endif | |
7948 win_T *wp; | |
7949 int outofmem = FALSE; | |
7950 int len; | |
7951 schar_T *new_ScreenLines; | |
7952 #ifdef FEAT_MBYTE | |
7953 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7954 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7955 schar_T *new_ScreenLines2 = NULL; |
714 | 7956 int i; |
7 | 7957 #endif |
7958 sattr_T *new_ScreenAttrs; | |
7959 unsigned *new_LineOffset; | |
7960 char_u *new_LineWraps; | |
671 | 7961 #ifdef FEAT_WINDOWS |
681 | 7962 short *new_TabPageIdxs; |
671 | 7963 tabpage_T *tp; |
7964 #endif | |
7 | 7965 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7966 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7967 #ifdef FEAT_AUTOCMD |
7968 int retry_count = 0; | |
7969 | |
7970 retry: | |
7971 #endif | |
7 | 7972 /* |
7973 * Allocation of the screen buffers is done only when the size changes and | |
7974 * when Rows and Columns have been set and we have started doing full | |
7975 * screen stuff. | |
7976 */ | |
7977 if ((ScreenLines != NULL | |
7978 && Rows == screen_Rows | |
7979 && Columns == screen_Columns | |
7980 #ifdef FEAT_MBYTE | |
7981 && enc_utf8 == (ScreenLinesUC != NULL) | |
7982 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7983 && p_mco == Screen_mco |
7 | 7984 #endif |
7985 ) | |
7986 || Rows == 0 | |
7987 || Columns == 0 | |
7988 || (!full_screen && ScreenLines == NULL)) | |
7989 return; | |
7990 | |
7991 /* | |
7992 * It's possible that we produce an out-of-memory message below, which | |
7993 * will cause this function to be called again. To break the loop, just | |
7994 * return here. | |
7995 */ | |
7996 if (entered) | |
7997 return; | |
7998 entered = TRUE; | |
7999 | |
911 | 8000 /* |
8001 * Note that the window sizes are updated before reallocating the arrays, | |
8002 * thus we must not redraw here! | |
8003 */ | |
8004 ++RedrawingDisabled; | |
8005 | |
7 | 8006 win_new_shellsize(); /* fit the windows in the new sized shell */ |
8007 | |
8008 comp_col(); /* recompute columns for shown command and ruler */ | |
8009 | |
8010 /* | |
8011 * We're changing the size of the screen. | |
8012 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
8013 * - Move lines from the old arrays into the new arrays, clear extra | |
8014 * lines (unless the screen is going to be cleared). | |
8015 * - Free the old arrays. | |
8016 * | |
8017 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
8018 * Continuing with the old ScreenLines may result in a crash, because the | |
8019 * size is wrong. | |
8020 */ | |
671 | 8021 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 8022 win_free_lsize(wp); |
1946 | 8023 #ifdef FEAT_AUTOCMD |
8024 if (aucmd_win != NULL) | |
8025 win_free_lsize(aucmd_win); | |
8026 #endif | |
7 | 8027 |
8028 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
8029 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
8030 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
8031 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 8032 if (enc_utf8) |
8033 { | |
8034 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
8035 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 8036 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
8037 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 8038 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
8039 } | |
8040 if (enc_dbcs == DBCS_JPNU) | |
8041 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
8042 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
8043 #endif | |
8044 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
8045 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
8046 new_LineOffset = (unsigned *)lalloc((long_u)( | |
8047 Rows * sizeof(unsigned)), FALSE); | |
8048 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 8049 #ifdef FEAT_WINDOWS |
681 | 8050 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 8051 #endif |
7 | 8052 |
677 | 8053 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 8054 { |
8055 if (win_alloc_lines(wp) == FAIL) | |
8056 { | |
8057 outofmem = TRUE; | |
8058 #ifdef FEAT_WINDOWS | |
1819 | 8059 goto give_up; |
8060 #endif | |
8061 } | |
8062 } | |
1906 | 8063 #ifdef FEAT_AUTOCMD |
1946 | 8064 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
8065 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 8066 outofmem = TRUE; |
8067 #endif | |
1819 | 8068 #ifdef FEAT_WINDOWS |
8069 give_up: | |
8070 #endif | |
7 | 8071 |
714 | 8072 #ifdef FEAT_MBYTE |
8073 for (i = 0; i < p_mco; ++i) | |
8074 if (new_ScreenLinesC[i] == NULL) | |
8075 break; | |
8076 #endif | |
7 | 8077 if (new_ScreenLines == NULL |
8078 #ifdef FEAT_MBYTE | |
714 | 8079 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 8080 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
8081 #endif | |
8082 || new_ScreenAttrs == NULL | |
8083 || new_LineOffset == NULL | |
8084 || new_LineWraps == NULL | |
671 | 8085 #ifdef FEAT_WINDOWS |
8086 || new_TabPageIdxs == NULL | |
8087 #endif | |
7 | 8088 || outofmem) |
8089 { | |
944 | 8090 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 8091 { |
8092 /* guess the size */ | |
8093 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
8094 | |
8095 /* Remember we did this to avoid getting outofmem messages over | |
8096 * and over again. */ | |
944 | 8097 done_outofmem_msg = TRUE; |
534 | 8098 } |
7 | 8099 vim_free(new_ScreenLines); |
8100 new_ScreenLines = NULL; | |
8101 #ifdef FEAT_MBYTE | |
8102 vim_free(new_ScreenLinesUC); | |
8103 new_ScreenLinesUC = NULL; | |
714 | 8104 for (i = 0; i < p_mco; ++i) |
8105 { | |
8106 vim_free(new_ScreenLinesC[i]); | |
8107 new_ScreenLinesC[i] = NULL; | |
8108 } | |
7 | 8109 vim_free(new_ScreenLines2); |
8110 new_ScreenLines2 = NULL; | |
8111 #endif | |
8112 vim_free(new_ScreenAttrs); | |
8113 new_ScreenAttrs = NULL; | |
8114 vim_free(new_LineOffset); | |
8115 new_LineOffset = NULL; | |
8116 vim_free(new_LineWraps); | |
8117 new_LineWraps = NULL; | |
671 | 8118 #ifdef FEAT_WINDOWS |
8119 vim_free(new_TabPageIdxs); | |
8120 new_TabPageIdxs = NULL; | |
8121 #endif | |
7 | 8122 } |
8123 else | |
8124 { | |
944 | 8125 done_outofmem_msg = FALSE; |
534 | 8126 |
7 | 8127 for (new_row = 0; new_row < Rows; ++new_row) |
8128 { | |
8129 new_LineOffset[new_row] = new_row * Columns; | |
8130 new_LineWraps[new_row] = FALSE; | |
8131 | |
8132 /* | |
8133 * If the screen is not going to be cleared, copy as much as | |
8134 * possible from the old screen to the new one and clear the rest | |
8135 * (used when resizing the window at the "--more--" prompt or when | |
8136 * executing an external command, for the GUI). | |
8137 */ | |
3263 | 8138 if (!doclear) |
7 | 8139 { |
8140 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
8141 ' ', (size_t)Columns * sizeof(schar_T)); | |
8142 #ifdef FEAT_MBYTE | |
8143 if (enc_utf8) | |
8144 { | |
8145 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
8146 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 8147 for (i = 0; i < p_mco; ++i) |
8148 (void)vim_memset(new_ScreenLinesC[i] | |
8149 + new_row * Columns, | |
7 | 8150 0, (size_t)Columns * sizeof(u8char_T)); |
8151 } | |
8152 if (enc_dbcs == DBCS_JPNU) | |
8153 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8154 0, (size_t)Columns * sizeof(schar_T)); | |
8155 #endif | |
8156 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8157 0, (size_t)Columns * sizeof(sattr_T)); | |
8158 old_row = new_row + (screen_Rows - Rows); | |
534 | 8159 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8160 { |
8161 if (screen_Columns < Columns) | |
8162 len = screen_Columns; | |
8163 else | |
8164 len = Columns; | |
26 | 8165 #ifdef FEAT_MBYTE |
571 | 8166 /* When switching to utf-8 don't copy characters, they |
714 | 8167 * may be invalid now. Also when p_mco changes. */ |
8168 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8169 && p_mco == Screen_mco) | |
26 | 8170 #endif |
8171 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8172 ScreenLines + LineOffset[old_row], | |
8173 (size_t)len * sizeof(schar_T)); | |
7 | 8174 #ifdef FEAT_MBYTE |
714 | 8175 if (enc_utf8 && ScreenLinesUC != NULL |
8176 && p_mco == Screen_mco) | |
7 | 8177 { |
8178 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8179 ScreenLinesUC + LineOffset[old_row], | |
8180 (size_t)len * sizeof(u8char_T)); | |
714 | 8181 for (i = 0; i < p_mco; ++i) |
8182 mch_memmove(new_ScreenLinesC[i] | |
8183 + new_LineOffset[new_row], | |
8184 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8185 (size_t)len * sizeof(u8char_T)); |
8186 } | |
8187 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8188 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8189 ScreenLines2 + LineOffset[old_row], | |
8190 (size_t)len * sizeof(schar_T)); | |
8191 #endif | |
8192 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8193 ScreenAttrs + LineOffset[old_row], | |
8194 (size_t)len * sizeof(sattr_T)); | |
8195 } | |
8196 } | |
8197 } | |
8198 /* Use the last line of the screen for the current line. */ | |
8199 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8200 } | |
8201 | |
356 | 8202 free_screenlines(); |
8203 | |
7 | 8204 ScreenLines = new_ScreenLines; |
8205 #ifdef FEAT_MBYTE | |
8206 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8207 for (i = 0; i < p_mco; ++i) |
8208 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8209 Screen_mco = p_mco; | |
7 | 8210 ScreenLines2 = new_ScreenLines2; |
8211 #endif | |
8212 ScreenAttrs = new_ScreenAttrs; | |
8213 LineOffset = new_LineOffset; | |
8214 LineWraps = new_LineWraps; | |
671 | 8215 #ifdef FEAT_WINDOWS |
8216 TabPageIdxs = new_TabPageIdxs; | |
8217 #endif | |
7 | 8218 |
8219 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8220 * size of ScreenLines[]. Set them before calling anything. */ | |
8221 #ifdef FEAT_GUI | |
8222 old_Rows = screen_Rows; | |
8223 #endif | |
8224 screen_Rows = Rows; | |
8225 screen_Columns = Columns; | |
8226 | |
8227 must_redraw = CLEAR; /* need to clear the screen later */ | |
3263 | 8228 if (doclear) |
7 | 8229 screenclear2(); |
8230 | |
8231 #ifdef FEAT_GUI | |
8232 else if (gui.in_use | |
8233 && !gui.starting | |
8234 && ScreenLines != NULL | |
8235 && old_Rows != Rows) | |
8236 { | |
8237 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8238 /* | |
8239 * Adjust the position of the cursor, for when executing an external | |
8240 * command. | |
8241 */ | |
8242 if (msg_row >= Rows) /* Rows got smaller */ | |
8243 msg_row = Rows - 1; /* put cursor at last row */ | |
8244 else if (Rows > old_Rows) /* Rows got bigger */ | |
8245 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8246 if (msg_col >= Columns) /* Columns got smaller */ | |
8247 msg_col = Columns - 1; /* put cursor at last column */ | |
8248 } | |
8249 #endif | |
8250 | |
8251 entered = FALSE; | |
911 | 8252 --RedrawingDisabled; |
766 | 8253 |
8254 #ifdef FEAT_AUTOCMD | |
1824 | 8255 /* |
8256 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8257 * in case applying autocommands always changes Rows or Columns. | |
8258 */ | |
8259 if (starting == 0 && ++retry_count <= 3) | |
8260 { | |
766 | 8261 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8262 /* In rare cases, autocommands may have altered Rows or Columns, |
8263 * jump back to check if we need to allocate the screen again. */ | |
8264 goto retry; | |
8265 } | |
766 | 8266 #endif |
7 | 8267 } |
8268 | |
8269 void | |
356 | 8270 free_screenlines() |
8271 { | |
8272 #ifdef FEAT_MBYTE | |
714 | 8273 int i; |
8274 | |
356 | 8275 vim_free(ScreenLinesUC); |
714 | 8276 for (i = 0; i < Screen_mco; ++i) |
8277 vim_free(ScreenLinesC[i]); | |
356 | 8278 vim_free(ScreenLines2); |
8279 #endif | |
714 | 8280 vim_free(ScreenLines); |
356 | 8281 vim_free(ScreenAttrs); |
8282 vim_free(LineOffset); | |
8283 vim_free(LineWraps); | |
671 | 8284 #ifdef FEAT_WINDOWS |
8285 vim_free(TabPageIdxs); | |
8286 #endif | |
356 | 8287 } |
8288 | |
8289 void | |
7 | 8290 screenclear() |
8291 { | |
8292 check_for_delay(FALSE); | |
8293 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8294 screenclear2(); /* clear the screen */ | |
8295 } | |
8296 | |
8297 static void | |
8298 screenclear2() | |
8299 { | |
8300 int i; | |
8301 | |
8302 if (starting == NO_SCREEN || ScreenLines == NULL | |
8303 #ifdef FEAT_GUI | |
8304 || (gui.in_use && gui.starting) | |
8305 #endif | |
8306 ) | |
8307 return; | |
8308 | |
8309 #ifdef FEAT_GUI | |
8310 if (!gui.in_use) | |
8311 #endif | |
8312 screen_attr = -1; /* force setting the Normal colors */ | |
8313 screen_stop_highlight(); /* don't want highlighting here */ | |
8314 | |
8315 #ifdef FEAT_CLIPBOARD | |
8316 /* disable selection without redrawing it */ | |
8317 clip_scroll_selection(9999); | |
8318 #endif | |
8319 | |
8320 /* blank out ScreenLines */ | |
8321 for (i = 0; i < Rows; ++i) | |
8322 { | |
8323 lineclear(LineOffset[i], (int)Columns); | |
8324 LineWraps[i] = FALSE; | |
8325 } | |
8326 | |
8327 if (can_clear(T_CL)) | |
8328 { | |
8329 out_str(T_CL); /* clear the display */ | |
8330 clear_cmdline = FALSE; | |
644 | 8331 mode_displayed = FALSE; |
7 | 8332 } |
8333 else | |
8334 { | |
8335 /* can't clear the screen, mark all chars with invalid attributes */ | |
8336 for (i = 0; i < Rows; ++i) | |
8337 lineinvalid(LineOffset[i], (int)Columns); | |
8338 clear_cmdline = TRUE; | |
8339 } | |
8340 | |
8341 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8342 | |
8343 win_rest_invalid(firstwin); | |
8344 redraw_cmdline = TRUE; | |
670 | 8345 #ifdef FEAT_WINDOWS |
673 | 8346 redraw_tabline = TRUE; |
670 | 8347 #endif |
7 | 8348 if (must_redraw == CLEAR) /* no need to clear again */ |
8349 must_redraw = NOT_VALID; | |
8350 compute_cmdrow(); | |
8351 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8352 msg_col = 0; | |
8353 screen_start(); /* don't know where cursor is now */ | |
8354 msg_scrolled = 0; /* can't scroll back */ | |
8355 msg_didany = FALSE; | |
8356 msg_didout = FALSE; | |
8357 } | |
8358 | |
8359 /* | |
8360 * Clear one line in ScreenLines. | |
8361 */ | |
8362 static void | |
8363 lineclear(off, width) | |
8364 unsigned off; | |
8365 int width; | |
8366 { | |
8367 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8368 #ifdef FEAT_MBYTE | |
8369 if (enc_utf8) | |
8370 (void)vim_memset(ScreenLinesUC + off, 0, | |
8371 (size_t)width * sizeof(u8char_T)); | |
8372 #endif | |
8373 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8374 } | |
8375 | |
8376 /* | |
8377 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8378 * invalid value. | |
8379 */ | |
8380 static void | |
8381 lineinvalid(off, width) | |
8382 unsigned off; | |
8383 int width; | |
8384 { | |
8385 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8386 } | |
8387 | |
8388 #ifdef FEAT_VERTSPLIT | |
8389 /* | |
8390 * Copy part of a Screenline for vertically split window "wp". | |
8391 */ | |
8392 static void | |
8393 linecopy(to, from, wp) | |
8394 int to; | |
8395 int from; | |
8396 win_T *wp; | |
8397 { | |
8398 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8399 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8400 | |
8401 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8402 wp->w_width * sizeof(schar_T)); | |
8403 # ifdef FEAT_MBYTE | |
8404 if (enc_utf8) | |
8405 { | |
714 | 8406 int i; |
8407 | |
7 | 8408 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8409 wp->w_width * sizeof(u8char_T)); | |
714 | 8410 for (i = 0; i < p_mco; ++i) |
8411 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8412 wp->w_width * sizeof(u8char_T)); | |
7 | 8413 } |
8414 if (enc_dbcs == DBCS_JPNU) | |
8415 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8416 wp->w_width * sizeof(schar_T)); | |
8417 # endif | |
8418 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8419 wp->w_width * sizeof(sattr_T)); | |
8420 } | |
8421 #endif | |
8422 | |
8423 /* | |
8424 * Return TRUE if clearing with term string "p" would work. | |
8425 * It can't work when the string is empty or it won't set the right background. | |
8426 */ | |
8427 int | |
8428 can_clear(p) | |
8429 char_u *p; | |
8430 { | |
8431 return (*p != NUL && (t_colors <= 1 | |
8432 #ifdef FEAT_GUI | |
8433 || gui.in_use | |
8434 #endif | |
8435 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8436 } | |
8437 | |
8438 /* | |
8439 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8440 * something directly to the screen (shell commands) or a terminal control | |
8441 * code. | |
8442 */ | |
8443 void | |
8444 screen_start() | |
8445 { | |
8446 screen_cur_row = screen_cur_col = 9999; | |
8447 } | |
8448 | |
8449 /* | |
8450 * Move the cursor to position "row","col" in the screen. | |
8451 * This tries to find the most efficient way to move, minimizing the number of | |
8452 * characters sent to the terminal. | |
8453 */ | |
8454 void | |
8455 windgoto(row, col) | |
8456 int row; | |
8457 int col; | |
8458 { | |
205 | 8459 sattr_T *p; |
7 | 8460 int i; |
8461 int plan; | |
8462 int cost; | |
8463 int wouldbe_col; | |
8464 int noinvcurs; | |
8465 char_u *bs; | |
8466 int goto_cost; | |
8467 int attr; | |
8468 | |
1213 | 8469 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8470 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8471 | |
8472 #define PLAN_LE 1 | |
8473 #define PLAN_CR 2 | |
8474 #define PLAN_NL 3 | |
8475 #define PLAN_WRITE 4 | |
8476 /* Can't use ScreenLines unless initialized */ | |
8477 if (ScreenLines == NULL) | |
8478 return; | |
8479 | |
8480 if (col != screen_cur_col || row != screen_cur_row) | |
8481 { | |
8482 /* Check for valid position. */ | |
8483 if (row < 0) /* window without text lines? */ | |
8484 row = 0; | |
8485 if (row >= screen_Rows) | |
8486 row = screen_Rows - 1; | |
8487 if (col >= screen_Columns) | |
8488 col = screen_Columns - 1; | |
8489 | |
8490 /* check if no cursor movement is allowed in highlight mode */ | |
8491 if (screen_attr && *T_MS == NUL) | |
8492 noinvcurs = HIGHL_COST; | |
8493 else | |
8494 noinvcurs = 0; | |
8495 goto_cost = GOTO_COST + noinvcurs; | |
8496 | |
8497 /* | |
8498 * Plan how to do the positioning: | |
8499 * 1. Use CR to move it to column 0, same row. | |
8500 * 2. Use T_LE to move it a few columns to the left. | |
8501 * 3. Use NL to move a few lines down, column 0. | |
8502 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8503 * | |
8504 * Don't do this if the cursor went beyond the last column, the cursor | |
8505 * position is unknown then (some terminals wrap, some don't ) | |
8506 * | |
1213 | 8507 * First check if the highlighting attributes allow us to write |
7 | 8508 * characters to move the cursor to the right. |
8509 */ | |
8510 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8511 { | |
8512 /* | |
8513 * If the cursor is in the same row, bigger col, we can use CR | |
8514 * or T_LE. | |
8515 */ | |
8516 bs = NULL; /* init for GCC */ | |
8517 attr = screen_attr; | |
8518 if (row == screen_cur_row && col < screen_cur_col) | |
8519 { | |
8520 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8521 if (*T_LE) | |
8522 bs = T_LE; /* "cursor left" */ | |
8523 else | |
8524 bs = T_BC; /* "backspace character (old) */ | |
8525 if (*bs) | |
8526 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8527 else | |
8528 cost = 999; | |
8529 if (col + 1 < cost) /* using CR is less characters */ | |
8530 { | |
8531 plan = PLAN_CR; | |
8532 wouldbe_col = 0; | |
8533 cost = 1; /* CR is just one character */ | |
8534 } | |
8535 else | |
8536 { | |
8537 plan = PLAN_LE; | |
8538 wouldbe_col = col; | |
8539 } | |
8540 if (noinvcurs) /* will stop highlighting */ | |
8541 { | |
8542 cost += noinvcurs; | |
8543 attr = 0; | |
8544 } | |
8545 } | |
8546 | |
8547 /* | |
8548 * If the cursor is above where we want to be, we can use CR LF. | |
8549 */ | |
8550 else if (row > screen_cur_row) | |
8551 { | |
8552 plan = PLAN_NL; | |
8553 wouldbe_col = 0; | |
8554 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8555 if (noinvcurs) /* will stop highlighting */ | |
8556 { | |
8557 cost += noinvcurs; | |
8558 attr = 0; | |
8559 } | |
8560 } | |
8561 | |
8562 /* | |
8563 * If the cursor is in the same row, smaller col, just use write. | |
8564 */ | |
8565 else | |
8566 { | |
8567 plan = PLAN_WRITE; | |
8568 wouldbe_col = screen_cur_col; | |
8569 cost = 0; | |
8570 } | |
8571 | |
8572 /* | |
8573 * Check if any characters that need to be written have the | |
8574 * correct attributes. Also avoid UTF-8 characters. | |
8575 */ | |
8576 i = col - wouldbe_col; | |
8577 if (i > 0) | |
8578 cost += i; | |
8579 if (cost < goto_cost && i > 0) | |
8580 { | |
8581 /* | |
8582 * Check if the attributes are correct without additionally | |
8583 * stopping highlighting. | |
8584 */ | |
8585 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8586 while (i && *p++ == attr) | |
8587 --i; | |
8588 if (i != 0) | |
8589 { | |
8590 /* | |
8591 * Try if it works when highlighting is stopped here. | |
8592 */ | |
8593 if (*--p == 0) | |
8594 { | |
8595 cost += noinvcurs; | |
8596 while (i && *p++ == 0) | |
8597 --i; | |
8598 } | |
8599 if (i != 0) | |
8600 cost = 999; /* different attributes, don't do it */ | |
8601 } | |
8602 #ifdef FEAT_MBYTE | |
8603 if (enc_utf8) | |
8604 { | |
8605 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8606 for (i = wouldbe_col; i < col; ++i) | |
8607 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8608 { | |
8609 cost = 999; | |
8610 break; | |
8611 } | |
8612 } | |
8613 #endif | |
8614 } | |
8615 | |
8616 /* | |
8617 * We can do it without term_windgoto()! | |
8618 */ | |
8619 if (cost < goto_cost) | |
8620 { | |
8621 if (plan == PLAN_LE) | |
8622 { | |
8623 if (noinvcurs) | |
8624 screen_stop_highlight(); | |
8625 while (screen_cur_col > col) | |
8626 { | |
8627 out_str(bs); | |
8628 --screen_cur_col; | |
8629 } | |
8630 } | |
8631 else if (plan == PLAN_CR) | |
8632 { | |
8633 if (noinvcurs) | |
8634 screen_stop_highlight(); | |
8635 out_char('\r'); | |
8636 screen_cur_col = 0; | |
8637 } | |
8638 else if (plan == PLAN_NL) | |
8639 { | |
8640 if (noinvcurs) | |
8641 screen_stop_highlight(); | |
8642 while (screen_cur_row < row) | |
8643 { | |
8644 out_char('\n'); | |
8645 ++screen_cur_row; | |
8646 } | |
8647 screen_cur_col = 0; | |
8648 } | |
8649 | |
8650 i = col - screen_cur_col; | |
8651 if (i > 0) | |
8652 { | |
8653 /* | |
8654 * Use cursor-right if it's one character only. Avoids | |
8655 * removing a line of pixels from the last bold char, when | |
8656 * using the bold trick in the GUI. | |
8657 */ | |
8658 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8659 { | |
8660 while (i-- > 0) | |
8661 out_char(*T_ND); | |
8662 } | |
8663 else | |
8664 { | |
8665 int off; | |
8666 | |
8667 off = LineOffset[row] + screen_cur_col; | |
8668 while (i-- > 0) | |
8669 { | |
8670 if (ScreenAttrs[off] != screen_attr) | |
8671 screen_stop_highlight(); | |
8672 #ifdef FEAT_MBYTE | |
8673 out_flush_check(); | |
8674 #endif | |
8675 out_char(ScreenLines[off]); | |
8676 #ifdef FEAT_MBYTE | |
8677 if (enc_dbcs == DBCS_JPNU | |
8678 && ScreenLines[off] == 0x8e) | |
8679 out_char(ScreenLines2[off]); | |
8680 #endif | |
8681 ++off; | |
8682 } | |
8683 } | |
8684 } | |
8685 } | |
8686 } | |
8687 else | |
8688 cost = 999; | |
8689 | |
8690 if (cost >= goto_cost) | |
8691 { | |
8692 if (noinvcurs) | |
8693 screen_stop_highlight(); | |
8694 if (row == screen_cur_row && (col > screen_cur_col) && | |
8695 *T_CRI != NUL) | |
8696 term_cursor_right(col - screen_cur_col); | |
8697 else | |
8698 term_windgoto(row, col); | |
8699 } | |
8700 screen_cur_row = row; | |
8701 screen_cur_col = col; | |
8702 } | |
8703 } | |
8704 | |
8705 /* | |
8706 * Set cursor to its position in the current window. | |
8707 */ | |
8708 void | |
8709 setcursor() | |
8710 { | |
8711 if (redrawing()) | |
8712 { | |
8713 validate_cursor(); | |
8714 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8715 W_WINCOL(curwin) + ( | |
8716 #ifdef FEAT_RIGHTLEFT | |
1545 | 8717 /* With 'rightleft' set and the cursor on a double-wide |
8718 * character, position it on the leftmost column. */ | |
7 | 8719 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8720 # ifdef FEAT_MBYTE | |
1545 | 8721 (has_mbyte |
8722 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8723 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8724 # endif |
8725 1)) : | |
8726 #endif | |
8727 curwin->w_wcol)); | |
8728 } | |
8729 } | |
8730 | |
8731 | |
8732 /* | |
8733 * insert 'line_count' lines at 'row' in window 'wp' | |
8734 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8735 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8736 * scrolling. | |
8737 * Returns FAIL if the lines are not inserted, OK for success. | |
8738 */ | |
8739 int | |
8740 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8741 win_T *wp; | |
8742 int row; | |
8743 int line_count; | |
8744 int invalid; | |
8745 int mayclear; | |
8746 { | |
8747 int did_delete; | |
8748 int nextrow; | |
8749 int lastrow; | |
8750 int retval; | |
8751 | |
8752 if (invalid) | |
8753 wp->w_lines_valid = 0; | |
8754 | |
8755 if (wp->w_height < 5) | |
8756 return FAIL; | |
8757 | |
8758 if (line_count > wp->w_height - row) | |
8759 line_count = wp->w_height - row; | |
8760 | |
8761 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8762 if (retval != MAYBE) | |
8763 return retval; | |
8764 | |
8765 /* | |
8766 * If there is a next window or a status line, we first try to delete the | |
8767 * lines at the bottom to avoid messing what is after the window. | |
8768 * If this fails and there are following windows, don't do anything to avoid | |
8769 * messing up those windows, better just redraw. | |
8770 */ | |
8771 did_delete = FALSE; | |
8772 #ifdef FEAT_WINDOWS | |
8773 if (wp->w_next != NULL || wp->w_status_height) | |
8774 { | |
8775 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8776 line_count, (int)Rows, FALSE, NULL) == OK) | |
8777 did_delete = TRUE; | |
8778 else if (wp->w_next) | |
8779 return FAIL; | |
8780 } | |
8781 #endif | |
8782 /* | |
8783 * if no lines deleted, blank the lines that will end up below the window | |
8784 */ | |
8785 if (!did_delete) | |
8786 { | |
8787 #ifdef FEAT_WINDOWS | |
8788 wp->w_redr_status = TRUE; | |
8789 #endif | |
8790 redraw_cmdline = TRUE; | |
8791 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8792 lastrow = nextrow + line_count; | |
8793 if (lastrow > Rows) | |
8794 lastrow = Rows; | |
8795 screen_fill(nextrow - line_count, lastrow - line_count, | |
8796 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8797 ' ', ' ', 0); | |
8798 } | |
8799 | |
8800 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8801 == FAIL) | |
8802 { | |
8803 /* deletion will have messed up other windows */ | |
8804 if (did_delete) | |
8805 { | |
8806 #ifdef FEAT_WINDOWS | |
8807 wp->w_redr_status = TRUE; | |
8808 #endif | |
8809 win_rest_invalid(W_NEXT(wp)); | |
8810 } | |
8811 return FAIL; | |
8812 } | |
8813 | |
8814 return OK; | |
8815 } | |
8816 | |
8817 /* | |
8818 * delete "line_count" window lines at "row" in window "wp" | |
8819 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8820 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8821 * scrolling | |
8822 * Return OK for success, FAIL if the lines are not deleted. | |
8823 */ | |
8824 int | |
8825 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8826 win_T *wp; | |
8827 int row; | |
8828 int line_count; | |
8829 int invalid; | |
8830 int mayclear; | |
8831 { | |
8832 int retval; | |
8833 | |
8834 if (invalid) | |
8835 wp->w_lines_valid = 0; | |
8836 | |
8837 if (line_count > wp->w_height - row) | |
8838 line_count = wp->w_height - row; | |
8839 | |
8840 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8841 if (retval != MAYBE) | |
8842 return retval; | |
8843 | |
8844 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8845 (int)Rows, FALSE, NULL) == FAIL) | |
8846 return FAIL; | |
8847 | |
8848 #ifdef FEAT_WINDOWS | |
8849 /* | |
8850 * If there are windows or status lines below, try to put them at the | |
8851 * correct place. If we can't do that, they have to be redrawn. | |
8852 */ | |
8853 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8854 { | |
8855 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8856 line_count, (int)Rows, NULL) == FAIL) | |
8857 { | |
8858 wp->w_redr_status = TRUE; | |
8859 win_rest_invalid(wp->w_next); | |
8860 } | |
8861 } | |
8862 /* | |
8863 * If this is the last window and there is no status line, redraw the | |
8864 * command line later. | |
8865 */ | |
8866 else | |
8867 #endif | |
8868 redraw_cmdline = TRUE; | |
8869 return OK; | |
8870 } | |
8871 | |
8872 /* | |
8873 * Common code for win_ins_lines() and win_del_lines(). | |
8874 * Returns OK or FAIL when the work has been done. | |
8875 * Returns MAYBE when not finished yet. | |
8876 */ | |
8877 static int | |
8878 win_do_lines(wp, row, line_count, mayclear, del) | |
8879 win_T *wp; | |
8880 int row; | |
8881 int line_count; | |
8882 int mayclear; | |
8883 int del; | |
8884 { | |
8885 int retval; | |
8886 | |
8887 if (!redrawing() || line_count <= 0) | |
8888 return FAIL; | |
8889 | |
8890 /* only a few lines left: redraw is faster */ | |
8891 if (mayclear && Rows - line_count < 5 | |
8892 #ifdef FEAT_VERTSPLIT | |
8893 && wp->w_width == Columns | |
8894 #endif | |
8895 ) | |
8896 { | |
8897 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8898 return FAIL; | |
8899 } | |
8900 | |
8901 /* | |
8902 * Delete all remaining lines | |
8903 */ | |
8904 if (row + line_count >= wp->w_height) | |
8905 { | |
8906 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8907 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8908 ' ', ' ', 0); | |
8909 return OK; | |
8910 } | |
8911 | |
8912 /* | |
8913 * when scrolling, the message on the command line should be cleared, | |
8914 * otherwise it will stay there forever. | |
8915 */ | |
8916 clear_cmdline = TRUE; | |
8917 | |
8918 /* | |
8919 * If the terminal can set a scroll region, use that. | |
8920 * Always do this in a vertically split window. This will redraw from | |
8921 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8922 * win_line(). | |
8923 * Don't use a scroll region when we are going to redraw the text, writing | |
8924 * a character in the lower right corner of the scroll region causes a | |
8925 * scroll-up in the DJGPP version. | |
8926 */ | |
8927 if (scroll_region | |
8928 #ifdef FEAT_VERTSPLIT | |
8929 || W_WIDTH(wp) != Columns | |
8930 #endif | |
8931 ) | |
8932 { | |
8933 #ifdef FEAT_VERTSPLIT | |
8934 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8935 #endif | |
8936 scroll_region_set(wp, row); | |
8937 if (del) | |
8938 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8939 wp->w_height - row, FALSE, wp); | |
8940 else | |
8941 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8942 wp->w_height - row, wp); | |
8943 #ifdef FEAT_VERTSPLIT | |
8944 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8945 #endif | |
8946 scroll_region_reset(); | |
8947 return retval; | |
8948 } | |
8949 | |
8950 #ifdef FEAT_WINDOWS | |
8951 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8952 return FAIL; | |
8953 #endif | |
8954 | |
8955 return MAYBE; | |
8956 } | |
8957 | |
8958 /* | |
8959 * window 'wp' and everything after it is messed up, mark it for redraw | |
8960 */ | |
8961 static void | |
8962 win_rest_invalid(wp) | |
8963 win_T *wp; | |
8964 { | |
8965 #ifdef FEAT_WINDOWS | |
8966 while (wp != NULL) | |
8967 #else | |
8968 if (wp != NULL) | |
8969 #endif | |
8970 { | |
8971 redraw_win_later(wp, NOT_VALID); | |
8972 #ifdef FEAT_WINDOWS | |
8973 wp->w_redr_status = TRUE; | |
8974 wp = wp->w_next; | |
8975 #endif | |
8976 } | |
8977 redraw_cmdline = TRUE; | |
8978 } | |
8979 | |
8980 /* | |
8981 * The rest of the routines in this file perform screen manipulations. The | |
8982 * given operation is performed physically on the screen. The corresponding | |
8983 * change is also made to the internal screen image. In this way, the editor | |
8984 * anticipates the effect of editing changes on the appearance of the screen. | |
8985 * That way, when we call screenupdate a complete redraw isn't usually | |
8986 * necessary. Another advantage is that we can keep adding code to anticipate | |
8987 * screen changes, and in the meantime, everything still works. | |
8988 */ | |
8989 | |
8990 /* | |
8991 * types for inserting or deleting lines | |
8992 */ | |
8993 #define USE_T_CAL 1 | |
8994 #define USE_T_CDL 2 | |
8995 #define USE_T_AL 3 | |
8996 #define USE_T_CE 4 | |
8997 #define USE_T_DL 5 | |
8998 #define USE_T_SR 6 | |
8999 #define USE_NL 7 | |
9000 #define USE_T_CD 8 | |
9001 #define USE_REDRAW 9 | |
9002 | |
9003 /* | |
9004 * insert lines on the screen and update ScreenLines[] | |
9005 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9006 * When scrolling region used 'off' is the offset from the top for the region. | |
9007 * 'row' and 'end' are relative to the start of the region. | |
9008 * | |
9009 * return FAIL for failure, OK for success. | |
9010 */ | |
446 | 9011 int |
7 | 9012 screen_ins_lines(off, row, line_count, end, wp) |
9013 int off; | |
9014 int row; | |
9015 int line_count; | |
9016 int end; | |
9017 win_T *wp; /* NULL or window to use width from */ | |
9018 { | |
9019 int i; | |
9020 int j; | |
9021 unsigned temp; | |
9022 int cursor_row; | |
9023 int type; | |
9024 int result_empty; | |
9025 int can_ce = can_clear(T_CE); | |
9026 | |
9027 /* | |
9028 * FAIL if | |
9029 * - there is no valid screen | |
9030 * - the screen has to be redrawn completely | |
9031 * - the line count is less than one | |
9032 * - the line count is more than 'ttyscroll' | |
9033 */ | |
9034 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
9035 return FAIL; | |
9036 | |
9037 /* | |
9038 * There are seven ways to insert lines: | |
9039 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9040 * characters from ScreenLines[]. | |
9041 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
9042 * the insert is just empty lines | |
9043 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
9044 * present or line_count > 1. It looks better if we do all the inserts | |
9045 * at once. | |
9046 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
9047 * insert is just empty lines and T_CE is not present or line_count > | |
9048 * 1. | |
9049 * 4. Use T_AL (insert line) if it exists. | |
9050 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
9051 * just empty lines. | |
9052 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
9053 * just empty lines. | |
9054 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
9055 * the 'da' flag is not set or we have clear line capability. | |
9056 * 8. redraw the characters from ScreenLines[]. | |
9057 * | |
9058 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
9059 * the scrollbar for the window. It does have insert line, use that if it | |
9060 * exists. | |
9061 */ | |
9062 result_empty = (row + line_count >= end); | |
9063 #ifdef FEAT_VERTSPLIT | |
9064 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9065 type = USE_REDRAW; | |
9066 else | |
9067 #endif | |
9068 if (can_clear(T_CD) && result_empty) | |
9069 type = USE_T_CD; | |
9070 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
9071 type = USE_T_CAL; | |
9072 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
9073 type = USE_T_CDL; | |
9074 else if (*T_AL != NUL) | |
9075 type = USE_T_AL; | |
9076 else if (can_ce && result_empty) | |
9077 type = USE_T_CE; | |
9078 else if (*T_DL != NUL && result_empty) | |
9079 type = USE_T_DL; | |
9080 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
9081 type = USE_T_SR; | |
9082 else | |
9083 return FAIL; | |
9084 | |
9085 /* | |
9086 * For clearing the lines screen_del_lines() is used. This will also take | |
9087 * care of t_db if necessary. | |
9088 */ | |
9089 if (type == USE_T_CD || type == USE_T_CDL || | |
9090 type == USE_T_CE || type == USE_T_DL) | |
9091 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
9092 | |
9093 /* | |
9094 * If text is retained below the screen, first clear or delete as many | |
9095 * lines at the bottom of the window as are about to be inserted so that | |
9096 * the deleted lines won't later surface during a screen_del_lines. | |
9097 */ | |
9098 if (*T_DB) | |
9099 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
9100 | |
9101 #ifdef FEAT_CLIPBOARD | |
9102 /* Remove a modeless selection when inserting lines halfway the screen | |
9103 * or not the full width of the screen. */ | |
9104 if (off + row > 0 | |
9105 # ifdef FEAT_VERTSPLIT | |
9106 || (wp != NULL && wp->w_width != Columns) | |
9107 # endif | |
9108 ) | |
3674 | 9109 clip_clear_selection(&clip_star); |
7 | 9110 else |
9111 clip_scroll_selection(-line_count); | |
9112 #endif | |
9113 | |
9114 #ifdef FEAT_GUI | |
9115 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9116 * scrolling is actually carried out. */ | |
9117 gui_dont_update_cursor(); | |
9118 #endif | |
9119 | |
9120 if (*T_CCS != NUL) /* cursor relative to region */ | |
9121 cursor_row = row; | |
9122 else | |
9123 cursor_row = row + off; | |
9124 | |
9125 /* | |
9126 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
9127 * Clear the inserted lines in ScreenLines[]. | |
9128 */ | |
9129 row += off; | |
9130 end += off; | |
9131 for (i = 0; i < line_count; ++i) | |
9132 { | |
9133 #ifdef FEAT_VERTSPLIT | |
9134 if (wp != NULL && wp->w_width != Columns) | |
9135 { | |
9136 /* need to copy part of a line */ | |
9137 j = end - 1 - i; | |
9138 while ((j -= line_count) >= row) | |
9139 linecopy(j + line_count, j, wp); | |
9140 j += line_count; | |
9141 if (can_clear((char_u *)" ")) | |
9142 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9143 else | |
9144 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9145 LineWraps[j] = FALSE; | |
9146 } | |
9147 else | |
9148 #endif | |
9149 { | |
9150 j = end - 1 - i; | |
9151 temp = LineOffset[j]; | |
9152 while ((j -= line_count) >= row) | |
9153 { | |
9154 LineOffset[j + line_count] = LineOffset[j]; | |
9155 LineWraps[j + line_count] = LineWraps[j]; | |
9156 } | |
9157 LineOffset[j + line_count] = temp; | |
9158 LineWraps[j + line_count] = FALSE; | |
9159 if (can_clear((char_u *)" ")) | |
9160 lineclear(temp, (int)Columns); | |
9161 else | |
9162 lineinvalid(temp, (int)Columns); | |
9163 } | |
9164 } | |
9165 | |
9166 screen_stop_highlight(); | |
9167 windgoto(cursor_row, 0); | |
9168 | |
9169 #ifdef FEAT_VERTSPLIT | |
9170 /* redraw the characters */ | |
9171 if (type == USE_REDRAW) | |
9172 redraw_block(row, end, wp); | |
9173 else | |
9174 #endif | |
9175 if (type == USE_T_CAL) | |
9176 { | |
9177 term_append_lines(line_count); | |
9178 screen_start(); /* don't know where cursor is now */ | |
9179 } | |
9180 else | |
9181 { | |
9182 for (i = 0; i < line_count; i++) | |
9183 { | |
9184 if (type == USE_T_AL) | |
9185 { | |
9186 if (i && cursor_row != 0) | |
9187 windgoto(cursor_row, 0); | |
9188 out_str(T_AL); | |
9189 } | |
9190 else /* type == USE_T_SR */ | |
9191 out_str(T_SR); | |
9192 screen_start(); /* don't know where cursor is now */ | |
9193 } | |
9194 } | |
9195 | |
9196 /* | |
9197 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9198 * have been scrolled down into the region. | |
9199 */ | |
9200 if (type == USE_T_SR && *T_DA) | |
9201 { | |
9202 for (i = 0; i < line_count; ++i) | |
9203 { | |
9204 windgoto(off + i, 0); | |
9205 out_str(T_CE); | |
9206 screen_start(); /* don't know where cursor is now */ | |
9207 } | |
9208 } | |
9209 | |
9210 #ifdef FEAT_GUI | |
9211 gui_can_update_cursor(); | |
9212 if (gui.in_use) | |
9213 out_flush(); /* always flush after a scroll */ | |
9214 #endif | |
9215 return OK; | |
9216 } | |
9217 | |
9218 /* | |
9219 * delete lines on the screen and update ScreenLines[] | |
9220 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9221 * When scrolling region used 'off' is the offset from the top for the region. | |
9222 * 'row' and 'end' are relative to the start of the region. | |
9223 * | |
9224 * Return OK for success, FAIL if the lines are not deleted. | |
9225 */ | |
9226 int | |
9227 screen_del_lines(off, row, line_count, end, force, wp) | |
9228 int off; | |
9229 int row; | |
9230 int line_count; | |
9231 int end; | |
9232 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9233 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9234 { |
9235 int j; | |
9236 int i; | |
9237 unsigned temp; | |
9238 int cursor_row; | |
9239 int cursor_end; | |
9240 int result_empty; /* result is empty until end of region */ | |
9241 int can_delete; /* deleting line codes can be used */ | |
9242 int type; | |
9243 | |
9244 /* | |
9245 * FAIL if | |
9246 * - there is no valid screen | |
9247 * - the screen has to be redrawn completely | |
9248 * - the line count is less than one | |
9249 * - the line count is more than 'ttyscroll' | |
9250 */ | |
9251 if (!screen_valid(TRUE) || line_count <= 0 || | |
9252 (!force && line_count > p_ttyscroll)) | |
9253 return FAIL; | |
9254 | |
9255 /* | |
9256 * Check if the rest of the current region will become empty. | |
9257 */ | |
9258 result_empty = row + line_count >= end; | |
9259 | |
9260 /* | |
9261 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9262 * available. | |
9263 */ | |
9264 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9265 | |
9266 /* | |
9267 * There are six ways to delete lines: | |
9268 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9269 * characters from ScreenLines[]. | |
9270 * 1. Use T_CD if it exists and the result is empty. | |
9271 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9272 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9273 * none of the other ways work. | |
9274 * 4. Use T_CE (erase line) if the result is empty. | |
9275 * 5. Use T_DL (delete line) if it exists. | |
9276 * 6. redraw the characters from ScreenLines[]. | |
9277 */ | |
9278 #ifdef FEAT_VERTSPLIT | |
9279 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9280 type = USE_REDRAW; | |
9281 else | |
9282 #endif | |
9283 if (can_clear(T_CD) && result_empty) | |
9284 type = USE_T_CD; | |
9285 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9286 /* | |
9287 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9288 * its internal termcap... this works okay for tests which test *T_DB != | |
9289 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9290 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9291 * the trick... | |
9292 * Anyway, this hack will hopefully go away with the next OS release. | |
9293 * (Olaf Seibert) | |
9294 */ | |
9295 else if (row == 0 && T_DB == empty_option | |
9296 && (line_count == 1 || *T_CDL == NUL)) | |
9297 #else | |
9298 else if (row == 0 && ( | |
9299 #ifndef AMIGA | |
9300 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9301 * up, so use delete-line command */ | |
9302 line_count == 1 || | |
9303 #endif | |
9304 *T_CDL == NUL)) | |
9305 #endif | |
9306 type = USE_NL; | |
9307 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9308 type = USE_T_CDL; | |
9309 else if (can_clear(T_CE) && result_empty | |
9310 #ifdef FEAT_VERTSPLIT | |
9311 && (wp == NULL || wp->w_width == Columns) | |
9312 #endif | |
9313 ) | |
9314 type = USE_T_CE; | |
9315 else if (*T_DL != NUL && can_delete) | |
9316 type = USE_T_DL; | |
9317 else if (*T_CDL != NUL && can_delete) | |
9318 type = USE_T_CDL; | |
9319 else | |
9320 return FAIL; | |
9321 | |
9322 #ifdef FEAT_CLIPBOARD | |
9323 /* Remove a modeless selection when deleting lines halfway the screen or | |
9324 * not the full width of the screen. */ | |
9325 if (off + row > 0 | |
9326 # ifdef FEAT_VERTSPLIT | |
9327 || (wp != NULL && wp->w_width != Columns) | |
9328 # endif | |
9329 ) | |
3674 | 9330 clip_clear_selection(&clip_star); |
7 | 9331 else |
9332 clip_scroll_selection(line_count); | |
9333 #endif | |
9334 | |
9335 #ifdef FEAT_GUI | |
9336 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9337 * scrolling is actually carried out. */ | |
9338 gui_dont_update_cursor(); | |
9339 #endif | |
9340 | |
9341 if (*T_CCS != NUL) /* cursor relative to region */ | |
9342 { | |
9343 cursor_row = row; | |
9344 cursor_end = end; | |
9345 } | |
9346 else | |
9347 { | |
9348 cursor_row = row + off; | |
9349 cursor_end = end + off; | |
9350 } | |
9351 | |
9352 /* | |
9353 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9354 * Clear the inserted lines in ScreenLines[]. | |
9355 */ | |
9356 row += off; | |
9357 end += off; | |
9358 for (i = 0; i < line_count; ++i) | |
9359 { | |
9360 #ifdef FEAT_VERTSPLIT | |
9361 if (wp != NULL && wp->w_width != Columns) | |
9362 { | |
9363 /* need to copy part of a line */ | |
9364 j = row + i; | |
9365 while ((j += line_count) <= end - 1) | |
9366 linecopy(j - line_count, j, wp); | |
9367 j -= line_count; | |
9368 if (can_clear((char_u *)" ")) | |
9369 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9370 else | |
9371 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9372 LineWraps[j] = FALSE; | |
9373 } | |
9374 else | |
9375 #endif | |
9376 { | |
9377 /* whole width, moving the line pointers is faster */ | |
9378 j = row + i; | |
9379 temp = LineOffset[j]; | |
9380 while ((j += line_count) <= end - 1) | |
9381 { | |
9382 LineOffset[j - line_count] = LineOffset[j]; | |
9383 LineWraps[j - line_count] = LineWraps[j]; | |
9384 } | |
9385 LineOffset[j - line_count] = temp; | |
9386 LineWraps[j - line_count] = FALSE; | |
9387 if (can_clear((char_u *)" ")) | |
9388 lineclear(temp, (int)Columns); | |
9389 else | |
9390 lineinvalid(temp, (int)Columns); | |
9391 } | |
9392 } | |
9393 | |
9394 screen_stop_highlight(); | |
9395 | |
9396 #ifdef FEAT_VERTSPLIT | |
9397 /* redraw the characters */ | |
9398 if (type == USE_REDRAW) | |
9399 redraw_block(row, end, wp); | |
9400 else | |
9401 #endif | |
9402 if (type == USE_T_CD) /* delete the lines */ | |
9403 { | |
9404 windgoto(cursor_row, 0); | |
9405 out_str(T_CD); | |
9406 screen_start(); /* don't know where cursor is now */ | |
9407 } | |
9408 else if (type == USE_T_CDL) | |
9409 { | |
9410 windgoto(cursor_row, 0); | |
9411 term_delete_lines(line_count); | |
9412 screen_start(); /* don't know where cursor is now */ | |
9413 } | |
9414 /* | |
9415 * Deleting lines at top of the screen or scroll region: Just scroll | |
9416 * the whole screen (scroll region) up by outputting newlines on the | |
9417 * last line. | |
9418 */ | |
9419 else if (type == USE_NL) | |
9420 { | |
9421 windgoto(cursor_end - 1, 0); | |
9422 for (i = line_count; --i >= 0; ) | |
9423 out_char('\n'); /* cursor will remain on same line */ | |
9424 } | |
9425 else | |
9426 { | |
9427 for (i = line_count; --i >= 0; ) | |
9428 { | |
9429 if (type == USE_T_DL) | |
9430 { | |
9431 windgoto(cursor_row, 0); | |
9432 out_str(T_DL); /* delete a line */ | |
9433 } | |
9434 else /* type == USE_T_CE */ | |
9435 { | |
9436 windgoto(cursor_row + i, 0); | |
9437 out_str(T_CE); /* erase a line */ | |
9438 } | |
9439 screen_start(); /* don't know where cursor is now */ | |
9440 } | |
9441 } | |
9442 | |
9443 /* | |
9444 * If the 'db' flag is set, we need to clear the lines that have been | |
9445 * scrolled up at the bottom of the region. | |
9446 */ | |
9447 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9448 { | |
9449 for (i = line_count; i > 0; --i) | |
9450 { | |
9451 windgoto(cursor_end - i, 0); | |
9452 out_str(T_CE); /* erase a line */ | |
9453 screen_start(); /* don't know where cursor is now */ | |
9454 } | |
9455 } | |
9456 | |
9457 #ifdef FEAT_GUI | |
9458 gui_can_update_cursor(); | |
9459 if (gui.in_use) | |
9460 out_flush(); /* always flush after a scroll */ | |
9461 #endif | |
9462 | |
9463 return OK; | |
9464 } | |
9465 | |
9466 /* | |
9467 * show the current mode and ruler | |
9468 * | |
9469 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9470 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9471 * cleared only if a mode is shown. | |
9472 * Return the length of the message (0 if no message). | |
9473 */ | |
9474 int | |
9475 showmode() | |
9476 { | |
9477 int need_clear; | |
9478 int length = 0; | |
9479 int do_mode; | |
9480 int attr; | |
9481 int nwr_save; | |
9482 #ifdef FEAT_INS_EXPAND | |
9483 int sub_attr; | |
9484 #endif | |
9485 | |
642 | 9486 do_mode = ((p_smd && msg_silent == 0) |
9487 && ((State & INSERT) | |
9488 || restart_edit | |
7 | 9489 #ifdef FEAT_VISUAL |
9490 || VIsual_active | |
9491 #endif | |
9492 )); | |
9493 if (do_mode || Recording) | |
9494 { | |
9495 /* | |
9496 * Don't show mode right now, when not redrawing or inside a mapping. | |
9497 * Call char_avail() only when we are going to show something, because | |
9498 * it takes a bit of time. | |
9499 */ | |
9500 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9501 { | |
9502 redraw_cmdline = TRUE; /* show mode later */ | |
9503 return 0; | |
9504 } | |
9505 | |
9506 nwr_save = need_wait_return; | |
9507 | |
9508 /* wait a bit before overwriting an important message */ | |
9509 check_for_delay(FALSE); | |
9510 | |
9511 /* if the cmdline is more than one line high, erase top lines */ | |
9512 need_clear = clear_cmdline; | |
9513 if (clear_cmdline && cmdline_row < Rows - 1) | |
9514 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9515 | |
9516 /* Position on the last line in the window, column 0 */ | |
9517 msg_pos_mode(); | |
9518 cursor_off(); | |
9519 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9520 if (do_mode) | |
9521 { | |
9522 MSG_PUTS_ATTR("--", attr); | |
9523 #if defined(FEAT_XIM) | |
2520 | 9524 if ( |
9525 # ifdef FEAT_GUI_GTK | |
9526 preedit_get_status() | |
1668 | 9527 # else |
9528 im_get_status() | |
2520 | 9529 # endif |
1668 | 9530 ) |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9531 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9532 MSG_PUTS_ATTR(" IM", attr); |
9533 # else | |
9534 MSG_PUTS_ATTR(" XIM", attr); | |
9535 # endif | |
9536 #endif | |
9537 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9538 if (gui.in_use) | |
9539 { | |
9540 if (hangul_input_state_get()) | |
236 | 9541 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9542 } |
9543 #endif | |
9544 #ifdef FEAT_INS_EXPAND | |
9545 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9546 { | |
9547 /* These messages can get long, avoid a wrap in a narrow | |
9548 * window. Prefer showing edit_submode_extra. */ | |
9549 length = (Rows - msg_row) * Columns - 3; | |
9550 if (edit_submode_extra != NULL) | |
9551 length -= vim_strsize(edit_submode_extra); | |
9552 if (length > 0) | |
9553 { | |
9554 if (edit_submode_pre != NULL) | |
9555 length -= vim_strsize(edit_submode_pre); | |
9556 if (length - vim_strsize(edit_submode) > 0) | |
9557 { | |
9558 if (edit_submode_pre != NULL) | |
9559 msg_puts_attr(edit_submode_pre, attr); | |
9560 msg_puts_attr(edit_submode, attr); | |
9561 } | |
9562 if (edit_submode_extra != NULL) | |
9563 { | |
9564 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9565 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9566 sub_attr = hl_attr(edit_submode_highl); | |
9567 else | |
9568 sub_attr = attr; | |
9569 msg_puts_attr(edit_submode_extra, sub_attr); | |
9570 } | |
9571 } | |
9572 length = 0; | |
9573 } | |
9574 else | |
9575 #endif | |
9576 { | |
9577 #ifdef FEAT_VREPLACE | |
9578 if (State & VREPLACE_FLAG) | |
9579 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9580 else | |
9581 #endif | |
9582 if (State & REPLACE_FLAG) | |
9583 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9584 else if (State & INSERT) | |
9585 { | |
9586 #ifdef FEAT_RIGHTLEFT | |
9587 if (p_ri) | |
9588 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9589 #endif | |
9590 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9591 } | |
9592 else if (restart_edit == 'I') | |
9593 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9594 else if (restart_edit == 'R') | |
9595 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9596 else if (restart_edit == 'V') | |
9597 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9598 #ifdef FEAT_RIGHTLEFT | |
9599 if (p_hkmap) | |
9600 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9601 # ifdef FEAT_FKMAP | |
9602 if (p_fkmap) | |
9603 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9604 # endif | |
9605 #endif | |
9606 #ifdef FEAT_KEYMAP | |
9607 if (State & LANGMAP) | |
9608 { | |
9609 # ifdef FEAT_ARABIC | |
9610 if (curwin->w_p_arab) | |
9611 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9612 else | |
9613 # endif | |
9614 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9615 } | |
9616 #endif | |
9617 if ((State & INSERT) && p_paste) | |
9618 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9619 | |
9620 #ifdef FEAT_VISUAL | |
9621 if (VIsual_active) | |
9622 { | |
9623 char *p; | |
9624 | |
9625 /* Don't concatenate separate words to avoid translation | |
9626 * problems. */ | |
9627 switch ((VIsual_select ? 4 : 0) | |
9628 + (VIsual_mode == Ctrl_V) * 2 | |
9629 + (VIsual_mode == 'V')) | |
9630 { | |
9631 case 0: p = N_(" VISUAL"); break; | |
9632 case 1: p = N_(" VISUAL LINE"); break; | |
9633 case 2: p = N_(" VISUAL BLOCK"); break; | |
9634 case 4: p = N_(" SELECT"); break; | |
9635 case 5: p = N_(" SELECT LINE"); break; | |
9636 default: p = N_(" SELECT BLOCK"); break; | |
9637 } | |
9638 MSG_PUTS_ATTR(_(p), attr); | |
9639 } | |
9640 #endif | |
9641 MSG_PUTS_ATTR(" --", attr); | |
9642 } | |
644 | 9643 |
7 | 9644 need_clear = TRUE; |
9645 } | |
9646 if (Recording | |
9647 #ifdef FEAT_INS_EXPAND | |
9648 && edit_submode == NULL /* otherwise it gets too long */ | |
9649 #endif | |
9650 ) | |
9651 { | |
9652 MSG_PUTS_ATTR(_("recording"), attr); | |
9653 need_clear = TRUE; | |
9654 } | |
644 | 9655 |
9656 mode_displayed = TRUE; | |
7 | 9657 if (need_clear || clear_cmdline) |
9658 msg_clr_eos(); | |
9659 msg_didout = FALSE; /* overwrite this message */ | |
9660 length = msg_col; | |
9661 msg_col = 0; | |
9662 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9663 } | |
9664 else if (clear_cmdline && msg_silent == 0) | |
9665 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9666 msg_clr_cmdline(); | |
9667 | |
9668 #ifdef FEAT_CMDL_INFO | |
9669 # ifdef FEAT_VISUAL | |
9670 /* In Visual mode the size of the selected area must be redrawn. */ | |
9671 if (VIsual_active) | |
9672 clear_showcmd(); | |
9673 # endif | |
9674 | |
9675 /* If the last window has no status line, the ruler is after the mode | |
9676 * message and must be redrawn */ | |
9677 if (redrawing() | |
9678 # ifdef FEAT_WINDOWS | |
9679 && lastwin->w_status_height == 0 | |
9680 # endif | |
9681 ) | |
9682 win_redr_ruler(lastwin, TRUE); | |
9683 #endif | |
9684 redraw_cmdline = FALSE; | |
9685 clear_cmdline = FALSE; | |
9686 | |
9687 return length; | |
9688 } | |
9689 | |
9690 /* | |
9691 * Position for a mode message. | |
9692 */ | |
9693 static void | |
9694 msg_pos_mode() | |
9695 { | |
9696 msg_col = 0; | |
9697 msg_row = Rows - 1; | |
9698 } | |
9699 | |
9700 /* | |
9701 * Delete mode message. Used when ESC is typed which is expected to end | |
9702 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9703 * Caller should check "mode_displayed". |
7 | 9704 */ |
9705 void | |
9706 unshowmode(force) | |
9707 int force; | |
9708 { | |
9709 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9710 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9711 */ |
9712 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9713 redraw_cmdline = TRUE; /* delete mode later */ | |
9714 else | |
9715 { | |
9716 msg_pos_mode(); | |
9717 if (Recording) | |
9718 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9719 msg_clr_eos(); | |
9720 } | |
9721 } | |
9722 | |
667 | 9723 #if defined(FEAT_WINDOWS) |
9724 /* | |
9725 * Draw the tab pages line at the top of the Vim window. | |
9726 */ | |
9727 static void | |
677 | 9728 draw_tabline() |
667 | 9729 { |
9730 int tabcount = 0; | |
9731 tabpage_T *tp; | |
9732 int tabwidth; | |
9733 int col = 0; | |
673 | 9734 int scol = 0; |
667 | 9735 int attr; |
9736 win_T *wp; | |
671 | 9737 win_T *cwp; |
9738 int wincount; | |
9739 int modified; | |
667 | 9740 int c; |
9741 int len; | |
9742 int attr_sel = hl_attr(HLF_TPS); | |
9743 int attr_nosel = hl_attr(HLF_TP); | |
9744 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9745 char_u *p; |
677 | 9746 int room; |
9747 int use_sep_chars = (t_colors < 8 | |
9748 #ifdef FEAT_GUI | |
9749 && !gui.in_use | |
9750 #endif | |
9751 ); | |
673 | 9752 |
9753 redraw_tabline = FALSE; | |
667 | 9754 |
685 | 9755 #ifdef FEAT_GUI_TABLINE |
798 | 9756 /* Take care of a GUI tabline. */ |
685 | 9757 if (gui_use_tabline()) |
9758 { | |
9759 gui_update_tabline(); | |
9760 return; | |
9761 } | |
9762 #endif | |
9763 | |
9764 if (tabline_height() < 1) | |
667 | 9765 return; |
9766 | |
677 | 9767 #if defined(FEAT_STL_OPT) |
681 | 9768 |
9769 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9770 for (scol = 0; scol < Columns; ++scol) | |
9771 TabPageIdxs[scol] = 0; | |
9772 | |
677 | 9773 /* Use the 'tabline' option if it's set. */ |
9774 if (*p_tal != NUL) | |
9775 { | |
680 | 9776 int save_called_emsg = called_emsg; |
9777 | |
9778 /* Check for an error. If there is one we would loop in redrawing the | |
9779 * screen. Avoid that by making 'tabline' empty. */ | |
9780 called_emsg = FALSE; | |
677 | 9781 win_redr_custom(NULL, FALSE); |
680 | 9782 if (called_emsg) |
9783 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9784 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9785 called_emsg |= save_called_emsg; |
9786 } | |
9787 else | |
9788 #endif | |
9789 { | |
9790 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9791 ++tabcount; | |
9792 | |
9793 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9794 if (tabwidth < 6) | |
9795 tabwidth = 6; | |
9796 | |
9797 attr = attr_nosel; | |
9798 tabcount = 0; | |
681 | 9799 scol = 0; |
699 | 9800 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9801 tp = tp->tp_next) | |
680 | 9802 { |
9803 scol = col; | |
9804 | |
9805 if (tp->tp_topframe == topframe) | |
9806 attr = attr_sel; | |
9807 if (use_sep_chars && col > 0) | |
9808 screen_putchar('|', 0, col++, attr); | |
9809 | |
9810 if (tp->tp_topframe != topframe) | |
9811 attr = attr_nosel; | |
9812 | |
9813 screen_putchar(' ', 0, col++, attr); | |
9814 | |
9815 if (tp == curtab) | |
9816 { | |
9817 cwp = curwin; | |
9818 wp = firstwin; | |
9819 } | |
9820 else | |
9821 { | |
9822 cwp = tp->tp_curwin; | |
9823 wp = tp->tp_firstwin; | |
9824 } | |
9825 | |
9826 modified = FALSE; | |
9827 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9828 if (bufIsChanged(wp->w_buffer)) | |
9829 modified = TRUE; | |
9830 if (modified || wincount > 1) | |
9831 { | |
9832 if (wincount > 1) | |
9833 { | |
9834 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9835 len = (int)STRLEN(NameBuff); |
699 | 9836 if (col + len >= Columns - 3) |
9837 break; | |
680 | 9838 screen_puts_len(NameBuff, len, 0, col, |
677 | 9839 #if defined(FEAT_SYN_HL) |
680 | 9840 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9841 #else |
680 | 9842 attr |
9843 #endif | |
9844 ); | |
9845 col += len; | |
9846 } | |
9847 if (modified) | |
9848 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9849 screen_putchar(' ', 0, col++, attr); | |
9850 } | |
9851 | |
9852 room = scol - col + tabwidth - 1; | |
9853 if (room > 0) | |
9854 { | |
685 | 9855 /* Get buffer name in NameBuff[] */ |
9856 get_trans_bufname(cwp->w_buffer); | |
819 | 9857 shorten_dir(NameBuff); |
680 | 9858 len = vim_strsize(NameBuff); |
9859 p = NameBuff; | |
677 | 9860 #ifdef FEAT_MBYTE |
680 | 9861 if (has_mbyte) |
9862 while (len > room) | |
9863 { | |
9864 len -= ptr2cells(p); | |
9865 mb_ptr_adv(p); | |
9866 } | |
9867 else | |
9868 #endif | |
9869 if (len > room) | |
677 | 9870 { |
680 | 9871 p += len - room; |
9872 len = room; | |
677 | 9873 } |
699 | 9874 if (len > Columns - col - 1) |
9875 len = Columns - col - 1; | |
680 | 9876 |
835 | 9877 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9878 col += len; |
9879 } | |
9880 screen_putchar(' ', 0, col++, attr); | |
9881 | |
9882 /* Store the tab page number in TabPageIdxs[], so that | |
9883 * jump_to_mouse() knows where each one is. */ | |
9884 ++tabcount; | |
9885 while (scol < col) | |
9886 TabPageIdxs[scol++] = tabcount; | |
9887 } | |
9888 | |
9889 if (use_sep_chars) | |
9890 c = '_'; | |
9891 else | |
9892 c = ' '; | |
9893 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9894 |
9895 /* Put an "X" for closing the current tab if there are several. */ | |
9896 if (first_tabpage->tp_next != NULL) | |
9897 { | |
9898 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9899 TabPageIdxs[Columns - 1] = -999; | |
9900 } | |
9901 } | |
834 | 9902 |
9903 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9904 * set. */ | |
9905 redraw_tabline = FALSE; | |
667 | 9906 } |
685 | 9907 |
9908 /* | |
9909 * Get buffer name for "buf" into NameBuff[]. | |
9910 * Takes care of special buffer names and translates special characters. | |
9911 */ | |
9912 void | |
9913 get_trans_bufname(buf) | |
9914 buf_T *buf; | |
9915 { | |
9916 if (buf_spname(buf) != NULL) | |
3839 | 9917 vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
685 | 9918 else |
9919 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9920 trans_characters(NameBuff, MAXPATHL); | |
9921 } | |
667 | 9922 #endif |
9923 | |
7 | 9924 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9925 /* | |
9926 * Get the character to use in a status line. Get its attributes in "*attr". | |
9927 */ | |
9928 static int | |
9929 fillchar_status(attr, is_curwin) | |
9930 int *attr; | |
9931 int is_curwin; | |
9932 { | |
9933 int fill; | |
9934 if (is_curwin) | |
9935 { | |
9936 *attr = hl_attr(HLF_S); | |
9937 fill = fill_stl; | |
9938 } | |
9939 else | |
9940 { | |
9941 *attr = hl_attr(HLF_SNC); | |
9942 fill = fill_stlnc; | |
9943 } | |
9944 /* Use fill when there is highlighting, and highlighting of current | |
9945 * window differs, or the fillchars differ, or this is not the | |
9946 * current window */ | |
9947 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9948 || !is_curwin || firstwin == lastwin) | |
9949 || (fill_stl != fill_stlnc))) | |
9950 return fill; | |
9951 if (is_curwin) | |
9952 return '^'; | |
9953 return '='; | |
9954 } | |
9955 #endif | |
9956 | |
9957 #ifdef FEAT_VERTSPLIT | |
9958 /* | |
9959 * Get the character to use in a separator between vertically split windows. | |
9960 * Get its attributes in "*attr". | |
9961 */ | |
9962 static int | |
9963 fillchar_vsep(attr) | |
9964 int *attr; | |
9965 { | |
9966 *attr = hl_attr(HLF_C); | |
9967 if (*attr == 0 && fill_vert == ' ') | |
9968 return '|'; | |
9969 else | |
9970 return fill_vert; | |
9971 } | |
9972 #endif | |
9973 | |
9974 /* | |
9975 * Return TRUE if redrawing should currently be done. | |
9976 */ | |
9977 int | |
9978 redrawing() | |
9979 { | |
9980 return (!RedrawingDisabled | |
9981 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9982 } | |
9983 | |
9984 /* | |
9985 * Return TRUE if printing messages should currently be done. | |
9986 */ | |
9987 int | |
9988 messaging() | |
9989 { | |
9990 return (!(p_lz && char_avail() && !KeyTyped)); | |
9991 } | |
9992 | |
9993 /* | |
9994 * Show current status info in ruler and various other places | |
9995 * If always is FALSE, only show ruler if position has changed. | |
9996 */ | |
9997 void | |
9998 showruler(always) | |
9999 int always; | |
10000 { | |
10001 if (!always && !redrawing()) | |
10002 return; | |
574 | 10003 #ifdef FEAT_INS_EXPAND |
10004 if (pum_visible()) | |
10005 { | |
639 | 10006 # ifdef FEAT_WINDOWS |
574 | 10007 /* Don't redraw right now, do it later. */ |
10008 curwin->w_redr_status = TRUE; | |
639 | 10009 # endif |
574 | 10010 return; |
10011 } | |
10012 #endif | |
7 | 10013 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 10014 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 10015 { |
1983 | 10016 redraw_custom_statusline(curwin); |
680 | 10017 } |
7 | 10018 else |
10019 #endif | |
10020 #ifdef FEAT_CMDL_INFO | |
10021 win_redr_ruler(curwin, always); | |
10022 #endif | |
10023 | |
10024 #ifdef FEAT_TITLE | |
10025 if (need_maketitle | |
10026 # ifdef FEAT_STL_OPT | |
10027 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
10028 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
10029 # endif | |
10030 ) | |
10031 maketitle(); | |
10032 #endif | |
1588 | 10033 #ifdef FEAT_WINDOWS |
10034 /* Redraw the tab pages line if needed. */ | |
10035 if (redraw_tabline) | |
10036 draw_tabline(); | |
10037 #endif | |
7 | 10038 } |
10039 | |
10040 #ifdef FEAT_CMDL_INFO | |
10041 static void | |
10042 win_redr_ruler(wp, always) | |
10043 win_T *wp; | |
10044 int always; | |
10045 { | |
1869 | 10046 #define RULER_BUF_LEN 70 |
10047 char_u buffer[RULER_BUF_LEN]; | |
7 | 10048 int row; |
10049 int fillchar; | |
10050 int attr; | |
10051 int empty_line = FALSE; | |
10052 colnr_T virtcol; | |
10053 int i; | |
1869 | 10054 size_t len; |
7 | 10055 int o; |
10056 #ifdef FEAT_VERTSPLIT | |
10057 int this_ru_col; | |
10058 int off = 0; | |
10059 int width = Columns; | |
10060 # define WITH_OFF(x) x | |
10061 # define WITH_WIDTH(x) x | |
10062 #else | |
10063 # define WITH_OFF(x) 0 | |
10064 # define WITH_WIDTH(x) Columns | |
10065 # define this_ru_col ru_col | |
10066 #endif | |
10067 | |
10068 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
10069 if (!p_ru) | |
10070 return; | |
10071 | |
10072 /* | |
10073 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
10074 * after deleting lines, before cursor.lnum is corrected. | |
10075 */ | |
10076 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
10077 return; | |
10078 | |
10079 #ifdef FEAT_INS_EXPAND | |
10080 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
10081 * the (long) mode message. */ | |
10082 # ifdef FEAT_WINDOWS | |
10083 if (wp == lastwin && lastwin->w_status_height == 0) | |
10084 # endif | |
10085 if (edit_submode != NULL) | |
10086 return; | |
540 | 10087 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
10088 if (pum_visible()) | |
10089 return; | |
7 | 10090 #endif |
10091 | |
10092 #ifdef FEAT_STL_OPT | |
10093 if (*p_ruf) | |
10094 { | |
680 | 10095 int save_called_emsg = called_emsg; |
10096 | |
10097 called_emsg = FALSE; | |
7 | 10098 win_redr_custom(wp, TRUE); |
680 | 10099 if (called_emsg) |
10100 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 10101 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 10102 called_emsg |= save_called_emsg; |
7 | 10103 return; |
10104 } | |
10105 #endif | |
10106 | |
10107 /* | |
10108 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
10109 */ | |
10110 if (!(State & INSERT) | |
10111 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
10112 empty_line = TRUE; | |
10113 | |
10114 /* | |
10115 * Only draw the ruler when something changed. | |
10116 */ | |
10117 validate_virtcol_win(wp); | |
10118 if ( redraw_cmdline | |
10119 || always | |
10120 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
10121 || wp->w_cursor.col != wp->w_ru_cursor.col | |
10122 || wp->w_virtcol != wp->w_ru_virtcol | |
10123 #ifdef FEAT_VIRTUALEDIT | |
10124 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
10125 #endif | |
10126 || wp->w_topline != wp->w_ru_topline | |
10127 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
10128 #ifdef FEAT_DIFF | |
10129 || wp->w_topfill != wp->w_ru_topfill | |
10130 #endif | |
10131 || empty_line != wp->w_ru_empty) | |
10132 { | |
10133 cursor_off(); | |
10134 #ifdef FEAT_WINDOWS | |
10135 if (wp->w_status_height) | |
10136 { | |
10137 row = W_WINROW(wp) + wp->w_height; | |
10138 fillchar = fillchar_status(&attr, wp == curwin); | |
10139 # ifdef FEAT_VERTSPLIT | |
10140 off = W_WINCOL(wp); | |
10141 width = W_WIDTH(wp); | |
10142 # endif | |
10143 } | |
10144 else | |
10145 #endif | |
10146 { | |
10147 row = Rows - 1; | |
10148 fillchar = ' '; | |
10149 attr = 0; | |
10150 #ifdef FEAT_VERTSPLIT | |
10151 width = Columns; | |
10152 off = 0; | |
10153 #endif | |
10154 } | |
10155 | |
10156 /* In list mode virtcol needs to be recomputed */ | |
10157 virtcol = wp->w_virtcol; | |
10158 if (wp->w_p_list && lcs_tab1 == NUL) | |
10159 { | |
10160 wp->w_p_list = FALSE; | |
10161 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10162 wp->w_p_list = TRUE; | |
10163 } | |
10164 | |
10165 /* | |
10166 * Some sprintfs return the length, some return a pointer. | |
10167 * To avoid portability problems we use strlen() here. | |
10168 */ | |
1869 | 10169 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10170 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10171 ? 0L | |
10172 : (long)(wp->w_cursor.lnum)); | |
1869 | 10173 len = STRLEN(buffer); |
10174 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10175 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10176 (int)virtcol + 1); | |
10177 | |
10178 /* | |
10179 * Add a "50%" if there is room for it. | |
10180 * On the last line, don't print in the last column (scrolls the | |
10181 * screen up on some terminals). | |
10182 */ | |
10183 i = (int)STRLEN(buffer); | |
1869 | 10184 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10185 o = i + vim_strsize(buffer + i + 1); |
10186 #ifdef FEAT_WINDOWS | |
10187 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10188 #endif | |
10189 ++o; | |
10190 #ifdef FEAT_VERTSPLIT | |
10191 this_ru_col = ru_col - (Columns - width); | |
10192 if (this_ru_col < 0) | |
10193 this_ru_col = 0; | |
10194 #endif | |
10195 /* Never use more than half the window/screen width, leave the other | |
10196 * half for the filename. */ | |
10197 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10198 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10199 if (this_ru_col + o < WITH_WIDTH(width)) | |
10200 { | |
10201 while (this_ru_col + o < WITH_WIDTH(width)) | |
10202 { | |
10203 #ifdef FEAT_MBYTE | |
10204 if (has_mbyte) | |
10205 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10206 else | |
10207 #endif | |
10208 buffer[i++] = fillchar; | |
10209 ++o; | |
10210 } | |
1869 | 10211 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10212 } |
10213 /* Truncate at window boundary. */ | |
10214 #ifdef FEAT_MBYTE | |
10215 if (has_mbyte) | |
10216 { | |
10217 o = 0; | |
474 | 10218 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10219 { |
10220 o += (*mb_ptr2cells)(buffer + i); | |
10221 if (this_ru_col + o > WITH_WIDTH(width)) | |
10222 { | |
10223 buffer[i] = NUL; | |
10224 break; | |
10225 } | |
10226 } | |
10227 } | |
10228 else | |
10229 #endif | |
10230 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10231 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10232 | |
10233 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10234 i = redraw_cmdline; | |
10235 screen_fill(row, row + 1, | |
10236 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10237 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10238 fillchar, fillchar, attr); | |
10239 /* don't redraw the cmdline because of showing the ruler */ | |
10240 redraw_cmdline = i; | |
10241 wp->w_ru_cursor = wp->w_cursor; | |
10242 wp->w_ru_virtcol = wp->w_virtcol; | |
10243 wp->w_ru_empty = empty_line; | |
10244 wp->w_ru_topline = wp->w_topline; | |
10245 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10246 #ifdef FEAT_DIFF | |
10247 wp->w_ru_topfill = wp->w_topfill; | |
10248 #endif | |
10249 } | |
10250 } | |
10251 #endif | |
13 | 10252 |
10253 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10254 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10255 * 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
|
10256 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10257 * Otherwise it depends on 'numberwidth' and the line count. |
10258 */ | |
10259 int | |
10260 number_width(wp) | |
10261 win_T *wp; | |
10262 { | |
10263 int n; | |
10264 linenr_T lnum; | |
10265 | |
4736
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10266 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
|
10267 /* cursor line shows "0" */ |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10268 lnum = wp->w_height; |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10269 else |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10270 /* cursor line shows absolute line number */ |
3f2319a953b3
updated for version 7.3.1115
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
10271 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
|
10272 |
13 | 10273 if (lnum == wp->w_nrwidth_line_count) |
10274 return wp->w_nrwidth_width; | |
10275 wp->w_nrwidth_line_count = lnum; | |
10276 | |
10277 n = 0; | |
10278 do | |
10279 { | |
856 | 10280 lnum /= 10; |
10281 ++n; | |
13 | 10282 } while (lnum > 0); |
10283 | |
10284 /* 'numberwidth' gives the minimal width plus one */ | |
10285 if (n < wp->w_p_nuw - 1) | |
10286 n = wp->w_p_nuw - 1; | |
10287 | |
10288 wp->w_nrwidth_width = n; | |
10289 return n; | |
10290 } | |
10291 #endif | |
3986 | 10292 |
10293 /* | |
10294 * Return the current cursor column. This is the actual position on the | |
10295 * screen. First column is 0. | |
10296 */ | |
10297 int | |
10298 screen_screencol() | |
10299 { | |
10300 return screen_cur_col; | |
10301 } | |
10302 | |
10303 /* | |
10304 * Return the current cursor row. This is the actual position on the screen. | |
10305 * First row is 0. | |
10306 */ | |
10307 int | |
10308 screen_screenrow() | |
10309 { | |
10310 return screen_cur_row; | |
10311 } |