Mercurial > vim
annotate src/screen.c @ 2400:e6f1424dd66a vim73
Let 'v' flag in 'concealcursor' apply to all lines in the Visual area.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 24 Jul 2010 23:52:26 +0200 |
parents | 210a5605e126 |
children | 0ca06a92adfb |
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 | |
92 /* | |
93 * The attributes that are actually active for writing to the screen. | |
94 */ | |
95 static int screen_attr = 0; | |
96 | |
97 /* | |
98 * Positioning the cursor is reduced by remembering the last position. | |
99 * Mostly used by windgoto() and screen_char(). | |
100 */ | |
101 static int screen_cur_row, screen_cur_col; /* last known cursor position */ | |
102 | |
103 #ifdef FEAT_SEARCH_EXTRA | |
104 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
105 #endif | |
106 | |
107 #ifdef FEAT_FOLDING | |
108 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
109 #endif | |
110 | |
111 /* | |
112 * Buffer for one screen line (characters and attributes). | |
113 */ | |
114 static schar_T *current_ScreenLine; | |
115 | |
116 static void win_update __ARGS((win_T *wp)); | |
534 | 117 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 118 #ifdef FEAT_FOLDING |
119 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
120 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
121 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
122 #endif | |
625 | 123 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 124 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
125 #ifdef FEAT_RIGHTLEFT | |
126 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
127 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
128 #else | |
129 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
131 #endif | |
132 #ifdef FEAT_VERTSPLIT | |
133 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
134 #endif | |
680 | 135 #ifdef FEAT_STL_OPT |
1983 | 136 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 137 #endif |
7 | 138 #ifdef FEAT_SEARCH_EXTRA |
1326 | 139 #define SEARCH_HL_PRIORITY 0 |
7 | 140 static void start_search_hl __ARGS((void)); |
141 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
|
142 static void init_search_hl __ARGS((win_T *wp)); |
7 | 143 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
144 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
145 #endif | |
146 static void screen_start_highlight __ARGS((int attr)); | |
147 static void screen_char __ARGS((unsigned off, int row, int col)); | |
148 #ifdef FEAT_MBYTE | |
149 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
150 #endif | |
151 static void screenclear2 __ARGS((void)); | |
152 static void lineclear __ARGS((unsigned off, int width)); | |
153 static void lineinvalid __ARGS((unsigned off, int width)); | |
154 #ifdef FEAT_VERTSPLIT | |
155 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
156 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
157 #endif | |
158 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
159 static void win_rest_invalid __ARGS((win_T *wp)); | |
160 static void msg_pos_mode __ARGS((void)); | |
667 | 161 #if defined(FEAT_WINDOWS) |
677 | 162 static void draw_tabline __ARGS((void)); |
667 | 163 #endif |
7 | 164 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
165 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
166 #endif | |
167 #ifdef FEAT_VERTSPLIT | |
168 static int fillchar_vsep __ARGS((int *attr)); | |
169 #endif | |
170 #ifdef FEAT_STL_OPT | |
574 | 171 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 172 #endif |
173 #ifdef FEAT_CMDL_INFO | |
174 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
175 #endif | |
176 | |
177 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
178 /* Ugly global: overrule attribute used by screen_char() */ | |
179 static int screen_char_attr = 0; | |
180 #endif | |
181 | |
182 /* | |
183 * Redraw the current window later, with update_screen(type). | |
184 * Set must_redraw only if not already set to a higher value. | |
185 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
186 */ | |
187 void | |
188 redraw_later(type) | |
189 int type; | |
190 { | |
191 redraw_win_later(curwin, type); | |
192 } | |
193 | |
194 void | |
195 redraw_win_later(wp, type) | |
196 win_T *wp; | |
197 int type; | |
198 { | |
199 if (wp->w_redr_type < type) | |
200 { | |
201 wp->w_redr_type = type; | |
202 if (type >= NOT_VALID) | |
203 wp->w_lines_valid = 0; | |
204 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
205 must_redraw = type; | |
206 } | |
207 } | |
208 | |
209 /* | |
210 * Force a complete redraw later. Also resets the highlighting. To be used | |
211 * after executing a shell command that messes up the screen. | |
212 */ | |
213 void | |
214 redraw_later_clear() | |
215 { | |
216 redraw_all_later(CLEAR); | |
826 | 217 #ifdef FEAT_GUI |
218 if (gui.in_use) | |
219 /* Use a code that will reset gui.highlight_mask in | |
220 * gui_stop_highlight(). */ | |
221 screen_attr = HL_ALL + 1; | |
222 else | |
223 #endif | |
224 /* Use attributes that is very unlikely to appear in text. */ | |
225 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 226 } |
227 | |
228 /* | |
229 * Mark all windows to be redrawn later. | |
230 */ | |
231 void | |
232 redraw_all_later(type) | |
233 int type; | |
234 { | |
235 win_T *wp; | |
236 | |
237 FOR_ALL_WINDOWS(wp) | |
238 { | |
239 redraw_win_later(wp, type); | |
240 } | |
241 } | |
242 | |
243 /* | |
301 | 244 * Mark all windows that are editing the current buffer to be updated later. |
7 | 245 */ |
246 void | |
247 redraw_curbuf_later(type) | |
248 int type; | |
249 { | |
250 redraw_buf_later(curbuf, type); | |
251 } | |
252 | |
253 void | |
254 redraw_buf_later(buf, type) | |
255 buf_T *buf; | |
256 int type; | |
257 { | |
258 win_T *wp; | |
259 | |
260 FOR_ALL_WINDOWS(wp) | |
261 { | |
262 if (wp->w_buffer == buf) | |
263 redraw_win_later(wp, type); | |
264 } | |
265 } | |
266 | |
267 /* | |
268 * Changed something in the current window, at buffer line "lnum", that | |
269 * requires that line and possibly other lines to be redrawn. | |
270 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
271 * Used to remove the "$" from a change command. | |
272 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
273 * may become invalid and the whole window will have to be redrawn. | |
274 */ | |
275 void | |
276 redrawWinline(lnum, invalid) | |
277 linenr_T lnum; | |
1883 | 278 int invalid UNUSED; /* window line height is invalid now */ |
7 | 279 { |
280 #ifdef FEAT_FOLDING | |
281 int i; | |
282 #endif | |
283 | |
284 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
285 curwin->w_redraw_top = lnum; | |
286 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
287 curwin->w_redraw_bot = lnum; | |
288 redraw_later(VALID); | |
289 | |
290 #ifdef FEAT_FOLDING | |
291 if (invalid) | |
292 { | |
293 /* A w_lines[] entry for this lnum has become invalid. */ | |
294 i = find_wl_entry(curwin, lnum); | |
295 if (i >= 0) | |
296 curwin->w_lines[i].wl_valid = FALSE; | |
297 } | |
298 #endif | |
299 } | |
300 | |
2255 | 301 #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
|
302 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 303 /* |
304 * update all windows that are editing the current buffer | |
305 */ | |
306 void | |
307 update_curbuf(type) | |
308 int type; | |
309 { | |
310 redraw_curbuf_later(type); | |
311 update_screen(type); | |
312 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
313 #endif |
7 | 314 |
315 /* | |
316 * update_screen() | |
317 * | |
318 * Based on the current value of curwin->w_topline, transfer a screenfull | |
319 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
320 */ | |
321 void | |
322 update_screen(type) | |
323 int type; | |
324 { | |
325 win_T *wp; | |
326 static int did_intro = FALSE; | |
327 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
328 int did_one; | |
329 #endif | |
330 | |
2008 | 331 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 332 if (!screen_valid(TRUE)) |
333 return; | |
334 | |
335 if (must_redraw) | |
336 { | |
337 if (type < must_redraw) /* use maximal type */ | |
338 type = must_redraw; | |
1331 | 339 |
340 /* must_redraw is reset here, so that when we run into some weird | |
341 * reason to redraw while busy redrawing (e.g., asynchronous | |
342 * scrolling), or update_topline() in win_update() will cause a | |
343 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 344 must_redraw = 0; |
345 } | |
346 | |
347 /* Need to update w_lines[]. */ | |
348 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
349 type = NOT_VALID; | |
350 | |
2008 | 351 /* Postpone the redrawing when it's not needed and when being called |
352 * recursively. */ | |
353 if (!redrawing() || updating_screen) | |
7 | 354 { |
355 redraw_later(type); /* remember type for next time */ | |
356 must_redraw = type; | |
357 if (type > INVERTED_ALL) | |
358 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
359 return; | |
360 } | |
361 | |
362 updating_screen = TRUE; | |
363 #ifdef FEAT_SYN_HL | |
364 ++display_tick; /* let syntax code know we're in a next round of | |
365 * display updating */ | |
366 #endif | |
367 | |
368 /* | |
369 * if the screen was scrolled up when displaying a message, scroll it down | |
370 */ | |
371 if (msg_scrolled) | |
372 { | |
373 clear_cmdline = TRUE; | |
374 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
375 type = CLEAR; | |
376 else if (type != CLEAR) | |
377 { | |
378 check_for_delay(FALSE); | |
379 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
380 type = CLEAR; | |
381 FOR_ALL_WINDOWS(wp) | |
382 { | |
383 if (W_WINROW(wp) < msg_scrolled) | |
384 { | |
385 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
386 && wp->w_redr_type < REDRAW_TOP | |
387 && wp->w_lines_valid > 0 | |
388 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
389 { | |
390 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
391 wp->w_redr_type = REDRAW_TOP; | |
392 } | |
393 else | |
394 { | |
395 wp->w_redr_type = NOT_VALID; | |
396 #ifdef FEAT_WINDOWS | |
397 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
398 <= msg_scrolled) | |
399 wp->w_redr_status = TRUE; | |
400 #endif | |
401 } | |
402 } | |
403 } | |
404 redraw_cmdline = TRUE; | |
667 | 405 #ifdef FEAT_WINDOWS |
673 | 406 redraw_tabline = TRUE; |
667 | 407 #endif |
7 | 408 } |
409 msg_scrolled = 0; | |
410 need_wait_return = FALSE; | |
411 } | |
412 | |
413 /* reset cmdline_row now (may have been changed temporarily) */ | |
414 compute_cmdrow(); | |
415 | |
416 /* Check for changed highlighting */ | |
417 if (need_highlight_changed) | |
418 highlight_changed(); | |
419 | |
420 if (type == CLEAR) /* first clear screen */ | |
421 { | |
422 screenclear(); /* will reset clear_cmdline */ | |
423 type = NOT_VALID; | |
424 } | |
425 | |
426 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
427 check_for_delay(FALSE); | |
428 | |
13 | 429 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
430 /* 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
|
431 * changes. */ |
13 | 432 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
433 && 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
|
434 ? number_width(curwin) : 0)) |
13 | 435 curwin->w_redr_type = NOT_VALID; |
436 #endif | |
437 | |
7 | 438 /* |
439 * Only start redrawing if there is really something to do. | |
440 */ | |
441 if (type == INVERTED) | |
442 update_curswant(); | |
443 if (curwin->w_redr_type < type | |
444 && !((type == VALID | |
445 && curwin->w_lines[0].wl_valid | |
446 #ifdef FEAT_DIFF | |
447 && curwin->w_topfill == curwin->w_old_topfill | |
448 && curwin->w_botfill == curwin->w_old_botfill | |
449 #endif | |
450 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
451 #ifdef FEAT_VISUAL | |
452 || (type == INVERTED | |
1043 | 453 && VIsual_active |
7 | 454 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
455 && curwin->w_old_visual_mode == VIsual_mode | |
456 && (curwin->w_valid & VALID_VIRTCOL) | |
457 && curwin->w_old_curswant == curwin->w_curswant) | |
458 #endif | |
459 )) | |
460 curwin->w_redr_type = type; | |
461 | |
849 | 462 #ifdef FEAT_WINDOWS |
463 /* Redraw the tab pages line if needed. */ | |
464 if (redraw_tabline || type >= NOT_VALID) | |
465 draw_tabline(); | |
466 #endif | |
467 | |
7 | 468 #ifdef FEAT_SYN_HL |
469 /* | |
470 * Correct stored syntax highlighting info for changes in each displayed | |
471 * buffer. Each buffer must only be done once. | |
472 */ | |
473 FOR_ALL_WINDOWS(wp) | |
474 { | |
475 if (wp->w_buffer->b_mod_set) | |
476 { | |
477 # ifdef FEAT_WINDOWS | |
478 win_T *wwp; | |
479 | |
480 /* Check if we already did this buffer. */ | |
481 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
482 if (wwp->w_buffer == wp->w_buffer) | |
483 break; | |
484 # endif | |
485 if ( | |
486 # ifdef FEAT_WINDOWS | |
487 wwp == wp && | |
488 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
489 syntax_present(wp)) |
7 | 490 syn_stack_apply_changes(wp->w_buffer); |
491 } | |
492 } | |
493 #endif | |
494 | |
495 /* | |
496 * Go from top to bottom through the windows, redrawing the ones that need | |
497 * it. | |
498 */ | |
499 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
500 did_one = FALSE; | |
501 #endif | |
502 #ifdef FEAT_SEARCH_EXTRA | |
503 search_hl.rm.regprog = NULL; | |
504 #endif | |
505 FOR_ALL_WINDOWS(wp) | |
506 { | |
507 if (wp->w_redr_type != 0) | |
508 { | |
509 cursor_off(); | |
510 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
511 if (!did_one) | |
512 { | |
513 did_one = TRUE; | |
514 # ifdef FEAT_SEARCH_EXTRA | |
515 start_search_hl(); | |
516 # endif | |
517 # ifdef FEAT_CLIPBOARD | |
518 /* When Visual area changed, may have to update selection. */ | |
519 if (clip_star.available && clip_isautosel()) | |
520 clip_update_selection(); | |
521 # endif | |
522 #ifdef FEAT_GUI | |
523 /* Remove the cursor before starting to do anything, because | |
524 * scrolling may make it difficult to redraw the text under | |
525 * it. */ | |
526 if (gui.in_use) | |
527 gui_undraw_cursor(); | |
528 #endif | |
529 } | |
530 #endif | |
531 win_update(wp); | |
532 } | |
533 | |
534 #ifdef FEAT_WINDOWS | |
535 /* redraw status line after the window to minimize cursor movement */ | |
536 if (wp->w_redr_status) | |
537 { | |
538 cursor_off(); | |
539 win_redr_status(wp); | |
540 } | |
541 #endif | |
542 } | |
543 #if defined(FEAT_SEARCH_EXTRA) | |
544 end_search_hl(); | |
545 #endif | |
546 | |
547 #ifdef FEAT_WINDOWS | |
548 /* Reset b_mod_set flags. Going through all windows is probably faster | |
549 * than going through all buffers (there could be many buffers). */ | |
550 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
551 wp->w_buffer->b_mod_set = FALSE; | |
552 #else | |
553 curbuf->b_mod_set = FALSE; | |
554 #endif | |
555 | |
556 updating_screen = FALSE; | |
557 #ifdef FEAT_GUI | |
558 gui_may_resize_shell(); | |
559 #endif | |
560 | |
561 /* Clear or redraw the command line. Done last, because scrolling may | |
562 * mess up the command line. */ | |
563 if (clear_cmdline || redraw_cmdline) | |
564 showmode(); | |
565 | |
566 /* May put up an introductory message when not editing a file */ | |
567 if (!did_intro && bufempty() | |
568 && curbuf->b_fname == NULL | |
569 #ifdef FEAT_WINDOWS | |
570 && firstwin->w_next == NULL | |
571 #endif | |
572 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
573 intro_message(FALSE); | |
574 did_intro = TRUE; | |
575 | |
576 #ifdef FEAT_GUI | |
577 /* Redraw the cursor and update the scrollbars when all screen updating is | |
578 * done. */ | |
579 if (gui.in_use) | |
580 { | |
581 out_flush(); /* required before updating the cursor */ | |
582 if (did_one) | |
583 gui_update_cursor(FALSE, FALSE); | |
584 gui_update_scrollbars(FALSE); | |
585 } | |
586 #endif | |
587 } | |
588 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
589 #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
|
590 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
591 * 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
|
592 * 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
|
593 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
594 int |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
595 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
|
596 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
|
597 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
598 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
|
599 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 c = 'n'; |
2382
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
608 else if (State & CMDLINE) |
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
609 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
|
610 else |
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 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
|
613 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
614 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
615 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
616 * 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
|
617 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
618 void |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
619 conceal_check_cursur_line_redraw() |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
620 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
621 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
|
622 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
623 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
|
624 /* 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
|
625 * 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
|
626 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
|
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 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
629 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
630 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
631 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
632 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
633 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
634 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
635 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
636 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
637 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
638 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
|
639 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
640 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
641 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
642 /* 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
|
643 * 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
|
644 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
645 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
646 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
647 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
648 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
|
649 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
650 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
|
651 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
652 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
|
653 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
654 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
655 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
656 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
657 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
658 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
|
659 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
660 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
661 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
662 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
663 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
664 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
665 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
666 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
667 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
668 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
669 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
670 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
671 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
672 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
673 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
674 } |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
675 need_cursor_line_redraw = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
676 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
677 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
678 |
7 | 679 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
680 static void update_prepare __ARGS((void)); | |
681 static void update_finish __ARGS((void)); | |
682 | |
683 /* | |
684 * Prepare for updating one or more windows. | |
2008 | 685 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 686 */ |
687 static void | |
688 update_prepare() | |
689 { | |
690 cursor_off(); | |
691 updating_screen = TRUE; | |
692 #ifdef FEAT_GUI | |
693 /* Remove the cursor before starting to do anything, because scrolling may | |
694 * make it difficult to redraw the text under it. */ | |
695 if (gui.in_use) | |
696 gui_undraw_cursor(); | |
697 #endif | |
698 #ifdef FEAT_SEARCH_EXTRA | |
699 start_search_hl(); | |
700 #endif | |
701 } | |
702 | |
703 /* | |
704 * Finish updating one or more windows. | |
705 */ | |
706 static void | |
707 update_finish() | |
708 { | |
709 if (redraw_cmdline) | |
710 showmode(); | |
711 | |
712 # ifdef FEAT_SEARCH_EXTRA | |
713 end_search_hl(); | |
714 # endif | |
715 | |
716 updating_screen = FALSE; | |
717 | |
718 # ifdef FEAT_GUI | |
719 gui_may_resize_shell(); | |
720 | |
721 /* Redraw the cursor and update the scrollbars when all screen updating is | |
722 * done. */ | |
723 if (gui.in_use) | |
724 { | |
725 out_flush(); /* required before updating the cursor */ | |
726 gui_update_cursor(FALSE, FALSE); | |
727 gui_update_scrollbars(FALSE); | |
728 } | |
729 # endif | |
730 } | |
731 #endif | |
732 | |
733 #if defined(FEAT_SIGNS) || defined(PROTO) | |
734 void | |
735 update_debug_sign(buf, lnum) | |
736 buf_T *buf; | |
737 linenr_T lnum; | |
738 { | |
739 win_T *wp; | |
740 int doit = FALSE; | |
741 | |
742 # ifdef FEAT_FOLDING | |
743 win_foldinfo.fi_level = 0; | |
744 # endif | |
745 | |
746 /* update/delete a specific mark */ | |
747 FOR_ALL_WINDOWS(wp) | |
748 { | |
749 if (buf != NULL && lnum > 0) | |
750 { | |
751 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
752 && lnum < wp->w_botline) | |
753 { | |
754 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
755 wp->w_redraw_top = lnum; | |
756 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
757 wp->w_redraw_bot = lnum; | |
758 redraw_win_later(wp, VALID); | |
759 } | |
760 } | |
761 else | |
762 redraw_win_later(wp, VALID); | |
763 if (wp->w_redr_type != 0) | |
764 doit = TRUE; | |
765 } | |
766 | |
2008 | 767 /* Return when there is nothing to do or screen updating already |
768 * happening. */ | |
769 if (!doit || updating_screen) | |
7 | 770 return; |
771 | |
772 /* update all windows that need updating */ | |
773 update_prepare(); | |
774 | |
775 # ifdef FEAT_WINDOWS | |
776 for (wp = firstwin; wp; wp = wp->w_next) | |
777 { | |
778 if (wp->w_redr_type != 0) | |
779 win_update(wp); | |
780 if (wp->w_redr_status) | |
781 win_redr_status(wp); | |
782 } | |
783 # else | |
784 if (curwin->w_redr_type != 0) | |
785 win_update(curwin); | |
786 # endif | |
787 | |
788 update_finish(); | |
789 } | |
790 #endif | |
791 | |
792 | |
793 #if defined(FEAT_GUI) || defined(PROTO) | |
794 /* | |
795 * Update a single window, its status line and maybe the command line msg. | |
796 * Used for the GUI scrollbar. | |
797 */ | |
798 void | |
799 updateWindow(wp) | |
800 win_T *wp; | |
801 { | |
2008 | 802 /* return if already busy updating */ |
803 if (updating_screen) | |
804 return; | |
805 | |
7 | 806 update_prepare(); |
807 | |
808 #ifdef FEAT_CLIPBOARD | |
809 /* When Visual area changed, may have to update selection. */ | |
810 if (clip_star.available && clip_isautosel()) | |
811 clip_update_selection(); | |
812 #endif | |
670 | 813 |
7 | 814 win_update(wp); |
670 | 815 |
7 | 816 #ifdef FEAT_WINDOWS |
670 | 817 /* When the screen was cleared redraw the tab pages line. */ |
673 | 818 if (redraw_tabline) |
677 | 819 draw_tabline(); |
670 | 820 |
7 | 821 if (wp->w_redr_status |
822 # ifdef FEAT_CMDL_INFO | |
823 || p_ru | |
824 # endif | |
825 # ifdef FEAT_STL_OPT | |
40 | 826 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 827 # endif |
828 ) | |
829 win_redr_status(wp); | |
830 #endif | |
831 | |
832 update_finish(); | |
833 } | |
834 #endif | |
835 | |
836 /* | |
837 * Update a single window. | |
838 * | |
839 * This may cause the windows below it also to be redrawn (when clearing the | |
840 * screen or scrolling lines). | |
841 * | |
842 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
843 * implies the one below it. | |
844 * NOT_VALID redraw the whole window | |
743 | 845 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 846 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
847 * INVERTED redraw the changed part of the Visual area | |
848 * INVERTED_ALL redraw the whole Visual area | |
849 * VALID 1. scroll up/down to adjust for a changed w_topline | |
850 * 2. update lines at the top when scrolled down | |
851 * 3. redraw changed text: | |
301 | 852 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 853 * b_mod_top and b_mod_bot. |
854 * - if wp->w_redraw_top non-zero, redraw lines between | |
855 * wp->w_redraw_top and wp->w_redr_bot. | |
856 * - continue redrawing when syntax status is invalid. | |
857 * 4. if scrolled up, update lines at the bottom. | |
858 * This results in three areas that may need updating: | |
859 * top: from first row to top_end (when scrolled down) | |
860 * mid: from mid_start to mid_end (update inversion or changed text) | |
861 * bot: from bot_start to last row (when scrolled up) | |
862 */ | |
863 static void | |
864 win_update(wp) | |
865 win_T *wp; | |
866 { | |
867 buf_T *buf = wp->w_buffer; | |
868 int type; | |
869 int top_end = 0; /* Below last row of the top area that needs | |
870 updating. 0 when no top area updating. */ | |
871 int mid_start = 999;/* first row of the mid area that needs | |
872 updating. 999 when no mid area updating. */ | |
873 int mid_end = 0; /* Below last row of the mid area that needs | |
874 updating. 0 when no mid area updating. */ | |
875 int bot_start = 999;/* first row of the bot area that needs | |
876 updating. 999 when no bot area updating */ | |
877 #ifdef FEAT_VISUAL | |
878 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
879 w_topline got smaller a bit */ | |
880 #endif | |
881 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 882 matchitem_T *cur; /* points to the match list */ |
7 | 883 int top_to_mod = FALSE; /* redraw above mod_top */ |
884 #endif | |
885 | |
886 int row; /* current window row to display */ | |
887 linenr_T lnum; /* current buffer lnum to display */ | |
888 int idx; /* current index in w_lines[] */ | |
889 int srow; /* starting row of the current line */ | |
890 | |
891 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
892 int didline = FALSE; /* if TRUE, we finished the last line */ | |
893 int i; | |
894 long j; | |
895 static int recursive = FALSE; /* being called recursively */ | |
896 int old_botline = wp->w_botline; | |
897 #ifdef FEAT_FOLDING | |
898 long fold_count; | |
899 #endif | |
900 #ifdef FEAT_SYN_HL | |
901 /* remember what happened to the previous line, to know if | |
902 * check_visual_highlight() can be used */ | |
903 #define DID_NONE 1 /* didn't update a line */ | |
904 #define DID_LINE 2 /* updated a normal line */ | |
905 #define DID_FOLD 3 /* updated a folded line */ | |
906 int did_update = DID_NONE; | |
907 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
908 #endif | |
909 linenr_T mod_top = 0; | |
910 linenr_T mod_bot = 0; | |
911 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
912 int save_got_int; | |
913 #endif | |
914 | |
915 type = wp->w_redr_type; | |
916 | |
917 if (type == NOT_VALID) | |
918 { | |
919 #ifdef FEAT_WINDOWS | |
920 wp->w_redr_status = TRUE; | |
921 #endif | |
922 wp->w_lines_valid = 0; | |
923 } | |
924 | |
925 /* Window is zero-height: nothing to draw. */ | |
926 if (wp->w_height == 0) | |
927 { | |
928 wp->w_redr_type = 0; | |
929 return; | |
930 } | |
931 | |
932 #ifdef FEAT_VERTSPLIT | |
933 /* Window is zero-width: Only need to draw the separator. */ | |
934 if (wp->w_width == 0) | |
935 { | |
936 /* draw the vertical separator right of this window */ | |
937 draw_vsep_win(wp, 0); | |
938 wp->w_redr_type = 0; | |
939 return; | |
940 } | |
941 #endif | |
942 | |
943 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
944 init_search_hl(wp); |
7 | 945 #endif |
946 | |
13 | 947 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
948 /* 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
|
949 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
950 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 951 if (wp->w_nrwidth != i) |
13 | 952 { |
953 type = NOT_VALID; | |
677 | 954 wp->w_nrwidth = i; |
13 | 955 } |
956 else | |
957 #endif | |
958 | |
7 | 959 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
960 { | |
961 /* | |
962 * When there are both inserted/deleted lines and specific lines to be | |
963 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
964 * everything (only happens when redrawing is off for while). | |
965 */ | |
966 type = NOT_VALID; | |
967 } | |
968 else | |
969 { | |
970 /* | |
971 * Set mod_top to the first line that needs displaying because of | |
972 * changes. Set mod_bot to the first line after the changes. | |
973 */ | |
974 mod_top = wp->w_redraw_top; | |
975 if (wp->w_redraw_bot != 0) | |
976 mod_bot = wp->w_redraw_bot + 1; | |
977 else | |
978 mod_bot = 0; | |
979 wp->w_redraw_top = 0; /* reset for next time */ | |
980 wp->w_redraw_bot = 0; | |
981 if (buf->b_mod_set) | |
982 { | |
983 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
984 { | |
985 mod_top = buf->b_mod_top; | |
986 #ifdef FEAT_SYN_HL | |
987 /* Need to redraw lines above the change that may be included | |
988 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
989 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
990 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
991 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 992 if (mod_top < 1) |
993 mod_top = 1; | |
994 } | |
995 #endif | |
996 } | |
997 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
998 mod_bot = buf->b_mod_bot; | |
999 | |
1000 #ifdef FEAT_SEARCH_EXTRA | |
1001 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
1002 * change in one line may make the Search highlighting in a | |
1003 * previous line invalid. Simple solution: redraw all visible | |
1004 * lines above the change. | |
1326 | 1005 * Same for a match pattern. |
7 | 1006 */ |
699 | 1007 if (search_hl.rm.regprog != NULL |
1008 && re_multiline(search_hl.rm.regprog)) | |
7 | 1009 top_to_mod = TRUE; |
699 | 1010 else |
1326 | 1011 { |
1012 cur = wp->w_match_head; | |
1013 while (cur != NULL) | |
1014 { | |
1015 if (cur->match.regprog != NULL | |
1016 && re_multiline(cur->match.regprog)) | |
699 | 1017 { |
1018 top_to_mod = TRUE; | |
1019 break; | |
1020 } | |
1326 | 1021 cur = cur->next; |
1022 } | |
1023 } | |
7 | 1024 #endif |
1025 } | |
1026 #ifdef FEAT_FOLDING | |
1027 if (mod_top != 0 && hasAnyFolding(wp)) | |
1028 { | |
1029 linenr_T lnumt, lnumb; | |
1030 | |
1031 /* | |
1032 * A change in a line can cause lines above it to become folded or | |
1033 * unfolded. Find the top most buffer line that may be affected. | |
1034 * If the line was previously folded and displayed, get the first | |
1035 * line of that fold. If the line is folded now, get the first | |
1036 * folded line. Use the minimum of these two. | |
1037 */ | |
1038 | |
1039 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
1040 * the line below it. If there is no valid entry, use w_topline. | |
1041 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1042 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1043 lnumt = wp->w_topline; | |
1044 lnumb = MAXLNUM; | |
1045 for (i = 0; i < wp->w_lines_valid; ++i) | |
1046 if (wp->w_lines[i].wl_valid) | |
1047 { | |
1048 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1049 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1050 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1051 { | |
1052 lnumb = wp->w_lines[i].wl_lnum; | |
1053 /* When there is a fold column it might need updating | |
1054 * in the next line ("J" just above an open fold). */ | |
1055 if (wp->w_p_fdc > 0) | |
1056 ++lnumb; | |
1057 } | |
1058 } | |
1059 | |
1060 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1061 if (mod_top > lnumt) | |
1062 mod_top = lnumt; | |
1063 | |
1064 /* Now do the same for the bottom line (one above mod_bot). */ | |
1065 --mod_bot; | |
1066 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1067 ++mod_bot; | |
1068 if (mod_bot < lnumb) | |
1069 mod_bot = lnumb; | |
1070 } | |
1071 #endif | |
1072 | |
1073 /* When a change starts above w_topline and the end is below | |
1074 * w_topline, start redrawing at w_topline. | |
36 | 1075 * If the end of the change is above w_topline: do like no change was |
1076 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1077 if (mod_top != 0 && mod_top < wp->w_topline) |
1078 { | |
1079 if (mod_bot > wp->w_topline) | |
1080 mod_top = wp->w_topline; | |
1081 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1082 else if (syntax_present(wp)) |
7 | 1083 top_end = 1; |
1084 #endif | |
1085 } | |
36 | 1086 |
1087 /* When line numbers are displayed need to redraw all lines below | |
1088 * inserted/deleted lines. */ | |
1089 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1090 mod_bot = MAXLNUM; | |
7 | 1091 } |
1092 | |
1093 /* | |
1094 * When only displaying the lines at the top, set top_end. Used when | |
1095 * window has scrolled down for msg_scrolled. | |
1096 */ | |
1097 if (type == REDRAW_TOP) | |
1098 { | |
1099 j = 0; | |
1100 for (i = 0; i < wp->w_lines_valid; ++i) | |
1101 { | |
1102 j += wp->w_lines[i].wl_size; | |
1103 if (j >= wp->w_upd_rows) | |
1104 { | |
1105 top_end = j; | |
1106 break; | |
1107 } | |
1108 } | |
1109 if (top_end == 0) | |
1110 /* not found (cannot happen?): redraw everything */ | |
1111 type = NOT_VALID; | |
1112 else | |
1113 /* top area defined, the rest is VALID */ | |
1114 type = VALID; | |
1115 } | |
1116 | |
1378 | 1117 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1118 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1119 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1120 * called. */ | |
1121 if (screen_cleared) | |
1122 screen_cleared = MAYBE; | |
1123 | |
7 | 1124 /* |
1125 * If there are no changes on the screen that require a complete redraw, | |
1126 * handle three cases: | |
1127 * 1: we are off the top of the screen by a few lines: scroll down | |
1128 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1129 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1130 * w_lines[] that needs updating. | |
1131 */ | |
743 | 1132 if ((type == VALID || type == SOME_VALID |
1133 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1134 #ifdef FEAT_DIFF |
1135 && !wp->w_botfill && !wp->w_old_botfill | |
1136 #endif | |
1137 ) | |
1138 { | |
1139 if (mod_top != 0 && wp->w_topline == mod_top) | |
1140 { | |
1141 /* | |
1142 * w_topline is the first changed line, the scrolling will be done | |
1143 * further down. | |
1144 */ | |
1145 } | |
1146 else if (wp->w_lines[0].wl_valid | |
1147 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1148 #ifdef FEAT_DIFF | |
1149 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1150 && wp->w_topfill > wp->w_old_topfill) | |
1151 #endif | |
1152 )) | |
1153 { | |
1154 /* | |
1155 * New topline is above old topline: May scroll down. | |
1156 */ | |
1157 #ifdef FEAT_FOLDING | |
1158 if (hasAnyFolding(wp)) | |
1159 { | |
1160 linenr_T ln; | |
1161 | |
1162 /* count the number of lines we are off, counting a sequence | |
1163 * of folded lines as one */ | |
1164 j = 0; | |
1165 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1166 { | |
1167 ++j; | |
1168 if (j >= wp->w_height - 2) | |
1169 break; | |
1170 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1171 } | |
1172 } | |
1173 else | |
1174 #endif | |
1175 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1176 if (j < wp->w_height - 2) /* not too far off */ | |
1177 { | |
1178 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1179 #ifdef FEAT_DIFF | |
1180 /* insert extra lines for previously invisible filler lines */ | |
1181 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1182 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1183 - wp->w_old_topfill; | |
1184 #endif | |
1185 if (i < wp->w_height - 2) /* less than a screen off */ | |
1186 { | |
1187 /* | |
1188 * Try to insert the correct number of lines. | |
1189 * If not the last window, delete the lines at the bottom. | |
1190 * win_ins_lines may fail when the terminal can't do it. | |
1191 */ | |
1192 if (i > 0) | |
1193 check_for_delay(FALSE); | |
1194 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1195 { | |
1196 if (wp->w_lines_valid != 0) | |
1197 { | |
1198 /* Need to update rows that are new, stop at the | |
1199 * first one that scrolled down. */ | |
1200 top_end = i; | |
1201 #ifdef FEAT_VISUAL | |
1202 scrolled_down = TRUE; | |
1203 #endif | |
1204 | |
1205 /* Move the entries that were scrolled, disable | |
1206 * the entries for the lines to be redrawn. */ | |
1207 if ((wp->w_lines_valid += j) > wp->w_height) | |
1208 wp->w_lines_valid = wp->w_height; | |
1209 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1210 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1211 while (idx >= 0) | |
1212 wp->w_lines[idx--].wl_valid = FALSE; | |
1213 } | |
1214 } | |
1215 else | |
1216 mid_start = 0; /* redraw all lines */ | |
1217 } | |
1218 else | |
1219 mid_start = 0; /* redraw all lines */ | |
1220 } | |
1221 else | |
1222 mid_start = 0; /* redraw all lines */ | |
1223 } | |
1224 else | |
1225 { | |
1226 /* | |
1227 * New topline is at or below old topline: May scroll up. | |
1228 * When topline didn't change, find first entry in w_lines[] that | |
1229 * needs updating. | |
1230 */ | |
1231 | |
1232 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1233 j = -1; | |
1234 row = 0; | |
1235 for (i = 0; i < wp->w_lines_valid; i++) | |
1236 { | |
1237 if (wp->w_lines[i].wl_valid | |
1238 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1239 { | |
1240 j = i; | |
1241 break; | |
1242 } | |
1243 row += wp->w_lines[i].wl_size; | |
1244 } | |
1245 if (j == -1) | |
1246 { | |
1247 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1248 * lines */ | |
1249 mid_start = 0; | |
1250 } | |
1251 else | |
1252 { | |
1253 /* | |
1254 * Try to delete the correct number of lines. | |
1255 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1256 */ | |
1257 #ifdef FEAT_DIFF | |
1258 /* If the topline didn't change, delete old filler lines, | |
1259 * otherwise delete filler lines of the new topline... */ | |
1260 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1261 row += wp->w_old_topfill; | |
1262 else | |
1263 row += diff_check_fill(wp, wp->w_topline); | |
1264 /* ... but don't delete new filler lines. */ | |
1265 row -= wp->w_topfill; | |
1266 #endif | |
1267 if (row > 0) | |
1268 { | |
1269 check_for_delay(FALSE); | |
1270 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1271 bot_start = wp->w_height - row; | |
1272 else | |
1273 mid_start = 0; /* redraw all lines */ | |
1274 } | |
1275 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1276 { | |
1277 /* | |
1278 * Skip the lines (below the deleted lines) that are still | |
1279 * valid and don't need redrawing. Copy their info | |
1280 * upwards, to compensate for the deleted lines. Set | |
1281 * bot_start to the first row that needs redrawing. | |
1282 */ | |
1283 bot_start = 0; | |
1284 idx = 0; | |
1285 for (;;) | |
1286 { | |
1287 wp->w_lines[idx] = wp->w_lines[j]; | |
1288 /* stop at line that didn't fit, unless it is still | |
1289 * valid (no lines deleted) */ | |
1290 if (row > 0 && bot_start + row | |
1291 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1292 { | |
1293 wp->w_lines_valid = idx + 1; | |
1294 break; | |
1295 } | |
1296 bot_start += wp->w_lines[idx++].wl_size; | |
1297 | |
1298 /* stop at the last valid entry in w_lines[].wl_size */ | |
1299 if (++j >= wp->w_lines_valid) | |
1300 { | |
1301 wp->w_lines_valid = idx; | |
1302 break; | |
1303 } | |
1304 } | |
1305 #ifdef FEAT_DIFF | |
1306 /* Correct the first entry for filler lines at the top | |
1307 * when it won't get updated below. */ | |
1308 if (wp->w_p_diff && bot_start > 0) | |
1309 wp->w_lines[0].wl_size = | |
1310 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1311 + wp->w_topfill; | |
1312 #endif | |
1313 } | |
1314 } | |
1315 } | |
1316 | |
1317 /* When starting redraw in the first line, redraw all lines. When | |
1318 * there is only one window it's probably faster to clear the screen | |
1319 * first. */ | |
1320 if (mid_start == 0) | |
1321 { | |
1322 mid_end = wp->w_height; | |
1323 if (lastwin == firstwin) | |
981 | 1324 { |
1331 | 1325 /* Clear the screen when it was not done by win_del_lines() or |
1326 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1327 * then. */ | |
1328 if (screen_cleared != TRUE) | |
1329 screenclear(); | |
981 | 1330 #ifdef FEAT_WINDOWS |
1331 /* The screen was cleared, redraw the tab pages line. */ | |
1332 if (redraw_tabline) | |
1333 draw_tabline(); | |
1334 #endif | |
1335 } | |
7 | 1336 } |
1331 | 1337 |
1338 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1339 * cleared (only happens for the first window) or when screenclear() | |
1340 * was called directly above, "must_redraw" will have been set to | |
1341 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1342 if (screen_cleared == TRUE) | |
1343 must_redraw = 0; | |
7 | 1344 } |
1345 else | |
1346 { | |
1347 /* Not VALID or INVERTED: redraw all lines. */ | |
1348 mid_start = 0; | |
1349 mid_end = wp->w_height; | |
1350 } | |
1351 | |
743 | 1352 if (type == SOME_VALID) |
1353 { | |
1354 /* SOME_VALID: redraw all lines. */ | |
1355 mid_start = 0; | |
1356 mid_end = wp->w_height; | |
1357 type = NOT_VALID; | |
1358 } | |
1359 | |
7 | 1360 #ifdef FEAT_VISUAL |
1361 /* check if we are updating or removing the inverted part */ | |
1362 if ((VIsual_active && buf == curwin->w_buffer) | |
1363 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1364 { | |
1365 linenr_T from, to; | |
1366 | |
1367 if (VIsual_active) | |
1368 { | |
1369 if (VIsual_active | |
1370 && (VIsual_mode != wp->w_old_visual_mode | |
1371 || type == INVERTED_ALL)) | |
1372 { | |
1373 /* | |
1374 * If the type of Visual selection changed, redraw the whole | |
1375 * selection. Also when the ownership of the X selection is | |
1376 * gained or lost. | |
1377 */ | |
1378 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1379 { | |
1380 from = curwin->w_cursor.lnum; | |
1381 to = VIsual.lnum; | |
1382 } | |
1383 else | |
1384 { | |
1385 from = VIsual.lnum; | |
1386 to = curwin->w_cursor.lnum; | |
1387 } | |
1388 /* redraw more when the cursor moved as well */ | |
1389 if (wp->w_old_cursor_lnum < from) | |
1390 from = wp->w_old_cursor_lnum; | |
1391 if (wp->w_old_cursor_lnum > to) | |
1392 to = wp->w_old_cursor_lnum; | |
1393 if (wp->w_old_visual_lnum < from) | |
1394 from = wp->w_old_visual_lnum; | |
1395 if (wp->w_old_visual_lnum > to) | |
1396 to = wp->w_old_visual_lnum; | |
1397 } | |
1398 else | |
1399 { | |
1400 /* | |
1401 * Find the line numbers that need to be updated: The lines | |
1402 * between the old cursor position and the current cursor | |
1403 * position. Also check if the Visual position changed. | |
1404 */ | |
1405 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1406 { | |
1407 from = curwin->w_cursor.lnum; | |
1408 to = wp->w_old_cursor_lnum; | |
1409 } | |
1410 else | |
1411 { | |
1412 from = wp->w_old_cursor_lnum; | |
1413 to = curwin->w_cursor.lnum; | |
1414 if (from == 0) /* Visual mode just started */ | |
1415 from = to; | |
1416 } | |
1417 | |
422 | 1418 if (VIsual.lnum != wp->w_old_visual_lnum |
1419 || VIsual.col != wp->w_old_visual_col) | |
7 | 1420 { |
1421 if (wp->w_old_visual_lnum < from | |
1422 && wp->w_old_visual_lnum != 0) | |
1423 from = wp->w_old_visual_lnum; | |
1424 if (wp->w_old_visual_lnum > to) | |
1425 to = wp->w_old_visual_lnum; | |
1426 if (VIsual.lnum < from) | |
1427 from = VIsual.lnum; | |
1428 if (VIsual.lnum > to) | |
1429 to = VIsual.lnum; | |
1430 } | |
1431 } | |
1432 | |
1433 /* | |
1434 * If in block mode and changed column or curwin->w_curswant: | |
1435 * update all lines. | |
1436 * First compute the actual start and end column. | |
1437 */ | |
1438 if (VIsual_mode == Ctrl_V) | |
1439 { | |
1440 colnr_T fromc, toc; | |
1441 | |
1442 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1443 ++toc; | |
1444 if (curwin->w_curswant == MAXCOL) | |
1445 toc = MAXCOL; | |
1446 | |
1447 if (fromc != wp->w_old_cursor_fcol | |
1448 || toc != wp->w_old_cursor_lcol) | |
1449 { | |
1450 if (from > VIsual.lnum) | |
1451 from = VIsual.lnum; | |
1452 if (to < VIsual.lnum) | |
1453 to = VIsual.lnum; | |
1454 } | |
1455 wp->w_old_cursor_fcol = fromc; | |
1456 wp->w_old_cursor_lcol = toc; | |
1457 } | |
1458 } | |
1459 else | |
1460 { | |
1461 /* Use the line numbers of the old Visual area. */ | |
1462 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1463 { | |
1464 from = wp->w_old_cursor_lnum; | |
1465 to = wp->w_old_visual_lnum; | |
1466 } | |
1467 else | |
1468 { | |
1469 from = wp->w_old_visual_lnum; | |
1470 to = wp->w_old_cursor_lnum; | |
1471 } | |
1472 } | |
1473 | |
1474 /* | |
1475 * There is no need to update lines above the top of the window. | |
1476 */ | |
1477 if (from < wp->w_topline) | |
1478 from = wp->w_topline; | |
1479 | |
1480 /* | |
1481 * If we know the value of w_botline, use it to restrict the update to | |
1482 * the lines that are visible in the window. | |
1483 */ | |
1484 if (wp->w_valid & VALID_BOTLINE) | |
1485 { | |
1486 if (from >= wp->w_botline) | |
1487 from = wp->w_botline - 1; | |
1488 if (to >= wp->w_botline) | |
1489 to = wp->w_botline - 1; | |
1490 } | |
1491 | |
1492 /* | |
1493 * Find the minimal part to be updated. | |
1494 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1495 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1496 * top_end; need to redraw from top_end to the "to" line. | |
1497 * A middle mouse click with a Visual selection may change the text | |
1498 * above the Visual area and reset wl_valid, do count these for | |
1499 * mid_end (in srow). | |
1500 */ | |
1501 if (mid_start > 0) | |
1502 { | |
1503 lnum = wp->w_topline; | |
1504 idx = 0; | |
1505 srow = 0; | |
1506 if (scrolled_down) | |
1507 mid_start = top_end; | |
1508 else | |
1509 mid_start = 0; | |
1510 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1511 { | |
1512 if (wp->w_lines[idx].wl_valid) | |
1513 mid_start += wp->w_lines[idx].wl_size; | |
1514 else if (!scrolled_down) | |
1515 srow += wp->w_lines[idx].wl_size; | |
1516 ++idx; | |
1517 # ifdef FEAT_FOLDING | |
1518 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1519 lnum = wp->w_lines[idx].wl_lnum; | |
1520 else | |
1521 # endif | |
1522 ++lnum; | |
1523 } | |
1524 srow += mid_start; | |
1525 mid_end = wp->w_height; | |
1526 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1527 { | |
1528 if (wp->w_lines[idx].wl_valid | |
1529 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1530 { | |
1531 /* Only update until first row of this line */ | |
1532 mid_end = srow; | |
1533 break; | |
1534 } | |
1535 srow += wp->w_lines[idx].wl_size; | |
1536 } | |
1537 } | |
1538 } | |
1539 | |
1540 if (VIsual_active && buf == curwin->w_buffer) | |
1541 { | |
1542 wp->w_old_visual_mode = VIsual_mode; | |
1543 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1544 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1545 wp->w_old_visual_col = VIsual.col; |
7 | 1546 wp->w_old_curswant = curwin->w_curswant; |
1547 } | |
1548 else | |
1549 { | |
1550 wp->w_old_visual_mode = 0; | |
1551 wp->w_old_cursor_lnum = 0; | |
1552 wp->w_old_visual_lnum = 0; | |
422 | 1553 wp->w_old_visual_col = 0; |
7 | 1554 } |
1555 #endif /* FEAT_VISUAL */ | |
1556 | |
1557 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1558 /* reset got_int, otherwise regexp won't work */ | |
1559 save_got_int = got_int; | |
1560 got_int = 0; | |
1561 #endif | |
1562 #ifdef FEAT_FOLDING | |
1563 win_foldinfo.fi_level = 0; | |
1564 #endif | |
1565 | |
1566 /* | |
1567 * Update all the window rows. | |
1568 */ | |
1569 idx = 0; /* first entry in w_lines[].wl_size */ | |
1570 row = 0; | |
1571 srow = 0; | |
1572 lnum = wp->w_topline; /* first line shown in window */ | |
1573 for (;;) | |
1574 { | |
1575 /* stop updating when reached the end of the window (check for _past_ | |
1576 * the end of the window is at the end of the loop) */ | |
1577 if (row == wp->w_height) | |
1578 { | |
1579 didline = TRUE; | |
1580 break; | |
1581 } | |
1582 | |
1583 /* stop updating when hit the end of the file */ | |
1584 if (lnum > buf->b_ml.ml_line_count) | |
1585 { | |
1586 eof = TRUE; | |
1587 break; | |
1588 } | |
1589 | |
1590 /* Remember the starting row of the line that is going to be dealt | |
1591 * with. It is used further down when the line doesn't fit. */ | |
1592 srow = row; | |
1593 | |
1594 /* | |
1595 * Update a line when it is in an area that needs updating, when it | |
1596 * has changes or w_lines[idx] is invalid. | |
1597 * bot_start may be halfway a wrapped line after using | |
1598 * win_del_lines(), check if the current line includes it. | |
1599 * When syntax folding is being used, the saved syntax states will | |
1600 * already have been updated, we can't see where the syntax state is | |
1601 * the same again, just update until the end of the window. | |
1602 */ | |
1603 if (row < top_end | |
1604 || (row >= mid_start && row < mid_end) | |
1605 #ifdef FEAT_SEARCH_EXTRA | |
1606 || top_to_mod | |
1607 #endif | |
1608 || idx >= wp->w_lines_valid | |
1609 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1610 || (mod_top != 0 | |
1611 && (lnum == mod_top | |
1612 || (lnum >= mod_top | |
1613 && (lnum < mod_bot | |
1614 #ifdef FEAT_SYN_HL | |
1615 || did_update == DID_FOLD | |
1616 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1617 && syntax_present(wp) |
7 | 1618 && ( |
1619 # ifdef FEAT_FOLDING | |
1620 (foldmethodIsSyntax(wp) | |
1621 && hasAnyFolding(wp)) || | |
1622 # endif | |
1623 syntax_check_changed(lnum))) | |
1624 #endif | |
1625 ))))) | |
1626 { | |
1627 #ifdef FEAT_SEARCH_EXTRA | |
1628 if (lnum == mod_top) | |
1629 top_to_mod = FALSE; | |
1630 #endif | |
1631 | |
1632 /* | |
1633 * When at start of changed lines: May scroll following lines | |
1634 * up or down to minimize redrawing. | |
1635 * Don't do this when the change continues until the end. | |
1636 * Don't scroll when dollar_vcol is non-zero, keep the "$". | |
1637 */ | |
1638 if (lnum == mod_top | |
1639 && mod_bot != MAXLNUM | |
1640 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) | |
1641 { | |
1642 int old_rows = 0; | |
1643 int new_rows = 0; | |
1644 int xtra_rows; | |
1645 linenr_T l; | |
1646 | |
1647 /* Count the old number of window rows, using w_lines[], which | |
1648 * should still contain the sizes for the lines as they are | |
1649 * currently displayed. */ | |
1650 for (i = idx; i < wp->w_lines_valid; ++i) | |
1651 { | |
1652 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1653 * lines are part of the changed area. */ | |
1654 if (wp->w_lines[i].wl_valid | |
1655 && wp->w_lines[i].wl_lnum == mod_bot) | |
1656 break; | |
1657 old_rows += wp->w_lines[i].wl_size; | |
1658 #ifdef FEAT_FOLDING | |
1659 if (wp->w_lines[i].wl_valid | |
1660 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1661 { | |
1662 /* Must have found the last valid entry above mod_bot. | |
1663 * Add following invalid entries. */ | |
1664 ++i; | |
1665 while (i < wp->w_lines_valid | |
1666 && !wp->w_lines[i].wl_valid) | |
1667 old_rows += wp->w_lines[i++].wl_size; | |
1668 break; | |
1669 } | |
1670 #endif | |
1671 } | |
1672 | |
1673 if (i >= wp->w_lines_valid) | |
1674 { | |
1675 /* We can't find a valid line below the changed lines, | |
1676 * need to redraw until the end of the window. | |
1677 * Inserting/deleting lines has no use. */ | |
1678 bot_start = 0; | |
1679 } | |
1680 else | |
1681 { | |
1682 /* Able to count old number of rows: Count new window | |
1683 * rows, and may insert/delete lines */ | |
1684 j = idx; | |
1685 for (l = lnum; l < mod_bot; ++l) | |
1686 { | |
1687 #ifdef FEAT_FOLDING | |
1688 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1689 ++new_rows; | |
1690 else | |
1691 #endif | |
1692 #ifdef FEAT_DIFF | |
1693 if (l == wp->w_topline) | |
1694 new_rows += plines_win_nofill(wp, l, TRUE) | |
1695 + wp->w_topfill; | |
1696 else | |
1697 #endif | |
1698 new_rows += plines_win(wp, l, TRUE); | |
1699 ++j; | |
1700 if (new_rows > wp->w_height - row - 2) | |
1701 { | |
1702 /* it's getting too much, must redraw the rest */ | |
1703 new_rows = 9999; | |
1704 break; | |
1705 } | |
1706 } | |
1707 xtra_rows = new_rows - old_rows; | |
1708 if (xtra_rows < 0) | |
1709 { | |
1710 /* May scroll text up. If there is not enough | |
1711 * remaining text or scrolling fails, must redraw the | |
1712 * rest. If scrolling works, must redraw the text | |
1713 * below the scrolled text. */ | |
1714 if (row - xtra_rows >= wp->w_height - 2) | |
1715 mod_bot = MAXLNUM; | |
1716 else | |
1717 { | |
1718 check_for_delay(FALSE); | |
1719 if (win_del_lines(wp, row, | |
1720 -xtra_rows, FALSE, FALSE) == FAIL) | |
1721 mod_bot = MAXLNUM; | |
1722 else | |
1723 bot_start = wp->w_height + xtra_rows; | |
1724 } | |
1725 } | |
1726 else if (xtra_rows > 0) | |
1727 { | |
1728 /* May scroll text down. If there is not enough | |
1729 * remaining text of scrolling fails, must redraw the | |
1730 * rest. */ | |
1731 if (row + xtra_rows >= wp->w_height - 2) | |
1732 mod_bot = MAXLNUM; | |
1733 else | |
1734 { | |
1735 check_for_delay(FALSE); | |
1736 if (win_ins_lines(wp, row + old_rows, | |
1737 xtra_rows, FALSE, FALSE) == FAIL) | |
1738 mod_bot = MAXLNUM; | |
1739 else if (top_end > row + old_rows) | |
1740 /* Scrolled the part at the top that requires | |
1741 * updating down. */ | |
1742 top_end += xtra_rows; | |
1743 } | |
1744 } | |
1745 | |
1746 /* When not updating the rest, may need to move w_lines[] | |
1747 * entries. */ | |
1748 if (mod_bot != MAXLNUM && i != j) | |
1749 { | |
1750 if (j < i) | |
1751 { | |
1752 int x = row + new_rows; | |
1753 | |
1754 /* move entries in w_lines[] upwards */ | |
1755 for (;;) | |
1756 { | |
1757 /* stop at last valid entry in w_lines[] */ | |
1758 if (i >= wp->w_lines_valid) | |
1759 { | |
1760 wp->w_lines_valid = j; | |
1761 break; | |
1762 } | |
1763 wp->w_lines[j] = wp->w_lines[i]; | |
1764 /* stop at a line that won't fit */ | |
1765 if (x + (int)wp->w_lines[j].wl_size | |
1766 > wp->w_height) | |
1767 { | |
1768 wp->w_lines_valid = j + 1; | |
1769 break; | |
1770 } | |
1771 x += wp->w_lines[j++].wl_size; | |
1772 ++i; | |
1773 } | |
1774 if (bot_start > x) | |
1775 bot_start = x; | |
1776 } | |
1777 else /* j > i */ | |
1778 { | |
1779 /* move entries in w_lines[] downwards */ | |
1780 j -= i; | |
1781 wp->w_lines_valid += j; | |
1782 if (wp->w_lines_valid > wp->w_height) | |
1783 wp->w_lines_valid = wp->w_height; | |
1784 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1785 wp->w_lines[i] = wp->w_lines[i - j]; | |
1786 | |
1787 /* The w_lines[] entries for inserted lines are | |
1788 * now invalid, but wl_size may be used above. | |
1789 * Reset to zero. */ | |
1790 while (i >= idx) | |
1791 { | |
1792 wp->w_lines[i].wl_size = 0; | |
1793 wp->w_lines[i--].wl_valid = FALSE; | |
1794 } | |
1795 } | |
1796 } | |
1797 } | |
1798 } | |
1799 | |
1800 #ifdef FEAT_FOLDING | |
1801 /* | |
1802 * When lines are folded, display one line for all of them. | |
1803 * Otherwise, display normally (can be several display lines when | |
1804 * 'wrap' is on). | |
1805 */ | |
1806 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1807 if (fold_count != 0) | |
1808 { | |
1809 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1810 ++row; | |
1811 --fold_count; | |
1812 wp->w_lines[idx].wl_folded = TRUE; | |
1813 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1814 # ifdef FEAT_SYN_HL | |
1815 did_update = DID_FOLD; | |
1816 # endif | |
1817 } | |
1818 else | |
1819 #endif | |
1820 if (idx < wp->w_lines_valid | |
1821 && wp->w_lines[idx].wl_valid | |
1822 && wp->w_lines[idx].wl_lnum == lnum | |
1823 && lnum > wp->w_topline | |
1824 && !(dy_flags & DY_LASTLINE) | |
1825 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1826 #ifdef FEAT_DIFF | |
1827 && diff_check_fill(wp, lnum) == 0 | |
1828 #endif | |
1829 ) | |
1830 { | |
1831 /* This line is not going to fit. Don't draw anything here, | |
1832 * will draw "@ " lines below. */ | |
1833 row = wp->w_height + 1; | |
1834 } | |
1835 else | |
1836 { | |
1837 #ifdef FEAT_SEARCH_EXTRA | |
1838 prepare_search_hl(wp, lnum); | |
1839 #endif | |
1840 #ifdef FEAT_SYN_HL | |
1841 /* Let the syntax stuff know we skipped a few lines. */ | |
1842 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
|
1843 && syntax_present(wp)) |
7 | 1844 syntax_end_parsing(syntax_last_parsed + 1); |
1845 #endif | |
1846 | |
1847 /* | |
1848 * Display one line. | |
1849 */ | |
625 | 1850 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1851 |
1852 #ifdef FEAT_FOLDING | |
1853 wp->w_lines[idx].wl_folded = FALSE; | |
1854 wp->w_lines[idx].wl_lastlnum = lnum; | |
1855 #endif | |
1856 #ifdef FEAT_SYN_HL | |
1857 did_update = DID_LINE; | |
1858 syntax_last_parsed = lnum; | |
1859 #endif | |
1860 } | |
1861 | |
1862 wp->w_lines[idx].wl_lnum = lnum; | |
1863 wp->w_lines[idx].wl_valid = TRUE; | |
1864 if (row > wp->w_height) /* past end of screen */ | |
1865 { | |
1866 /* we may need the size of that too long line later on */ | |
1867 if (dollar_vcol == 0) | |
1868 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); | |
1869 ++idx; | |
1870 break; | |
1871 } | |
1872 if (dollar_vcol == 0) | |
1873 wp->w_lines[idx].wl_size = row - srow; | |
1874 ++idx; | |
1875 #ifdef FEAT_FOLDING | |
1876 lnum += fold_count + 1; | |
1877 #else | |
1878 ++lnum; | |
1879 #endif | |
1880 } | |
1881 else | |
1882 { | |
1883 /* This line does not need updating, advance to the next one */ | |
1884 row += wp->w_lines[idx++].wl_size; | |
1885 if (row > wp->w_height) /* past end of screen */ | |
1886 break; | |
1887 #ifdef FEAT_FOLDING | |
1888 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1889 #else | |
1890 ++lnum; | |
1891 #endif | |
1892 #ifdef FEAT_SYN_HL | |
1893 did_update = DID_NONE; | |
1894 #endif | |
1895 } | |
1896 | |
1897 if (lnum > buf->b_ml.ml_line_count) | |
1898 { | |
1899 eof = TRUE; | |
1900 break; | |
1901 } | |
1902 } | |
1903 /* | |
1904 * End of loop over all window lines. | |
1905 */ | |
1906 | |
1907 | |
1908 if (idx > wp->w_lines_valid) | |
1909 wp->w_lines_valid = idx; | |
1910 | |
1911 #ifdef FEAT_SYN_HL | |
1912 /* | |
1913 * Let the syntax stuff know we stop parsing here. | |
1914 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1915 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1916 syntax_end_parsing(syntax_last_parsed + 1); |
1917 #endif | |
1918 | |
1919 /* | |
1920 * If we didn't hit the end of the file, and we didn't finish the last | |
1921 * line we were working on, then the line didn't fit. | |
1922 */ | |
1923 wp->w_empty_rows = 0; | |
1924 #ifdef FEAT_DIFF | |
1925 wp->w_filler_rows = 0; | |
1926 #endif | |
1927 if (!eof && !didline) | |
1928 { | |
1929 if (lnum == wp->w_topline) | |
1930 { | |
1931 /* | |
1932 * Single line that does not fit! | |
1933 * Don't overwrite it, it can be edited. | |
1934 */ | |
1935 wp->w_botline = lnum + 1; | |
1936 } | |
1937 #ifdef FEAT_DIFF | |
1938 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1939 { | |
1940 /* Window ends in filler lines. */ | |
1941 wp->w_botline = lnum; | |
1942 wp->w_filler_rows = wp->w_height - srow; | |
1943 } | |
1944 #endif | |
1945 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1946 { | |
1947 /* | |
1948 * Last line isn't finished: Display "@@@" at the end. | |
1949 */ | |
1950 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1951 W_WINROW(wp) + wp->w_height, | |
1952 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1953 '@', '@', hl_attr(HLF_AT)); | |
1954 set_empty_rows(wp, srow); | |
1955 wp->w_botline = lnum; | |
1956 } | |
1957 else | |
1958 { | |
1959 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1960 wp->w_botline = lnum; | |
1961 } | |
1962 } | |
1963 else | |
1964 { | |
1965 #ifdef FEAT_VERTSPLIT | |
1966 draw_vsep_win(wp, row); | |
1967 #endif | |
1968 if (eof) /* we hit the end of the file */ | |
1969 { | |
1970 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1971 #ifdef FEAT_DIFF | |
1972 j = diff_check_fill(wp, wp->w_botline); | |
1973 if (j > 0 && !wp->w_botfill) | |
1974 { | |
1975 /* | |
1976 * Display filler lines at the end of the file | |
1977 */ | |
1978 if (char2cells(fill_diff) > 1) | |
1979 i = '-'; | |
1980 else | |
1981 i = fill_diff; | |
1982 if (row + j > wp->w_height) | |
1983 j = wp->w_height - row; | |
1984 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1985 row += j; | |
1986 } | |
1987 #endif | |
1988 } | |
1989 else if (dollar_vcol == 0) | |
1990 wp->w_botline = lnum; | |
1991 | |
1992 /* make sure the rest of the screen is blank */ | |
1993 /* put '~'s on rows that aren't part of the file. */ | |
1994 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
1995 } | |
1996 | |
1997 /* Reset the type of redrawing required, the window has been updated. */ | |
1998 wp->w_redr_type = 0; | |
1999 #ifdef FEAT_DIFF | |
2000 wp->w_old_topfill = wp->w_topfill; | |
2001 wp->w_old_botfill = wp->w_botfill; | |
2002 #endif | |
2003 | |
2004 if (dollar_vcol == 0) | |
2005 { | |
2006 /* | |
2007 * There is a trick with w_botline. If we invalidate it on each | |
2008 * change that might modify it, this will cause a lot of expensive | |
2009 * calls to plines() in update_topline() each time. Therefore the | |
2010 * value of w_botline is often approximated, and this value is used to | |
2011 * compute the value of w_topline. If the value of w_botline was | |
2012 * wrong, check that the value of w_topline is correct (cursor is on | |
2013 * the visible part of the text). If it's not, we need to redraw | |
2014 * again. Mostly this just means scrolling up a few lines, so it | |
2015 * doesn't look too bad. Only do this for the current window (where | |
2016 * changes are relevant). | |
2017 */ | |
2018 wp->w_valid |= VALID_BOTLINE; | |
2019 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
2020 { | |
2021 recursive = TRUE; | |
2022 curwin->w_valid &= ~VALID_TOPLINE; | |
2023 update_topline(); /* may invalidate w_botline again */ | |
2024 if (must_redraw != 0) | |
2025 { | |
2026 /* Don't update for changes in buffer again. */ | |
2027 i = curbuf->b_mod_set; | |
2028 curbuf->b_mod_set = FALSE; | |
2029 win_update(curwin); | |
2030 must_redraw = 0; | |
2031 curbuf->b_mod_set = i; | |
2032 } | |
2033 recursive = FALSE; | |
2034 } | |
2035 } | |
2036 | |
2037 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
2038 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
2039 if (!got_int) | |
2040 got_int = save_got_int; | |
2041 #endif | |
2042 } | |
2043 | |
2044 #ifdef FEAT_SIGNS | |
2045 static int draw_signcolumn __ARGS((win_T *wp)); | |
2046 | |
2047 /* | |
2048 * Return TRUE when window "wp" has a column to draw signs in. | |
2049 */ | |
2050 static int | |
2051 draw_signcolumn(wp) | |
2052 win_T *wp; | |
2053 { | |
2054 return (wp->w_buffer->b_signlist != NULL | |
2055 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2056 || netbeans_active() |
7 | 2057 # endif |
2058 ); | |
2059 } | |
2060 #endif | |
2061 | |
2062 /* | |
2063 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2064 * as the filler character. | |
2065 */ | |
2066 static void | |
2067 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2068 win_T *wp; | |
2069 int c1; | |
2070 int c2; | |
2071 int row; | |
2072 int endrow; | |
534 | 2073 hlf_T hl; |
7 | 2074 { |
2075 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2076 int n = 0; | |
2077 # define FDC_OFF n | |
2078 #else | |
2079 # define FDC_OFF 0 | |
2080 #endif | |
2081 | |
2082 #ifdef FEAT_RIGHTLEFT | |
2083 if (wp->w_p_rl) | |
2084 { | |
2085 /* No check for cmdline window: should never be right-left. */ | |
2086 # ifdef FEAT_FOLDING | |
2087 n = wp->w_p_fdc; | |
2088 | |
2089 if (n > 0) | |
2090 { | |
2091 /* draw the fold column at the right */ | |
119 | 2092 if (n > W_WIDTH(wp)) |
2093 n = W_WIDTH(wp); | |
7 | 2094 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2095 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2096 ' ', ' ', hl_attr(HLF_FC)); | |
2097 } | |
2098 # endif | |
2099 # ifdef FEAT_SIGNS | |
2100 if (draw_signcolumn(wp)) | |
2101 { | |
2102 int nn = n + 2; | |
2103 | |
2104 /* draw the sign column left of the fold column */ | |
119 | 2105 if (nn > W_WIDTH(wp)) |
2106 nn = W_WIDTH(wp); | |
7 | 2107 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2108 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2109 ' ', ' ', hl_attr(HLF_SC)); | |
2110 n = nn; | |
2111 } | |
2112 # endif | |
2113 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2114 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2115 c2, c2, hl_attr(hl)); | |
2116 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2117 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2118 c1, c2, hl_attr(hl)); | |
2119 } | |
2120 else | |
2121 #endif | |
2122 { | |
2123 #ifdef FEAT_CMDWIN | |
2124 if (cmdwin_type != 0 && wp == curwin) | |
2125 { | |
2126 /* draw the cmdline character in the leftmost column */ | |
2127 n = 1; | |
2128 if (n > wp->w_width) | |
2129 n = wp->w_width; | |
2130 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2131 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2132 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2133 } | |
2134 #endif | |
2135 #ifdef FEAT_FOLDING | |
2136 if (wp->w_p_fdc > 0) | |
2137 { | |
2138 int nn = n + wp->w_p_fdc; | |
2139 | |
2140 /* draw the fold column at the left */ | |
2141 if (nn > W_WIDTH(wp)) | |
2142 nn = W_WIDTH(wp); | |
2143 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2144 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2145 ' ', ' ', hl_attr(HLF_FC)); | |
2146 n = nn; | |
2147 } | |
2148 #endif | |
2149 #ifdef FEAT_SIGNS | |
2150 if (draw_signcolumn(wp)) | |
2151 { | |
2152 int nn = n + 2; | |
2153 | |
2154 /* draw the sign column after the fold column */ | |
2155 if (nn > W_WIDTH(wp)) | |
2156 nn = W_WIDTH(wp); | |
2157 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2158 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2159 ' ', ' ', hl_attr(HLF_SC)); | |
2160 n = nn; | |
2161 } | |
2162 #endif | |
2163 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2164 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2165 c1, c2, hl_attr(hl)); | |
2166 } | |
2167 set_empty_rows(wp, row); | |
2168 } | |
2169 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2170 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2171 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
|
2172 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2173 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2174 * 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
|
2175 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2176 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2177 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2178 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2179 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2180 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2181 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2182 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2183 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2184 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2185 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2186 |
7 | 2187 #ifdef FEAT_FOLDING |
2188 /* | |
2189 * Display one folded line. | |
2190 */ | |
2191 static void | |
2192 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2193 win_T *wp; | |
2194 long fold_count; | |
2195 foldinfo_T *foldinfo; | |
2196 linenr_T lnum; | |
2197 int row; | |
2198 { | |
2199 char_u buf[51]; | |
2200 pos_T *top, *bot; | |
2201 linenr_T lnume = lnum + fold_count - 1; | |
2202 int len; | |
29 | 2203 char_u *text; |
7 | 2204 int fdc; |
2205 int col; | |
2206 int txtcol; | |
2207 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2208 int ri; |
7 | 2209 |
2210 /* Build the fold line: | |
2211 * 1. Add the cmdwin_type for the command-line window | |
2212 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2213 * 3. Add the 'number' or 'relativenumber' column |
7 | 2214 * 4. Compose the text |
2215 * 5. Add the text | |
2216 * 6. set highlighting for the Visual area an other text | |
2217 */ | |
2218 col = 0; | |
2219 | |
2220 /* | |
2221 * 1. Add the cmdwin_type for the command-line window | |
2222 * Ignores 'rightleft', this window is never right-left. | |
2223 */ | |
2224 #ifdef FEAT_CMDWIN | |
2225 if (cmdwin_type != 0 && wp == curwin) | |
2226 { | |
2227 ScreenLines[off] = cmdwin_type; | |
2228 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2229 #ifdef FEAT_MBYTE | |
2230 if (enc_utf8) | |
2231 ScreenLinesUC[off] = 0; | |
2232 #endif | |
2233 ++col; | |
2234 } | |
2235 #endif | |
2236 | |
2237 /* | |
2238 * 2. Add the 'foldcolumn' | |
2239 */ | |
2240 fdc = wp->w_p_fdc; | |
2241 if (fdc > W_WIDTH(wp) - col) | |
2242 fdc = W_WIDTH(wp) - col; | |
2243 if (fdc > 0) | |
2244 { | |
2245 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2246 #ifdef FEAT_RIGHTLEFT | |
2247 if (wp->w_p_rl) | |
2248 { | |
2249 int i; | |
2250 | |
2251 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2252 hl_attr(HLF_FC)); | |
2253 /* reverse the fold column */ | |
2254 for (i = 0; i < fdc; ++i) | |
2255 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2256 } | |
2257 else | |
2258 #endif | |
2259 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2260 col += fdc; | |
2261 } | |
2262 | |
2263 #ifdef FEAT_RIGHTLEFT | |
216 | 2264 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2265 for (ri = 0; ri < l; ++ri) \ | |
2266 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2267 else \ | |
2268 for (ri = 0; ri < l; ++ri) \ | |
2269 ScreenAttrs[off + (p) + ri] = v | |
7 | 2270 #else |
216 | 2271 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2272 ScreenAttrs[off + (p) + ri] = v | |
7 | 2273 #endif |
2274 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2275 /* 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
|
2276 * text */ |
216 | 2277 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2278 |
2279 #ifdef FEAT_SIGNS | |
2280 /* If signs are being displayed, add two spaces. */ | |
2281 if (draw_signcolumn(wp)) | |
2282 { | |
2283 len = W_WIDTH(wp) - col; | |
2284 if (len > 0) | |
2285 { | |
2286 if (len > 2) | |
2287 len = 2; | |
2288 # ifdef FEAT_RIGHTLEFT | |
2289 if (wp->w_p_rl) | |
2290 /* the line number isn't reversed */ | |
2291 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2292 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2293 else | |
2294 # endif | |
2295 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2296 col += len; | |
2297 } | |
2298 } | |
2299 #endif | |
2300 | |
2301 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2302 * 3. Add the 'number' or 'relativenumber' column |
7 | 2303 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2304 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2305 { |
2306 len = W_WIDTH(wp) - col; | |
2307 if (len > 0) | |
2308 { | |
13 | 2309 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2310 long num; |
13 | 2311 |
2312 if (len > w + 1) | |
2313 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2314 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2315 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2316 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2317 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2318 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2319 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2320 num = (long)abs((int)get_cursor_rel_lnum(wp, lnum)); |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2321 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2322 sprintf((char *)buf, "%*ld ", w, num); |
7 | 2323 #ifdef FEAT_RIGHTLEFT |
2324 if (wp->w_p_rl) | |
2325 /* the line number isn't reversed */ | |
2326 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2327 hl_attr(HLF_FL)); | |
2328 else | |
2329 #endif | |
2330 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2331 col += len; | |
2332 } | |
2333 } | |
2334 | |
2335 /* | |
2336 * 4. Compose the folded-line string with 'foldtext', if set. | |
2337 */ | |
29 | 2338 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2339 |
2340 txtcol = col; /* remember where text starts */ | |
2341 | |
2342 /* | |
2343 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2344 * Right-left text is put in columns 0 - number-col, normal text is put | |
2345 * in columns number-col - window-width. | |
2346 */ | |
2347 #ifdef FEAT_MBYTE | |
2348 if (has_mbyte) | |
2349 { | |
2350 int cells; | |
714 | 2351 int u8c, u8cc[MAX_MCO]; |
2352 int i; | |
7 | 2353 int idx; |
2354 int c_len; | |
33 | 2355 char_u *p; |
7 | 2356 # ifdef FEAT_ARABIC |
2357 int prev_c = 0; /* previous Arabic character */ | |
2358 int prev_c1 = 0; /* first composing char for prev_c */ | |
2359 # endif | |
2360 | |
2361 # ifdef FEAT_RIGHTLEFT | |
2362 if (wp->w_p_rl) | |
2363 idx = off; | |
2364 else | |
2365 # endif | |
2366 idx = off + col; | |
2367 | |
2368 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2369 for (p = text; *p != NUL; ) | |
2370 { | |
2371 cells = (*mb_ptr2cells)(p); | |
474 | 2372 c_len = (*mb_ptr2len)(p); |
7 | 2373 if (col + cells > W_WIDTH(wp) |
2374 # ifdef FEAT_RIGHTLEFT | |
2375 - (wp->w_p_rl ? col : 0) | |
2376 # endif | |
2377 ) | |
2378 break; | |
2379 ScreenLines[idx] = *p; | |
2380 if (enc_utf8) | |
2381 { | |
714 | 2382 u8c = utfc_ptr2char(p, u8cc); |
2383 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2384 { |
2385 ScreenLinesUC[idx] = 0; | |
2386 #ifdef FEAT_ARABIC | |
2387 prev_c = u8c; | |
2388 #endif | |
2389 } | |
2390 else | |
2391 { | |
2392 #ifdef FEAT_ARABIC | |
2393 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2394 { | |
2395 /* Do Arabic shaping. */ | |
714 | 2396 int pc, pc1, nc; |
2397 int pcc[MAX_MCO]; | |
7 | 2398 int firstbyte = *p; |
2399 | |
2400 /* The idea of what is the previous and next | |
2401 * character depends on 'rightleft'. */ | |
2402 if (wp->w_p_rl) | |
2403 { | |
2404 pc = prev_c; | |
2405 pc1 = prev_c1; | |
2406 nc = utf_ptr2char(p + c_len); | |
714 | 2407 prev_c1 = u8cc[0]; |
7 | 2408 } |
2409 else | |
2410 { | |
714 | 2411 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2412 nc = prev_c; |
714 | 2413 pc1 = pcc[0]; |
7 | 2414 } |
2415 prev_c = u8c; | |
2416 | |
714 | 2417 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2418 pc, pc1, nc); |
2419 ScreenLines[idx] = firstbyte; | |
2420 } | |
2421 else | |
2422 prev_c = u8c; | |
2423 #endif | |
2424 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2425 #ifdef UNICODE16 |
7 | 2426 if (u8c >= 0x10000) |
2427 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2428 else | |
1401 | 2429 #endif |
7 | 2430 ScreenLinesUC[idx] = u8c; |
714 | 2431 for (i = 0; i < Screen_mco; ++i) |
2432 { | |
2433 ScreenLinesC[i][idx] = u8cc[i]; | |
2434 if (u8cc[i] == 0) | |
2435 break; | |
2436 } | |
7 | 2437 } |
2438 if (cells > 1) | |
2439 ScreenLines[idx + 1] = 0; | |
2440 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2441 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2442 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2443 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2444 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2445 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2446 ScreenLines[idx + 1] = p[1]; |
7 | 2447 col += cells; |
2448 idx += cells; | |
2449 p += c_len; | |
2450 } | |
2451 } | |
2452 else | |
2453 #endif | |
2454 { | |
2455 len = (int)STRLEN(text); | |
2456 if (len > W_WIDTH(wp) - col) | |
2457 len = W_WIDTH(wp) - col; | |
2458 if (len > 0) | |
2459 { | |
2460 #ifdef FEAT_RIGHTLEFT | |
2461 if (wp->w_p_rl) | |
2462 STRNCPY(current_ScreenLine, text, len); | |
2463 else | |
2464 #endif | |
2465 STRNCPY(current_ScreenLine + col, text, len); | |
2466 col += len; | |
2467 } | |
2468 } | |
2469 | |
2470 /* Fill the rest of the line with the fold filler */ | |
2471 #ifdef FEAT_RIGHTLEFT | |
2472 if (wp->w_p_rl) | |
2473 col -= txtcol; | |
2474 #endif | |
2475 while (col < W_WIDTH(wp) | |
2476 #ifdef FEAT_RIGHTLEFT | |
2477 - (wp->w_p_rl ? txtcol : 0) | |
2478 #endif | |
2479 ) | |
2480 { | |
2481 #ifdef FEAT_MBYTE | |
2482 if (enc_utf8) | |
2483 { | |
2484 if (fill_fold >= 0x80) | |
2485 { | |
2486 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2487 ScreenLinesC[0][off + col] = 0; |
7 | 2488 } |
2489 else | |
2490 ScreenLinesUC[off + col] = 0; | |
2491 } | |
2492 #endif | |
2493 ScreenLines[off + col++] = fill_fold; | |
2494 } | |
2495 | |
2496 if (text != buf) | |
2497 vim_free(text); | |
2498 | |
2499 /* | |
2500 * 6. set highlighting for the Visual area an other text. | |
2501 * If all folded lines are in the Visual area, highlight the line. | |
2502 */ | |
2503 #ifdef FEAT_VISUAL | |
2504 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2505 { | |
2506 if (ltoreq(curwin->w_cursor, VIsual)) | |
2507 { | |
2508 /* Visual is after curwin->w_cursor */ | |
2509 top = &curwin->w_cursor; | |
2510 bot = &VIsual; | |
2511 } | |
2512 else | |
2513 { | |
2514 /* Visual is before curwin->w_cursor */ | |
2515 top = &VIsual; | |
2516 bot = &curwin->w_cursor; | |
2517 } | |
2518 if (lnum >= top->lnum | |
2519 && lnume <= bot->lnum | |
2520 && (VIsual_mode != 'v' | |
2521 || ((lnum > top->lnum | |
2522 || (lnum == top->lnum | |
2523 && top->col == 0)) | |
2524 && (lnume < bot->lnum | |
2525 || (lnume == bot->lnum | |
2526 && (bot->col - (*p_sel == 'e')) | |
1883 | 2527 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2528 { |
2529 if (VIsual_mode == Ctrl_V) | |
2530 { | |
2531 /* Visual block mode: highlight the chars part of the block */ | |
2532 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2533 { | |
2534 if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2535 len = wp->w_old_cursor_lcol; | |
2536 else | |
2537 len = W_WIDTH(wp) - txtcol; | |
2538 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2539 len - (int)wp->w_old_cursor_fcol); |
7 | 2540 } |
2541 } | |
2542 else | |
216 | 2543 { |
7 | 2544 /* Set all attributes of the text */ |
216 | 2545 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2546 } | |
7 | 2547 } |
2548 } | |
2549 #endif | |
2550 | |
743 | 2551 #ifdef FEAT_SYN_HL |
2552 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2553 if (wp->w_p_cuc) |
2554 { | |
2555 txtcol += wp->w_virtcol; | |
2556 if (wp->w_p_wrap) | |
2557 txtcol -= wp->w_skipcol; | |
2558 else | |
2559 txtcol -= wp->w_leftcol; | |
2560 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2561 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2562 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2563 } | |
743 | 2564 #endif |
7 | 2565 |
2566 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2567 (int)W_WIDTH(wp), FALSE); | |
2568 | |
2569 /* | |
2570 * Update w_cline_height and w_cline_folded if the cursor line was | |
2571 * updated (saves a call to plines() later). | |
2572 */ | |
2573 if (wp == curwin | |
2574 && lnum <= curwin->w_cursor.lnum | |
2575 && lnume >= curwin->w_cursor.lnum) | |
2576 { | |
2577 curwin->w_cline_row = row; | |
2578 curwin->w_cline_height = 1; | |
2579 curwin->w_cline_folded = TRUE; | |
2580 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2581 } | |
2582 } | |
2583 | |
2584 /* | |
2585 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2586 */ | |
2587 static void | |
2588 copy_text_attr(off, buf, len, attr) | |
2589 int off; | |
2590 char_u *buf; | |
2591 int len; | |
2592 int attr; | |
2593 { | |
216 | 2594 int i; |
2595 | |
7 | 2596 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2597 # ifdef FEAT_MBYTE | |
2598 if (enc_utf8) | |
2599 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2600 # endif | |
216 | 2601 for (i = 0; i < len; ++i) |
2602 ScreenAttrs[off + i] = attr; | |
7 | 2603 } |
2604 | |
2605 /* | |
2606 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2607 * Only to be called when 'foldcolumn' > 0. |
7 | 2608 */ |
2609 static void | |
2610 fill_foldcolumn(p, wp, closed, lnum) | |
2611 char_u *p; | |
2612 win_T *wp; | |
2613 int closed; /* TRUE of FALSE */ | |
2614 linenr_T lnum; /* current line number */ | |
2615 { | |
2616 int i = 0; | |
2617 int level; | |
2618 int first_level; | |
519 | 2619 int empty; |
7 | 2620 |
2621 /* Init to all spaces. */ | |
2622 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2623 | |
2624 level = win_foldinfo.fi_level; | |
2625 if (level > 0) | |
2626 { | |
519 | 2627 /* If there is only one column put more info in it. */ |
2628 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2629 | |
7 | 2630 /* If the column is too narrow, we start at the lowest level that |
2631 * fits and use numbers to indicated the depth. */ | |
519 | 2632 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2633 if (first_level < 1) |
2634 first_level = 1; | |
2635 | |
519 | 2636 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2637 { |
2638 if (win_foldinfo.fi_lnum == lnum | |
2639 && first_level + i >= win_foldinfo.fi_low_level) | |
2640 p[i] = '-'; | |
2641 else if (first_level == 1) | |
2642 p[i] = '|'; | |
2643 else if (first_level + i <= 9) | |
2644 p[i] = '0' + first_level + i; | |
2645 else | |
2646 p[i] = '>'; | |
2647 if (first_level + i == level) | |
2648 break; | |
2649 } | |
2650 } | |
2651 if (closed) | |
548 | 2652 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2653 } |
2654 #endif /* FEAT_FOLDING */ | |
2655 | |
2656 /* | |
2657 * Display line "lnum" of window 'wp' on the screen. | |
2658 * Start at row "startrow", stop when "endrow" is reached. | |
2659 * wp->w_virtcol needs to be valid. | |
2660 * | |
2661 * Return the number of last row the line occupies. | |
2662 */ | |
2663 static int | |
625 | 2664 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2665 win_T *wp; |
2666 linenr_T lnum; | |
2667 int startrow; | |
2668 int endrow; | |
1883 | 2669 int nochange UNUSED; /* not updating for changed text */ |
7 | 2670 { |
2671 int col; /* visual column on screen */ | |
2672 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2673 int c = 0; /* init for GCC */ | |
2674 long vcol = 0; /* virtual column (for tabs) */ | |
2675 long vcol_prev = -1; /* "vcol" of previous character */ | |
2676 char_u *line; /* current line */ | |
2677 char_u *ptr; /* current position in "line" */ | |
2678 int row; /* row in the window, excl w_winrow */ | |
2679 int screen_row; /* row on the screen, incl w_winrow */ | |
2680 | |
2681 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2682 int n_extra = 0; /* number of extra chars */ | |
1340 | 2683 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2684 int c_extra = NUL; /* extra chars, all the same */ |
2685 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2686 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2687 displaying lcs_eol at end-of-line */ | |
2688 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2689 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2690 | |
2691 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2692 int saved_n_extra = 0; | |
2693 char_u *saved_p_extra = NULL; | |
2694 int saved_c_extra = 0; | |
2695 int saved_char_attr = 0; | |
2696 | |
2697 int n_attr = 0; /* chars with special attr */ | |
2698 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2699 int n_attr3 = 0; /* chars with overruling special attr */ | |
2700 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2701 | |
2702 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2703 | |
2704 int fromcol, tocol; /* start/end of inverting */ | |
2705 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2706 int noinvcur = FALSE; /* don't invert the cursor */ | |
2707 #ifdef FEAT_VISUAL | |
2708 pos_T *top, *bot; | |
1813 | 2709 int lnum_in_visual_area = FALSE; |
7 | 2710 #endif |
2711 pos_T pos; | |
2712 long v; | |
2713 | |
2714 int char_attr = 0; /* attributes for next character */ | |
674 | 2715 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2716 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2717 in this line */ | |
2718 int attr = 0; /* attributes for area highlighting */ | |
2719 int area_attr = 0; /* attributes desired by highlighting */ | |
2720 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2721 #ifdef FEAT_SYN_HL | |
743 | 2722 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2723 int syntax_attr = 0; /* attributes desired by syntax */ |
2724 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2725 int save_did_emsg; | |
1437 | 2726 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
|
2727 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2728 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2729 #endif |
2730 #ifdef FEAT_SPELL | |
221 | 2731 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2732 # define SPWORDLEN 150 |
2733 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2734 int nextlinecol = 0; /* column where nextline[] starts */ |
2735 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2736 starts */ |
221 | 2737 int spell_attr = 0; /* attributes desired by spelling */ |
2738 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2739 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2740 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2741 * there are no spell errors */ |
386 | 2742 static int cap_col = -1; /* column to check for Cap word */ |
2743 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2744 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2745 #endif |
2746 int extra_check; /* has syntax or linebreak */ | |
2747 #ifdef FEAT_MBYTE | |
2748 int multi_attr = 0; /* attributes desired by multibyte */ | |
2749 int mb_l = 1; /* multi-byte byte length */ | |
2750 int mb_c = 0; /* decoded multi-byte character */ | |
2751 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2752 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2753 #endif |
2754 #ifdef FEAT_DIFF | |
2755 int filler_lines; /* nr of filler lines to be drawn */ | |
2756 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2757 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2758 int change_start = MAXCOL; /* first col of changed area */ |
2759 int change_end = -1; /* last col of changed area */ | |
2760 #endif | |
2761 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2762 #ifdef FEAT_LINEBREAK | |
2763 int need_showbreak = FALSE; | |
2764 #endif | |
910 | 2765 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2766 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2767 # define LINE_ATTR |
1536 | 2768 int line_attr = 0; /* attribute for the whole line */ |
7 | 2769 #endif |
2770 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2771 matchitem_T *cur; /* points to the match list */ |
2772 match_T *shl; /* points to search_hl or a match */ | |
2773 int shl_flag; /* flag to indicate whether search_hl | |
2774 has been processed or not */ | |
2775 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2776 equals startcol of search_hl or one | |
2777 of the matches */ | |
7 | 2778 #endif |
2779 #ifdef FEAT_ARABIC | |
2780 int prev_c = 0; /* previous Arabic character */ | |
2781 int prev_c1 = 0; /* first composing char for prev_c */ | |
2782 #endif | |
910 | 2783 #if defined(LINE_ATTR) |
867 | 2784 int did_line_attr = 0; |
2785 #endif | |
7 | 2786 |
2787 /* draw_state: items that are drawn in sequence: */ | |
2788 #define WL_START 0 /* nothing done yet */ | |
2789 #ifdef FEAT_CMDWIN | |
2790 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2791 #else | |
2792 # define WL_CMDLINE WL_START | |
2793 #endif | |
2794 #ifdef FEAT_FOLDING | |
2795 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2796 #else | |
2797 # define WL_FOLD WL_CMDLINE | |
2798 #endif | |
2799 #ifdef FEAT_SIGNS | |
2800 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2801 #else | |
2802 # define WL_SIGN WL_FOLD /* column for signs */ | |
2803 #endif | |
2804 #define WL_NR WL_SIGN + 1 /* line number */ | |
2805 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2806 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2807 #else | |
2808 # define WL_SBR WL_NR | |
2809 #endif | |
2810 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2811 int draw_state = WL_START; /* what to draw next */ | |
574 | 2812 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2813 int feedback_col = 0; |
2814 int feedback_old_attr = -1; | |
2815 #endif | |
2816 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2817 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2818 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
|
2819 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
|
2820 int prev_syntax_id = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2821 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2822 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2823 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
|
2824 wrapping */ |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2825 int vcol_off = 0; /* offset for concealed characters */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2826 int did_wcol = FALSE; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2827 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2828 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2829 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2830 #endif |
7 | 2831 |
2832 if (startrow > endrow) /* past the end already! */ | |
2833 return startrow; | |
2834 | |
2835 row = startrow; | |
2836 screen_row = row + W_WINROW(wp); | |
2837 | |
2838 /* | |
2839 * To speed up the loop below, set extra_check when there is linebreak, | |
2840 * trailing white space and/or syntax processing to be done. | |
2841 */ | |
2842 #ifdef FEAT_LINEBREAK | |
2843 extra_check = wp->w_p_lbr; | |
2844 #else | |
2845 extra_check = 0; | |
2846 #endif | |
2847 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2848 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2849 { |
2850 /* Prepare for syntax highlighting in this line. When there is an | |
2851 * error, stop syntax highlighting. */ | |
2852 save_did_emsg = did_emsg; | |
2853 did_emsg = FALSE; | |
2854 syntax_start(wp, lnum); | |
2855 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2856 wp->w_s->b_syn_error = TRUE; |
7 | 2857 else |
2858 { | |
2859 did_emsg = save_did_emsg; | |
2860 has_syntax = TRUE; | |
2861 extra_check = TRUE; | |
2862 } | |
2863 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2864 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2865 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2866 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2867 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2868 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 2869 #endif |
2870 | |
2871 #ifdef FEAT_SPELL | |
258 | 2872 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2873 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2874 && 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
|
2875 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2876 { |
2877 /* Prepare for spell checking. */ | |
2878 has_spell = TRUE; | |
2879 extra_check = TRUE; | |
348 | 2880 |
2881 /* Get the start of the next line, so that words that wrap to the next | |
2882 * line are found too: "et<line-break>al.". | |
2883 * Trick: skip a few chars for C/shell/Vim comments */ | |
2884 nextline[SPWORDLEN] = NUL; | |
2885 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2886 { | |
2887 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2888 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2889 } | |
2890 | |
2891 /* When a word wrapped from the previous line the start of the current | |
2892 * line is valid. */ | |
2893 if (lnum == checked_lnum) | |
2894 cur_checked_col = checked_col; | |
2895 checked_lnum = 0; | |
386 | 2896 |
2897 /* When there was a sentence end in the previous line may require a | |
2898 * word starting with capital in this line. In line 1 always check | |
2899 * the first word. */ | |
2900 if (lnum != capcol_lnum) | |
2901 cap_col = -1; | |
2902 if (lnum == 1) | |
2903 cap_col = 0; | |
2904 capcol_lnum = 0; | |
221 | 2905 } |
7 | 2906 #endif |
2907 | |
2908 /* | |
2909 * handle visual active in this window | |
2910 */ | |
2911 fromcol = -10; | |
2912 tocol = MAXCOL; | |
2913 #ifdef FEAT_VISUAL | |
2914 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2915 { | |
2916 /* Visual is after curwin->w_cursor */ | |
2917 if (ltoreq(curwin->w_cursor, VIsual)) | |
2918 { | |
2919 top = &curwin->w_cursor; | |
2920 bot = &VIsual; | |
2921 } | |
2922 else /* Visual is before curwin->w_cursor */ | |
2923 { | |
2924 top = &VIsual; | |
2925 bot = &curwin->w_cursor; | |
2926 } | |
1813 | 2927 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2928 if (VIsual_mode == Ctrl_V) /* block mode */ |
2929 { | |
1813 | 2930 if (lnum_in_visual_area) |
7 | 2931 { |
2932 fromcol = wp->w_old_cursor_fcol; | |
2933 tocol = wp->w_old_cursor_lcol; | |
2934 } | |
2935 } | |
2936 else /* non-block mode */ | |
2937 { | |
2938 if (lnum > top->lnum && lnum <= bot->lnum) | |
2939 fromcol = 0; | |
2940 else if (lnum == top->lnum) | |
2941 { | |
2942 if (VIsual_mode == 'V') /* linewise */ | |
2943 fromcol = 0; | |
2944 else | |
2945 { | |
2946 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2947 if (gchar_pos(top) == NUL) | |
2948 tocol = fromcol + 1; | |
2949 } | |
2950 } | |
2951 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2952 { | |
2953 if (*p_sel == 'e' && bot->col == 0 | |
2954 #ifdef FEAT_VIRTUALEDIT | |
2955 && bot->coladd == 0 | |
2956 #endif | |
2957 ) | |
2958 { | |
2959 fromcol = -10; | |
2960 tocol = MAXCOL; | |
2961 } | |
36 | 2962 else if (bot->col == MAXCOL) |
2963 tocol = MAXCOL; | |
7 | 2964 else |
2965 { | |
2966 pos = *bot; | |
2967 if (*p_sel == 'e') | |
2968 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2969 else | |
2970 { | |
2971 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2972 ++tocol; | |
2973 } | |
2974 } | |
2975 } | |
2976 } | |
2977 | |
2978 #ifndef MSDOS | |
2979 /* Check if the character under the cursor should not be inverted */ | |
2980 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2981 # ifdef FEAT_GUI | |
2982 && !gui.in_use | |
2983 # endif | |
2984 ) | |
2985 noinvcur = TRUE; | |
2986 #endif | |
2987 | |
2988 /* if inverting in this line set area_highlighting */ | |
2989 if (fromcol >= 0) | |
2990 { | |
2991 area_highlighting = TRUE; | |
2992 attr = hl_attr(HLF_V); | |
2993 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2994 if (clip_star.available && !clip_star.owned && clip_isautosel()) | |
2995 attr = hl_attr(HLF_VNC); | |
2996 #endif | |
2997 } | |
2998 } | |
2999 | |
3000 /* | |
674 | 3001 * handle 'incsearch' and ":s///c" highlighting |
7 | 3002 */ |
3003 else | |
3004 #endif /* FEAT_VISUAL */ | |
3005 if (highlight_match | |
3006 && wp == curwin | |
3007 && lnum >= curwin->w_cursor.lnum | |
3008 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
3009 { | |
3010 if (lnum == curwin->w_cursor.lnum) | |
3011 getvcol(curwin, &(curwin->w_cursor), | |
3012 (colnr_T *)&fromcol, NULL, NULL); | |
3013 else | |
3014 fromcol = 0; | |
3015 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
3016 { | |
3017 pos.lnum = lnum; | |
3018 pos.col = search_match_endcol; | |
3019 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3020 } | |
3021 else | |
3022 tocol = MAXCOL; | |
1850 | 3023 /* do at least one character; happens when past end of line */ |
3024 if (fromcol == tocol) | |
3025 tocol = fromcol + 1; | |
7 | 3026 area_highlighting = TRUE; |
3027 attr = hl_attr(HLF_I); | |
3028 } | |
3029 | |
3030 #ifdef FEAT_DIFF | |
3031 filler_lines = diff_check(wp, lnum); | |
3032 if (filler_lines < 0) | |
3033 { | |
3034 if (filler_lines == -1) | |
3035 { | |
3036 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
3037 diff_hlf = HLF_ADD; /* added line */ | |
3038 else if (change_start == 0) | |
3039 diff_hlf = HLF_TXD; /* changed text */ | |
3040 else | |
3041 diff_hlf = HLF_CHD; /* changed line */ | |
3042 } | |
3043 else | |
3044 diff_hlf = HLF_ADD; /* added line */ | |
3045 filler_lines = 0; | |
3046 area_highlighting = TRUE; | |
3047 } | |
3048 if (lnum == wp->w_topline) | |
3049 filler_lines = wp->w_topfill; | |
3050 filler_todo = filler_lines; | |
3051 #endif | |
3052 | |
3053 #ifdef LINE_ATTR | |
3054 # ifdef FEAT_SIGNS | |
3055 /* If this line has a sign with line highlighting set line_attr. */ | |
3056 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3057 if (v != 0) | |
3058 line_attr = sign_get_attr((int)v, TRUE); | |
3059 # endif | |
3060 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3061 /* Highlight the current line in the quickfix window. */ | |
644 | 3062 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3063 line_attr = hl_attr(HLF_L); |
3064 # endif | |
3065 if (line_attr != 0) | |
3066 area_highlighting = TRUE; | |
3067 #endif | |
3068 | |
3069 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3070 ptr = line; | |
3071 | |
743 | 3072 #ifdef FEAT_SPELL |
348 | 3073 if (has_spell) |
3074 { | |
386 | 3075 /* For checking first word with a capital skip white space. */ |
3076 if (cap_col == 0) | |
835 | 3077 cap_col = (int)(skipwhite(line) - line); |
386 | 3078 |
348 | 3079 /* To be able to spell-check over line boundaries copy the end of the |
3080 * current line into nextline[]. Above the start of the next line was | |
3081 * copied to nextline[SPWORDLEN]. */ | |
3082 if (nextline[SPWORDLEN] == NUL) | |
3083 { | |
3084 /* No next line or it is empty. */ | |
3085 nextlinecol = MAXCOL; | |
3086 nextline_idx = 0; | |
3087 } | |
3088 else | |
3089 { | |
835 | 3090 v = (long)STRLEN(line); |
348 | 3091 if (v < SPWORDLEN) |
3092 { | |
3093 /* Short line, use it completely and append the start of the | |
3094 * next line. */ | |
3095 nextlinecol = 0; | |
3096 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3097 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3098 nextline_idx = v + 1; |
3099 } | |
3100 else | |
3101 { | |
3102 /* Long line, use only the last SPWORDLEN bytes. */ | |
3103 nextlinecol = v - SPWORDLEN; | |
3104 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3105 nextline_idx = SPWORDLEN + 1; | |
3106 } | |
3107 } | |
3108 } | |
3109 #endif | |
3110 | |
7 | 3111 /* find start of trailing whitespace */ |
3112 if (wp->w_p_list && lcs_trail) | |
3113 { | |
3114 trailcol = (colnr_T)STRLEN(ptr); | |
3115 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3116 --trailcol; | |
3117 trailcol += (colnr_T) (ptr - line); | |
3118 extra_check = TRUE; | |
3119 } | |
3120 | |
3121 /* | |
3122 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3123 * first character to be displayed. | |
3124 */ | |
3125 if (wp->w_p_wrap) | |
3126 v = wp->w_skipcol; | |
3127 else | |
3128 v = wp->w_leftcol; | |
3129 if (v > 0) | |
3130 { | |
3131 #ifdef FEAT_MBYTE | |
3132 char_u *prev_ptr = ptr; | |
3133 #endif | |
3134 while (vcol < v && *ptr != NUL) | |
3135 { | |
3136 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3137 vcol += c; | |
3138 #ifdef FEAT_MBYTE | |
3139 prev_ptr = ptr; | |
39 | 3140 #endif |
3141 mb_ptr_adv(ptr); | |
7 | 3142 } |
3143 | |
1984 | 3144 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3145 /* When: | |
3146 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3147 * - 'colorcolumn' is set, or |
1984 | 3148 * - 'virtualedit' is set, or |
3149 * - the visual mode is active, | |
3150 * the end of the line may be before the start of the displayed part. | |
3151 */ | |
3152 if (vcol < v && ( | |
3153 # ifdef FEAT_SYN_HL | |
3154 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3155 || draw_color_col |
1984 | 3156 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3157 || | |
3158 # endif | |
3159 # endif | |
3160 # ifdef FEAT_VIRTUALEDIT | |
3161 virtual_active() | |
3162 # ifdef FEAT_VISUAL | |
3163 || | |
3164 # endif | |
3165 # endif | |
3166 # ifdef FEAT_VISUAL | |
3167 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3168 # endif | |
3169 )) | |
3170 { | |
7 | 3171 vcol = v; |
1984 | 3172 } |
7 | 3173 #endif |
3174 | |
3175 /* Handle a character that's not completely on the screen: Put ptr at | |
3176 * that character but skip the first few screen characters. */ | |
3177 if (vcol > v) | |
3178 { | |
3179 vcol -= c; | |
3180 #ifdef FEAT_MBYTE | |
3181 ptr = prev_ptr; | |
3182 #else | |
3183 --ptr; | |
3184 #endif | |
3185 n_skip = v - vcol; | |
3186 } | |
3187 | |
3188 /* | |
3189 * Adjust for when the inverted text is before the screen, | |
3190 * and when the start of the inverted text is before the screen. | |
3191 */ | |
3192 if (tocol <= vcol) | |
3193 fromcol = 0; | |
3194 else if (fromcol >= 0 && fromcol < vcol) | |
3195 fromcol = vcol; | |
3196 | |
3197 #ifdef FEAT_LINEBREAK | |
3198 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3199 if (wp->w_p_wrap) | |
3200 need_showbreak = TRUE; | |
3201 #endif | |
743 | 3202 #ifdef FEAT_SPELL |
499 | 3203 /* When spell checking a word we need to figure out the start of the |
3204 * word and if it's badly spelled or not. */ | |
3205 if (has_spell) | |
3206 { | |
3207 int len; | |
1536 | 3208 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3209 hlf_T spell_hlf = HLF_COUNT; |
499 | 3210 |
3211 pos = wp->w_cursor; | |
3212 wp->w_cursor.lnum = lnum; | |
1536 | 3213 wp->w_cursor.col = linecol; |
534 | 3214 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3215 |
3216 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3217 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3218 ptr = line + linecol; | |
3219 | |
530 | 3220 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3221 { |
3222 /* no bad word found at line start, don't check until end of a | |
3223 * word */ | |
534 | 3224 spell_hlf = HLF_COUNT; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3225 word_end = (int)(spell_to_word_end(ptr, wp) |
1536 | 3226 - line + 1); |
499 | 3227 } |
3228 else | |
534 | 3229 { |
499 | 3230 /* bad word found, use attributes until end of word */ |
3231 word_end = wp->w_cursor.col + len + 1; | |
3232 | |
534 | 3233 /* Turn index into actual attributes. */ |
3234 if (spell_hlf != HLF_COUNT) | |
3235 spell_attr = highlight_attr[spell_hlf]; | |
3236 } | |
499 | 3237 wp->w_cursor = pos; |
501 | 3238 |
743 | 3239 # ifdef FEAT_SYN_HL |
501 | 3240 /* Need to restart syntax highlighting for this line. */ |
3241 if (has_syntax) | |
3242 syntax_start(wp, lnum); | |
743 | 3243 # endif |
499 | 3244 } |
3245 #endif | |
7 | 3246 } |
3247 | |
3248 /* | |
3249 * Correct highlighting for cursor that can't be disabled. | |
3250 * Avoids having to check this for each character. | |
3251 */ | |
3252 if (fromcol >= 0) | |
3253 { | |
3254 if (noinvcur) | |
3255 { | |
3256 if ((colnr_T)fromcol == wp->w_virtcol) | |
3257 { | |
3258 /* highlighting starts at cursor, let it start just after the | |
3259 * cursor */ | |
3260 fromcol_prev = fromcol; | |
3261 fromcol = -1; | |
3262 } | |
3263 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3264 /* restart highlighting after the cursor */ | |
3265 fromcol_prev = wp->w_virtcol; | |
3266 } | |
3267 if (fromcol >= tocol) | |
3268 fromcol = -1; | |
3269 } | |
3270 | |
3271 #ifdef FEAT_SEARCH_EXTRA | |
3272 /* | |
1326 | 3273 * Handle highlighting the last used search pattern and matches. |
3274 * Do this for both search_hl and the match list. | |
7 | 3275 */ |
1326 | 3276 cur = wp->w_match_head; |
3277 shl_flag = FALSE; | |
3278 while (cur != NULL || shl_flag == FALSE) | |
3279 { | |
3280 if (shl_flag == FALSE) | |
3281 { | |
3282 shl = &search_hl; | |
3283 shl_flag = TRUE; | |
3284 } | |
3285 else | |
3286 shl = &cur->hl; | |
36 | 3287 shl->startcol = MAXCOL; |
3288 shl->endcol = MAXCOL; | |
7 | 3289 shl->attr_cur = 0; |
3290 if (shl->rm.regprog != NULL) | |
3291 { | |
3292 v = (long)(ptr - line); | |
3293 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3294 | |
3295 /* Need to get the line again, a multi-line regexp may have made it | |
3296 * invalid. */ | |
3297 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3298 ptr = line + v; | |
3299 | |
3300 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3301 { | |
3302 if (shl->lnum == lnum) | |
36 | 3303 shl->startcol = shl->rm.startpos[0].col; |
7 | 3304 else |
36 | 3305 shl->startcol = 0; |
7 | 3306 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3307 - shl->rm.startpos[0].lnum) | |
36 | 3308 shl->endcol = shl->rm.endpos[0].col; |
7 | 3309 else |
36 | 3310 shl->endcol = MAXCOL; |
7 | 3311 /* Highlight one character for an empty match. */ |
36 | 3312 if (shl->startcol == shl->endcol) |
7 | 3313 { |
3314 #ifdef FEAT_MBYTE | |
36 | 3315 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3316 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3317 else |
3318 #endif | |
36 | 3319 ++shl->endcol; |
7 | 3320 } |
36 | 3321 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3322 { |
3323 shl->attr_cur = shl->attr; | |
3324 search_attr = shl->attr; | |
3325 } | |
3326 area_highlighting = TRUE; | |
3327 } | |
3328 } | |
1326 | 3329 if (shl != &search_hl && cur != NULL) |
3330 cur = cur->next; | |
7 | 3331 } |
3332 #endif | |
3333 | |
743 | 3334 #ifdef FEAT_SYN_HL |
818 | 3335 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3336 * active, because it's not clear what is selected then. */ | |
3337 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3338 { |
3339 line_attr = hl_attr(HLF_CUL); | |
3340 area_highlighting = TRUE; | |
3341 } | |
3342 #endif | |
3343 | |
504 | 3344 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3345 col = 0; |
3346 #ifdef FEAT_RIGHTLEFT | |
3347 if (wp->w_p_rl) | |
3348 { | |
3349 /* Rightleft window: process the text in the normal direction, but put | |
3350 * it in current_ScreenLine[] from right to left. Start at the | |
3351 * rightmost column of the window. */ | |
3352 col = W_WIDTH(wp) - 1; | |
3353 off += col; | |
3354 } | |
3355 #endif | |
3356 | |
3357 /* | |
3358 * Repeat for the whole displayed line. | |
3359 */ | |
3360 for (;;) | |
3361 { | |
3362 /* Skip this quickly when working on the text. */ | |
3363 if (draw_state != WL_LINE) | |
3364 { | |
3365 #ifdef FEAT_CMDWIN | |
3366 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3367 { | |
3368 draw_state = WL_CMDLINE; | |
3369 if (cmdwin_type != 0 && wp == curwin) | |
3370 { | |
3371 /* Draw the cmdline character. */ | |
3372 n_extra = 1; | |
1340 | 3373 c_extra = cmdwin_type; |
7 | 3374 char_attr = hl_attr(HLF_AT); |
3375 } | |
3376 } | |
3377 #endif | |
3378 | |
3379 #ifdef FEAT_FOLDING | |
3380 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3381 { | |
3382 draw_state = WL_FOLD; | |
3383 if (wp->w_p_fdc > 0) | |
3384 { | |
3385 /* Draw the 'foldcolumn'. */ | |
3386 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3387 n_extra = wp->w_p_fdc; | |
3388 p_extra = extra; | |
1340 | 3389 p_extra[n_extra] = NUL; |
7 | 3390 c_extra = NUL; |
3391 char_attr = hl_attr(HLF_FC); | |
3392 } | |
3393 } | |
3394 #endif | |
3395 | |
3396 #ifdef FEAT_SIGNS | |
3397 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3398 { | |
3399 draw_state = WL_SIGN; | |
3400 /* Show the sign column when there are any signs in this | |
3401 * buffer or when using Netbeans. */ | |
3402 if (draw_signcolumn(wp) | |
3403 # ifdef FEAT_DIFF | |
3404 && filler_todo <= 0 | |
3405 # endif | |
3406 ) | |
3407 { | |
3408 int_u text_sign; | |
3409 # ifdef FEAT_SIGN_ICONS | |
3410 int_u icon_sign; | |
3411 # endif | |
3412 | |
3413 /* Draw two cells with the sign value or blank. */ | |
3414 c_extra = ' '; | |
3415 char_attr = hl_attr(HLF_SC); | |
3416 n_extra = 2; | |
3417 | |
3418 if (row == startrow) | |
3419 { | |
3420 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3421 SIGN_TEXT); | |
3422 # ifdef FEAT_SIGN_ICONS | |
3423 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3424 SIGN_ICON); | |
3425 if (gui.in_use && icon_sign != 0) | |
3426 { | |
3427 /* Use the image in this position. */ | |
3428 c_extra = SIGN_BYTE; | |
3429 # ifdef FEAT_NETBEANS_INTG | |
3430 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3431 c_extra = MULTISIGN_BYTE; | |
3432 # endif | |
3433 char_attr = icon_sign; | |
3434 } | |
3435 else | |
3436 # endif | |
3437 if (text_sign != 0) | |
3438 { | |
3439 p_extra = sign_get_text(text_sign); | |
3440 if (p_extra != NULL) | |
3441 { | |
3442 c_extra = NUL; | |
835 | 3443 n_extra = (int)STRLEN(p_extra); |
7 | 3444 } |
3445 char_attr = sign_get_attr(text_sign, FALSE); | |
3446 } | |
3447 } | |
3448 } | |
3449 } | |
3450 #endif | |
3451 | |
3452 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3453 { | |
3454 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3455 /* 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
|
3456 * 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
|
3457 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3458 && (row == startrow |
3459 #ifdef FEAT_DIFF | |
3460 + filler_lines | |
3461 #endif | |
3462 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3463 { | |
3464 /* Draw the line number (empty space after wrapping). */ | |
3465 if (row == startrow | |
3466 #ifdef FEAT_DIFF | |
3467 + filler_lines | |
3468 #endif | |
3469 ) | |
3470 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3471 long num; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3472 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3473 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3474 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3475 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3476 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3477 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3478 num = (long)abs((int)get_cursor_rel_lnum(wp, |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3479 lnum)); |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3480 |
13 | 3481 sprintf((char *)extra, "%*ld ", |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3482 number_width(wp), num); |
7 | 3483 if (wp->w_skipcol > 0) |
3484 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3485 *p_extra = '-'; | |
3486 #ifdef FEAT_RIGHTLEFT | |
3487 if (wp->w_p_rl) /* reverse line numbers */ | |
3488 rl_mirror(extra); | |
3489 #endif | |
3490 p_extra = extra; | |
3491 c_extra = NUL; | |
3492 } | |
3493 else | |
3494 c_extra = ' '; | |
13 | 3495 n_extra = number_width(wp) + 1; |
7 | 3496 char_attr = hl_attr(HLF_N); |
743 | 3497 #ifdef FEAT_SYN_HL |
3498 /* When 'cursorline' is set highlight the line number of | |
3499 * the current line differently. */ | |
3500 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) | |
3501 char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); | |
3502 #endif | |
7 | 3503 } |
3504 } | |
3505 | |
3506 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3507 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3508 { | |
3509 draw_state = WL_SBR; | |
3510 # ifdef FEAT_DIFF | |
3511 if (filler_todo > 0) | |
3512 { | |
3513 /* Draw "deleted" diff line(s). */ | |
3514 if (char2cells(fill_diff) > 1) | |
3515 c_extra = '-'; | |
3516 else | |
3517 c_extra = fill_diff; | |
3518 # ifdef FEAT_RIGHTLEFT | |
3519 if (wp->w_p_rl) | |
3520 n_extra = col + 1; | |
3521 else | |
3522 # endif | |
3523 n_extra = W_WIDTH(wp) - col; | |
3524 char_attr = hl_attr(HLF_DED); | |
3525 } | |
3526 # endif | |
3527 # ifdef FEAT_LINEBREAK | |
3528 if (*p_sbr != NUL && need_showbreak) | |
3529 { | |
3530 /* Draw 'showbreak' at the start of each broken line. */ | |
3531 p_extra = p_sbr; | |
3532 c_extra = NUL; | |
3533 n_extra = (int)STRLEN(p_sbr); | |
3534 char_attr = hl_attr(HLF_AT); | |
3535 need_showbreak = FALSE; | |
3536 /* Correct end of highlighted area for 'showbreak', | |
3537 * required when 'linebreak' is also set. */ | |
3538 if (tocol == vcol) | |
3539 tocol += n_extra; | |
3540 } | |
3541 # endif | |
3542 } | |
3543 #endif | |
3544 | |
3545 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3546 { | |
3547 draw_state = WL_LINE; | |
3548 if (saved_n_extra) | |
3549 { | |
3550 /* Continue item from end of wrapped line. */ | |
3551 n_extra = saved_n_extra; | |
3552 c_extra = saved_c_extra; | |
3553 p_extra = saved_p_extra; | |
3554 char_attr = saved_char_attr; | |
3555 } | |
3556 else | |
3557 char_attr = 0; | |
3558 } | |
3559 } | |
3560 | |
3561 /* When still displaying '$' of change command, stop at cursor */ | |
819 | 3562 if (dollar_vcol != 0 && wp == curwin |
3563 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol | |
7 | 3564 #ifdef FEAT_DIFF |
3565 && filler_todo <= 0 | |
3566 #endif | |
3567 ) | |
3568 { | |
3569 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3570 wp->w_p_rl); | |
819 | 3571 /* Pretend we have finished updating the window. Except when |
3572 * 'cursorcolumn' is set. */ | |
3573 #ifdef FEAT_SYN_HL | |
3574 if (wp->w_p_cuc) | |
3575 row = wp->w_cline_row + wp->w_cline_height; | |
3576 else | |
3577 #endif | |
3578 row = wp->w_height; | |
7 | 3579 break; |
3580 } | |
3581 | |
3582 if (draw_state == WL_LINE && area_highlighting) | |
3583 { | |
3584 /* handle Visual or match highlighting in this line */ | |
3585 if (vcol == fromcol | |
3586 #ifdef FEAT_MBYTE | |
3587 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3588 && (*mb_ptr2cells)(ptr) > 1) | |
3589 #endif | |
3590 || ((int)vcol_prev == fromcol_prev | |
1814 | 3591 && vcol_prev < vcol /* not at margin */ |
7 | 3592 && vcol < tocol)) |
3593 area_attr = attr; /* start highlighting */ | |
3594 else if (area_attr != 0 | |
3595 && (vcol == tocol | |
3596 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3597 area_attr = 0; /* stop highlighting */ | |
3598 | |
3599 #ifdef FEAT_SEARCH_EXTRA | |
3600 if (!n_extra) | |
3601 { | |
3602 /* | |
3603 * Check for start/end of search pattern match. | |
3604 * After end, check for start/end of next match. | |
3605 * When another match, have to check for start again. | |
3606 * Watch out for matching an empty string! | |
1326 | 3607 * Do this for 'search_hl' and the match list (ordered by |
3608 * priority). | |
7 | 3609 */ |
36 | 3610 v = (long)(ptr - line); |
1326 | 3611 cur = wp->w_match_head; |
3612 shl_flag = FALSE; | |
3613 while (cur != NULL || shl_flag == FALSE) | |
3614 { | |
3615 if (shl_flag == FALSE | |
3616 && ((cur != NULL | |
3617 && cur->priority > SEARCH_HL_PRIORITY) | |
3618 || cur == NULL)) | |
3619 { | |
3620 shl = &search_hl; | |
3621 shl_flag = TRUE; | |
3622 } | |
3623 else | |
3624 shl = &cur->hl; | |
7 | 3625 while (shl->rm.regprog != NULL) |
3626 { | |
36 | 3627 if (shl->startcol != MAXCOL |
3628 && v >= (long)shl->startcol | |
3629 && v < (long)shl->endcol) | |
7 | 3630 { |
3631 shl->attr_cur = shl->attr; | |
3632 } | |
36 | 3633 else if (v == (long)shl->endcol) |
7 | 3634 { |
3635 shl->attr_cur = 0; | |
3636 | |
3637 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3638 | |
3639 /* Need to get the line again, a multi-line regexp | |
3640 * may have made it invalid. */ | |
3641 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3642 ptr = line + v; | |
3643 | |
3644 if (shl->lnum == lnum) | |
3645 { | |
36 | 3646 shl->startcol = shl->rm.startpos[0].col; |
7 | 3647 if (shl->rm.endpos[0].lnum == 0) |
36 | 3648 shl->endcol = shl->rm.endpos[0].col; |
7 | 3649 else |
36 | 3650 shl->endcol = MAXCOL; |
3651 | |
3652 if (shl->startcol == shl->endcol) | |
7 | 3653 { |
3654 /* highlight empty match, try again after | |
3655 * it */ | |
3656 #ifdef FEAT_MBYTE | |
3657 if (has_mbyte) | |
474 | 3658 shl->endcol += (*mb_ptr2len)(line |
36 | 3659 + shl->endcol); |
7 | 3660 else |
3661 #endif | |
36 | 3662 ++shl->endcol; |
7 | 3663 } |
3664 | |
3665 /* Loop to check if the match starts at the | |
3666 * current position */ | |
3667 continue; | |
3668 } | |
3669 } | |
3670 break; | |
3671 } | |
1326 | 3672 if (shl != &search_hl && cur != NULL) |
3673 cur = cur->next; | |
3674 } | |
3675 | |
3676 /* Use attributes from match with highest priority among | |
3677 * 'search_hl' and the match list. */ | |
3678 search_attr = search_hl.attr_cur; | |
3679 cur = wp->w_match_head; | |
3680 shl_flag = FALSE; | |
3681 while (cur != NULL || shl_flag == FALSE) | |
3682 { | |
3683 if (shl_flag == FALSE | |
3684 && ((cur != NULL | |
3685 && cur->priority > SEARCH_HL_PRIORITY) | |
3686 || cur == NULL)) | |
699 | 3687 { |
1326 | 3688 shl = &search_hl; |
3689 shl_flag = TRUE; | |
699 | 3690 } |
1326 | 3691 else |
3692 shl = &cur->hl; | |
3693 if (shl->attr_cur != 0) | |
3694 search_attr = shl->attr_cur; | |
3695 if (shl != &search_hl && cur != NULL) | |
3696 cur = cur->next; | |
3697 } | |
7 | 3698 } |
3699 #endif | |
3700 | |
3701 #ifdef FEAT_DIFF | |
674 | 3702 if (diff_hlf != (hlf_T)0) |
7 | 3703 { |
1295 | 3704 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3705 && n_extra == 0) | |
7 | 3706 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3707 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3708 && n_extra == 0) | |
7 | 3709 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3710 line_attr = hl_attr(diff_hlf); |
3711 } | |
3712 #endif | |
3713 | |
3714 /* Decide which of the highlight attributes to use. */ | |
3715 attr_pri = TRUE; | |
3716 if (area_attr != 0) | |
3717 char_attr = area_attr; | |
3718 else if (search_attr != 0) | |
3719 char_attr = search_attr; | |
3720 #ifdef LINE_ATTR | |
3721 /* Use line_attr when not in the Visual or 'incsearch' area | |
3722 * (area_attr may be 0 when "noinvcur" is set). */ | |
3723 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3724 || vcol < fromcol || vcol_prev < fromcol_prev |
3725 || vcol >= tocol)) | |
674 | 3726 char_attr = line_attr; |
3727 #endif | |
3728 else | |
3729 { | |
3730 attr_pri = FALSE; | |
3731 #ifdef FEAT_SYN_HL | |
3732 if (has_syntax) | |
3733 char_attr = syntax_attr; | |
3734 else | |
3735 #endif | |
3736 char_attr = 0; | |
3737 } | |
7 | 3738 } |
3739 | |
3740 /* | |
3741 * Get the next character to put on the screen. | |
3742 */ | |
3743 /* | |
1340 | 3744 * The "p_extra" points to the extra stuff that is inserted to |
3745 * represent special characters (non-printable stuff) and other | |
3746 * things. When all characters are the same, c_extra is used. | |
3747 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3748 * "p_extra[n_extra]". | |
7 | 3749 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3750 */ | |
3751 if (n_extra > 0) | |
3752 { | |
3753 if (c_extra != NUL) | |
3754 { | |
3755 c = c_extra; | |
3756 #ifdef FEAT_MBYTE | |
3757 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3758 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3759 { | |
3760 mb_utf8 = TRUE; | |
714 | 3761 u8cc[0] = 0; |
819 | 3762 c = 0xc0; |
7 | 3763 } |
3764 else | |
3765 mb_utf8 = FALSE; | |
3766 #endif | |
3767 } | |
3768 else | |
3769 { | |
3770 c = *p_extra; | |
3771 #ifdef FEAT_MBYTE | |
3772 if (has_mbyte) | |
3773 { | |
3774 mb_c = c; | |
3775 if (enc_utf8) | |
3776 { | |
3777 /* If the UTF-8 character is more than one byte: | |
3778 * Decode it into "mb_c". */ | |
474 | 3779 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3780 mb_utf8 = FALSE; |
3781 if (mb_l > n_extra) | |
3782 mb_l = 1; | |
3783 else if (mb_l > 1) | |
3784 { | |
714 | 3785 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3786 mb_utf8 = TRUE; |
819 | 3787 c = 0xc0; |
7 | 3788 } |
3789 } | |
3790 else | |
3791 { | |
3792 /* if this is a DBCS character, put it in "mb_c" */ | |
3793 mb_l = MB_BYTE2LEN(c); | |
3794 if (mb_l >= n_extra) | |
3795 mb_l = 1; | |
3796 else if (mb_l > 1) | |
3797 mb_c = (c << 8) + p_extra[1]; | |
3798 } | |
504 | 3799 if (mb_l == 0) /* at the NUL at end-of-line */ |
3800 mb_l = 1; | |
3801 | |
7 | 3802 /* If a double-width char doesn't fit display a '>' in the |
3803 * last column. */ | |
504 | 3804 if (( |
7 | 3805 # ifdef FEAT_RIGHTLEFT |
3806 wp->w_p_rl ? (col <= 0) : | |
3807 # endif | |
504 | 3808 (col >= W_WIDTH(wp) - 1)) |
7 | 3809 && (*mb_char2cells)(mb_c) == 2) |
3810 { | |
3811 c = '>'; | |
3812 mb_c = c; | |
3813 mb_l = 1; | |
3814 mb_utf8 = FALSE; | |
3815 multi_attr = hl_attr(HLF_AT); | |
3816 /* put the pointer back to output the double-width | |
3817 * character at the start of the next line. */ | |
3818 ++n_extra; | |
3819 --p_extra; | |
3820 } | |
3821 else | |
3822 { | |
3823 n_extra -= mb_l - 1; | |
3824 p_extra += mb_l - 1; | |
3825 } | |
3826 } | |
3827 #endif | |
3828 ++p_extra; | |
3829 } | |
3830 --n_extra; | |
3831 } | |
3832 else | |
3833 { | |
3834 /* | |
3835 * Get a character from the line itself. | |
3836 */ | |
3837 c = *ptr; | |
3838 #ifdef FEAT_MBYTE | |
3839 if (has_mbyte) | |
3840 { | |
3841 mb_c = c; | |
3842 if (enc_utf8) | |
3843 { | |
3844 /* If the UTF-8 character is more than one byte: Decode it | |
3845 * into "mb_c". */ | |
474 | 3846 mb_l = (*mb_ptr2len)(ptr); |
7 | 3847 mb_utf8 = FALSE; |
3848 if (mb_l > 1) | |
3849 { | |
714 | 3850 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3851 /* Overlong encoded ASCII or ASCII with composing char |
3852 * is displayed normally, except a NUL. */ | |
3853 if (mb_c < 0x80) | |
3854 c = mb_c; | |
3855 mb_utf8 = TRUE; | |
507 | 3856 |
3857 /* At start of the line we can have a composing char. | |
3858 * Draw it as a space with a composing char. */ | |
3859 if (utf_iscomposing(mb_c)) | |
3860 { | |
1326 | 3861 int i; |
3862 | |
714 | 3863 for (i = Screen_mco - 1; i > 0; --i) |
3864 u8cc[i] = u8cc[i - 1]; | |
3865 u8cc[0] = mb_c; | |
507 | 3866 mb_c = ' '; |
3867 } | |
7 | 3868 } |
3869 | |
3870 if ((mb_l == 1 && c >= 0x80) | |
3871 || (mb_l >= 1 && mb_c == 0) | |
3872 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3873 # ifdef UNICODE16 |
3874 || mb_c >= 0x10000 | |
3875 # endif | |
3876 ))) | |
7 | 3877 { |
3878 /* | |
3879 * Illegal UTF-8 byte: display as <xx>. | |
3880 * Non-BMP character : display as ? or fullwidth ?. | |
3881 */ | |
1401 | 3882 # ifdef UNICODE16 |
7 | 3883 if (mb_c < 0x10000) |
1401 | 3884 # endif |
7 | 3885 { |
3886 transchar_hex(extra, mb_c); | |
714 | 3887 # ifdef FEAT_RIGHTLEFT |
7 | 3888 if (wp->w_p_rl) /* reverse */ |
3889 rl_mirror(extra); | |
714 | 3890 # endif |
7 | 3891 } |
1401 | 3892 # ifdef UNICODE16 |
7 | 3893 else if (utf_char2cells(mb_c) != 2) |
3894 STRCPY(extra, "?"); | |
3895 else | |
3896 /* 0xff1f in UTF-8: full-width '?' */ | |
3897 STRCPY(extra, "\357\274\237"); | |
1401 | 3898 # endif |
7 | 3899 |
3900 p_extra = extra; | |
3901 c = *p_extra; | |
3902 mb_c = mb_ptr2char_adv(&p_extra); | |
3903 mb_utf8 = (c >= 0x80); | |
3904 n_extra = (int)STRLEN(p_extra); | |
3905 c_extra = NUL; | |
3906 if (area_attr == 0 && search_attr == 0) | |
3907 { | |
3908 n_attr = n_extra + 1; | |
3909 extra_attr = hl_attr(HLF_8); | |
3910 saved_attr2 = char_attr; /* save current attr */ | |
3911 } | |
3912 } | |
3913 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3914 mb_l = 1; | |
3915 #ifdef FEAT_ARABIC | |
3916 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3917 { | |
3918 /* Do Arabic shaping. */ | |
714 | 3919 int pc, pc1, nc; |
3920 int pcc[MAX_MCO]; | |
7 | 3921 |
3922 /* The idea of what is the previous and next | |
3923 * character depends on 'rightleft'. */ | |
3924 if (wp->w_p_rl) | |
3925 { | |
3926 pc = prev_c; | |
3927 pc1 = prev_c1; | |
3928 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3929 prev_c1 = u8cc[0]; |
7 | 3930 } |
3931 else | |
3932 { | |
714 | 3933 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3934 nc = prev_c; |
714 | 3935 pc1 = pcc[0]; |
7 | 3936 } |
3937 prev_c = mb_c; | |
3938 | |
714 | 3939 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3940 } |
3941 else | |
3942 prev_c = mb_c; | |
3943 #endif | |
3944 } | |
3945 else /* enc_dbcs */ | |
3946 { | |
3947 mb_l = MB_BYTE2LEN(c); | |
3948 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3949 mb_l = 1; | |
3950 else if (mb_l > 1) | |
3951 { | |
3952 /* We assume a second byte below 32 is illegal. | |
3953 * Hopefully this is OK for all double-byte encodings! | |
3954 */ | |
3955 if (ptr[1] >= 32) | |
3956 mb_c = (c << 8) + ptr[1]; | |
3957 else | |
3958 { | |
3959 if (ptr[1] == NUL) | |
3960 { | |
3961 /* head byte at end of line */ | |
3962 mb_l = 1; | |
3963 transchar_nonprint(extra, c); | |
3964 } | |
3965 else | |
3966 { | |
3967 /* illegal tail byte */ | |
3968 mb_l = 2; | |
3969 STRCPY(extra, "XX"); | |
3970 } | |
3971 p_extra = extra; | |
3972 n_extra = (int)STRLEN(extra) - 1; | |
3973 c_extra = NUL; | |
3974 c = *p_extra++; | |
3975 if (area_attr == 0 && search_attr == 0) | |
3976 { | |
3977 n_attr = n_extra + 1; | |
3978 extra_attr = hl_attr(HLF_8); | |
3979 saved_attr2 = char_attr; /* save current attr */ | |
3980 } | |
3981 mb_c = c; | |
3982 } | |
3983 } | |
3984 } | |
3985 /* If a double-width char doesn't fit display a '>' in the | |
3986 * last column; the character is displayed at the start of the | |
3987 * next line. */ | |
3988 if (( | |
3989 # ifdef FEAT_RIGHTLEFT | |
3990 wp->w_p_rl ? (col <= 0) : | |
3991 # endif | |
3992 (col >= W_WIDTH(wp) - 1)) | |
3993 && (*mb_char2cells)(mb_c) == 2) | |
3994 { | |
3995 c = '>'; | |
3996 mb_c = c; | |
3997 mb_utf8 = FALSE; | |
3998 mb_l = 1; | |
3999 multi_attr = hl_attr(HLF_AT); | |
4000 /* Put pointer back so that the character will be | |
4001 * displayed at the start of the next line. */ | |
4002 --ptr; | |
4003 } | |
4004 else if (*ptr != NUL) | |
4005 ptr += mb_l - 1; | |
4006 | |
4007 /* If a double-width char doesn't fit at the left side display | |
4008 * a '<' in the first column. */ | |
4009 if (n_skip > 0 && mb_l > 1) | |
4010 { | |
4011 n_extra = 1; | |
1340 | 4012 c_extra = '<'; |
7 | 4013 c = ' '; |
4014 if (area_attr == 0 && search_attr == 0) | |
4015 { | |
4016 n_attr = n_extra + 1; | |
4017 extra_attr = hl_attr(HLF_AT); | |
4018 saved_attr2 = char_attr; /* save current attr */ | |
4019 } | |
4020 mb_c = c; | |
4021 mb_utf8 = FALSE; | |
4022 mb_l = 1; | |
4023 } | |
4024 | |
4025 } | |
4026 #endif | |
4027 ++ptr; | |
4028 | |
12 | 4029 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 4030 if (wp->w_p_list && (c == 160 |
4031 #ifdef FEAT_MBYTE | |
4032 || (mb_utf8 && mb_c == 160) | |
4033 #endif | |
4034 ) && lcs_nbsp) | |
12 | 4035 { |
4036 c = lcs_nbsp; | |
4037 if (area_attr == 0 && search_attr == 0) | |
4038 { | |
4039 n_attr = 1; | |
4040 extra_attr = hl_attr(HLF_8); | |
4041 saved_attr2 = char_attr; /* save current attr */ | |
4042 } | |
4043 #ifdef FEAT_MBYTE | |
4044 mb_c = c; | |
4045 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4046 { | |
4047 mb_utf8 = TRUE; | |
714 | 4048 u8cc[0] = 0; |
819 | 4049 c = 0xc0; |
12 | 4050 } |
4051 else | |
4052 mb_utf8 = FALSE; | |
4053 #endif | |
4054 } | |
4055 | |
7 | 4056 if (extra_check) |
4057 { | |
743 | 4058 #ifdef FEAT_SPELL |
221 | 4059 int can_spell = TRUE; |
743 | 4060 #endif |
4061 | |
4062 #ifdef FEAT_SYN_HL | |
7 | 4063 /* Get syntax attribute, unless still at the start of the line |
4064 * (double-wide char that doesn't fit). */ | |
221 | 4065 v = (long)(ptr - line); |
4066 if (has_syntax && v > 0) | |
7 | 4067 { |
4068 /* Get the syntax attribute for the character. If there | |
4069 * is an error, disable syntax highlighting. */ | |
4070 save_did_emsg = did_emsg; | |
4071 did_emsg = FALSE; | |
4072 | |
221 | 4073 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 4074 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4075 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4076 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4077 NULL, FALSE); |
7 | 4078 |
4079 if (did_emsg) | |
482 | 4080 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4081 wp->w_s->b_syn_error = TRUE; |
482 | 4082 has_syntax = FALSE; |
4083 } | |
7 | 4084 else |
4085 did_emsg = save_did_emsg; | |
4086 | |
4087 /* Need to get the line again, a multi-line regexp may | |
4088 * have made it invalid. */ | |
4089 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4090 ptr = line + v; | |
4091 | |
674 | 4092 if (!attr_pri) |
7 | 4093 char_attr = syntax_attr; |
301 | 4094 else |
303 | 4095 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
|
4096 # 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
|
4097 /* 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
|
4098 * 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
|
4099 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
|
4100 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
|
4101 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
|
4102 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
|
4103 # endif |
7 | 4104 } |
743 | 4105 #endif |
4106 | |
4107 #ifdef FEAT_SPELL | |
301 | 4108 /* Check spelling (unless at the end of the line). |
319 | 4109 * Only do this when there is no syntax highlighting, the |
4110 * @Spell cluster is not used or the current syntax item | |
4111 * contains the @Spell cluster. */ | |
348 | 4112 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4113 { |
230 | 4114 spell_attr = 0; |
743 | 4115 # ifdef FEAT_SYN_HL |
674 | 4116 if (!attr_pri) |
230 | 4117 char_attr = syntax_attr; |
743 | 4118 # endif |
4119 if (c != 0 && ( | |
4120 # ifdef FEAT_SYN_HL | |
4121 !has_syntax || | |
4122 # endif | |
4123 can_spell)) | |
221 | 4124 { |
348 | 4125 char_u *prev_ptr, *p; |
4126 int len; | |
534 | 4127 hlf_T spell_hlf = HLF_COUNT; |
221 | 4128 # ifdef FEAT_MBYTE |
336 | 4129 if (has_mbyte) |
4130 { | |
4131 prev_ptr = ptr - mb_l; | |
4132 v -= mb_l - 1; | |
4133 } | |
4134 else | |
221 | 4135 # endif |
336 | 4136 prev_ptr = ptr - 1; |
348 | 4137 |
4138 /* Use nextline[] if possible, it has the start of the | |
4139 * next line concatenated. */ | |
4140 if ((prev_ptr - line) - nextlinecol >= 0) | |
4141 p = nextline + (prev_ptr - line) - nextlinecol; | |
4142 else | |
4143 p = prev_ptr; | |
835 | 4144 cap_col -= (int)(prev_ptr - line); |
625 | 4145 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4146 nochange); | |
348 | 4147 word_end = v + len; |
301 | 4148 |
4149 /* In Insert mode only highlight a word that | |
4150 * doesn't touch the cursor. */ | |
534 | 4151 if (spell_hlf != HLF_COUNT |
301 | 4152 && (State & INSERT) != 0 |
4153 && wp->w_cursor.lnum == lnum | |
4154 && wp->w_cursor.col >= | |
4155 (colnr_T)(prev_ptr - line) | |
4156 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4157 { |
534 | 4158 spell_hlf = HLF_COUNT; |
301 | 4159 spell_redraw_lnum = lnum; |
221 | 4160 } |
348 | 4161 |
534 | 4162 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4163 && (p - nextline) + len > nextline_idx) |
4164 { | |
4165 /* Remember that the good word continues at the | |
4166 * start of the next line. */ | |
4167 checked_lnum = lnum + 1; | |
835 | 4168 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4169 } |
386 | 4170 |
534 | 4171 /* Turn index into actual attributes. */ |
4172 if (spell_hlf != HLF_COUNT) | |
4173 spell_attr = highlight_attr[spell_hlf]; | |
4174 | |
386 | 4175 if (cap_col > 0) |
4176 { | |
4177 if (p != prev_ptr | |
4178 && (p - nextline) + cap_col >= nextline_idx) | |
4179 { | |
4180 /* Remember that the word in the next line | |
4181 * must start with a capital. */ | |
4182 capcol_lnum = lnum + 1; | |
835 | 4183 cap_col = (int)((p - nextline) + cap_col |
4184 - nextline_idx); | |
386 | 4185 } |
4186 else | |
4187 /* Compute the actual column. */ | |
835 | 4188 cap_col += (int)(prev_ptr - line); |
386 | 4189 } |
221 | 4190 } |
4191 } | |
4192 if (spell_attr != 0) | |
348 | 4193 { |
674 | 4194 if (!attr_pri) |
348 | 4195 char_attr = hl_combine_attr(char_attr, spell_attr); |
4196 else | |
4197 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4198 } | |
7 | 4199 #endif |
4200 #ifdef FEAT_LINEBREAK | |
4201 /* | |
221 | 4202 * Found last space before word: check for line break. |
7 | 4203 */ |
4204 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4205 && !wp->w_p_list) |
7 | 4206 { |
4207 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4208 # ifdef FEAT_MBYTE | |
4209 has_mbyte ? mb_l : | |
4210 # endif | |
4211 1), (colnr_T)vcol, NULL) - 1; | |
4212 c_extra = ' '; | |
4213 if (vim_iswhite(c)) | |
4214 c = ' '; | |
4215 } | |
4216 #endif | |
4217 | |
4218 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4219 { | |
4220 c = lcs_trail; | |
674 | 4221 if (!attr_pri) |
7 | 4222 { |
4223 n_attr = 1; | |
4224 extra_attr = hl_attr(HLF_8); | |
4225 saved_attr2 = char_attr; /* save current attr */ | |
4226 } | |
4227 #ifdef FEAT_MBYTE | |
4228 mb_c = c; | |
4229 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4230 { | |
4231 mb_utf8 = TRUE; | |
714 | 4232 u8cc[0] = 0; |
819 | 4233 c = 0xc0; |
7 | 4234 } |
4235 else | |
4236 mb_utf8 = FALSE; | |
4237 #endif | |
4238 } | |
4239 } | |
4240 | |
4241 /* | |
4242 * Handling of non-printable characters. | |
4243 */ | |
819 | 4244 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4245 { |
4246 /* | |
4247 * when getting a character from the file, we may have to | |
4248 * turn it into something else on the way to putting it | |
4249 * into "ScreenLines". | |
4250 */ | |
4251 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4252 { | |
4253 /* tab amount depends on current column */ | |
4254 n_extra = (int)wp->w_buffer->b_p_ts | |
4255 - vcol % (int)wp->w_buffer->b_p_ts - 1; | |
4256 #ifdef FEAT_MBYTE | |
4257 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4258 #endif | |
4259 if (wp->w_p_list) | |
4260 { | |
4261 c = lcs_tab1; | |
4262 c_extra = lcs_tab2; | |
4263 n_attr = n_extra + 1; | |
4264 extra_attr = hl_attr(HLF_8); | |
4265 saved_attr2 = char_attr; /* save current attr */ | |
4266 #ifdef FEAT_MBYTE | |
4267 mb_c = c; | |
4268 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4269 { | |
4270 mb_utf8 = TRUE; | |
714 | 4271 u8cc[0] = 0; |
819 | 4272 c = 0xc0; |
7 | 4273 } |
4274 #endif | |
4275 } | |
4276 else | |
4277 { | |
4278 c_extra = ' '; | |
4279 c = ' '; | |
4280 } | |
4281 } | |
36 | 4282 else if (c == NUL |
4283 && ((wp->w_p_list && lcs_eol > 0) | |
4284 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4285 && tocol > vcol | |
39 | 4286 #ifdef FEAT_VISUAL |
36 | 4287 && VIsual_mode != Ctrl_V |
39 | 4288 #endif |
36 | 4289 && ( |
4290 # ifdef FEAT_RIGHTLEFT | |
4291 wp->w_p_rl ? (col >= 0) : | |
4292 # endif | |
4293 (col < W_WIDTH(wp))) | |
4294 && !(noinvcur | |
1850 | 4295 && lnum == wp->w_cursor.lnum |
36 | 4296 && (colnr_T)vcol == wp->w_virtcol))) |
4297 && lcs_eol_one >= 0) | |
7 | 4298 { |
36 | 4299 /* Display a '$' after the line or highlight an extra |
4300 * character if the line break is included. */ | |
7 | 4301 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4302 /* For a diff line the highlighting continues after the | |
4303 * "$". */ | |
4304 if ( | |
4305 # ifdef FEAT_DIFF | |
534 | 4306 diff_hlf == (hlf_T)0 |
7 | 4307 # ifdef LINE_ATTR |
4308 && | |
4309 # endif | |
4310 # endif | |
4311 # ifdef LINE_ATTR | |
4312 line_attr == 0 | |
4313 # endif | |
4314 ) | |
4315 #endif | |
4316 { | |
4317 #ifdef FEAT_VIRTUALEDIT | |
4318 /* In virtualedit, visual selections may extend | |
4319 * beyond end of line. */ | |
4320 if (area_highlighting && virtual_active() | |
4321 && tocol != MAXCOL && vcol < tocol) | |
4322 n_extra = 0; | |
4323 else | |
4324 #endif | |
4325 { | |
4326 p_extra = at_end_str; | |
4327 n_extra = 1; | |
4328 c_extra = NUL; | |
4329 } | |
4330 } | |
36 | 4331 if (wp->w_p_list) |
4332 c = lcs_eol; | |
4333 else | |
4334 c = ' '; | |
7 | 4335 lcs_eol_one = -1; |
4336 --ptr; /* put it back at the NUL */ | |
674 | 4337 if (!attr_pri) |
7 | 4338 { |
4339 extra_attr = hl_attr(HLF_AT); | |
4340 n_attr = 1; | |
4341 } | |
4342 #ifdef FEAT_MBYTE | |
4343 mb_c = c; | |
4344 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4345 { | |
4346 mb_utf8 = TRUE; | |
714 | 4347 u8cc[0] = 0; |
819 | 4348 c = 0xc0; |
7 | 4349 } |
4350 else | |
4351 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4352 #endif | |
4353 } | |
4354 else if (c != NUL) | |
4355 { | |
4356 p_extra = transchar(c); | |
4357 #ifdef FEAT_RIGHTLEFT | |
4358 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4359 rl_mirror(p_extra); /* reverse "<12>" */ | |
4360 #endif | |
4361 n_extra = byte2cells(c) - 1; | |
4362 c_extra = NUL; | |
4363 c = *p_extra++; | |
674 | 4364 if (!attr_pri) |
7 | 4365 { |
4366 n_attr = n_extra + 1; | |
4367 extra_attr = hl_attr(HLF_8); | |
4368 saved_attr2 = char_attr; /* save current attr */ | |
4369 } | |
4370 #ifdef FEAT_MBYTE | |
4371 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4372 #endif | |
4373 } | |
4374 #ifdef FEAT_VIRTUALEDIT | |
4375 else if (VIsual_active | |
4376 && (VIsual_mode == Ctrl_V | |
4377 || VIsual_mode == 'v') | |
4378 && virtual_active() | |
4379 && tocol != MAXCOL | |
4380 && vcol < tocol | |
4381 && ( | |
4382 # ifdef FEAT_RIGHTLEFT | |
4383 wp->w_p_rl ? (col >= 0) : | |
4384 # endif | |
4385 (col < W_WIDTH(wp)))) | |
4386 { | |
4387 c = ' '; | |
4388 --ptr; /* put it back at the NUL */ | |
4389 } | |
4390 #endif | |
910 | 4391 #if defined(LINE_ATTR) |
7 | 4392 else if (( |
4393 # ifdef FEAT_DIFF | |
910 | 4394 diff_hlf != (hlf_T)0 || |
7 | 4395 # endif |
4396 line_attr != 0 | |
4397 ) && ( | |
4398 # ifdef FEAT_RIGHTLEFT | |
4399 wp->w_p_rl ? (col >= 0) : | |
4400 # endif | |
4401 (col < W_WIDTH(wp)))) | |
4402 { | |
4403 /* Highlight until the right side of the window */ | |
4404 c = ' '; | |
4405 --ptr; /* put it back at the NUL */ | |
867 | 4406 |
4407 /* Remember we do the char for line highlighting. */ | |
4408 ++did_line_attr; | |
4409 | |
4410 /* don't do search HL for the rest of the line */ | |
4411 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4412 char_attr = line_attr; | |
7 | 4413 # ifdef FEAT_DIFF |
4414 if (diff_hlf == HLF_TXD) | |
4415 { | |
4416 diff_hlf = HLF_CHD; | |
4417 if (attr == 0 || char_attr != attr) | |
4418 char_attr = hl_attr(diff_hlf); | |
4419 } | |
4420 # endif | |
4421 } | |
4422 #endif | |
4423 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4424 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4425 #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
|
4426 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
|
4427 && (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
|
4428 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
|
4429 && (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
|
4430 && !(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
|
4431 && 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
|
4432 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4433 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
|
4434 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
|
4435 && (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
|
4436 && 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
|
4437 { |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4438 /* 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
|
4439 * character. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4440 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4441 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4442 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4443 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4444 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4445 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4446 |
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
|
4447 prev_syntax_id = syntax_seqnr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4448 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4449 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4450 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4451 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4452 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
|
4453 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4454 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4455 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4456 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4457 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4458 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4459 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4460 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4461 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4462 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4463 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4464 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4465 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4466 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4467 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4468 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4469 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4470 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4471 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4472 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4473 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4474 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4475 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4476 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4477 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4478 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4479 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4480 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4481 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4482 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4483 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4484 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
|
4485 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4486 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4487 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4488 { |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4489 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
|
4490 is_concealing = FALSE; |
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 #endif /* FEAT_CONCEAL */ |
7 | 4493 } |
4494 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4495 #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
|
4496 /* 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
|
4497 * 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
|
4498 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
|
4499 && 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
|
4500 && 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
|
4501 && (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
|
4502 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4503 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
|
4504 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
|
4505 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
|
4506 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4507 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4508 |
7 | 4509 /* Don't override visual selection highlighting. */ |
4510 if (n_attr > 0 | |
4511 && draw_state == WL_LINE | |
674 | 4512 && !attr_pri) |
7 | 4513 char_attr = extra_attr; |
4514 | |
42 | 4515 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4516 /* XIM don't send preedit_start and preedit_end, but they send |
4517 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4518 * im_is_preediting() here. */ | |
4519 if (xic != NULL | |
1850 | 4520 && lnum == wp->w_cursor.lnum |
7 | 4521 && (State & INSERT) |
4522 && !p_imdisable | |
4523 && im_is_preediting() | |
4524 && draw_state == WL_LINE) | |
4525 { | |
4526 colnr_T tcol; | |
4527 | |
4528 if (preedit_end_col == MAXCOL) | |
1850 | 4529 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4530 else |
4531 tcol = preedit_end_col; | |
4532 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4533 { | |
4534 if (feedback_old_attr < 0) | |
4535 { | |
4536 feedback_col = 0; | |
4537 feedback_old_attr = char_attr; | |
4538 } | |
4539 char_attr = im_get_feedback_attr(feedback_col); | |
4540 if (char_attr < 0) | |
4541 char_attr = feedback_old_attr; | |
4542 feedback_col++; | |
4543 } | |
4544 else if (feedback_old_attr >= 0) | |
4545 { | |
4546 char_attr = feedback_old_attr; | |
4547 feedback_old_attr = -1; | |
4548 feedback_col = 0; | |
4549 } | |
4550 } | |
4551 #endif | |
4552 /* | |
4553 * Handle the case where we are in column 0 but not on the first | |
4554 * character of the line and the user wants us to show us a | |
4555 * special character (via 'listchars' option "precedes:<char>". | |
4556 */ | |
4557 if (lcs_prec_todo != NUL | |
4558 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4559 #ifdef FEAT_DIFF | |
4560 && filler_todo <= 0 | |
4561 #endif | |
4562 && draw_state > WL_NR | |
4563 && c != NUL) | |
4564 { | |
4565 c = lcs_prec; | |
4566 lcs_prec_todo = NUL; | |
4567 #ifdef FEAT_MBYTE | |
4568 mb_c = c; | |
4569 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4570 { | |
4571 mb_utf8 = TRUE; | |
714 | 4572 u8cc[0] = 0; |
819 | 4573 c = 0xc0; |
7 | 4574 } |
4575 else | |
4576 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4577 #endif | |
674 | 4578 if (!attr_pri) |
7 | 4579 { |
4580 saved_attr3 = char_attr; /* save current attr */ | |
4581 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4582 n_attr3 = 1; | |
4583 } | |
4584 } | |
4585 | |
4586 /* | |
867 | 4587 * At end of the text line or just after the last character. |
7 | 4588 */ |
867 | 4589 if (c == NUL |
910 | 4590 #if defined(LINE_ATTR) |
867 | 4591 || did_line_attr == 1 |
4592 #endif | |
4593 ) | |
4594 { | |
4595 #ifdef FEAT_SEARCH_EXTRA | |
4596 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4597 |
4598 /* we're not really at that column when skipping some text */ | |
1439 | 4599 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4600 ++prevcol; |
867 | 4601 #endif |
4602 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4603 /* Invert at least one char, used for Visual and empty line or |
7 | 4604 * highlight match at end of line. If it's beyond the last |
4605 * char on the screen, just overwrite that one (tricky!) Not | |
4606 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4607 #ifdef FEAT_SEARCH_EXTRA |
4608 prevcol_hl_flag = FALSE; | |
4609 if (prevcol == (long)search_hl.startcol) | |
4610 prevcol_hl_flag = TRUE; | |
4611 else | |
4612 { | |
4613 cur = wp->w_match_head; | |
4614 while (cur != NULL) | |
4615 { | |
4616 if (prevcol == (long)cur->hl.startcol) | |
4617 { | |
4618 prevcol_hl_flag = TRUE; | |
4619 break; | |
4620 } | |
4621 cur = cur->next; | |
4622 } | |
4623 } | |
4624 #endif | |
7 | 4625 if (lcs_eol == lcs_eol_one |
1850 | 4626 && ((area_attr != 0 && vcol == fromcol |
4627 #ifdef FEAT_VISUAL | |
4628 && (VIsual_mode != Ctrl_V | |
4629 || lnum == VIsual.lnum | |
4630 || lnum == curwin->w_cursor.lnum) | |
4631 #endif | |
4632 && c == NUL) | |
7 | 4633 #ifdef FEAT_SEARCH_EXTRA |
4634 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4635 || (prevcol_hl_flag == TRUE |
910 | 4636 # if defined(LINE_ATTR) |
867 | 4637 && did_line_attr <= 1 |
4638 # endif | |
4639 ) | |
7 | 4640 #endif |
4641 )) | |
4642 { | |
4643 int n = 0; | |
4644 | |
4645 #ifdef FEAT_RIGHTLEFT | |
4646 if (wp->w_p_rl) | |
4647 { | |
4648 if (col < 0) | |
4649 n = 1; | |
4650 } | |
4651 else | |
4652 #endif | |
4653 { | |
4654 if (col >= W_WIDTH(wp)) | |
4655 n = -1; | |
4656 } | |
4657 if (n != 0) | |
4658 { | |
4659 /* At the window boundary, highlight the last character | |
4660 * instead (better than nothing). */ | |
4661 off += n; | |
4662 col += n; | |
4663 } | |
4664 else | |
4665 { | |
4666 /* Add a blank character to highlight. */ | |
4667 ScreenLines[off] = ' '; | |
4668 #ifdef FEAT_MBYTE | |
4669 if (enc_utf8) | |
4670 ScreenLinesUC[off] = 0; | |
4671 #endif | |
4672 } | |
4673 #ifdef FEAT_SEARCH_EXTRA | |
4674 if (area_attr == 0) | |
4675 { | |
1326 | 4676 /* Use attributes from match with highest priority among |
4677 * 'search_hl' and the match list. */ | |
4678 char_attr = search_hl.attr; | |
4679 cur = wp->w_match_head; | |
4680 shl_flag = FALSE; | |
4681 while (cur != NULL || shl_flag == FALSE) | |
699 | 4682 { |
1326 | 4683 if (shl_flag == FALSE |
4684 && ((cur != NULL | |
4685 && cur->priority > SEARCH_HL_PRIORITY) | |
4686 || cur == NULL)) | |
699 | 4687 { |
1326 | 4688 shl = &search_hl; |
4689 shl_flag = TRUE; | |
699 | 4690 } |
1326 | 4691 else |
4692 shl = &cur->hl; | |
4693 if ((ptr - line) - 1 == (long)shl->startcol) | |
4694 char_attr = shl->attr; | |
4695 if (shl != &search_hl && cur != NULL) | |
4696 cur = cur->next; | |
699 | 4697 } |
7 | 4698 } |
4699 #endif | |
4700 ScreenAttrs[off] = char_attr; | |
4701 #ifdef FEAT_RIGHTLEFT | |
4702 if (wp->w_p_rl) | |
1437 | 4703 { |
7 | 4704 --col; |
1437 | 4705 --off; |
4706 } | |
7 | 4707 else |
4708 #endif | |
1437 | 4709 { |
7 | 4710 ++col; |
1437 | 4711 ++off; |
4712 } | |
743 | 4713 ++vcol; |
1437 | 4714 #ifdef FEAT_SYN_HL |
4715 eol_hl_off = 1; | |
4716 #endif | |
743 | 4717 } |
867 | 4718 } |
4719 | |
4720 /* | |
4721 * At end of the text line. | |
4722 */ | |
4723 if (c == NUL) | |
4724 { | |
743 | 4725 #ifdef FEAT_SYN_HL |
1850 | 4726 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4727 && lnum == wp->w_cursor.lnum) | |
1437 | 4728 { |
4729 /* highlight last char after line */ | |
4730 --col; | |
4731 --off; | |
4732 --vcol; | |
4733 } | |
4734 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4735 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4736 if (wp->w_p_wrap) |
4737 v = wp->w_skipcol; | |
4738 else | |
4739 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4740 |
820 | 4741 /* check if line ends before left margin */ |
4742 if (vcol < v + col - win_col_off(wp)) | |
4743 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
|
4744 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4745 /* 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
|
4746 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4747 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4748 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4749 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4750 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4751 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4752 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
|
4753 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4754 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4755 && (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
|
4756 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4757 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
|
4758 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4759 || draw_color_col) |
743 | 4760 # ifdef FEAT_RIGHTLEFT |
4761 && !wp->w_p_rl | |
4762 # endif | |
4763 ) | |
4764 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4765 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4766 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4767 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4768 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4769 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4770 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4771 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4772 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
|
4773 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4774 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4775 |
743 | 4776 while (col < W_WIDTH(wp)) |
4777 { | |
4778 ScreenLines[off] = ' '; | |
4779 #ifdef FEAT_MBYTE | |
4780 if (enc_utf8) | |
4781 ScreenLinesUC[off] = 0; | |
4782 #endif | |
4783 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4784 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4785 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
|
4786 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4787 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4788 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
|
4789 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
|
4790 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
|
4791 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4792 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4793 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4794 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4795 if (VCOL_HLC >= rightmost_vcol) |
743 | 4796 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4797 |
743 | 4798 ++vcol; |
4799 } | |
4800 } | |
4801 #endif | |
7 | 4802 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4803 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
|
4804 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4805 row++; |
4806 | |
4807 /* | |
4808 * Update w_cline_height and w_cline_folded if the cursor line was | |
4809 * updated (saves a call to plines() later). | |
4810 */ | |
4811 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4812 { | |
4813 curwin->w_cline_row = startrow; | |
4814 curwin->w_cline_height = row - startrow; | |
4815 #ifdef FEAT_FOLDING | |
4816 curwin->w_cline_folded = FALSE; | |
4817 #endif | |
4818 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4819 } | |
4820 | |
4821 break; | |
4822 } | |
4823 | |
4824 /* line continues beyond line end */ | |
4825 if (lcs_ext | |
4826 && !wp->w_p_wrap | |
4827 #ifdef FEAT_DIFF | |
4828 && filler_todo <= 0 | |
4829 #endif | |
4830 && ( | |
4831 #ifdef FEAT_RIGHTLEFT | |
4832 wp->w_p_rl ? col == 0 : | |
4833 #endif | |
4834 col == W_WIDTH(wp) - 1) | |
4835 && (*ptr != NUL | |
1555 | 4836 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4837 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4838 { | |
4839 c = lcs_ext; | |
4840 char_attr = hl_attr(HLF_AT); | |
4841 #ifdef FEAT_MBYTE | |
4842 mb_c = c; | |
4843 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4844 { | |
4845 mb_utf8 = TRUE; | |
714 | 4846 u8cc[0] = 0; |
819 | 4847 c = 0xc0; |
7 | 4848 } |
4849 else | |
4850 mb_utf8 = FALSE; | |
4851 #endif | |
4852 } | |
4853 | |
743 | 4854 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4855 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4856 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4857 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
|
4858 |
743 | 4859 /* 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
|
4860 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4861 * 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
|
4862 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4863 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4864 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
|
4865 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4866 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
|
4867 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4868 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4869 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4870 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
|
4871 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4872 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
|
4873 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4874 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4875 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
|
4876 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4877 } |
743 | 4878 #endif |
4879 | |
7 | 4880 /* |
4881 * Store character to be displayed. | |
4882 * Skip characters that are left of the screen for 'nowrap'. | |
4883 */ | |
4884 vcol_prev = vcol; | |
4885 if (draw_state < WL_LINE || n_skip <= 0) | |
4886 { | |
4887 /* | |
4888 * Store the character. | |
4889 */ | |
4890 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4891 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4892 { | |
4893 /* A double-wide character is: put first halve in left cell. */ | |
4894 --off; | |
4895 --col; | |
4896 } | |
4897 #endif | |
4898 ScreenLines[off] = c; | |
4899 #ifdef FEAT_MBYTE | |
4900 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4901 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4902 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4903 ScreenLines[off] = 0x8e; |
7 | 4904 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4905 } |
7 | 4906 else if (enc_utf8) |
4907 { | |
4908 if (mb_utf8) | |
4909 { | |
1326 | 4910 int i; |
4911 | |
7 | 4912 ScreenLinesUC[off] = mb_c; |
819 | 4913 if ((c & 0xff) == 0) |
4914 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4915 for (i = 0; i < Screen_mco; ++i) |
4916 { | |
4917 ScreenLinesC[i][off] = u8cc[i]; | |
4918 if (u8cc[i] == 0) | |
4919 break; | |
4920 } | |
7 | 4921 } |
4922 else | |
4923 ScreenLinesUC[off] = 0; | |
4924 } | |
4925 if (multi_attr) | |
4926 { | |
4927 ScreenAttrs[off] = multi_attr; | |
4928 multi_attr = 0; | |
4929 } | |
4930 else | |
4931 #endif | |
4932 ScreenAttrs[off] = char_attr; | |
4933 | |
4934 #ifdef FEAT_MBYTE | |
4935 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4936 { | |
4937 /* Need to fill two screen columns. */ | |
4938 ++off; | |
4939 ++col; | |
4940 if (enc_utf8) | |
4941 /* UTF-8: Put a 0 in the second screen char. */ | |
4942 ScreenLines[off] = 0; | |
4943 else | |
4944 /* DBCS: Put second byte in the second screen char. */ | |
4945 ScreenLines[off] = mb_c & 0xff; | |
4946 ++vcol; | |
4947 /* When "tocol" is halfway a character, set it to the end of | |
4948 * the character, otherwise highlighting won't stop. */ | |
4949 if (tocol == vcol) | |
4950 ++tocol; | |
4951 #ifdef FEAT_RIGHTLEFT | |
4952 if (wp->w_p_rl) | |
4953 { | |
4954 /* now it's time to backup one cell */ | |
4955 --off; | |
4956 --col; | |
4957 } | |
4958 #endif | |
4959 } | |
4960 #endif | |
4961 #ifdef FEAT_RIGHTLEFT | |
4962 if (wp->w_p_rl) | |
4963 { | |
4964 --off; | |
4965 --col; | |
4966 } | |
4967 else | |
4968 #endif | |
4969 { | |
4970 ++off; | |
4971 ++col; | |
4972 } | |
4973 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4974 #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
|
4975 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
|
4976 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4977 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4978 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4979 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4980 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4981 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4982 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4983 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4984 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4985 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4986 * 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
|
4987 * 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
|
4988 * 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
|
4989 * 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
|
4990 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4991 * 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
|
4992 * 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
|
4993 * 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
|
4994 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4995 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4996 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4997 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4998 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4999 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5000 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5001 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5002 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5003 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5004 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5005 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5006 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5007 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5008 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5009 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5010 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5011 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5012 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5013 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5014 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5015 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5016 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5017 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
|
5018 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5019 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5020 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5021 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5022 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5023 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5024 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5025 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5026 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5027 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5028 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5029 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5030 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5031 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5032 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5033 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5034 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5035 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5036 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5037 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5038 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5039 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5040 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5041 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5043 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5044 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5045 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5046 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5047 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5048 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5049 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5050 if (n_extra > 0) |
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 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5053 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5054 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5055 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5056 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5057 |
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 #endif /* FEAT_CONCEAL */ |
7 | 5060 else |
5061 --n_skip; | |
5062 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5063 /* 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
|
5064 * column. */ |
1849 | 5065 if (draw_state > WL_NR |
7 | 5066 #ifdef FEAT_DIFF |
5067 && filler_todo <= 0 | |
5068 #endif | |
5069 ) | |
5070 ++vcol; | |
5071 | |
743 | 5072 #ifdef FEAT_SYN_HL |
5073 if (vcol_save_attr >= 0) | |
5074 char_attr = vcol_save_attr; | |
5075 #endif | |
5076 | |
7 | 5077 /* restore attributes after "predeces" in 'listchars' */ |
5078 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5079 char_attr = saved_attr3; | |
5080 | |
5081 /* restore attributes after last 'listchars' or 'number' char */ | |
5082 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5083 char_attr = saved_attr2; | |
5084 | |
5085 /* | |
5086 * At end of screen line and there is more to come: Display the line | |
1378 | 5087 * so far. If there is no more to display it is caught above. |
7 | 5088 */ |
5089 if (( | |
5090 #ifdef FEAT_RIGHTLEFT | |
5091 wp->w_p_rl ? (col < 0) : | |
5092 #endif | |
5093 (col >= W_WIDTH(wp))) | |
5094 && (*ptr != NUL | |
5095 #ifdef FEAT_DIFF | |
5096 || filler_todo > 0 | |
5097 #endif | |
5098 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) | |
5099 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) | |
5100 ) | |
5101 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5102 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5103 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
|
5104 (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
|
5105 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5106 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5107 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
|
5108 (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
|
5109 #endif |
7 | 5110 ++row; |
5111 ++screen_row; | |
5112 | |
5113 /* When not wrapping and finished diff lines, or when displayed | |
5114 * '$' and highlighting until last column, break here. */ | |
5115 if ((!wp->w_p_wrap | |
5116 #ifdef FEAT_DIFF | |
5117 && filler_todo <= 0 | |
5118 #endif | |
5119 ) || lcs_eol_one == -1) | |
5120 break; | |
5121 | |
5122 /* When the window is too narrow draw all "@" lines. */ | |
5123 if (draw_state != WL_LINE | |
5124 #ifdef FEAT_DIFF | |
5125 && filler_todo <= 0 | |
5126 #endif | |
5127 ) | |
5128 { | |
5129 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5130 #ifdef FEAT_VERTSPLIT | |
5131 draw_vsep_win(wp, row); | |
5132 #endif | |
5133 row = endrow; | |
5134 } | |
5135 | |
5136 /* When line got too long for screen break here. */ | |
5137 if (row == endrow) | |
5138 { | |
5139 ++row; | |
5140 break; | |
5141 } | |
5142 | |
5143 if (screen_cur_row == screen_row - 1 | |
5144 #ifdef FEAT_DIFF | |
5145 && filler_todo <= 0 | |
5146 #endif | |
5147 && W_WIDTH(wp) == Columns) | |
5148 { | |
5149 /* Remember that the line wraps, used for modeless copy. */ | |
5150 LineWraps[screen_row - 1] = TRUE; | |
5151 | |
5152 /* | |
5153 * Special trick to make copy/paste of wrapped lines work with | |
5154 * xterm/screen: write an extra character beyond the end of | |
5155 * the line. This will work with all terminal types | |
5156 * (regardless of the xn,am settings). | |
5157 * Only do this on a fast tty. | |
5158 * Only do this if the cursor is on the current line | |
5159 * (something has been written in it). | |
5160 * Don't do this for the GUI. | |
5161 * Don't do this for double-width characters. | |
5162 * Don't do this for a window not at the right screen border. | |
5163 */ | |
5164 if (p_tf | |
5165 #ifdef FEAT_GUI | |
5166 && !gui.in_use | |
5167 #endif | |
5168 #ifdef FEAT_MBYTE | |
5169 && !(has_mbyte | |
1378 | 5170 && ((*mb_off2cells)(LineOffset[screen_row], |
5171 LineOffset[screen_row] + screen_Columns) | |
5172 == 2 | |
7 | 5173 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5174 + (int)Columns - 2, |
5175 LineOffset[screen_row] + screen_Columns) | |
5176 == 2)) | |
7 | 5177 #endif |
5178 ) | |
5179 { | |
5180 /* First make sure we are at the end of the screen line, | |
5181 * then output the same character again to let the | |
5182 * terminal know about the wrap. If the terminal doesn't | |
5183 * auto-wrap, we overwrite the character. */ | |
5184 if (screen_cur_col != W_WIDTH(wp)) | |
5185 screen_char(LineOffset[screen_row - 1] | |
5186 + (unsigned)Columns - 1, | |
5187 screen_row - 1, (int)(Columns - 1)); | |
5188 | |
5189 #ifdef FEAT_MBYTE | |
5190 /* When there is a multi-byte character, just output a | |
5191 * space to keep it simple. */ | |
148 | 5192 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5193 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5194 out_char(' '); |
5195 else | |
5196 #endif | |
5197 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5198 + (Columns - 1)]); | |
5199 /* force a redraw of the first char on the next line */ | |
5200 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5201 screen_start(); /* don't know where cursor is now */ | |
5202 } | |
5203 } | |
5204 | |
5205 col = 0; | |
5206 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5207 #ifdef FEAT_RIGHTLEFT | |
5208 if (wp->w_p_rl) | |
5209 { | |
5210 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5211 off += col; | |
5212 } | |
5213 #endif | |
5214 | |
5215 /* reset the drawing state for the start of a wrapped line */ | |
5216 draw_state = WL_START; | |
5217 saved_n_extra = n_extra; | |
5218 saved_p_extra = p_extra; | |
5219 saved_c_extra = c_extra; | |
5220 saved_char_attr = char_attr; | |
5221 n_extra = 0; | |
5222 lcs_prec_todo = lcs_prec; | |
5223 #ifdef FEAT_LINEBREAK | |
5224 # ifdef FEAT_DIFF | |
5225 if (filler_todo <= 0) | |
5226 # endif | |
5227 need_showbreak = TRUE; | |
5228 #endif | |
5229 #ifdef FEAT_DIFF | |
5230 --filler_todo; | |
5231 /* When the filler lines are actually below the last line of the | |
5232 * file, don't draw the line itself, break here. */ | |
5233 if (filler_todo == 0 && wp->w_botfill) | |
5234 break; | |
5235 #endif | |
5236 } | |
5237 | |
5238 } /* for every character in the line */ | |
5239 | |
743 | 5240 #ifdef FEAT_SPELL |
386 | 5241 /* After an empty line check first word for capital. */ |
5242 if (*skipwhite(line) == NUL) | |
5243 { | |
5244 capcol_lnum = lnum + 1; | |
5245 cap_col = 0; | |
5246 } | |
5247 #endif | |
5248 | |
7 | 5249 return row; |
5250 } | |
5251 | |
714 | 5252 #ifdef FEAT_MBYTE |
5253 static int comp_char_differs __ARGS((int, int)); | |
5254 | |
5255 /* | |
5256 * 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
|
5257 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5258 */ |
5259 static int | |
5260 comp_char_differs(off_from, off_to) | |
5261 int off_from; | |
5262 int off_to; | |
5263 { | |
5264 int i; | |
5265 | |
5266 for (i = 0; i < Screen_mco; ++i) | |
5267 { | |
5268 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5269 return TRUE; | |
5270 if (ScreenLinesC[i][off_from] == 0) | |
5271 break; | |
5272 } | |
5273 return FALSE; | |
5274 } | |
5275 #endif | |
5276 | |
7 | 5277 /* |
5278 * Check whether the given character needs redrawing: | |
5279 * - the (first byte of the) character is different | |
5280 * - the attributes are different | |
5281 * - the character is multi-byte and the next byte is different | |
1616 | 5282 * - the character is two cells wide and the second cell differs. |
7 | 5283 */ |
5284 static int | |
5285 char_needs_redraw(off_from, off_to, cols) | |
5286 int off_from; | |
5287 int off_to; | |
5288 int cols; | |
5289 { | |
5290 if (cols > 0 | |
5291 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5292 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5293 | |
5294 #ifdef FEAT_MBYTE | |
5295 || (enc_dbcs != 0 | |
5296 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5297 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5298 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5299 : (cols > 1 && ScreenLines[off_from + 1] | |
5300 != ScreenLines[off_to + 1]))) | |
5301 || (enc_utf8 | |
5302 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5303 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5304 && comp_char_differs(off_from, off_to)) |
5305 || (cols > 1 && ScreenLines[off_from + 1] | |
5306 != ScreenLines[off_to + 1]))) | |
7 | 5307 #endif |
5308 )) | |
5309 return TRUE; | |
5310 return FALSE; | |
5311 } | |
5312 | |
5313 /* | |
5314 * Move one "cooked" screen line to the screen, but only the characters that | |
5315 * have actually changed. Handle insert/delete character. | |
5316 * "coloff" gives the first column on the screen for this line. | |
5317 * "endcol" gives the columns where valid characters are. | |
5318 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5319 * needs to be cleared, negative otherwise. | |
5320 * "rlflag" is TRUE in a rightleft window: | |
5321 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5322 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5323 */ | |
5324 static void | |
5325 screen_line(row, coloff, endcol, clear_width | |
5326 #ifdef FEAT_RIGHTLEFT | |
5327 , rlflag | |
5328 #endif | |
5329 ) | |
5330 int row; | |
5331 int coloff; | |
5332 int endcol; | |
5333 int clear_width; | |
5334 #ifdef FEAT_RIGHTLEFT | |
5335 int rlflag; | |
5336 #endif | |
5337 { | |
5338 unsigned off_from; | |
5339 unsigned off_to; | |
1378 | 5340 #ifdef FEAT_MBYTE |
5341 unsigned max_off_from; | |
5342 unsigned max_off_to; | |
5343 #endif | |
7 | 5344 int col = 0; |
5345 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5346 int hl; | |
5347 #endif | |
5348 int force = FALSE; /* force update rest of the line */ | |
5349 int redraw_this /* bool: does character need redraw? */ | |
5350 #ifdef FEAT_GUI | |
5351 = TRUE /* For GUI when while-loop empty */ | |
5352 #endif | |
5353 ; | |
5354 int redraw_next; /* redraw_this for next character */ | |
5355 #ifdef FEAT_MBYTE | |
5356 int clear_next = FALSE; | |
5357 int char_cells; /* 1: normal char */ | |
5358 /* 2: occupies two display cells */ | |
5359 # define CHAR_CELLS char_cells | |
5360 #else | |
5361 # define CHAR_CELLS 1 | |
5362 #endif | |
5363 | |
5364 # ifdef FEAT_CLIPBOARD | |
5365 clip_may_clear_selection(row, row); | |
5366 # endif | |
5367 | |
5368 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5369 off_to = LineOffset[row] + coloff; | |
1378 | 5370 #ifdef FEAT_MBYTE |
5371 max_off_from = off_from + screen_Columns; | |
5372 max_off_to = LineOffset[row] + screen_Columns; | |
5373 #endif | |
7 | 5374 |
5375 #ifdef FEAT_RIGHTLEFT | |
5376 if (rlflag) | |
5377 { | |
5378 /* Clear rest first, because it's left of the text. */ | |
5379 if (clear_width > 0) | |
5380 { | |
5381 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5382 && ScreenAttrs[off_to] == 0 | |
5383 # ifdef FEAT_MBYTE | |
5384 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5385 # endif | |
5386 ) | |
5387 { | |
5388 ++off_to; | |
5389 ++col; | |
5390 } | |
5391 if (col <= endcol) | |
5392 screen_fill(row, row + 1, col + coloff, | |
5393 endcol + coloff + 1, ' ', ' ', 0); | |
5394 } | |
5395 col = endcol + 1; | |
5396 off_to = LineOffset[row] + col + coloff; | |
5397 off_from += col; | |
5398 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5399 } | |
5400 #endif /* FEAT_RIGHTLEFT */ | |
5401 | |
5402 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5403 | |
5404 while (col < endcol) | |
5405 { | |
5406 #ifdef FEAT_MBYTE | |
5407 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5408 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5409 else |
5410 char_cells = 1; | |
5411 #endif | |
5412 | |
5413 redraw_this = redraw_next; | |
5414 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5415 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5416 | |
5417 #ifdef FEAT_GUI | |
5418 /* If the next character was bold, then redraw the current character to | |
5419 * remove any pixels that might have spilt over into us. This only | |
5420 * happens in the GUI. | |
5421 */ | |
5422 if (redraw_next && gui.in_use) | |
5423 { | |
5424 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5425 if (hl > HL_ALL) |
5426 hl = syn_attr2attr(hl); | |
5427 if (hl & HL_BOLD) | |
7 | 5428 redraw_this = TRUE; |
5429 } | |
5430 #endif | |
5431 | |
5432 if (redraw_this) | |
5433 { | |
5434 /* | |
5435 * Special handling when 'xs' termcap flag set (hpterm): | |
5436 * Attributes for characters are stored at the position where the | |
5437 * cursor is when writing the highlighting code. The | |
5438 * start-highlighting code must be written with the cursor on the | |
5439 * first highlighted character. The stop-highlighting code must | |
5440 * be written with the cursor just after the last highlighted | |
5441 * character. | |
5442 * Overwriting a character doesn't remove it's highlighting. Need | |
5443 * to clear the rest of the line, and force redrawing it | |
5444 * completely. | |
5445 */ | |
5446 if ( p_wiv | |
5447 && !force | |
5448 #ifdef FEAT_GUI | |
5449 && !gui.in_use | |
5450 #endif | |
5451 && ScreenAttrs[off_to] != 0 | |
5452 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5453 { | |
5454 /* | |
5455 * Need to remove highlighting attributes here. | |
5456 */ | |
5457 windgoto(row, col + coloff); | |
5458 out_str(T_CE); /* clear rest of this screen line */ | |
5459 screen_start(); /* don't know where cursor is now */ | |
5460 force = TRUE; /* force redraw of rest of the line */ | |
5461 redraw_next = TRUE; /* or else next char would miss out */ | |
5462 | |
5463 /* | |
5464 * If the previous character was highlighted, need to stop | |
5465 * highlighting at this character. | |
5466 */ | |
5467 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5468 { | |
5469 screen_attr = ScreenAttrs[off_to - 1]; | |
5470 term_windgoto(row, col + coloff); | |
5471 screen_stop_highlight(); | |
5472 } | |
5473 else | |
5474 screen_attr = 0; /* highlighting has stopped */ | |
5475 } | |
5476 #ifdef FEAT_MBYTE | |
5477 if (enc_dbcs != 0) | |
5478 { | |
5479 /* Check if overwriting a double-byte with a single-byte or | |
5480 * the other way around requires another character to be | |
5481 * redrawn. For UTF-8 this isn't needed, because comparing | |
5482 * ScreenLinesUC[] is sufficient. */ | |
5483 if (char_cells == 1 | |
5484 && col + 1 < endcol | |
1378 | 5485 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5486 { |
5487 /* Writing a single-cell character over a double-cell | |
5488 * character: need to redraw the next cell. */ | |
5489 ScreenLines[off_to + 1] = 0; | |
5490 redraw_next = TRUE; | |
5491 } | |
5492 else if (char_cells == 2 | |
5493 && col + 2 < endcol | |
1378 | 5494 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5495 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5496 { |
5497 /* Writing the second half of a double-cell character over | |
5498 * a double-cell character: need to redraw the second | |
5499 * cell. */ | |
5500 ScreenLines[off_to + 2] = 0; | |
5501 redraw_next = TRUE; | |
5502 } | |
5503 | |
5504 if (enc_dbcs == DBCS_JPNU) | |
5505 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5506 } | |
5507 /* When writing a single-width character over a double-width | |
5508 * character and at the end of the redrawn text, need to clear out | |
5509 * the right halve of the old character. | |
5510 * Also required when writing the right halve of a double-width | |
5511 * char over the left halve of an existing one. */ | |
5512 if (has_mbyte && col + char_cells == endcol | |
5513 && ((char_cells == 1 | |
1378 | 5514 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5515 || (char_cells == 2 |
1378 | 5516 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5517 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5518 clear_next = TRUE; |
5519 #endif | |
5520 | |
5521 ScreenLines[off_to] = ScreenLines[off_from]; | |
5522 #ifdef FEAT_MBYTE | |
5523 if (enc_utf8) | |
5524 { | |
5525 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5526 if (ScreenLinesUC[off_from] != 0) | |
5527 { | |
714 | 5528 int i; |
5529 | |
5530 for (i = 0; i < Screen_mco; ++i) | |
5531 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5532 } |
5533 } | |
5534 if (char_cells == 2) | |
5535 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5536 #endif | |
5537 | |
5538 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5539 /* The bold trick makes a single column of pixels appear in the |
5540 * next character. When a bold character is removed, the next | |
7 | 5541 * character should be redrawn too. This happens for our own GUI |
5542 * and for some xterms. */ | |
5543 if ( | |
5544 # ifdef FEAT_GUI | |
5545 gui.in_use | |
5546 # endif | |
5547 # if defined(FEAT_GUI) && defined(UNIX) | |
5548 || | |
5549 # endif | |
5550 # ifdef UNIX | |
5551 term_is_xterm | |
5552 # endif | |
5553 ) | |
5554 { | |
5555 hl = ScreenAttrs[off_to]; | |
743 | 5556 if (hl > HL_ALL) |
5557 hl = syn_attr2attr(hl); | |
5558 if (hl & HL_BOLD) | |
7 | 5559 redraw_next = TRUE; |
5560 } | |
5561 #endif | |
5562 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5563 #ifdef FEAT_MBYTE | |
819 | 5564 /* For simplicity set the attributes of second half of a |
5565 * double-wide character equal to the first half. */ | |
5566 if (char_cells == 2) | |
5567 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5568 | |
7 | 5569 if (enc_dbcs != 0 && char_cells == 2) |
5570 screen_char_2(off_to, row, col + coloff); | |
5571 else | |
5572 #endif | |
5573 screen_char(off_to, row, col + coloff); | |
5574 } | |
5575 else if ( p_wiv | |
5576 #ifdef FEAT_GUI | |
5577 && !gui.in_use | |
5578 #endif | |
5579 && col + coloff > 0) | |
5580 { | |
5581 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5582 { | |
5583 /* | |
5584 * Don't output stop-highlight when moving the cursor, it will | |
5585 * stop the highlighting when it should continue. | |
5586 */ | |
5587 screen_attr = 0; | |
5588 } | |
5589 else if (screen_attr != 0) | |
5590 screen_stop_highlight(); | |
5591 } | |
5592 | |
5593 off_to += CHAR_CELLS; | |
5594 off_from += CHAR_CELLS; | |
5595 col += CHAR_CELLS; | |
5596 } | |
5597 | |
5598 #ifdef FEAT_MBYTE | |
5599 if (clear_next) | |
5600 { | |
5601 /* Clear the second half of a double-wide character of which the left | |
5602 * half was overwritten with a single-wide character. */ | |
5603 ScreenLines[off_to] = ' '; | |
5604 if (enc_utf8) | |
5605 ScreenLinesUC[off_to] = 0; | |
5606 screen_char(off_to, row, col + coloff); | |
5607 } | |
5608 #endif | |
5609 | |
5610 if (clear_width > 0 | |
5611 #ifdef FEAT_RIGHTLEFT | |
5612 && !rlflag | |
5613 #endif | |
5614 ) | |
5615 { | |
5616 #ifdef FEAT_GUI | |
5617 int startCol = col; | |
5618 #endif | |
5619 | |
5620 /* blank out the rest of the line */ | |
5621 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5622 && ScreenAttrs[off_to] == 0 | |
5623 #ifdef FEAT_MBYTE | |
5624 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5625 #endif | |
5626 ) | |
5627 { | |
5628 ++off_to; | |
5629 ++col; | |
5630 } | |
5631 if (col < clear_width) | |
5632 { | |
5633 #ifdef FEAT_GUI | |
5634 /* | |
5635 * In the GUI, clearing the rest of the line may leave pixels | |
5636 * behind if the first character cleared was bold. Some bold | |
5637 * fonts spill over the left. In this case we redraw the previous | |
5638 * character too. If we didn't skip any blanks above, then we | |
5639 * only redraw if the character wasn't already redrawn anyway. | |
5640 */ | |
996 | 5641 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5642 { |
5643 hl = ScreenAttrs[off_to]; | |
5644 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5645 { |
5646 int prev_cells = 1; | |
5647 # ifdef FEAT_MBYTE | |
5648 if (enc_utf8) | |
5649 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5650 * that its width is 2. */ | |
5651 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5652 else if (enc_dbcs != 0) | |
5653 { | |
5654 /* find previous character by counting from first | |
5655 * column and get its width. */ | |
5656 unsigned off = LineOffset[row]; | |
1378 | 5657 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5658 |
5659 while (off < off_to) | |
5660 { | |
1378 | 5661 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5662 off += prev_cells; |
5663 } | |
5664 } | |
5665 | |
5666 if (enc_dbcs != 0 && prev_cells > 1) | |
5667 screen_char_2(off_to - prev_cells, row, | |
5668 col + coloff - prev_cells); | |
5669 else | |
5670 # endif | |
5671 screen_char(off_to - prev_cells, row, | |
5672 col + coloff - prev_cells); | |
5673 } | |
7 | 5674 } |
5675 #endif | |
5676 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5677 ' ', ' ', 0); | |
5678 #ifdef FEAT_VERTSPLIT | |
5679 off_to += clear_width - col; | |
5680 col = clear_width; | |
5681 #endif | |
5682 } | |
5683 } | |
5684 | |
5685 if (clear_width > 0) | |
5686 { | |
5687 #ifdef FEAT_VERTSPLIT | |
5688 /* For a window that's left of another, draw the separator char. */ | |
5689 if (col + coloff < Columns) | |
5690 { | |
5691 int c; | |
5692 | |
5693 c = fillchar_vsep(&hl); | |
5694 if (ScreenLines[off_to] != c | |
5695 # ifdef FEAT_MBYTE | |
714 | 5696 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5697 != (c >= 0x80 ? c : 0)) | |
7 | 5698 # endif |
5699 || ScreenAttrs[off_to] != hl) | |
5700 { | |
5701 ScreenLines[off_to] = c; | |
5702 ScreenAttrs[off_to] = hl; | |
5703 # ifdef FEAT_MBYTE | |
5704 if (enc_utf8) | |
5705 { | |
5706 if (c >= 0x80) | |
5707 { | |
5708 ScreenLinesUC[off_to] = c; | |
714 | 5709 ScreenLinesC[0][off_to] = 0; |
7 | 5710 } |
5711 else | |
5712 ScreenLinesUC[off_to] = 0; | |
5713 } | |
5714 # endif | |
5715 screen_char(off_to, row, col + coloff); | |
5716 } | |
5717 } | |
5718 else | |
5719 #endif | |
5720 LineWraps[row] = FALSE; | |
5721 } | |
5722 } | |
5723 | |
474 | 5724 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5725 /* |
474 | 5726 * Mirror text "str" for right-left displaying. |
5727 * Only works for single-byte characters (e.g., numbers). | |
7 | 5728 */ |
474 | 5729 void |
7 | 5730 rl_mirror(str) |
5731 char_u *str; | |
5732 { | |
5733 char_u *p1, *p2; | |
5734 int t; | |
5735 | |
5736 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5737 { | |
5738 t = *p1; | |
5739 *p1 = *p2; | |
5740 *p2 = t; | |
5741 } | |
5742 } | |
5743 #endif | |
5744 | |
5745 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5746 /* | |
5747 * mark all status lines for redraw; used after first :cd | |
5748 */ | |
5749 void | |
5750 status_redraw_all() | |
5751 { | |
5752 win_T *wp; | |
5753 | |
5754 for (wp = firstwin; wp; wp = wp->w_next) | |
5755 if (wp->w_status_height) | |
5756 { | |
5757 wp->w_redr_status = TRUE; | |
5758 redraw_later(VALID); | |
5759 } | |
5760 } | |
5761 | |
5762 /* | |
5763 * mark all status lines of the current buffer for redraw | |
5764 */ | |
5765 void | |
5766 status_redraw_curbuf() | |
5767 { | |
5768 win_T *wp; | |
5769 | |
5770 for (wp = firstwin; wp; wp = wp->w_next) | |
5771 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5772 { | |
5773 wp->w_redr_status = TRUE; | |
5774 redraw_later(VALID); | |
5775 } | |
5776 } | |
5777 | |
5778 /* | |
5779 * Redraw all status lines that need to be redrawn. | |
5780 */ | |
5781 void | |
5782 redraw_statuslines() | |
5783 { | |
5784 win_T *wp; | |
5785 | |
5786 for (wp = firstwin; wp; wp = wp->w_next) | |
5787 if (wp->w_redr_status) | |
5788 win_redr_status(wp); | |
673 | 5789 if (redraw_tabline) |
677 | 5790 draw_tabline(); |
7 | 5791 } |
5792 #endif | |
5793 | |
5794 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5795 /* | |
5796 * Redraw all status lines at the bottom of frame "frp". | |
5797 */ | |
5798 void | |
5799 win_redraw_last_status(frp) | |
5800 frame_T *frp; | |
5801 { | |
5802 if (frp->fr_layout == FR_LEAF) | |
5803 frp->fr_win->w_redr_status = TRUE; | |
5804 else if (frp->fr_layout == FR_ROW) | |
5805 { | |
5806 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5807 win_redraw_last_status(frp); | |
5808 } | |
5809 else /* frp->fr_layout == FR_COL */ | |
5810 { | |
5811 frp = frp->fr_child; | |
5812 while (frp->fr_next != NULL) | |
5813 frp = frp->fr_next; | |
5814 win_redraw_last_status(frp); | |
5815 } | |
5816 } | |
5817 #endif | |
5818 | |
5819 #ifdef FEAT_VERTSPLIT | |
5820 /* | |
5821 * Draw the verticap separator right of window "wp" starting with line "row". | |
5822 */ | |
5823 static void | |
5824 draw_vsep_win(wp, row) | |
5825 win_T *wp; | |
5826 int row; | |
5827 { | |
5828 int hl; | |
5829 int c; | |
5830 | |
5831 if (wp->w_vsep_width) | |
5832 { | |
5833 /* draw the vertical separator right of this window */ | |
5834 c = fillchar_vsep(&hl); | |
5835 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5836 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5837 c, ' ', hl); | |
5838 } | |
5839 } | |
5840 #endif | |
5841 | |
5842 #ifdef FEAT_WILDMENU | |
5843 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5844 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5845 |
5846 /* | |
1378 | 5847 * Get the length of an item as it will be shown in the status line. |
7 | 5848 */ |
5849 static int | |
5850 status_match_len(xp, s) | |
5851 expand_T *xp; | |
5852 char_u *s; | |
5853 { | |
5854 int len = 0; | |
5855 | |
5856 #ifdef FEAT_MENU | |
5857 int emenu = (xp->xp_context == EXPAND_MENUS | |
5858 || xp->xp_context == EXPAND_MENUNAMES); | |
5859 | |
5860 /* Check for menu separators - replace with '|'. */ | |
5861 if (emenu && menu_is_separator(s)) | |
5862 return 1; | |
5863 #endif | |
5864 | |
5865 while (*s != NUL) | |
5866 { | |
1685 | 5867 s += skip_status_match_char(xp, s); |
42 | 5868 len += ptr2cells(s); |
39 | 5869 mb_ptr_adv(s); |
7 | 5870 } |
5871 | |
5872 return len; | |
5873 } | |
5874 | |
5875 /* | |
1685 | 5876 * Return the number of characters that should be skipped in a status match. |
277 | 5877 * These are backslashes used for escaping. Do show backslashes in help tags. |
5878 */ | |
5879 static int | |
5880 skip_status_match_char(xp, s) | |
5881 expand_T *xp; | |
5882 char_u *s; | |
5883 { | |
1685 | 5884 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5885 #ifdef FEAT_MENU |
5886 || ((xp->xp_context == EXPAND_MENUS | |
5887 || xp->xp_context == EXPAND_MENUNAMES) | |
5888 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5889 #endif | |
1685 | 5890 ) |
5891 { | |
5892 #ifndef BACKSLASH_IN_FILENAME | |
5893 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5894 return 2; | |
5895 #endif | |
5896 return 1; | |
5897 } | |
5898 return 0; | |
277 | 5899 } |
5900 | |
5901 /* | |
7 | 5902 * Show wildchar matches in the status line. |
5903 * Show at least the "match" item. | |
5904 * We start at item 'first_match' in the list and show all matches that fit. | |
5905 * | |
5906 * If inversion is possible we use it. Else '=' characters are used. | |
5907 */ | |
5908 void | |
5909 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5910 expand_T *xp; | |
5911 int num_matches; | |
5912 char_u **matches; /* list of matches */ | |
5913 int match; | |
5914 int showtail; | |
5915 { | |
5916 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5917 int row; | |
5918 char_u *buf; | |
5919 int len; | |
1378 | 5920 int clen; /* length in screen cells */ |
7 | 5921 int fillchar; |
5922 int attr; | |
5923 int i; | |
5924 int highlight = TRUE; | |
5925 char_u *selstart = NULL; | |
5926 int selstart_col = 0; | |
5927 char_u *selend = NULL; | |
5928 static int first_match = 0; | |
5929 int add_left = FALSE; | |
5930 char_u *s; | |
5931 #ifdef FEAT_MENU | |
5932 int emenu; | |
5933 #endif | |
5934 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5935 int l; | |
5936 #endif | |
5937 | |
5938 if (matches == NULL) /* interrupted completion? */ | |
5939 return; | |
5940 | |
39 | 5941 #ifdef FEAT_MBYTE |
5942 if (has_mbyte) | |
5943 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5944 else | |
5945 #endif | |
5946 buf = alloc((unsigned)Columns + 1); | |
7 | 5947 if (buf == NULL) |
5948 return; | |
5949 | |
5950 if (match == -1) /* don't show match but original text */ | |
5951 { | |
5952 match = 0; | |
5953 highlight = FALSE; | |
5954 } | |
5955 /* count 1 for the ending ">" */ | |
5956 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5957 if (match == 0) | |
5958 first_match = 0; | |
5959 else if (match < first_match) | |
5960 { | |
5961 /* jumping left, as far as we can go */ | |
5962 first_match = match; | |
5963 add_left = TRUE; | |
5964 } | |
5965 else | |
5966 { | |
5967 /* check if match fits on the screen */ | |
5968 for (i = first_match; i < match; ++i) | |
5969 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5970 if (first_match > 0) | |
5971 clen += 2; | |
5972 /* jumping right, put match at the left */ | |
5973 if ((long)clen > Columns) | |
5974 { | |
5975 first_match = match; | |
5976 /* if showing the last match, we can add some on the left */ | |
5977 clen = 2; | |
5978 for (i = match; i < num_matches; ++i) | |
5979 { | |
5980 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5981 if ((long)clen >= Columns) | |
5982 break; | |
5983 } | |
5984 if (i == num_matches) | |
5985 add_left = TRUE; | |
5986 } | |
5987 } | |
5988 if (add_left) | |
5989 while (first_match > 0) | |
5990 { | |
5991 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5992 if ((long)clen >= Columns) | |
5993 break; | |
5994 --first_match; | |
5995 } | |
5996 | |
5997 fillchar = fillchar_status(&attr, TRUE); | |
5998 | |
5999 if (first_match == 0) | |
6000 { | |
6001 *buf = NUL; | |
6002 len = 0; | |
6003 } | |
6004 else | |
6005 { | |
6006 STRCPY(buf, "< "); | |
6007 len = 2; | |
6008 } | |
6009 clen = len; | |
6010 | |
6011 i = first_match; | |
6012 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
6013 { | |
6014 if (i == match) | |
6015 { | |
6016 selstart = buf + len; | |
6017 selstart_col = clen; | |
6018 } | |
6019 | |
6020 s = L_MATCH(i); | |
6021 /* Check for menu separators - replace with '|' */ | |
6022 #ifdef FEAT_MENU | |
6023 emenu = (xp->xp_context == EXPAND_MENUS | |
6024 || xp->xp_context == EXPAND_MENUNAMES); | |
6025 if (emenu && menu_is_separator(s)) | |
6026 { | |
6027 STRCPY(buf + len, transchar('|')); | |
6028 l = (int)STRLEN(buf + len); | |
6029 len += l; | |
6030 clen += l; | |
6031 } | |
6032 else | |
6033 #endif | |
6034 for ( ; *s != NUL; ++s) | |
6035 { | |
1685 | 6036 s += skip_status_match_char(xp, s); |
7 | 6037 clen += ptr2cells(s); |
6038 #ifdef FEAT_MBYTE | |
474 | 6039 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 6040 { |
6041 STRNCPY(buf + len, s, l); | |
6042 s += l - 1; | |
6043 len += l; | |
6044 } | |
6045 else | |
6046 #endif | |
6047 { | |
6048 STRCPY(buf + len, transchar_byte(*s)); | |
6049 len += (int)STRLEN(buf + len); | |
6050 } | |
6051 } | |
6052 if (i == match) | |
6053 selend = buf + len; | |
6054 | |
6055 *(buf + len++) = ' '; | |
6056 *(buf + len++) = ' '; | |
6057 clen += 2; | |
6058 if (++i == num_matches) | |
6059 break; | |
6060 } | |
6061 | |
6062 if (i != num_matches) | |
6063 { | |
6064 *(buf + len++) = '>'; | |
6065 ++clen; | |
6066 } | |
6067 | |
6068 buf[len] = NUL; | |
6069 | |
6070 row = cmdline_row - 1; | |
6071 if (row >= 0) | |
6072 { | |
6073 if (wild_menu_showing == 0) | |
6074 { | |
6075 if (msg_scrolled > 0) | |
6076 { | |
6077 /* Put the wildmenu just above the command line. If there is | |
6078 * no room, scroll the screen one line up. */ | |
6079 if (cmdline_row == Rows - 1) | |
6080 { | |
6081 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6082 ++msg_scrolled; | |
6083 } | |
6084 else | |
6085 { | |
6086 ++cmdline_row; | |
6087 ++row; | |
6088 } | |
6089 wild_menu_showing = WM_SCROLLED; | |
6090 } | |
6091 else | |
6092 { | |
6093 /* Create status line if needed by setting 'laststatus' to 2. | |
6094 * Set 'winminheight' to zero to avoid that the window is | |
6095 * resized. */ | |
6096 if (lastwin->w_status_height == 0) | |
6097 { | |
6098 save_p_ls = p_ls; | |
6099 save_p_wmh = p_wmh; | |
6100 p_ls = 2; | |
6101 p_wmh = 0; | |
6102 last_status(FALSE); | |
6103 } | |
6104 wild_menu_showing = WM_SHOWN; | |
6105 } | |
6106 } | |
6107 | |
6108 screen_puts(buf, row, 0, attr); | |
6109 if (selstart != NULL && highlight) | |
6110 { | |
6111 *selend = NUL; | |
6112 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6113 } | |
6114 | |
6115 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6116 } | |
6117 | |
6118 #ifdef FEAT_VERTSPLIT | |
6119 win_redraw_last_status(topframe); | |
6120 #else | |
6121 lastwin->w_redr_status = TRUE; | |
6122 #endif | |
6123 vim_free(buf); | |
6124 } | |
6125 #endif | |
6126 | |
6127 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6128 /* | |
6129 * Redraw the status line of window wp. | |
6130 * | |
6131 * If inversion is possible we use it. Else '=' characters are used. | |
6132 */ | |
6133 void | |
6134 win_redr_status(wp) | |
6135 win_T *wp; | |
6136 { | |
6137 int row; | |
6138 char_u *p; | |
6139 int len; | |
6140 int fillchar; | |
6141 int attr; | |
6142 int this_ru_col; | |
1910 | 6143 static int busy = FALSE; |
6144 | |
6145 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6146 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6147 if (busy) | |
6148 return; | |
6149 busy = TRUE; | |
7 | 6150 |
6151 wp->w_redr_status = FALSE; | |
6152 if (wp->w_status_height == 0) | |
6153 { | |
6154 /* no status line, can only be last window */ | |
6155 redraw_cmdline = TRUE; | |
6156 } | |
540 | 6157 else if (!redrawing() |
6158 #ifdef FEAT_INS_EXPAND | |
6159 /* don't update status line when popup menu is visible and may be | |
6160 * drawn over it */ | |
6161 || pum_visible() | |
6162 #endif | |
6163 ) | |
7 | 6164 { |
6165 /* Don't redraw right now, do it later. */ | |
6166 wp->w_redr_status = TRUE; | |
6167 } | |
6168 #ifdef FEAT_STL_OPT | |
40 | 6169 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6170 { |
6171 /* redraw custom status line */ | |
1983 | 6172 redraw_custom_statusline(wp); |
7 | 6173 } |
6174 #endif | |
6175 else | |
6176 { | |
6177 fillchar = fillchar_status(&attr, wp == curwin); | |
6178 | |
685 | 6179 get_trans_bufname(wp->w_buffer); |
7 | 6180 p = NameBuff; |
6181 len = (int)STRLEN(p); | |
6182 | |
6183 if (wp->w_buffer->b_help | |
6184 #ifdef FEAT_QUICKFIX | |
6185 || wp->w_p_pvw | |
6186 #endif | |
6187 || bufIsChanged(wp->w_buffer) | |
6188 || wp->w_buffer->b_p_ro) | |
6189 *(p + len++) = ' '; | |
6190 if (wp->w_buffer->b_help) | |
6191 { | |
809 | 6192 STRCPY(p + len, _("[Help]")); |
7 | 6193 len += (int)STRLEN(p + len); |
6194 } | |
6195 #ifdef FEAT_QUICKFIX | |
6196 if (wp->w_p_pvw) | |
6197 { | |
6198 STRCPY(p + len, _("[Preview]")); | |
6199 len += (int)STRLEN(p + len); | |
6200 } | |
6201 #endif | |
6202 if (bufIsChanged(wp->w_buffer)) | |
6203 { | |
6204 STRCPY(p + len, "[+]"); | |
6205 len += 3; | |
6206 } | |
6207 if (wp->w_buffer->b_p_ro) | |
6208 { | |
6209 STRCPY(p + len, "[RO]"); | |
6210 len += 4; | |
6211 } | |
6212 | |
6213 #ifndef FEAT_VERTSPLIT | |
6214 this_ru_col = ru_col; | |
6215 if (this_ru_col < (Columns + 1) / 2) | |
6216 this_ru_col = (Columns + 1) / 2; | |
6217 #else | |
6218 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6219 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6220 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6221 if (this_ru_col <= 1) | |
6222 { | |
6223 p = (char_u *)"<"; /* No room for file name! */ | |
6224 len = 1; | |
6225 } | |
6226 else | |
6227 #endif | |
6228 #ifdef FEAT_MBYTE | |
6229 if (has_mbyte) | |
6230 { | |
6231 int clen = 0, i; | |
6232 | |
6233 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6234 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6235 |
7 | 6236 /* Find first character that will fit. |
6237 * Going from start to end is much faster for DBCS. */ | |
6238 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6239 i += (*mb_ptr2len)(p + i)) |
7 | 6240 clen -= (*mb_ptr2cells)(p + i); |
6241 len = clen; | |
6242 if (i > 0) | |
6243 { | |
6244 p = p + i - 1; | |
6245 *p = '<'; | |
6246 ++len; | |
6247 } | |
6248 | |
6249 } | |
6250 else | |
6251 #endif | |
6252 if (len > this_ru_col - 1) | |
6253 { | |
6254 p += len - (this_ru_col - 1); | |
6255 *p = '<'; | |
6256 len = this_ru_col - 1; | |
6257 } | |
6258 | |
6259 row = W_WINROW(wp) + wp->w_height; | |
6260 screen_puts(p, row, W_WINCOL(wp), attr); | |
6261 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6262 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6263 | |
6264 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6265 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6266 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6267 - 1 + W_WINCOL(wp)), attr); | |
6268 | |
6269 #ifdef FEAT_CMDL_INFO | |
6270 win_redr_ruler(wp, TRUE); | |
6271 #endif | |
6272 } | |
6273 | |
6274 #ifdef FEAT_VERTSPLIT | |
6275 /* | |
6276 * May need to draw the character below the vertical separator. | |
6277 */ | |
6278 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6279 { | |
6280 if (stl_connected(wp)) | |
6281 fillchar = fillchar_status(&attr, wp == curwin); | |
6282 else | |
6283 fillchar = fillchar_vsep(&attr); | |
6284 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6285 attr); | |
6286 } | |
6287 #endif | |
1910 | 6288 busy = FALSE; |
7 | 6289 } |
6290 | |
680 | 6291 #ifdef FEAT_STL_OPT |
6292 /* | |
6293 * Redraw the status line according to 'statusline' and take care of any | |
6294 * errors encountered. | |
6295 */ | |
6296 static void | |
1983 | 6297 redraw_custom_statusline(wp) |
680 | 6298 win_T *wp; |
6299 { | |
1983 | 6300 static int entered = FALSE; |
6301 int save_called_emsg = called_emsg; | |
6302 | |
6303 /* When called recursively return. This can happen when the statusline | |
6304 * contains an expression that triggers a redraw. */ | |
6305 if (entered) | |
6306 return; | |
6307 entered = TRUE; | |
680 | 6308 |
6309 called_emsg = FALSE; | |
6310 win_redr_custom(wp, FALSE); | |
6311 if (called_emsg) | |
1983 | 6312 { |
6313 /* When there is an error disable the statusline, otherwise the | |
6314 * display is messed up with errors and a redraw triggers the problem | |
6315 * again and again. */ | |
680 | 6316 set_string_option_direct((char_u *)"statusline", -1, |
6317 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6318 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6319 } |
680 | 6320 called_emsg |= save_called_emsg; |
1983 | 6321 entered = FALSE; |
680 | 6322 } |
6323 #endif | |
6324 | |
7 | 6325 # ifdef FEAT_VERTSPLIT |
6326 /* | |
6327 * Return TRUE if the status line of window "wp" is connected to the status | |
6328 * line of the window right of it. If not, then it's a vertical separator. | |
6329 * Only call if (wp->w_vsep_width != 0). | |
6330 */ | |
6331 int | |
6332 stl_connected(wp) | |
6333 win_T *wp; | |
6334 { | |
6335 frame_T *fr; | |
6336 | |
6337 fr = wp->w_frame; | |
6338 while (fr->fr_parent != NULL) | |
6339 { | |
6340 if (fr->fr_parent->fr_layout == FR_COL) | |
6341 { | |
6342 if (fr->fr_next != NULL) | |
6343 break; | |
6344 } | |
6345 else | |
6346 { | |
6347 if (fr->fr_next != NULL) | |
6348 return TRUE; | |
6349 } | |
6350 fr = fr->fr_parent; | |
6351 } | |
6352 return FALSE; | |
6353 } | |
6354 # endif | |
6355 | |
6356 #endif /* FEAT_WINDOWS */ | |
6357 | |
6358 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6359 /* | |
6360 * Get the value to show for the language mappings, active 'keymap'. | |
6361 */ | |
6362 int | |
6363 get_keymap_str(wp, buf, len) | |
6364 win_T *wp; | |
6365 char_u *buf; /* buffer for the result */ | |
6366 int len; /* length of buffer */ | |
6367 { | |
6368 char_u *p; | |
6369 | |
6370 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6371 return FALSE; | |
6372 | |
6373 { | |
6374 #ifdef FEAT_EVAL | |
6375 buf_T *old_curbuf = curbuf; | |
6376 win_T *old_curwin = curwin; | |
6377 char_u *s; | |
6378 | |
6379 curbuf = wp->w_buffer; | |
6380 curwin = wp; | |
6381 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6382 ++emsg_skip; | |
714 | 6383 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6384 --emsg_skip; |
6385 curbuf = old_curbuf; | |
6386 curwin = old_curwin; | |
6387 if (p == NULL || *p == NUL) | |
6388 #endif | |
6389 { | |
6390 #ifdef FEAT_KEYMAP | |
6391 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6392 p = wp->w_buffer->b_p_keymap; | |
6393 else | |
6394 #endif | |
6395 p = (char_u *)"lang"; | |
6396 } | |
6397 if ((int)(STRLEN(p) + 3) < len) | |
6398 sprintf((char *)buf, "<%s>", p); | |
6399 else | |
6400 buf[0] = NUL; | |
6401 #ifdef FEAT_EVAL | |
6402 vim_free(s); | |
6403 #endif | |
6404 } | |
6405 return buf[0] != NUL; | |
6406 } | |
6407 #endif | |
6408 | |
6409 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6410 /* | |
677 | 6411 * Redraw the status line or ruler of window "wp". |
6412 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6413 */ |
6414 static void | |
574 | 6415 win_redr_custom(wp, draw_ruler) |
7 | 6416 win_T *wp; |
574 | 6417 int draw_ruler; /* TRUE or FALSE */ |
7 | 6418 { |
6419 int attr; | |
6420 int curattr; | |
6421 int row; | |
6422 int col = 0; | |
6423 int maxwidth; | |
6424 int width; | |
6425 int n; | |
6426 int len; | |
6427 int fillchar; | |
6428 char_u buf[MAXPATHL]; | |
1983 | 6429 char_u *stl; |
7 | 6430 char_u *p; |
681 | 6431 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6432 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6433 int use_sandbox = FALSE; |
7 | 6434 |
6435 /* setup environment for the task at hand */ | |
677 | 6436 if (wp == NULL) |
6437 { | |
6438 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6439 stl = p_tal; |
677 | 6440 row = 0; |
707 | 6441 fillchar = ' '; |
677 | 6442 attr = hl_attr(HLF_TPF); |
6443 maxwidth = Columns; | |
6444 # ifdef FEAT_EVAL | |
681 | 6445 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6446 # endif |
6447 } | |
40 | 6448 else |
677 | 6449 { |
6450 row = W_WINROW(wp) + wp->w_height; | |
6451 fillchar = fillchar_status(&attr, wp == curwin); | |
6452 maxwidth = W_WIDTH(wp); | |
6453 | |
6454 if (draw_ruler) | |
6455 { | |
1983 | 6456 stl = p_ruf; |
677 | 6457 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6458 if (*stl == '%') |
6459 { | |
6460 if (*++stl == '-') | |
6461 stl++; | |
6462 if (atoi((char *)stl)) | |
6463 while (VIM_ISDIGIT(*stl)) | |
6464 stl++; | |
6465 if (*stl++ != '(') | |
6466 stl = p_ruf; | |
677 | 6467 } |
7 | 6468 #ifdef FEAT_VERTSPLIT |
677 | 6469 col = ru_col - (Columns - W_WIDTH(wp)); |
6470 if (col < (W_WIDTH(wp) + 1) / 2) | |
6471 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6472 #else |
677 | 6473 col = ru_col; |
6474 if (col > (Columns + 1) / 2) | |
6475 col = (Columns + 1) / 2; | |
6476 #endif | |
6477 maxwidth = W_WIDTH(wp) - col; | |
7 | 6478 #ifdef FEAT_WINDOWS |
677 | 6479 if (!wp->w_status_height) |
6480 #endif | |
6481 { | |
6482 row = Rows - 1; | |
6483 --maxwidth; /* writing in last column may cause scrolling */ | |
6484 fillchar = ' '; | |
6485 attr = 0; | |
6486 } | |
6487 | |
6488 # ifdef FEAT_EVAL | |
681 | 6489 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6490 # endif |
6491 } | |
6492 else | |
6493 { | |
6494 if (*wp->w_p_stl != NUL) | |
1983 | 6495 stl = wp->w_p_stl; |
677 | 6496 else |
1983 | 6497 stl = p_stl; |
677 | 6498 # ifdef FEAT_EVAL |
681 | 6499 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6500 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6501 # endif |
6502 } | |
6503 | |
6504 #ifdef FEAT_VERTSPLIT | |
6505 col += W_WINCOL(wp); | |
6506 #endif | |
6507 } | |
6508 | |
7 | 6509 if (maxwidth <= 0) |
6510 return; | |
677 | 6511 |
1983 | 6512 /* Make a copy, because the statusline may include a function call that |
6513 * might change the option value and free the memory. */ | |
6514 stl = vim_strsave(stl); | |
677 | 6515 width = build_stl_str_hl(wp == NULL ? curwin : wp, |
6516 buf, sizeof(buf), | |
1983 | 6517 stl, use_sandbox, |
681 | 6518 fillchar, maxwidth, hltab, tabtab); |
1983 | 6519 vim_free(stl); |
835 | 6520 len = (int)STRLEN(buf); |
7 | 6521 |
1883 | 6522 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6523 { |
6524 #ifdef FEAT_MBYTE | |
6525 len += (*mb_char2bytes)(fillchar, buf + len); | |
6526 #else | |
6527 buf[len++] = fillchar; | |
6528 #endif | |
6529 ++width; | |
6530 } | |
6531 buf[len] = NUL; | |
6532 | |
681 | 6533 /* |
6534 * Draw each snippet with the specified highlighting. | |
6535 */ | |
7 | 6536 curattr = attr; |
6537 p = buf; | |
681 | 6538 for (n = 0; hltab[n].start != NULL; n++) |
6539 { | |
6540 len = (int)(hltab[n].start - p); | |
7 | 6541 screen_puts_len(p, len, row, col, curattr); |
6542 col += vim_strnsize(p, len); | |
681 | 6543 p = hltab[n].start; |
6544 | |
6545 if (hltab[n].userhl == 0) | |
7 | 6546 curattr = attr; |
681 | 6547 else if (hltab[n].userhl < 0) |
6548 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6549 #ifdef FEAT_WINDOWS |
680 | 6550 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6551 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6552 #endif |
6553 else | |
681 | 6554 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6555 } |
6556 screen_puts(p, row, col, curattr); | |
681 | 6557 |
6558 if (wp == NULL) | |
6559 { | |
6560 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6561 col = 0; | |
6562 len = 0; | |
6563 p = buf; | |
6564 fillchar = 0; | |
6565 for (n = 0; tabtab[n].start != NULL; n++) | |
6566 { | |
6567 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6568 while (col < len) | |
6569 TabPageIdxs[col++] = fillchar; | |
6570 p = tabtab[n].start; | |
6571 fillchar = tabtab[n].userhl; | |
6572 } | |
6573 while (col < Columns) | |
6574 TabPageIdxs[col++] = fillchar; | |
6575 } | |
7 | 6576 } |
6577 | |
6578 #endif /* FEAT_STL_OPT */ | |
6579 | |
6580 /* | |
6581 * Output a single character directly to the screen and update ScreenLines. | |
6582 */ | |
6583 void | |
6584 screen_putchar(c, row, col, attr) | |
6585 int c; | |
6586 int row, col; | |
6587 int attr; | |
6588 { | |
6589 #ifdef FEAT_MBYTE | |
6590 char_u buf[MB_MAXBYTES + 1]; | |
6591 | |
6592 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6593 #else | |
6594 char_u buf[2]; | |
6595 | |
6596 buf[0] = c; | |
6597 buf[1] = NUL; | |
6598 #endif | |
6599 screen_puts(buf, row, col, attr); | |
6600 } | |
6601 | |
6602 /* | |
6603 * Get a single character directly from ScreenLines into "bytes[]". | |
6604 * Also return its attribute in *attrp; | |
6605 */ | |
6606 void | |
6607 screen_getbytes(row, col, bytes, attrp) | |
6608 int row, col; | |
6609 char_u *bytes; | |
6610 int *attrp; | |
6611 { | |
6612 unsigned off; | |
6613 | |
6614 /* safety check */ | |
6615 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6616 { | |
6617 off = LineOffset[row] + col; | |
6618 *attrp = ScreenAttrs[off]; | |
6619 bytes[0] = ScreenLines[off]; | |
6620 bytes[1] = NUL; | |
6621 | |
6622 #ifdef FEAT_MBYTE | |
6623 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6624 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6625 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6626 { | |
6627 bytes[0] = ScreenLines[off]; | |
6628 bytes[1] = ScreenLines2[off]; | |
6629 bytes[2] = NUL; | |
6630 } | |
6631 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6632 { | |
6633 bytes[1] = ScreenLines[off + 1]; | |
6634 bytes[2] = NUL; | |
6635 } | |
6636 #endif | |
6637 } | |
6638 } | |
6639 | |
714 | 6640 #ifdef FEAT_MBYTE |
6641 static int screen_comp_differs __ARGS((int, int*)); | |
6642 | |
6643 /* | |
6644 * Return TRUE if composing characters for screen posn "off" differs from | |
6645 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6646 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6647 */ |
6648 static int | |
6649 screen_comp_differs(off, u8cc) | |
6650 int off; | |
6651 int *u8cc; | |
6652 { | |
6653 int i; | |
6654 | |
6655 for (i = 0; i < Screen_mco; ++i) | |
6656 { | |
6657 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6658 return TRUE; | |
6659 if (u8cc[i] == 0) | |
6660 break; | |
6661 } | |
6662 return FALSE; | |
6663 } | |
6664 #endif | |
6665 | |
7 | 6666 /* |
6667 * Put string '*text' on the screen at position 'row' and 'col', with | |
6668 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6669 * Note: only outputs within one row, message is truncated at screen boundary! | |
6670 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6671 */ | |
6672 void | |
6673 screen_puts(text, row, col, attr) | |
6674 char_u *text; | |
6675 int row; | |
6676 int col; | |
6677 int attr; | |
6678 { | |
6679 screen_puts_len(text, -1, row, col, attr); | |
6680 } | |
6681 | |
6682 /* | |
6683 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6684 * a NUL. | |
6685 */ | |
6686 void | |
6687 screen_puts_len(text, len, row, col, attr) | |
6688 char_u *text; | |
6689 int len; | |
6690 int row; | |
6691 int col; | |
6692 int attr; | |
6693 { | |
6694 unsigned off; | |
6695 char_u *ptr = text; | |
6696 int c; | |
6697 #ifdef FEAT_MBYTE | |
1378 | 6698 unsigned max_off; |
7 | 6699 int mbyte_blen = 1; |
6700 int mbyte_cells = 1; | |
6701 int u8c = 0; | |
714 | 6702 int u8cc[MAX_MCO]; |
7 | 6703 int clear_next_cell = FALSE; |
6704 # ifdef FEAT_ARABIC | |
6705 int prev_c = 0; /* previous Arabic character */ | |
714 | 6706 int pc, nc, nc1; |
6707 int pcc[MAX_MCO]; | |
7 | 6708 # endif |
6709 #endif | |
1843 | 6710 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6711 int force_redraw_this; | |
6712 int force_redraw_next = FALSE; | |
6713 #endif | |
6714 int need_redraw; | |
7 | 6715 |
6716 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6717 return; | |
1843 | 6718 off = LineOffset[row] + col; |
7 | 6719 |
1668 | 6720 #ifdef FEAT_MBYTE |
6721 /* When drawing over the right halve of a double-wide char clear out the | |
6722 * left halve. Only needed in a terminal. */ | |
1685 | 6723 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6724 # ifdef FEAT_GUI |
6725 && !gui.in_use | |
6726 # endif | |
6727 && mb_fix_col(col, row) != col) | |
1843 | 6728 { |
6729 ScreenLines[off - 1] = ' '; | |
6730 ScreenAttrs[off - 1] = 0; | |
6731 if (enc_utf8) | |
6732 { | |
6733 ScreenLinesUC[off - 1] = 0; | |
6734 ScreenLinesC[0][off - 1] = 0; | |
6735 } | |
6736 /* redraw the previous cell, make it empty */ | |
6737 screen_char(off - 1, row, col - 1); | |
6738 /* force the cell at "col" to be redrawn */ | |
6739 force_redraw_next = TRUE; | |
6740 } | |
6741 #endif | |
6742 | |
1378 | 6743 #ifdef FEAT_MBYTE |
6744 max_off = LineOffset[row] + screen_Columns; | |
6745 #endif | |
1340 | 6746 while (col < screen_Columns |
6747 && (len < 0 || (int)(ptr - text) < len) | |
6748 && *ptr != NUL) | |
7 | 6749 { |
6750 c = *ptr; | |
6751 #ifdef FEAT_MBYTE | |
6752 /* check if this is the first byte of a multibyte */ | |
6753 if (has_mbyte) | |
6754 { | |
6755 if (enc_utf8 && len > 0) | |
474 | 6756 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6757 else |
474 | 6758 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6759 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6760 mbyte_cells = 1; | |
6761 else if (enc_dbcs != 0) | |
6762 mbyte_cells = mbyte_blen; | |
6763 else /* enc_utf8 */ | |
6764 { | |
6765 if (len >= 0) | |
714 | 6766 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6767 (int)((text + len) - ptr)); |
6768 else | |
714 | 6769 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6770 mbyte_cells = utf_char2cells(u8c); |
1401 | 6771 # ifdef UNICODE16 |
7 | 6772 /* Non-BMP character: display as ? or fullwidth ?. */ |
6773 if (u8c >= 0x10000) | |
6774 { | |
6775 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6776 if (attr == 0) | |
6777 attr = hl_attr(HLF_8); | |
6778 } | |
1401 | 6779 # endif |
7 | 6780 # ifdef FEAT_ARABIC |
6781 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6782 { | |
6783 /* Do Arabic shaping. */ | |
6784 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6785 { | |
6786 /* Past end of string to be displayed. */ | |
6787 nc = NUL; | |
6788 nc1 = NUL; | |
6789 } | |
6790 else | |
714 | 6791 { |
1994 | 6792 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6793 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6794 nc1 = pcc[0]; |
6795 } | |
7 | 6796 pc = prev_c; |
6797 prev_c = u8c; | |
714 | 6798 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6799 } |
6800 else | |
6801 prev_c = u8c; | |
6802 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6803 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6804 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6805 /* 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
|
6806 * 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
|
6807 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6808 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6809 } |
7 | 6810 } |
6811 } | |
6812 #endif | |
6813 | |
1843 | 6814 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6815 force_redraw_this = force_redraw_next; | |
6816 force_redraw_next = FALSE; | |
6817 #endif | |
6818 | |
6819 need_redraw = ScreenLines[off] != c | |
7 | 6820 #ifdef FEAT_MBYTE |
6821 || (mbyte_cells == 2 | |
6822 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6823 || (enc_dbcs == DBCS_JPNU | |
6824 && c == 0x8e | |
6825 && ScreenLines2[off] != ptr[1]) | |
6826 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6827 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6828 (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
|
6829 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6830 && screen_comp_differs(off, u8cc)))) |
7 | 6831 #endif |
6832 || ScreenAttrs[off] != attr | |
1843 | 6833 || exmode_active; |
6834 | |
6835 if (need_redraw | |
6836 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6837 || force_redraw_this | |
6838 #endif | |
7 | 6839 ) |
6840 { | |
6841 #if defined(FEAT_GUI) || defined(UNIX) | |
6842 /* The bold trick makes a single row of pixels appear in the next | |
6843 * character. When a bold character is removed, the next | |
6844 * character should be redrawn too. This happens for our own GUI | |
1843 | 6845 * and for some xterms. */ |
6846 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6847 # ifdef FEAT_GUI |
6848 gui.in_use | |
6849 # endif | |
6850 # if defined(FEAT_GUI) && defined(UNIX) | |
6851 || | |
6852 # endif | |
6853 # ifdef UNIX | |
6854 term_is_xterm | |
6855 # endif | |
1843 | 6856 )) |
6857 { | |
6858 int n = ScreenAttrs[off]; | |
6859 | |
6860 if (n > HL_ALL) | |
6861 n = syn_attr2attr(n); | |
6862 if (n & HL_BOLD) | |
6863 force_redraw_next = TRUE; | |
7 | 6864 } |
6865 #endif | |
6866 #ifdef FEAT_MBYTE | |
6867 /* When at the end of the text and overwriting a two-cell | |
6868 * character with a one-cell character, need to clear the next | |
6869 * cell. Also when overwriting the left halve of a two-cell char | |
6870 * with the right halve of a two-cell char. Do this only once | |
6871 * (mb_off2cells() may return 2 on the right halve). */ | |
6872 if (clear_next_cell) | |
6873 clear_next_cell = FALSE; | |
6874 else if (has_mbyte | |
6875 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6876 : ptr + mbyte_blen >= text + len) | |
1378 | 6877 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6878 || (mbyte_cells == 2 |
1378 | 6879 && (*mb_off2cells)(off, max_off) == 1 |
6880 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6881 clear_next_cell = TRUE; |
6882 | |
6883 /* Make sure we never leave a second byte of a double-byte behind, | |
6884 * it confuses mb_off2cells(). */ | |
6885 if (enc_dbcs | |
1378 | 6886 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6887 || (mbyte_cells == 2 |
1378 | 6888 && (*mb_off2cells)(off, max_off) == 1 |
6889 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6890 ScreenLines[off + mbyte_blen] = 0; |
6891 #endif | |
6892 ScreenLines[off] = c; | |
6893 ScreenAttrs[off] = attr; | |
6894 #ifdef FEAT_MBYTE | |
6895 if (enc_utf8) | |
6896 { | |
714 | 6897 if (c < 0x80 && u8cc[0] == 0) |
7 | 6898 ScreenLinesUC[off] = 0; |
6899 else | |
6900 { | |
714 | 6901 int i; |
6902 | |
7 | 6903 ScreenLinesUC[off] = u8c; |
714 | 6904 for (i = 0; i < Screen_mco; ++i) |
6905 { | |
6906 ScreenLinesC[i][off] = u8cc[i]; | |
6907 if (u8cc[i] == 0) | |
6908 break; | |
6909 } | |
7 | 6910 } |
6911 if (mbyte_cells == 2) | |
6912 { | |
6913 ScreenLines[off + 1] = 0; | |
6914 ScreenAttrs[off + 1] = attr; | |
6915 } | |
6916 screen_char(off, row, col); | |
6917 } | |
6918 else if (mbyte_cells == 2) | |
6919 { | |
6920 ScreenLines[off + 1] = ptr[1]; | |
6921 ScreenAttrs[off + 1] = attr; | |
6922 screen_char_2(off, row, col); | |
6923 } | |
6924 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6925 { | |
6926 ScreenLines2[off] = ptr[1]; | |
6927 screen_char(off, row, col); | |
6928 } | |
6929 else | |
6930 #endif | |
6931 screen_char(off, row, col); | |
6932 } | |
6933 #ifdef FEAT_MBYTE | |
6934 if (has_mbyte) | |
6935 { | |
6936 off += mbyte_cells; | |
6937 col += mbyte_cells; | |
6938 ptr += mbyte_blen; | |
6939 if (clear_next_cell) | |
6940 ptr = (char_u *)" "; | |
6941 } | |
6942 else | |
6943 #endif | |
6944 { | |
6945 ++off; | |
6946 ++col; | |
6947 ++ptr; | |
6948 } | |
6949 } | |
1843 | 6950 |
6951 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6952 /* If we detected the next character needs to be redrawn, but the text | |
6953 * doesn't extend up to there, update the character here. */ | |
6954 if (force_redraw_next && col < screen_Columns) | |
6955 { | |
6956 # ifdef FEAT_MBYTE | |
6957 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6958 screen_char_2(off, row, col); | |
6959 else | |
6960 # endif | |
6961 screen_char(off, row, col); | |
6962 } | |
6963 #endif | |
7 | 6964 } |
6965 | |
6966 #ifdef FEAT_SEARCH_EXTRA | |
6967 /* | |
1326 | 6968 * Prepare for 'hlsearch' highlighting. |
7 | 6969 */ |
6970 static void | |
6971 start_search_hl() | |
6972 { | |
6973 if (p_hls && !no_hlsearch) | |
6974 { | |
6975 last_pat_prog(&search_hl.rm); | |
6976 search_hl.attr = hl_attr(HLF_L); | |
1521 | 6977 # ifdef FEAT_RELTIME |
6978 /* Set the time limit to 'redrawtime'. */ | |
6979 profile_setlimit(p_rdt, &search_hl.tm); | |
6980 # endif | |
7 | 6981 } |
6982 } | |
6983 | |
6984 /* | |
1326 | 6985 * Clean up for 'hlsearch' highlighting. |
7 | 6986 */ |
6987 static void | |
6988 end_search_hl() | |
6989 { | |
6990 if (search_hl.rm.regprog != NULL) | |
6991 { | |
6992 vim_free(search_hl.rm.regprog); | |
6993 search_hl.rm.regprog = NULL; | |
6994 } | |
6995 } | |
6996 | |
6997 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6998 * 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
|
6999 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7000 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7001 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7002 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7003 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7004 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7005 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7006 /* 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
|
7007 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7008 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7009 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7010 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7011 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7012 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7013 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7014 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7015 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
|
7016 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
|
7017 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7018 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7019 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7020 /* 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
|
7021 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
|
7022 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7023 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7024 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7025 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
|
7026 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7027 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7028 /* 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
|
7029 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7030 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7031 /* |
7 | 7032 * Advance to the match in window "wp" line "lnum" or past it. |
7033 */ | |
7034 static void | |
7035 prepare_search_hl(wp, lnum) | |
7036 win_T *wp; | |
7037 linenr_T lnum; | |
7038 { | |
1326 | 7039 matchitem_T *cur; /* points to the match list */ |
7040 match_T *shl; /* points to search_hl or a match */ | |
7041 int shl_flag; /* flag to indicate whether search_hl | |
7042 has been processed or not */ | |
7 | 7043 int n; |
7044 | |
7045 /* | |
7046 * When using a multi-line pattern, start searching at the top | |
7047 * of the window or just after a closed fold. | |
1326 | 7048 * Do this both for search_hl and the match list. |
7 | 7049 */ |
1326 | 7050 cur = wp->w_match_head; |
7051 shl_flag = FALSE; | |
7052 while (cur != NULL || shl_flag == FALSE) | |
7053 { | |
7054 if (shl_flag == FALSE) | |
7055 { | |
7056 shl = &search_hl; | |
7057 shl_flag = TRUE; | |
7058 } | |
7059 else | |
7060 shl = &cur->hl; | |
7 | 7061 if (shl->rm.regprog != NULL |
7062 && shl->lnum == 0 | |
7063 && re_multiline(shl->rm.regprog)) | |
7064 { | |
7065 if (shl->first_lnum == 0) | |
7066 { | |
7067 # ifdef FEAT_FOLDING | |
7068 for (shl->first_lnum = lnum; | |
7069 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7070 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7071 NULL, NULL, TRUE, NULL)) | |
7072 break; | |
7073 # else | |
7074 shl->first_lnum = wp->w_topline; | |
7075 # endif | |
7076 } | |
7077 n = 0; | |
7078 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7079 { | |
7080 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7081 if (shl->lnum != 0) | |
7082 { | |
7083 shl->first_lnum = shl->lnum | |
7084 + shl->rm.endpos[0].lnum | |
7085 - shl->rm.startpos[0].lnum; | |
7086 n = shl->rm.endpos[0].col; | |
7087 } | |
7088 else | |
7089 { | |
7090 ++shl->first_lnum; | |
7091 n = 0; | |
7092 } | |
7093 } | |
7094 } | |
1326 | 7095 if (shl != &search_hl && cur != NULL) |
7096 cur = cur->next; | |
7 | 7097 } |
7098 } | |
7099 | |
7100 /* | |
1326 | 7101 * Search for a next 'hlsearch' or match. |
7 | 7102 * Uses shl->buf. |
7103 * Sets shl->lnum and shl->rm contents. | |
7104 * Note: Assumes a previous match is always before "lnum", unless | |
7105 * shl->lnum is zero. | |
7106 * Careful: Any pointers for buffer lines will become invalid. | |
7107 */ | |
7108 static void | |
7109 next_search_hl(win, shl, lnum, mincol) | |
7110 win_T *win; | |
1326 | 7111 match_T *shl; /* points to search_hl or a match */ |
7 | 7112 linenr_T lnum; |
7113 colnr_T mincol; /* minimal column for a match */ | |
7114 { | |
7115 linenr_T l; | |
7116 colnr_T matchcol; | |
7117 long nmatched; | |
7118 | |
7119 if (shl->lnum != 0) | |
7120 { | |
7121 /* Check for three situations: | |
7122 * 1. If the "lnum" is below a previous match, start a new search. | |
7123 * 2. If the previous match includes "mincol", use it. | |
7124 * 3. Continue after the previous match. | |
7125 */ | |
7126 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7127 if (lnum > l) | |
7128 shl->lnum = 0; | |
7129 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7130 return; | |
7131 } | |
7132 | |
7133 /* | |
7134 * Repeat searching for a match until one is found that includes "mincol" | |
7135 * or none is found in this line. | |
7136 */ | |
7137 called_emsg = FALSE; | |
7138 for (;;) | |
7139 { | |
1521 | 7140 #ifdef FEAT_RELTIME |
7141 /* Stop searching after passing the time limit. */ | |
7142 if (profile_passed_limit(&(shl->tm))) | |
7143 { | |
7144 shl->lnum = 0; /* no match found in time */ | |
7145 break; | |
7146 } | |
7147 #endif | |
7 | 7148 /* Three situations: |
7149 * 1. No useful previous match: search from start of line. | |
7150 * 2. Not Vi compatible or empty match: continue at next character. | |
7151 * Break the loop if this is beyond the end of the line. | |
7152 * 3. Vi compatible searching: continue at end of previous match. | |
7153 */ | |
7154 if (shl->lnum == 0) | |
7155 matchcol = 0; | |
7156 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7157 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7158 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7159 { | |
688 | 7160 char_u *ml; |
685 | 7161 |
7162 matchcol = shl->rm.startpos[0].col; | |
688 | 7163 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7164 if (*ml == NUL) |
7165 { | |
7166 ++matchcol; | |
7 | 7167 shl->lnum = 0; |
7168 break; | |
7169 } | |
685 | 7170 #ifdef FEAT_MBYTE |
7171 if (has_mbyte) | |
7172 matchcol += mb_ptr2len(ml); | |
7173 else | |
7174 #endif | |
7175 ++matchcol; | |
7 | 7176 } |
7177 else | |
7178 matchcol = shl->rm.endpos[0].col; | |
7179 | |
7180 shl->lnum = lnum; | |
1521 | 7181 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7182 #ifdef FEAT_RELTIME | |
7183 &(shl->tm) | |
7184 #else | |
7185 NULL | |
7186 #endif | |
7187 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7188 if (called_emsg || got_int) |
7 | 7189 { |
7190 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7191 if (shl == &search_hl) |
7192 { | |
1326 | 7193 /* don't free regprog in the match list, it's a copy */ |
1112 | 7194 vim_free(shl->rm.regprog); |
7195 no_hlsearch = TRUE; | |
7196 } | |
7 | 7197 shl->rm.regprog = NULL; |
1112 | 7198 shl->lnum = 0; |
7199 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7200 break; |
7201 } | |
7202 if (nmatched == 0) | |
7203 { | |
7204 shl->lnum = 0; /* no match found */ | |
7205 break; | |
7206 } | |
7207 if (shl->rm.startpos[0].lnum > 0 | |
7208 || shl->rm.startpos[0].col >= mincol | |
7209 || nmatched > 1 | |
7210 || shl->rm.endpos[0].col > mincol) | |
7211 { | |
7212 shl->lnum += shl->rm.startpos[0].lnum; | |
7213 break; /* useful match found */ | |
7214 } | |
7215 } | |
7216 } | |
7217 #endif | |
7218 | |
7219 static void | |
7220 screen_start_highlight(attr) | |
7221 int attr; | |
7222 { | |
7223 attrentry_T *aep = NULL; | |
7224 | |
7225 screen_attr = attr; | |
7226 if (full_screen | |
7227 #ifdef WIN3264 | |
7228 && termcap_active | |
7229 #endif | |
7230 ) | |
7231 { | |
7232 #ifdef FEAT_GUI | |
7233 if (gui.in_use) | |
7234 { | |
7235 char buf[20]; | |
7236 | |
681 | 7237 /* The GUI handles this internally. */ |
7238 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7239 OUT_STR(buf); |
7240 } | |
7241 else | |
7242 #endif | |
7243 { | |
7244 if (attr > HL_ALL) /* special HL attr. */ | |
7245 { | |
7246 if (t_colors > 1) | |
7247 aep = syn_cterm_attr2entry(attr); | |
7248 else | |
7249 aep = syn_term_attr2entry(attr); | |
7250 if (aep == NULL) /* did ":syntax clear" */ | |
7251 attr = 0; | |
7252 else | |
7253 attr = aep->ae_attr; | |
7254 } | |
7255 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7256 out_str(T_MD); | |
681 | 7257 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7258 && cterm_normal_fg_bold) | |
7259 /* If the Normal FG color has BOLD attribute and the new HL | |
7260 * has a FG color defined, clear BOLD. */ | |
7261 out_str(T_ME); | |
7 | 7262 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7263 out_str(T_SO); | |
205 | 7264 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7265 /* underline or undercurl */ | |
7 | 7266 out_str(T_US); |
7267 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7268 out_str(T_CZH); | |
7269 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7270 out_str(T_MR); | |
7271 | |
7272 /* | |
7273 * Output the color or start string after bold etc., in case the | |
7274 * bold etc. override the color setting. | |
7275 */ | |
7276 if (aep != NULL) | |
7277 { | |
7278 if (t_colors > 1) | |
7279 { | |
7280 if (aep->ae_u.cterm.fg_color) | |
7281 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7282 if (aep->ae_u.cterm.bg_color) | |
7283 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7284 } | |
7285 else | |
7286 { | |
7287 if (aep->ae_u.term.start != NULL) | |
7288 out_str(aep->ae_u.term.start); | |
7289 } | |
7290 } | |
7291 } | |
7292 } | |
7293 } | |
7294 | |
7295 void | |
7296 screen_stop_highlight() | |
7297 { | |
7298 int do_ME = FALSE; /* output T_ME code */ | |
7299 | |
7300 if (screen_attr != 0 | |
7301 #ifdef WIN3264 | |
7302 && termcap_active | |
7303 #endif | |
7304 ) | |
7305 { | |
7306 #ifdef FEAT_GUI | |
7307 if (gui.in_use) | |
7308 { | |
7309 char buf[20]; | |
7310 | |
7311 /* use internal GUI code */ | |
7312 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7313 OUT_STR(buf); | |
7314 } | |
7315 else | |
7316 #endif | |
7317 { | |
7318 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7319 { | |
7320 attrentry_T *aep; | |
7321 | |
7322 if (t_colors > 1) | |
7323 { | |
7324 /* | |
7325 * Assume that t_me restores the original colors! | |
7326 */ | |
7327 aep = syn_cterm_attr2entry(screen_attr); | |
7328 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7329 || aep->ae_u.cterm.bg_color)) | |
7330 do_ME = TRUE; | |
7331 } | |
7332 else | |
7333 { | |
7334 aep = syn_term_attr2entry(screen_attr); | |
7335 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7336 { | |
7337 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7338 do_ME = TRUE; | |
7339 else | |
7340 out_str(aep->ae_u.term.stop); | |
7341 } | |
7342 } | |
7343 if (aep == NULL) /* did ":syntax clear" */ | |
7344 screen_attr = 0; | |
7345 else | |
7346 screen_attr = aep->ae_attr; | |
7347 } | |
7348 | |
7349 /* | |
7350 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7351 * same sequence several times. | |
7352 */ | |
7353 if (screen_attr & HL_STANDOUT) | |
7354 { | |
7355 if (STRCMP(T_SE, T_ME) == 0) | |
7356 do_ME = TRUE; | |
7357 else | |
7358 out_str(T_SE); | |
7359 } | |
205 | 7360 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7361 { |
7362 if (STRCMP(T_UE, T_ME) == 0) | |
7363 do_ME = TRUE; | |
7364 else | |
7365 out_str(T_UE); | |
7366 } | |
7367 if (screen_attr & HL_ITALIC) | |
7368 { | |
7369 if (STRCMP(T_CZR, T_ME) == 0) | |
7370 do_ME = TRUE; | |
7371 else | |
7372 out_str(T_CZR); | |
7373 } | |
7374 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7375 out_str(T_ME); | |
7376 | |
7377 if (t_colors > 1) | |
7378 { | |
7379 /* set Normal cterm colors */ | |
7380 if (cterm_normal_fg_color != 0) | |
7381 term_fg_color(cterm_normal_fg_color - 1); | |
7382 if (cterm_normal_bg_color != 0) | |
7383 term_bg_color(cterm_normal_bg_color - 1); | |
7384 if (cterm_normal_fg_bold) | |
7385 out_str(T_MD); | |
7386 } | |
7387 } | |
7388 } | |
7389 screen_attr = 0; | |
7390 } | |
7391 | |
7392 /* | |
7393 * Reset the colors for a cterm. Used when leaving Vim. | |
7394 * The machine specific code may override this again. | |
7395 */ | |
7396 void | |
7397 reset_cterm_colors() | |
7398 { | |
7399 if (t_colors > 1) | |
7400 { | |
7401 /* set Normal cterm colors */ | |
7402 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7403 { | |
7404 out_str(T_OP); | |
7405 screen_attr = -1; | |
7406 } | |
7407 if (cterm_normal_fg_bold) | |
7408 { | |
7409 out_str(T_ME); | |
7410 screen_attr = -1; | |
7411 } | |
7412 } | |
7413 } | |
7414 | |
7415 /* | |
7416 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7417 * using the attributes from ScreenAttrs["off"]. | |
7418 */ | |
7419 static void | |
7420 screen_char(off, row, col) | |
7421 unsigned off; | |
7422 int row; | |
7423 int col; | |
7424 { | |
7425 int attr; | |
7426 | |
7427 /* Check for illegal values, just in case (could happen just after | |
7428 * resizing). */ | |
7429 if (row >= screen_Rows || col >= screen_Columns) | |
7430 return; | |
7431 | |
7432 /* Outputting the last character on the screen may scrollup the screen. | |
7433 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7434 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7435 #ifdef FEAT_RIGHTLEFT | |
7436 /* account for first command-line character in rightleft mode */ | |
7437 && !cmdmsg_rl | |
7438 #endif | |
7439 ) | |
7440 { | |
7441 ScreenAttrs[off] = (sattr_T)-1; | |
7442 return; | |
7443 } | |
7444 | |
7445 /* | |
7446 * Stop highlighting first, so it's easier to move the cursor. | |
7447 */ | |
7448 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7449 if (screen_char_attr != 0) | |
7450 attr = screen_char_attr; | |
7451 else | |
7452 #endif | |
7453 attr = ScreenAttrs[off]; | |
7454 if (screen_attr != attr) | |
7455 screen_stop_highlight(); | |
7456 | |
7457 windgoto(row, col); | |
7458 | |
7459 if (screen_attr != attr) | |
7460 screen_start_highlight(attr); | |
7461 | |
7462 #ifdef FEAT_MBYTE | |
7463 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7464 { | |
7465 char_u buf[MB_MAXBYTES + 1]; | |
7466 | |
7467 /* Convert UTF-8 character to bytes and write it. */ | |
7468 | |
7469 buf[utfc_char2bytes(off, buf)] = NUL; | |
7470 | |
7471 out_str(buf); | |
7472 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7473 ++screen_cur_col; | |
7474 } | |
7475 else | |
7476 #endif | |
7477 { | |
7478 #ifdef FEAT_MBYTE | |
7479 out_flush_check(); | |
7480 #endif | |
7481 out_char(ScreenLines[off]); | |
7482 #ifdef FEAT_MBYTE | |
7483 /* double-byte character in single-width cell */ | |
7484 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7485 out_char(ScreenLines2[off]); | |
7486 #endif | |
7487 } | |
7488 | |
7489 screen_cur_col++; | |
7490 } | |
7491 | |
7492 #ifdef FEAT_MBYTE | |
7493 | |
7494 /* | |
7495 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7496 * on the screen at position 'row' and 'col'. | |
7497 * The attributes of the first byte is used for all. This is required to | |
7498 * output the two bytes of a double-byte character with nothing in between. | |
7499 */ | |
7500 static void | |
7501 screen_char_2(off, row, col) | |
7502 unsigned off; | |
7503 int row; | |
7504 int col; | |
7505 { | |
7506 /* Check for illegal values (could be wrong when screen was resized). */ | |
7507 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7508 return; | |
7509 | |
7510 /* Outputting the last character on the screen may scrollup the screen. | |
7511 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7512 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7513 { | |
7514 ScreenAttrs[off] = (sattr_T)-1; | |
7515 return; | |
7516 } | |
7517 | |
7518 /* Output the first byte normally (positions the cursor), then write the | |
7519 * second byte directly. */ | |
7520 screen_char(off, row, col); | |
7521 out_char(ScreenLines[off + 1]); | |
7522 ++screen_cur_col; | |
7523 } | |
7524 #endif | |
7525 | |
7526 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7527 /* | |
7528 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7529 * This uses the contents of ScreenLines[] and doesn't change it. | |
7530 */ | |
7531 void | |
7532 screen_draw_rectangle(row, col, height, width, invert) | |
7533 int row; | |
7534 int col; | |
7535 int height; | |
7536 int width; | |
7537 int invert; | |
7538 { | |
7539 int r, c; | |
7540 int off; | |
1378 | 7541 #ifdef FEAT_MBYTE |
7542 int max_off; | |
7543 #endif | |
7 | 7544 |
534 | 7545 /* Can't use ScreenLines unless initialized */ |
7546 if (ScreenLines == NULL) | |
7547 return; | |
7548 | |
7 | 7549 if (invert) |
7550 screen_char_attr = HL_INVERSE; | |
7551 for (r = row; r < row + height; ++r) | |
7552 { | |
7553 off = LineOffset[r]; | |
1378 | 7554 #ifdef FEAT_MBYTE |
7555 max_off = off + screen_Columns; | |
7556 #endif | |
7 | 7557 for (c = col; c < col + width; ++c) |
7558 { | |
7559 #ifdef FEAT_MBYTE | |
1378 | 7560 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7561 { |
7562 screen_char_2(off + c, r, c); | |
7563 ++c; | |
7564 } | |
7565 else | |
7566 #endif | |
7567 { | |
7568 screen_char(off + c, r, c); | |
7569 #ifdef FEAT_MBYTE | |
1378 | 7570 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7571 ++c; |
7572 #endif | |
7573 } | |
7574 } | |
7575 } | |
7576 screen_char_attr = 0; | |
7577 } | |
7578 #endif | |
7579 | |
7580 #ifdef FEAT_VERTSPLIT | |
7581 /* | |
7582 * Redraw the characters for a vertically split window. | |
7583 */ | |
7584 static void | |
7585 redraw_block(row, end, wp) | |
7586 int row; | |
7587 int end; | |
7588 win_T *wp; | |
7589 { | |
7590 int col; | |
7591 int width; | |
7592 | |
7593 # ifdef FEAT_CLIPBOARD | |
7594 clip_may_clear_selection(row, end - 1); | |
7595 # endif | |
7596 | |
7597 if (wp == NULL) | |
7598 { | |
7599 col = 0; | |
7600 width = Columns; | |
7601 } | |
7602 else | |
7603 { | |
7604 col = wp->w_wincol; | |
7605 width = wp->w_width; | |
7606 } | |
7607 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7608 } | |
7609 #endif | |
7610 | |
7611 /* | |
7612 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7613 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7614 * Use attributes 'attr'. | |
7615 */ | |
7616 void | |
7617 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7618 int start_row, end_row; | |
7619 int start_col, end_col; | |
7620 int c1, c2; | |
7621 int attr; | |
7622 { | |
7623 int row; | |
7624 int col; | |
7625 int off; | |
7626 int end_off; | |
7627 int did_delete; | |
7628 int c; | |
7629 int norm_term; | |
7630 #if defined(FEAT_GUI) || defined(UNIX) | |
7631 int force_next = FALSE; | |
7632 #endif | |
7633 | |
7634 if (end_row > screen_Rows) /* safety check */ | |
7635 end_row = screen_Rows; | |
7636 if (end_col > screen_Columns) /* safety check */ | |
7637 end_col = screen_Columns; | |
7638 if (ScreenLines == NULL | |
7639 || start_row >= end_row | |
7640 || start_col >= end_col) /* nothing to do */ | |
7641 return; | |
7642 | |
7643 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7644 norm_term = ( | |
7645 #ifdef FEAT_GUI | |
7646 !gui.in_use && | |
7647 #endif | |
7648 t_colors <= 1); | |
7649 for (row = start_row; row < end_row; ++row) | |
7650 { | |
1668 | 7651 #ifdef FEAT_MBYTE |
7652 if (has_mbyte | |
7653 # ifdef FEAT_GUI | |
7654 && !gui.in_use | |
7655 # endif | |
7656 ) | |
7657 { | |
7658 /* When drawing over the right halve of a double-wide char clear | |
7659 * out the left halve. When drawing over the left halve of a | |
7660 * double wide-char clear out the right halve. Only needed in a | |
7661 * terminal. */ | |
1685 | 7662 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7663 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7664 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7665 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7666 } |
7667 #endif | |
7 | 7668 /* |
7669 * Try to use delete-line termcap code, when no attributes or in a | |
7670 * "normal" terminal, where a bold/italic space is just a | |
7671 * space. | |
7672 */ | |
7673 did_delete = FALSE; | |
7674 if (c2 == ' ' | |
7675 && end_col == Columns | |
7676 && can_clear(T_CE) | |
7677 && (attr == 0 | |
7678 || (norm_term | |
7679 && attr <= HL_ALL | |
7680 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7681 { | |
7682 /* | |
7683 * check if we really need to clear something | |
7684 */ | |
7685 col = start_col; | |
7686 if (c1 != ' ') /* don't clear first char */ | |
7687 ++col; | |
7688 | |
7689 off = LineOffset[row] + col; | |
7690 end_off = LineOffset[row] + end_col; | |
7691 | |
7692 /* skip blanks (used often, keep it fast!) */ | |
7693 #ifdef FEAT_MBYTE | |
7694 if (enc_utf8) | |
7695 while (off < end_off && ScreenLines[off] == ' ' | |
7696 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7697 ++off; | |
7698 else | |
7699 #endif | |
7700 while (off < end_off && ScreenLines[off] == ' ' | |
7701 && ScreenAttrs[off] == 0) | |
7702 ++off; | |
7703 if (off < end_off) /* something to be cleared */ | |
7704 { | |
7705 col = off - LineOffset[row]; | |
7706 screen_stop_highlight(); | |
7707 term_windgoto(row, col);/* clear rest of this screen line */ | |
7708 out_str(T_CE); | |
7709 screen_start(); /* don't know where cursor is now */ | |
7710 col = end_col - col; | |
7711 while (col--) /* clear chars in ScreenLines */ | |
7712 { | |
7713 ScreenLines[off] = ' '; | |
7714 #ifdef FEAT_MBYTE | |
7715 if (enc_utf8) | |
7716 ScreenLinesUC[off] = 0; | |
7717 #endif | |
7718 ScreenAttrs[off] = 0; | |
7719 ++off; | |
7720 } | |
7721 } | |
7722 did_delete = TRUE; /* the chars are cleared now */ | |
7723 } | |
7724 | |
7725 off = LineOffset[row] + start_col; | |
7726 c = c1; | |
7727 for (col = start_col; col < end_col; ++col) | |
7728 { | |
7729 if (ScreenLines[off] != c | |
7730 #ifdef FEAT_MBYTE | |
714 | 7731 || (enc_utf8 && (int)ScreenLinesUC[off] |
7732 != (c >= 0x80 ? c : 0)) | |
7 | 7733 #endif |
7734 || ScreenAttrs[off] != attr | |
7735 #if defined(FEAT_GUI) || defined(UNIX) | |
7736 || force_next | |
7737 #endif | |
7738 ) | |
7739 { | |
7740 #if defined(FEAT_GUI) || defined(UNIX) | |
7741 /* The bold trick may make a single row of pixels appear in | |
7742 * the next character. When a bold character is removed, the | |
7743 * next character should be redrawn too. This happens for our | |
7744 * own GUI and for some xterms. */ | |
7745 if ( | |
7746 # ifdef FEAT_GUI | |
7747 gui.in_use | |
7748 # endif | |
7749 # if defined(FEAT_GUI) && defined(UNIX) | |
7750 || | |
7751 # endif | |
7752 # ifdef UNIX | |
7753 term_is_xterm | |
7754 # endif | |
7755 ) | |
7756 { | |
7757 if (ScreenLines[off] != ' ' | |
7758 && (ScreenAttrs[off] > HL_ALL | |
7759 || ScreenAttrs[off] & HL_BOLD)) | |
7760 force_next = TRUE; | |
7761 else | |
7762 force_next = FALSE; | |
7763 } | |
7764 #endif | |
7765 ScreenLines[off] = c; | |
7766 #ifdef FEAT_MBYTE | |
7767 if (enc_utf8) | |
7768 { | |
7769 if (c >= 0x80) | |
7770 { | |
7771 ScreenLinesUC[off] = c; | |
714 | 7772 ScreenLinesC[0][off] = 0; |
7 | 7773 } |
7774 else | |
7775 ScreenLinesUC[off] = 0; | |
7776 } | |
7777 #endif | |
7778 ScreenAttrs[off] = attr; | |
7779 if (!did_delete || c != ' ') | |
7780 screen_char(off, row, col); | |
7781 } | |
7782 ++off; | |
7783 if (col == start_col) | |
7784 { | |
7785 if (did_delete) | |
7786 break; | |
7787 c = c2; | |
7788 } | |
7789 } | |
7790 if (end_col == Columns) | |
7791 LineWraps[row] = FALSE; | |
7792 if (row == Rows - 1) /* overwritten the command line */ | |
7793 { | |
7794 redraw_cmdline = TRUE; | |
7795 if (c1 == ' ' && c2 == ' ') | |
7796 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7797 if (start_col == 0) |
7798 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7799 } |
7800 } | |
7801 } | |
7802 | |
7803 /* | |
7804 * Check if there should be a delay. Used before clearing or redrawing the | |
7805 * screen or the command line. | |
7806 */ | |
7807 void | |
7808 check_for_delay(check_msg_scroll) | |
7809 int check_msg_scroll; | |
7810 { | |
7811 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7812 && !did_wait_return | |
7813 && emsg_silent == 0) | |
7814 { | |
7815 out_flush(); | |
7816 ui_delay(1000L, TRUE); | |
7817 emsg_on_display = FALSE; | |
7818 if (check_msg_scroll) | |
7819 msg_scroll = FALSE; | |
7820 } | |
7821 } | |
7822 | |
7823 /* | |
7824 * screen_valid - allocate screen buffers if size changed | |
7825 * If "clear" is TRUE: clear screen if it has been resized. | |
7826 * Returns TRUE if there is a valid screen to write to. | |
7827 * Returns FALSE when starting up and screen not initialized yet. | |
7828 */ | |
7829 int | |
7830 screen_valid(clear) | |
7831 int clear; | |
7832 { | |
7833 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7834 return (ScreenLines != NULL); | |
7835 } | |
7836 | |
7837 /* | |
7838 * Resize the shell to Rows and Columns. | |
7839 * Allocate ScreenLines[] and associated items. | |
7840 * | |
7841 * There may be some time between setting Rows and Columns and (re)allocating | |
7842 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7843 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7844 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7845 * final size of the shell is needed. | |
7846 */ | |
7847 void | |
7848 screenalloc(clear) | |
7849 int clear; | |
7850 { | |
7851 int new_row, old_row; | |
7852 #ifdef FEAT_GUI | |
7853 int old_Rows; | |
7854 #endif | |
7855 win_T *wp; | |
7856 int outofmem = FALSE; | |
7857 int len; | |
7858 schar_T *new_ScreenLines; | |
7859 #ifdef FEAT_MBYTE | |
7860 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7861 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7862 schar_T *new_ScreenLines2 = NULL; |
714 | 7863 int i; |
7 | 7864 #endif |
7865 sattr_T *new_ScreenAttrs; | |
7866 unsigned *new_LineOffset; | |
7867 char_u *new_LineWraps; | |
671 | 7868 #ifdef FEAT_WINDOWS |
681 | 7869 short *new_TabPageIdxs; |
671 | 7870 tabpage_T *tp; |
7871 #endif | |
7 | 7872 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7873 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7874 #ifdef FEAT_AUTOCMD |
7875 int retry_count = 0; | |
7876 | |
7877 retry: | |
7878 #endif | |
7 | 7879 /* |
7880 * Allocation of the screen buffers is done only when the size changes and | |
7881 * when Rows and Columns have been set and we have started doing full | |
7882 * screen stuff. | |
7883 */ | |
7884 if ((ScreenLines != NULL | |
7885 && Rows == screen_Rows | |
7886 && Columns == screen_Columns | |
7887 #ifdef FEAT_MBYTE | |
7888 && enc_utf8 == (ScreenLinesUC != NULL) | |
7889 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7890 && p_mco == Screen_mco |
7 | 7891 #endif |
7892 ) | |
7893 || Rows == 0 | |
7894 || Columns == 0 | |
7895 || (!full_screen && ScreenLines == NULL)) | |
7896 return; | |
7897 | |
7898 /* | |
7899 * It's possible that we produce an out-of-memory message below, which | |
7900 * will cause this function to be called again. To break the loop, just | |
7901 * return here. | |
7902 */ | |
7903 if (entered) | |
7904 return; | |
7905 entered = TRUE; | |
7906 | |
911 | 7907 /* |
7908 * Note that the window sizes are updated before reallocating the arrays, | |
7909 * thus we must not redraw here! | |
7910 */ | |
7911 ++RedrawingDisabled; | |
7912 | |
7 | 7913 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7914 | |
7915 comp_col(); /* recompute columns for shown command and ruler */ | |
7916 | |
7917 /* | |
7918 * We're changing the size of the screen. | |
7919 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7920 * - Move lines from the old arrays into the new arrays, clear extra | |
7921 * lines (unless the screen is going to be cleared). | |
7922 * - Free the old arrays. | |
7923 * | |
7924 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7925 * Continuing with the old ScreenLines may result in a crash, because the | |
7926 * size is wrong. | |
7927 */ | |
671 | 7928 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7929 win_free_lsize(wp); |
1946 | 7930 #ifdef FEAT_AUTOCMD |
7931 if (aucmd_win != NULL) | |
7932 win_free_lsize(aucmd_win); | |
7933 #endif | |
7 | 7934 |
7935 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7936 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7937 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7938 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7939 if (enc_utf8) |
7940 { | |
7941 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7942 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7943 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7944 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7945 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7946 } | |
7947 if (enc_dbcs == DBCS_JPNU) | |
7948 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7949 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7950 #endif | |
7951 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7952 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7953 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7954 Rows * sizeof(unsigned)), FALSE); | |
7955 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7956 #ifdef FEAT_WINDOWS |
681 | 7957 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7958 #endif |
7 | 7959 |
677 | 7960 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7961 { |
7962 if (win_alloc_lines(wp) == FAIL) | |
7963 { | |
7964 outofmem = TRUE; | |
7965 #ifdef FEAT_WINDOWS | |
1819 | 7966 goto give_up; |
7967 #endif | |
7968 } | |
7969 } | |
1906 | 7970 #ifdef FEAT_AUTOCMD |
1946 | 7971 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7972 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7973 outofmem = TRUE; |
7974 #endif | |
1819 | 7975 #ifdef FEAT_WINDOWS |
7976 give_up: | |
7977 #endif | |
7 | 7978 |
714 | 7979 #ifdef FEAT_MBYTE |
7980 for (i = 0; i < p_mco; ++i) | |
7981 if (new_ScreenLinesC[i] == NULL) | |
7982 break; | |
7983 #endif | |
7 | 7984 if (new_ScreenLines == NULL |
7985 #ifdef FEAT_MBYTE | |
714 | 7986 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 7987 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
7988 #endif | |
7989 || new_ScreenAttrs == NULL | |
7990 || new_LineOffset == NULL | |
7991 || new_LineWraps == NULL | |
671 | 7992 #ifdef FEAT_WINDOWS |
7993 || new_TabPageIdxs == NULL | |
7994 #endif | |
7 | 7995 || outofmem) |
7996 { | |
944 | 7997 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 7998 { |
7999 /* guess the size */ | |
8000 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
8001 | |
8002 /* Remember we did this to avoid getting outofmem messages over | |
8003 * and over again. */ | |
944 | 8004 done_outofmem_msg = TRUE; |
534 | 8005 } |
7 | 8006 vim_free(new_ScreenLines); |
8007 new_ScreenLines = NULL; | |
8008 #ifdef FEAT_MBYTE | |
8009 vim_free(new_ScreenLinesUC); | |
8010 new_ScreenLinesUC = NULL; | |
714 | 8011 for (i = 0; i < p_mco; ++i) |
8012 { | |
8013 vim_free(new_ScreenLinesC[i]); | |
8014 new_ScreenLinesC[i] = NULL; | |
8015 } | |
7 | 8016 vim_free(new_ScreenLines2); |
8017 new_ScreenLines2 = NULL; | |
8018 #endif | |
8019 vim_free(new_ScreenAttrs); | |
8020 new_ScreenAttrs = NULL; | |
8021 vim_free(new_LineOffset); | |
8022 new_LineOffset = NULL; | |
8023 vim_free(new_LineWraps); | |
8024 new_LineWraps = NULL; | |
671 | 8025 #ifdef FEAT_WINDOWS |
8026 vim_free(new_TabPageIdxs); | |
8027 new_TabPageIdxs = NULL; | |
8028 #endif | |
7 | 8029 } |
8030 else | |
8031 { | |
944 | 8032 done_outofmem_msg = FALSE; |
534 | 8033 |
7 | 8034 for (new_row = 0; new_row < Rows; ++new_row) |
8035 { | |
8036 new_LineOffset[new_row] = new_row * Columns; | |
8037 new_LineWraps[new_row] = FALSE; | |
8038 | |
8039 /* | |
8040 * If the screen is not going to be cleared, copy as much as | |
8041 * possible from the old screen to the new one and clear the rest | |
8042 * (used when resizing the window at the "--more--" prompt or when | |
8043 * executing an external command, for the GUI). | |
8044 */ | |
8045 if (!clear) | |
8046 { | |
8047 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
8048 ' ', (size_t)Columns * sizeof(schar_T)); | |
8049 #ifdef FEAT_MBYTE | |
8050 if (enc_utf8) | |
8051 { | |
8052 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
8053 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 8054 for (i = 0; i < p_mco; ++i) |
8055 (void)vim_memset(new_ScreenLinesC[i] | |
8056 + new_row * Columns, | |
7 | 8057 0, (size_t)Columns * sizeof(u8char_T)); |
8058 } | |
8059 if (enc_dbcs == DBCS_JPNU) | |
8060 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8061 0, (size_t)Columns * sizeof(schar_T)); | |
8062 #endif | |
8063 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8064 0, (size_t)Columns * sizeof(sattr_T)); | |
8065 old_row = new_row + (screen_Rows - Rows); | |
534 | 8066 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8067 { |
8068 if (screen_Columns < Columns) | |
8069 len = screen_Columns; | |
8070 else | |
8071 len = Columns; | |
26 | 8072 #ifdef FEAT_MBYTE |
571 | 8073 /* When switching to utf-8 don't copy characters, they |
714 | 8074 * may be invalid now. Also when p_mco changes. */ |
8075 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8076 && p_mco == Screen_mco) | |
26 | 8077 #endif |
8078 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8079 ScreenLines + LineOffset[old_row], | |
8080 (size_t)len * sizeof(schar_T)); | |
7 | 8081 #ifdef FEAT_MBYTE |
714 | 8082 if (enc_utf8 && ScreenLinesUC != NULL |
8083 && p_mco == Screen_mco) | |
7 | 8084 { |
8085 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8086 ScreenLinesUC + LineOffset[old_row], | |
8087 (size_t)len * sizeof(u8char_T)); | |
714 | 8088 for (i = 0; i < p_mco; ++i) |
8089 mch_memmove(new_ScreenLinesC[i] | |
8090 + new_LineOffset[new_row], | |
8091 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8092 (size_t)len * sizeof(u8char_T)); |
8093 } | |
8094 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8095 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8096 ScreenLines2 + LineOffset[old_row], | |
8097 (size_t)len * sizeof(schar_T)); | |
8098 #endif | |
8099 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8100 ScreenAttrs + LineOffset[old_row], | |
8101 (size_t)len * sizeof(sattr_T)); | |
8102 } | |
8103 } | |
8104 } | |
8105 /* Use the last line of the screen for the current line. */ | |
8106 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8107 } | |
8108 | |
356 | 8109 free_screenlines(); |
8110 | |
7 | 8111 ScreenLines = new_ScreenLines; |
8112 #ifdef FEAT_MBYTE | |
8113 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8114 for (i = 0; i < p_mco; ++i) |
8115 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8116 Screen_mco = p_mco; | |
7 | 8117 ScreenLines2 = new_ScreenLines2; |
8118 #endif | |
8119 ScreenAttrs = new_ScreenAttrs; | |
8120 LineOffset = new_LineOffset; | |
8121 LineWraps = new_LineWraps; | |
671 | 8122 #ifdef FEAT_WINDOWS |
8123 TabPageIdxs = new_TabPageIdxs; | |
8124 #endif | |
7 | 8125 |
8126 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8127 * size of ScreenLines[]. Set them before calling anything. */ | |
8128 #ifdef FEAT_GUI | |
8129 old_Rows = screen_Rows; | |
8130 #endif | |
8131 screen_Rows = Rows; | |
8132 screen_Columns = Columns; | |
8133 | |
8134 must_redraw = CLEAR; /* need to clear the screen later */ | |
8135 if (clear) | |
8136 screenclear2(); | |
8137 | |
8138 #ifdef FEAT_GUI | |
8139 else if (gui.in_use | |
8140 && !gui.starting | |
8141 && ScreenLines != NULL | |
8142 && old_Rows != Rows) | |
8143 { | |
8144 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8145 /* | |
8146 * Adjust the position of the cursor, for when executing an external | |
8147 * command. | |
8148 */ | |
8149 if (msg_row >= Rows) /* Rows got smaller */ | |
8150 msg_row = Rows - 1; /* put cursor at last row */ | |
8151 else if (Rows > old_Rows) /* Rows got bigger */ | |
8152 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8153 if (msg_col >= Columns) /* Columns got smaller */ | |
8154 msg_col = Columns - 1; /* put cursor at last column */ | |
8155 } | |
8156 #endif | |
8157 | |
8158 entered = FALSE; | |
911 | 8159 --RedrawingDisabled; |
766 | 8160 |
8161 #ifdef FEAT_AUTOCMD | |
1824 | 8162 /* |
8163 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8164 * in case applying autocommands always changes Rows or Columns. | |
8165 */ | |
8166 if (starting == 0 && ++retry_count <= 3) | |
8167 { | |
766 | 8168 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8169 /* In rare cases, autocommands may have altered Rows or Columns, |
8170 * jump back to check if we need to allocate the screen again. */ | |
8171 goto retry; | |
8172 } | |
766 | 8173 #endif |
7 | 8174 } |
8175 | |
8176 void | |
356 | 8177 free_screenlines() |
8178 { | |
8179 #ifdef FEAT_MBYTE | |
714 | 8180 int i; |
8181 | |
356 | 8182 vim_free(ScreenLinesUC); |
714 | 8183 for (i = 0; i < Screen_mco; ++i) |
8184 vim_free(ScreenLinesC[i]); | |
356 | 8185 vim_free(ScreenLines2); |
8186 #endif | |
714 | 8187 vim_free(ScreenLines); |
356 | 8188 vim_free(ScreenAttrs); |
8189 vim_free(LineOffset); | |
8190 vim_free(LineWraps); | |
671 | 8191 #ifdef FEAT_WINDOWS |
8192 vim_free(TabPageIdxs); | |
8193 #endif | |
356 | 8194 } |
8195 | |
8196 void | |
7 | 8197 screenclear() |
8198 { | |
8199 check_for_delay(FALSE); | |
8200 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8201 screenclear2(); /* clear the screen */ | |
8202 } | |
8203 | |
8204 static void | |
8205 screenclear2() | |
8206 { | |
8207 int i; | |
8208 | |
8209 if (starting == NO_SCREEN || ScreenLines == NULL | |
8210 #ifdef FEAT_GUI | |
8211 || (gui.in_use && gui.starting) | |
8212 #endif | |
8213 ) | |
8214 return; | |
8215 | |
8216 #ifdef FEAT_GUI | |
8217 if (!gui.in_use) | |
8218 #endif | |
8219 screen_attr = -1; /* force setting the Normal colors */ | |
8220 screen_stop_highlight(); /* don't want highlighting here */ | |
8221 | |
8222 #ifdef FEAT_CLIPBOARD | |
8223 /* disable selection without redrawing it */ | |
8224 clip_scroll_selection(9999); | |
8225 #endif | |
8226 | |
8227 /* blank out ScreenLines */ | |
8228 for (i = 0; i < Rows; ++i) | |
8229 { | |
8230 lineclear(LineOffset[i], (int)Columns); | |
8231 LineWraps[i] = FALSE; | |
8232 } | |
8233 | |
8234 if (can_clear(T_CL)) | |
8235 { | |
8236 out_str(T_CL); /* clear the display */ | |
8237 clear_cmdline = FALSE; | |
644 | 8238 mode_displayed = FALSE; |
7 | 8239 } |
8240 else | |
8241 { | |
8242 /* can't clear the screen, mark all chars with invalid attributes */ | |
8243 for (i = 0; i < Rows; ++i) | |
8244 lineinvalid(LineOffset[i], (int)Columns); | |
8245 clear_cmdline = TRUE; | |
8246 } | |
8247 | |
8248 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8249 | |
8250 win_rest_invalid(firstwin); | |
8251 redraw_cmdline = TRUE; | |
670 | 8252 #ifdef FEAT_WINDOWS |
673 | 8253 redraw_tabline = TRUE; |
670 | 8254 #endif |
7 | 8255 if (must_redraw == CLEAR) /* no need to clear again */ |
8256 must_redraw = NOT_VALID; | |
8257 compute_cmdrow(); | |
8258 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8259 msg_col = 0; | |
8260 screen_start(); /* don't know where cursor is now */ | |
8261 msg_scrolled = 0; /* can't scroll back */ | |
8262 msg_didany = FALSE; | |
8263 msg_didout = FALSE; | |
8264 } | |
8265 | |
8266 /* | |
8267 * Clear one line in ScreenLines. | |
8268 */ | |
8269 static void | |
8270 lineclear(off, width) | |
8271 unsigned off; | |
8272 int width; | |
8273 { | |
8274 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8275 #ifdef FEAT_MBYTE | |
8276 if (enc_utf8) | |
8277 (void)vim_memset(ScreenLinesUC + off, 0, | |
8278 (size_t)width * sizeof(u8char_T)); | |
8279 #endif | |
8280 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8281 } | |
8282 | |
8283 /* | |
8284 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8285 * invalid value. | |
8286 */ | |
8287 static void | |
8288 lineinvalid(off, width) | |
8289 unsigned off; | |
8290 int width; | |
8291 { | |
8292 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8293 } | |
8294 | |
8295 #ifdef FEAT_VERTSPLIT | |
8296 /* | |
8297 * Copy part of a Screenline for vertically split window "wp". | |
8298 */ | |
8299 static void | |
8300 linecopy(to, from, wp) | |
8301 int to; | |
8302 int from; | |
8303 win_T *wp; | |
8304 { | |
8305 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8306 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8307 | |
8308 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8309 wp->w_width * sizeof(schar_T)); | |
8310 # ifdef FEAT_MBYTE | |
8311 if (enc_utf8) | |
8312 { | |
714 | 8313 int i; |
8314 | |
7 | 8315 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8316 wp->w_width * sizeof(u8char_T)); | |
714 | 8317 for (i = 0; i < p_mco; ++i) |
8318 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8319 wp->w_width * sizeof(u8char_T)); | |
7 | 8320 } |
8321 if (enc_dbcs == DBCS_JPNU) | |
8322 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8323 wp->w_width * sizeof(schar_T)); | |
8324 # endif | |
8325 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8326 wp->w_width * sizeof(sattr_T)); | |
8327 } | |
8328 #endif | |
8329 | |
8330 /* | |
8331 * Return TRUE if clearing with term string "p" would work. | |
8332 * It can't work when the string is empty or it won't set the right background. | |
8333 */ | |
8334 int | |
8335 can_clear(p) | |
8336 char_u *p; | |
8337 { | |
8338 return (*p != NUL && (t_colors <= 1 | |
8339 #ifdef FEAT_GUI | |
8340 || gui.in_use | |
8341 #endif | |
8342 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8343 } | |
8344 | |
8345 /* | |
8346 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8347 * something directly to the screen (shell commands) or a terminal control | |
8348 * code. | |
8349 */ | |
8350 void | |
8351 screen_start() | |
8352 { | |
8353 screen_cur_row = screen_cur_col = 9999; | |
8354 } | |
8355 | |
8356 /* | |
8357 * Move the cursor to position "row","col" in the screen. | |
8358 * This tries to find the most efficient way to move, minimizing the number of | |
8359 * characters sent to the terminal. | |
8360 */ | |
8361 void | |
8362 windgoto(row, col) | |
8363 int row; | |
8364 int col; | |
8365 { | |
205 | 8366 sattr_T *p; |
7 | 8367 int i; |
8368 int plan; | |
8369 int cost; | |
8370 int wouldbe_col; | |
8371 int noinvcurs; | |
8372 char_u *bs; | |
8373 int goto_cost; | |
8374 int attr; | |
8375 | |
1213 | 8376 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8377 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8378 | |
8379 #define PLAN_LE 1 | |
8380 #define PLAN_CR 2 | |
8381 #define PLAN_NL 3 | |
8382 #define PLAN_WRITE 4 | |
8383 /* Can't use ScreenLines unless initialized */ | |
8384 if (ScreenLines == NULL) | |
8385 return; | |
8386 | |
8387 if (col != screen_cur_col || row != screen_cur_row) | |
8388 { | |
8389 /* Check for valid position. */ | |
8390 if (row < 0) /* window without text lines? */ | |
8391 row = 0; | |
8392 if (row >= screen_Rows) | |
8393 row = screen_Rows - 1; | |
8394 if (col >= screen_Columns) | |
8395 col = screen_Columns - 1; | |
8396 | |
8397 /* check if no cursor movement is allowed in highlight mode */ | |
8398 if (screen_attr && *T_MS == NUL) | |
8399 noinvcurs = HIGHL_COST; | |
8400 else | |
8401 noinvcurs = 0; | |
8402 goto_cost = GOTO_COST + noinvcurs; | |
8403 | |
8404 /* | |
8405 * Plan how to do the positioning: | |
8406 * 1. Use CR to move it to column 0, same row. | |
8407 * 2. Use T_LE to move it a few columns to the left. | |
8408 * 3. Use NL to move a few lines down, column 0. | |
8409 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8410 * | |
8411 * Don't do this if the cursor went beyond the last column, the cursor | |
8412 * position is unknown then (some terminals wrap, some don't ) | |
8413 * | |
1213 | 8414 * First check if the highlighting attributes allow us to write |
7 | 8415 * characters to move the cursor to the right. |
8416 */ | |
8417 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8418 { | |
8419 /* | |
8420 * If the cursor is in the same row, bigger col, we can use CR | |
8421 * or T_LE. | |
8422 */ | |
8423 bs = NULL; /* init for GCC */ | |
8424 attr = screen_attr; | |
8425 if (row == screen_cur_row && col < screen_cur_col) | |
8426 { | |
8427 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8428 if (*T_LE) | |
8429 bs = T_LE; /* "cursor left" */ | |
8430 else | |
8431 bs = T_BC; /* "backspace character (old) */ | |
8432 if (*bs) | |
8433 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8434 else | |
8435 cost = 999; | |
8436 if (col + 1 < cost) /* using CR is less characters */ | |
8437 { | |
8438 plan = PLAN_CR; | |
8439 wouldbe_col = 0; | |
8440 cost = 1; /* CR is just one character */ | |
8441 } | |
8442 else | |
8443 { | |
8444 plan = PLAN_LE; | |
8445 wouldbe_col = col; | |
8446 } | |
8447 if (noinvcurs) /* will stop highlighting */ | |
8448 { | |
8449 cost += noinvcurs; | |
8450 attr = 0; | |
8451 } | |
8452 } | |
8453 | |
8454 /* | |
8455 * If the cursor is above where we want to be, we can use CR LF. | |
8456 */ | |
8457 else if (row > screen_cur_row) | |
8458 { | |
8459 plan = PLAN_NL; | |
8460 wouldbe_col = 0; | |
8461 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8462 if (noinvcurs) /* will stop highlighting */ | |
8463 { | |
8464 cost += noinvcurs; | |
8465 attr = 0; | |
8466 } | |
8467 } | |
8468 | |
8469 /* | |
8470 * If the cursor is in the same row, smaller col, just use write. | |
8471 */ | |
8472 else | |
8473 { | |
8474 plan = PLAN_WRITE; | |
8475 wouldbe_col = screen_cur_col; | |
8476 cost = 0; | |
8477 } | |
8478 | |
8479 /* | |
8480 * Check if any characters that need to be written have the | |
8481 * correct attributes. Also avoid UTF-8 characters. | |
8482 */ | |
8483 i = col - wouldbe_col; | |
8484 if (i > 0) | |
8485 cost += i; | |
8486 if (cost < goto_cost && i > 0) | |
8487 { | |
8488 /* | |
8489 * Check if the attributes are correct without additionally | |
8490 * stopping highlighting. | |
8491 */ | |
8492 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8493 while (i && *p++ == attr) | |
8494 --i; | |
8495 if (i != 0) | |
8496 { | |
8497 /* | |
8498 * Try if it works when highlighting is stopped here. | |
8499 */ | |
8500 if (*--p == 0) | |
8501 { | |
8502 cost += noinvcurs; | |
8503 while (i && *p++ == 0) | |
8504 --i; | |
8505 } | |
8506 if (i != 0) | |
8507 cost = 999; /* different attributes, don't do it */ | |
8508 } | |
8509 #ifdef FEAT_MBYTE | |
8510 if (enc_utf8) | |
8511 { | |
8512 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8513 for (i = wouldbe_col; i < col; ++i) | |
8514 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8515 { | |
8516 cost = 999; | |
8517 break; | |
8518 } | |
8519 } | |
8520 #endif | |
8521 } | |
8522 | |
8523 /* | |
8524 * We can do it without term_windgoto()! | |
8525 */ | |
8526 if (cost < goto_cost) | |
8527 { | |
8528 if (plan == PLAN_LE) | |
8529 { | |
8530 if (noinvcurs) | |
8531 screen_stop_highlight(); | |
8532 while (screen_cur_col > col) | |
8533 { | |
8534 out_str(bs); | |
8535 --screen_cur_col; | |
8536 } | |
8537 } | |
8538 else if (plan == PLAN_CR) | |
8539 { | |
8540 if (noinvcurs) | |
8541 screen_stop_highlight(); | |
8542 out_char('\r'); | |
8543 screen_cur_col = 0; | |
8544 } | |
8545 else if (plan == PLAN_NL) | |
8546 { | |
8547 if (noinvcurs) | |
8548 screen_stop_highlight(); | |
8549 while (screen_cur_row < row) | |
8550 { | |
8551 out_char('\n'); | |
8552 ++screen_cur_row; | |
8553 } | |
8554 screen_cur_col = 0; | |
8555 } | |
8556 | |
8557 i = col - screen_cur_col; | |
8558 if (i > 0) | |
8559 { | |
8560 /* | |
8561 * Use cursor-right if it's one character only. Avoids | |
8562 * removing a line of pixels from the last bold char, when | |
8563 * using the bold trick in the GUI. | |
8564 */ | |
8565 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8566 { | |
8567 while (i-- > 0) | |
8568 out_char(*T_ND); | |
8569 } | |
8570 else | |
8571 { | |
8572 int off; | |
8573 | |
8574 off = LineOffset[row] + screen_cur_col; | |
8575 while (i-- > 0) | |
8576 { | |
8577 if (ScreenAttrs[off] != screen_attr) | |
8578 screen_stop_highlight(); | |
8579 #ifdef FEAT_MBYTE | |
8580 out_flush_check(); | |
8581 #endif | |
8582 out_char(ScreenLines[off]); | |
8583 #ifdef FEAT_MBYTE | |
8584 if (enc_dbcs == DBCS_JPNU | |
8585 && ScreenLines[off] == 0x8e) | |
8586 out_char(ScreenLines2[off]); | |
8587 #endif | |
8588 ++off; | |
8589 } | |
8590 } | |
8591 } | |
8592 } | |
8593 } | |
8594 else | |
8595 cost = 999; | |
8596 | |
8597 if (cost >= goto_cost) | |
8598 { | |
8599 if (noinvcurs) | |
8600 screen_stop_highlight(); | |
8601 if (row == screen_cur_row && (col > screen_cur_col) && | |
8602 *T_CRI != NUL) | |
8603 term_cursor_right(col - screen_cur_col); | |
8604 else | |
8605 term_windgoto(row, col); | |
8606 } | |
8607 screen_cur_row = row; | |
8608 screen_cur_col = col; | |
8609 } | |
8610 } | |
8611 | |
8612 /* | |
8613 * Set cursor to its position in the current window. | |
8614 */ | |
8615 void | |
8616 setcursor() | |
8617 { | |
8618 if (redrawing()) | |
8619 { | |
8620 validate_cursor(); | |
8621 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8622 W_WINCOL(curwin) + ( | |
8623 #ifdef FEAT_RIGHTLEFT | |
1545 | 8624 /* With 'rightleft' set and the cursor on a double-wide |
8625 * character, position it on the leftmost column. */ | |
7 | 8626 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8627 # ifdef FEAT_MBYTE | |
1545 | 8628 (has_mbyte |
8629 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8630 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8631 # endif |
8632 1)) : | |
8633 #endif | |
8634 curwin->w_wcol)); | |
8635 } | |
8636 } | |
8637 | |
8638 | |
8639 /* | |
8640 * insert 'line_count' lines at 'row' in window 'wp' | |
8641 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8642 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8643 * scrolling. | |
8644 * Returns FAIL if the lines are not inserted, OK for success. | |
8645 */ | |
8646 int | |
8647 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8648 win_T *wp; | |
8649 int row; | |
8650 int line_count; | |
8651 int invalid; | |
8652 int mayclear; | |
8653 { | |
8654 int did_delete; | |
8655 int nextrow; | |
8656 int lastrow; | |
8657 int retval; | |
8658 | |
8659 if (invalid) | |
8660 wp->w_lines_valid = 0; | |
8661 | |
8662 if (wp->w_height < 5) | |
8663 return FAIL; | |
8664 | |
8665 if (line_count > wp->w_height - row) | |
8666 line_count = wp->w_height - row; | |
8667 | |
8668 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8669 if (retval != MAYBE) | |
8670 return retval; | |
8671 | |
8672 /* | |
8673 * If there is a next window or a status line, we first try to delete the | |
8674 * lines at the bottom to avoid messing what is after the window. | |
8675 * If this fails and there are following windows, don't do anything to avoid | |
8676 * messing up those windows, better just redraw. | |
8677 */ | |
8678 did_delete = FALSE; | |
8679 #ifdef FEAT_WINDOWS | |
8680 if (wp->w_next != NULL || wp->w_status_height) | |
8681 { | |
8682 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8683 line_count, (int)Rows, FALSE, NULL) == OK) | |
8684 did_delete = TRUE; | |
8685 else if (wp->w_next) | |
8686 return FAIL; | |
8687 } | |
8688 #endif | |
8689 /* | |
8690 * if no lines deleted, blank the lines that will end up below the window | |
8691 */ | |
8692 if (!did_delete) | |
8693 { | |
8694 #ifdef FEAT_WINDOWS | |
8695 wp->w_redr_status = TRUE; | |
8696 #endif | |
8697 redraw_cmdline = TRUE; | |
8698 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8699 lastrow = nextrow + line_count; | |
8700 if (lastrow > Rows) | |
8701 lastrow = Rows; | |
8702 screen_fill(nextrow - line_count, lastrow - line_count, | |
8703 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8704 ' ', ' ', 0); | |
8705 } | |
8706 | |
8707 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8708 == FAIL) | |
8709 { | |
8710 /* deletion will have messed up other windows */ | |
8711 if (did_delete) | |
8712 { | |
8713 #ifdef FEAT_WINDOWS | |
8714 wp->w_redr_status = TRUE; | |
8715 #endif | |
8716 win_rest_invalid(W_NEXT(wp)); | |
8717 } | |
8718 return FAIL; | |
8719 } | |
8720 | |
8721 return OK; | |
8722 } | |
8723 | |
8724 /* | |
8725 * delete "line_count" window lines at "row" in window "wp" | |
8726 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8727 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8728 * scrolling | |
8729 * Return OK for success, FAIL if the lines are not deleted. | |
8730 */ | |
8731 int | |
8732 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8733 win_T *wp; | |
8734 int row; | |
8735 int line_count; | |
8736 int invalid; | |
8737 int mayclear; | |
8738 { | |
8739 int retval; | |
8740 | |
8741 if (invalid) | |
8742 wp->w_lines_valid = 0; | |
8743 | |
8744 if (line_count > wp->w_height - row) | |
8745 line_count = wp->w_height - row; | |
8746 | |
8747 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8748 if (retval != MAYBE) | |
8749 return retval; | |
8750 | |
8751 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8752 (int)Rows, FALSE, NULL) == FAIL) | |
8753 return FAIL; | |
8754 | |
8755 #ifdef FEAT_WINDOWS | |
8756 /* | |
8757 * If there are windows or status lines below, try to put them at the | |
8758 * correct place. If we can't do that, they have to be redrawn. | |
8759 */ | |
8760 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8761 { | |
8762 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8763 line_count, (int)Rows, NULL) == FAIL) | |
8764 { | |
8765 wp->w_redr_status = TRUE; | |
8766 win_rest_invalid(wp->w_next); | |
8767 } | |
8768 } | |
8769 /* | |
8770 * If this is the last window and there is no status line, redraw the | |
8771 * command line later. | |
8772 */ | |
8773 else | |
8774 #endif | |
8775 redraw_cmdline = TRUE; | |
8776 return OK; | |
8777 } | |
8778 | |
8779 /* | |
8780 * Common code for win_ins_lines() and win_del_lines(). | |
8781 * Returns OK or FAIL when the work has been done. | |
8782 * Returns MAYBE when not finished yet. | |
8783 */ | |
8784 static int | |
8785 win_do_lines(wp, row, line_count, mayclear, del) | |
8786 win_T *wp; | |
8787 int row; | |
8788 int line_count; | |
8789 int mayclear; | |
8790 int del; | |
8791 { | |
8792 int retval; | |
8793 | |
8794 if (!redrawing() || line_count <= 0) | |
8795 return FAIL; | |
8796 | |
8797 /* only a few lines left: redraw is faster */ | |
8798 if (mayclear && Rows - line_count < 5 | |
8799 #ifdef FEAT_VERTSPLIT | |
8800 && wp->w_width == Columns | |
8801 #endif | |
8802 ) | |
8803 { | |
8804 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8805 return FAIL; | |
8806 } | |
8807 | |
8808 /* | |
8809 * Delete all remaining lines | |
8810 */ | |
8811 if (row + line_count >= wp->w_height) | |
8812 { | |
8813 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8814 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8815 ' ', ' ', 0); | |
8816 return OK; | |
8817 } | |
8818 | |
8819 /* | |
8820 * when scrolling, the message on the command line should be cleared, | |
8821 * otherwise it will stay there forever. | |
8822 */ | |
8823 clear_cmdline = TRUE; | |
8824 | |
8825 /* | |
8826 * If the terminal can set a scroll region, use that. | |
8827 * Always do this in a vertically split window. This will redraw from | |
8828 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8829 * win_line(). | |
8830 * Don't use a scroll region when we are going to redraw the text, writing | |
8831 * a character in the lower right corner of the scroll region causes a | |
8832 * scroll-up in the DJGPP version. | |
8833 */ | |
8834 if (scroll_region | |
8835 #ifdef FEAT_VERTSPLIT | |
8836 || W_WIDTH(wp) != Columns | |
8837 #endif | |
8838 ) | |
8839 { | |
8840 #ifdef FEAT_VERTSPLIT | |
8841 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8842 #endif | |
8843 scroll_region_set(wp, row); | |
8844 if (del) | |
8845 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8846 wp->w_height - row, FALSE, wp); | |
8847 else | |
8848 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8849 wp->w_height - row, wp); | |
8850 #ifdef FEAT_VERTSPLIT | |
8851 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8852 #endif | |
8853 scroll_region_reset(); | |
8854 return retval; | |
8855 } | |
8856 | |
8857 #ifdef FEAT_WINDOWS | |
8858 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8859 return FAIL; | |
8860 #endif | |
8861 | |
8862 return MAYBE; | |
8863 } | |
8864 | |
8865 /* | |
8866 * window 'wp' and everything after it is messed up, mark it for redraw | |
8867 */ | |
8868 static void | |
8869 win_rest_invalid(wp) | |
8870 win_T *wp; | |
8871 { | |
8872 #ifdef FEAT_WINDOWS | |
8873 while (wp != NULL) | |
8874 #else | |
8875 if (wp != NULL) | |
8876 #endif | |
8877 { | |
8878 redraw_win_later(wp, NOT_VALID); | |
8879 #ifdef FEAT_WINDOWS | |
8880 wp->w_redr_status = TRUE; | |
8881 wp = wp->w_next; | |
8882 #endif | |
8883 } | |
8884 redraw_cmdline = TRUE; | |
8885 } | |
8886 | |
8887 /* | |
8888 * The rest of the routines in this file perform screen manipulations. The | |
8889 * given operation is performed physically on the screen. The corresponding | |
8890 * change is also made to the internal screen image. In this way, the editor | |
8891 * anticipates the effect of editing changes on the appearance of the screen. | |
8892 * That way, when we call screenupdate a complete redraw isn't usually | |
8893 * necessary. Another advantage is that we can keep adding code to anticipate | |
8894 * screen changes, and in the meantime, everything still works. | |
8895 */ | |
8896 | |
8897 /* | |
8898 * types for inserting or deleting lines | |
8899 */ | |
8900 #define USE_T_CAL 1 | |
8901 #define USE_T_CDL 2 | |
8902 #define USE_T_AL 3 | |
8903 #define USE_T_CE 4 | |
8904 #define USE_T_DL 5 | |
8905 #define USE_T_SR 6 | |
8906 #define USE_NL 7 | |
8907 #define USE_T_CD 8 | |
8908 #define USE_REDRAW 9 | |
8909 | |
8910 /* | |
8911 * insert lines on the screen and update ScreenLines[] | |
8912 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8913 * When scrolling region used 'off' is the offset from the top for the region. | |
8914 * 'row' and 'end' are relative to the start of the region. | |
8915 * | |
8916 * return FAIL for failure, OK for success. | |
8917 */ | |
446 | 8918 int |
7 | 8919 screen_ins_lines(off, row, line_count, end, wp) |
8920 int off; | |
8921 int row; | |
8922 int line_count; | |
8923 int end; | |
8924 win_T *wp; /* NULL or window to use width from */ | |
8925 { | |
8926 int i; | |
8927 int j; | |
8928 unsigned temp; | |
8929 int cursor_row; | |
8930 int type; | |
8931 int result_empty; | |
8932 int can_ce = can_clear(T_CE); | |
8933 | |
8934 /* | |
8935 * FAIL if | |
8936 * - there is no valid screen | |
8937 * - the screen has to be redrawn completely | |
8938 * - the line count is less than one | |
8939 * - the line count is more than 'ttyscroll' | |
8940 */ | |
8941 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8942 return FAIL; | |
8943 | |
8944 /* | |
8945 * There are seven ways to insert lines: | |
8946 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8947 * characters from ScreenLines[]. | |
8948 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8949 * the insert is just empty lines | |
8950 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8951 * present or line_count > 1. It looks better if we do all the inserts | |
8952 * at once. | |
8953 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8954 * insert is just empty lines and T_CE is not present or line_count > | |
8955 * 1. | |
8956 * 4. Use T_AL (insert line) if it exists. | |
8957 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8958 * just empty lines. | |
8959 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8960 * just empty lines. | |
8961 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8962 * the 'da' flag is not set or we have clear line capability. | |
8963 * 8. redraw the characters from ScreenLines[]. | |
8964 * | |
8965 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8966 * the scrollbar for the window. It does have insert line, use that if it | |
8967 * exists. | |
8968 */ | |
8969 result_empty = (row + line_count >= end); | |
8970 #ifdef FEAT_VERTSPLIT | |
8971 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8972 type = USE_REDRAW; | |
8973 else | |
8974 #endif | |
8975 if (can_clear(T_CD) && result_empty) | |
8976 type = USE_T_CD; | |
8977 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
8978 type = USE_T_CAL; | |
8979 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
8980 type = USE_T_CDL; | |
8981 else if (*T_AL != NUL) | |
8982 type = USE_T_AL; | |
8983 else if (can_ce && result_empty) | |
8984 type = USE_T_CE; | |
8985 else if (*T_DL != NUL && result_empty) | |
8986 type = USE_T_DL; | |
8987 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
8988 type = USE_T_SR; | |
8989 else | |
8990 return FAIL; | |
8991 | |
8992 /* | |
8993 * For clearing the lines screen_del_lines() is used. This will also take | |
8994 * care of t_db if necessary. | |
8995 */ | |
8996 if (type == USE_T_CD || type == USE_T_CDL || | |
8997 type == USE_T_CE || type == USE_T_DL) | |
8998 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
8999 | |
9000 /* | |
9001 * If text is retained below the screen, first clear or delete as many | |
9002 * lines at the bottom of the window as are about to be inserted so that | |
9003 * the deleted lines won't later surface during a screen_del_lines. | |
9004 */ | |
9005 if (*T_DB) | |
9006 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
9007 | |
9008 #ifdef FEAT_CLIPBOARD | |
9009 /* Remove a modeless selection when inserting lines halfway the screen | |
9010 * or not the full width of the screen. */ | |
9011 if (off + row > 0 | |
9012 # ifdef FEAT_VERTSPLIT | |
9013 || (wp != NULL && wp->w_width != Columns) | |
9014 # endif | |
9015 ) | |
9016 clip_clear_selection(); | |
9017 else | |
9018 clip_scroll_selection(-line_count); | |
9019 #endif | |
9020 | |
9021 #ifdef FEAT_GUI | |
9022 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9023 * scrolling is actually carried out. */ | |
9024 gui_dont_update_cursor(); | |
9025 #endif | |
9026 | |
9027 if (*T_CCS != NUL) /* cursor relative to region */ | |
9028 cursor_row = row; | |
9029 else | |
9030 cursor_row = row + off; | |
9031 | |
9032 /* | |
9033 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
9034 * Clear the inserted lines in ScreenLines[]. | |
9035 */ | |
9036 row += off; | |
9037 end += off; | |
9038 for (i = 0; i < line_count; ++i) | |
9039 { | |
9040 #ifdef FEAT_VERTSPLIT | |
9041 if (wp != NULL && wp->w_width != Columns) | |
9042 { | |
9043 /* need to copy part of a line */ | |
9044 j = end - 1 - i; | |
9045 while ((j -= line_count) >= row) | |
9046 linecopy(j + line_count, j, wp); | |
9047 j += line_count; | |
9048 if (can_clear((char_u *)" ")) | |
9049 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9050 else | |
9051 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9052 LineWraps[j] = FALSE; | |
9053 } | |
9054 else | |
9055 #endif | |
9056 { | |
9057 j = end - 1 - i; | |
9058 temp = LineOffset[j]; | |
9059 while ((j -= line_count) >= row) | |
9060 { | |
9061 LineOffset[j + line_count] = LineOffset[j]; | |
9062 LineWraps[j + line_count] = LineWraps[j]; | |
9063 } | |
9064 LineOffset[j + line_count] = temp; | |
9065 LineWraps[j + line_count] = FALSE; | |
9066 if (can_clear((char_u *)" ")) | |
9067 lineclear(temp, (int)Columns); | |
9068 else | |
9069 lineinvalid(temp, (int)Columns); | |
9070 } | |
9071 } | |
9072 | |
9073 screen_stop_highlight(); | |
9074 windgoto(cursor_row, 0); | |
9075 | |
9076 #ifdef FEAT_VERTSPLIT | |
9077 /* redraw the characters */ | |
9078 if (type == USE_REDRAW) | |
9079 redraw_block(row, end, wp); | |
9080 else | |
9081 #endif | |
9082 if (type == USE_T_CAL) | |
9083 { | |
9084 term_append_lines(line_count); | |
9085 screen_start(); /* don't know where cursor is now */ | |
9086 } | |
9087 else | |
9088 { | |
9089 for (i = 0; i < line_count; i++) | |
9090 { | |
9091 if (type == USE_T_AL) | |
9092 { | |
9093 if (i && cursor_row != 0) | |
9094 windgoto(cursor_row, 0); | |
9095 out_str(T_AL); | |
9096 } | |
9097 else /* type == USE_T_SR */ | |
9098 out_str(T_SR); | |
9099 screen_start(); /* don't know where cursor is now */ | |
9100 } | |
9101 } | |
9102 | |
9103 /* | |
9104 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9105 * have been scrolled down into the region. | |
9106 */ | |
9107 if (type == USE_T_SR && *T_DA) | |
9108 { | |
9109 for (i = 0; i < line_count; ++i) | |
9110 { | |
9111 windgoto(off + i, 0); | |
9112 out_str(T_CE); | |
9113 screen_start(); /* don't know where cursor is now */ | |
9114 } | |
9115 } | |
9116 | |
9117 #ifdef FEAT_GUI | |
9118 gui_can_update_cursor(); | |
9119 if (gui.in_use) | |
9120 out_flush(); /* always flush after a scroll */ | |
9121 #endif | |
9122 return OK; | |
9123 } | |
9124 | |
9125 /* | |
9126 * delete lines on the screen and update ScreenLines[] | |
9127 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9128 * When scrolling region used 'off' is the offset from the top for the region. | |
9129 * 'row' and 'end' are relative to the start of the region. | |
9130 * | |
9131 * Return OK for success, FAIL if the lines are not deleted. | |
9132 */ | |
9133 int | |
9134 screen_del_lines(off, row, line_count, end, force, wp) | |
9135 int off; | |
9136 int row; | |
9137 int line_count; | |
9138 int end; | |
9139 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9140 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9141 { |
9142 int j; | |
9143 int i; | |
9144 unsigned temp; | |
9145 int cursor_row; | |
9146 int cursor_end; | |
9147 int result_empty; /* result is empty until end of region */ | |
9148 int can_delete; /* deleting line codes can be used */ | |
9149 int type; | |
9150 | |
9151 /* | |
9152 * FAIL if | |
9153 * - there is no valid screen | |
9154 * - the screen has to be redrawn completely | |
9155 * - the line count is less than one | |
9156 * - the line count is more than 'ttyscroll' | |
9157 */ | |
9158 if (!screen_valid(TRUE) || line_count <= 0 || | |
9159 (!force && line_count > p_ttyscroll)) | |
9160 return FAIL; | |
9161 | |
9162 /* | |
9163 * Check if the rest of the current region will become empty. | |
9164 */ | |
9165 result_empty = row + line_count >= end; | |
9166 | |
9167 /* | |
9168 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9169 * available. | |
9170 */ | |
9171 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9172 | |
9173 /* | |
9174 * There are six ways to delete lines: | |
9175 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9176 * characters from ScreenLines[]. | |
9177 * 1. Use T_CD if it exists and the result is empty. | |
9178 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9179 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9180 * none of the other ways work. | |
9181 * 4. Use T_CE (erase line) if the result is empty. | |
9182 * 5. Use T_DL (delete line) if it exists. | |
9183 * 6. redraw the characters from ScreenLines[]. | |
9184 */ | |
9185 #ifdef FEAT_VERTSPLIT | |
9186 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9187 type = USE_REDRAW; | |
9188 else | |
9189 #endif | |
9190 if (can_clear(T_CD) && result_empty) | |
9191 type = USE_T_CD; | |
9192 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9193 /* | |
9194 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9195 * its internal termcap... this works okay for tests which test *T_DB != | |
9196 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9197 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9198 * the trick... | |
9199 * Anyway, this hack will hopefully go away with the next OS release. | |
9200 * (Olaf Seibert) | |
9201 */ | |
9202 else if (row == 0 && T_DB == empty_option | |
9203 && (line_count == 1 || *T_CDL == NUL)) | |
9204 #else | |
9205 else if (row == 0 && ( | |
9206 #ifndef AMIGA | |
9207 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9208 * up, so use delete-line command */ | |
9209 line_count == 1 || | |
9210 #endif | |
9211 *T_CDL == NUL)) | |
9212 #endif | |
9213 type = USE_NL; | |
9214 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9215 type = USE_T_CDL; | |
9216 else if (can_clear(T_CE) && result_empty | |
9217 #ifdef FEAT_VERTSPLIT | |
9218 && (wp == NULL || wp->w_width == Columns) | |
9219 #endif | |
9220 ) | |
9221 type = USE_T_CE; | |
9222 else if (*T_DL != NUL && can_delete) | |
9223 type = USE_T_DL; | |
9224 else if (*T_CDL != NUL && can_delete) | |
9225 type = USE_T_CDL; | |
9226 else | |
9227 return FAIL; | |
9228 | |
9229 #ifdef FEAT_CLIPBOARD | |
9230 /* Remove a modeless selection when deleting lines halfway the screen or | |
9231 * not the full width of the screen. */ | |
9232 if (off + row > 0 | |
9233 # ifdef FEAT_VERTSPLIT | |
9234 || (wp != NULL && wp->w_width != Columns) | |
9235 # endif | |
9236 ) | |
9237 clip_clear_selection(); | |
9238 else | |
9239 clip_scroll_selection(line_count); | |
9240 #endif | |
9241 | |
9242 #ifdef FEAT_GUI | |
9243 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9244 * scrolling is actually carried out. */ | |
9245 gui_dont_update_cursor(); | |
9246 #endif | |
9247 | |
9248 if (*T_CCS != NUL) /* cursor relative to region */ | |
9249 { | |
9250 cursor_row = row; | |
9251 cursor_end = end; | |
9252 } | |
9253 else | |
9254 { | |
9255 cursor_row = row + off; | |
9256 cursor_end = end + off; | |
9257 } | |
9258 | |
9259 /* | |
9260 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9261 * Clear the inserted lines in ScreenLines[]. | |
9262 */ | |
9263 row += off; | |
9264 end += off; | |
9265 for (i = 0; i < line_count; ++i) | |
9266 { | |
9267 #ifdef FEAT_VERTSPLIT | |
9268 if (wp != NULL && wp->w_width != Columns) | |
9269 { | |
9270 /* need to copy part of a line */ | |
9271 j = row + i; | |
9272 while ((j += line_count) <= end - 1) | |
9273 linecopy(j - line_count, j, wp); | |
9274 j -= line_count; | |
9275 if (can_clear((char_u *)" ")) | |
9276 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9277 else | |
9278 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9279 LineWraps[j] = FALSE; | |
9280 } | |
9281 else | |
9282 #endif | |
9283 { | |
9284 /* whole width, moving the line pointers is faster */ | |
9285 j = row + i; | |
9286 temp = LineOffset[j]; | |
9287 while ((j += line_count) <= end - 1) | |
9288 { | |
9289 LineOffset[j - line_count] = LineOffset[j]; | |
9290 LineWraps[j - line_count] = LineWraps[j]; | |
9291 } | |
9292 LineOffset[j - line_count] = temp; | |
9293 LineWraps[j - line_count] = FALSE; | |
9294 if (can_clear((char_u *)" ")) | |
9295 lineclear(temp, (int)Columns); | |
9296 else | |
9297 lineinvalid(temp, (int)Columns); | |
9298 } | |
9299 } | |
9300 | |
9301 screen_stop_highlight(); | |
9302 | |
9303 #ifdef FEAT_VERTSPLIT | |
9304 /* redraw the characters */ | |
9305 if (type == USE_REDRAW) | |
9306 redraw_block(row, end, wp); | |
9307 else | |
9308 #endif | |
9309 if (type == USE_T_CD) /* delete the lines */ | |
9310 { | |
9311 windgoto(cursor_row, 0); | |
9312 out_str(T_CD); | |
9313 screen_start(); /* don't know where cursor is now */ | |
9314 } | |
9315 else if (type == USE_T_CDL) | |
9316 { | |
9317 windgoto(cursor_row, 0); | |
9318 term_delete_lines(line_count); | |
9319 screen_start(); /* don't know where cursor is now */ | |
9320 } | |
9321 /* | |
9322 * Deleting lines at top of the screen or scroll region: Just scroll | |
9323 * the whole screen (scroll region) up by outputting newlines on the | |
9324 * last line. | |
9325 */ | |
9326 else if (type == USE_NL) | |
9327 { | |
9328 windgoto(cursor_end - 1, 0); | |
9329 for (i = line_count; --i >= 0; ) | |
9330 out_char('\n'); /* cursor will remain on same line */ | |
9331 } | |
9332 else | |
9333 { | |
9334 for (i = line_count; --i >= 0; ) | |
9335 { | |
9336 if (type == USE_T_DL) | |
9337 { | |
9338 windgoto(cursor_row, 0); | |
9339 out_str(T_DL); /* delete a line */ | |
9340 } | |
9341 else /* type == USE_T_CE */ | |
9342 { | |
9343 windgoto(cursor_row + i, 0); | |
9344 out_str(T_CE); /* erase a line */ | |
9345 } | |
9346 screen_start(); /* don't know where cursor is now */ | |
9347 } | |
9348 } | |
9349 | |
9350 /* | |
9351 * If the 'db' flag is set, we need to clear the lines that have been | |
9352 * scrolled up at the bottom of the region. | |
9353 */ | |
9354 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9355 { | |
9356 for (i = line_count; i > 0; --i) | |
9357 { | |
9358 windgoto(cursor_end - i, 0); | |
9359 out_str(T_CE); /* erase a line */ | |
9360 screen_start(); /* don't know where cursor is now */ | |
9361 } | |
9362 } | |
9363 | |
9364 #ifdef FEAT_GUI | |
9365 gui_can_update_cursor(); | |
9366 if (gui.in_use) | |
9367 out_flush(); /* always flush after a scroll */ | |
9368 #endif | |
9369 | |
9370 return OK; | |
9371 } | |
9372 | |
9373 /* | |
9374 * show the current mode and ruler | |
9375 * | |
9376 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9377 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9378 * cleared only if a mode is shown. | |
9379 * Return the length of the message (0 if no message). | |
9380 */ | |
9381 int | |
9382 showmode() | |
9383 { | |
9384 int need_clear; | |
9385 int length = 0; | |
9386 int do_mode; | |
9387 int attr; | |
9388 int nwr_save; | |
9389 #ifdef FEAT_INS_EXPAND | |
9390 int sub_attr; | |
9391 #endif | |
9392 | |
642 | 9393 do_mode = ((p_smd && msg_silent == 0) |
9394 && ((State & INSERT) | |
9395 || restart_edit | |
7 | 9396 #ifdef FEAT_VISUAL |
9397 || VIsual_active | |
9398 #endif | |
9399 )); | |
9400 if (do_mode || Recording) | |
9401 { | |
9402 /* | |
9403 * Don't show mode right now, when not redrawing or inside a mapping. | |
9404 * Call char_avail() only when we are going to show something, because | |
9405 * it takes a bit of time. | |
9406 */ | |
9407 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9408 { | |
9409 redraw_cmdline = TRUE; /* show mode later */ | |
9410 return 0; | |
9411 } | |
9412 | |
9413 nwr_save = need_wait_return; | |
9414 | |
9415 /* wait a bit before overwriting an important message */ | |
9416 check_for_delay(FALSE); | |
9417 | |
9418 /* if the cmdline is more than one line high, erase top lines */ | |
9419 need_clear = clear_cmdline; | |
9420 if (clear_cmdline && cmdline_row < Rows - 1) | |
9421 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9422 | |
9423 /* Position on the last line in the window, column 0 */ | |
9424 msg_pos_mode(); | |
9425 cursor_off(); | |
9426 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9427 if (do_mode) | |
9428 { | |
9429 MSG_PUTS_ATTR("--", attr); | |
9430 #if defined(FEAT_XIM) | |
1668 | 9431 # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
7 | 9432 if (xic != NULL && im_get_status() && !p_imdisable |
9433 && curbuf->b_p_iminsert == B_IMODE_IM) | |
1668 | 9434 # else |
9435 if ( | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9436 # ifdef FEAT_GUI_GTK |
1668 | 9437 preedit_get_status() |
9438 # else | |
9439 im_get_status() | |
9440 # endif | |
9441 ) | |
9442 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9443 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9444 MSG_PUTS_ATTR(" IM", attr); |
9445 # else | |
9446 MSG_PUTS_ATTR(" XIM", attr); | |
9447 # endif | |
9448 #endif | |
9449 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9450 if (gui.in_use) | |
9451 { | |
9452 if (hangul_input_state_get()) | |
236 | 9453 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9454 } |
9455 #endif | |
9456 #ifdef FEAT_INS_EXPAND | |
9457 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9458 { | |
9459 /* These messages can get long, avoid a wrap in a narrow | |
9460 * window. Prefer showing edit_submode_extra. */ | |
9461 length = (Rows - msg_row) * Columns - 3; | |
9462 if (edit_submode_extra != NULL) | |
9463 length -= vim_strsize(edit_submode_extra); | |
9464 if (length > 0) | |
9465 { | |
9466 if (edit_submode_pre != NULL) | |
9467 length -= vim_strsize(edit_submode_pre); | |
9468 if (length - vim_strsize(edit_submode) > 0) | |
9469 { | |
9470 if (edit_submode_pre != NULL) | |
9471 msg_puts_attr(edit_submode_pre, attr); | |
9472 msg_puts_attr(edit_submode, attr); | |
9473 } | |
9474 if (edit_submode_extra != NULL) | |
9475 { | |
9476 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9477 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9478 sub_attr = hl_attr(edit_submode_highl); | |
9479 else | |
9480 sub_attr = attr; | |
9481 msg_puts_attr(edit_submode_extra, sub_attr); | |
9482 } | |
9483 } | |
9484 length = 0; | |
9485 } | |
9486 else | |
9487 #endif | |
9488 { | |
9489 #ifdef FEAT_VREPLACE | |
9490 if (State & VREPLACE_FLAG) | |
9491 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9492 else | |
9493 #endif | |
9494 if (State & REPLACE_FLAG) | |
9495 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9496 else if (State & INSERT) | |
9497 { | |
9498 #ifdef FEAT_RIGHTLEFT | |
9499 if (p_ri) | |
9500 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9501 #endif | |
9502 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9503 } | |
9504 else if (restart_edit == 'I') | |
9505 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9506 else if (restart_edit == 'R') | |
9507 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9508 else if (restart_edit == 'V') | |
9509 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9510 #ifdef FEAT_RIGHTLEFT | |
9511 if (p_hkmap) | |
9512 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9513 # ifdef FEAT_FKMAP | |
9514 if (p_fkmap) | |
9515 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9516 # endif | |
9517 #endif | |
9518 #ifdef FEAT_KEYMAP | |
9519 if (State & LANGMAP) | |
9520 { | |
9521 # ifdef FEAT_ARABIC | |
9522 if (curwin->w_p_arab) | |
9523 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9524 else | |
9525 # endif | |
9526 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9527 } | |
9528 #endif | |
9529 if ((State & INSERT) && p_paste) | |
9530 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9531 | |
9532 #ifdef FEAT_VISUAL | |
9533 if (VIsual_active) | |
9534 { | |
9535 char *p; | |
9536 | |
9537 /* Don't concatenate separate words to avoid translation | |
9538 * problems. */ | |
9539 switch ((VIsual_select ? 4 : 0) | |
9540 + (VIsual_mode == Ctrl_V) * 2 | |
9541 + (VIsual_mode == 'V')) | |
9542 { | |
9543 case 0: p = N_(" VISUAL"); break; | |
9544 case 1: p = N_(" VISUAL LINE"); break; | |
9545 case 2: p = N_(" VISUAL BLOCK"); break; | |
9546 case 4: p = N_(" SELECT"); break; | |
9547 case 5: p = N_(" SELECT LINE"); break; | |
9548 default: p = N_(" SELECT BLOCK"); break; | |
9549 } | |
9550 MSG_PUTS_ATTR(_(p), attr); | |
9551 } | |
9552 #endif | |
9553 MSG_PUTS_ATTR(" --", attr); | |
9554 } | |
644 | 9555 |
7 | 9556 need_clear = TRUE; |
9557 } | |
9558 if (Recording | |
9559 #ifdef FEAT_INS_EXPAND | |
9560 && edit_submode == NULL /* otherwise it gets too long */ | |
9561 #endif | |
9562 ) | |
9563 { | |
9564 MSG_PUTS_ATTR(_("recording"), attr); | |
9565 need_clear = TRUE; | |
9566 } | |
644 | 9567 |
9568 mode_displayed = TRUE; | |
7 | 9569 if (need_clear || clear_cmdline) |
9570 msg_clr_eos(); | |
9571 msg_didout = FALSE; /* overwrite this message */ | |
9572 length = msg_col; | |
9573 msg_col = 0; | |
9574 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9575 } | |
9576 else if (clear_cmdline && msg_silent == 0) | |
9577 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9578 msg_clr_cmdline(); | |
9579 | |
9580 #ifdef FEAT_CMDL_INFO | |
9581 # ifdef FEAT_VISUAL | |
9582 /* In Visual mode the size of the selected area must be redrawn. */ | |
9583 if (VIsual_active) | |
9584 clear_showcmd(); | |
9585 # endif | |
9586 | |
9587 /* If the last window has no status line, the ruler is after the mode | |
9588 * message and must be redrawn */ | |
9589 if (redrawing() | |
9590 # ifdef FEAT_WINDOWS | |
9591 && lastwin->w_status_height == 0 | |
9592 # endif | |
9593 ) | |
9594 win_redr_ruler(lastwin, TRUE); | |
9595 #endif | |
9596 redraw_cmdline = FALSE; | |
9597 clear_cmdline = FALSE; | |
9598 | |
9599 return length; | |
9600 } | |
9601 | |
9602 /* | |
9603 * Position for a mode message. | |
9604 */ | |
9605 static void | |
9606 msg_pos_mode() | |
9607 { | |
9608 msg_col = 0; | |
9609 msg_row = Rows - 1; | |
9610 } | |
9611 | |
9612 /* | |
9613 * Delete mode message. Used when ESC is typed which is expected to end | |
9614 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9615 * Caller should check "mode_displayed". |
7 | 9616 */ |
9617 void | |
9618 unshowmode(force) | |
9619 int force; | |
9620 { | |
9621 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9622 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9623 */ |
9624 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9625 redraw_cmdline = TRUE; /* delete mode later */ | |
9626 else | |
9627 { | |
9628 msg_pos_mode(); | |
9629 if (Recording) | |
9630 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9631 msg_clr_eos(); | |
9632 } | |
9633 } | |
9634 | |
667 | 9635 #if defined(FEAT_WINDOWS) |
9636 /* | |
9637 * Draw the tab pages line at the top of the Vim window. | |
9638 */ | |
9639 static void | |
677 | 9640 draw_tabline() |
667 | 9641 { |
9642 int tabcount = 0; | |
9643 tabpage_T *tp; | |
9644 int tabwidth; | |
9645 int col = 0; | |
673 | 9646 int scol = 0; |
667 | 9647 int attr; |
9648 win_T *wp; | |
671 | 9649 win_T *cwp; |
9650 int wincount; | |
9651 int modified; | |
667 | 9652 int c; |
9653 int len; | |
9654 int attr_sel = hl_attr(HLF_TPS); | |
9655 int attr_nosel = hl_attr(HLF_TP); | |
9656 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9657 char_u *p; |
677 | 9658 int room; |
9659 int use_sep_chars = (t_colors < 8 | |
9660 #ifdef FEAT_GUI | |
9661 && !gui.in_use | |
9662 #endif | |
9663 ); | |
673 | 9664 |
9665 redraw_tabline = FALSE; | |
667 | 9666 |
685 | 9667 #ifdef FEAT_GUI_TABLINE |
798 | 9668 /* Take care of a GUI tabline. */ |
685 | 9669 if (gui_use_tabline()) |
9670 { | |
9671 gui_update_tabline(); | |
9672 return; | |
9673 } | |
9674 #endif | |
9675 | |
9676 if (tabline_height() < 1) | |
667 | 9677 return; |
9678 | |
677 | 9679 #if defined(FEAT_STL_OPT) |
681 | 9680 |
9681 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9682 for (scol = 0; scol < Columns; ++scol) | |
9683 TabPageIdxs[scol] = 0; | |
9684 | |
677 | 9685 /* Use the 'tabline' option if it's set. */ |
9686 if (*p_tal != NUL) | |
9687 { | |
680 | 9688 int save_called_emsg = called_emsg; |
9689 | |
9690 /* Check for an error. If there is one we would loop in redrawing the | |
9691 * screen. Avoid that by making 'tabline' empty. */ | |
9692 called_emsg = FALSE; | |
677 | 9693 win_redr_custom(NULL, FALSE); |
680 | 9694 if (called_emsg) |
9695 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9696 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9697 called_emsg |= save_called_emsg; |
9698 } | |
9699 else | |
9700 #endif | |
9701 { | |
9702 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9703 ++tabcount; | |
9704 | |
9705 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9706 if (tabwidth < 6) | |
9707 tabwidth = 6; | |
9708 | |
9709 attr = attr_nosel; | |
9710 tabcount = 0; | |
681 | 9711 scol = 0; |
699 | 9712 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9713 tp = tp->tp_next) | |
680 | 9714 { |
9715 scol = col; | |
9716 | |
9717 if (tp->tp_topframe == topframe) | |
9718 attr = attr_sel; | |
9719 if (use_sep_chars && col > 0) | |
9720 screen_putchar('|', 0, col++, attr); | |
9721 | |
9722 if (tp->tp_topframe != topframe) | |
9723 attr = attr_nosel; | |
9724 | |
9725 screen_putchar(' ', 0, col++, attr); | |
9726 | |
9727 if (tp == curtab) | |
9728 { | |
9729 cwp = curwin; | |
9730 wp = firstwin; | |
9731 } | |
9732 else | |
9733 { | |
9734 cwp = tp->tp_curwin; | |
9735 wp = tp->tp_firstwin; | |
9736 } | |
9737 | |
9738 modified = FALSE; | |
9739 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9740 if (bufIsChanged(wp->w_buffer)) | |
9741 modified = TRUE; | |
9742 if (modified || wincount > 1) | |
9743 { | |
9744 if (wincount > 1) | |
9745 { | |
9746 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9747 len = (int)STRLEN(NameBuff); |
699 | 9748 if (col + len >= Columns - 3) |
9749 break; | |
680 | 9750 screen_puts_len(NameBuff, len, 0, col, |
677 | 9751 #if defined(FEAT_SYN_HL) |
680 | 9752 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9753 #else |
680 | 9754 attr |
9755 #endif | |
9756 ); | |
9757 col += len; | |
9758 } | |
9759 if (modified) | |
9760 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9761 screen_putchar(' ', 0, col++, attr); | |
9762 } | |
9763 | |
9764 room = scol - col + tabwidth - 1; | |
9765 if (room > 0) | |
9766 { | |
685 | 9767 /* Get buffer name in NameBuff[] */ |
9768 get_trans_bufname(cwp->w_buffer); | |
819 | 9769 shorten_dir(NameBuff); |
680 | 9770 len = vim_strsize(NameBuff); |
9771 p = NameBuff; | |
677 | 9772 #ifdef FEAT_MBYTE |
680 | 9773 if (has_mbyte) |
9774 while (len > room) | |
9775 { | |
9776 len -= ptr2cells(p); | |
9777 mb_ptr_adv(p); | |
9778 } | |
9779 else | |
9780 #endif | |
9781 if (len > room) | |
677 | 9782 { |
680 | 9783 p += len - room; |
9784 len = room; | |
677 | 9785 } |
699 | 9786 if (len > Columns - col - 1) |
9787 len = Columns - col - 1; | |
680 | 9788 |
835 | 9789 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9790 col += len; |
9791 } | |
9792 screen_putchar(' ', 0, col++, attr); | |
9793 | |
9794 /* Store the tab page number in TabPageIdxs[], so that | |
9795 * jump_to_mouse() knows where each one is. */ | |
9796 ++tabcount; | |
9797 while (scol < col) | |
9798 TabPageIdxs[scol++] = tabcount; | |
9799 } | |
9800 | |
9801 if (use_sep_chars) | |
9802 c = '_'; | |
9803 else | |
9804 c = ' '; | |
9805 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9806 |
9807 /* Put an "X" for closing the current tab if there are several. */ | |
9808 if (first_tabpage->tp_next != NULL) | |
9809 { | |
9810 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9811 TabPageIdxs[Columns - 1] = -999; | |
9812 } | |
9813 } | |
834 | 9814 |
9815 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9816 * set. */ | |
9817 redraw_tabline = FALSE; | |
667 | 9818 } |
685 | 9819 |
9820 /* | |
9821 * Get buffer name for "buf" into NameBuff[]. | |
9822 * Takes care of special buffer names and translates special characters. | |
9823 */ | |
9824 void | |
9825 get_trans_bufname(buf) | |
9826 buf_T *buf; | |
9827 { | |
9828 if (buf_spname(buf) != NULL) | |
9829 STRCPY(NameBuff, buf_spname(buf)); | |
9830 else | |
9831 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9832 trans_characters(NameBuff, MAXPATHL); | |
9833 } | |
667 | 9834 #endif |
9835 | |
7 | 9836 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9837 /* | |
9838 * Get the character to use in a status line. Get its attributes in "*attr". | |
9839 */ | |
9840 static int | |
9841 fillchar_status(attr, is_curwin) | |
9842 int *attr; | |
9843 int is_curwin; | |
9844 { | |
9845 int fill; | |
9846 if (is_curwin) | |
9847 { | |
9848 *attr = hl_attr(HLF_S); | |
9849 fill = fill_stl; | |
9850 } | |
9851 else | |
9852 { | |
9853 *attr = hl_attr(HLF_SNC); | |
9854 fill = fill_stlnc; | |
9855 } | |
9856 /* Use fill when there is highlighting, and highlighting of current | |
9857 * window differs, or the fillchars differ, or this is not the | |
9858 * current window */ | |
9859 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9860 || !is_curwin || firstwin == lastwin) | |
9861 || (fill_stl != fill_stlnc))) | |
9862 return fill; | |
9863 if (is_curwin) | |
9864 return '^'; | |
9865 return '='; | |
9866 } | |
9867 #endif | |
9868 | |
9869 #ifdef FEAT_VERTSPLIT | |
9870 /* | |
9871 * Get the character to use in a separator between vertically split windows. | |
9872 * Get its attributes in "*attr". | |
9873 */ | |
9874 static int | |
9875 fillchar_vsep(attr) | |
9876 int *attr; | |
9877 { | |
9878 *attr = hl_attr(HLF_C); | |
9879 if (*attr == 0 && fill_vert == ' ') | |
9880 return '|'; | |
9881 else | |
9882 return fill_vert; | |
9883 } | |
9884 #endif | |
9885 | |
9886 /* | |
9887 * Return TRUE if redrawing should currently be done. | |
9888 */ | |
9889 int | |
9890 redrawing() | |
9891 { | |
9892 return (!RedrawingDisabled | |
9893 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9894 } | |
9895 | |
9896 /* | |
9897 * Return TRUE if printing messages should currently be done. | |
9898 */ | |
9899 int | |
9900 messaging() | |
9901 { | |
9902 return (!(p_lz && char_avail() && !KeyTyped)); | |
9903 } | |
9904 | |
9905 /* | |
9906 * Show current status info in ruler and various other places | |
9907 * If always is FALSE, only show ruler if position has changed. | |
9908 */ | |
9909 void | |
9910 showruler(always) | |
9911 int always; | |
9912 { | |
9913 if (!always && !redrawing()) | |
9914 return; | |
574 | 9915 #ifdef FEAT_INS_EXPAND |
9916 if (pum_visible()) | |
9917 { | |
639 | 9918 # ifdef FEAT_WINDOWS |
574 | 9919 /* Don't redraw right now, do it later. */ |
9920 curwin->w_redr_status = TRUE; | |
639 | 9921 # endif |
574 | 9922 return; |
9923 } | |
9924 #endif | |
7 | 9925 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9926 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9927 { |
1983 | 9928 redraw_custom_statusline(curwin); |
680 | 9929 } |
7 | 9930 else |
9931 #endif | |
9932 #ifdef FEAT_CMDL_INFO | |
9933 win_redr_ruler(curwin, always); | |
9934 #endif | |
9935 | |
9936 #ifdef FEAT_TITLE | |
9937 if (need_maketitle | |
9938 # ifdef FEAT_STL_OPT | |
9939 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9940 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9941 # endif | |
9942 ) | |
9943 maketitle(); | |
9944 #endif | |
1588 | 9945 #ifdef FEAT_WINDOWS |
9946 /* Redraw the tab pages line if needed. */ | |
9947 if (redraw_tabline) | |
9948 draw_tabline(); | |
9949 #endif | |
7 | 9950 } |
9951 | |
9952 #ifdef FEAT_CMDL_INFO | |
9953 static void | |
9954 win_redr_ruler(wp, always) | |
9955 win_T *wp; | |
9956 int always; | |
9957 { | |
1869 | 9958 #define RULER_BUF_LEN 70 |
9959 char_u buffer[RULER_BUF_LEN]; | |
7 | 9960 int row; |
9961 int fillchar; | |
9962 int attr; | |
9963 int empty_line = FALSE; | |
9964 colnr_T virtcol; | |
9965 int i; | |
1869 | 9966 size_t len; |
7 | 9967 int o; |
9968 #ifdef FEAT_VERTSPLIT | |
9969 int this_ru_col; | |
9970 int off = 0; | |
9971 int width = Columns; | |
9972 # define WITH_OFF(x) x | |
9973 # define WITH_WIDTH(x) x | |
9974 #else | |
9975 # define WITH_OFF(x) 0 | |
9976 # define WITH_WIDTH(x) Columns | |
9977 # define this_ru_col ru_col | |
9978 #endif | |
9979 | |
9980 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9981 if (!p_ru) | |
9982 return; | |
9983 | |
9984 /* | |
9985 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
9986 * after deleting lines, before cursor.lnum is corrected. | |
9987 */ | |
9988 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
9989 return; | |
9990 | |
9991 #ifdef FEAT_INS_EXPAND | |
9992 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
9993 * the (long) mode message. */ | |
9994 # ifdef FEAT_WINDOWS | |
9995 if (wp == lastwin && lastwin->w_status_height == 0) | |
9996 # endif | |
9997 if (edit_submode != NULL) | |
9998 return; | |
540 | 9999 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
10000 if (pum_visible()) | |
10001 return; | |
7 | 10002 #endif |
10003 | |
10004 #ifdef FEAT_STL_OPT | |
10005 if (*p_ruf) | |
10006 { | |
680 | 10007 int save_called_emsg = called_emsg; |
10008 | |
10009 called_emsg = FALSE; | |
7 | 10010 win_redr_custom(wp, TRUE); |
680 | 10011 if (called_emsg) |
10012 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 10013 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 10014 called_emsg |= save_called_emsg; |
7 | 10015 return; |
10016 } | |
10017 #endif | |
10018 | |
10019 /* | |
10020 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
10021 */ | |
10022 if (!(State & INSERT) | |
10023 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
10024 empty_line = TRUE; | |
10025 | |
10026 /* | |
10027 * Only draw the ruler when something changed. | |
10028 */ | |
10029 validate_virtcol_win(wp); | |
10030 if ( redraw_cmdline | |
10031 || always | |
10032 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
10033 || wp->w_cursor.col != wp->w_ru_cursor.col | |
10034 || wp->w_virtcol != wp->w_ru_virtcol | |
10035 #ifdef FEAT_VIRTUALEDIT | |
10036 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
10037 #endif | |
10038 || wp->w_topline != wp->w_ru_topline | |
10039 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
10040 #ifdef FEAT_DIFF | |
10041 || wp->w_topfill != wp->w_ru_topfill | |
10042 #endif | |
10043 || empty_line != wp->w_ru_empty) | |
10044 { | |
10045 cursor_off(); | |
10046 #ifdef FEAT_WINDOWS | |
10047 if (wp->w_status_height) | |
10048 { | |
10049 row = W_WINROW(wp) + wp->w_height; | |
10050 fillchar = fillchar_status(&attr, wp == curwin); | |
10051 # ifdef FEAT_VERTSPLIT | |
10052 off = W_WINCOL(wp); | |
10053 width = W_WIDTH(wp); | |
10054 # endif | |
10055 } | |
10056 else | |
10057 #endif | |
10058 { | |
10059 row = Rows - 1; | |
10060 fillchar = ' '; | |
10061 attr = 0; | |
10062 #ifdef FEAT_VERTSPLIT | |
10063 width = Columns; | |
10064 off = 0; | |
10065 #endif | |
10066 } | |
10067 | |
10068 /* In list mode virtcol needs to be recomputed */ | |
10069 virtcol = wp->w_virtcol; | |
10070 if (wp->w_p_list && lcs_tab1 == NUL) | |
10071 { | |
10072 wp->w_p_list = FALSE; | |
10073 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10074 wp->w_p_list = TRUE; | |
10075 } | |
10076 | |
10077 /* | |
10078 * Some sprintfs return the length, some return a pointer. | |
10079 * To avoid portability problems we use strlen() here. | |
10080 */ | |
1869 | 10081 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10082 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10083 ? 0L | |
10084 : (long)(wp->w_cursor.lnum)); | |
1869 | 10085 len = STRLEN(buffer); |
10086 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10087 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10088 (int)virtcol + 1); | |
10089 | |
10090 /* | |
10091 * Add a "50%" if there is room for it. | |
10092 * On the last line, don't print in the last column (scrolls the | |
10093 * screen up on some terminals). | |
10094 */ | |
10095 i = (int)STRLEN(buffer); | |
1869 | 10096 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10097 o = i + vim_strsize(buffer + i + 1); |
10098 #ifdef FEAT_WINDOWS | |
10099 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10100 #endif | |
10101 ++o; | |
10102 #ifdef FEAT_VERTSPLIT | |
10103 this_ru_col = ru_col - (Columns - width); | |
10104 if (this_ru_col < 0) | |
10105 this_ru_col = 0; | |
10106 #endif | |
10107 /* Never use more than half the window/screen width, leave the other | |
10108 * half for the filename. */ | |
10109 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10110 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10111 if (this_ru_col + o < WITH_WIDTH(width)) | |
10112 { | |
10113 while (this_ru_col + o < WITH_WIDTH(width)) | |
10114 { | |
10115 #ifdef FEAT_MBYTE | |
10116 if (has_mbyte) | |
10117 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10118 else | |
10119 #endif | |
10120 buffer[i++] = fillchar; | |
10121 ++o; | |
10122 } | |
1869 | 10123 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10124 } |
10125 /* Truncate at window boundary. */ | |
10126 #ifdef FEAT_MBYTE | |
10127 if (has_mbyte) | |
10128 { | |
10129 o = 0; | |
474 | 10130 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10131 { |
10132 o += (*mb_ptr2cells)(buffer + i); | |
10133 if (this_ru_col + o > WITH_WIDTH(width)) | |
10134 { | |
10135 buffer[i] = NUL; | |
10136 break; | |
10137 } | |
10138 } | |
10139 } | |
10140 else | |
10141 #endif | |
10142 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10143 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10144 | |
10145 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10146 i = redraw_cmdline; | |
10147 screen_fill(row, row + 1, | |
10148 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10149 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10150 fillchar, fillchar, attr); | |
10151 /* don't redraw the cmdline because of showing the ruler */ | |
10152 redraw_cmdline = i; | |
10153 wp->w_ru_cursor = wp->w_cursor; | |
10154 wp->w_ru_virtcol = wp->w_virtcol; | |
10155 wp->w_ru_empty = empty_line; | |
10156 wp->w_ru_topline = wp->w_topline; | |
10157 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10158 #ifdef FEAT_DIFF | |
10159 wp->w_ru_topfill = wp->w_topfill; | |
10160 #endif | |
10161 } | |
10162 } | |
10163 #endif | |
13 | 10164 |
10165 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10166 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10167 * 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
|
10168 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10169 * Otherwise it depends on 'numberwidth' and the line count. |
10170 */ | |
10171 int | |
10172 number_width(wp) | |
10173 win_T *wp; | |
10174 { | |
10175 int n; | |
10176 linenr_T lnum; | |
10177 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10178 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10179 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10180 lnum = wp->w_buffer->b_ml.ml_line_count; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10181 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10182 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10183 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10184 |
13 | 10185 if (lnum == wp->w_nrwidth_line_count) |
10186 return wp->w_nrwidth_width; | |
10187 wp->w_nrwidth_line_count = lnum; | |
10188 | |
10189 n = 0; | |
10190 do | |
10191 { | |
856 | 10192 lnum /= 10; |
10193 ++n; | |
13 | 10194 } while (lnum > 0); |
10195 | |
10196 /* 'numberwidth' gives the minimal width plus one */ | |
10197 if (n < wp->w_p_nuw - 1) | |
10198 n = wp->w_p_nuw - 1; | |
10199 | |
10200 wp->w_nrwidth_width = n; | |
10201 return n; | |
10202 } | |
10203 #endif |