Mercurial > vim
annotate src/screen.c @ 2364:151b037b7e74 vim73
Fix hang when resizing in diff mode and there are concealed items.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 20 Jul 2010 22:33:34 +0200 |
parents | 496feb41b83f |
children | a96dd77ce213 |
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) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
590 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
591 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
592 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
593 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
594 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
595 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
596 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
597 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
598 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
|
599 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
600 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
601 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
602 /* 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
|
603 * 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
|
604 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
605 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
606 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
607 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
608 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
|
609 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
610 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
|
611 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
612 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
|
613 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
614 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
615 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
616 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
617 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
618 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
|
619 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
620 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
621 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
622 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
623 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
624 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
625 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
626 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
627 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
628 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
629 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
630 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
631 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
632 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
633 # endif |
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 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
636 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
637 |
7 | 638 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
639 static void update_prepare __ARGS((void)); | |
640 static void update_finish __ARGS((void)); | |
641 | |
642 /* | |
643 * Prepare for updating one or more windows. | |
2008 | 644 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 645 */ |
646 static void | |
647 update_prepare() | |
648 { | |
649 cursor_off(); | |
650 updating_screen = TRUE; | |
651 #ifdef FEAT_GUI | |
652 /* Remove the cursor before starting to do anything, because scrolling may | |
653 * make it difficult to redraw the text under it. */ | |
654 if (gui.in_use) | |
655 gui_undraw_cursor(); | |
656 #endif | |
657 #ifdef FEAT_SEARCH_EXTRA | |
658 start_search_hl(); | |
659 #endif | |
660 } | |
661 | |
662 /* | |
663 * Finish updating one or more windows. | |
664 */ | |
665 static void | |
666 update_finish() | |
667 { | |
668 if (redraw_cmdline) | |
669 showmode(); | |
670 | |
671 # ifdef FEAT_SEARCH_EXTRA | |
672 end_search_hl(); | |
673 # endif | |
674 | |
675 updating_screen = FALSE; | |
676 | |
677 # ifdef FEAT_GUI | |
678 gui_may_resize_shell(); | |
679 | |
680 /* Redraw the cursor and update the scrollbars when all screen updating is | |
681 * done. */ | |
682 if (gui.in_use) | |
683 { | |
684 out_flush(); /* required before updating the cursor */ | |
685 gui_update_cursor(FALSE, FALSE); | |
686 gui_update_scrollbars(FALSE); | |
687 } | |
688 # endif | |
689 } | |
690 #endif | |
691 | |
692 #if defined(FEAT_SIGNS) || defined(PROTO) | |
693 void | |
694 update_debug_sign(buf, lnum) | |
695 buf_T *buf; | |
696 linenr_T lnum; | |
697 { | |
698 win_T *wp; | |
699 int doit = FALSE; | |
700 | |
701 # ifdef FEAT_FOLDING | |
702 win_foldinfo.fi_level = 0; | |
703 # endif | |
704 | |
705 /* update/delete a specific mark */ | |
706 FOR_ALL_WINDOWS(wp) | |
707 { | |
708 if (buf != NULL && lnum > 0) | |
709 { | |
710 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
711 && lnum < wp->w_botline) | |
712 { | |
713 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
714 wp->w_redraw_top = lnum; | |
715 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
716 wp->w_redraw_bot = lnum; | |
717 redraw_win_later(wp, VALID); | |
718 } | |
719 } | |
720 else | |
721 redraw_win_later(wp, VALID); | |
722 if (wp->w_redr_type != 0) | |
723 doit = TRUE; | |
724 } | |
725 | |
2008 | 726 /* Return when there is nothing to do or screen updating already |
727 * happening. */ | |
728 if (!doit || updating_screen) | |
7 | 729 return; |
730 | |
731 /* update all windows that need updating */ | |
732 update_prepare(); | |
733 | |
734 # ifdef FEAT_WINDOWS | |
735 for (wp = firstwin; wp; wp = wp->w_next) | |
736 { | |
737 if (wp->w_redr_type != 0) | |
738 win_update(wp); | |
739 if (wp->w_redr_status) | |
740 win_redr_status(wp); | |
741 } | |
742 # else | |
743 if (curwin->w_redr_type != 0) | |
744 win_update(curwin); | |
745 # endif | |
746 | |
747 update_finish(); | |
748 } | |
749 #endif | |
750 | |
751 | |
752 #if defined(FEAT_GUI) || defined(PROTO) | |
753 /* | |
754 * Update a single window, its status line and maybe the command line msg. | |
755 * Used for the GUI scrollbar. | |
756 */ | |
757 void | |
758 updateWindow(wp) | |
759 win_T *wp; | |
760 { | |
2008 | 761 /* return if already busy updating */ |
762 if (updating_screen) | |
763 return; | |
764 | |
7 | 765 update_prepare(); |
766 | |
767 #ifdef FEAT_CLIPBOARD | |
768 /* When Visual area changed, may have to update selection. */ | |
769 if (clip_star.available && clip_isautosel()) | |
770 clip_update_selection(); | |
771 #endif | |
670 | 772 |
7 | 773 win_update(wp); |
670 | 774 |
7 | 775 #ifdef FEAT_WINDOWS |
670 | 776 /* When the screen was cleared redraw the tab pages line. */ |
673 | 777 if (redraw_tabline) |
677 | 778 draw_tabline(); |
670 | 779 |
7 | 780 if (wp->w_redr_status |
781 # ifdef FEAT_CMDL_INFO | |
782 || p_ru | |
783 # endif | |
784 # ifdef FEAT_STL_OPT | |
40 | 785 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 786 # endif |
787 ) | |
788 win_redr_status(wp); | |
789 #endif | |
790 | |
791 update_finish(); | |
792 } | |
793 #endif | |
794 | |
795 /* | |
796 * Update a single window. | |
797 * | |
798 * This may cause the windows below it also to be redrawn (when clearing the | |
799 * screen or scrolling lines). | |
800 * | |
801 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
802 * implies the one below it. | |
803 * NOT_VALID redraw the whole window | |
743 | 804 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 805 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
806 * INVERTED redraw the changed part of the Visual area | |
807 * INVERTED_ALL redraw the whole Visual area | |
808 * VALID 1. scroll up/down to adjust for a changed w_topline | |
809 * 2. update lines at the top when scrolled down | |
810 * 3. redraw changed text: | |
301 | 811 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 812 * b_mod_top and b_mod_bot. |
813 * - if wp->w_redraw_top non-zero, redraw lines between | |
814 * wp->w_redraw_top and wp->w_redr_bot. | |
815 * - continue redrawing when syntax status is invalid. | |
816 * 4. if scrolled up, update lines at the bottom. | |
817 * This results in three areas that may need updating: | |
818 * top: from first row to top_end (when scrolled down) | |
819 * mid: from mid_start to mid_end (update inversion or changed text) | |
820 * bot: from bot_start to last row (when scrolled up) | |
821 */ | |
822 static void | |
823 win_update(wp) | |
824 win_T *wp; | |
825 { | |
826 buf_T *buf = wp->w_buffer; | |
827 int type; | |
828 int top_end = 0; /* Below last row of the top area that needs | |
829 updating. 0 when no top area updating. */ | |
830 int mid_start = 999;/* first row of the mid area that needs | |
831 updating. 999 when no mid area updating. */ | |
832 int mid_end = 0; /* Below last row of the mid area that needs | |
833 updating. 0 when no mid area updating. */ | |
834 int bot_start = 999;/* first row of the bot area that needs | |
835 updating. 999 when no bot area updating */ | |
836 #ifdef FEAT_VISUAL | |
837 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
838 w_topline got smaller a bit */ | |
839 #endif | |
840 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 841 matchitem_T *cur; /* points to the match list */ |
7 | 842 int top_to_mod = FALSE; /* redraw above mod_top */ |
843 #endif | |
844 | |
845 int row; /* current window row to display */ | |
846 linenr_T lnum; /* current buffer lnum to display */ | |
847 int idx; /* current index in w_lines[] */ | |
848 int srow; /* starting row of the current line */ | |
849 | |
850 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
851 int didline = FALSE; /* if TRUE, we finished the last line */ | |
852 int i; | |
853 long j; | |
854 static int recursive = FALSE; /* being called recursively */ | |
855 int old_botline = wp->w_botline; | |
856 #ifdef FEAT_FOLDING | |
857 long fold_count; | |
858 #endif | |
859 #ifdef FEAT_SYN_HL | |
860 /* remember what happened to the previous line, to know if | |
861 * check_visual_highlight() can be used */ | |
862 #define DID_NONE 1 /* didn't update a line */ | |
863 #define DID_LINE 2 /* updated a normal line */ | |
864 #define DID_FOLD 3 /* updated a folded line */ | |
865 int did_update = DID_NONE; | |
866 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
867 #endif | |
868 linenr_T mod_top = 0; | |
869 linenr_T mod_bot = 0; | |
870 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
871 int save_got_int; | |
872 #endif | |
873 | |
874 type = wp->w_redr_type; | |
875 | |
876 if (type == NOT_VALID) | |
877 { | |
878 #ifdef FEAT_WINDOWS | |
879 wp->w_redr_status = TRUE; | |
880 #endif | |
881 wp->w_lines_valid = 0; | |
882 } | |
883 | |
884 /* Window is zero-height: nothing to draw. */ | |
885 if (wp->w_height == 0) | |
886 { | |
887 wp->w_redr_type = 0; | |
888 return; | |
889 } | |
890 | |
891 #ifdef FEAT_VERTSPLIT | |
892 /* Window is zero-width: Only need to draw the separator. */ | |
893 if (wp->w_width == 0) | |
894 { | |
895 /* draw the vertical separator right of this window */ | |
896 draw_vsep_win(wp, 0); | |
897 wp->w_redr_type = 0; | |
898 return; | |
899 } | |
900 #endif | |
901 | |
902 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
903 init_search_hl(wp); |
7 | 904 #endif |
905 | |
13 | 906 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
907 /* 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
|
908 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
909 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 910 if (wp->w_nrwidth != i) |
13 | 911 { |
912 type = NOT_VALID; | |
677 | 913 wp->w_nrwidth = i; |
13 | 914 } |
915 else | |
916 #endif | |
917 | |
7 | 918 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
919 { | |
920 /* | |
921 * When there are both inserted/deleted lines and specific lines to be | |
922 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
923 * everything (only happens when redrawing is off for while). | |
924 */ | |
925 type = NOT_VALID; | |
926 } | |
927 else | |
928 { | |
929 /* | |
930 * Set mod_top to the first line that needs displaying because of | |
931 * changes. Set mod_bot to the first line after the changes. | |
932 */ | |
933 mod_top = wp->w_redraw_top; | |
934 if (wp->w_redraw_bot != 0) | |
935 mod_bot = wp->w_redraw_bot + 1; | |
936 else | |
937 mod_bot = 0; | |
938 wp->w_redraw_top = 0; /* reset for next time */ | |
939 wp->w_redraw_bot = 0; | |
940 if (buf->b_mod_set) | |
941 { | |
942 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
943 { | |
944 mod_top = buf->b_mod_top; | |
945 #ifdef FEAT_SYN_HL | |
946 /* Need to redraw lines above the change that may be included | |
947 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
948 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
949 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
950 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 951 if (mod_top < 1) |
952 mod_top = 1; | |
953 } | |
954 #endif | |
955 } | |
956 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
957 mod_bot = buf->b_mod_bot; | |
958 | |
959 #ifdef FEAT_SEARCH_EXTRA | |
960 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
961 * change in one line may make the Search highlighting in a | |
962 * previous line invalid. Simple solution: redraw all visible | |
963 * lines above the change. | |
1326 | 964 * Same for a match pattern. |
7 | 965 */ |
699 | 966 if (search_hl.rm.regprog != NULL |
967 && re_multiline(search_hl.rm.regprog)) | |
7 | 968 top_to_mod = TRUE; |
699 | 969 else |
1326 | 970 { |
971 cur = wp->w_match_head; | |
972 while (cur != NULL) | |
973 { | |
974 if (cur->match.regprog != NULL | |
975 && re_multiline(cur->match.regprog)) | |
699 | 976 { |
977 top_to_mod = TRUE; | |
978 break; | |
979 } | |
1326 | 980 cur = cur->next; |
981 } | |
982 } | |
7 | 983 #endif |
984 } | |
985 #ifdef FEAT_FOLDING | |
986 if (mod_top != 0 && hasAnyFolding(wp)) | |
987 { | |
988 linenr_T lnumt, lnumb; | |
989 | |
990 /* | |
991 * A change in a line can cause lines above it to become folded or | |
992 * unfolded. Find the top most buffer line that may be affected. | |
993 * If the line was previously folded and displayed, get the first | |
994 * line of that fold. If the line is folded now, get the first | |
995 * folded line. Use the minimum of these two. | |
996 */ | |
997 | |
998 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
999 * the line below it. If there is no valid entry, use w_topline. | |
1000 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1001 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1002 lnumt = wp->w_topline; | |
1003 lnumb = MAXLNUM; | |
1004 for (i = 0; i < wp->w_lines_valid; ++i) | |
1005 if (wp->w_lines[i].wl_valid) | |
1006 { | |
1007 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1008 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1009 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1010 { | |
1011 lnumb = wp->w_lines[i].wl_lnum; | |
1012 /* When there is a fold column it might need updating | |
1013 * in the next line ("J" just above an open fold). */ | |
1014 if (wp->w_p_fdc > 0) | |
1015 ++lnumb; | |
1016 } | |
1017 } | |
1018 | |
1019 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1020 if (mod_top > lnumt) | |
1021 mod_top = lnumt; | |
1022 | |
1023 /* Now do the same for the bottom line (one above mod_bot). */ | |
1024 --mod_bot; | |
1025 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1026 ++mod_bot; | |
1027 if (mod_bot < lnumb) | |
1028 mod_bot = lnumb; | |
1029 } | |
1030 #endif | |
1031 | |
1032 /* When a change starts above w_topline and the end is below | |
1033 * w_topline, start redrawing at w_topline. | |
36 | 1034 * If the end of the change is above w_topline: do like no change was |
1035 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1036 if (mod_top != 0 && mod_top < wp->w_topline) |
1037 { | |
1038 if (mod_bot > wp->w_topline) | |
1039 mod_top = wp->w_topline; | |
1040 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1041 else if (syntax_present(wp)) |
7 | 1042 top_end = 1; |
1043 #endif | |
1044 } | |
36 | 1045 |
1046 /* When line numbers are displayed need to redraw all lines below | |
1047 * inserted/deleted lines. */ | |
1048 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1049 mod_bot = MAXLNUM; | |
7 | 1050 } |
1051 | |
1052 /* | |
1053 * When only displaying the lines at the top, set top_end. Used when | |
1054 * window has scrolled down for msg_scrolled. | |
1055 */ | |
1056 if (type == REDRAW_TOP) | |
1057 { | |
1058 j = 0; | |
1059 for (i = 0; i < wp->w_lines_valid; ++i) | |
1060 { | |
1061 j += wp->w_lines[i].wl_size; | |
1062 if (j >= wp->w_upd_rows) | |
1063 { | |
1064 top_end = j; | |
1065 break; | |
1066 } | |
1067 } | |
1068 if (top_end == 0) | |
1069 /* not found (cannot happen?): redraw everything */ | |
1070 type = NOT_VALID; | |
1071 else | |
1072 /* top area defined, the rest is VALID */ | |
1073 type = VALID; | |
1074 } | |
1075 | |
1378 | 1076 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1077 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1078 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1079 * called. */ | |
1080 if (screen_cleared) | |
1081 screen_cleared = MAYBE; | |
1082 | |
7 | 1083 /* |
1084 * If there are no changes on the screen that require a complete redraw, | |
1085 * handle three cases: | |
1086 * 1: we are off the top of the screen by a few lines: scroll down | |
1087 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1088 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1089 * w_lines[] that needs updating. | |
1090 */ | |
743 | 1091 if ((type == VALID || type == SOME_VALID |
1092 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1093 #ifdef FEAT_DIFF |
1094 && !wp->w_botfill && !wp->w_old_botfill | |
1095 #endif | |
1096 ) | |
1097 { | |
1098 if (mod_top != 0 && wp->w_topline == mod_top) | |
1099 { | |
1100 /* | |
1101 * w_topline is the first changed line, the scrolling will be done | |
1102 * further down. | |
1103 */ | |
1104 } | |
1105 else if (wp->w_lines[0].wl_valid | |
1106 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1107 #ifdef FEAT_DIFF | |
1108 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1109 && wp->w_topfill > wp->w_old_topfill) | |
1110 #endif | |
1111 )) | |
1112 { | |
1113 /* | |
1114 * New topline is above old topline: May scroll down. | |
1115 */ | |
1116 #ifdef FEAT_FOLDING | |
1117 if (hasAnyFolding(wp)) | |
1118 { | |
1119 linenr_T ln; | |
1120 | |
1121 /* count the number of lines we are off, counting a sequence | |
1122 * of folded lines as one */ | |
1123 j = 0; | |
1124 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1125 { | |
1126 ++j; | |
1127 if (j >= wp->w_height - 2) | |
1128 break; | |
1129 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1130 } | |
1131 } | |
1132 else | |
1133 #endif | |
1134 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1135 if (j < wp->w_height - 2) /* not too far off */ | |
1136 { | |
1137 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1138 #ifdef FEAT_DIFF | |
1139 /* insert extra lines for previously invisible filler lines */ | |
1140 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1141 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1142 - wp->w_old_topfill; | |
1143 #endif | |
1144 if (i < wp->w_height - 2) /* less than a screen off */ | |
1145 { | |
1146 /* | |
1147 * Try to insert the correct number of lines. | |
1148 * If not the last window, delete the lines at the bottom. | |
1149 * win_ins_lines may fail when the terminal can't do it. | |
1150 */ | |
1151 if (i > 0) | |
1152 check_for_delay(FALSE); | |
1153 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1154 { | |
1155 if (wp->w_lines_valid != 0) | |
1156 { | |
1157 /* Need to update rows that are new, stop at the | |
1158 * first one that scrolled down. */ | |
1159 top_end = i; | |
1160 #ifdef FEAT_VISUAL | |
1161 scrolled_down = TRUE; | |
1162 #endif | |
1163 | |
1164 /* Move the entries that were scrolled, disable | |
1165 * the entries for the lines to be redrawn. */ | |
1166 if ((wp->w_lines_valid += j) > wp->w_height) | |
1167 wp->w_lines_valid = wp->w_height; | |
1168 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1169 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1170 while (idx >= 0) | |
1171 wp->w_lines[idx--].wl_valid = FALSE; | |
1172 } | |
1173 } | |
1174 else | |
1175 mid_start = 0; /* redraw all lines */ | |
1176 } | |
1177 else | |
1178 mid_start = 0; /* redraw all lines */ | |
1179 } | |
1180 else | |
1181 mid_start = 0; /* redraw all lines */ | |
1182 } | |
1183 else | |
1184 { | |
1185 /* | |
1186 * New topline is at or below old topline: May scroll up. | |
1187 * When topline didn't change, find first entry in w_lines[] that | |
1188 * needs updating. | |
1189 */ | |
1190 | |
1191 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1192 j = -1; | |
1193 row = 0; | |
1194 for (i = 0; i < wp->w_lines_valid; i++) | |
1195 { | |
1196 if (wp->w_lines[i].wl_valid | |
1197 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1198 { | |
1199 j = i; | |
1200 break; | |
1201 } | |
1202 row += wp->w_lines[i].wl_size; | |
1203 } | |
1204 if (j == -1) | |
1205 { | |
1206 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1207 * lines */ | |
1208 mid_start = 0; | |
1209 } | |
1210 else | |
1211 { | |
1212 /* | |
1213 * Try to delete the correct number of lines. | |
1214 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1215 */ | |
1216 #ifdef FEAT_DIFF | |
1217 /* If the topline didn't change, delete old filler lines, | |
1218 * otherwise delete filler lines of the new topline... */ | |
1219 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1220 row += wp->w_old_topfill; | |
1221 else | |
1222 row += diff_check_fill(wp, wp->w_topline); | |
1223 /* ... but don't delete new filler lines. */ | |
1224 row -= wp->w_topfill; | |
1225 #endif | |
1226 if (row > 0) | |
1227 { | |
1228 check_for_delay(FALSE); | |
1229 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1230 bot_start = wp->w_height - row; | |
1231 else | |
1232 mid_start = 0; /* redraw all lines */ | |
1233 } | |
1234 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1235 { | |
1236 /* | |
1237 * Skip the lines (below the deleted lines) that are still | |
1238 * valid and don't need redrawing. Copy their info | |
1239 * upwards, to compensate for the deleted lines. Set | |
1240 * bot_start to the first row that needs redrawing. | |
1241 */ | |
1242 bot_start = 0; | |
1243 idx = 0; | |
1244 for (;;) | |
1245 { | |
1246 wp->w_lines[idx] = wp->w_lines[j]; | |
1247 /* stop at line that didn't fit, unless it is still | |
1248 * valid (no lines deleted) */ | |
1249 if (row > 0 && bot_start + row | |
1250 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1251 { | |
1252 wp->w_lines_valid = idx + 1; | |
1253 break; | |
1254 } | |
1255 bot_start += wp->w_lines[idx++].wl_size; | |
1256 | |
1257 /* stop at the last valid entry in w_lines[].wl_size */ | |
1258 if (++j >= wp->w_lines_valid) | |
1259 { | |
1260 wp->w_lines_valid = idx; | |
1261 break; | |
1262 } | |
1263 } | |
1264 #ifdef FEAT_DIFF | |
1265 /* Correct the first entry for filler lines at the top | |
1266 * when it won't get updated below. */ | |
1267 if (wp->w_p_diff && bot_start > 0) | |
1268 wp->w_lines[0].wl_size = | |
1269 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1270 + wp->w_topfill; | |
1271 #endif | |
1272 } | |
1273 } | |
1274 } | |
1275 | |
1276 /* When starting redraw in the first line, redraw all lines. When | |
1277 * there is only one window it's probably faster to clear the screen | |
1278 * first. */ | |
1279 if (mid_start == 0) | |
1280 { | |
1281 mid_end = wp->w_height; | |
1282 if (lastwin == firstwin) | |
981 | 1283 { |
1331 | 1284 /* Clear the screen when it was not done by win_del_lines() or |
1285 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1286 * then. */ | |
1287 if (screen_cleared != TRUE) | |
1288 screenclear(); | |
981 | 1289 #ifdef FEAT_WINDOWS |
1290 /* The screen was cleared, redraw the tab pages line. */ | |
1291 if (redraw_tabline) | |
1292 draw_tabline(); | |
1293 #endif | |
1294 } | |
7 | 1295 } |
1331 | 1296 |
1297 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1298 * cleared (only happens for the first window) or when screenclear() | |
1299 * was called directly above, "must_redraw" will have been set to | |
1300 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1301 if (screen_cleared == TRUE) | |
1302 must_redraw = 0; | |
7 | 1303 } |
1304 else | |
1305 { | |
1306 /* Not VALID or INVERTED: redraw all lines. */ | |
1307 mid_start = 0; | |
1308 mid_end = wp->w_height; | |
1309 } | |
1310 | |
743 | 1311 if (type == SOME_VALID) |
1312 { | |
1313 /* SOME_VALID: redraw all lines. */ | |
1314 mid_start = 0; | |
1315 mid_end = wp->w_height; | |
1316 type = NOT_VALID; | |
1317 } | |
1318 | |
7 | 1319 #ifdef FEAT_VISUAL |
1320 /* check if we are updating or removing the inverted part */ | |
1321 if ((VIsual_active && buf == curwin->w_buffer) | |
1322 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1323 { | |
1324 linenr_T from, to; | |
1325 | |
1326 if (VIsual_active) | |
1327 { | |
1328 if (VIsual_active | |
1329 && (VIsual_mode != wp->w_old_visual_mode | |
1330 || type == INVERTED_ALL)) | |
1331 { | |
1332 /* | |
1333 * If the type of Visual selection changed, redraw the whole | |
1334 * selection. Also when the ownership of the X selection is | |
1335 * gained or lost. | |
1336 */ | |
1337 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1338 { | |
1339 from = curwin->w_cursor.lnum; | |
1340 to = VIsual.lnum; | |
1341 } | |
1342 else | |
1343 { | |
1344 from = VIsual.lnum; | |
1345 to = curwin->w_cursor.lnum; | |
1346 } | |
1347 /* redraw more when the cursor moved as well */ | |
1348 if (wp->w_old_cursor_lnum < from) | |
1349 from = wp->w_old_cursor_lnum; | |
1350 if (wp->w_old_cursor_lnum > to) | |
1351 to = wp->w_old_cursor_lnum; | |
1352 if (wp->w_old_visual_lnum < from) | |
1353 from = wp->w_old_visual_lnum; | |
1354 if (wp->w_old_visual_lnum > to) | |
1355 to = wp->w_old_visual_lnum; | |
1356 } | |
1357 else | |
1358 { | |
1359 /* | |
1360 * Find the line numbers that need to be updated: The lines | |
1361 * between the old cursor position and the current cursor | |
1362 * position. Also check if the Visual position changed. | |
1363 */ | |
1364 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1365 { | |
1366 from = curwin->w_cursor.lnum; | |
1367 to = wp->w_old_cursor_lnum; | |
1368 } | |
1369 else | |
1370 { | |
1371 from = wp->w_old_cursor_lnum; | |
1372 to = curwin->w_cursor.lnum; | |
1373 if (from == 0) /* Visual mode just started */ | |
1374 from = to; | |
1375 } | |
1376 | |
422 | 1377 if (VIsual.lnum != wp->w_old_visual_lnum |
1378 || VIsual.col != wp->w_old_visual_col) | |
7 | 1379 { |
1380 if (wp->w_old_visual_lnum < from | |
1381 && wp->w_old_visual_lnum != 0) | |
1382 from = wp->w_old_visual_lnum; | |
1383 if (wp->w_old_visual_lnum > to) | |
1384 to = wp->w_old_visual_lnum; | |
1385 if (VIsual.lnum < from) | |
1386 from = VIsual.lnum; | |
1387 if (VIsual.lnum > to) | |
1388 to = VIsual.lnum; | |
1389 } | |
1390 } | |
1391 | |
1392 /* | |
1393 * If in block mode and changed column or curwin->w_curswant: | |
1394 * update all lines. | |
1395 * First compute the actual start and end column. | |
1396 */ | |
1397 if (VIsual_mode == Ctrl_V) | |
1398 { | |
1399 colnr_T fromc, toc; | |
1400 | |
1401 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1402 ++toc; | |
1403 if (curwin->w_curswant == MAXCOL) | |
1404 toc = MAXCOL; | |
1405 | |
1406 if (fromc != wp->w_old_cursor_fcol | |
1407 || toc != wp->w_old_cursor_lcol) | |
1408 { | |
1409 if (from > VIsual.lnum) | |
1410 from = VIsual.lnum; | |
1411 if (to < VIsual.lnum) | |
1412 to = VIsual.lnum; | |
1413 } | |
1414 wp->w_old_cursor_fcol = fromc; | |
1415 wp->w_old_cursor_lcol = toc; | |
1416 } | |
1417 } | |
1418 else | |
1419 { | |
1420 /* Use the line numbers of the old Visual area. */ | |
1421 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1422 { | |
1423 from = wp->w_old_cursor_lnum; | |
1424 to = wp->w_old_visual_lnum; | |
1425 } | |
1426 else | |
1427 { | |
1428 from = wp->w_old_visual_lnum; | |
1429 to = wp->w_old_cursor_lnum; | |
1430 } | |
1431 } | |
1432 | |
1433 /* | |
1434 * There is no need to update lines above the top of the window. | |
1435 */ | |
1436 if (from < wp->w_topline) | |
1437 from = wp->w_topline; | |
1438 | |
1439 /* | |
1440 * If we know the value of w_botline, use it to restrict the update to | |
1441 * the lines that are visible in the window. | |
1442 */ | |
1443 if (wp->w_valid & VALID_BOTLINE) | |
1444 { | |
1445 if (from >= wp->w_botline) | |
1446 from = wp->w_botline - 1; | |
1447 if (to >= wp->w_botline) | |
1448 to = wp->w_botline - 1; | |
1449 } | |
1450 | |
1451 /* | |
1452 * Find the minimal part to be updated. | |
1453 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1454 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1455 * top_end; need to redraw from top_end to the "to" line. | |
1456 * A middle mouse click with a Visual selection may change the text | |
1457 * above the Visual area and reset wl_valid, do count these for | |
1458 * mid_end (in srow). | |
1459 */ | |
1460 if (mid_start > 0) | |
1461 { | |
1462 lnum = wp->w_topline; | |
1463 idx = 0; | |
1464 srow = 0; | |
1465 if (scrolled_down) | |
1466 mid_start = top_end; | |
1467 else | |
1468 mid_start = 0; | |
1469 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1470 { | |
1471 if (wp->w_lines[idx].wl_valid) | |
1472 mid_start += wp->w_lines[idx].wl_size; | |
1473 else if (!scrolled_down) | |
1474 srow += wp->w_lines[idx].wl_size; | |
1475 ++idx; | |
1476 # ifdef FEAT_FOLDING | |
1477 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1478 lnum = wp->w_lines[idx].wl_lnum; | |
1479 else | |
1480 # endif | |
1481 ++lnum; | |
1482 } | |
1483 srow += mid_start; | |
1484 mid_end = wp->w_height; | |
1485 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1486 { | |
1487 if (wp->w_lines[idx].wl_valid | |
1488 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1489 { | |
1490 /* Only update until first row of this line */ | |
1491 mid_end = srow; | |
1492 break; | |
1493 } | |
1494 srow += wp->w_lines[idx].wl_size; | |
1495 } | |
1496 } | |
1497 } | |
1498 | |
1499 if (VIsual_active && buf == curwin->w_buffer) | |
1500 { | |
1501 wp->w_old_visual_mode = VIsual_mode; | |
1502 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1503 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1504 wp->w_old_visual_col = VIsual.col; |
7 | 1505 wp->w_old_curswant = curwin->w_curswant; |
1506 } | |
1507 else | |
1508 { | |
1509 wp->w_old_visual_mode = 0; | |
1510 wp->w_old_cursor_lnum = 0; | |
1511 wp->w_old_visual_lnum = 0; | |
422 | 1512 wp->w_old_visual_col = 0; |
7 | 1513 } |
1514 #endif /* FEAT_VISUAL */ | |
1515 | |
1516 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1517 /* reset got_int, otherwise regexp won't work */ | |
1518 save_got_int = got_int; | |
1519 got_int = 0; | |
1520 #endif | |
1521 #ifdef FEAT_FOLDING | |
1522 win_foldinfo.fi_level = 0; | |
1523 #endif | |
1524 | |
1525 /* | |
1526 * Update all the window rows. | |
1527 */ | |
1528 idx = 0; /* first entry in w_lines[].wl_size */ | |
1529 row = 0; | |
1530 srow = 0; | |
1531 lnum = wp->w_topline; /* first line shown in window */ | |
1532 for (;;) | |
1533 { | |
1534 /* stop updating when reached the end of the window (check for _past_ | |
1535 * the end of the window is at the end of the loop) */ | |
1536 if (row == wp->w_height) | |
1537 { | |
1538 didline = TRUE; | |
1539 break; | |
1540 } | |
1541 | |
1542 /* stop updating when hit the end of the file */ | |
1543 if (lnum > buf->b_ml.ml_line_count) | |
1544 { | |
1545 eof = TRUE; | |
1546 break; | |
1547 } | |
1548 | |
1549 /* Remember the starting row of the line that is going to be dealt | |
1550 * with. It is used further down when the line doesn't fit. */ | |
1551 srow = row; | |
1552 | |
1553 /* | |
1554 * Update a line when it is in an area that needs updating, when it | |
1555 * has changes or w_lines[idx] is invalid. | |
1556 * bot_start may be halfway a wrapped line after using | |
1557 * win_del_lines(), check if the current line includes it. | |
1558 * When syntax folding is being used, the saved syntax states will | |
1559 * already have been updated, we can't see where the syntax state is | |
1560 * the same again, just update until the end of the window. | |
1561 */ | |
1562 if (row < top_end | |
1563 || (row >= mid_start && row < mid_end) | |
1564 #ifdef FEAT_SEARCH_EXTRA | |
1565 || top_to_mod | |
1566 #endif | |
1567 || idx >= wp->w_lines_valid | |
1568 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1569 || (mod_top != 0 | |
1570 && (lnum == mod_top | |
1571 || (lnum >= mod_top | |
1572 && (lnum < mod_bot | |
1573 #ifdef FEAT_SYN_HL | |
1574 || did_update == DID_FOLD | |
1575 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1576 && syntax_present(wp) |
7 | 1577 && ( |
1578 # ifdef FEAT_FOLDING | |
1579 (foldmethodIsSyntax(wp) | |
1580 && hasAnyFolding(wp)) || | |
1581 # endif | |
1582 syntax_check_changed(lnum))) | |
1583 #endif | |
1584 ))))) | |
1585 { | |
1586 #ifdef FEAT_SEARCH_EXTRA | |
1587 if (lnum == mod_top) | |
1588 top_to_mod = FALSE; | |
1589 #endif | |
1590 | |
1591 /* | |
1592 * When at start of changed lines: May scroll following lines | |
1593 * up or down to minimize redrawing. | |
1594 * Don't do this when the change continues until the end. | |
1595 * Don't scroll when dollar_vcol is non-zero, keep the "$". | |
1596 */ | |
1597 if (lnum == mod_top | |
1598 && mod_bot != MAXLNUM | |
1599 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) | |
1600 { | |
1601 int old_rows = 0; | |
1602 int new_rows = 0; | |
1603 int xtra_rows; | |
1604 linenr_T l; | |
1605 | |
1606 /* Count the old number of window rows, using w_lines[], which | |
1607 * should still contain the sizes for the lines as they are | |
1608 * currently displayed. */ | |
1609 for (i = idx; i < wp->w_lines_valid; ++i) | |
1610 { | |
1611 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1612 * lines are part of the changed area. */ | |
1613 if (wp->w_lines[i].wl_valid | |
1614 && wp->w_lines[i].wl_lnum == mod_bot) | |
1615 break; | |
1616 old_rows += wp->w_lines[i].wl_size; | |
1617 #ifdef FEAT_FOLDING | |
1618 if (wp->w_lines[i].wl_valid | |
1619 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1620 { | |
1621 /* Must have found the last valid entry above mod_bot. | |
1622 * Add following invalid entries. */ | |
1623 ++i; | |
1624 while (i < wp->w_lines_valid | |
1625 && !wp->w_lines[i].wl_valid) | |
1626 old_rows += wp->w_lines[i++].wl_size; | |
1627 break; | |
1628 } | |
1629 #endif | |
1630 } | |
1631 | |
1632 if (i >= wp->w_lines_valid) | |
1633 { | |
1634 /* We can't find a valid line below the changed lines, | |
1635 * need to redraw until the end of the window. | |
1636 * Inserting/deleting lines has no use. */ | |
1637 bot_start = 0; | |
1638 } | |
1639 else | |
1640 { | |
1641 /* Able to count old number of rows: Count new window | |
1642 * rows, and may insert/delete lines */ | |
1643 j = idx; | |
1644 for (l = lnum; l < mod_bot; ++l) | |
1645 { | |
1646 #ifdef FEAT_FOLDING | |
1647 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1648 ++new_rows; | |
1649 else | |
1650 #endif | |
1651 #ifdef FEAT_DIFF | |
1652 if (l == wp->w_topline) | |
1653 new_rows += plines_win_nofill(wp, l, TRUE) | |
1654 + wp->w_topfill; | |
1655 else | |
1656 #endif | |
1657 new_rows += plines_win(wp, l, TRUE); | |
1658 ++j; | |
1659 if (new_rows > wp->w_height - row - 2) | |
1660 { | |
1661 /* it's getting too much, must redraw the rest */ | |
1662 new_rows = 9999; | |
1663 break; | |
1664 } | |
1665 } | |
1666 xtra_rows = new_rows - old_rows; | |
1667 if (xtra_rows < 0) | |
1668 { | |
1669 /* May scroll text up. If there is not enough | |
1670 * remaining text or scrolling fails, must redraw the | |
1671 * rest. If scrolling works, must redraw the text | |
1672 * below the scrolled text. */ | |
1673 if (row - xtra_rows >= wp->w_height - 2) | |
1674 mod_bot = MAXLNUM; | |
1675 else | |
1676 { | |
1677 check_for_delay(FALSE); | |
1678 if (win_del_lines(wp, row, | |
1679 -xtra_rows, FALSE, FALSE) == FAIL) | |
1680 mod_bot = MAXLNUM; | |
1681 else | |
1682 bot_start = wp->w_height + xtra_rows; | |
1683 } | |
1684 } | |
1685 else if (xtra_rows > 0) | |
1686 { | |
1687 /* May scroll text down. If there is not enough | |
1688 * remaining text of scrolling fails, must redraw the | |
1689 * rest. */ | |
1690 if (row + xtra_rows >= wp->w_height - 2) | |
1691 mod_bot = MAXLNUM; | |
1692 else | |
1693 { | |
1694 check_for_delay(FALSE); | |
1695 if (win_ins_lines(wp, row + old_rows, | |
1696 xtra_rows, FALSE, FALSE) == FAIL) | |
1697 mod_bot = MAXLNUM; | |
1698 else if (top_end > row + old_rows) | |
1699 /* Scrolled the part at the top that requires | |
1700 * updating down. */ | |
1701 top_end += xtra_rows; | |
1702 } | |
1703 } | |
1704 | |
1705 /* When not updating the rest, may need to move w_lines[] | |
1706 * entries. */ | |
1707 if (mod_bot != MAXLNUM && i != j) | |
1708 { | |
1709 if (j < i) | |
1710 { | |
1711 int x = row + new_rows; | |
1712 | |
1713 /* move entries in w_lines[] upwards */ | |
1714 for (;;) | |
1715 { | |
1716 /* stop at last valid entry in w_lines[] */ | |
1717 if (i >= wp->w_lines_valid) | |
1718 { | |
1719 wp->w_lines_valid = j; | |
1720 break; | |
1721 } | |
1722 wp->w_lines[j] = wp->w_lines[i]; | |
1723 /* stop at a line that won't fit */ | |
1724 if (x + (int)wp->w_lines[j].wl_size | |
1725 > wp->w_height) | |
1726 { | |
1727 wp->w_lines_valid = j + 1; | |
1728 break; | |
1729 } | |
1730 x += wp->w_lines[j++].wl_size; | |
1731 ++i; | |
1732 } | |
1733 if (bot_start > x) | |
1734 bot_start = x; | |
1735 } | |
1736 else /* j > i */ | |
1737 { | |
1738 /* move entries in w_lines[] downwards */ | |
1739 j -= i; | |
1740 wp->w_lines_valid += j; | |
1741 if (wp->w_lines_valid > wp->w_height) | |
1742 wp->w_lines_valid = wp->w_height; | |
1743 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1744 wp->w_lines[i] = wp->w_lines[i - j]; | |
1745 | |
1746 /* The w_lines[] entries for inserted lines are | |
1747 * now invalid, but wl_size may be used above. | |
1748 * Reset to zero. */ | |
1749 while (i >= idx) | |
1750 { | |
1751 wp->w_lines[i].wl_size = 0; | |
1752 wp->w_lines[i--].wl_valid = FALSE; | |
1753 } | |
1754 } | |
1755 } | |
1756 } | |
1757 } | |
1758 | |
1759 #ifdef FEAT_FOLDING | |
1760 /* | |
1761 * When lines are folded, display one line for all of them. | |
1762 * Otherwise, display normally (can be several display lines when | |
1763 * 'wrap' is on). | |
1764 */ | |
1765 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1766 if (fold_count != 0) | |
1767 { | |
1768 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1769 ++row; | |
1770 --fold_count; | |
1771 wp->w_lines[idx].wl_folded = TRUE; | |
1772 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1773 # ifdef FEAT_SYN_HL | |
1774 did_update = DID_FOLD; | |
1775 # endif | |
1776 } | |
1777 else | |
1778 #endif | |
1779 if (idx < wp->w_lines_valid | |
1780 && wp->w_lines[idx].wl_valid | |
1781 && wp->w_lines[idx].wl_lnum == lnum | |
1782 && lnum > wp->w_topline | |
1783 && !(dy_flags & DY_LASTLINE) | |
1784 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1785 #ifdef FEAT_DIFF | |
1786 && diff_check_fill(wp, lnum) == 0 | |
1787 #endif | |
1788 ) | |
1789 { | |
1790 /* This line is not going to fit. Don't draw anything here, | |
1791 * will draw "@ " lines below. */ | |
1792 row = wp->w_height + 1; | |
1793 } | |
1794 else | |
1795 { | |
1796 #ifdef FEAT_SEARCH_EXTRA | |
1797 prepare_search_hl(wp, lnum); | |
1798 #endif | |
1799 #ifdef FEAT_SYN_HL | |
1800 /* Let the syntax stuff know we skipped a few lines. */ | |
1801 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
|
1802 && syntax_present(wp)) |
7 | 1803 syntax_end_parsing(syntax_last_parsed + 1); |
1804 #endif | |
1805 | |
1806 /* | |
1807 * Display one line. | |
1808 */ | |
625 | 1809 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1810 |
1811 #ifdef FEAT_FOLDING | |
1812 wp->w_lines[idx].wl_folded = FALSE; | |
1813 wp->w_lines[idx].wl_lastlnum = lnum; | |
1814 #endif | |
1815 #ifdef FEAT_SYN_HL | |
1816 did_update = DID_LINE; | |
1817 syntax_last_parsed = lnum; | |
1818 #endif | |
1819 } | |
1820 | |
1821 wp->w_lines[idx].wl_lnum = lnum; | |
1822 wp->w_lines[idx].wl_valid = TRUE; | |
1823 if (row > wp->w_height) /* past end of screen */ | |
1824 { | |
1825 /* we may need the size of that too long line later on */ | |
1826 if (dollar_vcol == 0) | |
1827 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); | |
1828 ++idx; | |
1829 break; | |
1830 } | |
1831 if (dollar_vcol == 0) | |
1832 wp->w_lines[idx].wl_size = row - srow; | |
1833 ++idx; | |
1834 #ifdef FEAT_FOLDING | |
1835 lnum += fold_count + 1; | |
1836 #else | |
1837 ++lnum; | |
1838 #endif | |
1839 } | |
1840 else | |
1841 { | |
1842 /* This line does not need updating, advance to the next one */ | |
1843 row += wp->w_lines[idx++].wl_size; | |
1844 if (row > wp->w_height) /* past end of screen */ | |
1845 break; | |
1846 #ifdef FEAT_FOLDING | |
1847 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1848 #else | |
1849 ++lnum; | |
1850 #endif | |
1851 #ifdef FEAT_SYN_HL | |
1852 did_update = DID_NONE; | |
1853 #endif | |
1854 } | |
1855 | |
1856 if (lnum > buf->b_ml.ml_line_count) | |
1857 { | |
1858 eof = TRUE; | |
1859 break; | |
1860 } | |
1861 } | |
1862 /* | |
1863 * End of loop over all window lines. | |
1864 */ | |
1865 | |
1866 | |
1867 if (idx > wp->w_lines_valid) | |
1868 wp->w_lines_valid = idx; | |
1869 | |
1870 #ifdef FEAT_SYN_HL | |
1871 /* | |
1872 * Let the syntax stuff know we stop parsing here. | |
1873 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1874 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1875 syntax_end_parsing(syntax_last_parsed + 1); |
1876 #endif | |
1877 | |
1878 /* | |
1879 * If we didn't hit the end of the file, and we didn't finish the last | |
1880 * line we were working on, then the line didn't fit. | |
1881 */ | |
1882 wp->w_empty_rows = 0; | |
1883 #ifdef FEAT_DIFF | |
1884 wp->w_filler_rows = 0; | |
1885 #endif | |
1886 if (!eof && !didline) | |
1887 { | |
1888 if (lnum == wp->w_topline) | |
1889 { | |
1890 /* | |
1891 * Single line that does not fit! | |
1892 * Don't overwrite it, it can be edited. | |
1893 */ | |
1894 wp->w_botline = lnum + 1; | |
1895 } | |
1896 #ifdef FEAT_DIFF | |
1897 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1898 { | |
1899 /* Window ends in filler lines. */ | |
1900 wp->w_botline = lnum; | |
1901 wp->w_filler_rows = wp->w_height - srow; | |
1902 } | |
1903 #endif | |
1904 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1905 { | |
1906 /* | |
1907 * Last line isn't finished: Display "@@@" at the end. | |
1908 */ | |
1909 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1910 W_WINROW(wp) + wp->w_height, | |
1911 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1912 '@', '@', hl_attr(HLF_AT)); | |
1913 set_empty_rows(wp, srow); | |
1914 wp->w_botline = lnum; | |
1915 } | |
1916 else | |
1917 { | |
1918 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1919 wp->w_botline = lnum; | |
1920 } | |
1921 } | |
1922 else | |
1923 { | |
1924 #ifdef FEAT_VERTSPLIT | |
1925 draw_vsep_win(wp, row); | |
1926 #endif | |
1927 if (eof) /* we hit the end of the file */ | |
1928 { | |
1929 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1930 #ifdef FEAT_DIFF | |
1931 j = diff_check_fill(wp, wp->w_botline); | |
1932 if (j > 0 && !wp->w_botfill) | |
1933 { | |
1934 /* | |
1935 * Display filler lines at the end of the file | |
1936 */ | |
1937 if (char2cells(fill_diff) > 1) | |
1938 i = '-'; | |
1939 else | |
1940 i = fill_diff; | |
1941 if (row + j > wp->w_height) | |
1942 j = wp->w_height - row; | |
1943 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1944 row += j; | |
1945 } | |
1946 #endif | |
1947 } | |
1948 else if (dollar_vcol == 0) | |
1949 wp->w_botline = lnum; | |
1950 | |
1951 /* make sure the rest of the screen is blank */ | |
1952 /* put '~'s on rows that aren't part of the file. */ | |
1953 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
1954 } | |
1955 | |
1956 /* Reset the type of redrawing required, the window has been updated. */ | |
1957 wp->w_redr_type = 0; | |
1958 #ifdef FEAT_DIFF | |
1959 wp->w_old_topfill = wp->w_topfill; | |
1960 wp->w_old_botfill = wp->w_botfill; | |
1961 #endif | |
1962 | |
1963 if (dollar_vcol == 0) | |
1964 { | |
1965 /* | |
1966 * There is a trick with w_botline. If we invalidate it on each | |
1967 * change that might modify it, this will cause a lot of expensive | |
1968 * calls to plines() in update_topline() each time. Therefore the | |
1969 * value of w_botline is often approximated, and this value is used to | |
1970 * compute the value of w_topline. If the value of w_botline was | |
1971 * wrong, check that the value of w_topline is correct (cursor is on | |
1972 * the visible part of the text). If it's not, we need to redraw | |
1973 * again. Mostly this just means scrolling up a few lines, so it | |
1974 * doesn't look too bad. Only do this for the current window (where | |
1975 * changes are relevant). | |
1976 */ | |
1977 wp->w_valid |= VALID_BOTLINE; | |
1978 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
1979 { | |
1980 recursive = TRUE; | |
1981 curwin->w_valid &= ~VALID_TOPLINE; | |
1982 update_topline(); /* may invalidate w_botline again */ | |
1983 if (must_redraw != 0) | |
1984 { | |
1985 /* Don't update for changes in buffer again. */ | |
1986 i = curbuf->b_mod_set; | |
1987 curbuf->b_mod_set = FALSE; | |
1988 win_update(curwin); | |
1989 must_redraw = 0; | |
1990 curbuf->b_mod_set = i; | |
1991 } | |
1992 recursive = FALSE; | |
1993 } | |
1994 } | |
1995 | |
1996 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1997 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
1998 if (!got_int) | |
1999 got_int = save_got_int; | |
2000 #endif | |
2001 } | |
2002 | |
2003 #ifdef FEAT_SIGNS | |
2004 static int draw_signcolumn __ARGS((win_T *wp)); | |
2005 | |
2006 /* | |
2007 * Return TRUE when window "wp" has a column to draw signs in. | |
2008 */ | |
2009 static int | |
2010 draw_signcolumn(wp) | |
2011 win_T *wp; | |
2012 { | |
2013 return (wp->w_buffer->b_signlist != NULL | |
2014 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2015 || netbeans_active() |
7 | 2016 # endif |
2017 ); | |
2018 } | |
2019 #endif | |
2020 | |
2021 /* | |
2022 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2023 * as the filler character. | |
2024 */ | |
2025 static void | |
2026 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2027 win_T *wp; | |
2028 int c1; | |
2029 int c2; | |
2030 int row; | |
2031 int endrow; | |
534 | 2032 hlf_T hl; |
7 | 2033 { |
2034 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2035 int n = 0; | |
2036 # define FDC_OFF n | |
2037 #else | |
2038 # define FDC_OFF 0 | |
2039 #endif | |
2040 | |
2041 #ifdef FEAT_RIGHTLEFT | |
2042 if (wp->w_p_rl) | |
2043 { | |
2044 /* No check for cmdline window: should never be right-left. */ | |
2045 # ifdef FEAT_FOLDING | |
2046 n = wp->w_p_fdc; | |
2047 | |
2048 if (n > 0) | |
2049 { | |
2050 /* draw the fold column at the right */ | |
119 | 2051 if (n > W_WIDTH(wp)) |
2052 n = W_WIDTH(wp); | |
7 | 2053 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2054 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2055 ' ', ' ', hl_attr(HLF_FC)); | |
2056 } | |
2057 # endif | |
2058 # ifdef FEAT_SIGNS | |
2059 if (draw_signcolumn(wp)) | |
2060 { | |
2061 int nn = n + 2; | |
2062 | |
2063 /* draw the sign column left of the fold column */ | |
119 | 2064 if (nn > W_WIDTH(wp)) |
2065 nn = W_WIDTH(wp); | |
7 | 2066 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2067 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2068 ' ', ' ', hl_attr(HLF_SC)); | |
2069 n = nn; | |
2070 } | |
2071 # endif | |
2072 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2073 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2074 c2, c2, hl_attr(hl)); | |
2075 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2076 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2077 c1, c2, hl_attr(hl)); | |
2078 } | |
2079 else | |
2080 #endif | |
2081 { | |
2082 #ifdef FEAT_CMDWIN | |
2083 if (cmdwin_type != 0 && wp == curwin) | |
2084 { | |
2085 /* draw the cmdline character in the leftmost column */ | |
2086 n = 1; | |
2087 if (n > wp->w_width) | |
2088 n = wp->w_width; | |
2089 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2090 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2091 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2092 } | |
2093 #endif | |
2094 #ifdef FEAT_FOLDING | |
2095 if (wp->w_p_fdc > 0) | |
2096 { | |
2097 int nn = n + wp->w_p_fdc; | |
2098 | |
2099 /* draw the fold column at the left */ | |
2100 if (nn > W_WIDTH(wp)) | |
2101 nn = W_WIDTH(wp); | |
2102 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2103 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2104 ' ', ' ', hl_attr(HLF_FC)); | |
2105 n = nn; | |
2106 } | |
2107 #endif | |
2108 #ifdef FEAT_SIGNS | |
2109 if (draw_signcolumn(wp)) | |
2110 { | |
2111 int nn = n + 2; | |
2112 | |
2113 /* draw the sign column after the fold column */ | |
2114 if (nn > W_WIDTH(wp)) | |
2115 nn = W_WIDTH(wp); | |
2116 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2117 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2118 ' ', ' ', hl_attr(HLF_SC)); | |
2119 n = nn; | |
2120 } | |
2121 #endif | |
2122 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2123 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2124 c1, c2, hl_attr(hl)); | |
2125 } | |
2126 set_empty_rows(wp, row); | |
2127 } | |
2128 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2129 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2130 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
|
2131 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2132 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2133 * 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
|
2134 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2135 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2136 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2137 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2138 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2139 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2140 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2141 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2142 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2143 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2144 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2145 |
7 | 2146 #ifdef FEAT_FOLDING |
2147 /* | |
2148 * Display one folded line. | |
2149 */ | |
2150 static void | |
2151 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2152 win_T *wp; | |
2153 long fold_count; | |
2154 foldinfo_T *foldinfo; | |
2155 linenr_T lnum; | |
2156 int row; | |
2157 { | |
2158 char_u buf[51]; | |
2159 pos_T *top, *bot; | |
2160 linenr_T lnume = lnum + fold_count - 1; | |
2161 int len; | |
29 | 2162 char_u *text; |
7 | 2163 int fdc; |
2164 int col; | |
2165 int txtcol; | |
2166 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2167 int ri; |
7 | 2168 |
2169 /* Build the fold line: | |
2170 * 1. Add the cmdwin_type for the command-line window | |
2171 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2172 * 3. Add the 'number' or 'relativenumber' column |
7 | 2173 * 4. Compose the text |
2174 * 5. Add the text | |
2175 * 6. set highlighting for the Visual area an other text | |
2176 */ | |
2177 col = 0; | |
2178 | |
2179 /* | |
2180 * 1. Add the cmdwin_type for the command-line window | |
2181 * Ignores 'rightleft', this window is never right-left. | |
2182 */ | |
2183 #ifdef FEAT_CMDWIN | |
2184 if (cmdwin_type != 0 && wp == curwin) | |
2185 { | |
2186 ScreenLines[off] = cmdwin_type; | |
2187 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2188 #ifdef FEAT_MBYTE | |
2189 if (enc_utf8) | |
2190 ScreenLinesUC[off] = 0; | |
2191 #endif | |
2192 ++col; | |
2193 } | |
2194 #endif | |
2195 | |
2196 /* | |
2197 * 2. Add the 'foldcolumn' | |
2198 */ | |
2199 fdc = wp->w_p_fdc; | |
2200 if (fdc > W_WIDTH(wp) - col) | |
2201 fdc = W_WIDTH(wp) - col; | |
2202 if (fdc > 0) | |
2203 { | |
2204 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2205 #ifdef FEAT_RIGHTLEFT | |
2206 if (wp->w_p_rl) | |
2207 { | |
2208 int i; | |
2209 | |
2210 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2211 hl_attr(HLF_FC)); | |
2212 /* reverse the fold column */ | |
2213 for (i = 0; i < fdc; ++i) | |
2214 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2215 } | |
2216 else | |
2217 #endif | |
2218 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2219 col += fdc; | |
2220 } | |
2221 | |
2222 #ifdef FEAT_RIGHTLEFT | |
216 | 2223 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2224 for (ri = 0; ri < l; ++ri) \ | |
2225 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2226 else \ | |
2227 for (ri = 0; ri < l; ++ri) \ | |
2228 ScreenAttrs[off + (p) + ri] = v | |
7 | 2229 #else |
216 | 2230 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2231 ScreenAttrs[off + (p) + ri] = v | |
7 | 2232 #endif |
2233 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2234 /* 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
|
2235 * text */ |
216 | 2236 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2237 |
2238 #ifdef FEAT_SIGNS | |
2239 /* If signs are being displayed, add two spaces. */ | |
2240 if (draw_signcolumn(wp)) | |
2241 { | |
2242 len = W_WIDTH(wp) - col; | |
2243 if (len > 0) | |
2244 { | |
2245 if (len > 2) | |
2246 len = 2; | |
2247 # ifdef FEAT_RIGHTLEFT | |
2248 if (wp->w_p_rl) | |
2249 /* the line number isn't reversed */ | |
2250 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2251 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2252 else | |
2253 # endif | |
2254 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2255 col += len; | |
2256 } | |
2257 } | |
2258 #endif | |
2259 | |
2260 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2261 * 3. Add the 'number' or 'relativenumber' column |
7 | 2262 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2263 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2264 { |
2265 len = W_WIDTH(wp) - col; | |
2266 if (len > 0) | |
2267 { | |
13 | 2268 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2269 long num; |
13 | 2270 |
2271 if (len > w + 1) | |
2272 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2273 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2274 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2275 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2276 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2277 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2278 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2279 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
|
2280 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2281 sprintf((char *)buf, "%*ld ", w, num); |
7 | 2282 #ifdef FEAT_RIGHTLEFT |
2283 if (wp->w_p_rl) | |
2284 /* the line number isn't reversed */ | |
2285 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2286 hl_attr(HLF_FL)); | |
2287 else | |
2288 #endif | |
2289 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2290 col += len; | |
2291 } | |
2292 } | |
2293 | |
2294 /* | |
2295 * 4. Compose the folded-line string with 'foldtext', if set. | |
2296 */ | |
29 | 2297 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2298 |
2299 txtcol = col; /* remember where text starts */ | |
2300 | |
2301 /* | |
2302 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2303 * Right-left text is put in columns 0 - number-col, normal text is put | |
2304 * in columns number-col - window-width. | |
2305 */ | |
2306 #ifdef FEAT_MBYTE | |
2307 if (has_mbyte) | |
2308 { | |
2309 int cells; | |
714 | 2310 int u8c, u8cc[MAX_MCO]; |
2311 int i; | |
7 | 2312 int idx; |
2313 int c_len; | |
33 | 2314 char_u *p; |
7 | 2315 # ifdef FEAT_ARABIC |
2316 int prev_c = 0; /* previous Arabic character */ | |
2317 int prev_c1 = 0; /* first composing char for prev_c */ | |
2318 # endif | |
2319 | |
2320 # ifdef FEAT_RIGHTLEFT | |
2321 if (wp->w_p_rl) | |
2322 idx = off; | |
2323 else | |
2324 # endif | |
2325 idx = off + col; | |
2326 | |
2327 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2328 for (p = text; *p != NUL; ) | |
2329 { | |
2330 cells = (*mb_ptr2cells)(p); | |
474 | 2331 c_len = (*mb_ptr2len)(p); |
7 | 2332 if (col + cells > W_WIDTH(wp) |
2333 # ifdef FEAT_RIGHTLEFT | |
2334 - (wp->w_p_rl ? col : 0) | |
2335 # endif | |
2336 ) | |
2337 break; | |
2338 ScreenLines[idx] = *p; | |
2339 if (enc_utf8) | |
2340 { | |
714 | 2341 u8c = utfc_ptr2char(p, u8cc); |
2342 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2343 { |
2344 ScreenLinesUC[idx] = 0; | |
2345 #ifdef FEAT_ARABIC | |
2346 prev_c = u8c; | |
2347 #endif | |
2348 } | |
2349 else | |
2350 { | |
2351 #ifdef FEAT_ARABIC | |
2352 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2353 { | |
2354 /* Do Arabic shaping. */ | |
714 | 2355 int pc, pc1, nc; |
2356 int pcc[MAX_MCO]; | |
7 | 2357 int firstbyte = *p; |
2358 | |
2359 /* The idea of what is the previous and next | |
2360 * character depends on 'rightleft'. */ | |
2361 if (wp->w_p_rl) | |
2362 { | |
2363 pc = prev_c; | |
2364 pc1 = prev_c1; | |
2365 nc = utf_ptr2char(p + c_len); | |
714 | 2366 prev_c1 = u8cc[0]; |
7 | 2367 } |
2368 else | |
2369 { | |
714 | 2370 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2371 nc = prev_c; |
714 | 2372 pc1 = pcc[0]; |
7 | 2373 } |
2374 prev_c = u8c; | |
2375 | |
714 | 2376 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2377 pc, pc1, nc); |
2378 ScreenLines[idx] = firstbyte; | |
2379 } | |
2380 else | |
2381 prev_c = u8c; | |
2382 #endif | |
2383 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2384 #ifdef UNICODE16 |
7 | 2385 if (u8c >= 0x10000) |
2386 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2387 else | |
1401 | 2388 #endif |
7 | 2389 ScreenLinesUC[idx] = u8c; |
714 | 2390 for (i = 0; i < Screen_mco; ++i) |
2391 { | |
2392 ScreenLinesC[i][idx] = u8cc[i]; | |
2393 if (u8cc[i] == 0) | |
2394 break; | |
2395 } | |
7 | 2396 } |
2397 if (cells > 1) | |
2398 ScreenLines[idx + 1] = 0; | |
2399 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2400 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2401 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2402 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2403 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2404 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2405 ScreenLines[idx + 1] = p[1]; |
7 | 2406 col += cells; |
2407 idx += cells; | |
2408 p += c_len; | |
2409 } | |
2410 } | |
2411 else | |
2412 #endif | |
2413 { | |
2414 len = (int)STRLEN(text); | |
2415 if (len > W_WIDTH(wp) - col) | |
2416 len = W_WIDTH(wp) - col; | |
2417 if (len > 0) | |
2418 { | |
2419 #ifdef FEAT_RIGHTLEFT | |
2420 if (wp->w_p_rl) | |
2421 STRNCPY(current_ScreenLine, text, len); | |
2422 else | |
2423 #endif | |
2424 STRNCPY(current_ScreenLine + col, text, len); | |
2425 col += len; | |
2426 } | |
2427 } | |
2428 | |
2429 /* Fill the rest of the line with the fold filler */ | |
2430 #ifdef FEAT_RIGHTLEFT | |
2431 if (wp->w_p_rl) | |
2432 col -= txtcol; | |
2433 #endif | |
2434 while (col < W_WIDTH(wp) | |
2435 #ifdef FEAT_RIGHTLEFT | |
2436 - (wp->w_p_rl ? txtcol : 0) | |
2437 #endif | |
2438 ) | |
2439 { | |
2440 #ifdef FEAT_MBYTE | |
2441 if (enc_utf8) | |
2442 { | |
2443 if (fill_fold >= 0x80) | |
2444 { | |
2445 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2446 ScreenLinesC[0][off + col] = 0; |
7 | 2447 } |
2448 else | |
2449 ScreenLinesUC[off + col] = 0; | |
2450 } | |
2451 #endif | |
2452 ScreenLines[off + col++] = fill_fold; | |
2453 } | |
2454 | |
2455 if (text != buf) | |
2456 vim_free(text); | |
2457 | |
2458 /* | |
2459 * 6. set highlighting for the Visual area an other text. | |
2460 * If all folded lines are in the Visual area, highlight the line. | |
2461 */ | |
2462 #ifdef FEAT_VISUAL | |
2463 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2464 { | |
2465 if (ltoreq(curwin->w_cursor, VIsual)) | |
2466 { | |
2467 /* Visual is after curwin->w_cursor */ | |
2468 top = &curwin->w_cursor; | |
2469 bot = &VIsual; | |
2470 } | |
2471 else | |
2472 { | |
2473 /* Visual is before curwin->w_cursor */ | |
2474 top = &VIsual; | |
2475 bot = &curwin->w_cursor; | |
2476 } | |
2477 if (lnum >= top->lnum | |
2478 && lnume <= bot->lnum | |
2479 && (VIsual_mode != 'v' | |
2480 || ((lnum > top->lnum | |
2481 || (lnum == top->lnum | |
2482 && top->col == 0)) | |
2483 && (lnume < bot->lnum | |
2484 || (lnume == bot->lnum | |
2485 && (bot->col - (*p_sel == 'e')) | |
1883 | 2486 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2487 { |
2488 if (VIsual_mode == Ctrl_V) | |
2489 { | |
2490 /* Visual block mode: highlight the chars part of the block */ | |
2491 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2492 { | |
2493 if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2494 len = wp->w_old_cursor_lcol; | |
2495 else | |
2496 len = W_WIDTH(wp) - txtcol; | |
2497 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2498 len - (int)wp->w_old_cursor_fcol); |
7 | 2499 } |
2500 } | |
2501 else | |
216 | 2502 { |
7 | 2503 /* Set all attributes of the text */ |
216 | 2504 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2505 } | |
7 | 2506 } |
2507 } | |
2508 #endif | |
2509 | |
743 | 2510 #ifdef FEAT_SYN_HL |
2511 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2512 if (wp->w_p_cuc) |
2513 { | |
2514 txtcol += wp->w_virtcol; | |
2515 if (wp->w_p_wrap) | |
2516 txtcol -= wp->w_skipcol; | |
2517 else | |
2518 txtcol -= wp->w_leftcol; | |
2519 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2520 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2521 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2522 } | |
743 | 2523 #endif |
7 | 2524 |
2525 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2526 (int)W_WIDTH(wp), FALSE); | |
2527 | |
2528 /* | |
2529 * Update w_cline_height and w_cline_folded if the cursor line was | |
2530 * updated (saves a call to plines() later). | |
2531 */ | |
2532 if (wp == curwin | |
2533 && lnum <= curwin->w_cursor.lnum | |
2534 && lnume >= curwin->w_cursor.lnum) | |
2535 { | |
2536 curwin->w_cline_row = row; | |
2537 curwin->w_cline_height = 1; | |
2538 curwin->w_cline_folded = TRUE; | |
2539 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2540 } | |
2541 } | |
2542 | |
2543 /* | |
2544 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2545 */ | |
2546 static void | |
2547 copy_text_attr(off, buf, len, attr) | |
2548 int off; | |
2549 char_u *buf; | |
2550 int len; | |
2551 int attr; | |
2552 { | |
216 | 2553 int i; |
2554 | |
7 | 2555 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2556 # ifdef FEAT_MBYTE | |
2557 if (enc_utf8) | |
2558 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2559 # endif | |
216 | 2560 for (i = 0; i < len; ++i) |
2561 ScreenAttrs[off + i] = attr; | |
7 | 2562 } |
2563 | |
2564 /* | |
2565 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2566 * Only to be called when 'foldcolumn' > 0. |
7 | 2567 */ |
2568 static void | |
2569 fill_foldcolumn(p, wp, closed, lnum) | |
2570 char_u *p; | |
2571 win_T *wp; | |
2572 int closed; /* TRUE of FALSE */ | |
2573 linenr_T lnum; /* current line number */ | |
2574 { | |
2575 int i = 0; | |
2576 int level; | |
2577 int first_level; | |
519 | 2578 int empty; |
7 | 2579 |
2580 /* Init to all spaces. */ | |
2581 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2582 | |
2583 level = win_foldinfo.fi_level; | |
2584 if (level > 0) | |
2585 { | |
519 | 2586 /* If there is only one column put more info in it. */ |
2587 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2588 | |
7 | 2589 /* If the column is too narrow, we start at the lowest level that |
2590 * fits and use numbers to indicated the depth. */ | |
519 | 2591 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2592 if (first_level < 1) |
2593 first_level = 1; | |
2594 | |
519 | 2595 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2596 { |
2597 if (win_foldinfo.fi_lnum == lnum | |
2598 && first_level + i >= win_foldinfo.fi_low_level) | |
2599 p[i] = '-'; | |
2600 else if (first_level == 1) | |
2601 p[i] = '|'; | |
2602 else if (first_level + i <= 9) | |
2603 p[i] = '0' + first_level + i; | |
2604 else | |
2605 p[i] = '>'; | |
2606 if (first_level + i == level) | |
2607 break; | |
2608 } | |
2609 } | |
2610 if (closed) | |
548 | 2611 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2612 } |
2613 #endif /* FEAT_FOLDING */ | |
2614 | |
2615 /* | |
2616 * Display line "lnum" of window 'wp' on the screen. | |
2617 * Start at row "startrow", stop when "endrow" is reached. | |
2618 * wp->w_virtcol needs to be valid. | |
2619 * | |
2620 * Return the number of last row the line occupies. | |
2621 */ | |
2622 static int | |
625 | 2623 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2624 win_T *wp; |
2625 linenr_T lnum; | |
2626 int startrow; | |
2627 int endrow; | |
1883 | 2628 int nochange UNUSED; /* not updating for changed text */ |
7 | 2629 { |
2630 int col; /* visual column on screen */ | |
2631 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2632 int c = 0; /* init for GCC */ | |
2633 long vcol = 0; /* virtual column (for tabs) */ | |
2634 long vcol_prev = -1; /* "vcol" of previous character */ | |
2635 char_u *line; /* current line */ | |
2636 char_u *ptr; /* current position in "line" */ | |
2637 int row; /* row in the window, excl w_winrow */ | |
2638 int screen_row; /* row on the screen, incl w_winrow */ | |
2639 | |
2640 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2641 int n_extra = 0; /* number of extra chars */ | |
1340 | 2642 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2643 int c_extra = NUL; /* extra chars, all the same */ |
2644 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2645 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2646 displaying lcs_eol at end-of-line */ | |
2647 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2648 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2649 | |
2650 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2651 int saved_n_extra = 0; | |
2652 char_u *saved_p_extra = NULL; | |
2653 int saved_c_extra = 0; | |
2654 int saved_char_attr = 0; | |
2655 | |
2656 int n_attr = 0; /* chars with special attr */ | |
2657 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2658 int n_attr3 = 0; /* chars with overruling special attr */ | |
2659 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2660 | |
2661 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2662 | |
2663 int fromcol, tocol; /* start/end of inverting */ | |
2664 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2665 int noinvcur = FALSE; /* don't invert the cursor */ | |
2666 #ifdef FEAT_VISUAL | |
2667 pos_T *top, *bot; | |
1813 | 2668 int lnum_in_visual_area = FALSE; |
7 | 2669 #endif |
2670 pos_T pos; | |
2671 long v; | |
2672 | |
2673 int char_attr = 0; /* attributes for next character */ | |
674 | 2674 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2675 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2676 in this line */ | |
2677 int attr = 0; /* attributes for area highlighting */ | |
2678 int area_attr = 0; /* attributes desired by highlighting */ | |
2679 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2680 #ifdef FEAT_SYN_HL | |
743 | 2681 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2682 int syntax_attr = 0; /* attributes desired by syntax */ |
2683 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2684 int save_did_emsg; | |
1437 | 2685 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
|
2686 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2687 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2688 #endif |
2689 #ifdef FEAT_SPELL | |
221 | 2690 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2691 # define SPWORDLEN 150 |
2692 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2693 int nextlinecol = 0; /* column where nextline[] starts */ |
2694 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2695 starts */ |
221 | 2696 int spell_attr = 0; /* attributes desired by spelling */ |
2697 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2698 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2699 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2700 * there are no spell errors */ |
386 | 2701 static int cap_col = -1; /* column to check for Cap word */ |
2702 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2703 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2704 #endif |
2705 int extra_check; /* has syntax or linebreak */ | |
2706 #ifdef FEAT_MBYTE | |
2707 int multi_attr = 0; /* attributes desired by multibyte */ | |
2708 int mb_l = 1; /* multi-byte byte length */ | |
2709 int mb_c = 0; /* decoded multi-byte character */ | |
2710 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2711 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2712 #endif |
2713 #ifdef FEAT_DIFF | |
2714 int filler_lines; /* nr of filler lines to be drawn */ | |
2715 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2716 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2717 int change_start = MAXCOL; /* first col of changed area */ |
2718 int change_end = -1; /* last col of changed area */ | |
2719 #endif | |
2720 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2721 #ifdef FEAT_LINEBREAK | |
2722 int need_showbreak = FALSE; | |
2723 #endif | |
910 | 2724 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2725 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2726 # define LINE_ATTR |
1536 | 2727 int line_attr = 0; /* attribute for the whole line */ |
7 | 2728 #endif |
2729 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2730 matchitem_T *cur; /* points to the match list */ |
2731 match_T *shl; /* points to search_hl or a match */ | |
2732 int shl_flag; /* flag to indicate whether search_hl | |
2733 has been processed or not */ | |
2734 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2735 equals startcol of search_hl or one | |
2736 of the matches */ | |
7 | 2737 #endif |
2738 #ifdef FEAT_ARABIC | |
2739 int prev_c = 0; /* previous Arabic character */ | |
2740 int prev_c1 = 0; /* first composing char for prev_c */ | |
2741 #endif | |
910 | 2742 #if defined(LINE_ATTR) |
867 | 2743 int did_line_attr = 0; |
2744 #endif | |
7 | 2745 |
2746 /* draw_state: items that are drawn in sequence: */ | |
2747 #define WL_START 0 /* nothing done yet */ | |
2748 #ifdef FEAT_CMDWIN | |
2749 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2750 #else | |
2751 # define WL_CMDLINE WL_START | |
2752 #endif | |
2753 #ifdef FEAT_FOLDING | |
2754 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2755 #else | |
2756 # define WL_FOLD WL_CMDLINE | |
2757 #endif | |
2758 #ifdef FEAT_SIGNS | |
2759 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2760 #else | |
2761 # define WL_SIGN WL_FOLD /* column for signs */ | |
2762 #endif | |
2763 #define WL_NR WL_SIGN + 1 /* line number */ | |
2764 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2765 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2766 #else | |
2767 # define WL_SBR WL_NR | |
2768 #endif | |
2769 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2770 int draw_state = WL_START; /* what to draw next */ | |
574 | 2771 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2772 int feedback_col = 0; |
2773 int feedback_old_attr = -1; | |
2774 #endif | |
2775 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2776 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2777 int syntax_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2778 int conceal_attr = hl_attr(HLF_CONCEAL); |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
2779 int first_conceal = (wp->w_p_conc != 3); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2780 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2781 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
|
2782 wrapping */ |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2783 int vcol_off = 0; /* offset for concealed characters */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2784 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2785 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2786 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2787 #endif |
7 | 2788 |
2789 if (startrow > endrow) /* past the end already! */ | |
2790 return startrow; | |
2791 | |
2792 row = startrow; | |
2793 screen_row = row + W_WINROW(wp); | |
2794 | |
2795 /* | |
2796 * To speed up the loop below, set extra_check when there is linebreak, | |
2797 * trailing white space and/or syntax processing to be done. | |
2798 */ | |
2799 #ifdef FEAT_LINEBREAK | |
2800 extra_check = wp->w_p_lbr; | |
2801 #else | |
2802 extra_check = 0; | |
2803 #endif | |
2804 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2805 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2806 { |
2807 /* Prepare for syntax highlighting in this line. When there is an | |
2808 * error, stop syntax highlighting. */ | |
2809 save_did_emsg = did_emsg; | |
2810 did_emsg = FALSE; | |
2811 syntax_start(wp, lnum); | |
2812 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2813 wp->w_s->b_syn_error = TRUE; |
7 | 2814 else |
2815 { | |
2816 did_emsg = save_did_emsg; | |
2817 has_syntax = TRUE; | |
2818 extra_check = TRUE; | |
2819 } | |
2820 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2821 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2822 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2823 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2824 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2825 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 2826 #endif |
2827 | |
2828 #ifdef FEAT_SPELL | |
258 | 2829 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2830 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2831 && 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
|
2832 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2833 { |
2834 /* Prepare for spell checking. */ | |
2835 has_spell = TRUE; | |
2836 extra_check = TRUE; | |
348 | 2837 |
2838 /* Get the start of the next line, so that words that wrap to the next | |
2839 * line are found too: "et<line-break>al.". | |
2840 * Trick: skip a few chars for C/shell/Vim comments */ | |
2841 nextline[SPWORDLEN] = NUL; | |
2842 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2843 { | |
2844 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2845 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2846 } | |
2847 | |
2848 /* When a word wrapped from the previous line the start of the current | |
2849 * line is valid. */ | |
2850 if (lnum == checked_lnum) | |
2851 cur_checked_col = checked_col; | |
2852 checked_lnum = 0; | |
386 | 2853 |
2854 /* When there was a sentence end in the previous line may require a | |
2855 * word starting with capital in this line. In line 1 always check | |
2856 * the first word. */ | |
2857 if (lnum != capcol_lnum) | |
2858 cap_col = -1; | |
2859 if (lnum == 1) | |
2860 cap_col = 0; | |
2861 capcol_lnum = 0; | |
221 | 2862 } |
7 | 2863 #endif |
2864 | |
2865 /* | |
2866 * handle visual active in this window | |
2867 */ | |
2868 fromcol = -10; | |
2869 tocol = MAXCOL; | |
2870 #ifdef FEAT_VISUAL | |
2871 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2872 { | |
2873 /* Visual is after curwin->w_cursor */ | |
2874 if (ltoreq(curwin->w_cursor, VIsual)) | |
2875 { | |
2876 top = &curwin->w_cursor; | |
2877 bot = &VIsual; | |
2878 } | |
2879 else /* Visual is before curwin->w_cursor */ | |
2880 { | |
2881 top = &VIsual; | |
2882 bot = &curwin->w_cursor; | |
2883 } | |
1813 | 2884 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2885 if (VIsual_mode == Ctrl_V) /* block mode */ |
2886 { | |
1813 | 2887 if (lnum_in_visual_area) |
7 | 2888 { |
2889 fromcol = wp->w_old_cursor_fcol; | |
2890 tocol = wp->w_old_cursor_lcol; | |
2891 } | |
2892 } | |
2893 else /* non-block mode */ | |
2894 { | |
2895 if (lnum > top->lnum && lnum <= bot->lnum) | |
2896 fromcol = 0; | |
2897 else if (lnum == top->lnum) | |
2898 { | |
2899 if (VIsual_mode == 'V') /* linewise */ | |
2900 fromcol = 0; | |
2901 else | |
2902 { | |
2903 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2904 if (gchar_pos(top) == NUL) | |
2905 tocol = fromcol + 1; | |
2906 } | |
2907 } | |
2908 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2909 { | |
2910 if (*p_sel == 'e' && bot->col == 0 | |
2911 #ifdef FEAT_VIRTUALEDIT | |
2912 && bot->coladd == 0 | |
2913 #endif | |
2914 ) | |
2915 { | |
2916 fromcol = -10; | |
2917 tocol = MAXCOL; | |
2918 } | |
36 | 2919 else if (bot->col == MAXCOL) |
2920 tocol = MAXCOL; | |
7 | 2921 else |
2922 { | |
2923 pos = *bot; | |
2924 if (*p_sel == 'e') | |
2925 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2926 else | |
2927 { | |
2928 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2929 ++tocol; | |
2930 } | |
2931 } | |
2932 } | |
2933 } | |
2934 | |
2935 #ifndef MSDOS | |
2936 /* Check if the character under the cursor should not be inverted */ | |
2937 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2938 # ifdef FEAT_GUI | |
2939 && !gui.in_use | |
2940 # endif | |
2941 ) | |
2942 noinvcur = TRUE; | |
2943 #endif | |
2944 | |
2945 /* if inverting in this line set area_highlighting */ | |
2946 if (fromcol >= 0) | |
2947 { | |
2948 area_highlighting = TRUE; | |
2949 attr = hl_attr(HLF_V); | |
2950 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2951 if (clip_star.available && !clip_star.owned && clip_isautosel()) | |
2952 attr = hl_attr(HLF_VNC); | |
2953 #endif | |
2954 } | |
2955 } | |
2956 | |
2957 /* | |
674 | 2958 * handle 'incsearch' and ":s///c" highlighting |
7 | 2959 */ |
2960 else | |
2961 #endif /* FEAT_VISUAL */ | |
2962 if (highlight_match | |
2963 && wp == curwin | |
2964 && lnum >= curwin->w_cursor.lnum | |
2965 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
2966 { | |
2967 if (lnum == curwin->w_cursor.lnum) | |
2968 getvcol(curwin, &(curwin->w_cursor), | |
2969 (colnr_T *)&fromcol, NULL, NULL); | |
2970 else | |
2971 fromcol = 0; | |
2972 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
2973 { | |
2974 pos.lnum = lnum; | |
2975 pos.col = search_match_endcol; | |
2976 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2977 } | |
2978 else | |
2979 tocol = MAXCOL; | |
1850 | 2980 /* do at least one character; happens when past end of line */ |
2981 if (fromcol == tocol) | |
2982 tocol = fromcol + 1; | |
7 | 2983 area_highlighting = TRUE; |
2984 attr = hl_attr(HLF_I); | |
2985 } | |
2986 | |
2987 #ifdef FEAT_DIFF | |
2988 filler_lines = diff_check(wp, lnum); | |
2989 if (filler_lines < 0) | |
2990 { | |
2991 if (filler_lines == -1) | |
2992 { | |
2993 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
2994 diff_hlf = HLF_ADD; /* added line */ | |
2995 else if (change_start == 0) | |
2996 diff_hlf = HLF_TXD; /* changed text */ | |
2997 else | |
2998 diff_hlf = HLF_CHD; /* changed line */ | |
2999 } | |
3000 else | |
3001 diff_hlf = HLF_ADD; /* added line */ | |
3002 filler_lines = 0; | |
3003 area_highlighting = TRUE; | |
3004 } | |
3005 if (lnum == wp->w_topline) | |
3006 filler_lines = wp->w_topfill; | |
3007 filler_todo = filler_lines; | |
3008 #endif | |
3009 | |
3010 #ifdef LINE_ATTR | |
3011 # ifdef FEAT_SIGNS | |
3012 /* If this line has a sign with line highlighting set line_attr. */ | |
3013 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3014 if (v != 0) | |
3015 line_attr = sign_get_attr((int)v, TRUE); | |
3016 # endif | |
3017 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3018 /* Highlight the current line in the quickfix window. */ | |
644 | 3019 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3020 line_attr = hl_attr(HLF_L); |
3021 # endif | |
3022 if (line_attr != 0) | |
3023 area_highlighting = TRUE; | |
3024 #endif | |
3025 | |
3026 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3027 ptr = line; | |
3028 | |
743 | 3029 #ifdef FEAT_SPELL |
348 | 3030 if (has_spell) |
3031 { | |
386 | 3032 /* For checking first word with a capital skip white space. */ |
3033 if (cap_col == 0) | |
835 | 3034 cap_col = (int)(skipwhite(line) - line); |
386 | 3035 |
348 | 3036 /* To be able to spell-check over line boundaries copy the end of the |
3037 * current line into nextline[]. Above the start of the next line was | |
3038 * copied to nextline[SPWORDLEN]. */ | |
3039 if (nextline[SPWORDLEN] == NUL) | |
3040 { | |
3041 /* No next line or it is empty. */ | |
3042 nextlinecol = MAXCOL; | |
3043 nextline_idx = 0; | |
3044 } | |
3045 else | |
3046 { | |
835 | 3047 v = (long)STRLEN(line); |
348 | 3048 if (v < SPWORDLEN) |
3049 { | |
3050 /* Short line, use it completely and append the start of the | |
3051 * next line. */ | |
3052 nextlinecol = 0; | |
3053 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3054 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3055 nextline_idx = v + 1; |
3056 } | |
3057 else | |
3058 { | |
3059 /* Long line, use only the last SPWORDLEN bytes. */ | |
3060 nextlinecol = v - SPWORDLEN; | |
3061 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3062 nextline_idx = SPWORDLEN + 1; | |
3063 } | |
3064 } | |
3065 } | |
3066 #endif | |
3067 | |
7 | 3068 /* find start of trailing whitespace */ |
3069 if (wp->w_p_list && lcs_trail) | |
3070 { | |
3071 trailcol = (colnr_T)STRLEN(ptr); | |
3072 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3073 --trailcol; | |
3074 trailcol += (colnr_T) (ptr - line); | |
3075 extra_check = TRUE; | |
3076 } | |
3077 | |
3078 /* | |
3079 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3080 * first character to be displayed. | |
3081 */ | |
3082 if (wp->w_p_wrap) | |
3083 v = wp->w_skipcol; | |
3084 else | |
3085 v = wp->w_leftcol; | |
3086 if (v > 0) | |
3087 { | |
3088 #ifdef FEAT_MBYTE | |
3089 char_u *prev_ptr = ptr; | |
3090 #endif | |
3091 while (vcol < v && *ptr != NUL) | |
3092 { | |
3093 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3094 vcol += c; | |
3095 #ifdef FEAT_MBYTE | |
3096 prev_ptr = ptr; | |
39 | 3097 #endif |
3098 mb_ptr_adv(ptr); | |
7 | 3099 } |
3100 | |
1984 | 3101 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3102 /* When: | |
3103 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3104 * - 'colorcolumn' is set, or |
1984 | 3105 * - 'virtualedit' is set, or |
3106 * - the visual mode is active, | |
3107 * the end of the line may be before the start of the displayed part. | |
3108 */ | |
3109 if (vcol < v && ( | |
3110 # ifdef FEAT_SYN_HL | |
3111 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3112 || draw_color_col |
1984 | 3113 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3114 || | |
3115 # endif | |
3116 # endif | |
3117 # ifdef FEAT_VIRTUALEDIT | |
3118 virtual_active() | |
3119 # ifdef FEAT_VISUAL | |
3120 || | |
3121 # endif | |
3122 # endif | |
3123 # ifdef FEAT_VISUAL | |
3124 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3125 # endif | |
3126 )) | |
3127 { | |
7 | 3128 vcol = v; |
1984 | 3129 } |
7 | 3130 #endif |
3131 | |
3132 /* Handle a character that's not completely on the screen: Put ptr at | |
3133 * that character but skip the first few screen characters. */ | |
3134 if (vcol > v) | |
3135 { | |
3136 vcol -= c; | |
3137 #ifdef FEAT_MBYTE | |
3138 ptr = prev_ptr; | |
3139 #else | |
3140 --ptr; | |
3141 #endif | |
3142 n_skip = v - vcol; | |
3143 } | |
3144 | |
3145 /* | |
3146 * Adjust for when the inverted text is before the screen, | |
3147 * and when the start of the inverted text is before the screen. | |
3148 */ | |
3149 if (tocol <= vcol) | |
3150 fromcol = 0; | |
3151 else if (fromcol >= 0 && fromcol < vcol) | |
3152 fromcol = vcol; | |
3153 | |
3154 #ifdef FEAT_LINEBREAK | |
3155 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3156 if (wp->w_p_wrap) | |
3157 need_showbreak = TRUE; | |
3158 #endif | |
743 | 3159 #ifdef FEAT_SPELL |
499 | 3160 /* When spell checking a word we need to figure out the start of the |
3161 * word and if it's badly spelled or not. */ | |
3162 if (has_spell) | |
3163 { | |
3164 int len; | |
1536 | 3165 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3166 hlf_T spell_hlf = HLF_COUNT; |
499 | 3167 |
3168 pos = wp->w_cursor; | |
3169 wp->w_cursor.lnum = lnum; | |
1536 | 3170 wp->w_cursor.col = linecol; |
534 | 3171 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3172 |
3173 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3174 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3175 ptr = line + linecol; | |
3176 | |
530 | 3177 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3178 { |
3179 /* no bad word found at line start, don't check until end of a | |
3180 * word */ | |
534 | 3181 spell_hlf = HLF_COUNT; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3182 word_end = (int)(spell_to_word_end(ptr, wp) |
1536 | 3183 - line + 1); |
499 | 3184 } |
3185 else | |
534 | 3186 { |
499 | 3187 /* bad word found, use attributes until end of word */ |
3188 word_end = wp->w_cursor.col + len + 1; | |
3189 | |
534 | 3190 /* Turn index into actual attributes. */ |
3191 if (spell_hlf != HLF_COUNT) | |
3192 spell_attr = highlight_attr[spell_hlf]; | |
3193 } | |
499 | 3194 wp->w_cursor = pos; |
501 | 3195 |
743 | 3196 # ifdef FEAT_SYN_HL |
501 | 3197 /* Need to restart syntax highlighting for this line. */ |
3198 if (has_syntax) | |
3199 syntax_start(wp, lnum); | |
743 | 3200 # endif |
499 | 3201 } |
3202 #endif | |
7 | 3203 } |
3204 | |
3205 /* | |
3206 * Correct highlighting for cursor that can't be disabled. | |
3207 * Avoids having to check this for each character. | |
3208 */ | |
3209 if (fromcol >= 0) | |
3210 { | |
3211 if (noinvcur) | |
3212 { | |
3213 if ((colnr_T)fromcol == wp->w_virtcol) | |
3214 { | |
3215 /* highlighting starts at cursor, let it start just after the | |
3216 * cursor */ | |
3217 fromcol_prev = fromcol; | |
3218 fromcol = -1; | |
3219 } | |
3220 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3221 /* restart highlighting after the cursor */ | |
3222 fromcol_prev = wp->w_virtcol; | |
3223 } | |
3224 if (fromcol >= tocol) | |
3225 fromcol = -1; | |
3226 } | |
3227 | |
3228 #ifdef FEAT_SEARCH_EXTRA | |
3229 /* | |
1326 | 3230 * Handle highlighting the last used search pattern and matches. |
3231 * Do this for both search_hl and the match list. | |
7 | 3232 */ |
1326 | 3233 cur = wp->w_match_head; |
3234 shl_flag = FALSE; | |
3235 while (cur != NULL || shl_flag == FALSE) | |
3236 { | |
3237 if (shl_flag == FALSE) | |
3238 { | |
3239 shl = &search_hl; | |
3240 shl_flag = TRUE; | |
3241 } | |
3242 else | |
3243 shl = &cur->hl; | |
36 | 3244 shl->startcol = MAXCOL; |
3245 shl->endcol = MAXCOL; | |
7 | 3246 shl->attr_cur = 0; |
3247 if (shl->rm.regprog != NULL) | |
3248 { | |
3249 v = (long)(ptr - line); | |
3250 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3251 | |
3252 /* Need to get the line again, a multi-line regexp may have made it | |
3253 * invalid. */ | |
3254 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3255 ptr = line + v; | |
3256 | |
3257 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3258 { | |
3259 if (shl->lnum == lnum) | |
36 | 3260 shl->startcol = shl->rm.startpos[0].col; |
7 | 3261 else |
36 | 3262 shl->startcol = 0; |
7 | 3263 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3264 - shl->rm.startpos[0].lnum) | |
36 | 3265 shl->endcol = shl->rm.endpos[0].col; |
7 | 3266 else |
36 | 3267 shl->endcol = MAXCOL; |
7 | 3268 /* Highlight one character for an empty match. */ |
36 | 3269 if (shl->startcol == shl->endcol) |
7 | 3270 { |
3271 #ifdef FEAT_MBYTE | |
36 | 3272 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3273 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3274 else |
3275 #endif | |
36 | 3276 ++shl->endcol; |
7 | 3277 } |
36 | 3278 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3279 { |
3280 shl->attr_cur = shl->attr; | |
3281 search_attr = shl->attr; | |
3282 } | |
3283 area_highlighting = TRUE; | |
3284 } | |
3285 } | |
1326 | 3286 if (shl != &search_hl && cur != NULL) |
3287 cur = cur->next; | |
7 | 3288 } |
3289 #endif | |
3290 | |
743 | 3291 #ifdef FEAT_SYN_HL |
818 | 3292 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3293 * active, because it's not clear what is selected then. */ | |
3294 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3295 { |
3296 line_attr = hl_attr(HLF_CUL); | |
3297 area_highlighting = TRUE; | |
3298 } | |
3299 #endif | |
3300 | |
504 | 3301 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3302 col = 0; |
3303 #ifdef FEAT_RIGHTLEFT | |
3304 if (wp->w_p_rl) | |
3305 { | |
3306 /* Rightleft window: process the text in the normal direction, but put | |
3307 * it in current_ScreenLine[] from right to left. Start at the | |
3308 * rightmost column of the window. */ | |
3309 col = W_WIDTH(wp) - 1; | |
3310 off += col; | |
3311 } | |
3312 #endif | |
3313 | |
3314 /* | |
3315 * Repeat for the whole displayed line. | |
3316 */ | |
3317 for (;;) | |
3318 { | |
3319 /* Skip this quickly when working on the text. */ | |
3320 if (draw_state != WL_LINE) | |
3321 { | |
3322 #ifdef FEAT_CMDWIN | |
3323 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3324 { | |
3325 draw_state = WL_CMDLINE; | |
3326 if (cmdwin_type != 0 && wp == curwin) | |
3327 { | |
3328 /* Draw the cmdline character. */ | |
3329 n_extra = 1; | |
1340 | 3330 c_extra = cmdwin_type; |
7 | 3331 char_attr = hl_attr(HLF_AT); |
3332 } | |
3333 } | |
3334 #endif | |
3335 | |
3336 #ifdef FEAT_FOLDING | |
3337 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3338 { | |
3339 draw_state = WL_FOLD; | |
3340 if (wp->w_p_fdc > 0) | |
3341 { | |
3342 /* Draw the 'foldcolumn'. */ | |
3343 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3344 n_extra = wp->w_p_fdc; | |
3345 p_extra = extra; | |
1340 | 3346 p_extra[n_extra] = NUL; |
7 | 3347 c_extra = NUL; |
3348 char_attr = hl_attr(HLF_FC); | |
3349 } | |
3350 } | |
3351 #endif | |
3352 | |
3353 #ifdef FEAT_SIGNS | |
3354 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3355 { | |
3356 draw_state = WL_SIGN; | |
3357 /* Show the sign column when there are any signs in this | |
3358 * buffer or when using Netbeans. */ | |
3359 if (draw_signcolumn(wp) | |
3360 # ifdef FEAT_DIFF | |
3361 && filler_todo <= 0 | |
3362 # endif | |
3363 ) | |
3364 { | |
3365 int_u text_sign; | |
3366 # ifdef FEAT_SIGN_ICONS | |
3367 int_u icon_sign; | |
3368 # endif | |
3369 | |
3370 /* Draw two cells with the sign value or blank. */ | |
3371 c_extra = ' '; | |
3372 char_attr = hl_attr(HLF_SC); | |
3373 n_extra = 2; | |
3374 | |
3375 if (row == startrow) | |
3376 { | |
3377 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3378 SIGN_TEXT); | |
3379 # ifdef FEAT_SIGN_ICONS | |
3380 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3381 SIGN_ICON); | |
3382 if (gui.in_use && icon_sign != 0) | |
3383 { | |
3384 /* Use the image in this position. */ | |
3385 c_extra = SIGN_BYTE; | |
3386 # ifdef FEAT_NETBEANS_INTG | |
3387 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3388 c_extra = MULTISIGN_BYTE; | |
3389 # endif | |
3390 char_attr = icon_sign; | |
3391 } | |
3392 else | |
3393 # endif | |
3394 if (text_sign != 0) | |
3395 { | |
3396 p_extra = sign_get_text(text_sign); | |
3397 if (p_extra != NULL) | |
3398 { | |
3399 c_extra = NUL; | |
835 | 3400 n_extra = (int)STRLEN(p_extra); |
7 | 3401 } |
3402 char_attr = sign_get_attr(text_sign, FALSE); | |
3403 } | |
3404 } | |
3405 } | |
3406 } | |
3407 #endif | |
3408 | |
3409 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3410 { | |
3411 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3412 /* 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
|
3413 * 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
|
3414 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3415 && (row == startrow |
3416 #ifdef FEAT_DIFF | |
3417 + filler_lines | |
3418 #endif | |
3419 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3420 { | |
3421 /* Draw the line number (empty space after wrapping). */ | |
3422 if (row == startrow | |
3423 #ifdef FEAT_DIFF | |
3424 + filler_lines | |
3425 #endif | |
3426 ) | |
3427 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3428 long num; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3429 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3430 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3431 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3432 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3433 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3434 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3435 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
|
3436 lnum)); |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3437 |
13 | 3438 sprintf((char *)extra, "%*ld ", |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3439 number_width(wp), num); |
7 | 3440 if (wp->w_skipcol > 0) |
3441 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3442 *p_extra = '-'; | |
3443 #ifdef FEAT_RIGHTLEFT | |
3444 if (wp->w_p_rl) /* reverse line numbers */ | |
3445 rl_mirror(extra); | |
3446 #endif | |
3447 p_extra = extra; | |
3448 c_extra = NUL; | |
3449 } | |
3450 else | |
3451 c_extra = ' '; | |
13 | 3452 n_extra = number_width(wp) + 1; |
7 | 3453 char_attr = hl_attr(HLF_N); |
743 | 3454 #ifdef FEAT_SYN_HL |
3455 /* When 'cursorline' is set highlight the line number of | |
3456 * the current line differently. */ | |
3457 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) | |
3458 char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); | |
3459 #endif | |
7 | 3460 } |
3461 } | |
3462 | |
3463 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3464 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3465 { | |
3466 draw_state = WL_SBR; | |
3467 # ifdef FEAT_DIFF | |
3468 if (filler_todo > 0) | |
3469 { | |
3470 /* Draw "deleted" diff line(s). */ | |
3471 if (char2cells(fill_diff) > 1) | |
3472 c_extra = '-'; | |
3473 else | |
3474 c_extra = fill_diff; | |
3475 # ifdef FEAT_RIGHTLEFT | |
3476 if (wp->w_p_rl) | |
3477 n_extra = col + 1; | |
3478 else | |
3479 # endif | |
3480 n_extra = W_WIDTH(wp) - col; | |
3481 char_attr = hl_attr(HLF_DED); | |
3482 } | |
3483 # endif | |
3484 # ifdef FEAT_LINEBREAK | |
3485 if (*p_sbr != NUL && need_showbreak) | |
3486 { | |
3487 /* Draw 'showbreak' at the start of each broken line. */ | |
3488 p_extra = p_sbr; | |
3489 c_extra = NUL; | |
3490 n_extra = (int)STRLEN(p_sbr); | |
3491 char_attr = hl_attr(HLF_AT); | |
3492 need_showbreak = FALSE; | |
3493 /* Correct end of highlighted area for 'showbreak', | |
3494 * required when 'linebreak' is also set. */ | |
3495 if (tocol == vcol) | |
3496 tocol += n_extra; | |
3497 } | |
3498 # endif | |
3499 } | |
3500 #endif | |
3501 | |
3502 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3503 { | |
3504 draw_state = WL_LINE; | |
3505 if (saved_n_extra) | |
3506 { | |
3507 /* Continue item from end of wrapped line. */ | |
3508 n_extra = saved_n_extra; | |
3509 c_extra = saved_c_extra; | |
3510 p_extra = saved_p_extra; | |
3511 char_attr = saved_char_attr; | |
3512 } | |
3513 else | |
3514 char_attr = 0; | |
3515 } | |
3516 } | |
3517 | |
3518 /* When still displaying '$' of change command, stop at cursor */ | |
819 | 3519 if (dollar_vcol != 0 && wp == curwin |
3520 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol | |
7 | 3521 #ifdef FEAT_DIFF |
3522 && filler_todo <= 0 | |
3523 #endif | |
3524 ) | |
3525 { | |
3526 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3527 wp->w_p_rl); | |
819 | 3528 /* Pretend we have finished updating the window. Except when |
3529 * 'cursorcolumn' is set. */ | |
3530 #ifdef FEAT_SYN_HL | |
3531 if (wp->w_p_cuc) | |
3532 row = wp->w_cline_row + wp->w_cline_height; | |
3533 else | |
3534 #endif | |
3535 row = wp->w_height; | |
7 | 3536 break; |
3537 } | |
3538 | |
3539 if (draw_state == WL_LINE && area_highlighting) | |
3540 { | |
3541 /* handle Visual or match highlighting in this line */ | |
3542 if (vcol == fromcol | |
3543 #ifdef FEAT_MBYTE | |
3544 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3545 && (*mb_ptr2cells)(ptr) > 1) | |
3546 #endif | |
3547 || ((int)vcol_prev == fromcol_prev | |
1814 | 3548 && vcol_prev < vcol /* not at margin */ |
7 | 3549 && vcol < tocol)) |
3550 area_attr = attr; /* start highlighting */ | |
3551 else if (area_attr != 0 | |
3552 && (vcol == tocol | |
3553 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3554 area_attr = 0; /* stop highlighting */ | |
3555 | |
3556 #ifdef FEAT_SEARCH_EXTRA | |
3557 if (!n_extra) | |
3558 { | |
3559 /* | |
3560 * Check for start/end of search pattern match. | |
3561 * After end, check for start/end of next match. | |
3562 * When another match, have to check for start again. | |
3563 * Watch out for matching an empty string! | |
1326 | 3564 * Do this for 'search_hl' and the match list (ordered by |
3565 * priority). | |
7 | 3566 */ |
36 | 3567 v = (long)(ptr - line); |
1326 | 3568 cur = wp->w_match_head; |
3569 shl_flag = FALSE; | |
3570 while (cur != NULL || shl_flag == FALSE) | |
3571 { | |
3572 if (shl_flag == FALSE | |
3573 && ((cur != NULL | |
3574 && cur->priority > SEARCH_HL_PRIORITY) | |
3575 || cur == NULL)) | |
3576 { | |
3577 shl = &search_hl; | |
3578 shl_flag = TRUE; | |
3579 } | |
3580 else | |
3581 shl = &cur->hl; | |
7 | 3582 while (shl->rm.regprog != NULL) |
3583 { | |
36 | 3584 if (shl->startcol != MAXCOL |
3585 && v >= (long)shl->startcol | |
3586 && v < (long)shl->endcol) | |
7 | 3587 { |
3588 shl->attr_cur = shl->attr; | |
3589 } | |
36 | 3590 else if (v == (long)shl->endcol) |
7 | 3591 { |
3592 shl->attr_cur = 0; | |
3593 | |
3594 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3595 | |
3596 /* Need to get the line again, a multi-line regexp | |
3597 * may have made it invalid. */ | |
3598 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3599 ptr = line + v; | |
3600 | |
3601 if (shl->lnum == lnum) | |
3602 { | |
36 | 3603 shl->startcol = shl->rm.startpos[0].col; |
7 | 3604 if (shl->rm.endpos[0].lnum == 0) |
36 | 3605 shl->endcol = shl->rm.endpos[0].col; |
7 | 3606 else |
36 | 3607 shl->endcol = MAXCOL; |
3608 | |
3609 if (shl->startcol == shl->endcol) | |
7 | 3610 { |
3611 /* highlight empty match, try again after | |
3612 * it */ | |
3613 #ifdef FEAT_MBYTE | |
3614 if (has_mbyte) | |
474 | 3615 shl->endcol += (*mb_ptr2len)(line |
36 | 3616 + shl->endcol); |
7 | 3617 else |
3618 #endif | |
36 | 3619 ++shl->endcol; |
7 | 3620 } |
3621 | |
3622 /* Loop to check if the match starts at the | |
3623 * current position */ | |
3624 continue; | |
3625 } | |
3626 } | |
3627 break; | |
3628 } | |
1326 | 3629 if (shl != &search_hl && cur != NULL) |
3630 cur = cur->next; | |
3631 } | |
3632 | |
3633 /* Use attributes from match with highest priority among | |
3634 * 'search_hl' and the match list. */ | |
3635 search_attr = search_hl.attr_cur; | |
3636 cur = wp->w_match_head; | |
3637 shl_flag = FALSE; | |
3638 while (cur != NULL || shl_flag == FALSE) | |
3639 { | |
3640 if (shl_flag == FALSE | |
3641 && ((cur != NULL | |
3642 && cur->priority > SEARCH_HL_PRIORITY) | |
3643 || cur == NULL)) | |
699 | 3644 { |
1326 | 3645 shl = &search_hl; |
3646 shl_flag = TRUE; | |
699 | 3647 } |
1326 | 3648 else |
3649 shl = &cur->hl; | |
3650 if (shl->attr_cur != 0) | |
3651 search_attr = shl->attr_cur; | |
3652 if (shl != &search_hl && cur != NULL) | |
3653 cur = cur->next; | |
3654 } | |
7 | 3655 } |
3656 #endif | |
3657 | |
3658 #ifdef FEAT_DIFF | |
674 | 3659 if (diff_hlf != (hlf_T)0) |
7 | 3660 { |
1295 | 3661 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3662 && n_extra == 0) | |
7 | 3663 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3664 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3665 && n_extra == 0) | |
7 | 3666 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3667 line_attr = hl_attr(diff_hlf); |
3668 } | |
3669 #endif | |
3670 | |
3671 /* Decide which of the highlight attributes to use. */ | |
3672 attr_pri = TRUE; | |
3673 if (area_attr != 0) | |
3674 char_attr = area_attr; | |
3675 else if (search_attr != 0) | |
3676 char_attr = search_attr; | |
3677 #ifdef LINE_ATTR | |
3678 /* Use line_attr when not in the Visual or 'incsearch' area | |
3679 * (area_attr may be 0 when "noinvcur" is set). */ | |
3680 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3681 || vcol < fromcol || vcol_prev < fromcol_prev |
3682 || vcol >= tocol)) | |
674 | 3683 char_attr = line_attr; |
3684 #endif | |
3685 else | |
3686 { | |
3687 attr_pri = FALSE; | |
3688 #ifdef FEAT_SYN_HL | |
3689 if (has_syntax) | |
3690 char_attr = syntax_attr; | |
3691 else | |
3692 #endif | |
3693 char_attr = 0; | |
3694 } | |
7 | 3695 } |
3696 | |
3697 /* | |
3698 * Get the next character to put on the screen. | |
3699 */ | |
3700 /* | |
1340 | 3701 * The "p_extra" points to the extra stuff that is inserted to |
3702 * represent special characters (non-printable stuff) and other | |
3703 * things. When all characters are the same, c_extra is used. | |
3704 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3705 * "p_extra[n_extra]". | |
7 | 3706 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3707 */ | |
3708 if (n_extra > 0) | |
3709 { | |
3710 if (c_extra != NUL) | |
3711 { | |
3712 c = c_extra; | |
3713 #ifdef FEAT_MBYTE | |
3714 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3715 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3716 { | |
3717 mb_utf8 = TRUE; | |
714 | 3718 u8cc[0] = 0; |
819 | 3719 c = 0xc0; |
7 | 3720 } |
3721 else | |
3722 mb_utf8 = FALSE; | |
3723 #endif | |
3724 } | |
3725 else | |
3726 { | |
3727 c = *p_extra; | |
3728 #ifdef FEAT_MBYTE | |
3729 if (has_mbyte) | |
3730 { | |
3731 mb_c = c; | |
3732 if (enc_utf8) | |
3733 { | |
3734 /* If the UTF-8 character is more than one byte: | |
3735 * Decode it into "mb_c". */ | |
474 | 3736 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3737 mb_utf8 = FALSE; |
3738 if (mb_l > n_extra) | |
3739 mb_l = 1; | |
3740 else if (mb_l > 1) | |
3741 { | |
714 | 3742 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3743 mb_utf8 = TRUE; |
819 | 3744 c = 0xc0; |
7 | 3745 } |
3746 } | |
3747 else | |
3748 { | |
3749 /* if this is a DBCS character, put it in "mb_c" */ | |
3750 mb_l = MB_BYTE2LEN(c); | |
3751 if (mb_l >= n_extra) | |
3752 mb_l = 1; | |
3753 else if (mb_l > 1) | |
3754 mb_c = (c << 8) + p_extra[1]; | |
3755 } | |
504 | 3756 if (mb_l == 0) /* at the NUL at end-of-line */ |
3757 mb_l = 1; | |
3758 | |
7 | 3759 /* If a double-width char doesn't fit display a '>' in the |
3760 * last column. */ | |
504 | 3761 if (( |
7 | 3762 # ifdef FEAT_RIGHTLEFT |
3763 wp->w_p_rl ? (col <= 0) : | |
3764 # endif | |
504 | 3765 (col >= W_WIDTH(wp) - 1)) |
7 | 3766 && (*mb_char2cells)(mb_c) == 2) |
3767 { | |
3768 c = '>'; | |
3769 mb_c = c; | |
3770 mb_l = 1; | |
3771 mb_utf8 = FALSE; | |
3772 multi_attr = hl_attr(HLF_AT); | |
3773 /* put the pointer back to output the double-width | |
3774 * character at the start of the next line. */ | |
3775 ++n_extra; | |
3776 --p_extra; | |
3777 } | |
3778 else | |
3779 { | |
3780 n_extra -= mb_l - 1; | |
3781 p_extra += mb_l - 1; | |
3782 } | |
3783 } | |
3784 #endif | |
3785 ++p_extra; | |
3786 } | |
3787 --n_extra; | |
3788 } | |
3789 else | |
3790 { | |
3791 /* | |
3792 * Get a character from the line itself. | |
3793 */ | |
3794 c = *ptr; | |
3795 #ifdef FEAT_MBYTE | |
3796 if (has_mbyte) | |
3797 { | |
3798 mb_c = c; | |
3799 if (enc_utf8) | |
3800 { | |
3801 /* If the UTF-8 character is more than one byte: Decode it | |
3802 * into "mb_c". */ | |
474 | 3803 mb_l = (*mb_ptr2len)(ptr); |
7 | 3804 mb_utf8 = FALSE; |
3805 if (mb_l > 1) | |
3806 { | |
714 | 3807 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3808 /* Overlong encoded ASCII or ASCII with composing char |
3809 * is displayed normally, except a NUL. */ | |
3810 if (mb_c < 0x80) | |
3811 c = mb_c; | |
3812 mb_utf8 = TRUE; | |
507 | 3813 |
3814 /* At start of the line we can have a composing char. | |
3815 * Draw it as a space with a composing char. */ | |
3816 if (utf_iscomposing(mb_c)) | |
3817 { | |
1326 | 3818 int i; |
3819 | |
714 | 3820 for (i = Screen_mco - 1; i > 0; --i) |
3821 u8cc[i] = u8cc[i - 1]; | |
3822 u8cc[0] = mb_c; | |
507 | 3823 mb_c = ' '; |
3824 } | |
7 | 3825 } |
3826 | |
3827 if ((mb_l == 1 && c >= 0x80) | |
3828 || (mb_l >= 1 && mb_c == 0) | |
3829 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3830 # ifdef UNICODE16 |
3831 || mb_c >= 0x10000 | |
3832 # endif | |
3833 ))) | |
7 | 3834 { |
3835 /* | |
3836 * Illegal UTF-8 byte: display as <xx>. | |
3837 * Non-BMP character : display as ? or fullwidth ?. | |
3838 */ | |
1401 | 3839 # ifdef UNICODE16 |
7 | 3840 if (mb_c < 0x10000) |
1401 | 3841 # endif |
7 | 3842 { |
3843 transchar_hex(extra, mb_c); | |
714 | 3844 # ifdef FEAT_RIGHTLEFT |
7 | 3845 if (wp->w_p_rl) /* reverse */ |
3846 rl_mirror(extra); | |
714 | 3847 # endif |
7 | 3848 } |
1401 | 3849 # ifdef UNICODE16 |
7 | 3850 else if (utf_char2cells(mb_c) != 2) |
3851 STRCPY(extra, "?"); | |
3852 else | |
3853 /* 0xff1f in UTF-8: full-width '?' */ | |
3854 STRCPY(extra, "\357\274\237"); | |
1401 | 3855 # endif |
7 | 3856 |
3857 p_extra = extra; | |
3858 c = *p_extra; | |
3859 mb_c = mb_ptr2char_adv(&p_extra); | |
3860 mb_utf8 = (c >= 0x80); | |
3861 n_extra = (int)STRLEN(p_extra); | |
3862 c_extra = NUL; | |
3863 if (area_attr == 0 && search_attr == 0) | |
3864 { | |
3865 n_attr = n_extra + 1; | |
3866 extra_attr = hl_attr(HLF_8); | |
3867 saved_attr2 = char_attr; /* save current attr */ | |
3868 } | |
3869 } | |
3870 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3871 mb_l = 1; | |
3872 #ifdef FEAT_ARABIC | |
3873 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3874 { | |
3875 /* Do Arabic shaping. */ | |
714 | 3876 int pc, pc1, nc; |
3877 int pcc[MAX_MCO]; | |
7 | 3878 |
3879 /* The idea of what is the previous and next | |
3880 * character depends on 'rightleft'. */ | |
3881 if (wp->w_p_rl) | |
3882 { | |
3883 pc = prev_c; | |
3884 pc1 = prev_c1; | |
3885 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3886 prev_c1 = u8cc[0]; |
7 | 3887 } |
3888 else | |
3889 { | |
714 | 3890 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3891 nc = prev_c; |
714 | 3892 pc1 = pcc[0]; |
7 | 3893 } |
3894 prev_c = mb_c; | |
3895 | |
714 | 3896 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3897 } |
3898 else | |
3899 prev_c = mb_c; | |
3900 #endif | |
3901 } | |
3902 else /* enc_dbcs */ | |
3903 { | |
3904 mb_l = MB_BYTE2LEN(c); | |
3905 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3906 mb_l = 1; | |
3907 else if (mb_l > 1) | |
3908 { | |
3909 /* We assume a second byte below 32 is illegal. | |
3910 * Hopefully this is OK for all double-byte encodings! | |
3911 */ | |
3912 if (ptr[1] >= 32) | |
3913 mb_c = (c << 8) + ptr[1]; | |
3914 else | |
3915 { | |
3916 if (ptr[1] == NUL) | |
3917 { | |
3918 /* head byte at end of line */ | |
3919 mb_l = 1; | |
3920 transchar_nonprint(extra, c); | |
3921 } | |
3922 else | |
3923 { | |
3924 /* illegal tail byte */ | |
3925 mb_l = 2; | |
3926 STRCPY(extra, "XX"); | |
3927 } | |
3928 p_extra = extra; | |
3929 n_extra = (int)STRLEN(extra) - 1; | |
3930 c_extra = NUL; | |
3931 c = *p_extra++; | |
3932 if (area_attr == 0 && search_attr == 0) | |
3933 { | |
3934 n_attr = n_extra + 1; | |
3935 extra_attr = hl_attr(HLF_8); | |
3936 saved_attr2 = char_attr; /* save current attr */ | |
3937 } | |
3938 mb_c = c; | |
3939 } | |
3940 } | |
3941 } | |
3942 /* If a double-width char doesn't fit display a '>' in the | |
3943 * last column; the character is displayed at the start of the | |
3944 * next line. */ | |
3945 if (( | |
3946 # ifdef FEAT_RIGHTLEFT | |
3947 wp->w_p_rl ? (col <= 0) : | |
3948 # endif | |
3949 (col >= W_WIDTH(wp) - 1)) | |
3950 && (*mb_char2cells)(mb_c) == 2) | |
3951 { | |
3952 c = '>'; | |
3953 mb_c = c; | |
3954 mb_utf8 = FALSE; | |
3955 mb_l = 1; | |
3956 multi_attr = hl_attr(HLF_AT); | |
3957 /* Put pointer back so that the character will be | |
3958 * displayed at the start of the next line. */ | |
3959 --ptr; | |
3960 } | |
3961 else if (*ptr != NUL) | |
3962 ptr += mb_l - 1; | |
3963 | |
3964 /* If a double-width char doesn't fit at the left side display | |
3965 * a '<' in the first column. */ | |
3966 if (n_skip > 0 && mb_l > 1) | |
3967 { | |
3968 n_extra = 1; | |
1340 | 3969 c_extra = '<'; |
7 | 3970 c = ' '; |
3971 if (area_attr == 0 && search_attr == 0) | |
3972 { | |
3973 n_attr = n_extra + 1; | |
3974 extra_attr = hl_attr(HLF_AT); | |
3975 saved_attr2 = char_attr; /* save current attr */ | |
3976 } | |
3977 mb_c = c; | |
3978 mb_utf8 = FALSE; | |
3979 mb_l = 1; | |
3980 } | |
3981 | |
3982 } | |
3983 #endif | |
3984 ++ptr; | |
3985 | |
12 | 3986 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 3987 if (wp->w_p_list && (c == 160 |
3988 #ifdef FEAT_MBYTE | |
3989 || (mb_utf8 && mb_c == 160) | |
3990 #endif | |
3991 ) && lcs_nbsp) | |
12 | 3992 { |
3993 c = lcs_nbsp; | |
3994 if (area_attr == 0 && search_attr == 0) | |
3995 { | |
3996 n_attr = 1; | |
3997 extra_attr = hl_attr(HLF_8); | |
3998 saved_attr2 = char_attr; /* save current attr */ | |
3999 } | |
4000 #ifdef FEAT_MBYTE | |
4001 mb_c = c; | |
4002 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4003 { | |
4004 mb_utf8 = TRUE; | |
714 | 4005 u8cc[0] = 0; |
819 | 4006 c = 0xc0; |
12 | 4007 } |
4008 else | |
4009 mb_utf8 = FALSE; | |
4010 #endif | |
4011 } | |
4012 | |
7 | 4013 if (extra_check) |
4014 { | |
743 | 4015 #ifdef FEAT_SPELL |
221 | 4016 int can_spell = TRUE; |
743 | 4017 #endif |
4018 | |
4019 #ifdef FEAT_SYN_HL | |
7 | 4020 /* Get syntax attribute, unless still at the start of the line |
4021 * (double-wide char that doesn't fit). */ | |
221 | 4022 v = (long)(ptr - line); |
4023 if (has_syntax && v > 0) | |
7 | 4024 { |
4025 /* Get the syntax attribute for the character. If there | |
4026 * is an error, disable syntax highlighting. */ | |
4027 save_did_emsg = did_emsg; | |
4028 did_emsg = FALSE; | |
4029 | |
221 | 4030 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4031 # ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4032 &syntax_flags, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4033 # else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4034 NULL, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4035 # endif |
743 | 4036 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4037 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4038 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4039 NULL, FALSE); |
7 | 4040 |
4041 if (did_emsg) | |
482 | 4042 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4043 wp->w_s->b_syn_error = TRUE; |
482 | 4044 has_syntax = FALSE; |
4045 } | |
7 | 4046 else |
4047 did_emsg = save_did_emsg; | |
4048 | |
4049 /* Need to get the line again, a multi-line regexp may | |
4050 * have made it invalid. */ | |
4051 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4052 ptr = line + v; | |
4053 | |
674 | 4054 if (!attr_pri) |
7 | 4055 char_attr = syntax_attr; |
301 | 4056 else |
303 | 4057 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
|
4058 # 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
|
4059 /* 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
|
4060 * 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
|
4061 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
|
4062 syntax_flags = 0; |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4063 # endif |
7 | 4064 } |
743 | 4065 #endif |
4066 | |
4067 #ifdef FEAT_SPELL | |
301 | 4068 /* Check spelling (unless at the end of the line). |
319 | 4069 * Only do this when there is no syntax highlighting, the |
4070 * @Spell cluster is not used or the current syntax item | |
4071 * contains the @Spell cluster. */ | |
348 | 4072 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4073 { |
230 | 4074 spell_attr = 0; |
743 | 4075 # ifdef FEAT_SYN_HL |
674 | 4076 if (!attr_pri) |
230 | 4077 char_attr = syntax_attr; |
743 | 4078 # endif |
4079 if (c != 0 && ( | |
4080 # ifdef FEAT_SYN_HL | |
4081 !has_syntax || | |
4082 # endif | |
4083 can_spell)) | |
221 | 4084 { |
348 | 4085 char_u *prev_ptr, *p; |
4086 int len; | |
534 | 4087 hlf_T spell_hlf = HLF_COUNT; |
221 | 4088 # ifdef FEAT_MBYTE |
336 | 4089 if (has_mbyte) |
4090 { | |
4091 prev_ptr = ptr - mb_l; | |
4092 v -= mb_l - 1; | |
4093 } | |
4094 else | |
221 | 4095 # endif |
336 | 4096 prev_ptr = ptr - 1; |
348 | 4097 |
4098 /* Use nextline[] if possible, it has the start of the | |
4099 * next line concatenated. */ | |
4100 if ((prev_ptr - line) - nextlinecol >= 0) | |
4101 p = nextline + (prev_ptr - line) - nextlinecol; | |
4102 else | |
4103 p = prev_ptr; | |
835 | 4104 cap_col -= (int)(prev_ptr - line); |
625 | 4105 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4106 nochange); | |
348 | 4107 word_end = v + len; |
301 | 4108 |
4109 /* In Insert mode only highlight a word that | |
4110 * doesn't touch the cursor. */ | |
534 | 4111 if (spell_hlf != HLF_COUNT |
301 | 4112 && (State & INSERT) != 0 |
4113 && wp->w_cursor.lnum == lnum | |
4114 && wp->w_cursor.col >= | |
4115 (colnr_T)(prev_ptr - line) | |
4116 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4117 { |
534 | 4118 spell_hlf = HLF_COUNT; |
301 | 4119 spell_redraw_lnum = lnum; |
221 | 4120 } |
348 | 4121 |
534 | 4122 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4123 && (p - nextline) + len > nextline_idx) |
4124 { | |
4125 /* Remember that the good word continues at the | |
4126 * start of the next line. */ | |
4127 checked_lnum = lnum + 1; | |
835 | 4128 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4129 } |
386 | 4130 |
534 | 4131 /* Turn index into actual attributes. */ |
4132 if (spell_hlf != HLF_COUNT) | |
4133 spell_attr = highlight_attr[spell_hlf]; | |
4134 | |
386 | 4135 if (cap_col > 0) |
4136 { | |
4137 if (p != prev_ptr | |
4138 && (p - nextline) + cap_col >= nextline_idx) | |
4139 { | |
4140 /* Remember that the word in the next line | |
4141 * must start with a capital. */ | |
4142 capcol_lnum = lnum + 1; | |
835 | 4143 cap_col = (int)((p - nextline) + cap_col |
4144 - nextline_idx); | |
386 | 4145 } |
4146 else | |
4147 /* Compute the actual column. */ | |
835 | 4148 cap_col += (int)(prev_ptr - line); |
386 | 4149 } |
221 | 4150 } |
4151 } | |
4152 if (spell_attr != 0) | |
348 | 4153 { |
674 | 4154 if (!attr_pri) |
348 | 4155 char_attr = hl_combine_attr(char_attr, spell_attr); |
4156 else | |
4157 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4158 } | |
7 | 4159 #endif |
4160 #ifdef FEAT_LINEBREAK | |
4161 /* | |
221 | 4162 * Found last space before word: check for line break. |
7 | 4163 */ |
4164 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4165 && !wp->w_p_list) |
7 | 4166 { |
4167 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4168 # ifdef FEAT_MBYTE | |
4169 has_mbyte ? mb_l : | |
4170 # endif | |
4171 1), (colnr_T)vcol, NULL) - 1; | |
4172 c_extra = ' '; | |
4173 if (vim_iswhite(c)) | |
4174 c = ' '; | |
4175 } | |
4176 #endif | |
4177 | |
4178 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4179 { | |
4180 c = lcs_trail; | |
674 | 4181 if (!attr_pri) |
7 | 4182 { |
4183 n_attr = 1; | |
4184 extra_attr = hl_attr(HLF_8); | |
4185 saved_attr2 = char_attr; /* save current attr */ | |
4186 } | |
4187 #ifdef FEAT_MBYTE | |
4188 mb_c = c; | |
4189 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4190 { | |
4191 mb_utf8 = TRUE; | |
714 | 4192 u8cc[0] = 0; |
819 | 4193 c = 0xc0; |
7 | 4194 } |
4195 else | |
4196 mb_utf8 = FALSE; | |
4197 #endif | |
4198 } | |
4199 } | |
4200 | |
4201 /* | |
4202 * Handling of non-printable characters. | |
4203 */ | |
819 | 4204 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4205 { |
4206 /* | |
4207 * when getting a character from the file, we may have to | |
4208 * turn it into something else on the way to putting it | |
4209 * into "ScreenLines". | |
4210 */ | |
4211 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4212 { | |
4213 /* tab amount depends on current column */ | |
4214 n_extra = (int)wp->w_buffer->b_p_ts | |
4215 - vcol % (int)wp->w_buffer->b_p_ts - 1; | |
4216 #ifdef FEAT_MBYTE | |
4217 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4218 #endif | |
4219 if (wp->w_p_list) | |
4220 { | |
4221 c = lcs_tab1; | |
4222 c_extra = lcs_tab2; | |
4223 n_attr = n_extra + 1; | |
4224 extra_attr = hl_attr(HLF_8); | |
4225 saved_attr2 = char_attr; /* save current attr */ | |
4226 #ifdef FEAT_MBYTE | |
4227 mb_c = c; | |
4228 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4229 { | |
4230 mb_utf8 = TRUE; | |
714 | 4231 u8cc[0] = 0; |
819 | 4232 c = 0xc0; |
7 | 4233 } |
4234 #endif | |
4235 } | |
4236 else | |
4237 { | |
4238 c_extra = ' '; | |
4239 c = ' '; | |
4240 } | |
4241 } | |
36 | 4242 else if (c == NUL |
4243 && ((wp->w_p_list && lcs_eol > 0) | |
4244 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4245 && tocol > vcol | |
39 | 4246 #ifdef FEAT_VISUAL |
36 | 4247 && VIsual_mode != Ctrl_V |
39 | 4248 #endif |
36 | 4249 && ( |
4250 # ifdef FEAT_RIGHTLEFT | |
4251 wp->w_p_rl ? (col >= 0) : | |
4252 # endif | |
4253 (col < W_WIDTH(wp))) | |
4254 && !(noinvcur | |
1850 | 4255 && lnum == wp->w_cursor.lnum |
36 | 4256 && (colnr_T)vcol == wp->w_virtcol))) |
4257 && lcs_eol_one >= 0) | |
7 | 4258 { |
36 | 4259 /* Display a '$' after the line or highlight an extra |
4260 * character if the line break is included. */ | |
7 | 4261 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4262 /* For a diff line the highlighting continues after the | |
4263 * "$". */ | |
4264 if ( | |
4265 # ifdef FEAT_DIFF | |
534 | 4266 diff_hlf == (hlf_T)0 |
7 | 4267 # ifdef LINE_ATTR |
4268 && | |
4269 # endif | |
4270 # endif | |
4271 # ifdef LINE_ATTR | |
4272 line_attr == 0 | |
4273 # endif | |
4274 ) | |
4275 #endif | |
4276 { | |
4277 #ifdef FEAT_VIRTUALEDIT | |
4278 /* In virtualedit, visual selections may extend | |
4279 * beyond end of line. */ | |
4280 if (area_highlighting && virtual_active() | |
4281 && tocol != MAXCOL && vcol < tocol) | |
4282 n_extra = 0; | |
4283 else | |
4284 #endif | |
4285 { | |
4286 p_extra = at_end_str; | |
4287 n_extra = 1; | |
4288 c_extra = NUL; | |
4289 } | |
4290 } | |
36 | 4291 if (wp->w_p_list) |
4292 c = lcs_eol; | |
4293 else | |
4294 c = ' '; | |
7 | 4295 lcs_eol_one = -1; |
4296 --ptr; /* put it back at the NUL */ | |
674 | 4297 if (!attr_pri) |
7 | 4298 { |
4299 extra_attr = hl_attr(HLF_AT); | |
4300 n_attr = 1; | |
4301 } | |
4302 #ifdef FEAT_MBYTE | |
4303 mb_c = c; | |
4304 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4305 { | |
4306 mb_utf8 = TRUE; | |
714 | 4307 u8cc[0] = 0; |
819 | 4308 c = 0xc0; |
7 | 4309 } |
4310 else | |
4311 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4312 #endif | |
4313 } | |
4314 else if (c != NUL) | |
4315 { | |
4316 p_extra = transchar(c); | |
4317 #ifdef FEAT_RIGHTLEFT | |
4318 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4319 rl_mirror(p_extra); /* reverse "<12>" */ | |
4320 #endif | |
4321 n_extra = byte2cells(c) - 1; | |
4322 c_extra = NUL; | |
4323 c = *p_extra++; | |
674 | 4324 if (!attr_pri) |
7 | 4325 { |
4326 n_attr = n_extra + 1; | |
4327 extra_attr = hl_attr(HLF_8); | |
4328 saved_attr2 = char_attr; /* save current attr */ | |
4329 } | |
4330 #ifdef FEAT_MBYTE | |
4331 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4332 #endif | |
4333 } | |
4334 #ifdef FEAT_VIRTUALEDIT | |
4335 else if (VIsual_active | |
4336 && (VIsual_mode == Ctrl_V | |
4337 || VIsual_mode == 'v') | |
4338 && virtual_active() | |
4339 && tocol != MAXCOL | |
4340 && vcol < tocol | |
4341 && ( | |
4342 # ifdef FEAT_RIGHTLEFT | |
4343 wp->w_p_rl ? (col >= 0) : | |
4344 # endif | |
4345 (col < W_WIDTH(wp)))) | |
4346 { | |
4347 c = ' '; | |
4348 --ptr; /* put it back at the NUL */ | |
4349 } | |
4350 #endif | |
910 | 4351 #if defined(LINE_ATTR) |
7 | 4352 else if (( |
4353 # ifdef FEAT_DIFF | |
910 | 4354 diff_hlf != (hlf_T)0 || |
7 | 4355 # endif |
4356 line_attr != 0 | |
4357 ) && ( | |
4358 # ifdef FEAT_RIGHTLEFT | |
4359 wp->w_p_rl ? (col >= 0) : | |
4360 # endif | |
4361 (col < W_WIDTH(wp)))) | |
4362 { | |
4363 /* Highlight until the right side of the window */ | |
4364 c = ' '; | |
4365 --ptr; /* put it back at the NUL */ | |
867 | 4366 |
4367 /* Remember we do the char for line highlighting. */ | |
4368 ++did_line_attr; | |
4369 | |
4370 /* don't do search HL for the rest of the line */ | |
4371 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4372 char_attr = line_attr; | |
7 | 4373 # ifdef FEAT_DIFF |
4374 if (diff_hlf == HLF_TXD) | |
4375 { | |
4376 diff_hlf = HLF_CHD; | |
4377 if (attr == 0 || char_attr != attr) | |
4378 char_attr = hl_attr(diff_hlf); | |
4379 } | |
4380 # endif | |
4381 } | |
4382 #endif | |
4383 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4384 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4385 #ifdef FEAT_CONCEAL |
2349
586a459f3980
Never hide text for conceal in cursor line. Do hide when there is
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
4386 if ( wp->w_p_conc > 0 |
586a459f3980
Never hide text for conceal in cursor line. Do hide when there is
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
4387 && (lnum != wp->w_cursor.lnum || curwin != wp) |
586a459f3980
Never hide text for conceal in cursor line. Do hide when there is
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
4388 && (syntax_flags & HL_CONCEAL) != 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4389 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4390 char_attr = conceal_attr; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4391 if (first_conceal |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4392 && (syn_get_sub_char() != NUL || wp->w_p_conc == 1)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4393 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4394 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4395 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4396 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4397 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4398 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4399 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4400 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4401 first_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4402 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4403 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4404 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4405 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4406 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
|
4407 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4408 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4409 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4410 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4411 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4412 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4413 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4414 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4415 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4416 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4417 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4418 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4419 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4420 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4421 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4422 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4423 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4424 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4425 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4426 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4427 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4428 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4429 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4430 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4431 if (enc_utf8 && (*mb_char2len)(c) > 1) |
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 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4434 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4435 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4436 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4437 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4438 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
|
4439 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4440 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4441 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4442 { |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4443 first_conceal = (wp->w_p_conc != 3); |
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4444 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4445 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4446 #endif /* FEAT_CONCEAL */ |
7 | 4447 } |
4448 | |
4449 /* Don't override visual selection highlighting. */ | |
4450 if (n_attr > 0 | |
4451 && draw_state == WL_LINE | |
674 | 4452 && !attr_pri) |
7 | 4453 char_attr = extra_attr; |
4454 | |
42 | 4455 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4456 /* XIM don't send preedit_start and preedit_end, but they send |
4457 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4458 * im_is_preediting() here. */ | |
4459 if (xic != NULL | |
1850 | 4460 && lnum == wp->w_cursor.lnum |
7 | 4461 && (State & INSERT) |
4462 && !p_imdisable | |
4463 && im_is_preediting() | |
4464 && draw_state == WL_LINE) | |
4465 { | |
4466 colnr_T tcol; | |
4467 | |
4468 if (preedit_end_col == MAXCOL) | |
1850 | 4469 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4470 else |
4471 tcol = preedit_end_col; | |
4472 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4473 { | |
4474 if (feedback_old_attr < 0) | |
4475 { | |
4476 feedback_col = 0; | |
4477 feedback_old_attr = char_attr; | |
4478 } | |
4479 char_attr = im_get_feedback_attr(feedback_col); | |
4480 if (char_attr < 0) | |
4481 char_attr = feedback_old_attr; | |
4482 feedback_col++; | |
4483 } | |
4484 else if (feedback_old_attr >= 0) | |
4485 { | |
4486 char_attr = feedback_old_attr; | |
4487 feedback_old_attr = -1; | |
4488 feedback_col = 0; | |
4489 } | |
4490 } | |
4491 #endif | |
4492 /* | |
4493 * Handle the case where we are in column 0 but not on the first | |
4494 * character of the line and the user wants us to show us a | |
4495 * special character (via 'listchars' option "precedes:<char>". | |
4496 */ | |
4497 if (lcs_prec_todo != NUL | |
4498 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4499 #ifdef FEAT_DIFF | |
4500 && filler_todo <= 0 | |
4501 #endif | |
4502 && draw_state > WL_NR | |
4503 && c != NUL) | |
4504 { | |
4505 c = lcs_prec; | |
4506 lcs_prec_todo = NUL; | |
4507 #ifdef FEAT_MBYTE | |
4508 mb_c = c; | |
4509 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4510 { | |
4511 mb_utf8 = TRUE; | |
714 | 4512 u8cc[0] = 0; |
819 | 4513 c = 0xc0; |
7 | 4514 } |
4515 else | |
4516 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4517 #endif | |
674 | 4518 if (!attr_pri) |
7 | 4519 { |
4520 saved_attr3 = char_attr; /* save current attr */ | |
4521 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4522 n_attr3 = 1; | |
4523 } | |
4524 } | |
4525 | |
4526 /* | |
867 | 4527 * At end of the text line or just after the last character. |
7 | 4528 */ |
867 | 4529 if (c == NUL |
910 | 4530 #if defined(LINE_ATTR) |
867 | 4531 || did_line_attr == 1 |
4532 #endif | |
4533 ) | |
4534 { | |
4535 #ifdef FEAT_SEARCH_EXTRA | |
4536 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4537 |
4538 /* we're not really at that column when skipping some text */ | |
1439 | 4539 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4540 ++prevcol; |
867 | 4541 #endif |
4542 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4543 /* Invert at least one char, used for Visual and empty line or |
7 | 4544 * highlight match at end of line. If it's beyond the last |
4545 * char on the screen, just overwrite that one (tricky!) Not | |
4546 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4547 #ifdef FEAT_SEARCH_EXTRA |
4548 prevcol_hl_flag = FALSE; | |
4549 if (prevcol == (long)search_hl.startcol) | |
4550 prevcol_hl_flag = TRUE; | |
4551 else | |
4552 { | |
4553 cur = wp->w_match_head; | |
4554 while (cur != NULL) | |
4555 { | |
4556 if (prevcol == (long)cur->hl.startcol) | |
4557 { | |
4558 prevcol_hl_flag = TRUE; | |
4559 break; | |
4560 } | |
4561 cur = cur->next; | |
4562 } | |
4563 } | |
4564 #endif | |
7 | 4565 if (lcs_eol == lcs_eol_one |
1850 | 4566 && ((area_attr != 0 && vcol == fromcol |
4567 #ifdef FEAT_VISUAL | |
4568 && (VIsual_mode != Ctrl_V | |
4569 || lnum == VIsual.lnum | |
4570 || lnum == curwin->w_cursor.lnum) | |
4571 #endif | |
4572 && c == NUL) | |
7 | 4573 #ifdef FEAT_SEARCH_EXTRA |
4574 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4575 || (prevcol_hl_flag == TRUE |
910 | 4576 # if defined(LINE_ATTR) |
867 | 4577 && did_line_attr <= 1 |
4578 # endif | |
4579 ) | |
7 | 4580 #endif |
4581 )) | |
4582 { | |
4583 int n = 0; | |
4584 | |
4585 #ifdef FEAT_RIGHTLEFT | |
4586 if (wp->w_p_rl) | |
4587 { | |
4588 if (col < 0) | |
4589 n = 1; | |
4590 } | |
4591 else | |
4592 #endif | |
4593 { | |
4594 if (col >= W_WIDTH(wp)) | |
4595 n = -1; | |
4596 } | |
4597 if (n != 0) | |
4598 { | |
4599 /* At the window boundary, highlight the last character | |
4600 * instead (better than nothing). */ | |
4601 off += n; | |
4602 col += n; | |
4603 } | |
4604 else | |
4605 { | |
4606 /* Add a blank character to highlight. */ | |
4607 ScreenLines[off] = ' '; | |
4608 #ifdef FEAT_MBYTE | |
4609 if (enc_utf8) | |
4610 ScreenLinesUC[off] = 0; | |
4611 #endif | |
4612 } | |
4613 #ifdef FEAT_SEARCH_EXTRA | |
4614 if (area_attr == 0) | |
4615 { | |
1326 | 4616 /* Use attributes from match with highest priority among |
4617 * 'search_hl' and the match list. */ | |
4618 char_attr = search_hl.attr; | |
4619 cur = wp->w_match_head; | |
4620 shl_flag = FALSE; | |
4621 while (cur != NULL || shl_flag == FALSE) | |
699 | 4622 { |
1326 | 4623 if (shl_flag == FALSE |
4624 && ((cur != NULL | |
4625 && cur->priority > SEARCH_HL_PRIORITY) | |
4626 || cur == NULL)) | |
699 | 4627 { |
1326 | 4628 shl = &search_hl; |
4629 shl_flag = TRUE; | |
699 | 4630 } |
1326 | 4631 else |
4632 shl = &cur->hl; | |
4633 if ((ptr - line) - 1 == (long)shl->startcol) | |
4634 char_attr = shl->attr; | |
4635 if (shl != &search_hl && cur != NULL) | |
4636 cur = cur->next; | |
699 | 4637 } |
7 | 4638 } |
4639 #endif | |
4640 ScreenAttrs[off] = char_attr; | |
4641 #ifdef FEAT_RIGHTLEFT | |
4642 if (wp->w_p_rl) | |
1437 | 4643 { |
7 | 4644 --col; |
1437 | 4645 --off; |
4646 } | |
7 | 4647 else |
4648 #endif | |
1437 | 4649 { |
7 | 4650 ++col; |
1437 | 4651 ++off; |
4652 } | |
743 | 4653 ++vcol; |
1437 | 4654 #ifdef FEAT_SYN_HL |
4655 eol_hl_off = 1; | |
4656 #endif | |
743 | 4657 } |
867 | 4658 } |
4659 | |
4660 /* | |
4661 * At end of the text line. | |
4662 */ | |
4663 if (c == NUL) | |
4664 { | |
743 | 4665 #ifdef FEAT_SYN_HL |
1850 | 4666 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4667 && lnum == wp->w_cursor.lnum) | |
1437 | 4668 { |
4669 /* highlight last char after line */ | |
4670 --col; | |
4671 --off; | |
4672 --vcol; | |
4673 } | |
4674 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4675 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4676 if (wp->w_p_wrap) |
4677 v = wp->w_skipcol; | |
4678 else | |
4679 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4680 |
820 | 4681 /* check if line ends before left margin */ |
4682 if (vcol < v + col - win_col_off(wp)) | |
4683 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
|
4684 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4685 /* 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
|
4686 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4687 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4688 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4689 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4690 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4691 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4692 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
|
4693 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4694 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4695 && (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
|
4696 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4697 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
|
4698 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4699 || draw_color_col) |
743 | 4700 # ifdef FEAT_RIGHTLEFT |
4701 && !wp->w_p_rl | |
4702 # endif | |
4703 ) | |
4704 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4705 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4706 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4707 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4708 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4709 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4710 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4711 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4712 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
|
4713 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4714 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4715 |
743 | 4716 while (col < W_WIDTH(wp)) |
4717 { | |
4718 ScreenLines[off] = ' '; | |
4719 #ifdef FEAT_MBYTE | |
4720 if (enc_utf8) | |
4721 ScreenLinesUC[off] = 0; | |
4722 #endif | |
4723 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4724 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4725 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
|
4726 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4727 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4728 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
|
4729 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
|
4730 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
|
4731 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4732 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4733 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4734 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4735 if (VCOL_HLC >= rightmost_vcol) |
743 | 4736 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4737 |
743 | 4738 ++vcol; |
4739 } | |
4740 } | |
4741 #endif | |
7 | 4742 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4743 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
|
4744 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4745 row++; |
4746 | |
4747 /* | |
4748 * Update w_cline_height and w_cline_folded if the cursor line was | |
4749 * updated (saves a call to plines() later). | |
4750 */ | |
4751 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4752 { | |
4753 curwin->w_cline_row = startrow; | |
4754 curwin->w_cline_height = row - startrow; | |
4755 #ifdef FEAT_FOLDING | |
4756 curwin->w_cline_folded = FALSE; | |
4757 #endif | |
4758 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4759 } | |
4760 | |
4761 break; | |
4762 } | |
4763 | |
4764 /* line continues beyond line end */ | |
4765 if (lcs_ext | |
4766 && !wp->w_p_wrap | |
4767 #ifdef FEAT_DIFF | |
4768 && filler_todo <= 0 | |
4769 #endif | |
4770 && ( | |
4771 #ifdef FEAT_RIGHTLEFT | |
4772 wp->w_p_rl ? col == 0 : | |
4773 #endif | |
4774 col == W_WIDTH(wp) - 1) | |
4775 && (*ptr != NUL | |
1555 | 4776 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4777 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4778 { | |
4779 c = lcs_ext; | |
4780 char_attr = hl_attr(HLF_AT); | |
4781 #ifdef FEAT_MBYTE | |
4782 mb_c = c; | |
4783 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4784 { | |
4785 mb_utf8 = TRUE; | |
714 | 4786 u8cc[0] = 0; |
819 | 4787 c = 0xc0; |
7 | 4788 } |
4789 else | |
4790 mb_utf8 = FALSE; | |
4791 #endif | |
4792 } | |
4793 | |
743 | 4794 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4795 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4796 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4797 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
|
4798 |
743 | 4799 /* 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
|
4800 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4801 * 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
|
4802 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4803 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4804 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
|
4805 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4806 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
|
4807 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4808 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4809 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4810 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
|
4811 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4812 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
|
4813 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4814 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4815 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
|
4816 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4817 } |
743 | 4818 #endif |
4819 | |
7 | 4820 /* |
4821 * Store character to be displayed. | |
4822 * Skip characters that are left of the screen for 'nowrap'. | |
4823 */ | |
4824 vcol_prev = vcol; | |
4825 if (draw_state < WL_LINE || n_skip <= 0) | |
4826 { | |
4827 /* | |
4828 * Store the character. | |
4829 */ | |
4830 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4831 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4832 { | |
4833 /* A double-wide character is: put first halve in left cell. */ | |
4834 --off; | |
4835 --col; | |
4836 } | |
4837 #endif | |
4838 ScreenLines[off] = c; | |
4839 #ifdef FEAT_MBYTE | |
4840 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4841 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4842 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4843 ScreenLines[off] = 0x8e; |
7 | 4844 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4845 } |
7 | 4846 else if (enc_utf8) |
4847 { | |
4848 if (mb_utf8) | |
4849 { | |
1326 | 4850 int i; |
4851 | |
7 | 4852 ScreenLinesUC[off] = mb_c; |
819 | 4853 if ((c & 0xff) == 0) |
4854 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4855 for (i = 0; i < Screen_mco; ++i) |
4856 { | |
4857 ScreenLinesC[i][off] = u8cc[i]; | |
4858 if (u8cc[i] == 0) | |
4859 break; | |
4860 } | |
7 | 4861 } |
4862 else | |
4863 ScreenLinesUC[off] = 0; | |
4864 } | |
4865 if (multi_attr) | |
4866 { | |
4867 ScreenAttrs[off] = multi_attr; | |
4868 multi_attr = 0; | |
4869 } | |
4870 else | |
4871 #endif | |
4872 ScreenAttrs[off] = char_attr; | |
4873 | |
4874 #ifdef FEAT_MBYTE | |
4875 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4876 { | |
4877 /* Need to fill two screen columns. */ | |
4878 ++off; | |
4879 ++col; | |
4880 if (enc_utf8) | |
4881 /* UTF-8: Put a 0 in the second screen char. */ | |
4882 ScreenLines[off] = 0; | |
4883 else | |
4884 /* DBCS: Put second byte in the second screen char. */ | |
4885 ScreenLines[off] = mb_c & 0xff; | |
4886 ++vcol; | |
4887 /* When "tocol" is halfway a character, set it to the end of | |
4888 * the character, otherwise highlighting won't stop. */ | |
4889 if (tocol == vcol) | |
4890 ++tocol; | |
4891 #ifdef FEAT_RIGHTLEFT | |
4892 if (wp->w_p_rl) | |
4893 { | |
4894 /* now it's time to backup one cell */ | |
4895 --off; | |
4896 --col; | |
4897 } | |
4898 #endif | |
4899 } | |
4900 #endif | |
4901 #ifdef FEAT_RIGHTLEFT | |
4902 if (wp->w_p_rl) | |
4903 { | |
4904 --off; | |
4905 --col; | |
4906 } | |
4907 else | |
4908 #endif | |
4909 { | |
4910 ++off; | |
4911 ++col; | |
4912 } | |
4913 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4914 #ifdef FEAT_CONCEAL |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4915 else if (wp->w_p_conc > 0 && is_concealing) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4916 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4917 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4918 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4919 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4920 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4921 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4922 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4923 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4924 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4925 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4926 * 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
|
4927 * 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
|
4928 * 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
|
4929 * 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
|
4930 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4931 * 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
|
4932 * 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
|
4933 * 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
|
4934 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4935 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4936 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4937 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4938 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4939 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4940 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4941 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4942 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4943 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4944 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4945 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4946 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4947 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4948 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4949 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4950 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4951 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4952 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4953 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4954 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4955 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4956 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4957 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
|
4958 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4959 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4960 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4961 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4962 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4963 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4964 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4965 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4966 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4967 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4968 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4969 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4970 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4971 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4972 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4973 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4974 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4975 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4976 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4977 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4978 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4979 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4980 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4981 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4982 # endif |
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 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4985 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4986 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4987 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4988 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4989 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4990 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4991 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4992 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4993 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4994 n_attr = 0; |
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 } |
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 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4999 #endif /* FEAT_CONCEAL */ |
7 | 5000 else |
5001 --n_skip; | |
5002 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5003 /* 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
|
5004 * column. */ |
1849 | 5005 if (draw_state > WL_NR |
7 | 5006 #ifdef FEAT_DIFF |
5007 && filler_todo <= 0 | |
5008 #endif | |
5009 ) | |
5010 ++vcol; | |
5011 | |
743 | 5012 #ifdef FEAT_SYN_HL |
5013 if (vcol_save_attr >= 0) | |
5014 char_attr = vcol_save_attr; | |
5015 #endif | |
5016 | |
7 | 5017 /* restore attributes after "predeces" in 'listchars' */ |
5018 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5019 char_attr = saved_attr3; | |
5020 | |
5021 /* restore attributes after last 'listchars' or 'number' char */ | |
5022 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5023 char_attr = saved_attr2; | |
5024 | |
5025 /* | |
5026 * At end of screen line and there is more to come: Display the line | |
1378 | 5027 * so far. If there is no more to display it is caught above. |
7 | 5028 */ |
5029 if (( | |
5030 #ifdef FEAT_RIGHTLEFT | |
5031 wp->w_p_rl ? (col < 0) : | |
5032 #endif | |
5033 (col >= W_WIDTH(wp))) | |
5034 && (*ptr != NUL | |
5035 #ifdef FEAT_DIFF | |
5036 || filler_todo > 0 | |
5037 #endif | |
5038 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) | |
5039 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) | |
5040 ) | |
5041 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5043 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
|
5044 (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
|
5045 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5046 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5047 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
|
5048 (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
|
5049 #endif |
7 | 5050 ++row; |
5051 ++screen_row; | |
5052 | |
5053 /* When not wrapping and finished diff lines, or when displayed | |
5054 * '$' and highlighting until last column, break here. */ | |
5055 if ((!wp->w_p_wrap | |
5056 #ifdef FEAT_DIFF | |
5057 && filler_todo <= 0 | |
5058 #endif | |
5059 ) || lcs_eol_one == -1) | |
5060 break; | |
5061 | |
5062 /* When the window is too narrow draw all "@" lines. */ | |
5063 if (draw_state != WL_LINE | |
5064 #ifdef FEAT_DIFF | |
5065 && filler_todo <= 0 | |
5066 #endif | |
5067 ) | |
5068 { | |
5069 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5070 #ifdef FEAT_VERTSPLIT | |
5071 draw_vsep_win(wp, row); | |
5072 #endif | |
5073 row = endrow; | |
5074 } | |
5075 | |
5076 /* When line got too long for screen break here. */ | |
5077 if (row == endrow) | |
5078 { | |
5079 ++row; | |
5080 break; | |
5081 } | |
5082 | |
5083 if (screen_cur_row == screen_row - 1 | |
5084 #ifdef FEAT_DIFF | |
5085 && filler_todo <= 0 | |
5086 #endif | |
5087 && W_WIDTH(wp) == Columns) | |
5088 { | |
5089 /* Remember that the line wraps, used for modeless copy. */ | |
5090 LineWraps[screen_row - 1] = TRUE; | |
5091 | |
5092 /* | |
5093 * Special trick to make copy/paste of wrapped lines work with | |
5094 * xterm/screen: write an extra character beyond the end of | |
5095 * the line. This will work with all terminal types | |
5096 * (regardless of the xn,am settings). | |
5097 * Only do this on a fast tty. | |
5098 * Only do this if the cursor is on the current line | |
5099 * (something has been written in it). | |
5100 * Don't do this for the GUI. | |
5101 * Don't do this for double-width characters. | |
5102 * Don't do this for a window not at the right screen border. | |
5103 */ | |
5104 if (p_tf | |
5105 #ifdef FEAT_GUI | |
5106 && !gui.in_use | |
5107 #endif | |
5108 #ifdef FEAT_MBYTE | |
5109 && !(has_mbyte | |
1378 | 5110 && ((*mb_off2cells)(LineOffset[screen_row], |
5111 LineOffset[screen_row] + screen_Columns) | |
5112 == 2 | |
7 | 5113 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5114 + (int)Columns - 2, |
5115 LineOffset[screen_row] + screen_Columns) | |
5116 == 2)) | |
7 | 5117 #endif |
5118 ) | |
5119 { | |
5120 /* First make sure we are at the end of the screen line, | |
5121 * then output the same character again to let the | |
5122 * terminal know about the wrap. If the terminal doesn't | |
5123 * auto-wrap, we overwrite the character. */ | |
5124 if (screen_cur_col != W_WIDTH(wp)) | |
5125 screen_char(LineOffset[screen_row - 1] | |
5126 + (unsigned)Columns - 1, | |
5127 screen_row - 1, (int)(Columns - 1)); | |
5128 | |
5129 #ifdef FEAT_MBYTE | |
5130 /* When there is a multi-byte character, just output a | |
5131 * space to keep it simple. */ | |
148 | 5132 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5133 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5134 out_char(' '); |
5135 else | |
5136 #endif | |
5137 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5138 + (Columns - 1)]); | |
5139 /* force a redraw of the first char on the next line */ | |
5140 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5141 screen_start(); /* don't know where cursor is now */ | |
5142 } | |
5143 } | |
5144 | |
5145 col = 0; | |
5146 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5147 #ifdef FEAT_RIGHTLEFT | |
5148 if (wp->w_p_rl) | |
5149 { | |
5150 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5151 off += col; | |
5152 } | |
5153 #endif | |
5154 | |
5155 /* reset the drawing state for the start of a wrapped line */ | |
5156 draw_state = WL_START; | |
5157 saved_n_extra = n_extra; | |
5158 saved_p_extra = p_extra; | |
5159 saved_c_extra = c_extra; | |
5160 saved_char_attr = char_attr; | |
5161 n_extra = 0; | |
5162 lcs_prec_todo = lcs_prec; | |
5163 #ifdef FEAT_LINEBREAK | |
5164 # ifdef FEAT_DIFF | |
5165 if (filler_todo <= 0) | |
5166 # endif | |
5167 need_showbreak = TRUE; | |
5168 #endif | |
5169 #ifdef FEAT_DIFF | |
5170 --filler_todo; | |
5171 /* When the filler lines are actually below the last line of the | |
5172 * file, don't draw the line itself, break here. */ | |
5173 if (filler_todo == 0 && wp->w_botfill) | |
5174 break; | |
5175 #endif | |
5176 } | |
5177 | |
5178 } /* for every character in the line */ | |
5179 | |
743 | 5180 #ifdef FEAT_SPELL |
386 | 5181 /* After an empty line check first word for capital. */ |
5182 if (*skipwhite(line) == NUL) | |
5183 { | |
5184 capcol_lnum = lnum + 1; | |
5185 cap_col = 0; | |
5186 } | |
5187 #endif | |
5188 | |
7 | 5189 return row; |
5190 } | |
5191 | |
714 | 5192 #ifdef FEAT_MBYTE |
5193 static int comp_char_differs __ARGS((int, int)); | |
5194 | |
5195 /* | |
5196 * 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
|
5197 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5198 */ |
5199 static int | |
5200 comp_char_differs(off_from, off_to) | |
5201 int off_from; | |
5202 int off_to; | |
5203 { | |
5204 int i; | |
5205 | |
5206 for (i = 0; i < Screen_mco; ++i) | |
5207 { | |
5208 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5209 return TRUE; | |
5210 if (ScreenLinesC[i][off_from] == 0) | |
5211 break; | |
5212 } | |
5213 return FALSE; | |
5214 } | |
5215 #endif | |
5216 | |
7 | 5217 /* |
5218 * Check whether the given character needs redrawing: | |
5219 * - the (first byte of the) character is different | |
5220 * - the attributes are different | |
5221 * - the character is multi-byte and the next byte is different | |
1616 | 5222 * - the character is two cells wide and the second cell differs. |
7 | 5223 */ |
5224 static int | |
5225 char_needs_redraw(off_from, off_to, cols) | |
5226 int off_from; | |
5227 int off_to; | |
5228 int cols; | |
5229 { | |
5230 if (cols > 0 | |
5231 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5232 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5233 | |
5234 #ifdef FEAT_MBYTE | |
5235 || (enc_dbcs != 0 | |
5236 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5237 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5238 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5239 : (cols > 1 && ScreenLines[off_from + 1] | |
5240 != ScreenLines[off_to + 1]))) | |
5241 || (enc_utf8 | |
5242 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5243 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5244 && comp_char_differs(off_from, off_to)) |
5245 || (cols > 1 && ScreenLines[off_from + 1] | |
5246 != ScreenLines[off_to + 1]))) | |
7 | 5247 #endif |
5248 )) | |
5249 return TRUE; | |
5250 return FALSE; | |
5251 } | |
5252 | |
5253 /* | |
5254 * Move one "cooked" screen line to the screen, but only the characters that | |
5255 * have actually changed. Handle insert/delete character. | |
5256 * "coloff" gives the first column on the screen for this line. | |
5257 * "endcol" gives the columns where valid characters are. | |
5258 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5259 * needs to be cleared, negative otherwise. | |
5260 * "rlflag" is TRUE in a rightleft window: | |
5261 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5262 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5263 */ | |
5264 static void | |
5265 screen_line(row, coloff, endcol, clear_width | |
5266 #ifdef FEAT_RIGHTLEFT | |
5267 , rlflag | |
5268 #endif | |
5269 ) | |
5270 int row; | |
5271 int coloff; | |
5272 int endcol; | |
5273 int clear_width; | |
5274 #ifdef FEAT_RIGHTLEFT | |
5275 int rlflag; | |
5276 #endif | |
5277 { | |
5278 unsigned off_from; | |
5279 unsigned off_to; | |
1378 | 5280 #ifdef FEAT_MBYTE |
5281 unsigned max_off_from; | |
5282 unsigned max_off_to; | |
5283 #endif | |
7 | 5284 int col = 0; |
5285 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5286 int hl; | |
5287 #endif | |
5288 int force = FALSE; /* force update rest of the line */ | |
5289 int redraw_this /* bool: does character need redraw? */ | |
5290 #ifdef FEAT_GUI | |
5291 = TRUE /* For GUI when while-loop empty */ | |
5292 #endif | |
5293 ; | |
5294 int redraw_next; /* redraw_this for next character */ | |
5295 #ifdef FEAT_MBYTE | |
5296 int clear_next = FALSE; | |
5297 int char_cells; /* 1: normal char */ | |
5298 /* 2: occupies two display cells */ | |
5299 # define CHAR_CELLS char_cells | |
5300 #else | |
5301 # define CHAR_CELLS 1 | |
5302 #endif | |
5303 | |
5304 # ifdef FEAT_CLIPBOARD | |
5305 clip_may_clear_selection(row, row); | |
5306 # endif | |
5307 | |
5308 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5309 off_to = LineOffset[row] + coloff; | |
1378 | 5310 #ifdef FEAT_MBYTE |
5311 max_off_from = off_from + screen_Columns; | |
5312 max_off_to = LineOffset[row] + screen_Columns; | |
5313 #endif | |
7 | 5314 |
5315 #ifdef FEAT_RIGHTLEFT | |
5316 if (rlflag) | |
5317 { | |
5318 /* Clear rest first, because it's left of the text. */ | |
5319 if (clear_width > 0) | |
5320 { | |
5321 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5322 && ScreenAttrs[off_to] == 0 | |
5323 # ifdef FEAT_MBYTE | |
5324 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5325 # endif | |
5326 ) | |
5327 { | |
5328 ++off_to; | |
5329 ++col; | |
5330 } | |
5331 if (col <= endcol) | |
5332 screen_fill(row, row + 1, col + coloff, | |
5333 endcol + coloff + 1, ' ', ' ', 0); | |
5334 } | |
5335 col = endcol + 1; | |
5336 off_to = LineOffset[row] + col + coloff; | |
5337 off_from += col; | |
5338 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5339 } | |
5340 #endif /* FEAT_RIGHTLEFT */ | |
5341 | |
5342 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5343 | |
5344 while (col < endcol) | |
5345 { | |
5346 #ifdef FEAT_MBYTE | |
5347 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5348 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5349 else |
5350 char_cells = 1; | |
5351 #endif | |
5352 | |
5353 redraw_this = redraw_next; | |
5354 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5355 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5356 | |
5357 #ifdef FEAT_GUI | |
5358 /* If the next character was bold, then redraw the current character to | |
5359 * remove any pixels that might have spilt over into us. This only | |
5360 * happens in the GUI. | |
5361 */ | |
5362 if (redraw_next && gui.in_use) | |
5363 { | |
5364 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5365 if (hl > HL_ALL) |
5366 hl = syn_attr2attr(hl); | |
5367 if (hl & HL_BOLD) | |
7 | 5368 redraw_this = TRUE; |
5369 } | |
5370 #endif | |
5371 | |
5372 if (redraw_this) | |
5373 { | |
5374 /* | |
5375 * Special handling when 'xs' termcap flag set (hpterm): | |
5376 * Attributes for characters are stored at the position where the | |
5377 * cursor is when writing the highlighting code. The | |
5378 * start-highlighting code must be written with the cursor on the | |
5379 * first highlighted character. The stop-highlighting code must | |
5380 * be written with the cursor just after the last highlighted | |
5381 * character. | |
5382 * Overwriting a character doesn't remove it's highlighting. Need | |
5383 * to clear the rest of the line, and force redrawing it | |
5384 * completely. | |
5385 */ | |
5386 if ( p_wiv | |
5387 && !force | |
5388 #ifdef FEAT_GUI | |
5389 && !gui.in_use | |
5390 #endif | |
5391 && ScreenAttrs[off_to] != 0 | |
5392 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5393 { | |
5394 /* | |
5395 * Need to remove highlighting attributes here. | |
5396 */ | |
5397 windgoto(row, col + coloff); | |
5398 out_str(T_CE); /* clear rest of this screen line */ | |
5399 screen_start(); /* don't know where cursor is now */ | |
5400 force = TRUE; /* force redraw of rest of the line */ | |
5401 redraw_next = TRUE; /* or else next char would miss out */ | |
5402 | |
5403 /* | |
5404 * If the previous character was highlighted, need to stop | |
5405 * highlighting at this character. | |
5406 */ | |
5407 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5408 { | |
5409 screen_attr = ScreenAttrs[off_to - 1]; | |
5410 term_windgoto(row, col + coloff); | |
5411 screen_stop_highlight(); | |
5412 } | |
5413 else | |
5414 screen_attr = 0; /* highlighting has stopped */ | |
5415 } | |
5416 #ifdef FEAT_MBYTE | |
5417 if (enc_dbcs != 0) | |
5418 { | |
5419 /* Check if overwriting a double-byte with a single-byte or | |
5420 * the other way around requires another character to be | |
5421 * redrawn. For UTF-8 this isn't needed, because comparing | |
5422 * ScreenLinesUC[] is sufficient. */ | |
5423 if (char_cells == 1 | |
5424 && col + 1 < endcol | |
1378 | 5425 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5426 { |
5427 /* Writing a single-cell character over a double-cell | |
5428 * character: need to redraw the next cell. */ | |
5429 ScreenLines[off_to + 1] = 0; | |
5430 redraw_next = TRUE; | |
5431 } | |
5432 else if (char_cells == 2 | |
5433 && col + 2 < endcol | |
1378 | 5434 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5435 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5436 { |
5437 /* Writing the second half of a double-cell character over | |
5438 * a double-cell character: need to redraw the second | |
5439 * cell. */ | |
5440 ScreenLines[off_to + 2] = 0; | |
5441 redraw_next = TRUE; | |
5442 } | |
5443 | |
5444 if (enc_dbcs == DBCS_JPNU) | |
5445 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5446 } | |
5447 /* When writing a single-width character over a double-width | |
5448 * character and at the end of the redrawn text, need to clear out | |
5449 * the right halve of the old character. | |
5450 * Also required when writing the right halve of a double-width | |
5451 * char over the left halve of an existing one. */ | |
5452 if (has_mbyte && col + char_cells == endcol | |
5453 && ((char_cells == 1 | |
1378 | 5454 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5455 || (char_cells == 2 |
1378 | 5456 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5457 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5458 clear_next = TRUE; |
5459 #endif | |
5460 | |
5461 ScreenLines[off_to] = ScreenLines[off_from]; | |
5462 #ifdef FEAT_MBYTE | |
5463 if (enc_utf8) | |
5464 { | |
5465 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5466 if (ScreenLinesUC[off_from] != 0) | |
5467 { | |
714 | 5468 int i; |
5469 | |
5470 for (i = 0; i < Screen_mco; ++i) | |
5471 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5472 } |
5473 } | |
5474 if (char_cells == 2) | |
5475 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5476 #endif | |
5477 | |
5478 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5479 /* The bold trick makes a single column of pixels appear in the |
5480 * next character. When a bold character is removed, the next | |
7 | 5481 * character should be redrawn too. This happens for our own GUI |
5482 * and for some xterms. */ | |
5483 if ( | |
5484 # ifdef FEAT_GUI | |
5485 gui.in_use | |
5486 # endif | |
5487 # if defined(FEAT_GUI) && defined(UNIX) | |
5488 || | |
5489 # endif | |
5490 # ifdef UNIX | |
5491 term_is_xterm | |
5492 # endif | |
5493 ) | |
5494 { | |
5495 hl = ScreenAttrs[off_to]; | |
743 | 5496 if (hl > HL_ALL) |
5497 hl = syn_attr2attr(hl); | |
5498 if (hl & HL_BOLD) | |
7 | 5499 redraw_next = TRUE; |
5500 } | |
5501 #endif | |
5502 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5503 #ifdef FEAT_MBYTE | |
819 | 5504 /* For simplicity set the attributes of second half of a |
5505 * double-wide character equal to the first half. */ | |
5506 if (char_cells == 2) | |
5507 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5508 | |
7 | 5509 if (enc_dbcs != 0 && char_cells == 2) |
5510 screen_char_2(off_to, row, col + coloff); | |
5511 else | |
5512 #endif | |
5513 screen_char(off_to, row, col + coloff); | |
5514 } | |
5515 else if ( p_wiv | |
5516 #ifdef FEAT_GUI | |
5517 && !gui.in_use | |
5518 #endif | |
5519 && col + coloff > 0) | |
5520 { | |
5521 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5522 { | |
5523 /* | |
5524 * Don't output stop-highlight when moving the cursor, it will | |
5525 * stop the highlighting when it should continue. | |
5526 */ | |
5527 screen_attr = 0; | |
5528 } | |
5529 else if (screen_attr != 0) | |
5530 screen_stop_highlight(); | |
5531 } | |
5532 | |
5533 off_to += CHAR_CELLS; | |
5534 off_from += CHAR_CELLS; | |
5535 col += CHAR_CELLS; | |
5536 } | |
5537 | |
5538 #ifdef FEAT_MBYTE | |
5539 if (clear_next) | |
5540 { | |
5541 /* Clear the second half of a double-wide character of which the left | |
5542 * half was overwritten with a single-wide character. */ | |
5543 ScreenLines[off_to] = ' '; | |
5544 if (enc_utf8) | |
5545 ScreenLinesUC[off_to] = 0; | |
5546 screen_char(off_to, row, col + coloff); | |
5547 } | |
5548 #endif | |
5549 | |
5550 if (clear_width > 0 | |
5551 #ifdef FEAT_RIGHTLEFT | |
5552 && !rlflag | |
5553 #endif | |
5554 ) | |
5555 { | |
5556 #ifdef FEAT_GUI | |
5557 int startCol = col; | |
5558 #endif | |
5559 | |
5560 /* blank out the rest of the line */ | |
5561 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5562 && ScreenAttrs[off_to] == 0 | |
5563 #ifdef FEAT_MBYTE | |
5564 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5565 #endif | |
5566 ) | |
5567 { | |
5568 ++off_to; | |
5569 ++col; | |
5570 } | |
5571 if (col < clear_width) | |
5572 { | |
5573 #ifdef FEAT_GUI | |
5574 /* | |
5575 * In the GUI, clearing the rest of the line may leave pixels | |
5576 * behind if the first character cleared was bold. Some bold | |
5577 * fonts spill over the left. In this case we redraw the previous | |
5578 * character too. If we didn't skip any blanks above, then we | |
5579 * only redraw if the character wasn't already redrawn anyway. | |
5580 */ | |
996 | 5581 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5582 { |
5583 hl = ScreenAttrs[off_to]; | |
5584 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5585 { |
5586 int prev_cells = 1; | |
5587 # ifdef FEAT_MBYTE | |
5588 if (enc_utf8) | |
5589 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5590 * that its width is 2. */ | |
5591 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5592 else if (enc_dbcs != 0) | |
5593 { | |
5594 /* find previous character by counting from first | |
5595 * column and get its width. */ | |
5596 unsigned off = LineOffset[row]; | |
1378 | 5597 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5598 |
5599 while (off < off_to) | |
5600 { | |
1378 | 5601 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5602 off += prev_cells; |
5603 } | |
5604 } | |
5605 | |
5606 if (enc_dbcs != 0 && prev_cells > 1) | |
5607 screen_char_2(off_to - prev_cells, row, | |
5608 col + coloff - prev_cells); | |
5609 else | |
5610 # endif | |
5611 screen_char(off_to - prev_cells, row, | |
5612 col + coloff - prev_cells); | |
5613 } | |
7 | 5614 } |
5615 #endif | |
5616 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5617 ' ', ' ', 0); | |
5618 #ifdef FEAT_VERTSPLIT | |
5619 off_to += clear_width - col; | |
5620 col = clear_width; | |
5621 #endif | |
5622 } | |
5623 } | |
5624 | |
5625 if (clear_width > 0) | |
5626 { | |
5627 #ifdef FEAT_VERTSPLIT | |
5628 /* For a window that's left of another, draw the separator char. */ | |
5629 if (col + coloff < Columns) | |
5630 { | |
5631 int c; | |
5632 | |
5633 c = fillchar_vsep(&hl); | |
5634 if (ScreenLines[off_to] != c | |
5635 # ifdef FEAT_MBYTE | |
714 | 5636 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5637 != (c >= 0x80 ? c : 0)) | |
7 | 5638 # endif |
5639 || ScreenAttrs[off_to] != hl) | |
5640 { | |
5641 ScreenLines[off_to] = c; | |
5642 ScreenAttrs[off_to] = hl; | |
5643 # ifdef FEAT_MBYTE | |
5644 if (enc_utf8) | |
5645 { | |
5646 if (c >= 0x80) | |
5647 { | |
5648 ScreenLinesUC[off_to] = c; | |
714 | 5649 ScreenLinesC[0][off_to] = 0; |
7 | 5650 } |
5651 else | |
5652 ScreenLinesUC[off_to] = 0; | |
5653 } | |
5654 # endif | |
5655 screen_char(off_to, row, col + coloff); | |
5656 } | |
5657 } | |
5658 else | |
5659 #endif | |
5660 LineWraps[row] = FALSE; | |
5661 } | |
5662 } | |
5663 | |
474 | 5664 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5665 /* |
474 | 5666 * Mirror text "str" for right-left displaying. |
5667 * Only works for single-byte characters (e.g., numbers). | |
7 | 5668 */ |
474 | 5669 void |
7 | 5670 rl_mirror(str) |
5671 char_u *str; | |
5672 { | |
5673 char_u *p1, *p2; | |
5674 int t; | |
5675 | |
5676 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5677 { | |
5678 t = *p1; | |
5679 *p1 = *p2; | |
5680 *p2 = t; | |
5681 } | |
5682 } | |
5683 #endif | |
5684 | |
5685 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5686 /* | |
5687 * mark all status lines for redraw; used after first :cd | |
5688 */ | |
5689 void | |
5690 status_redraw_all() | |
5691 { | |
5692 win_T *wp; | |
5693 | |
5694 for (wp = firstwin; wp; wp = wp->w_next) | |
5695 if (wp->w_status_height) | |
5696 { | |
5697 wp->w_redr_status = TRUE; | |
5698 redraw_later(VALID); | |
5699 } | |
5700 } | |
5701 | |
5702 /* | |
5703 * mark all status lines of the current buffer for redraw | |
5704 */ | |
5705 void | |
5706 status_redraw_curbuf() | |
5707 { | |
5708 win_T *wp; | |
5709 | |
5710 for (wp = firstwin; wp; wp = wp->w_next) | |
5711 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5712 { | |
5713 wp->w_redr_status = TRUE; | |
5714 redraw_later(VALID); | |
5715 } | |
5716 } | |
5717 | |
5718 /* | |
5719 * Redraw all status lines that need to be redrawn. | |
5720 */ | |
5721 void | |
5722 redraw_statuslines() | |
5723 { | |
5724 win_T *wp; | |
5725 | |
5726 for (wp = firstwin; wp; wp = wp->w_next) | |
5727 if (wp->w_redr_status) | |
5728 win_redr_status(wp); | |
673 | 5729 if (redraw_tabline) |
677 | 5730 draw_tabline(); |
7 | 5731 } |
5732 #endif | |
5733 | |
5734 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5735 /* | |
5736 * Redraw all status lines at the bottom of frame "frp". | |
5737 */ | |
5738 void | |
5739 win_redraw_last_status(frp) | |
5740 frame_T *frp; | |
5741 { | |
5742 if (frp->fr_layout == FR_LEAF) | |
5743 frp->fr_win->w_redr_status = TRUE; | |
5744 else if (frp->fr_layout == FR_ROW) | |
5745 { | |
5746 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5747 win_redraw_last_status(frp); | |
5748 } | |
5749 else /* frp->fr_layout == FR_COL */ | |
5750 { | |
5751 frp = frp->fr_child; | |
5752 while (frp->fr_next != NULL) | |
5753 frp = frp->fr_next; | |
5754 win_redraw_last_status(frp); | |
5755 } | |
5756 } | |
5757 #endif | |
5758 | |
5759 #ifdef FEAT_VERTSPLIT | |
5760 /* | |
5761 * Draw the verticap separator right of window "wp" starting with line "row". | |
5762 */ | |
5763 static void | |
5764 draw_vsep_win(wp, row) | |
5765 win_T *wp; | |
5766 int row; | |
5767 { | |
5768 int hl; | |
5769 int c; | |
5770 | |
5771 if (wp->w_vsep_width) | |
5772 { | |
5773 /* draw the vertical separator right of this window */ | |
5774 c = fillchar_vsep(&hl); | |
5775 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5776 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5777 c, ' ', hl); | |
5778 } | |
5779 } | |
5780 #endif | |
5781 | |
5782 #ifdef FEAT_WILDMENU | |
5783 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5784 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5785 |
5786 /* | |
1378 | 5787 * Get the length of an item as it will be shown in the status line. |
7 | 5788 */ |
5789 static int | |
5790 status_match_len(xp, s) | |
5791 expand_T *xp; | |
5792 char_u *s; | |
5793 { | |
5794 int len = 0; | |
5795 | |
5796 #ifdef FEAT_MENU | |
5797 int emenu = (xp->xp_context == EXPAND_MENUS | |
5798 || xp->xp_context == EXPAND_MENUNAMES); | |
5799 | |
5800 /* Check for menu separators - replace with '|'. */ | |
5801 if (emenu && menu_is_separator(s)) | |
5802 return 1; | |
5803 #endif | |
5804 | |
5805 while (*s != NUL) | |
5806 { | |
1685 | 5807 s += skip_status_match_char(xp, s); |
42 | 5808 len += ptr2cells(s); |
39 | 5809 mb_ptr_adv(s); |
7 | 5810 } |
5811 | |
5812 return len; | |
5813 } | |
5814 | |
5815 /* | |
1685 | 5816 * Return the number of characters that should be skipped in a status match. |
277 | 5817 * These are backslashes used for escaping. Do show backslashes in help tags. |
5818 */ | |
5819 static int | |
5820 skip_status_match_char(xp, s) | |
5821 expand_T *xp; | |
5822 char_u *s; | |
5823 { | |
1685 | 5824 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5825 #ifdef FEAT_MENU |
5826 || ((xp->xp_context == EXPAND_MENUS | |
5827 || xp->xp_context == EXPAND_MENUNAMES) | |
5828 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5829 #endif | |
1685 | 5830 ) |
5831 { | |
5832 #ifndef BACKSLASH_IN_FILENAME | |
5833 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5834 return 2; | |
5835 #endif | |
5836 return 1; | |
5837 } | |
5838 return 0; | |
277 | 5839 } |
5840 | |
5841 /* | |
7 | 5842 * Show wildchar matches in the status line. |
5843 * Show at least the "match" item. | |
5844 * We start at item 'first_match' in the list and show all matches that fit. | |
5845 * | |
5846 * If inversion is possible we use it. Else '=' characters are used. | |
5847 */ | |
5848 void | |
5849 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5850 expand_T *xp; | |
5851 int num_matches; | |
5852 char_u **matches; /* list of matches */ | |
5853 int match; | |
5854 int showtail; | |
5855 { | |
5856 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5857 int row; | |
5858 char_u *buf; | |
5859 int len; | |
1378 | 5860 int clen; /* length in screen cells */ |
7 | 5861 int fillchar; |
5862 int attr; | |
5863 int i; | |
5864 int highlight = TRUE; | |
5865 char_u *selstart = NULL; | |
5866 int selstart_col = 0; | |
5867 char_u *selend = NULL; | |
5868 static int first_match = 0; | |
5869 int add_left = FALSE; | |
5870 char_u *s; | |
5871 #ifdef FEAT_MENU | |
5872 int emenu; | |
5873 #endif | |
5874 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5875 int l; | |
5876 #endif | |
5877 | |
5878 if (matches == NULL) /* interrupted completion? */ | |
5879 return; | |
5880 | |
39 | 5881 #ifdef FEAT_MBYTE |
5882 if (has_mbyte) | |
5883 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5884 else | |
5885 #endif | |
5886 buf = alloc((unsigned)Columns + 1); | |
7 | 5887 if (buf == NULL) |
5888 return; | |
5889 | |
5890 if (match == -1) /* don't show match but original text */ | |
5891 { | |
5892 match = 0; | |
5893 highlight = FALSE; | |
5894 } | |
5895 /* count 1 for the ending ">" */ | |
5896 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5897 if (match == 0) | |
5898 first_match = 0; | |
5899 else if (match < first_match) | |
5900 { | |
5901 /* jumping left, as far as we can go */ | |
5902 first_match = match; | |
5903 add_left = TRUE; | |
5904 } | |
5905 else | |
5906 { | |
5907 /* check if match fits on the screen */ | |
5908 for (i = first_match; i < match; ++i) | |
5909 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5910 if (first_match > 0) | |
5911 clen += 2; | |
5912 /* jumping right, put match at the left */ | |
5913 if ((long)clen > Columns) | |
5914 { | |
5915 first_match = match; | |
5916 /* if showing the last match, we can add some on the left */ | |
5917 clen = 2; | |
5918 for (i = match; i < num_matches; ++i) | |
5919 { | |
5920 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5921 if ((long)clen >= Columns) | |
5922 break; | |
5923 } | |
5924 if (i == num_matches) | |
5925 add_left = TRUE; | |
5926 } | |
5927 } | |
5928 if (add_left) | |
5929 while (first_match > 0) | |
5930 { | |
5931 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5932 if ((long)clen >= Columns) | |
5933 break; | |
5934 --first_match; | |
5935 } | |
5936 | |
5937 fillchar = fillchar_status(&attr, TRUE); | |
5938 | |
5939 if (first_match == 0) | |
5940 { | |
5941 *buf = NUL; | |
5942 len = 0; | |
5943 } | |
5944 else | |
5945 { | |
5946 STRCPY(buf, "< "); | |
5947 len = 2; | |
5948 } | |
5949 clen = len; | |
5950 | |
5951 i = first_match; | |
5952 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
5953 { | |
5954 if (i == match) | |
5955 { | |
5956 selstart = buf + len; | |
5957 selstart_col = clen; | |
5958 } | |
5959 | |
5960 s = L_MATCH(i); | |
5961 /* Check for menu separators - replace with '|' */ | |
5962 #ifdef FEAT_MENU | |
5963 emenu = (xp->xp_context == EXPAND_MENUS | |
5964 || xp->xp_context == EXPAND_MENUNAMES); | |
5965 if (emenu && menu_is_separator(s)) | |
5966 { | |
5967 STRCPY(buf + len, transchar('|')); | |
5968 l = (int)STRLEN(buf + len); | |
5969 len += l; | |
5970 clen += l; | |
5971 } | |
5972 else | |
5973 #endif | |
5974 for ( ; *s != NUL; ++s) | |
5975 { | |
1685 | 5976 s += skip_status_match_char(xp, s); |
7 | 5977 clen += ptr2cells(s); |
5978 #ifdef FEAT_MBYTE | |
474 | 5979 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 5980 { |
5981 STRNCPY(buf + len, s, l); | |
5982 s += l - 1; | |
5983 len += l; | |
5984 } | |
5985 else | |
5986 #endif | |
5987 { | |
5988 STRCPY(buf + len, transchar_byte(*s)); | |
5989 len += (int)STRLEN(buf + len); | |
5990 } | |
5991 } | |
5992 if (i == match) | |
5993 selend = buf + len; | |
5994 | |
5995 *(buf + len++) = ' '; | |
5996 *(buf + len++) = ' '; | |
5997 clen += 2; | |
5998 if (++i == num_matches) | |
5999 break; | |
6000 } | |
6001 | |
6002 if (i != num_matches) | |
6003 { | |
6004 *(buf + len++) = '>'; | |
6005 ++clen; | |
6006 } | |
6007 | |
6008 buf[len] = NUL; | |
6009 | |
6010 row = cmdline_row - 1; | |
6011 if (row >= 0) | |
6012 { | |
6013 if (wild_menu_showing == 0) | |
6014 { | |
6015 if (msg_scrolled > 0) | |
6016 { | |
6017 /* Put the wildmenu just above the command line. If there is | |
6018 * no room, scroll the screen one line up. */ | |
6019 if (cmdline_row == Rows - 1) | |
6020 { | |
6021 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6022 ++msg_scrolled; | |
6023 } | |
6024 else | |
6025 { | |
6026 ++cmdline_row; | |
6027 ++row; | |
6028 } | |
6029 wild_menu_showing = WM_SCROLLED; | |
6030 } | |
6031 else | |
6032 { | |
6033 /* Create status line if needed by setting 'laststatus' to 2. | |
6034 * Set 'winminheight' to zero to avoid that the window is | |
6035 * resized. */ | |
6036 if (lastwin->w_status_height == 0) | |
6037 { | |
6038 save_p_ls = p_ls; | |
6039 save_p_wmh = p_wmh; | |
6040 p_ls = 2; | |
6041 p_wmh = 0; | |
6042 last_status(FALSE); | |
6043 } | |
6044 wild_menu_showing = WM_SHOWN; | |
6045 } | |
6046 } | |
6047 | |
6048 screen_puts(buf, row, 0, attr); | |
6049 if (selstart != NULL && highlight) | |
6050 { | |
6051 *selend = NUL; | |
6052 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6053 } | |
6054 | |
6055 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6056 } | |
6057 | |
6058 #ifdef FEAT_VERTSPLIT | |
6059 win_redraw_last_status(topframe); | |
6060 #else | |
6061 lastwin->w_redr_status = TRUE; | |
6062 #endif | |
6063 vim_free(buf); | |
6064 } | |
6065 #endif | |
6066 | |
6067 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6068 /* | |
6069 * Redraw the status line of window wp. | |
6070 * | |
6071 * If inversion is possible we use it. Else '=' characters are used. | |
6072 */ | |
6073 void | |
6074 win_redr_status(wp) | |
6075 win_T *wp; | |
6076 { | |
6077 int row; | |
6078 char_u *p; | |
6079 int len; | |
6080 int fillchar; | |
6081 int attr; | |
6082 int this_ru_col; | |
1910 | 6083 static int busy = FALSE; |
6084 | |
6085 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6086 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6087 if (busy) | |
6088 return; | |
6089 busy = TRUE; | |
7 | 6090 |
6091 wp->w_redr_status = FALSE; | |
6092 if (wp->w_status_height == 0) | |
6093 { | |
6094 /* no status line, can only be last window */ | |
6095 redraw_cmdline = TRUE; | |
6096 } | |
540 | 6097 else if (!redrawing() |
6098 #ifdef FEAT_INS_EXPAND | |
6099 /* don't update status line when popup menu is visible and may be | |
6100 * drawn over it */ | |
6101 || pum_visible() | |
6102 #endif | |
6103 ) | |
7 | 6104 { |
6105 /* Don't redraw right now, do it later. */ | |
6106 wp->w_redr_status = TRUE; | |
6107 } | |
6108 #ifdef FEAT_STL_OPT | |
40 | 6109 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6110 { |
6111 /* redraw custom status line */ | |
1983 | 6112 redraw_custom_statusline(wp); |
7 | 6113 } |
6114 #endif | |
6115 else | |
6116 { | |
6117 fillchar = fillchar_status(&attr, wp == curwin); | |
6118 | |
685 | 6119 get_trans_bufname(wp->w_buffer); |
7 | 6120 p = NameBuff; |
6121 len = (int)STRLEN(p); | |
6122 | |
6123 if (wp->w_buffer->b_help | |
6124 #ifdef FEAT_QUICKFIX | |
6125 || wp->w_p_pvw | |
6126 #endif | |
6127 || bufIsChanged(wp->w_buffer) | |
6128 || wp->w_buffer->b_p_ro) | |
6129 *(p + len++) = ' '; | |
6130 if (wp->w_buffer->b_help) | |
6131 { | |
809 | 6132 STRCPY(p + len, _("[Help]")); |
7 | 6133 len += (int)STRLEN(p + len); |
6134 } | |
6135 #ifdef FEAT_QUICKFIX | |
6136 if (wp->w_p_pvw) | |
6137 { | |
6138 STRCPY(p + len, _("[Preview]")); | |
6139 len += (int)STRLEN(p + len); | |
6140 } | |
6141 #endif | |
6142 if (bufIsChanged(wp->w_buffer)) | |
6143 { | |
6144 STRCPY(p + len, "[+]"); | |
6145 len += 3; | |
6146 } | |
6147 if (wp->w_buffer->b_p_ro) | |
6148 { | |
6149 STRCPY(p + len, "[RO]"); | |
6150 len += 4; | |
6151 } | |
6152 | |
6153 #ifndef FEAT_VERTSPLIT | |
6154 this_ru_col = ru_col; | |
6155 if (this_ru_col < (Columns + 1) / 2) | |
6156 this_ru_col = (Columns + 1) / 2; | |
6157 #else | |
6158 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6159 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6160 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6161 if (this_ru_col <= 1) | |
6162 { | |
6163 p = (char_u *)"<"; /* No room for file name! */ | |
6164 len = 1; | |
6165 } | |
6166 else | |
6167 #endif | |
6168 #ifdef FEAT_MBYTE | |
6169 if (has_mbyte) | |
6170 { | |
6171 int clen = 0, i; | |
6172 | |
6173 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6174 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6175 |
7 | 6176 /* Find first character that will fit. |
6177 * Going from start to end is much faster for DBCS. */ | |
6178 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6179 i += (*mb_ptr2len)(p + i)) |
7 | 6180 clen -= (*mb_ptr2cells)(p + i); |
6181 len = clen; | |
6182 if (i > 0) | |
6183 { | |
6184 p = p + i - 1; | |
6185 *p = '<'; | |
6186 ++len; | |
6187 } | |
6188 | |
6189 } | |
6190 else | |
6191 #endif | |
6192 if (len > this_ru_col - 1) | |
6193 { | |
6194 p += len - (this_ru_col - 1); | |
6195 *p = '<'; | |
6196 len = this_ru_col - 1; | |
6197 } | |
6198 | |
6199 row = W_WINROW(wp) + wp->w_height; | |
6200 screen_puts(p, row, W_WINCOL(wp), attr); | |
6201 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6202 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6203 | |
6204 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6205 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6206 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6207 - 1 + W_WINCOL(wp)), attr); | |
6208 | |
6209 #ifdef FEAT_CMDL_INFO | |
6210 win_redr_ruler(wp, TRUE); | |
6211 #endif | |
6212 } | |
6213 | |
6214 #ifdef FEAT_VERTSPLIT | |
6215 /* | |
6216 * May need to draw the character below the vertical separator. | |
6217 */ | |
6218 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6219 { | |
6220 if (stl_connected(wp)) | |
6221 fillchar = fillchar_status(&attr, wp == curwin); | |
6222 else | |
6223 fillchar = fillchar_vsep(&attr); | |
6224 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6225 attr); | |
6226 } | |
6227 #endif | |
1910 | 6228 busy = FALSE; |
7 | 6229 } |
6230 | |
680 | 6231 #ifdef FEAT_STL_OPT |
6232 /* | |
6233 * Redraw the status line according to 'statusline' and take care of any | |
6234 * errors encountered. | |
6235 */ | |
6236 static void | |
1983 | 6237 redraw_custom_statusline(wp) |
680 | 6238 win_T *wp; |
6239 { | |
1983 | 6240 static int entered = FALSE; |
6241 int save_called_emsg = called_emsg; | |
6242 | |
6243 /* When called recursively return. This can happen when the statusline | |
6244 * contains an expression that triggers a redraw. */ | |
6245 if (entered) | |
6246 return; | |
6247 entered = TRUE; | |
680 | 6248 |
6249 called_emsg = FALSE; | |
6250 win_redr_custom(wp, FALSE); | |
6251 if (called_emsg) | |
1983 | 6252 { |
6253 /* When there is an error disable the statusline, otherwise the | |
6254 * display is messed up with errors and a redraw triggers the problem | |
6255 * again and again. */ | |
680 | 6256 set_string_option_direct((char_u *)"statusline", -1, |
6257 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6258 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6259 } |
680 | 6260 called_emsg |= save_called_emsg; |
1983 | 6261 entered = FALSE; |
680 | 6262 } |
6263 #endif | |
6264 | |
7 | 6265 # ifdef FEAT_VERTSPLIT |
6266 /* | |
6267 * Return TRUE if the status line of window "wp" is connected to the status | |
6268 * line of the window right of it. If not, then it's a vertical separator. | |
6269 * Only call if (wp->w_vsep_width != 0). | |
6270 */ | |
6271 int | |
6272 stl_connected(wp) | |
6273 win_T *wp; | |
6274 { | |
6275 frame_T *fr; | |
6276 | |
6277 fr = wp->w_frame; | |
6278 while (fr->fr_parent != NULL) | |
6279 { | |
6280 if (fr->fr_parent->fr_layout == FR_COL) | |
6281 { | |
6282 if (fr->fr_next != NULL) | |
6283 break; | |
6284 } | |
6285 else | |
6286 { | |
6287 if (fr->fr_next != NULL) | |
6288 return TRUE; | |
6289 } | |
6290 fr = fr->fr_parent; | |
6291 } | |
6292 return FALSE; | |
6293 } | |
6294 # endif | |
6295 | |
6296 #endif /* FEAT_WINDOWS */ | |
6297 | |
6298 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6299 /* | |
6300 * Get the value to show for the language mappings, active 'keymap'. | |
6301 */ | |
6302 int | |
6303 get_keymap_str(wp, buf, len) | |
6304 win_T *wp; | |
6305 char_u *buf; /* buffer for the result */ | |
6306 int len; /* length of buffer */ | |
6307 { | |
6308 char_u *p; | |
6309 | |
6310 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6311 return FALSE; | |
6312 | |
6313 { | |
6314 #ifdef FEAT_EVAL | |
6315 buf_T *old_curbuf = curbuf; | |
6316 win_T *old_curwin = curwin; | |
6317 char_u *s; | |
6318 | |
6319 curbuf = wp->w_buffer; | |
6320 curwin = wp; | |
6321 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6322 ++emsg_skip; | |
714 | 6323 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6324 --emsg_skip; |
6325 curbuf = old_curbuf; | |
6326 curwin = old_curwin; | |
6327 if (p == NULL || *p == NUL) | |
6328 #endif | |
6329 { | |
6330 #ifdef FEAT_KEYMAP | |
6331 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6332 p = wp->w_buffer->b_p_keymap; | |
6333 else | |
6334 #endif | |
6335 p = (char_u *)"lang"; | |
6336 } | |
6337 if ((int)(STRLEN(p) + 3) < len) | |
6338 sprintf((char *)buf, "<%s>", p); | |
6339 else | |
6340 buf[0] = NUL; | |
6341 #ifdef FEAT_EVAL | |
6342 vim_free(s); | |
6343 #endif | |
6344 } | |
6345 return buf[0] != NUL; | |
6346 } | |
6347 #endif | |
6348 | |
6349 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6350 /* | |
677 | 6351 * Redraw the status line or ruler of window "wp". |
6352 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6353 */ |
6354 static void | |
574 | 6355 win_redr_custom(wp, draw_ruler) |
7 | 6356 win_T *wp; |
574 | 6357 int draw_ruler; /* TRUE or FALSE */ |
7 | 6358 { |
6359 int attr; | |
6360 int curattr; | |
6361 int row; | |
6362 int col = 0; | |
6363 int maxwidth; | |
6364 int width; | |
6365 int n; | |
6366 int len; | |
6367 int fillchar; | |
6368 char_u buf[MAXPATHL]; | |
1983 | 6369 char_u *stl; |
7 | 6370 char_u *p; |
681 | 6371 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6372 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6373 int use_sandbox = FALSE; |
7 | 6374 |
6375 /* setup environment for the task at hand */ | |
677 | 6376 if (wp == NULL) |
6377 { | |
6378 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6379 stl = p_tal; |
677 | 6380 row = 0; |
707 | 6381 fillchar = ' '; |
677 | 6382 attr = hl_attr(HLF_TPF); |
6383 maxwidth = Columns; | |
6384 # ifdef FEAT_EVAL | |
681 | 6385 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6386 # endif |
6387 } | |
40 | 6388 else |
677 | 6389 { |
6390 row = W_WINROW(wp) + wp->w_height; | |
6391 fillchar = fillchar_status(&attr, wp == curwin); | |
6392 maxwidth = W_WIDTH(wp); | |
6393 | |
6394 if (draw_ruler) | |
6395 { | |
1983 | 6396 stl = p_ruf; |
677 | 6397 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6398 if (*stl == '%') |
6399 { | |
6400 if (*++stl == '-') | |
6401 stl++; | |
6402 if (atoi((char *)stl)) | |
6403 while (VIM_ISDIGIT(*stl)) | |
6404 stl++; | |
6405 if (*stl++ != '(') | |
6406 stl = p_ruf; | |
677 | 6407 } |
7 | 6408 #ifdef FEAT_VERTSPLIT |
677 | 6409 col = ru_col - (Columns - W_WIDTH(wp)); |
6410 if (col < (W_WIDTH(wp) + 1) / 2) | |
6411 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6412 #else |
677 | 6413 col = ru_col; |
6414 if (col > (Columns + 1) / 2) | |
6415 col = (Columns + 1) / 2; | |
6416 #endif | |
6417 maxwidth = W_WIDTH(wp) - col; | |
7 | 6418 #ifdef FEAT_WINDOWS |
677 | 6419 if (!wp->w_status_height) |
6420 #endif | |
6421 { | |
6422 row = Rows - 1; | |
6423 --maxwidth; /* writing in last column may cause scrolling */ | |
6424 fillchar = ' '; | |
6425 attr = 0; | |
6426 } | |
6427 | |
6428 # ifdef FEAT_EVAL | |
681 | 6429 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6430 # endif |
6431 } | |
6432 else | |
6433 { | |
6434 if (*wp->w_p_stl != NUL) | |
1983 | 6435 stl = wp->w_p_stl; |
677 | 6436 else |
1983 | 6437 stl = p_stl; |
677 | 6438 # ifdef FEAT_EVAL |
681 | 6439 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6440 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6441 # endif |
6442 } | |
6443 | |
6444 #ifdef FEAT_VERTSPLIT | |
6445 col += W_WINCOL(wp); | |
6446 #endif | |
6447 } | |
6448 | |
7 | 6449 if (maxwidth <= 0) |
6450 return; | |
677 | 6451 |
1983 | 6452 /* Make a copy, because the statusline may include a function call that |
6453 * might change the option value and free the memory. */ | |
6454 stl = vim_strsave(stl); | |
677 | 6455 width = build_stl_str_hl(wp == NULL ? curwin : wp, |
6456 buf, sizeof(buf), | |
1983 | 6457 stl, use_sandbox, |
681 | 6458 fillchar, maxwidth, hltab, tabtab); |
1983 | 6459 vim_free(stl); |
835 | 6460 len = (int)STRLEN(buf); |
7 | 6461 |
1883 | 6462 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6463 { |
6464 #ifdef FEAT_MBYTE | |
6465 len += (*mb_char2bytes)(fillchar, buf + len); | |
6466 #else | |
6467 buf[len++] = fillchar; | |
6468 #endif | |
6469 ++width; | |
6470 } | |
6471 buf[len] = NUL; | |
6472 | |
681 | 6473 /* |
6474 * Draw each snippet with the specified highlighting. | |
6475 */ | |
7 | 6476 curattr = attr; |
6477 p = buf; | |
681 | 6478 for (n = 0; hltab[n].start != NULL; n++) |
6479 { | |
6480 len = (int)(hltab[n].start - p); | |
7 | 6481 screen_puts_len(p, len, row, col, curattr); |
6482 col += vim_strnsize(p, len); | |
681 | 6483 p = hltab[n].start; |
6484 | |
6485 if (hltab[n].userhl == 0) | |
7 | 6486 curattr = attr; |
681 | 6487 else if (hltab[n].userhl < 0) |
6488 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6489 #ifdef FEAT_WINDOWS |
680 | 6490 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6491 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6492 #endif |
6493 else | |
681 | 6494 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6495 } |
6496 screen_puts(p, row, col, curattr); | |
681 | 6497 |
6498 if (wp == NULL) | |
6499 { | |
6500 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6501 col = 0; | |
6502 len = 0; | |
6503 p = buf; | |
6504 fillchar = 0; | |
6505 for (n = 0; tabtab[n].start != NULL; n++) | |
6506 { | |
6507 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6508 while (col < len) | |
6509 TabPageIdxs[col++] = fillchar; | |
6510 p = tabtab[n].start; | |
6511 fillchar = tabtab[n].userhl; | |
6512 } | |
6513 while (col < Columns) | |
6514 TabPageIdxs[col++] = fillchar; | |
6515 } | |
7 | 6516 } |
6517 | |
6518 #endif /* FEAT_STL_OPT */ | |
6519 | |
6520 /* | |
6521 * Output a single character directly to the screen and update ScreenLines. | |
6522 */ | |
6523 void | |
6524 screen_putchar(c, row, col, attr) | |
6525 int c; | |
6526 int row, col; | |
6527 int attr; | |
6528 { | |
6529 #ifdef FEAT_MBYTE | |
6530 char_u buf[MB_MAXBYTES + 1]; | |
6531 | |
6532 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6533 #else | |
6534 char_u buf[2]; | |
6535 | |
6536 buf[0] = c; | |
6537 buf[1] = NUL; | |
6538 #endif | |
6539 screen_puts(buf, row, col, attr); | |
6540 } | |
6541 | |
6542 /* | |
6543 * Get a single character directly from ScreenLines into "bytes[]". | |
6544 * Also return its attribute in *attrp; | |
6545 */ | |
6546 void | |
6547 screen_getbytes(row, col, bytes, attrp) | |
6548 int row, col; | |
6549 char_u *bytes; | |
6550 int *attrp; | |
6551 { | |
6552 unsigned off; | |
6553 | |
6554 /* safety check */ | |
6555 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6556 { | |
6557 off = LineOffset[row] + col; | |
6558 *attrp = ScreenAttrs[off]; | |
6559 bytes[0] = ScreenLines[off]; | |
6560 bytes[1] = NUL; | |
6561 | |
6562 #ifdef FEAT_MBYTE | |
6563 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6564 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6565 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6566 { | |
6567 bytes[0] = ScreenLines[off]; | |
6568 bytes[1] = ScreenLines2[off]; | |
6569 bytes[2] = NUL; | |
6570 } | |
6571 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6572 { | |
6573 bytes[1] = ScreenLines[off + 1]; | |
6574 bytes[2] = NUL; | |
6575 } | |
6576 #endif | |
6577 } | |
6578 } | |
6579 | |
714 | 6580 #ifdef FEAT_MBYTE |
6581 static int screen_comp_differs __ARGS((int, int*)); | |
6582 | |
6583 /* | |
6584 * Return TRUE if composing characters for screen posn "off" differs from | |
6585 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6586 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6587 */ |
6588 static int | |
6589 screen_comp_differs(off, u8cc) | |
6590 int off; | |
6591 int *u8cc; | |
6592 { | |
6593 int i; | |
6594 | |
6595 for (i = 0; i < Screen_mco; ++i) | |
6596 { | |
6597 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6598 return TRUE; | |
6599 if (u8cc[i] == 0) | |
6600 break; | |
6601 } | |
6602 return FALSE; | |
6603 } | |
6604 #endif | |
6605 | |
7 | 6606 /* |
6607 * Put string '*text' on the screen at position 'row' and 'col', with | |
6608 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6609 * Note: only outputs within one row, message is truncated at screen boundary! | |
6610 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6611 */ | |
6612 void | |
6613 screen_puts(text, row, col, attr) | |
6614 char_u *text; | |
6615 int row; | |
6616 int col; | |
6617 int attr; | |
6618 { | |
6619 screen_puts_len(text, -1, row, col, attr); | |
6620 } | |
6621 | |
6622 /* | |
6623 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6624 * a NUL. | |
6625 */ | |
6626 void | |
6627 screen_puts_len(text, len, row, col, attr) | |
6628 char_u *text; | |
6629 int len; | |
6630 int row; | |
6631 int col; | |
6632 int attr; | |
6633 { | |
6634 unsigned off; | |
6635 char_u *ptr = text; | |
6636 int c; | |
6637 #ifdef FEAT_MBYTE | |
1378 | 6638 unsigned max_off; |
7 | 6639 int mbyte_blen = 1; |
6640 int mbyte_cells = 1; | |
6641 int u8c = 0; | |
714 | 6642 int u8cc[MAX_MCO]; |
7 | 6643 int clear_next_cell = FALSE; |
6644 # ifdef FEAT_ARABIC | |
6645 int prev_c = 0; /* previous Arabic character */ | |
714 | 6646 int pc, nc, nc1; |
6647 int pcc[MAX_MCO]; | |
7 | 6648 # endif |
6649 #endif | |
1843 | 6650 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6651 int force_redraw_this; | |
6652 int force_redraw_next = FALSE; | |
6653 #endif | |
6654 int need_redraw; | |
7 | 6655 |
6656 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6657 return; | |
1843 | 6658 off = LineOffset[row] + col; |
7 | 6659 |
1668 | 6660 #ifdef FEAT_MBYTE |
6661 /* When drawing over the right halve of a double-wide char clear out the | |
6662 * left halve. Only needed in a terminal. */ | |
1685 | 6663 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6664 # ifdef FEAT_GUI |
6665 && !gui.in_use | |
6666 # endif | |
6667 && mb_fix_col(col, row) != col) | |
1843 | 6668 { |
6669 ScreenLines[off - 1] = ' '; | |
6670 ScreenAttrs[off - 1] = 0; | |
6671 if (enc_utf8) | |
6672 { | |
6673 ScreenLinesUC[off - 1] = 0; | |
6674 ScreenLinesC[0][off - 1] = 0; | |
6675 } | |
6676 /* redraw the previous cell, make it empty */ | |
6677 screen_char(off - 1, row, col - 1); | |
6678 /* force the cell at "col" to be redrawn */ | |
6679 force_redraw_next = TRUE; | |
6680 } | |
6681 #endif | |
6682 | |
1378 | 6683 #ifdef FEAT_MBYTE |
6684 max_off = LineOffset[row] + screen_Columns; | |
6685 #endif | |
1340 | 6686 while (col < screen_Columns |
6687 && (len < 0 || (int)(ptr - text) < len) | |
6688 && *ptr != NUL) | |
7 | 6689 { |
6690 c = *ptr; | |
6691 #ifdef FEAT_MBYTE | |
6692 /* check if this is the first byte of a multibyte */ | |
6693 if (has_mbyte) | |
6694 { | |
6695 if (enc_utf8 && len > 0) | |
474 | 6696 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6697 else |
474 | 6698 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6699 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6700 mbyte_cells = 1; | |
6701 else if (enc_dbcs != 0) | |
6702 mbyte_cells = mbyte_blen; | |
6703 else /* enc_utf8 */ | |
6704 { | |
6705 if (len >= 0) | |
714 | 6706 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6707 (int)((text + len) - ptr)); |
6708 else | |
714 | 6709 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6710 mbyte_cells = utf_char2cells(u8c); |
1401 | 6711 # ifdef UNICODE16 |
7 | 6712 /* Non-BMP character: display as ? or fullwidth ?. */ |
6713 if (u8c >= 0x10000) | |
6714 { | |
6715 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6716 if (attr == 0) | |
6717 attr = hl_attr(HLF_8); | |
6718 } | |
1401 | 6719 # endif |
7 | 6720 # ifdef FEAT_ARABIC |
6721 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6722 { | |
6723 /* Do Arabic shaping. */ | |
6724 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6725 { | |
6726 /* Past end of string to be displayed. */ | |
6727 nc = NUL; | |
6728 nc1 = NUL; | |
6729 } | |
6730 else | |
714 | 6731 { |
1994 | 6732 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6733 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6734 nc1 = pcc[0]; |
6735 } | |
7 | 6736 pc = prev_c; |
6737 prev_c = u8c; | |
714 | 6738 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6739 } |
6740 else | |
6741 prev_c = u8c; | |
6742 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6743 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6744 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6745 /* 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
|
6746 * 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
|
6747 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6748 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6749 } |
7 | 6750 } |
6751 } | |
6752 #endif | |
6753 | |
1843 | 6754 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6755 force_redraw_this = force_redraw_next; | |
6756 force_redraw_next = FALSE; | |
6757 #endif | |
6758 | |
6759 need_redraw = ScreenLines[off] != c | |
7 | 6760 #ifdef FEAT_MBYTE |
6761 || (mbyte_cells == 2 | |
6762 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6763 || (enc_dbcs == DBCS_JPNU | |
6764 && c == 0x8e | |
6765 && ScreenLines2[off] != ptr[1]) | |
6766 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6767 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6768 (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
|
6769 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6770 && screen_comp_differs(off, u8cc)))) |
7 | 6771 #endif |
6772 || ScreenAttrs[off] != attr | |
1843 | 6773 || exmode_active; |
6774 | |
6775 if (need_redraw | |
6776 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6777 || force_redraw_this | |
6778 #endif | |
7 | 6779 ) |
6780 { | |
6781 #if defined(FEAT_GUI) || defined(UNIX) | |
6782 /* The bold trick makes a single row of pixels appear in the next | |
6783 * character. When a bold character is removed, the next | |
6784 * character should be redrawn too. This happens for our own GUI | |
1843 | 6785 * and for some xterms. */ |
6786 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6787 # ifdef FEAT_GUI |
6788 gui.in_use | |
6789 # endif | |
6790 # if defined(FEAT_GUI) && defined(UNIX) | |
6791 || | |
6792 # endif | |
6793 # ifdef UNIX | |
6794 term_is_xterm | |
6795 # endif | |
1843 | 6796 )) |
6797 { | |
6798 int n = ScreenAttrs[off]; | |
6799 | |
6800 if (n > HL_ALL) | |
6801 n = syn_attr2attr(n); | |
6802 if (n & HL_BOLD) | |
6803 force_redraw_next = TRUE; | |
7 | 6804 } |
6805 #endif | |
6806 #ifdef FEAT_MBYTE | |
6807 /* When at the end of the text and overwriting a two-cell | |
6808 * character with a one-cell character, need to clear the next | |
6809 * cell. Also when overwriting the left halve of a two-cell char | |
6810 * with the right halve of a two-cell char. Do this only once | |
6811 * (mb_off2cells() may return 2 on the right halve). */ | |
6812 if (clear_next_cell) | |
6813 clear_next_cell = FALSE; | |
6814 else if (has_mbyte | |
6815 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6816 : ptr + mbyte_blen >= text + len) | |
1378 | 6817 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6818 || (mbyte_cells == 2 |
1378 | 6819 && (*mb_off2cells)(off, max_off) == 1 |
6820 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6821 clear_next_cell = TRUE; |
6822 | |
6823 /* Make sure we never leave a second byte of a double-byte behind, | |
6824 * it confuses mb_off2cells(). */ | |
6825 if (enc_dbcs | |
1378 | 6826 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6827 || (mbyte_cells == 2 |
1378 | 6828 && (*mb_off2cells)(off, max_off) == 1 |
6829 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6830 ScreenLines[off + mbyte_blen] = 0; |
6831 #endif | |
6832 ScreenLines[off] = c; | |
6833 ScreenAttrs[off] = attr; | |
6834 #ifdef FEAT_MBYTE | |
6835 if (enc_utf8) | |
6836 { | |
714 | 6837 if (c < 0x80 && u8cc[0] == 0) |
7 | 6838 ScreenLinesUC[off] = 0; |
6839 else | |
6840 { | |
714 | 6841 int i; |
6842 | |
7 | 6843 ScreenLinesUC[off] = u8c; |
714 | 6844 for (i = 0; i < Screen_mco; ++i) |
6845 { | |
6846 ScreenLinesC[i][off] = u8cc[i]; | |
6847 if (u8cc[i] == 0) | |
6848 break; | |
6849 } | |
7 | 6850 } |
6851 if (mbyte_cells == 2) | |
6852 { | |
6853 ScreenLines[off + 1] = 0; | |
6854 ScreenAttrs[off + 1] = attr; | |
6855 } | |
6856 screen_char(off, row, col); | |
6857 } | |
6858 else if (mbyte_cells == 2) | |
6859 { | |
6860 ScreenLines[off + 1] = ptr[1]; | |
6861 ScreenAttrs[off + 1] = attr; | |
6862 screen_char_2(off, row, col); | |
6863 } | |
6864 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6865 { | |
6866 ScreenLines2[off] = ptr[1]; | |
6867 screen_char(off, row, col); | |
6868 } | |
6869 else | |
6870 #endif | |
6871 screen_char(off, row, col); | |
6872 } | |
6873 #ifdef FEAT_MBYTE | |
6874 if (has_mbyte) | |
6875 { | |
6876 off += mbyte_cells; | |
6877 col += mbyte_cells; | |
6878 ptr += mbyte_blen; | |
6879 if (clear_next_cell) | |
6880 ptr = (char_u *)" "; | |
6881 } | |
6882 else | |
6883 #endif | |
6884 { | |
6885 ++off; | |
6886 ++col; | |
6887 ++ptr; | |
6888 } | |
6889 } | |
1843 | 6890 |
6891 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6892 /* If we detected the next character needs to be redrawn, but the text | |
6893 * doesn't extend up to there, update the character here. */ | |
6894 if (force_redraw_next && col < screen_Columns) | |
6895 { | |
6896 # ifdef FEAT_MBYTE | |
6897 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6898 screen_char_2(off, row, col); | |
6899 else | |
6900 # endif | |
6901 screen_char(off, row, col); | |
6902 } | |
6903 #endif | |
7 | 6904 } |
6905 | |
6906 #ifdef FEAT_SEARCH_EXTRA | |
6907 /* | |
1326 | 6908 * Prepare for 'hlsearch' highlighting. |
7 | 6909 */ |
6910 static void | |
6911 start_search_hl() | |
6912 { | |
6913 if (p_hls && !no_hlsearch) | |
6914 { | |
6915 last_pat_prog(&search_hl.rm); | |
6916 search_hl.attr = hl_attr(HLF_L); | |
1521 | 6917 # ifdef FEAT_RELTIME |
6918 /* Set the time limit to 'redrawtime'. */ | |
6919 profile_setlimit(p_rdt, &search_hl.tm); | |
6920 # endif | |
7 | 6921 } |
6922 } | |
6923 | |
6924 /* | |
1326 | 6925 * Clean up for 'hlsearch' highlighting. |
7 | 6926 */ |
6927 static void | |
6928 end_search_hl() | |
6929 { | |
6930 if (search_hl.rm.regprog != NULL) | |
6931 { | |
6932 vim_free(search_hl.rm.regprog); | |
6933 search_hl.rm.regprog = NULL; | |
6934 } | |
6935 } | |
6936 | |
6937 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6938 * 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
|
6939 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6940 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6941 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6942 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6943 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6944 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6945 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6946 /* 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
|
6947 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6948 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6949 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6950 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6951 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6952 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6953 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6954 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6955 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
|
6956 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
|
6957 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6958 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6959 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6960 /* 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
|
6961 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
|
6962 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6963 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6964 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6965 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
|
6966 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6967 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6968 /* 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
|
6969 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6970 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6971 /* |
7 | 6972 * Advance to the match in window "wp" line "lnum" or past it. |
6973 */ | |
6974 static void | |
6975 prepare_search_hl(wp, lnum) | |
6976 win_T *wp; | |
6977 linenr_T lnum; | |
6978 { | |
1326 | 6979 matchitem_T *cur; /* points to the match list */ |
6980 match_T *shl; /* points to search_hl or a match */ | |
6981 int shl_flag; /* flag to indicate whether search_hl | |
6982 has been processed or not */ | |
7 | 6983 int n; |
6984 | |
6985 /* | |
6986 * When using a multi-line pattern, start searching at the top | |
6987 * of the window or just after a closed fold. | |
1326 | 6988 * Do this both for search_hl and the match list. |
7 | 6989 */ |
1326 | 6990 cur = wp->w_match_head; |
6991 shl_flag = FALSE; | |
6992 while (cur != NULL || shl_flag == FALSE) | |
6993 { | |
6994 if (shl_flag == FALSE) | |
6995 { | |
6996 shl = &search_hl; | |
6997 shl_flag = TRUE; | |
6998 } | |
6999 else | |
7000 shl = &cur->hl; | |
7 | 7001 if (shl->rm.regprog != NULL |
7002 && shl->lnum == 0 | |
7003 && re_multiline(shl->rm.regprog)) | |
7004 { | |
7005 if (shl->first_lnum == 0) | |
7006 { | |
7007 # ifdef FEAT_FOLDING | |
7008 for (shl->first_lnum = lnum; | |
7009 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7010 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7011 NULL, NULL, TRUE, NULL)) | |
7012 break; | |
7013 # else | |
7014 shl->first_lnum = wp->w_topline; | |
7015 # endif | |
7016 } | |
7017 n = 0; | |
7018 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7019 { | |
7020 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7021 if (shl->lnum != 0) | |
7022 { | |
7023 shl->first_lnum = shl->lnum | |
7024 + shl->rm.endpos[0].lnum | |
7025 - shl->rm.startpos[0].lnum; | |
7026 n = shl->rm.endpos[0].col; | |
7027 } | |
7028 else | |
7029 { | |
7030 ++shl->first_lnum; | |
7031 n = 0; | |
7032 } | |
7033 } | |
7034 } | |
1326 | 7035 if (shl != &search_hl && cur != NULL) |
7036 cur = cur->next; | |
7 | 7037 } |
7038 } | |
7039 | |
7040 /* | |
1326 | 7041 * Search for a next 'hlsearch' or match. |
7 | 7042 * Uses shl->buf. |
7043 * Sets shl->lnum and shl->rm contents. | |
7044 * Note: Assumes a previous match is always before "lnum", unless | |
7045 * shl->lnum is zero. | |
7046 * Careful: Any pointers for buffer lines will become invalid. | |
7047 */ | |
7048 static void | |
7049 next_search_hl(win, shl, lnum, mincol) | |
7050 win_T *win; | |
1326 | 7051 match_T *shl; /* points to search_hl or a match */ |
7 | 7052 linenr_T lnum; |
7053 colnr_T mincol; /* minimal column for a match */ | |
7054 { | |
7055 linenr_T l; | |
7056 colnr_T matchcol; | |
7057 long nmatched; | |
7058 | |
7059 if (shl->lnum != 0) | |
7060 { | |
7061 /* Check for three situations: | |
7062 * 1. If the "lnum" is below a previous match, start a new search. | |
7063 * 2. If the previous match includes "mincol", use it. | |
7064 * 3. Continue after the previous match. | |
7065 */ | |
7066 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7067 if (lnum > l) | |
7068 shl->lnum = 0; | |
7069 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7070 return; | |
7071 } | |
7072 | |
7073 /* | |
7074 * Repeat searching for a match until one is found that includes "mincol" | |
7075 * or none is found in this line. | |
7076 */ | |
7077 called_emsg = FALSE; | |
7078 for (;;) | |
7079 { | |
1521 | 7080 #ifdef FEAT_RELTIME |
7081 /* Stop searching after passing the time limit. */ | |
7082 if (profile_passed_limit(&(shl->tm))) | |
7083 { | |
7084 shl->lnum = 0; /* no match found in time */ | |
7085 break; | |
7086 } | |
7087 #endif | |
7 | 7088 /* Three situations: |
7089 * 1. No useful previous match: search from start of line. | |
7090 * 2. Not Vi compatible or empty match: continue at next character. | |
7091 * Break the loop if this is beyond the end of the line. | |
7092 * 3. Vi compatible searching: continue at end of previous match. | |
7093 */ | |
7094 if (shl->lnum == 0) | |
7095 matchcol = 0; | |
7096 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7097 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7098 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7099 { | |
688 | 7100 char_u *ml; |
685 | 7101 |
7102 matchcol = shl->rm.startpos[0].col; | |
688 | 7103 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7104 if (*ml == NUL) |
7105 { | |
7106 ++matchcol; | |
7 | 7107 shl->lnum = 0; |
7108 break; | |
7109 } | |
685 | 7110 #ifdef FEAT_MBYTE |
7111 if (has_mbyte) | |
7112 matchcol += mb_ptr2len(ml); | |
7113 else | |
7114 #endif | |
7115 ++matchcol; | |
7 | 7116 } |
7117 else | |
7118 matchcol = shl->rm.endpos[0].col; | |
7119 | |
7120 shl->lnum = lnum; | |
1521 | 7121 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7122 #ifdef FEAT_RELTIME | |
7123 &(shl->tm) | |
7124 #else | |
7125 NULL | |
7126 #endif | |
7127 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7128 if (called_emsg || got_int) |
7 | 7129 { |
7130 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7131 if (shl == &search_hl) |
7132 { | |
1326 | 7133 /* don't free regprog in the match list, it's a copy */ |
1112 | 7134 vim_free(shl->rm.regprog); |
7135 no_hlsearch = TRUE; | |
7136 } | |
7 | 7137 shl->rm.regprog = NULL; |
1112 | 7138 shl->lnum = 0; |
7139 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7140 break; |
7141 } | |
7142 if (nmatched == 0) | |
7143 { | |
7144 shl->lnum = 0; /* no match found */ | |
7145 break; | |
7146 } | |
7147 if (shl->rm.startpos[0].lnum > 0 | |
7148 || shl->rm.startpos[0].col >= mincol | |
7149 || nmatched > 1 | |
7150 || shl->rm.endpos[0].col > mincol) | |
7151 { | |
7152 shl->lnum += shl->rm.startpos[0].lnum; | |
7153 break; /* useful match found */ | |
7154 } | |
7155 } | |
7156 } | |
7157 #endif | |
7158 | |
7159 static void | |
7160 screen_start_highlight(attr) | |
7161 int attr; | |
7162 { | |
7163 attrentry_T *aep = NULL; | |
7164 | |
7165 screen_attr = attr; | |
7166 if (full_screen | |
7167 #ifdef WIN3264 | |
7168 && termcap_active | |
7169 #endif | |
7170 ) | |
7171 { | |
7172 #ifdef FEAT_GUI | |
7173 if (gui.in_use) | |
7174 { | |
7175 char buf[20]; | |
7176 | |
681 | 7177 /* The GUI handles this internally. */ |
7178 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7179 OUT_STR(buf); |
7180 } | |
7181 else | |
7182 #endif | |
7183 { | |
7184 if (attr > HL_ALL) /* special HL attr. */ | |
7185 { | |
7186 if (t_colors > 1) | |
7187 aep = syn_cterm_attr2entry(attr); | |
7188 else | |
7189 aep = syn_term_attr2entry(attr); | |
7190 if (aep == NULL) /* did ":syntax clear" */ | |
7191 attr = 0; | |
7192 else | |
7193 attr = aep->ae_attr; | |
7194 } | |
7195 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7196 out_str(T_MD); | |
681 | 7197 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7198 && cterm_normal_fg_bold) | |
7199 /* If the Normal FG color has BOLD attribute and the new HL | |
7200 * has a FG color defined, clear BOLD. */ | |
7201 out_str(T_ME); | |
7 | 7202 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7203 out_str(T_SO); | |
205 | 7204 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7205 /* underline or undercurl */ | |
7 | 7206 out_str(T_US); |
7207 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7208 out_str(T_CZH); | |
7209 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7210 out_str(T_MR); | |
7211 | |
7212 /* | |
7213 * Output the color or start string after bold etc., in case the | |
7214 * bold etc. override the color setting. | |
7215 */ | |
7216 if (aep != NULL) | |
7217 { | |
7218 if (t_colors > 1) | |
7219 { | |
7220 if (aep->ae_u.cterm.fg_color) | |
7221 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7222 if (aep->ae_u.cterm.bg_color) | |
7223 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7224 } | |
7225 else | |
7226 { | |
7227 if (aep->ae_u.term.start != NULL) | |
7228 out_str(aep->ae_u.term.start); | |
7229 } | |
7230 } | |
7231 } | |
7232 } | |
7233 } | |
7234 | |
7235 void | |
7236 screen_stop_highlight() | |
7237 { | |
7238 int do_ME = FALSE; /* output T_ME code */ | |
7239 | |
7240 if (screen_attr != 0 | |
7241 #ifdef WIN3264 | |
7242 && termcap_active | |
7243 #endif | |
7244 ) | |
7245 { | |
7246 #ifdef FEAT_GUI | |
7247 if (gui.in_use) | |
7248 { | |
7249 char buf[20]; | |
7250 | |
7251 /* use internal GUI code */ | |
7252 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7253 OUT_STR(buf); | |
7254 } | |
7255 else | |
7256 #endif | |
7257 { | |
7258 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7259 { | |
7260 attrentry_T *aep; | |
7261 | |
7262 if (t_colors > 1) | |
7263 { | |
7264 /* | |
7265 * Assume that t_me restores the original colors! | |
7266 */ | |
7267 aep = syn_cterm_attr2entry(screen_attr); | |
7268 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7269 || aep->ae_u.cterm.bg_color)) | |
7270 do_ME = TRUE; | |
7271 } | |
7272 else | |
7273 { | |
7274 aep = syn_term_attr2entry(screen_attr); | |
7275 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7276 { | |
7277 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7278 do_ME = TRUE; | |
7279 else | |
7280 out_str(aep->ae_u.term.stop); | |
7281 } | |
7282 } | |
7283 if (aep == NULL) /* did ":syntax clear" */ | |
7284 screen_attr = 0; | |
7285 else | |
7286 screen_attr = aep->ae_attr; | |
7287 } | |
7288 | |
7289 /* | |
7290 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7291 * same sequence several times. | |
7292 */ | |
7293 if (screen_attr & HL_STANDOUT) | |
7294 { | |
7295 if (STRCMP(T_SE, T_ME) == 0) | |
7296 do_ME = TRUE; | |
7297 else | |
7298 out_str(T_SE); | |
7299 } | |
205 | 7300 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7301 { |
7302 if (STRCMP(T_UE, T_ME) == 0) | |
7303 do_ME = TRUE; | |
7304 else | |
7305 out_str(T_UE); | |
7306 } | |
7307 if (screen_attr & HL_ITALIC) | |
7308 { | |
7309 if (STRCMP(T_CZR, T_ME) == 0) | |
7310 do_ME = TRUE; | |
7311 else | |
7312 out_str(T_CZR); | |
7313 } | |
7314 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7315 out_str(T_ME); | |
7316 | |
7317 if (t_colors > 1) | |
7318 { | |
7319 /* set Normal cterm colors */ | |
7320 if (cterm_normal_fg_color != 0) | |
7321 term_fg_color(cterm_normal_fg_color - 1); | |
7322 if (cterm_normal_bg_color != 0) | |
7323 term_bg_color(cterm_normal_bg_color - 1); | |
7324 if (cterm_normal_fg_bold) | |
7325 out_str(T_MD); | |
7326 } | |
7327 } | |
7328 } | |
7329 screen_attr = 0; | |
7330 } | |
7331 | |
7332 /* | |
7333 * Reset the colors for a cterm. Used when leaving Vim. | |
7334 * The machine specific code may override this again. | |
7335 */ | |
7336 void | |
7337 reset_cterm_colors() | |
7338 { | |
7339 if (t_colors > 1) | |
7340 { | |
7341 /* set Normal cterm colors */ | |
7342 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7343 { | |
7344 out_str(T_OP); | |
7345 screen_attr = -1; | |
7346 } | |
7347 if (cterm_normal_fg_bold) | |
7348 { | |
7349 out_str(T_ME); | |
7350 screen_attr = -1; | |
7351 } | |
7352 } | |
7353 } | |
7354 | |
7355 /* | |
7356 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7357 * using the attributes from ScreenAttrs["off"]. | |
7358 */ | |
7359 static void | |
7360 screen_char(off, row, col) | |
7361 unsigned off; | |
7362 int row; | |
7363 int col; | |
7364 { | |
7365 int attr; | |
7366 | |
7367 /* Check for illegal values, just in case (could happen just after | |
7368 * resizing). */ | |
7369 if (row >= screen_Rows || col >= screen_Columns) | |
7370 return; | |
7371 | |
7372 /* Outputting the last character on the screen may scrollup the screen. | |
7373 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7374 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7375 #ifdef FEAT_RIGHTLEFT | |
7376 /* account for first command-line character in rightleft mode */ | |
7377 && !cmdmsg_rl | |
7378 #endif | |
7379 ) | |
7380 { | |
7381 ScreenAttrs[off] = (sattr_T)-1; | |
7382 return; | |
7383 } | |
7384 | |
7385 /* | |
7386 * Stop highlighting first, so it's easier to move the cursor. | |
7387 */ | |
7388 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7389 if (screen_char_attr != 0) | |
7390 attr = screen_char_attr; | |
7391 else | |
7392 #endif | |
7393 attr = ScreenAttrs[off]; | |
7394 if (screen_attr != attr) | |
7395 screen_stop_highlight(); | |
7396 | |
7397 windgoto(row, col); | |
7398 | |
7399 if (screen_attr != attr) | |
7400 screen_start_highlight(attr); | |
7401 | |
7402 #ifdef FEAT_MBYTE | |
7403 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7404 { | |
7405 char_u buf[MB_MAXBYTES + 1]; | |
7406 | |
7407 /* Convert UTF-8 character to bytes and write it. */ | |
7408 | |
7409 buf[utfc_char2bytes(off, buf)] = NUL; | |
7410 | |
7411 out_str(buf); | |
7412 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7413 ++screen_cur_col; | |
7414 } | |
7415 else | |
7416 #endif | |
7417 { | |
7418 #ifdef FEAT_MBYTE | |
7419 out_flush_check(); | |
7420 #endif | |
7421 out_char(ScreenLines[off]); | |
7422 #ifdef FEAT_MBYTE | |
7423 /* double-byte character in single-width cell */ | |
7424 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7425 out_char(ScreenLines2[off]); | |
7426 #endif | |
7427 } | |
7428 | |
7429 screen_cur_col++; | |
7430 } | |
7431 | |
7432 #ifdef FEAT_MBYTE | |
7433 | |
7434 /* | |
7435 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7436 * on the screen at position 'row' and 'col'. | |
7437 * The attributes of the first byte is used for all. This is required to | |
7438 * output the two bytes of a double-byte character with nothing in between. | |
7439 */ | |
7440 static void | |
7441 screen_char_2(off, row, col) | |
7442 unsigned off; | |
7443 int row; | |
7444 int col; | |
7445 { | |
7446 /* Check for illegal values (could be wrong when screen was resized). */ | |
7447 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7448 return; | |
7449 | |
7450 /* Outputting the last character on the screen may scrollup the screen. | |
7451 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7452 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7453 { | |
7454 ScreenAttrs[off] = (sattr_T)-1; | |
7455 return; | |
7456 } | |
7457 | |
7458 /* Output the first byte normally (positions the cursor), then write the | |
7459 * second byte directly. */ | |
7460 screen_char(off, row, col); | |
7461 out_char(ScreenLines[off + 1]); | |
7462 ++screen_cur_col; | |
7463 } | |
7464 #endif | |
7465 | |
7466 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7467 /* | |
7468 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7469 * This uses the contents of ScreenLines[] and doesn't change it. | |
7470 */ | |
7471 void | |
7472 screen_draw_rectangle(row, col, height, width, invert) | |
7473 int row; | |
7474 int col; | |
7475 int height; | |
7476 int width; | |
7477 int invert; | |
7478 { | |
7479 int r, c; | |
7480 int off; | |
1378 | 7481 #ifdef FEAT_MBYTE |
7482 int max_off; | |
7483 #endif | |
7 | 7484 |
534 | 7485 /* Can't use ScreenLines unless initialized */ |
7486 if (ScreenLines == NULL) | |
7487 return; | |
7488 | |
7 | 7489 if (invert) |
7490 screen_char_attr = HL_INVERSE; | |
7491 for (r = row; r < row + height; ++r) | |
7492 { | |
7493 off = LineOffset[r]; | |
1378 | 7494 #ifdef FEAT_MBYTE |
7495 max_off = off + screen_Columns; | |
7496 #endif | |
7 | 7497 for (c = col; c < col + width; ++c) |
7498 { | |
7499 #ifdef FEAT_MBYTE | |
1378 | 7500 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7501 { |
7502 screen_char_2(off + c, r, c); | |
7503 ++c; | |
7504 } | |
7505 else | |
7506 #endif | |
7507 { | |
7508 screen_char(off + c, r, c); | |
7509 #ifdef FEAT_MBYTE | |
1378 | 7510 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7511 ++c; |
7512 #endif | |
7513 } | |
7514 } | |
7515 } | |
7516 screen_char_attr = 0; | |
7517 } | |
7518 #endif | |
7519 | |
7520 #ifdef FEAT_VERTSPLIT | |
7521 /* | |
7522 * Redraw the characters for a vertically split window. | |
7523 */ | |
7524 static void | |
7525 redraw_block(row, end, wp) | |
7526 int row; | |
7527 int end; | |
7528 win_T *wp; | |
7529 { | |
7530 int col; | |
7531 int width; | |
7532 | |
7533 # ifdef FEAT_CLIPBOARD | |
7534 clip_may_clear_selection(row, end - 1); | |
7535 # endif | |
7536 | |
7537 if (wp == NULL) | |
7538 { | |
7539 col = 0; | |
7540 width = Columns; | |
7541 } | |
7542 else | |
7543 { | |
7544 col = wp->w_wincol; | |
7545 width = wp->w_width; | |
7546 } | |
7547 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7548 } | |
7549 #endif | |
7550 | |
7551 /* | |
7552 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7553 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7554 * Use attributes 'attr'. | |
7555 */ | |
7556 void | |
7557 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7558 int start_row, end_row; | |
7559 int start_col, end_col; | |
7560 int c1, c2; | |
7561 int attr; | |
7562 { | |
7563 int row; | |
7564 int col; | |
7565 int off; | |
7566 int end_off; | |
7567 int did_delete; | |
7568 int c; | |
7569 int norm_term; | |
7570 #if defined(FEAT_GUI) || defined(UNIX) | |
7571 int force_next = FALSE; | |
7572 #endif | |
7573 | |
7574 if (end_row > screen_Rows) /* safety check */ | |
7575 end_row = screen_Rows; | |
7576 if (end_col > screen_Columns) /* safety check */ | |
7577 end_col = screen_Columns; | |
7578 if (ScreenLines == NULL | |
7579 || start_row >= end_row | |
7580 || start_col >= end_col) /* nothing to do */ | |
7581 return; | |
7582 | |
7583 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7584 norm_term = ( | |
7585 #ifdef FEAT_GUI | |
7586 !gui.in_use && | |
7587 #endif | |
7588 t_colors <= 1); | |
7589 for (row = start_row; row < end_row; ++row) | |
7590 { | |
1668 | 7591 #ifdef FEAT_MBYTE |
7592 if (has_mbyte | |
7593 # ifdef FEAT_GUI | |
7594 && !gui.in_use | |
7595 # endif | |
7596 ) | |
7597 { | |
7598 /* When drawing over the right halve of a double-wide char clear | |
7599 * out the left halve. When drawing over the left halve of a | |
7600 * double wide-char clear out the right halve. Only needed in a | |
7601 * terminal. */ | |
1685 | 7602 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7603 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7604 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7605 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7606 } |
7607 #endif | |
7 | 7608 /* |
7609 * Try to use delete-line termcap code, when no attributes or in a | |
7610 * "normal" terminal, where a bold/italic space is just a | |
7611 * space. | |
7612 */ | |
7613 did_delete = FALSE; | |
7614 if (c2 == ' ' | |
7615 && end_col == Columns | |
7616 && can_clear(T_CE) | |
7617 && (attr == 0 | |
7618 || (norm_term | |
7619 && attr <= HL_ALL | |
7620 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7621 { | |
7622 /* | |
7623 * check if we really need to clear something | |
7624 */ | |
7625 col = start_col; | |
7626 if (c1 != ' ') /* don't clear first char */ | |
7627 ++col; | |
7628 | |
7629 off = LineOffset[row] + col; | |
7630 end_off = LineOffset[row] + end_col; | |
7631 | |
7632 /* skip blanks (used often, keep it fast!) */ | |
7633 #ifdef FEAT_MBYTE | |
7634 if (enc_utf8) | |
7635 while (off < end_off && ScreenLines[off] == ' ' | |
7636 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7637 ++off; | |
7638 else | |
7639 #endif | |
7640 while (off < end_off && ScreenLines[off] == ' ' | |
7641 && ScreenAttrs[off] == 0) | |
7642 ++off; | |
7643 if (off < end_off) /* something to be cleared */ | |
7644 { | |
7645 col = off - LineOffset[row]; | |
7646 screen_stop_highlight(); | |
7647 term_windgoto(row, col);/* clear rest of this screen line */ | |
7648 out_str(T_CE); | |
7649 screen_start(); /* don't know where cursor is now */ | |
7650 col = end_col - col; | |
7651 while (col--) /* clear chars in ScreenLines */ | |
7652 { | |
7653 ScreenLines[off] = ' '; | |
7654 #ifdef FEAT_MBYTE | |
7655 if (enc_utf8) | |
7656 ScreenLinesUC[off] = 0; | |
7657 #endif | |
7658 ScreenAttrs[off] = 0; | |
7659 ++off; | |
7660 } | |
7661 } | |
7662 did_delete = TRUE; /* the chars are cleared now */ | |
7663 } | |
7664 | |
7665 off = LineOffset[row] + start_col; | |
7666 c = c1; | |
7667 for (col = start_col; col < end_col; ++col) | |
7668 { | |
7669 if (ScreenLines[off] != c | |
7670 #ifdef FEAT_MBYTE | |
714 | 7671 || (enc_utf8 && (int)ScreenLinesUC[off] |
7672 != (c >= 0x80 ? c : 0)) | |
7 | 7673 #endif |
7674 || ScreenAttrs[off] != attr | |
7675 #if defined(FEAT_GUI) || defined(UNIX) | |
7676 || force_next | |
7677 #endif | |
7678 ) | |
7679 { | |
7680 #if defined(FEAT_GUI) || defined(UNIX) | |
7681 /* The bold trick may make a single row of pixels appear in | |
7682 * the next character. When a bold character is removed, the | |
7683 * next character should be redrawn too. This happens for our | |
7684 * own GUI and for some xterms. */ | |
7685 if ( | |
7686 # ifdef FEAT_GUI | |
7687 gui.in_use | |
7688 # endif | |
7689 # if defined(FEAT_GUI) && defined(UNIX) | |
7690 || | |
7691 # endif | |
7692 # ifdef UNIX | |
7693 term_is_xterm | |
7694 # endif | |
7695 ) | |
7696 { | |
7697 if (ScreenLines[off] != ' ' | |
7698 && (ScreenAttrs[off] > HL_ALL | |
7699 || ScreenAttrs[off] & HL_BOLD)) | |
7700 force_next = TRUE; | |
7701 else | |
7702 force_next = FALSE; | |
7703 } | |
7704 #endif | |
7705 ScreenLines[off] = c; | |
7706 #ifdef FEAT_MBYTE | |
7707 if (enc_utf8) | |
7708 { | |
7709 if (c >= 0x80) | |
7710 { | |
7711 ScreenLinesUC[off] = c; | |
714 | 7712 ScreenLinesC[0][off] = 0; |
7 | 7713 } |
7714 else | |
7715 ScreenLinesUC[off] = 0; | |
7716 } | |
7717 #endif | |
7718 ScreenAttrs[off] = attr; | |
7719 if (!did_delete || c != ' ') | |
7720 screen_char(off, row, col); | |
7721 } | |
7722 ++off; | |
7723 if (col == start_col) | |
7724 { | |
7725 if (did_delete) | |
7726 break; | |
7727 c = c2; | |
7728 } | |
7729 } | |
7730 if (end_col == Columns) | |
7731 LineWraps[row] = FALSE; | |
7732 if (row == Rows - 1) /* overwritten the command line */ | |
7733 { | |
7734 redraw_cmdline = TRUE; | |
7735 if (c1 == ' ' && c2 == ' ') | |
7736 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7737 if (start_col == 0) |
7738 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7739 } |
7740 } | |
7741 } | |
7742 | |
7743 /* | |
7744 * Check if there should be a delay. Used before clearing or redrawing the | |
7745 * screen or the command line. | |
7746 */ | |
7747 void | |
7748 check_for_delay(check_msg_scroll) | |
7749 int check_msg_scroll; | |
7750 { | |
7751 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7752 && !did_wait_return | |
7753 && emsg_silent == 0) | |
7754 { | |
7755 out_flush(); | |
7756 ui_delay(1000L, TRUE); | |
7757 emsg_on_display = FALSE; | |
7758 if (check_msg_scroll) | |
7759 msg_scroll = FALSE; | |
7760 } | |
7761 } | |
7762 | |
7763 /* | |
7764 * screen_valid - allocate screen buffers if size changed | |
7765 * If "clear" is TRUE: clear screen if it has been resized. | |
7766 * Returns TRUE if there is a valid screen to write to. | |
7767 * Returns FALSE when starting up and screen not initialized yet. | |
7768 */ | |
7769 int | |
7770 screen_valid(clear) | |
7771 int clear; | |
7772 { | |
7773 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7774 return (ScreenLines != NULL); | |
7775 } | |
7776 | |
7777 /* | |
7778 * Resize the shell to Rows and Columns. | |
7779 * Allocate ScreenLines[] and associated items. | |
7780 * | |
7781 * There may be some time between setting Rows and Columns and (re)allocating | |
7782 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7783 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7784 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7785 * final size of the shell is needed. | |
7786 */ | |
7787 void | |
7788 screenalloc(clear) | |
7789 int clear; | |
7790 { | |
7791 int new_row, old_row; | |
7792 #ifdef FEAT_GUI | |
7793 int old_Rows; | |
7794 #endif | |
7795 win_T *wp; | |
7796 int outofmem = FALSE; | |
7797 int len; | |
7798 schar_T *new_ScreenLines; | |
7799 #ifdef FEAT_MBYTE | |
7800 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7801 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7802 schar_T *new_ScreenLines2 = NULL; |
714 | 7803 int i; |
7 | 7804 #endif |
7805 sattr_T *new_ScreenAttrs; | |
7806 unsigned *new_LineOffset; | |
7807 char_u *new_LineWraps; | |
671 | 7808 #ifdef FEAT_WINDOWS |
681 | 7809 short *new_TabPageIdxs; |
671 | 7810 tabpage_T *tp; |
7811 #endif | |
7 | 7812 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7813 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7814 #ifdef FEAT_AUTOCMD |
7815 int retry_count = 0; | |
7816 | |
7817 retry: | |
7818 #endif | |
7 | 7819 /* |
7820 * Allocation of the screen buffers is done only when the size changes and | |
7821 * when Rows and Columns have been set and we have started doing full | |
7822 * screen stuff. | |
7823 */ | |
7824 if ((ScreenLines != NULL | |
7825 && Rows == screen_Rows | |
7826 && Columns == screen_Columns | |
7827 #ifdef FEAT_MBYTE | |
7828 && enc_utf8 == (ScreenLinesUC != NULL) | |
7829 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7830 && p_mco == Screen_mco |
7 | 7831 #endif |
7832 ) | |
7833 || Rows == 0 | |
7834 || Columns == 0 | |
7835 || (!full_screen && ScreenLines == NULL)) | |
7836 return; | |
7837 | |
7838 /* | |
7839 * It's possible that we produce an out-of-memory message below, which | |
7840 * will cause this function to be called again. To break the loop, just | |
7841 * return here. | |
7842 */ | |
7843 if (entered) | |
7844 return; | |
7845 entered = TRUE; | |
7846 | |
911 | 7847 /* |
7848 * Note that the window sizes are updated before reallocating the arrays, | |
7849 * thus we must not redraw here! | |
7850 */ | |
7851 ++RedrawingDisabled; | |
7852 | |
7 | 7853 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7854 | |
7855 comp_col(); /* recompute columns for shown command and ruler */ | |
7856 | |
7857 /* | |
7858 * We're changing the size of the screen. | |
7859 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7860 * - Move lines from the old arrays into the new arrays, clear extra | |
7861 * lines (unless the screen is going to be cleared). | |
7862 * - Free the old arrays. | |
7863 * | |
7864 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7865 * Continuing with the old ScreenLines may result in a crash, because the | |
7866 * size is wrong. | |
7867 */ | |
671 | 7868 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7869 win_free_lsize(wp); |
1946 | 7870 #ifdef FEAT_AUTOCMD |
7871 if (aucmd_win != NULL) | |
7872 win_free_lsize(aucmd_win); | |
7873 #endif | |
7 | 7874 |
7875 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7876 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7877 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7878 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7879 if (enc_utf8) |
7880 { | |
7881 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7882 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7883 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7884 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7885 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7886 } | |
7887 if (enc_dbcs == DBCS_JPNU) | |
7888 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7889 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7890 #endif | |
7891 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7892 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7893 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7894 Rows * sizeof(unsigned)), FALSE); | |
7895 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7896 #ifdef FEAT_WINDOWS |
681 | 7897 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7898 #endif |
7 | 7899 |
677 | 7900 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7901 { |
7902 if (win_alloc_lines(wp) == FAIL) | |
7903 { | |
7904 outofmem = TRUE; | |
7905 #ifdef FEAT_WINDOWS | |
1819 | 7906 goto give_up; |
7907 #endif | |
7908 } | |
7909 } | |
1906 | 7910 #ifdef FEAT_AUTOCMD |
1946 | 7911 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7912 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7913 outofmem = TRUE; |
7914 #endif | |
1819 | 7915 #ifdef FEAT_WINDOWS |
7916 give_up: | |
7917 #endif | |
7 | 7918 |
714 | 7919 #ifdef FEAT_MBYTE |
7920 for (i = 0; i < p_mco; ++i) | |
7921 if (new_ScreenLinesC[i] == NULL) | |
7922 break; | |
7923 #endif | |
7 | 7924 if (new_ScreenLines == NULL |
7925 #ifdef FEAT_MBYTE | |
714 | 7926 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 7927 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
7928 #endif | |
7929 || new_ScreenAttrs == NULL | |
7930 || new_LineOffset == NULL | |
7931 || new_LineWraps == NULL | |
671 | 7932 #ifdef FEAT_WINDOWS |
7933 || new_TabPageIdxs == NULL | |
7934 #endif | |
7 | 7935 || outofmem) |
7936 { | |
944 | 7937 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 7938 { |
7939 /* guess the size */ | |
7940 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
7941 | |
7942 /* Remember we did this to avoid getting outofmem messages over | |
7943 * and over again. */ | |
944 | 7944 done_outofmem_msg = TRUE; |
534 | 7945 } |
7 | 7946 vim_free(new_ScreenLines); |
7947 new_ScreenLines = NULL; | |
7948 #ifdef FEAT_MBYTE | |
7949 vim_free(new_ScreenLinesUC); | |
7950 new_ScreenLinesUC = NULL; | |
714 | 7951 for (i = 0; i < p_mco; ++i) |
7952 { | |
7953 vim_free(new_ScreenLinesC[i]); | |
7954 new_ScreenLinesC[i] = NULL; | |
7955 } | |
7 | 7956 vim_free(new_ScreenLines2); |
7957 new_ScreenLines2 = NULL; | |
7958 #endif | |
7959 vim_free(new_ScreenAttrs); | |
7960 new_ScreenAttrs = NULL; | |
7961 vim_free(new_LineOffset); | |
7962 new_LineOffset = NULL; | |
7963 vim_free(new_LineWraps); | |
7964 new_LineWraps = NULL; | |
671 | 7965 #ifdef FEAT_WINDOWS |
7966 vim_free(new_TabPageIdxs); | |
7967 new_TabPageIdxs = NULL; | |
7968 #endif | |
7 | 7969 } |
7970 else | |
7971 { | |
944 | 7972 done_outofmem_msg = FALSE; |
534 | 7973 |
7 | 7974 for (new_row = 0; new_row < Rows; ++new_row) |
7975 { | |
7976 new_LineOffset[new_row] = new_row * Columns; | |
7977 new_LineWraps[new_row] = FALSE; | |
7978 | |
7979 /* | |
7980 * If the screen is not going to be cleared, copy as much as | |
7981 * possible from the old screen to the new one and clear the rest | |
7982 * (used when resizing the window at the "--more--" prompt or when | |
7983 * executing an external command, for the GUI). | |
7984 */ | |
7985 if (!clear) | |
7986 { | |
7987 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
7988 ' ', (size_t)Columns * sizeof(schar_T)); | |
7989 #ifdef FEAT_MBYTE | |
7990 if (enc_utf8) | |
7991 { | |
7992 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
7993 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 7994 for (i = 0; i < p_mco; ++i) |
7995 (void)vim_memset(new_ScreenLinesC[i] | |
7996 + new_row * Columns, | |
7 | 7997 0, (size_t)Columns * sizeof(u8char_T)); |
7998 } | |
7999 if (enc_dbcs == DBCS_JPNU) | |
8000 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8001 0, (size_t)Columns * sizeof(schar_T)); | |
8002 #endif | |
8003 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8004 0, (size_t)Columns * sizeof(sattr_T)); | |
8005 old_row = new_row + (screen_Rows - Rows); | |
534 | 8006 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8007 { |
8008 if (screen_Columns < Columns) | |
8009 len = screen_Columns; | |
8010 else | |
8011 len = Columns; | |
26 | 8012 #ifdef FEAT_MBYTE |
571 | 8013 /* When switching to utf-8 don't copy characters, they |
714 | 8014 * may be invalid now. Also when p_mco changes. */ |
8015 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8016 && p_mco == Screen_mco) | |
26 | 8017 #endif |
8018 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8019 ScreenLines + LineOffset[old_row], | |
8020 (size_t)len * sizeof(schar_T)); | |
7 | 8021 #ifdef FEAT_MBYTE |
714 | 8022 if (enc_utf8 && ScreenLinesUC != NULL |
8023 && p_mco == Screen_mco) | |
7 | 8024 { |
8025 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8026 ScreenLinesUC + LineOffset[old_row], | |
8027 (size_t)len * sizeof(u8char_T)); | |
714 | 8028 for (i = 0; i < p_mco; ++i) |
8029 mch_memmove(new_ScreenLinesC[i] | |
8030 + new_LineOffset[new_row], | |
8031 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8032 (size_t)len * sizeof(u8char_T)); |
8033 } | |
8034 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8035 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8036 ScreenLines2 + LineOffset[old_row], | |
8037 (size_t)len * sizeof(schar_T)); | |
8038 #endif | |
8039 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8040 ScreenAttrs + LineOffset[old_row], | |
8041 (size_t)len * sizeof(sattr_T)); | |
8042 } | |
8043 } | |
8044 } | |
8045 /* Use the last line of the screen for the current line. */ | |
8046 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8047 } | |
8048 | |
356 | 8049 free_screenlines(); |
8050 | |
7 | 8051 ScreenLines = new_ScreenLines; |
8052 #ifdef FEAT_MBYTE | |
8053 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8054 for (i = 0; i < p_mco; ++i) |
8055 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8056 Screen_mco = p_mco; | |
7 | 8057 ScreenLines2 = new_ScreenLines2; |
8058 #endif | |
8059 ScreenAttrs = new_ScreenAttrs; | |
8060 LineOffset = new_LineOffset; | |
8061 LineWraps = new_LineWraps; | |
671 | 8062 #ifdef FEAT_WINDOWS |
8063 TabPageIdxs = new_TabPageIdxs; | |
8064 #endif | |
7 | 8065 |
8066 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8067 * size of ScreenLines[]. Set them before calling anything. */ | |
8068 #ifdef FEAT_GUI | |
8069 old_Rows = screen_Rows; | |
8070 #endif | |
8071 screen_Rows = Rows; | |
8072 screen_Columns = Columns; | |
8073 | |
8074 must_redraw = CLEAR; /* need to clear the screen later */ | |
8075 if (clear) | |
8076 screenclear2(); | |
8077 | |
8078 #ifdef FEAT_GUI | |
8079 else if (gui.in_use | |
8080 && !gui.starting | |
8081 && ScreenLines != NULL | |
8082 && old_Rows != Rows) | |
8083 { | |
8084 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8085 /* | |
8086 * Adjust the position of the cursor, for when executing an external | |
8087 * command. | |
8088 */ | |
8089 if (msg_row >= Rows) /* Rows got smaller */ | |
8090 msg_row = Rows - 1; /* put cursor at last row */ | |
8091 else if (Rows > old_Rows) /* Rows got bigger */ | |
8092 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8093 if (msg_col >= Columns) /* Columns got smaller */ | |
8094 msg_col = Columns - 1; /* put cursor at last column */ | |
8095 } | |
8096 #endif | |
8097 | |
8098 entered = FALSE; | |
911 | 8099 --RedrawingDisabled; |
766 | 8100 |
8101 #ifdef FEAT_AUTOCMD | |
1824 | 8102 /* |
8103 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8104 * in case applying autocommands always changes Rows or Columns. | |
8105 */ | |
8106 if (starting == 0 && ++retry_count <= 3) | |
8107 { | |
766 | 8108 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8109 /* In rare cases, autocommands may have altered Rows or Columns, |
8110 * jump back to check if we need to allocate the screen again. */ | |
8111 goto retry; | |
8112 } | |
766 | 8113 #endif |
7 | 8114 } |
8115 | |
8116 void | |
356 | 8117 free_screenlines() |
8118 { | |
8119 #ifdef FEAT_MBYTE | |
714 | 8120 int i; |
8121 | |
356 | 8122 vim_free(ScreenLinesUC); |
714 | 8123 for (i = 0; i < Screen_mco; ++i) |
8124 vim_free(ScreenLinesC[i]); | |
356 | 8125 vim_free(ScreenLines2); |
8126 #endif | |
714 | 8127 vim_free(ScreenLines); |
356 | 8128 vim_free(ScreenAttrs); |
8129 vim_free(LineOffset); | |
8130 vim_free(LineWraps); | |
671 | 8131 #ifdef FEAT_WINDOWS |
8132 vim_free(TabPageIdxs); | |
8133 #endif | |
356 | 8134 } |
8135 | |
8136 void | |
7 | 8137 screenclear() |
8138 { | |
8139 check_for_delay(FALSE); | |
8140 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8141 screenclear2(); /* clear the screen */ | |
8142 } | |
8143 | |
8144 static void | |
8145 screenclear2() | |
8146 { | |
8147 int i; | |
8148 | |
8149 if (starting == NO_SCREEN || ScreenLines == NULL | |
8150 #ifdef FEAT_GUI | |
8151 || (gui.in_use && gui.starting) | |
8152 #endif | |
8153 ) | |
8154 return; | |
8155 | |
8156 #ifdef FEAT_GUI | |
8157 if (!gui.in_use) | |
8158 #endif | |
8159 screen_attr = -1; /* force setting the Normal colors */ | |
8160 screen_stop_highlight(); /* don't want highlighting here */ | |
8161 | |
8162 #ifdef FEAT_CLIPBOARD | |
8163 /* disable selection without redrawing it */ | |
8164 clip_scroll_selection(9999); | |
8165 #endif | |
8166 | |
8167 /* blank out ScreenLines */ | |
8168 for (i = 0; i < Rows; ++i) | |
8169 { | |
8170 lineclear(LineOffset[i], (int)Columns); | |
8171 LineWraps[i] = FALSE; | |
8172 } | |
8173 | |
8174 if (can_clear(T_CL)) | |
8175 { | |
8176 out_str(T_CL); /* clear the display */ | |
8177 clear_cmdline = FALSE; | |
644 | 8178 mode_displayed = FALSE; |
7 | 8179 } |
8180 else | |
8181 { | |
8182 /* can't clear the screen, mark all chars with invalid attributes */ | |
8183 for (i = 0; i < Rows; ++i) | |
8184 lineinvalid(LineOffset[i], (int)Columns); | |
8185 clear_cmdline = TRUE; | |
8186 } | |
8187 | |
8188 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8189 | |
8190 win_rest_invalid(firstwin); | |
8191 redraw_cmdline = TRUE; | |
670 | 8192 #ifdef FEAT_WINDOWS |
673 | 8193 redraw_tabline = TRUE; |
670 | 8194 #endif |
7 | 8195 if (must_redraw == CLEAR) /* no need to clear again */ |
8196 must_redraw = NOT_VALID; | |
8197 compute_cmdrow(); | |
8198 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8199 msg_col = 0; | |
8200 screen_start(); /* don't know where cursor is now */ | |
8201 msg_scrolled = 0; /* can't scroll back */ | |
8202 msg_didany = FALSE; | |
8203 msg_didout = FALSE; | |
8204 } | |
8205 | |
8206 /* | |
8207 * Clear one line in ScreenLines. | |
8208 */ | |
8209 static void | |
8210 lineclear(off, width) | |
8211 unsigned off; | |
8212 int width; | |
8213 { | |
8214 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8215 #ifdef FEAT_MBYTE | |
8216 if (enc_utf8) | |
8217 (void)vim_memset(ScreenLinesUC + off, 0, | |
8218 (size_t)width * sizeof(u8char_T)); | |
8219 #endif | |
8220 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8221 } | |
8222 | |
8223 /* | |
8224 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8225 * invalid value. | |
8226 */ | |
8227 static void | |
8228 lineinvalid(off, width) | |
8229 unsigned off; | |
8230 int width; | |
8231 { | |
8232 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8233 } | |
8234 | |
8235 #ifdef FEAT_VERTSPLIT | |
8236 /* | |
8237 * Copy part of a Screenline for vertically split window "wp". | |
8238 */ | |
8239 static void | |
8240 linecopy(to, from, wp) | |
8241 int to; | |
8242 int from; | |
8243 win_T *wp; | |
8244 { | |
8245 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8246 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8247 | |
8248 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8249 wp->w_width * sizeof(schar_T)); | |
8250 # ifdef FEAT_MBYTE | |
8251 if (enc_utf8) | |
8252 { | |
714 | 8253 int i; |
8254 | |
7 | 8255 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8256 wp->w_width * sizeof(u8char_T)); | |
714 | 8257 for (i = 0; i < p_mco; ++i) |
8258 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8259 wp->w_width * sizeof(u8char_T)); | |
7 | 8260 } |
8261 if (enc_dbcs == DBCS_JPNU) | |
8262 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8263 wp->w_width * sizeof(schar_T)); | |
8264 # endif | |
8265 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8266 wp->w_width * sizeof(sattr_T)); | |
8267 } | |
8268 #endif | |
8269 | |
8270 /* | |
8271 * Return TRUE if clearing with term string "p" would work. | |
8272 * It can't work when the string is empty or it won't set the right background. | |
8273 */ | |
8274 int | |
8275 can_clear(p) | |
8276 char_u *p; | |
8277 { | |
8278 return (*p != NUL && (t_colors <= 1 | |
8279 #ifdef FEAT_GUI | |
8280 || gui.in_use | |
8281 #endif | |
8282 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8283 } | |
8284 | |
8285 /* | |
8286 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8287 * something directly to the screen (shell commands) or a terminal control | |
8288 * code. | |
8289 */ | |
8290 void | |
8291 screen_start() | |
8292 { | |
8293 screen_cur_row = screen_cur_col = 9999; | |
8294 } | |
8295 | |
8296 /* | |
8297 * Move the cursor to position "row","col" in the screen. | |
8298 * This tries to find the most efficient way to move, minimizing the number of | |
8299 * characters sent to the terminal. | |
8300 */ | |
8301 void | |
8302 windgoto(row, col) | |
8303 int row; | |
8304 int col; | |
8305 { | |
205 | 8306 sattr_T *p; |
7 | 8307 int i; |
8308 int plan; | |
8309 int cost; | |
8310 int wouldbe_col; | |
8311 int noinvcurs; | |
8312 char_u *bs; | |
8313 int goto_cost; | |
8314 int attr; | |
8315 | |
1213 | 8316 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8317 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8318 | |
8319 #define PLAN_LE 1 | |
8320 #define PLAN_CR 2 | |
8321 #define PLAN_NL 3 | |
8322 #define PLAN_WRITE 4 | |
8323 /* Can't use ScreenLines unless initialized */ | |
8324 if (ScreenLines == NULL) | |
8325 return; | |
8326 | |
8327 if (col != screen_cur_col || row != screen_cur_row) | |
8328 { | |
8329 /* Check for valid position. */ | |
8330 if (row < 0) /* window without text lines? */ | |
8331 row = 0; | |
8332 if (row >= screen_Rows) | |
8333 row = screen_Rows - 1; | |
8334 if (col >= screen_Columns) | |
8335 col = screen_Columns - 1; | |
8336 | |
8337 /* check if no cursor movement is allowed in highlight mode */ | |
8338 if (screen_attr && *T_MS == NUL) | |
8339 noinvcurs = HIGHL_COST; | |
8340 else | |
8341 noinvcurs = 0; | |
8342 goto_cost = GOTO_COST + noinvcurs; | |
8343 | |
8344 /* | |
8345 * Plan how to do the positioning: | |
8346 * 1. Use CR to move it to column 0, same row. | |
8347 * 2. Use T_LE to move it a few columns to the left. | |
8348 * 3. Use NL to move a few lines down, column 0. | |
8349 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8350 * | |
8351 * Don't do this if the cursor went beyond the last column, the cursor | |
8352 * position is unknown then (some terminals wrap, some don't ) | |
8353 * | |
1213 | 8354 * First check if the highlighting attributes allow us to write |
7 | 8355 * characters to move the cursor to the right. |
8356 */ | |
8357 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8358 { | |
8359 /* | |
8360 * If the cursor is in the same row, bigger col, we can use CR | |
8361 * or T_LE. | |
8362 */ | |
8363 bs = NULL; /* init for GCC */ | |
8364 attr = screen_attr; | |
8365 if (row == screen_cur_row && col < screen_cur_col) | |
8366 { | |
8367 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8368 if (*T_LE) | |
8369 bs = T_LE; /* "cursor left" */ | |
8370 else | |
8371 bs = T_BC; /* "backspace character (old) */ | |
8372 if (*bs) | |
8373 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8374 else | |
8375 cost = 999; | |
8376 if (col + 1 < cost) /* using CR is less characters */ | |
8377 { | |
8378 plan = PLAN_CR; | |
8379 wouldbe_col = 0; | |
8380 cost = 1; /* CR is just one character */ | |
8381 } | |
8382 else | |
8383 { | |
8384 plan = PLAN_LE; | |
8385 wouldbe_col = col; | |
8386 } | |
8387 if (noinvcurs) /* will stop highlighting */ | |
8388 { | |
8389 cost += noinvcurs; | |
8390 attr = 0; | |
8391 } | |
8392 } | |
8393 | |
8394 /* | |
8395 * If the cursor is above where we want to be, we can use CR LF. | |
8396 */ | |
8397 else if (row > screen_cur_row) | |
8398 { | |
8399 plan = PLAN_NL; | |
8400 wouldbe_col = 0; | |
8401 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8402 if (noinvcurs) /* will stop highlighting */ | |
8403 { | |
8404 cost += noinvcurs; | |
8405 attr = 0; | |
8406 } | |
8407 } | |
8408 | |
8409 /* | |
8410 * If the cursor is in the same row, smaller col, just use write. | |
8411 */ | |
8412 else | |
8413 { | |
8414 plan = PLAN_WRITE; | |
8415 wouldbe_col = screen_cur_col; | |
8416 cost = 0; | |
8417 } | |
8418 | |
8419 /* | |
8420 * Check if any characters that need to be written have the | |
8421 * correct attributes. Also avoid UTF-8 characters. | |
8422 */ | |
8423 i = col - wouldbe_col; | |
8424 if (i > 0) | |
8425 cost += i; | |
8426 if (cost < goto_cost && i > 0) | |
8427 { | |
8428 /* | |
8429 * Check if the attributes are correct without additionally | |
8430 * stopping highlighting. | |
8431 */ | |
8432 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8433 while (i && *p++ == attr) | |
8434 --i; | |
8435 if (i != 0) | |
8436 { | |
8437 /* | |
8438 * Try if it works when highlighting is stopped here. | |
8439 */ | |
8440 if (*--p == 0) | |
8441 { | |
8442 cost += noinvcurs; | |
8443 while (i && *p++ == 0) | |
8444 --i; | |
8445 } | |
8446 if (i != 0) | |
8447 cost = 999; /* different attributes, don't do it */ | |
8448 } | |
8449 #ifdef FEAT_MBYTE | |
8450 if (enc_utf8) | |
8451 { | |
8452 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8453 for (i = wouldbe_col; i < col; ++i) | |
8454 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8455 { | |
8456 cost = 999; | |
8457 break; | |
8458 } | |
8459 } | |
8460 #endif | |
8461 } | |
8462 | |
8463 /* | |
8464 * We can do it without term_windgoto()! | |
8465 */ | |
8466 if (cost < goto_cost) | |
8467 { | |
8468 if (plan == PLAN_LE) | |
8469 { | |
8470 if (noinvcurs) | |
8471 screen_stop_highlight(); | |
8472 while (screen_cur_col > col) | |
8473 { | |
8474 out_str(bs); | |
8475 --screen_cur_col; | |
8476 } | |
8477 } | |
8478 else if (plan == PLAN_CR) | |
8479 { | |
8480 if (noinvcurs) | |
8481 screen_stop_highlight(); | |
8482 out_char('\r'); | |
8483 screen_cur_col = 0; | |
8484 } | |
8485 else if (plan == PLAN_NL) | |
8486 { | |
8487 if (noinvcurs) | |
8488 screen_stop_highlight(); | |
8489 while (screen_cur_row < row) | |
8490 { | |
8491 out_char('\n'); | |
8492 ++screen_cur_row; | |
8493 } | |
8494 screen_cur_col = 0; | |
8495 } | |
8496 | |
8497 i = col - screen_cur_col; | |
8498 if (i > 0) | |
8499 { | |
8500 /* | |
8501 * Use cursor-right if it's one character only. Avoids | |
8502 * removing a line of pixels from the last bold char, when | |
8503 * using the bold trick in the GUI. | |
8504 */ | |
8505 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8506 { | |
8507 while (i-- > 0) | |
8508 out_char(*T_ND); | |
8509 } | |
8510 else | |
8511 { | |
8512 int off; | |
8513 | |
8514 off = LineOffset[row] + screen_cur_col; | |
8515 while (i-- > 0) | |
8516 { | |
8517 if (ScreenAttrs[off] != screen_attr) | |
8518 screen_stop_highlight(); | |
8519 #ifdef FEAT_MBYTE | |
8520 out_flush_check(); | |
8521 #endif | |
8522 out_char(ScreenLines[off]); | |
8523 #ifdef FEAT_MBYTE | |
8524 if (enc_dbcs == DBCS_JPNU | |
8525 && ScreenLines[off] == 0x8e) | |
8526 out_char(ScreenLines2[off]); | |
8527 #endif | |
8528 ++off; | |
8529 } | |
8530 } | |
8531 } | |
8532 } | |
8533 } | |
8534 else | |
8535 cost = 999; | |
8536 | |
8537 if (cost >= goto_cost) | |
8538 { | |
8539 if (noinvcurs) | |
8540 screen_stop_highlight(); | |
8541 if (row == screen_cur_row && (col > screen_cur_col) && | |
8542 *T_CRI != NUL) | |
8543 term_cursor_right(col - screen_cur_col); | |
8544 else | |
8545 term_windgoto(row, col); | |
8546 } | |
8547 screen_cur_row = row; | |
8548 screen_cur_col = col; | |
8549 } | |
8550 } | |
8551 | |
8552 /* | |
8553 * Set cursor to its position in the current window. | |
8554 */ | |
8555 void | |
8556 setcursor() | |
8557 { | |
8558 if (redrawing()) | |
8559 { | |
8560 validate_cursor(); | |
8561 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8562 W_WINCOL(curwin) + ( | |
8563 #ifdef FEAT_RIGHTLEFT | |
1545 | 8564 /* With 'rightleft' set and the cursor on a double-wide |
8565 * character, position it on the leftmost column. */ | |
7 | 8566 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8567 # ifdef FEAT_MBYTE | |
1545 | 8568 (has_mbyte |
8569 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8570 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8571 # endif |
8572 1)) : | |
8573 #endif | |
8574 curwin->w_wcol)); | |
8575 } | |
8576 } | |
8577 | |
8578 | |
8579 /* | |
8580 * insert 'line_count' lines at 'row' in window 'wp' | |
8581 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8582 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8583 * scrolling. | |
8584 * Returns FAIL if the lines are not inserted, OK for success. | |
8585 */ | |
8586 int | |
8587 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8588 win_T *wp; | |
8589 int row; | |
8590 int line_count; | |
8591 int invalid; | |
8592 int mayclear; | |
8593 { | |
8594 int did_delete; | |
8595 int nextrow; | |
8596 int lastrow; | |
8597 int retval; | |
8598 | |
8599 if (invalid) | |
8600 wp->w_lines_valid = 0; | |
8601 | |
8602 if (wp->w_height < 5) | |
8603 return FAIL; | |
8604 | |
8605 if (line_count > wp->w_height - row) | |
8606 line_count = wp->w_height - row; | |
8607 | |
8608 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8609 if (retval != MAYBE) | |
8610 return retval; | |
8611 | |
8612 /* | |
8613 * If there is a next window or a status line, we first try to delete the | |
8614 * lines at the bottom to avoid messing what is after the window. | |
8615 * If this fails and there are following windows, don't do anything to avoid | |
8616 * messing up those windows, better just redraw. | |
8617 */ | |
8618 did_delete = FALSE; | |
8619 #ifdef FEAT_WINDOWS | |
8620 if (wp->w_next != NULL || wp->w_status_height) | |
8621 { | |
8622 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8623 line_count, (int)Rows, FALSE, NULL) == OK) | |
8624 did_delete = TRUE; | |
8625 else if (wp->w_next) | |
8626 return FAIL; | |
8627 } | |
8628 #endif | |
8629 /* | |
8630 * if no lines deleted, blank the lines that will end up below the window | |
8631 */ | |
8632 if (!did_delete) | |
8633 { | |
8634 #ifdef FEAT_WINDOWS | |
8635 wp->w_redr_status = TRUE; | |
8636 #endif | |
8637 redraw_cmdline = TRUE; | |
8638 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8639 lastrow = nextrow + line_count; | |
8640 if (lastrow > Rows) | |
8641 lastrow = Rows; | |
8642 screen_fill(nextrow - line_count, lastrow - line_count, | |
8643 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8644 ' ', ' ', 0); | |
8645 } | |
8646 | |
8647 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8648 == FAIL) | |
8649 { | |
8650 /* deletion will have messed up other windows */ | |
8651 if (did_delete) | |
8652 { | |
8653 #ifdef FEAT_WINDOWS | |
8654 wp->w_redr_status = TRUE; | |
8655 #endif | |
8656 win_rest_invalid(W_NEXT(wp)); | |
8657 } | |
8658 return FAIL; | |
8659 } | |
8660 | |
8661 return OK; | |
8662 } | |
8663 | |
8664 /* | |
8665 * delete "line_count" window lines at "row" in window "wp" | |
8666 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8667 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8668 * scrolling | |
8669 * Return OK for success, FAIL if the lines are not deleted. | |
8670 */ | |
8671 int | |
8672 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8673 win_T *wp; | |
8674 int row; | |
8675 int line_count; | |
8676 int invalid; | |
8677 int mayclear; | |
8678 { | |
8679 int retval; | |
8680 | |
8681 if (invalid) | |
8682 wp->w_lines_valid = 0; | |
8683 | |
8684 if (line_count > wp->w_height - row) | |
8685 line_count = wp->w_height - row; | |
8686 | |
8687 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8688 if (retval != MAYBE) | |
8689 return retval; | |
8690 | |
8691 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8692 (int)Rows, FALSE, NULL) == FAIL) | |
8693 return FAIL; | |
8694 | |
8695 #ifdef FEAT_WINDOWS | |
8696 /* | |
8697 * If there are windows or status lines below, try to put them at the | |
8698 * correct place. If we can't do that, they have to be redrawn. | |
8699 */ | |
8700 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8701 { | |
8702 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8703 line_count, (int)Rows, NULL) == FAIL) | |
8704 { | |
8705 wp->w_redr_status = TRUE; | |
8706 win_rest_invalid(wp->w_next); | |
8707 } | |
8708 } | |
8709 /* | |
8710 * If this is the last window and there is no status line, redraw the | |
8711 * command line later. | |
8712 */ | |
8713 else | |
8714 #endif | |
8715 redraw_cmdline = TRUE; | |
8716 return OK; | |
8717 } | |
8718 | |
8719 /* | |
8720 * Common code for win_ins_lines() and win_del_lines(). | |
8721 * Returns OK or FAIL when the work has been done. | |
8722 * Returns MAYBE when not finished yet. | |
8723 */ | |
8724 static int | |
8725 win_do_lines(wp, row, line_count, mayclear, del) | |
8726 win_T *wp; | |
8727 int row; | |
8728 int line_count; | |
8729 int mayclear; | |
8730 int del; | |
8731 { | |
8732 int retval; | |
8733 | |
8734 if (!redrawing() || line_count <= 0) | |
8735 return FAIL; | |
8736 | |
8737 /* only a few lines left: redraw is faster */ | |
8738 if (mayclear && Rows - line_count < 5 | |
8739 #ifdef FEAT_VERTSPLIT | |
8740 && wp->w_width == Columns | |
8741 #endif | |
8742 ) | |
8743 { | |
8744 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8745 return FAIL; | |
8746 } | |
8747 | |
8748 /* | |
8749 * Delete all remaining lines | |
8750 */ | |
8751 if (row + line_count >= wp->w_height) | |
8752 { | |
8753 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8754 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8755 ' ', ' ', 0); | |
8756 return OK; | |
8757 } | |
8758 | |
8759 /* | |
8760 * when scrolling, the message on the command line should be cleared, | |
8761 * otherwise it will stay there forever. | |
8762 */ | |
8763 clear_cmdline = TRUE; | |
8764 | |
8765 /* | |
8766 * If the terminal can set a scroll region, use that. | |
8767 * Always do this in a vertically split window. This will redraw from | |
8768 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8769 * win_line(). | |
8770 * Don't use a scroll region when we are going to redraw the text, writing | |
8771 * a character in the lower right corner of the scroll region causes a | |
8772 * scroll-up in the DJGPP version. | |
8773 */ | |
8774 if (scroll_region | |
8775 #ifdef FEAT_VERTSPLIT | |
8776 || W_WIDTH(wp) != Columns | |
8777 #endif | |
8778 ) | |
8779 { | |
8780 #ifdef FEAT_VERTSPLIT | |
8781 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8782 #endif | |
8783 scroll_region_set(wp, row); | |
8784 if (del) | |
8785 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8786 wp->w_height - row, FALSE, wp); | |
8787 else | |
8788 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8789 wp->w_height - row, wp); | |
8790 #ifdef FEAT_VERTSPLIT | |
8791 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8792 #endif | |
8793 scroll_region_reset(); | |
8794 return retval; | |
8795 } | |
8796 | |
8797 #ifdef FEAT_WINDOWS | |
8798 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8799 return FAIL; | |
8800 #endif | |
8801 | |
8802 return MAYBE; | |
8803 } | |
8804 | |
8805 /* | |
8806 * window 'wp' and everything after it is messed up, mark it for redraw | |
8807 */ | |
8808 static void | |
8809 win_rest_invalid(wp) | |
8810 win_T *wp; | |
8811 { | |
8812 #ifdef FEAT_WINDOWS | |
8813 while (wp != NULL) | |
8814 #else | |
8815 if (wp != NULL) | |
8816 #endif | |
8817 { | |
8818 redraw_win_later(wp, NOT_VALID); | |
8819 #ifdef FEAT_WINDOWS | |
8820 wp->w_redr_status = TRUE; | |
8821 wp = wp->w_next; | |
8822 #endif | |
8823 } | |
8824 redraw_cmdline = TRUE; | |
8825 } | |
8826 | |
8827 /* | |
8828 * The rest of the routines in this file perform screen manipulations. The | |
8829 * given operation is performed physically on the screen. The corresponding | |
8830 * change is also made to the internal screen image. In this way, the editor | |
8831 * anticipates the effect of editing changes on the appearance of the screen. | |
8832 * That way, when we call screenupdate a complete redraw isn't usually | |
8833 * necessary. Another advantage is that we can keep adding code to anticipate | |
8834 * screen changes, and in the meantime, everything still works. | |
8835 */ | |
8836 | |
8837 /* | |
8838 * types for inserting or deleting lines | |
8839 */ | |
8840 #define USE_T_CAL 1 | |
8841 #define USE_T_CDL 2 | |
8842 #define USE_T_AL 3 | |
8843 #define USE_T_CE 4 | |
8844 #define USE_T_DL 5 | |
8845 #define USE_T_SR 6 | |
8846 #define USE_NL 7 | |
8847 #define USE_T_CD 8 | |
8848 #define USE_REDRAW 9 | |
8849 | |
8850 /* | |
8851 * insert lines on the screen and update ScreenLines[] | |
8852 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8853 * When scrolling region used 'off' is the offset from the top for the region. | |
8854 * 'row' and 'end' are relative to the start of the region. | |
8855 * | |
8856 * return FAIL for failure, OK for success. | |
8857 */ | |
446 | 8858 int |
7 | 8859 screen_ins_lines(off, row, line_count, end, wp) |
8860 int off; | |
8861 int row; | |
8862 int line_count; | |
8863 int end; | |
8864 win_T *wp; /* NULL or window to use width from */ | |
8865 { | |
8866 int i; | |
8867 int j; | |
8868 unsigned temp; | |
8869 int cursor_row; | |
8870 int type; | |
8871 int result_empty; | |
8872 int can_ce = can_clear(T_CE); | |
8873 | |
8874 /* | |
8875 * FAIL if | |
8876 * - there is no valid screen | |
8877 * - the screen has to be redrawn completely | |
8878 * - the line count is less than one | |
8879 * - the line count is more than 'ttyscroll' | |
8880 */ | |
8881 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8882 return FAIL; | |
8883 | |
8884 /* | |
8885 * There are seven ways to insert lines: | |
8886 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8887 * characters from ScreenLines[]. | |
8888 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8889 * the insert is just empty lines | |
8890 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8891 * present or line_count > 1. It looks better if we do all the inserts | |
8892 * at once. | |
8893 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8894 * insert is just empty lines and T_CE is not present or line_count > | |
8895 * 1. | |
8896 * 4. Use T_AL (insert line) if it exists. | |
8897 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8898 * just empty lines. | |
8899 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8900 * just empty lines. | |
8901 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8902 * the 'da' flag is not set or we have clear line capability. | |
8903 * 8. redraw the characters from ScreenLines[]. | |
8904 * | |
8905 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8906 * the scrollbar for the window. It does have insert line, use that if it | |
8907 * exists. | |
8908 */ | |
8909 result_empty = (row + line_count >= end); | |
8910 #ifdef FEAT_VERTSPLIT | |
8911 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8912 type = USE_REDRAW; | |
8913 else | |
8914 #endif | |
8915 if (can_clear(T_CD) && result_empty) | |
8916 type = USE_T_CD; | |
8917 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
8918 type = USE_T_CAL; | |
8919 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
8920 type = USE_T_CDL; | |
8921 else if (*T_AL != NUL) | |
8922 type = USE_T_AL; | |
8923 else if (can_ce && result_empty) | |
8924 type = USE_T_CE; | |
8925 else if (*T_DL != NUL && result_empty) | |
8926 type = USE_T_DL; | |
8927 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
8928 type = USE_T_SR; | |
8929 else | |
8930 return FAIL; | |
8931 | |
8932 /* | |
8933 * For clearing the lines screen_del_lines() is used. This will also take | |
8934 * care of t_db if necessary. | |
8935 */ | |
8936 if (type == USE_T_CD || type == USE_T_CDL || | |
8937 type == USE_T_CE || type == USE_T_DL) | |
8938 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
8939 | |
8940 /* | |
8941 * If text is retained below the screen, first clear or delete as many | |
8942 * lines at the bottom of the window as are about to be inserted so that | |
8943 * the deleted lines won't later surface during a screen_del_lines. | |
8944 */ | |
8945 if (*T_DB) | |
8946 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
8947 | |
8948 #ifdef FEAT_CLIPBOARD | |
8949 /* Remove a modeless selection when inserting lines halfway the screen | |
8950 * or not the full width of the screen. */ | |
8951 if (off + row > 0 | |
8952 # ifdef FEAT_VERTSPLIT | |
8953 || (wp != NULL && wp->w_width != Columns) | |
8954 # endif | |
8955 ) | |
8956 clip_clear_selection(); | |
8957 else | |
8958 clip_scroll_selection(-line_count); | |
8959 #endif | |
8960 | |
8961 #ifdef FEAT_GUI | |
8962 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
8963 * scrolling is actually carried out. */ | |
8964 gui_dont_update_cursor(); | |
8965 #endif | |
8966 | |
8967 if (*T_CCS != NUL) /* cursor relative to region */ | |
8968 cursor_row = row; | |
8969 else | |
8970 cursor_row = row + off; | |
8971 | |
8972 /* | |
8973 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
8974 * Clear the inserted lines in ScreenLines[]. | |
8975 */ | |
8976 row += off; | |
8977 end += off; | |
8978 for (i = 0; i < line_count; ++i) | |
8979 { | |
8980 #ifdef FEAT_VERTSPLIT | |
8981 if (wp != NULL && wp->w_width != Columns) | |
8982 { | |
8983 /* need to copy part of a line */ | |
8984 j = end - 1 - i; | |
8985 while ((j -= line_count) >= row) | |
8986 linecopy(j + line_count, j, wp); | |
8987 j += line_count; | |
8988 if (can_clear((char_u *)" ")) | |
8989 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8990 else | |
8991 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8992 LineWraps[j] = FALSE; | |
8993 } | |
8994 else | |
8995 #endif | |
8996 { | |
8997 j = end - 1 - i; | |
8998 temp = LineOffset[j]; | |
8999 while ((j -= line_count) >= row) | |
9000 { | |
9001 LineOffset[j + line_count] = LineOffset[j]; | |
9002 LineWraps[j + line_count] = LineWraps[j]; | |
9003 } | |
9004 LineOffset[j + line_count] = temp; | |
9005 LineWraps[j + line_count] = FALSE; | |
9006 if (can_clear((char_u *)" ")) | |
9007 lineclear(temp, (int)Columns); | |
9008 else | |
9009 lineinvalid(temp, (int)Columns); | |
9010 } | |
9011 } | |
9012 | |
9013 screen_stop_highlight(); | |
9014 windgoto(cursor_row, 0); | |
9015 | |
9016 #ifdef FEAT_VERTSPLIT | |
9017 /* redraw the characters */ | |
9018 if (type == USE_REDRAW) | |
9019 redraw_block(row, end, wp); | |
9020 else | |
9021 #endif | |
9022 if (type == USE_T_CAL) | |
9023 { | |
9024 term_append_lines(line_count); | |
9025 screen_start(); /* don't know where cursor is now */ | |
9026 } | |
9027 else | |
9028 { | |
9029 for (i = 0; i < line_count; i++) | |
9030 { | |
9031 if (type == USE_T_AL) | |
9032 { | |
9033 if (i && cursor_row != 0) | |
9034 windgoto(cursor_row, 0); | |
9035 out_str(T_AL); | |
9036 } | |
9037 else /* type == USE_T_SR */ | |
9038 out_str(T_SR); | |
9039 screen_start(); /* don't know where cursor is now */ | |
9040 } | |
9041 } | |
9042 | |
9043 /* | |
9044 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9045 * have been scrolled down into the region. | |
9046 */ | |
9047 if (type == USE_T_SR && *T_DA) | |
9048 { | |
9049 for (i = 0; i < line_count; ++i) | |
9050 { | |
9051 windgoto(off + i, 0); | |
9052 out_str(T_CE); | |
9053 screen_start(); /* don't know where cursor is now */ | |
9054 } | |
9055 } | |
9056 | |
9057 #ifdef FEAT_GUI | |
9058 gui_can_update_cursor(); | |
9059 if (gui.in_use) | |
9060 out_flush(); /* always flush after a scroll */ | |
9061 #endif | |
9062 return OK; | |
9063 } | |
9064 | |
9065 /* | |
9066 * delete lines on the screen and update ScreenLines[] | |
9067 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9068 * When scrolling region used 'off' is the offset from the top for the region. | |
9069 * 'row' and 'end' are relative to the start of the region. | |
9070 * | |
9071 * Return OK for success, FAIL if the lines are not deleted. | |
9072 */ | |
9073 int | |
9074 screen_del_lines(off, row, line_count, end, force, wp) | |
9075 int off; | |
9076 int row; | |
9077 int line_count; | |
9078 int end; | |
9079 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9080 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9081 { |
9082 int j; | |
9083 int i; | |
9084 unsigned temp; | |
9085 int cursor_row; | |
9086 int cursor_end; | |
9087 int result_empty; /* result is empty until end of region */ | |
9088 int can_delete; /* deleting line codes can be used */ | |
9089 int type; | |
9090 | |
9091 /* | |
9092 * FAIL if | |
9093 * - there is no valid screen | |
9094 * - the screen has to be redrawn completely | |
9095 * - the line count is less than one | |
9096 * - the line count is more than 'ttyscroll' | |
9097 */ | |
9098 if (!screen_valid(TRUE) || line_count <= 0 || | |
9099 (!force && line_count > p_ttyscroll)) | |
9100 return FAIL; | |
9101 | |
9102 /* | |
9103 * Check if the rest of the current region will become empty. | |
9104 */ | |
9105 result_empty = row + line_count >= end; | |
9106 | |
9107 /* | |
9108 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9109 * available. | |
9110 */ | |
9111 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9112 | |
9113 /* | |
9114 * There are six ways to delete lines: | |
9115 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9116 * characters from ScreenLines[]. | |
9117 * 1. Use T_CD if it exists and the result is empty. | |
9118 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9119 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9120 * none of the other ways work. | |
9121 * 4. Use T_CE (erase line) if the result is empty. | |
9122 * 5. Use T_DL (delete line) if it exists. | |
9123 * 6. redraw the characters from ScreenLines[]. | |
9124 */ | |
9125 #ifdef FEAT_VERTSPLIT | |
9126 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9127 type = USE_REDRAW; | |
9128 else | |
9129 #endif | |
9130 if (can_clear(T_CD) && result_empty) | |
9131 type = USE_T_CD; | |
9132 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9133 /* | |
9134 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9135 * its internal termcap... this works okay for tests which test *T_DB != | |
9136 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9137 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9138 * the trick... | |
9139 * Anyway, this hack will hopefully go away with the next OS release. | |
9140 * (Olaf Seibert) | |
9141 */ | |
9142 else if (row == 0 && T_DB == empty_option | |
9143 && (line_count == 1 || *T_CDL == NUL)) | |
9144 #else | |
9145 else if (row == 0 && ( | |
9146 #ifndef AMIGA | |
9147 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9148 * up, so use delete-line command */ | |
9149 line_count == 1 || | |
9150 #endif | |
9151 *T_CDL == NUL)) | |
9152 #endif | |
9153 type = USE_NL; | |
9154 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9155 type = USE_T_CDL; | |
9156 else if (can_clear(T_CE) && result_empty | |
9157 #ifdef FEAT_VERTSPLIT | |
9158 && (wp == NULL || wp->w_width == Columns) | |
9159 #endif | |
9160 ) | |
9161 type = USE_T_CE; | |
9162 else if (*T_DL != NUL && can_delete) | |
9163 type = USE_T_DL; | |
9164 else if (*T_CDL != NUL && can_delete) | |
9165 type = USE_T_CDL; | |
9166 else | |
9167 return FAIL; | |
9168 | |
9169 #ifdef FEAT_CLIPBOARD | |
9170 /* Remove a modeless selection when deleting lines halfway the screen or | |
9171 * not the full width of the screen. */ | |
9172 if (off + row > 0 | |
9173 # ifdef FEAT_VERTSPLIT | |
9174 || (wp != NULL && wp->w_width != Columns) | |
9175 # endif | |
9176 ) | |
9177 clip_clear_selection(); | |
9178 else | |
9179 clip_scroll_selection(line_count); | |
9180 #endif | |
9181 | |
9182 #ifdef FEAT_GUI | |
9183 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9184 * scrolling is actually carried out. */ | |
9185 gui_dont_update_cursor(); | |
9186 #endif | |
9187 | |
9188 if (*T_CCS != NUL) /* cursor relative to region */ | |
9189 { | |
9190 cursor_row = row; | |
9191 cursor_end = end; | |
9192 } | |
9193 else | |
9194 { | |
9195 cursor_row = row + off; | |
9196 cursor_end = end + off; | |
9197 } | |
9198 | |
9199 /* | |
9200 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9201 * Clear the inserted lines in ScreenLines[]. | |
9202 */ | |
9203 row += off; | |
9204 end += off; | |
9205 for (i = 0; i < line_count; ++i) | |
9206 { | |
9207 #ifdef FEAT_VERTSPLIT | |
9208 if (wp != NULL && wp->w_width != Columns) | |
9209 { | |
9210 /* need to copy part of a line */ | |
9211 j = row + i; | |
9212 while ((j += line_count) <= end - 1) | |
9213 linecopy(j - line_count, j, wp); | |
9214 j -= line_count; | |
9215 if (can_clear((char_u *)" ")) | |
9216 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9217 else | |
9218 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9219 LineWraps[j] = FALSE; | |
9220 } | |
9221 else | |
9222 #endif | |
9223 { | |
9224 /* whole width, moving the line pointers is faster */ | |
9225 j = row + i; | |
9226 temp = LineOffset[j]; | |
9227 while ((j += line_count) <= end - 1) | |
9228 { | |
9229 LineOffset[j - line_count] = LineOffset[j]; | |
9230 LineWraps[j - line_count] = LineWraps[j]; | |
9231 } | |
9232 LineOffset[j - line_count] = temp; | |
9233 LineWraps[j - line_count] = FALSE; | |
9234 if (can_clear((char_u *)" ")) | |
9235 lineclear(temp, (int)Columns); | |
9236 else | |
9237 lineinvalid(temp, (int)Columns); | |
9238 } | |
9239 } | |
9240 | |
9241 screen_stop_highlight(); | |
9242 | |
9243 #ifdef FEAT_VERTSPLIT | |
9244 /* redraw the characters */ | |
9245 if (type == USE_REDRAW) | |
9246 redraw_block(row, end, wp); | |
9247 else | |
9248 #endif | |
9249 if (type == USE_T_CD) /* delete the lines */ | |
9250 { | |
9251 windgoto(cursor_row, 0); | |
9252 out_str(T_CD); | |
9253 screen_start(); /* don't know where cursor is now */ | |
9254 } | |
9255 else if (type == USE_T_CDL) | |
9256 { | |
9257 windgoto(cursor_row, 0); | |
9258 term_delete_lines(line_count); | |
9259 screen_start(); /* don't know where cursor is now */ | |
9260 } | |
9261 /* | |
9262 * Deleting lines at top of the screen or scroll region: Just scroll | |
9263 * the whole screen (scroll region) up by outputting newlines on the | |
9264 * last line. | |
9265 */ | |
9266 else if (type == USE_NL) | |
9267 { | |
9268 windgoto(cursor_end - 1, 0); | |
9269 for (i = line_count; --i >= 0; ) | |
9270 out_char('\n'); /* cursor will remain on same line */ | |
9271 } | |
9272 else | |
9273 { | |
9274 for (i = line_count; --i >= 0; ) | |
9275 { | |
9276 if (type == USE_T_DL) | |
9277 { | |
9278 windgoto(cursor_row, 0); | |
9279 out_str(T_DL); /* delete a line */ | |
9280 } | |
9281 else /* type == USE_T_CE */ | |
9282 { | |
9283 windgoto(cursor_row + i, 0); | |
9284 out_str(T_CE); /* erase a line */ | |
9285 } | |
9286 screen_start(); /* don't know where cursor is now */ | |
9287 } | |
9288 } | |
9289 | |
9290 /* | |
9291 * If the 'db' flag is set, we need to clear the lines that have been | |
9292 * scrolled up at the bottom of the region. | |
9293 */ | |
9294 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9295 { | |
9296 for (i = line_count; i > 0; --i) | |
9297 { | |
9298 windgoto(cursor_end - i, 0); | |
9299 out_str(T_CE); /* erase a line */ | |
9300 screen_start(); /* don't know where cursor is now */ | |
9301 } | |
9302 } | |
9303 | |
9304 #ifdef FEAT_GUI | |
9305 gui_can_update_cursor(); | |
9306 if (gui.in_use) | |
9307 out_flush(); /* always flush after a scroll */ | |
9308 #endif | |
9309 | |
9310 return OK; | |
9311 } | |
9312 | |
9313 /* | |
9314 * show the current mode and ruler | |
9315 * | |
9316 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9317 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9318 * cleared only if a mode is shown. | |
9319 * Return the length of the message (0 if no message). | |
9320 */ | |
9321 int | |
9322 showmode() | |
9323 { | |
9324 int need_clear; | |
9325 int length = 0; | |
9326 int do_mode; | |
9327 int attr; | |
9328 int nwr_save; | |
9329 #ifdef FEAT_INS_EXPAND | |
9330 int sub_attr; | |
9331 #endif | |
9332 | |
642 | 9333 do_mode = ((p_smd && msg_silent == 0) |
9334 && ((State & INSERT) | |
9335 || restart_edit | |
7 | 9336 #ifdef FEAT_VISUAL |
9337 || VIsual_active | |
9338 #endif | |
9339 )); | |
9340 if (do_mode || Recording) | |
9341 { | |
9342 /* | |
9343 * Don't show mode right now, when not redrawing or inside a mapping. | |
9344 * Call char_avail() only when we are going to show something, because | |
9345 * it takes a bit of time. | |
9346 */ | |
9347 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9348 { | |
9349 redraw_cmdline = TRUE; /* show mode later */ | |
9350 return 0; | |
9351 } | |
9352 | |
9353 nwr_save = need_wait_return; | |
9354 | |
9355 /* wait a bit before overwriting an important message */ | |
9356 check_for_delay(FALSE); | |
9357 | |
9358 /* if the cmdline is more than one line high, erase top lines */ | |
9359 need_clear = clear_cmdline; | |
9360 if (clear_cmdline && cmdline_row < Rows - 1) | |
9361 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9362 | |
9363 /* Position on the last line in the window, column 0 */ | |
9364 msg_pos_mode(); | |
9365 cursor_off(); | |
9366 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9367 if (do_mode) | |
9368 { | |
9369 MSG_PUTS_ATTR("--", attr); | |
9370 #if defined(FEAT_XIM) | |
1668 | 9371 # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
7 | 9372 if (xic != NULL && im_get_status() && !p_imdisable |
9373 && curbuf->b_p_iminsert == B_IMODE_IM) | |
1668 | 9374 # else |
9375 if ( | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9376 # ifdef FEAT_GUI_GTK |
1668 | 9377 preedit_get_status() |
9378 # else | |
9379 im_get_status() | |
9380 # endif | |
9381 ) | |
9382 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9383 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9384 MSG_PUTS_ATTR(" IM", attr); |
9385 # else | |
9386 MSG_PUTS_ATTR(" XIM", attr); | |
9387 # endif | |
9388 #endif | |
9389 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9390 if (gui.in_use) | |
9391 { | |
9392 if (hangul_input_state_get()) | |
236 | 9393 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9394 } |
9395 #endif | |
9396 #ifdef FEAT_INS_EXPAND | |
9397 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9398 { | |
9399 /* These messages can get long, avoid a wrap in a narrow | |
9400 * window. Prefer showing edit_submode_extra. */ | |
9401 length = (Rows - msg_row) * Columns - 3; | |
9402 if (edit_submode_extra != NULL) | |
9403 length -= vim_strsize(edit_submode_extra); | |
9404 if (length > 0) | |
9405 { | |
9406 if (edit_submode_pre != NULL) | |
9407 length -= vim_strsize(edit_submode_pre); | |
9408 if (length - vim_strsize(edit_submode) > 0) | |
9409 { | |
9410 if (edit_submode_pre != NULL) | |
9411 msg_puts_attr(edit_submode_pre, attr); | |
9412 msg_puts_attr(edit_submode, attr); | |
9413 } | |
9414 if (edit_submode_extra != NULL) | |
9415 { | |
9416 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9417 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9418 sub_attr = hl_attr(edit_submode_highl); | |
9419 else | |
9420 sub_attr = attr; | |
9421 msg_puts_attr(edit_submode_extra, sub_attr); | |
9422 } | |
9423 } | |
9424 length = 0; | |
9425 } | |
9426 else | |
9427 #endif | |
9428 { | |
9429 #ifdef FEAT_VREPLACE | |
9430 if (State & VREPLACE_FLAG) | |
9431 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9432 else | |
9433 #endif | |
9434 if (State & REPLACE_FLAG) | |
9435 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9436 else if (State & INSERT) | |
9437 { | |
9438 #ifdef FEAT_RIGHTLEFT | |
9439 if (p_ri) | |
9440 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9441 #endif | |
9442 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9443 } | |
9444 else if (restart_edit == 'I') | |
9445 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9446 else if (restart_edit == 'R') | |
9447 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9448 else if (restart_edit == 'V') | |
9449 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9450 #ifdef FEAT_RIGHTLEFT | |
9451 if (p_hkmap) | |
9452 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9453 # ifdef FEAT_FKMAP | |
9454 if (p_fkmap) | |
9455 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9456 # endif | |
9457 #endif | |
9458 #ifdef FEAT_KEYMAP | |
9459 if (State & LANGMAP) | |
9460 { | |
9461 # ifdef FEAT_ARABIC | |
9462 if (curwin->w_p_arab) | |
9463 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9464 else | |
9465 # endif | |
9466 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9467 } | |
9468 #endif | |
9469 if ((State & INSERT) && p_paste) | |
9470 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9471 | |
9472 #ifdef FEAT_VISUAL | |
9473 if (VIsual_active) | |
9474 { | |
9475 char *p; | |
9476 | |
9477 /* Don't concatenate separate words to avoid translation | |
9478 * problems. */ | |
9479 switch ((VIsual_select ? 4 : 0) | |
9480 + (VIsual_mode == Ctrl_V) * 2 | |
9481 + (VIsual_mode == 'V')) | |
9482 { | |
9483 case 0: p = N_(" VISUAL"); break; | |
9484 case 1: p = N_(" VISUAL LINE"); break; | |
9485 case 2: p = N_(" VISUAL BLOCK"); break; | |
9486 case 4: p = N_(" SELECT"); break; | |
9487 case 5: p = N_(" SELECT LINE"); break; | |
9488 default: p = N_(" SELECT BLOCK"); break; | |
9489 } | |
9490 MSG_PUTS_ATTR(_(p), attr); | |
9491 } | |
9492 #endif | |
9493 MSG_PUTS_ATTR(" --", attr); | |
9494 } | |
644 | 9495 |
7 | 9496 need_clear = TRUE; |
9497 } | |
9498 if (Recording | |
9499 #ifdef FEAT_INS_EXPAND | |
9500 && edit_submode == NULL /* otherwise it gets too long */ | |
9501 #endif | |
9502 ) | |
9503 { | |
9504 MSG_PUTS_ATTR(_("recording"), attr); | |
9505 need_clear = TRUE; | |
9506 } | |
644 | 9507 |
9508 mode_displayed = TRUE; | |
7 | 9509 if (need_clear || clear_cmdline) |
9510 msg_clr_eos(); | |
9511 msg_didout = FALSE; /* overwrite this message */ | |
9512 length = msg_col; | |
9513 msg_col = 0; | |
9514 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9515 } | |
9516 else if (clear_cmdline && msg_silent == 0) | |
9517 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9518 msg_clr_cmdline(); | |
9519 | |
9520 #ifdef FEAT_CMDL_INFO | |
9521 # ifdef FEAT_VISUAL | |
9522 /* In Visual mode the size of the selected area must be redrawn. */ | |
9523 if (VIsual_active) | |
9524 clear_showcmd(); | |
9525 # endif | |
9526 | |
9527 /* If the last window has no status line, the ruler is after the mode | |
9528 * message and must be redrawn */ | |
9529 if (redrawing() | |
9530 # ifdef FEAT_WINDOWS | |
9531 && lastwin->w_status_height == 0 | |
9532 # endif | |
9533 ) | |
9534 win_redr_ruler(lastwin, TRUE); | |
9535 #endif | |
9536 redraw_cmdline = FALSE; | |
9537 clear_cmdline = FALSE; | |
9538 | |
9539 return length; | |
9540 } | |
9541 | |
9542 /* | |
9543 * Position for a mode message. | |
9544 */ | |
9545 static void | |
9546 msg_pos_mode() | |
9547 { | |
9548 msg_col = 0; | |
9549 msg_row = Rows - 1; | |
9550 } | |
9551 | |
9552 /* | |
9553 * Delete mode message. Used when ESC is typed which is expected to end | |
9554 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9555 * Caller should check "mode_displayed". |
7 | 9556 */ |
9557 void | |
9558 unshowmode(force) | |
9559 int force; | |
9560 { | |
9561 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9562 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9563 */ |
9564 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9565 redraw_cmdline = TRUE; /* delete mode later */ | |
9566 else | |
9567 { | |
9568 msg_pos_mode(); | |
9569 if (Recording) | |
9570 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9571 msg_clr_eos(); | |
9572 } | |
9573 } | |
9574 | |
667 | 9575 #if defined(FEAT_WINDOWS) |
9576 /* | |
9577 * Draw the tab pages line at the top of the Vim window. | |
9578 */ | |
9579 static void | |
677 | 9580 draw_tabline() |
667 | 9581 { |
9582 int tabcount = 0; | |
9583 tabpage_T *tp; | |
9584 int tabwidth; | |
9585 int col = 0; | |
673 | 9586 int scol = 0; |
667 | 9587 int attr; |
9588 win_T *wp; | |
671 | 9589 win_T *cwp; |
9590 int wincount; | |
9591 int modified; | |
667 | 9592 int c; |
9593 int len; | |
9594 int attr_sel = hl_attr(HLF_TPS); | |
9595 int attr_nosel = hl_attr(HLF_TP); | |
9596 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9597 char_u *p; |
677 | 9598 int room; |
9599 int use_sep_chars = (t_colors < 8 | |
9600 #ifdef FEAT_GUI | |
9601 && !gui.in_use | |
9602 #endif | |
9603 ); | |
673 | 9604 |
9605 redraw_tabline = FALSE; | |
667 | 9606 |
685 | 9607 #ifdef FEAT_GUI_TABLINE |
798 | 9608 /* Take care of a GUI tabline. */ |
685 | 9609 if (gui_use_tabline()) |
9610 { | |
9611 gui_update_tabline(); | |
9612 return; | |
9613 } | |
9614 #endif | |
9615 | |
9616 if (tabline_height() < 1) | |
667 | 9617 return; |
9618 | |
677 | 9619 #if defined(FEAT_STL_OPT) |
681 | 9620 |
9621 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9622 for (scol = 0; scol < Columns; ++scol) | |
9623 TabPageIdxs[scol] = 0; | |
9624 | |
677 | 9625 /* Use the 'tabline' option if it's set. */ |
9626 if (*p_tal != NUL) | |
9627 { | |
680 | 9628 int save_called_emsg = called_emsg; |
9629 | |
9630 /* Check for an error. If there is one we would loop in redrawing the | |
9631 * screen. Avoid that by making 'tabline' empty. */ | |
9632 called_emsg = FALSE; | |
677 | 9633 win_redr_custom(NULL, FALSE); |
680 | 9634 if (called_emsg) |
9635 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9636 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9637 called_emsg |= save_called_emsg; |
9638 } | |
9639 else | |
9640 #endif | |
9641 { | |
9642 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9643 ++tabcount; | |
9644 | |
9645 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9646 if (tabwidth < 6) | |
9647 tabwidth = 6; | |
9648 | |
9649 attr = attr_nosel; | |
9650 tabcount = 0; | |
681 | 9651 scol = 0; |
699 | 9652 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9653 tp = tp->tp_next) | |
680 | 9654 { |
9655 scol = col; | |
9656 | |
9657 if (tp->tp_topframe == topframe) | |
9658 attr = attr_sel; | |
9659 if (use_sep_chars && col > 0) | |
9660 screen_putchar('|', 0, col++, attr); | |
9661 | |
9662 if (tp->tp_topframe != topframe) | |
9663 attr = attr_nosel; | |
9664 | |
9665 screen_putchar(' ', 0, col++, attr); | |
9666 | |
9667 if (tp == curtab) | |
9668 { | |
9669 cwp = curwin; | |
9670 wp = firstwin; | |
9671 } | |
9672 else | |
9673 { | |
9674 cwp = tp->tp_curwin; | |
9675 wp = tp->tp_firstwin; | |
9676 } | |
9677 | |
9678 modified = FALSE; | |
9679 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9680 if (bufIsChanged(wp->w_buffer)) | |
9681 modified = TRUE; | |
9682 if (modified || wincount > 1) | |
9683 { | |
9684 if (wincount > 1) | |
9685 { | |
9686 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9687 len = (int)STRLEN(NameBuff); |
699 | 9688 if (col + len >= Columns - 3) |
9689 break; | |
680 | 9690 screen_puts_len(NameBuff, len, 0, col, |
677 | 9691 #if defined(FEAT_SYN_HL) |
680 | 9692 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9693 #else |
680 | 9694 attr |
9695 #endif | |
9696 ); | |
9697 col += len; | |
9698 } | |
9699 if (modified) | |
9700 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9701 screen_putchar(' ', 0, col++, attr); | |
9702 } | |
9703 | |
9704 room = scol - col + tabwidth - 1; | |
9705 if (room > 0) | |
9706 { | |
685 | 9707 /* Get buffer name in NameBuff[] */ |
9708 get_trans_bufname(cwp->w_buffer); | |
819 | 9709 shorten_dir(NameBuff); |
680 | 9710 len = vim_strsize(NameBuff); |
9711 p = NameBuff; | |
677 | 9712 #ifdef FEAT_MBYTE |
680 | 9713 if (has_mbyte) |
9714 while (len > room) | |
9715 { | |
9716 len -= ptr2cells(p); | |
9717 mb_ptr_adv(p); | |
9718 } | |
9719 else | |
9720 #endif | |
9721 if (len > room) | |
677 | 9722 { |
680 | 9723 p += len - room; |
9724 len = room; | |
677 | 9725 } |
699 | 9726 if (len > Columns - col - 1) |
9727 len = Columns - col - 1; | |
680 | 9728 |
835 | 9729 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9730 col += len; |
9731 } | |
9732 screen_putchar(' ', 0, col++, attr); | |
9733 | |
9734 /* Store the tab page number in TabPageIdxs[], so that | |
9735 * jump_to_mouse() knows where each one is. */ | |
9736 ++tabcount; | |
9737 while (scol < col) | |
9738 TabPageIdxs[scol++] = tabcount; | |
9739 } | |
9740 | |
9741 if (use_sep_chars) | |
9742 c = '_'; | |
9743 else | |
9744 c = ' '; | |
9745 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9746 |
9747 /* Put an "X" for closing the current tab if there are several. */ | |
9748 if (first_tabpage->tp_next != NULL) | |
9749 { | |
9750 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9751 TabPageIdxs[Columns - 1] = -999; | |
9752 } | |
9753 } | |
834 | 9754 |
9755 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9756 * set. */ | |
9757 redraw_tabline = FALSE; | |
667 | 9758 } |
685 | 9759 |
9760 /* | |
9761 * Get buffer name for "buf" into NameBuff[]. | |
9762 * Takes care of special buffer names and translates special characters. | |
9763 */ | |
9764 void | |
9765 get_trans_bufname(buf) | |
9766 buf_T *buf; | |
9767 { | |
9768 if (buf_spname(buf) != NULL) | |
9769 STRCPY(NameBuff, buf_spname(buf)); | |
9770 else | |
9771 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9772 trans_characters(NameBuff, MAXPATHL); | |
9773 } | |
667 | 9774 #endif |
9775 | |
7 | 9776 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9777 /* | |
9778 * Get the character to use in a status line. Get its attributes in "*attr". | |
9779 */ | |
9780 static int | |
9781 fillchar_status(attr, is_curwin) | |
9782 int *attr; | |
9783 int is_curwin; | |
9784 { | |
9785 int fill; | |
9786 if (is_curwin) | |
9787 { | |
9788 *attr = hl_attr(HLF_S); | |
9789 fill = fill_stl; | |
9790 } | |
9791 else | |
9792 { | |
9793 *attr = hl_attr(HLF_SNC); | |
9794 fill = fill_stlnc; | |
9795 } | |
9796 /* Use fill when there is highlighting, and highlighting of current | |
9797 * window differs, or the fillchars differ, or this is not the | |
9798 * current window */ | |
9799 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9800 || !is_curwin || firstwin == lastwin) | |
9801 || (fill_stl != fill_stlnc))) | |
9802 return fill; | |
9803 if (is_curwin) | |
9804 return '^'; | |
9805 return '='; | |
9806 } | |
9807 #endif | |
9808 | |
9809 #ifdef FEAT_VERTSPLIT | |
9810 /* | |
9811 * Get the character to use in a separator between vertically split windows. | |
9812 * Get its attributes in "*attr". | |
9813 */ | |
9814 static int | |
9815 fillchar_vsep(attr) | |
9816 int *attr; | |
9817 { | |
9818 *attr = hl_attr(HLF_C); | |
9819 if (*attr == 0 && fill_vert == ' ') | |
9820 return '|'; | |
9821 else | |
9822 return fill_vert; | |
9823 } | |
9824 #endif | |
9825 | |
9826 /* | |
9827 * Return TRUE if redrawing should currently be done. | |
9828 */ | |
9829 int | |
9830 redrawing() | |
9831 { | |
9832 return (!RedrawingDisabled | |
9833 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9834 } | |
9835 | |
9836 /* | |
9837 * Return TRUE if printing messages should currently be done. | |
9838 */ | |
9839 int | |
9840 messaging() | |
9841 { | |
9842 return (!(p_lz && char_avail() && !KeyTyped)); | |
9843 } | |
9844 | |
9845 /* | |
9846 * Show current status info in ruler and various other places | |
9847 * If always is FALSE, only show ruler if position has changed. | |
9848 */ | |
9849 void | |
9850 showruler(always) | |
9851 int always; | |
9852 { | |
9853 if (!always && !redrawing()) | |
9854 return; | |
574 | 9855 #ifdef FEAT_INS_EXPAND |
9856 if (pum_visible()) | |
9857 { | |
639 | 9858 # ifdef FEAT_WINDOWS |
574 | 9859 /* Don't redraw right now, do it later. */ |
9860 curwin->w_redr_status = TRUE; | |
639 | 9861 # endif |
574 | 9862 return; |
9863 } | |
9864 #endif | |
7 | 9865 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9866 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9867 { |
1983 | 9868 redraw_custom_statusline(curwin); |
680 | 9869 } |
7 | 9870 else |
9871 #endif | |
9872 #ifdef FEAT_CMDL_INFO | |
9873 win_redr_ruler(curwin, always); | |
9874 #endif | |
9875 | |
9876 #ifdef FEAT_TITLE | |
9877 if (need_maketitle | |
9878 # ifdef FEAT_STL_OPT | |
9879 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9880 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9881 # endif | |
9882 ) | |
9883 maketitle(); | |
9884 #endif | |
1588 | 9885 #ifdef FEAT_WINDOWS |
9886 /* Redraw the tab pages line if needed. */ | |
9887 if (redraw_tabline) | |
9888 draw_tabline(); | |
9889 #endif | |
7 | 9890 } |
9891 | |
9892 #ifdef FEAT_CMDL_INFO | |
9893 static void | |
9894 win_redr_ruler(wp, always) | |
9895 win_T *wp; | |
9896 int always; | |
9897 { | |
1869 | 9898 #define RULER_BUF_LEN 70 |
9899 char_u buffer[RULER_BUF_LEN]; | |
7 | 9900 int row; |
9901 int fillchar; | |
9902 int attr; | |
9903 int empty_line = FALSE; | |
9904 colnr_T virtcol; | |
9905 int i; | |
1869 | 9906 size_t len; |
7 | 9907 int o; |
9908 #ifdef FEAT_VERTSPLIT | |
9909 int this_ru_col; | |
9910 int off = 0; | |
9911 int width = Columns; | |
9912 # define WITH_OFF(x) x | |
9913 # define WITH_WIDTH(x) x | |
9914 #else | |
9915 # define WITH_OFF(x) 0 | |
9916 # define WITH_WIDTH(x) Columns | |
9917 # define this_ru_col ru_col | |
9918 #endif | |
9919 | |
9920 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9921 if (!p_ru) | |
9922 return; | |
9923 | |
9924 /* | |
9925 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
9926 * after deleting lines, before cursor.lnum is corrected. | |
9927 */ | |
9928 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
9929 return; | |
9930 | |
9931 #ifdef FEAT_INS_EXPAND | |
9932 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
9933 * the (long) mode message. */ | |
9934 # ifdef FEAT_WINDOWS | |
9935 if (wp == lastwin && lastwin->w_status_height == 0) | |
9936 # endif | |
9937 if (edit_submode != NULL) | |
9938 return; | |
540 | 9939 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
9940 if (pum_visible()) | |
9941 return; | |
7 | 9942 #endif |
9943 | |
9944 #ifdef FEAT_STL_OPT | |
9945 if (*p_ruf) | |
9946 { | |
680 | 9947 int save_called_emsg = called_emsg; |
9948 | |
9949 called_emsg = FALSE; | |
7 | 9950 win_redr_custom(wp, TRUE); |
680 | 9951 if (called_emsg) |
9952 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 9953 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9954 called_emsg |= save_called_emsg; |
7 | 9955 return; |
9956 } | |
9957 #endif | |
9958 | |
9959 /* | |
9960 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
9961 */ | |
9962 if (!(State & INSERT) | |
9963 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
9964 empty_line = TRUE; | |
9965 | |
9966 /* | |
9967 * Only draw the ruler when something changed. | |
9968 */ | |
9969 validate_virtcol_win(wp); | |
9970 if ( redraw_cmdline | |
9971 || always | |
9972 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
9973 || wp->w_cursor.col != wp->w_ru_cursor.col | |
9974 || wp->w_virtcol != wp->w_ru_virtcol | |
9975 #ifdef FEAT_VIRTUALEDIT | |
9976 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
9977 #endif | |
9978 || wp->w_topline != wp->w_ru_topline | |
9979 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
9980 #ifdef FEAT_DIFF | |
9981 || wp->w_topfill != wp->w_ru_topfill | |
9982 #endif | |
9983 || empty_line != wp->w_ru_empty) | |
9984 { | |
9985 cursor_off(); | |
9986 #ifdef FEAT_WINDOWS | |
9987 if (wp->w_status_height) | |
9988 { | |
9989 row = W_WINROW(wp) + wp->w_height; | |
9990 fillchar = fillchar_status(&attr, wp == curwin); | |
9991 # ifdef FEAT_VERTSPLIT | |
9992 off = W_WINCOL(wp); | |
9993 width = W_WIDTH(wp); | |
9994 # endif | |
9995 } | |
9996 else | |
9997 #endif | |
9998 { | |
9999 row = Rows - 1; | |
10000 fillchar = ' '; | |
10001 attr = 0; | |
10002 #ifdef FEAT_VERTSPLIT | |
10003 width = Columns; | |
10004 off = 0; | |
10005 #endif | |
10006 } | |
10007 | |
10008 /* In list mode virtcol needs to be recomputed */ | |
10009 virtcol = wp->w_virtcol; | |
10010 if (wp->w_p_list && lcs_tab1 == NUL) | |
10011 { | |
10012 wp->w_p_list = FALSE; | |
10013 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10014 wp->w_p_list = TRUE; | |
10015 } | |
10016 | |
10017 /* | |
10018 * Some sprintfs return the length, some return a pointer. | |
10019 * To avoid portability problems we use strlen() here. | |
10020 */ | |
1869 | 10021 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10022 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10023 ? 0L | |
10024 : (long)(wp->w_cursor.lnum)); | |
1869 | 10025 len = STRLEN(buffer); |
10026 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10027 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10028 (int)virtcol + 1); | |
10029 | |
10030 /* | |
10031 * Add a "50%" if there is room for it. | |
10032 * On the last line, don't print in the last column (scrolls the | |
10033 * screen up on some terminals). | |
10034 */ | |
10035 i = (int)STRLEN(buffer); | |
1869 | 10036 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10037 o = i + vim_strsize(buffer + i + 1); |
10038 #ifdef FEAT_WINDOWS | |
10039 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10040 #endif | |
10041 ++o; | |
10042 #ifdef FEAT_VERTSPLIT | |
10043 this_ru_col = ru_col - (Columns - width); | |
10044 if (this_ru_col < 0) | |
10045 this_ru_col = 0; | |
10046 #endif | |
10047 /* Never use more than half the window/screen width, leave the other | |
10048 * half for the filename. */ | |
10049 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10050 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10051 if (this_ru_col + o < WITH_WIDTH(width)) | |
10052 { | |
10053 while (this_ru_col + o < WITH_WIDTH(width)) | |
10054 { | |
10055 #ifdef FEAT_MBYTE | |
10056 if (has_mbyte) | |
10057 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10058 else | |
10059 #endif | |
10060 buffer[i++] = fillchar; | |
10061 ++o; | |
10062 } | |
1869 | 10063 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10064 } |
10065 /* Truncate at window boundary. */ | |
10066 #ifdef FEAT_MBYTE | |
10067 if (has_mbyte) | |
10068 { | |
10069 o = 0; | |
474 | 10070 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10071 { |
10072 o += (*mb_ptr2cells)(buffer + i); | |
10073 if (this_ru_col + o > WITH_WIDTH(width)) | |
10074 { | |
10075 buffer[i] = NUL; | |
10076 break; | |
10077 } | |
10078 } | |
10079 } | |
10080 else | |
10081 #endif | |
10082 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10083 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10084 | |
10085 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10086 i = redraw_cmdline; | |
10087 screen_fill(row, row + 1, | |
10088 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10089 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10090 fillchar, fillchar, attr); | |
10091 /* don't redraw the cmdline because of showing the ruler */ | |
10092 redraw_cmdline = i; | |
10093 wp->w_ru_cursor = wp->w_cursor; | |
10094 wp->w_ru_virtcol = wp->w_virtcol; | |
10095 wp->w_ru_empty = empty_line; | |
10096 wp->w_ru_topline = wp->w_topline; | |
10097 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10098 #ifdef FEAT_DIFF | |
10099 wp->w_ru_topfill = wp->w_topfill; | |
10100 #endif | |
10101 } | |
10102 } | |
10103 #endif | |
13 | 10104 |
10105 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10106 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10107 * 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
|
10108 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10109 * Otherwise it depends on 'numberwidth' and the line count. |
10110 */ | |
10111 int | |
10112 number_width(wp) | |
10113 win_T *wp; | |
10114 { | |
10115 int n; | |
10116 linenr_T lnum; | |
10117 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10118 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10119 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10120 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
|
10121 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10122 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10123 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10124 |
13 | 10125 if (lnum == wp->w_nrwidth_line_count) |
10126 return wp->w_nrwidth_width; | |
10127 wp->w_nrwidth_line_count = lnum; | |
10128 | |
10129 n = 0; | |
10130 do | |
10131 { | |
856 | 10132 lnum /= 10; |
10133 ++n; | |
13 | 10134 } while (lnum > 0); |
10135 | |
10136 /* 'numberwidth' gives the minimal width plus one */ | |
10137 if (n < wp->w_p_nuw - 1) | |
10138 n = wp->w_p_nuw - 1; | |
10139 | |
10140 wp->w_nrwidth_width = n; | |
10141 return n; | |
10142 } | |
10143 #endif |