Mercurial > vim
annotate src/screen.c @ 2348:8878a9f8db87 vim73
Rename w_p_conceal to w_p_conc for consistency.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 19 Jul 2010 19:52:13 +0200 |
parents | b38c324bdc36 |
children | 586a459f3980 |
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); |
7 | 4058 } |
743 | 4059 #endif |
4060 | |
4061 #ifdef FEAT_SPELL | |
301 | 4062 /* Check spelling (unless at the end of the line). |
319 | 4063 * Only do this when there is no syntax highlighting, the |
4064 * @Spell cluster is not used or the current syntax item | |
4065 * contains the @Spell cluster. */ | |
348 | 4066 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4067 { |
230 | 4068 spell_attr = 0; |
743 | 4069 # ifdef FEAT_SYN_HL |
674 | 4070 if (!attr_pri) |
230 | 4071 char_attr = syntax_attr; |
743 | 4072 # endif |
4073 if (c != 0 && ( | |
4074 # ifdef FEAT_SYN_HL | |
4075 !has_syntax || | |
4076 # endif | |
4077 can_spell)) | |
221 | 4078 { |
348 | 4079 char_u *prev_ptr, *p; |
4080 int len; | |
534 | 4081 hlf_T spell_hlf = HLF_COUNT; |
221 | 4082 # ifdef FEAT_MBYTE |
336 | 4083 if (has_mbyte) |
4084 { | |
4085 prev_ptr = ptr - mb_l; | |
4086 v -= mb_l - 1; | |
4087 } | |
4088 else | |
221 | 4089 # endif |
336 | 4090 prev_ptr = ptr - 1; |
348 | 4091 |
4092 /* Use nextline[] if possible, it has the start of the | |
4093 * next line concatenated. */ | |
4094 if ((prev_ptr - line) - nextlinecol >= 0) | |
4095 p = nextline + (prev_ptr - line) - nextlinecol; | |
4096 else | |
4097 p = prev_ptr; | |
835 | 4098 cap_col -= (int)(prev_ptr - line); |
625 | 4099 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4100 nochange); | |
348 | 4101 word_end = v + len; |
301 | 4102 |
4103 /* In Insert mode only highlight a word that | |
4104 * doesn't touch the cursor. */ | |
534 | 4105 if (spell_hlf != HLF_COUNT |
301 | 4106 && (State & INSERT) != 0 |
4107 && wp->w_cursor.lnum == lnum | |
4108 && wp->w_cursor.col >= | |
4109 (colnr_T)(prev_ptr - line) | |
4110 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4111 { |
534 | 4112 spell_hlf = HLF_COUNT; |
301 | 4113 spell_redraw_lnum = lnum; |
221 | 4114 } |
348 | 4115 |
534 | 4116 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4117 && (p - nextline) + len > nextline_idx) |
4118 { | |
4119 /* Remember that the good word continues at the | |
4120 * start of the next line. */ | |
4121 checked_lnum = lnum + 1; | |
835 | 4122 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4123 } |
386 | 4124 |
534 | 4125 /* Turn index into actual attributes. */ |
4126 if (spell_hlf != HLF_COUNT) | |
4127 spell_attr = highlight_attr[spell_hlf]; | |
4128 | |
386 | 4129 if (cap_col > 0) |
4130 { | |
4131 if (p != prev_ptr | |
4132 && (p - nextline) + cap_col >= nextline_idx) | |
4133 { | |
4134 /* Remember that the word in the next line | |
4135 * must start with a capital. */ | |
4136 capcol_lnum = lnum + 1; | |
835 | 4137 cap_col = (int)((p - nextline) + cap_col |
4138 - nextline_idx); | |
386 | 4139 } |
4140 else | |
4141 /* Compute the actual column. */ | |
835 | 4142 cap_col += (int)(prev_ptr - line); |
386 | 4143 } |
221 | 4144 } |
4145 } | |
4146 if (spell_attr != 0) | |
348 | 4147 { |
674 | 4148 if (!attr_pri) |
348 | 4149 char_attr = hl_combine_attr(char_attr, spell_attr); |
4150 else | |
4151 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4152 } | |
7 | 4153 #endif |
4154 #ifdef FEAT_LINEBREAK | |
4155 /* | |
221 | 4156 * Found last space before word: check for line break. |
7 | 4157 */ |
4158 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4159 && !wp->w_p_list) |
7 | 4160 { |
4161 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4162 # ifdef FEAT_MBYTE | |
4163 has_mbyte ? mb_l : | |
4164 # endif | |
4165 1), (colnr_T)vcol, NULL) - 1; | |
4166 c_extra = ' '; | |
4167 if (vim_iswhite(c)) | |
4168 c = ' '; | |
4169 } | |
4170 #endif | |
4171 | |
4172 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4173 { | |
4174 c = lcs_trail; | |
674 | 4175 if (!attr_pri) |
7 | 4176 { |
4177 n_attr = 1; | |
4178 extra_attr = hl_attr(HLF_8); | |
4179 saved_attr2 = char_attr; /* save current attr */ | |
4180 } | |
4181 #ifdef FEAT_MBYTE | |
4182 mb_c = c; | |
4183 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4184 { | |
4185 mb_utf8 = TRUE; | |
714 | 4186 u8cc[0] = 0; |
819 | 4187 c = 0xc0; |
7 | 4188 } |
4189 else | |
4190 mb_utf8 = FALSE; | |
4191 #endif | |
4192 } | |
4193 } | |
4194 | |
4195 /* | |
4196 * Handling of non-printable characters. | |
4197 */ | |
819 | 4198 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4199 { |
4200 /* | |
4201 * when getting a character from the file, we may have to | |
4202 * turn it into something else on the way to putting it | |
4203 * into "ScreenLines". | |
4204 */ | |
4205 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4206 { | |
4207 /* tab amount depends on current column */ | |
4208 n_extra = (int)wp->w_buffer->b_p_ts | |
4209 - vcol % (int)wp->w_buffer->b_p_ts - 1; | |
4210 #ifdef FEAT_MBYTE | |
4211 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4212 #endif | |
4213 if (wp->w_p_list) | |
4214 { | |
4215 c = lcs_tab1; | |
4216 c_extra = lcs_tab2; | |
4217 n_attr = n_extra + 1; | |
4218 extra_attr = hl_attr(HLF_8); | |
4219 saved_attr2 = char_attr; /* save current attr */ | |
4220 #ifdef FEAT_MBYTE | |
4221 mb_c = c; | |
4222 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4223 { | |
4224 mb_utf8 = TRUE; | |
714 | 4225 u8cc[0] = 0; |
819 | 4226 c = 0xc0; |
7 | 4227 } |
4228 #endif | |
4229 } | |
4230 else | |
4231 { | |
4232 c_extra = ' '; | |
4233 c = ' '; | |
4234 } | |
4235 } | |
36 | 4236 else if (c == NUL |
4237 && ((wp->w_p_list && lcs_eol > 0) | |
4238 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4239 && tocol > vcol | |
39 | 4240 #ifdef FEAT_VISUAL |
36 | 4241 && VIsual_mode != Ctrl_V |
39 | 4242 #endif |
36 | 4243 && ( |
4244 # ifdef FEAT_RIGHTLEFT | |
4245 wp->w_p_rl ? (col >= 0) : | |
4246 # endif | |
4247 (col < W_WIDTH(wp))) | |
4248 && !(noinvcur | |
1850 | 4249 && lnum == wp->w_cursor.lnum |
36 | 4250 && (colnr_T)vcol == wp->w_virtcol))) |
4251 && lcs_eol_one >= 0) | |
7 | 4252 { |
36 | 4253 /* Display a '$' after the line or highlight an extra |
4254 * character if the line break is included. */ | |
7 | 4255 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4256 /* For a diff line the highlighting continues after the | |
4257 * "$". */ | |
4258 if ( | |
4259 # ifdef FEAT_DIFF | |
534 | 4260 diff_hlf == (hlf_T)0 |
7 | 4261 # ifdef LINE_ATTR |
4262 && | |
4263 # endif | |
4264 # endif | |
4265 # ifdef LINE_ATTR | |
4266 line_attr == 0 | |
4267 # endif | |
4268 ) | |
4269 #endif | |
4270 { | |
4271 #ifdef FEAT_VIRTUALEDIT | |
4272 /* In virtualedit, visual selections may extend | |
4273 * beyond end of line. */ | |
4274 if (area_highlighting && virtual_active() | |
4275 && tocol != MAXCOL && vcol < tocol) | |
4276 n_extra = 0; | |
4277 else | |
4278 #endif | |
4279 { | |
4280 p_extra = at_end_str; | |
4281 n_extra = 1; | |
4282 c_extra = NUL; | |
4283 } | |
4284 } | |
36 | 4285 if (wp->w_p_list) |
4286 c = lcs_eol; | |
4287 else | |
4288 c = ' '; | |
7 | 4289 lcs_eol_one = -1; |
4290 --ptr; /* put it back at the NUL */ | |
674 | 4291 if (!attr_pri) |
7 | 4292 { |
4293 extra_attr = hl_attr(HLF_AT); | |
4294 n_attr = 1; | |
4295 } | |
4296 #ifdef FEAT_MBYTE | |
4297 mb_c = c; | |
4298 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4299 { | |
4300 mb_utf8 = TRUE; | |
714 | 4301 u8cc[0] = 0; |
819 | 4302 c = 0xc0; |
7 | 4303 } |
4304 else | |
4305 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4306 #endif | |
4307 } | |
4308 else if (c != NUL) | |
4309 { | |
4310 p_extra = transchar(c); | |
4311 #ifdef FEAT_RIGHTLEFT | |
4312 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4313 rl_mirror(p_extra); /* reverse "<12>" */ | |
4314 #endif | |
4315 n_extra = byte2cells(c) - 1; | |
4316 c_extra = NUL; | |
4317 c = *p_extra++; | |
674 | 4318 if (!attr_pri) |
7 | 4319 { |
4320 n_attr = n_extra + 1; | |
4321 extra_attr = hl_attr(HLF_8); | |
4322 saved_attr2 = char_attr; /* save current attr */ | |
4323 } | |
4324 #ifdef FEAT_MBYTE | |
4325 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4326 #endif | |
4327 } | |
4328 #ifdef FEAT_VIRTUALEDIT | |
4329 else if (VIsual_active | |
4330 && (VIsual_mode == Ctrl_V | |
4331 || VIsual_mode == 'v') | |
4332 && virtual_active() | |
4333 && tocol != MAXCOL | |
4334 && vcol < tocol | |
4335 && ( | |
4336 # ifdef FEAT_RIGHTLEFT | |
4337 wp->w_p_rl ? (col >= 0) : | |
4338 # endif | |
4339 (col < W_WIDTH(wp)))) | |
4340 { | |
4341 c = ' '; | |
4342 --ptr; /* put it back at the NUL */ | |
4343 } | |
4344 #endif | |
910 | 4345 #if defined(LINE_ATTR) |
7 | 4346 else if (( |
4347 # ifdef FEAT_DIFF | |
910 | 4348 diff_hlf != (hlf_T)0 || |
7 | 4349 # endif |
4350 line_attr != 0 | |
4351 ) && ( | |
4352 # ifdef FEAT_RIGHTLEFT | |
4353 wp->w_p_rl ? (col >= 0) : | |
4354 # endif | |
4355 (col < W_WIDTH(wp)))) | |
4356 { | |
4357 /* Highlight until the right side of the window */ | |
4358 c = ' '; | |
4359 --ptr; /* put it back at the NUL */ | |
867 | 4360 |
4361 /* Remember we do the char for line highlighting. */ | |
4362 ++did_line_attr; | |
4363 | |
4364 /* don't do search HL for the rest of the line */ | |
4365 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4366 char_attr = line_attr; | |
7 | 4367 # ifdef FEAT_DIFF |
4368 if (diff_hlf == HLF_TXD) | |
4369 { | |
4370 diff_hlf = HLF_CHD; | |
4371 if (attr == 0 || char_attr != attr) | |
4372 char_attr = hl_attr(diff_hlf); | |
4373 } | |
4374 # endif | |
4375 } | |
4376 #endif | |
4377 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4378 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4379 #ifdef FEAT_CONCEAL |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4380 if ( wp->w_p_conc > 0 |
2285
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4381 && !area_highlighting |
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4382 && (lnum != wp->w_cursor.lnum |
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4383 || curwin != wp || wp->w_buffer->b_p_ma == FALSE) |
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4384 && (syntax_flags & HL_CONCEAL) != 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4385 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4386 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4387 char_attr = conceal_attr; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4388 if (first_conceal |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4389 && (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
|
4390 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4391 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4392 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4393 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4394 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4395 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4396 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4397 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4398 first_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4399 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4400 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4401 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4402 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4403 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
|
4404 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4405 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4406 if (wp->w_p_rl) |
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 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4409 boguscols -= n_extra; |
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 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4412 # endif |
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 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4415 col += n_extra; |
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 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4418 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4419 n_attr = 0; |
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 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4422 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4423 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4424 n_skip = 1; |
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 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4427 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4428 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4429 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4430 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4431 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4432 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4433 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4434 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4435 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
|
4436 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4437 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4438 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4439 { |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4440 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
|
4441 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4442 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4443 #endif /* FEAT_CONCEAL */ |
7 | 4444 } |
4445 | |
4446 /* Don't override visual selection highlighting. */ | |
4447 if (n_attr > 0 | |
4448 && draw_state == WL_LINE | |
674 | 4449 && !attr_pri) |
7 | 4450 char_attr = extra_attr; |
4451 | |
42 | 4452 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4453 /* XIM don't send preedit_start and preedit_end, but they send |
4454 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4455 * im_is_preediting() here. */ | |
4456 if (xic != NULL | |
1850 | 4457 && lnum == wp->w_cursor.lnum |
7 | 4458 && (State & INSERT) |
4459 && !p_imdisable | |
4460 && im_is_preediting() | |
4461 && draw_state == WL_LINE) | |
4462 { | |
4463 colnr_T tcol; | |
4464 | |
4465 if (preedit_end_col == MAXCOL) | |
1850 | 4466 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4467 else |
4468 tcol = preedit_end_col; | |
4469 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4470 { | |
4471 if (feedback_old_attr < 0) | |
4472 { | |
4473 feedback_col = 0; | |
4474 feedback_old_attr = char_attr; | |
4475 } | |
4476 char_attr = im_get_feedback_attr(feedback_col); | |
4477 if (char_attr < 0) | |
4478 char_attr = feedback_old_attr; | |
4479 feedback_col++; | |
4480 } | |
4481 else if (feedback_old_attr >= 0) | |
4482 { | |
4483 char_attr = feedback_old_attr; | |
4484 feedback_old_attr = -1; | |
4485 feedback_col = 0; | |
4486 } | |
4487 } | |
4488 #endif | |
4489 /* | |
4490 * Handle the case where we are in column 0 but not on the first | |
4491 * character of the line and the user wants us to show us a | |
4492 * special character (via 'listchars' option "precedes:<char>". | |
4493 */ | |
4494 if (lcs_prec_todo != NUL | |
4495 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4496 #ifdef FEAT_DIFF | |
4497 && filler_todo <= 0 | |
4498 #endif | |
4499 && draw_state > WL_NR | |
4500 && c != NUL) | |
4501 { | |
4502 c = lcs_prec; | |
4503 lcs_prec_todo = NUL; | |
4504 #ifdef FEAT_MBYTE | |
4505 mb_c = c; | |
4506 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4507 { | |
4508 mb_utf8 = TRUE; | |
714 | 4509 u8cc[0] = 0; |
819 | 4510 c = 0xc0; |
7 | 4511 } |
4512 else | |
4513 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4514 #endif | |
674 | 4515 if (!attr_pri) |
7 | 4516 { |
4517 saved_attr3 = char_attr; /* save current attr */ | |
4518 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4519 n_attr3 = 1; | |
4520 } | |
4521 } | |
4522 | |
4523 /* | |
867 | 4524 * At end of the text line or just after the last character. |
7 | 4525 */ |
867 | 4526 if (c == NUL |
910 | 4527 #if defined(LINE_ATTR) |
867 | 4528 || did_line_attr == 1 |
4529 #endif | |
4530 ) | |
4531 { | |
4532 #ifdef FEAT_SEARCH_EXTRA | |
4533 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4534 |
4535 /* we're not really at that column when skipping some text */ | |
1439 | 4536 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4537 ++prevcol; |
867 | 4538 #endif |
4539 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4540 /* Invert at least one char, used for Visual and empty line or |
7 | 4541 * highlight match at end of line. If it's beyond the last |
4542 * char on the screen, just overwrite that one (tricky!) Not | |
4543 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4544 #ifdef FEAT_SEARCH_EXTRA |
4545 prevcol_hl_flag = FALSE; | |
4546 if (prevcol == (long)search_hl.startcol) | |
4547 prevcol_hl_flag = TRUE; | |
4548 else | |
4549 { | |
4550 cur = wp->w_match_head; | |
4551 while (cur != NULL) | |
4552 { | |
4553 if (prevcol == (long)cur->hl.startcol) | |
4554 { | |
4555 prevcol_hl_flag = TRUE; | |
4556 break; | |
4557 } | |
4558 cur = cur->next; | |
4559 } | |
4560 } | |
4561 #endif | |
7 | 4562 if (lcs_eol == lcs_eol_one |
1850 | 4563 && ((area_attr != 0 && vcol == fromcol |
4564 #ifdef FEAT_VISUAL | |
4565 && (VIsual_mode != Ctrl_V | |
4566 || lnum == VIsual.lnum | |
4567 || lnum == curwin->w_cursor.lnum) | |
4568 #endif | |
4569 && c == NUL) | |
7 | 4570 #ifdef FEAT_SEARCH_EXTRA |
4571 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4572 || (prevcol_hl_flag == TRUE |
910 | 4573 # if defined(LINE_ATTR) |
867 | 4574 && did_line_attr <= 1 |
4575 # endif | |
4576 ) | |
7 | 4577 #endif |
4578 )) | |
4579 { | |
4580 int n = 0; | |
4581 | |
4582 #ifdef FEAT_RIGHTLEFT | |
4583 if (wp->w_p_rl) | |
4584 { | |
4585 if (col < 0) | |
4586 n = 1; | |
4587 } | |
4588 else | |
4589 #endif | |
4590 { | |
4591 if (col >= W_WIDTH(wp)) | |
4592 n = -1; | |
4593 } | |
4594 if (n != 0) | |
4595 { | |
4596 /* At the window boundary, highlight the last character | |
4597 * instead (better than nothing). */ | |
4598 off += n; | |
4599 col += n; | |
4600 } | |
4601 else | |
4602 { | |
4603 /* Add a blank character to highlight. */ | |
4604 ScreenLines[off] = ' '; | |
4605 #ifdef FEAT_MBYTE | |
4606 if (enc_utf8) | |
4607 ScreenLinesUC[off] = 0; | |
4608 #endif | |
4609 } | |
4610 #ifdef FEAT_SEARCH_EXTRA | |
4611 if (area_attr == 0) | |
4612 { | |
1326 | 4613 /* Use attributes from match with highest priority among |
4614 * 'search_hl' and the match list. */ | |
4615 char_attr = search_hl.attr; | |
4616 cur = wp->w_match_head; | |
4617 shl_flag = FALSE; | |
4618 while (cur != NULL || shl_flag == FALSE) | |
699 | 4619 { |
1326 | 4620 if (shl_flag == FALSE |
4621 && ((cur != NULL | |
4622 && cur->priority > SEARCH_HL_PRIORITY) | |
4623 || cur == NULL)) | |
699 | 4624 { |
1326 | 4625 shl = &search_hl; |
4626 shl_flag = TRUE; | |
699 | 4627 } |
1326 | 4628 else |
4629 shl = &cur->hl; | |
4630 if ((ptr - line) - 1 == (long)shl->startcol) | |
4631 char_attr = shl->attr; | |
4632 if (shl != &search_hl && cur != NULL) | |
4633 cur = cur->next; | |
699 | 4634 } |
7 | 4635 } |
4636 #endif | |
4637 ScreenAttrs[off] = char_attr; | |
4638 #ifdef FEAT_RIGHTLEFT | |
4639 if (wp->w_p_rl) | |
1437 | 4640 { |
7 | 4641 --col; |
1437 | 4642 --off; |
4643 } | |
7 | 4644 else |
4645 #endif | |
1437 | 4646 { |
7 | 4647 ++col; |
1437 | 4648 ++off; |
4649 } | |
743 | 4650 ++vcol; |
1437 | 4651 #ifdef FEAT_SYN_HL |
4652 eol_hl_off = 1; | |
4653 #endif | |
743 | 4654 } |
867 | 4655 } |
4656 | |
4657 /* | |
4658 * At end of the text line. | |
4659 */ | |
4660 if (c == NUL) | |
4661 { | |
743 | 4662 #ifdef FEAT_SYN_HL |
1850 | 4663 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4664 && lnum == wp->w_cursor.lnum) | |
1437 | 4665 { |
4666 /* highlight last char after line */ | |
4667 --col; | |
4668 --off; | |
4669 --vcol; | |
4670 } | |
4671 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4672 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4673 if (wp->w_p_wrap) |
4674 v = wp->w_skipcol; | |
4675 else | |
4676 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4677 |
820 | 4678 /* check if line ends before left margin */ |
4679 if (vcol < v + col - win_col_off(wp)) | |
4680 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
|
4681 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4682 /* 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
|
4683 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4684 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4685 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4686 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4687 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4688 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4689 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
|
4690 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4691 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4692 && (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
|
4693 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4694 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
|
4695 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4696 || draw_color_col) |
743 | 4697 # ifdef FEAT_RIGHTLEFT |
4698 && !wp->w_p_rl | |
4699 # endif | |
4700 ) | |
4701 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4702 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4703 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4704 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4705 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4706 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4707 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4708 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4709 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
|
4710 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4711 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4712 |
743 | 4713 while (col < W_WIDTH(wp)) |
4714 { | |
4715 ScreenLines[off] = ' '; | |
4716 #ifdef FEAT_MBYTE | |
4717 if (enc_utf8) | |
4718 ScreenLinesUC[off] = 0; | |
4719 #endif | |
4720 ++col; | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4721 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
|
4722 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
|
4723 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
|
4724 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4725 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4726 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4727 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4728 if (VCOL_HLC >= rightmost_vcol) |
743 | 4729 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4730 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4731 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4732 draw_color_col = advance_color_col(VCOL_HLC, |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4733 &color_cols); |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4734 |
743 | 4735 ++vcol; |
4736 } | |
4737 } | |
4738 #endif | |
7 | 4739 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4740 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
|
4741 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4742 row++; |
4743 | |
4744 /* | |
4745 * Update w_cline_height and w_cline_folded if the cursor line was | |
4746 * updated (saves a call to plines() later). | |
4747 */ | |
4748 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4749 { | |
4750 curwin->w_cline_row = startrow; | |
4751 curwin->w_cline_height = row - startrow; | |
4752 #ifdef FEAT_FOLDING | |
4753 curwin->w_cline_folded = FALSE; | |
4754 #endif | |
4755 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4756 } | |
4757 | |
4758 break; | |
4759 } | |
4760 | |
4761 /* line continues beyond line end */ | |
4762 if (lcs_ext | |
4763 && !wp->w_p_wrap | |
4764 #ifdef FEAT_DIFF | |
4765 && filler_todo <= 0 | |
4766 #endif | |
4767 && ( | |
4768 #ifdef FEAT_RIGHTLEFT | |
4769 wp->w_p_rl ? col == 0 : | |
4770 #endif | |
4771 col == W_WIDTH(wp) - 1) | |
4772 && (*ptr != NUL | |
1555 | 4773 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4774 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4775 { | |
4776 c = lcs_ext; | |
4777 char_attr = hl_attr(HLF_AT); | |
4778 #ifdef FEAT_MBYTE | |
4779 mb_c = c; | |
4780 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4781 { | |
4782 mb_utf8 = TRUE; | |
714 | 4783 u8cc[0] = 0; |
819 | 4784 c = 0xc0; |
7 | 4785 } |
4786 else | |
4787 mb_utf8 = FALSE; | |
4788 #endif | |
4789 } | |
4790 | |
743 | 4791 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4792 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4793 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4794 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
|
4795 |
743 | 4796 /* 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
|
4797 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4798 * 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
|
4799 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4800 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4801 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
|
4802 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4803 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
|
4804 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4805 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4806 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4807 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
|
4808 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4809 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
|
4810 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4811 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4812 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
|
4813 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4814 } |
743 | 4815 #endif |
4816 | |
7 | 4817 /* |
4818 * Store character to be displayed. | |
4819 * Skip characters that are left of the screen for 'nowrap'. | |
4820 */ | |
4821 vcol_prev = vcol; | |
4822 if (draw_state < WL_LINE || n_skip <= 0) | |
4823 { | |
4824 /* | |
4825 * Store the character. | |
4826 */ | |
4827 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4828 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4829 { | |
4830 /* A double-wide character is: put first halve in left cell. */ | |
4831 --off; | |
4832 --col; | |
4833 } | |
4834 #endif | |
4835 ScreenLines[off] = c; | |
4836 #ifdef FEAT_MBYTE | |
4837 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4838 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4839 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4840 ScreenLines[off] = 0x8e; |
7 | 4841 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4842 } |
7 | 4843 else if (enc_utf8) |
4844 { | |
4845 if (mb_utf8) | |
4846 { | |
1326 | 4847 int i; |
4848 | |
7 | 4849 ScreenLinesUC[off] = mb_c; |
819 | 4850 if ((c & 0xff) == 0) |
4851 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4852 for (i = 0; i < Screen_mco; ++i) |
4853 { | |
4854 ScreenLinesC[i][off] = u8cc[i]; | |
4855 if (u8cc[i] == 0) | |
4856 break; | |
4857 } | |
7 | 4858 } |
4859 else | |
4860 ScreenLinesUC[off] = 0; | |
4861 } | |
4862 if (multi_attr) | |
4863 { | |
4864 ScreenAttrs[off] = multi_attr; | |
4865 multi_attr = 0; | |
4866 } | |
4867 else | |
4868 #endif | |
4869 ScreenAttrs[off] = char_attr; | |
4870 | |
4871 #ifdef FEAT_MBYTE | |
4872 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4873 { | |
4874 /* Need to fill two screen columns. */ | |
4875 ++off; | |
4876 ++col; | |
4877 if (enc_utf8) | |
4878 /* UTF-8: Put a 0 in the second screen char. */ | |
4879 ScreenLines[off] = 0; | |
4880 else | |
4881 /* DBCS: Put second byte in the second screen char. */ | |
4882 ScreenLines[off] = mb_c & 0xff; | |
4883 ++vcol; | |
4884 /* When "tocol" is halfway a character, set it to the end of | |
4885 * the character, otherwise highlighting won't stop. */ | |
4886 if (tocol == vcol) | |
4887 ++tocol; | |
4888 #ifdef FEAT_RIGHTLEFT | |
4889 if (wp->w_p_rl) | |
4890 { | |
4891 /* now it's time to backup one cell */ | |
4892 --off; | |
4893 --col; | |
4894 } | |
4895 #endif | |
4896 } | |
4897 #endif | |
4898 #ifdef FEAT_RIGHTLEFT | |
4899 if (wp->w_p_rl) | |
4900 { | |
4901 --off; | |
4902 --col; | |
4903 } | |
4904 else | |
4905 #endif | |
4906 { | |
4907 ++off; | |
4908 ++col; | |
4909 } | |
4910 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4911 #ifdef FEAT_CONCEAL |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4912 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
|
4913 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4914 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4915 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4916 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4917 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4918 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4919 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4920 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4921 * Special voodoo required if 'wrap' is on. |
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 * 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
|
4924 * 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
|
4925 * 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
|
4926 * 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
|
4927 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4928 * 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
|
4929 * 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
|
4930 * 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
|
4931 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4932 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4933 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4934 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4935 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4936 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4937 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4938 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4939 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4940 boguscols -= n_extra; |
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 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4943 # endif |
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 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4946 boguscols += n_extra; |
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 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4949 n_attr = 0; |
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 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4952 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4953 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4954 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
|
4955 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4956 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4957 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4958 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4959 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4960 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4961 --col; |
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 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4964 # endif |
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 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4967 ++col; |
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 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4970 # endif |
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 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4973 if (wp->w_p_rl) |
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 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4976 --col; |
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 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4979 # endif |
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 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4982 ++col; |
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 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4985 else |
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 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4988 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4989 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4990 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4991 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4992 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4993 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4994 |
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 #endif /* FEAT_CONCEAL */ |
7 | 4997 else |
4998 --n_skip; | |
4999 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5000 /* 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
|
5001 * column. */ |
1849 | 5002 if (draw_state > WL_NR |
7 | 5003 #ifdef FEAT_DIFF |
5004 && filler_todo <= 0 | |
5005 #endif | |
5006 ) | |
5007 ++vcol; | |
5008 | |
743 | 5009 #ifdef FEAT_SYN_HL |
5010 if (vcol_save_attr >= 0) | |
5011 char_attr = vcol_save_attr; | |
5012 #endif | |
5013 | |
7 | 5014 /* restore attributes after "predeces" in 'listchars' */ |
5015 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5016 char_attr = saved_attr3; | |
5017 | |
5018 /* restore attributes after last 'listchars' or 'number' char */ | |
5019 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5020 char_attr = saved_attr2; | |
5021 | |
5022 /* | |
5023 * At end of screen line and there is more to come: Display the line | |
1378 | 5024 * so far. If there is no more to display it is caught above. |
7 | 5025 */ |
5026 if (( | |
5027 #ifdef FEAT_RIGHTLEFT | |
5028 wp->w_p_rl ? (col < 0) : | |
5029 #endif | |
5030 (col >= W_WIDTH(wp))) | |
5031 && (*ptr != NUL | |
5032 #ifdef FEAT_DIFF | |
5033 || filler_todo > 0 | |
5034 #endif | |
5035 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) | |
5036 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) | |
5037 ) | |
5038 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5039 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5040 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
|
5041 (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
|
5042 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5043 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5044 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
|
5045 (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
|
5046 #endif |
7 | 5047 ++row; |
5048 ++screen_row; | |
5049 | |
5050 /* When not wrapping and finished diff lines, or when displayed | |
5051 * '$' and highlighting until last column, break here. */ | |
5052 if ((!wp->w_p_wrap | |
5053 #ifdef FEAT_DIFF | |
5054 && filler_todo <= 0 | |
5055 #endif | |
5056 ) || lcs_eol_one == -1) | |
5057 break; | |
5058 | |
5059 /* When the window is too narrow draw all "@" lines. */ | |
5060 if (draw_state != WL_LINE | |
5061 #ifdef FEAT_DIFF | |
5062 && filler_todo <= 0 | |
5063 #endif | |
5064 ) | |
5065 { | |
5066 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5067 #ifdef FEAT_VERTSPLIT | |
5068 draw_vsep_win(wp, row); | |
5069 #endif | |
5070 row = endrow; | |
5071 } | |
5072 | |
5073 /* When line got too long for screen break here. */ | |
5074 if (row == endrow) | |
5075 { | |
5076 ++row; | |
5077 break; | |
5078 } | |
5079 | |
5080 if (screen_cur_row == screen_row - 1 | |
5081 #ifdef FEAT_DIFF | |
5082 && filler_todo <= 0 | |
5083 #endif | |
5084 && W_WIDTH(wp) == Columns) | |
5085 { | |
5086 /* Remember that the line wraps, used for modeless copy. */ | |
5087 LineWraps[screen_row - 1] = TRUE; | |
5088 | |
5089 /* | |
5090 * Special trick to make copy/paste of wrapped lines work with | |
5091 * xterm/screen: write an extra character beyond the end of | |
5092 * the line. This will work with all terminal types | |
5093 * (regardless of the xn,am settings). | |
5094 * Only do this on a fast tty. | |
5095 * Only do this if the cursor is on the current line | |
5096 * (something has been written in it). | |
5097 * Don't do this for the GUI. | |
5098 * Don't do this for double-width characters. | |
5099 * Don't do this for a window not at the right screen border. | |
5100 */ | |
5101 if (p_tf | |
5102 #ifdef FEAT_GUI | |
5103 && !gui.in_use | |
5104 #endif | |
5105 #ifdef FEAT_MBYTE | |
5106 && !(has_mbyte | |
1378 | 5107 && ((*mb_off2cells)(LineOffset[screen_row], |
5108 LineOffset[screen_row] + screen_Columns) | |
5109 == 2 | |
7 | 5110 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5111 + (int)Columns - 2, |
5112 LineOffset[screen_row] + screen_Columns) | |
5113 == 2)) | |
7 | 5114 #endif |
5115 ) | |
5116 { | |
5117 /* First make sure we are at the end of the screen line, | |
5118 * then output the same character again to let the | |
5119 * terminal know about the wrap. If the terminal doesn't | |
5120 * auto-wrap, we overwrite the character. */ | |
5121 if (screen_cur_col != W_WIDTH(wp)) | |
5122 screen_char(LineOffset[screen_row - 1] | |
5123 + (unsigned)Columns - 1, | |
5124 screen_row - 1, (int)(Columns - 1)); | |
5125 | |
5126 #ifdef FEAT_MBYTE | |
5127 /* When there is a multi-byte character, just output a | |
5128 * space to keep it simple. */ | |
148 | 5129 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5130 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5131 out_char(' '); |
5132 else | |
5133 #endif | |
5134 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5135 + (Columns - 1)]); | |
5136 /* force a redraw of the first char on the next line */ | |
5137 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5138 screen_start(); /* don't know where cursor is now */ | |
5139 } | |
5140 } | |
5141 | |
5142 col = 0; | |
5143 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5144 #ifdef FEAT_RIGHTLEFT | |
5145 if (wp->w_p_rl) | |
5146 { | |
5147 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5148 off += col; | |
5149 } | |
5150 #endif | |
5151 | |
5152 /* reset the drawing state for the start of a wrapped line */ | |
5153 draw_state = WL_START; | |
5154 saved_n_extra = n_extra; | |
5155 saved_p_extra = p_extra; | |
5156 saved_c_extra = c_extra; | |
5157 saved_char_attr = char_attr; | |
5158 n_extra = 0; | |
5159 lcs_prec_todo = lcs_prec; | |
5160 #ifdef FEAT_LINEBREAK | |
5161 # ifdef FEAT_DIFF | |
5162 if (filler_todo <= 0) | |
5163 # endif | |
5164 need_showbreak = TRUE; | |
5165 #endif | |
5166 #ifdef FEAT_DIFF | |
5167 --filler_todo; | |
5168 /* When the filler lines are actually below the last line of the | |
5169 * file, don't draw the line itself, break here. */ | |
5170 if (filler_todo == 0 && wp->w_botfill) | |
5171 break; | |
5172 #endif | |
5173 } | |
5174 | |
5175 } /* for every character in the line */ | |
5176 | |
743 | 5177 #ifdef FEAT_SPELL |
386 | 5178 /* After an empty line check first word for capital. */ |
5179 if (*skipwhite(line) == NUL) | |
5180 { | |
5181 capcol_lnum = lnum + 1; | |
5182 cap_col = 0; | |
5183 } | |
5184 #endif | |
5185 | |
7 | 5186 return row; |
5187 } | |
5188 | |
714 | 5189 #ifdef FEAT_MBYTE |
5190 static int comp_char_differs __ARGS((int, int)); | |
5191 | |
5192 /* | |
5193 * 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
|
5194 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5195 */ |
5196 static int | |
5197 comp_char_differs(off_from, off_to) | |
5198 int off_from; | |
5199 int off_to; | |
5200 { | |
5201 int i; | |
5202 | |
5203 for (i = 0; i < Screen_mco; ++i) | |
5204 { | |
5205 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5206 return TRUE; | |
5207 if (ScreenLinesC[i][off_from] == 0) | |
5208 break; | |
5209 } | |
5210 return FALSE; | |
5211 } | |
5212 #endif | |
5213 | |
7 | 5214 /* |
5215 * Check whether the given character needs redrawing: | |
5216 * - the (first byte of the) character is different | |
5217 * - the attributes are different | |
5218 * - the character is multi-byte and the next byte is different | |
1616 | 5219 * - the character is two cells wide and the second cell differs. |
7 | 5220 */ |
5221 static int | |
5222 char_needs_redraw(off_from, off_to, cols) | |
5223 int off_from; | |
5224 int off_to; | |
5225 int cols; | |
5226 { | |
5227 if (cols > 0 | |
5228 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5229 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5230 | |
5231 #ifdef FEAT_MBYTE | |
5232 || (enc_dbcs != 0 | |
5233 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5234 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5235 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5236 : (cols > 1 && ScreenLines[off_from + 1] | |
5237 != ScreenLines[off_to + 1]))) | |
5238 || (enc_utf8 | |
5239 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5240 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5241 && comp_char_differs(off_from, off_to)) |
5242 || (cols > 1 && ScreenLines[off_from + 1] | |
5243 != ScreenLines[off_to + 1]))) | |
7 | 5244 #endif |
5245 )) | |
5246 return TRUE; | |
5247 return FALSE; | |
5248 } | |
5249 | |
5250 /* | |
5251 * Move one "cooked" screen line to the screen, but only the characters that | |
5252 * have actually changed. Handle insert/delete character. | |
5253 * "coloff" gives the first column on the screen for this line. | |
5254 * "endcol" gives the columns where valid characters are. | |
5255 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5256 * needs to be cleared, negative otherwise. | |
5257 * "rlflag" is TRUE in a rightleft window: | |
5258 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5259 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5260 */ | |
5261 static void | |
5262 screen_line(row, coloff, endcol, clear_width | |
5263 #ifdef FEAT_RIGHTLEFT | |
5264 , rlflag | |
5265 #endif | |
5266 ) | |
5267 int row; | |
5268 int coloff; | |
5269 int endcol; | |
5270 int clear_width; | |
5271 #ifdef FEAT_RIGHTLEFT | |
5272 int rlflag; | |
5273 #endif | |
5274 { | |
5275 unsigned off_from; | |
5276 unsigned off_to; | |
1378 | 5277 #ifdef FEAT_MBYTE |
5278 unsigned max_off_from; | |
5279 unsigned max_off_to; | |
5280 #endif | |
7 | 5281 int col = 0; |
5282 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5283 int hl; | |
5284 #endif | |
5285 int force = FALSE; /* force update rest of the line */ | |
5286 int redraw_this /* bool: does character need redraw? */ | |
5287 #ifdef FEAT_GUI | |
5288 = TRUE /* For GUI when while-loop empty */ | |
5289 #endif | |
5290 ; | |
5291 int redraw_next; /* redraw_this for next character */ | |
5292 #ifdef FEAT_MBYTE | |
5293 int clear_next = FALSE; | |
5294 int char_cells; /* 1: normal char */ | |
5295 /* 2: occupies two display cells */ | |
5296 # define CHAR_CELLS char_cells | |
5297 #else | |
5298 # define CHAR_CELLS 1 | |
5299 #endif | |
5300 | |
5301 # ifdef FEAT_CLIPBOARD | |
5302 clip_may_clear_selection(row, row); | |
5303 # endif | |
5304 | |
5305 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5306 off_to = LineOffset[row] + coloff; | |
1378 | 5307 #ifdef FEAT_MBYTE |
5308 max_off_from = off_from + screen_Columns; | |
5309 max_off_to = LineOffset[row] + screen_Columns; | |
5310 #endif | |
7 | 5311 |
5312 #ifdef FEAT_RIGHTLEFT | |
5313 if (rlflag) | |
5314 { | |
5315 /* Clear rest first, because it's left of the text. */ | |
5316 if (clear_width > 0) | |
5317 { | |
5318 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5319 && ScreenAttrs[off_to] == 0 | |
5320 # ifdef FEAT_MBYTE | |
5321 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5322 # endif | |
5323 ) | |
5324 { | |
5325 ++off_to; | |
5326 ++col; | |
5327 } | |
5328 if (col <= endcol) | |
5329 screen_fill(row, row + 1, col + coloff, | |
5330 endcol + coloff + 1, ' ', ' ', 0); | |
5331 } | |
5332 col = endcol + 1; | |
5333 off_to = LineOffset[row] + col + coloff; | |
5334 off_from += col; | |
5335 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5336 } | |
5337 #endif /* FEAT_RIGHTLEFT */ | |
5338 | |
5339 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5340 | |
5341 while (col < endcol) | |
5342 { | |
5343 #ifdef FEAT_MBYTE | |
5344 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5345 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5346 else |
5347 char_cells = 1; | |
5348 #endif | |
5349 | |
5350 redraw_this = redraw_next; | |
5351 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5352 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5353 | |
5354 #ifdef FEAT_GUI | |
5355 /* If the next character was bold, then redraw the current character to | |
5356 * remove any pixels that might have spilt over into us. This only | |
5357 * happens in the GUI. | |
5358 */ | |
5359 if (redraw_next && gui.in_use) | |
5360 { | |
5361 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5362 if (hl > HL_ALL) |
5363 hl = syn_attr2attr(hl); | |
5364 if (hl & HL_BOLD) | |
7 | 5365 redraw_this = TRUE; |
5366 } | |
5367 #endif | |
5368 | |
5369 if (redraw_this) | |
5370 { | |
5371 /* | |
5372 * Special handling when 'xs' termcap flag set (hpterm): | |
5373 * Attributes for characters are stored at the position where the | |
5374 * cursor is when writing the highlighting code. The | |
5375 * start-highlighting code must be written with the cursor on the | |
5376 * first highlighted character. The stop-highlighting code must | |
5377 * be written with the cursor just after the last highlighted | |
5378 * character. | |
5379 * Overwriting a character doesn't remove it's highlighting. Need | |
5380 * to clear the rest of the line, and force redrawing it | |
5381 * completely. | |
5382 */ | |
5383 if ( p_wiv | |
5384 && !force | |
5385 #ifdef FEAT_GUI | |
5386 && !gui.in_use | |
5387 #endif | |
5388 && ScreenAttrs[off_to] != 0 | |
5389 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5390 { | |
5391 /* | |
5392 * Need to remove highlighting attributes here. | |
5393 */ | |
5394 windgoto(row, col + coloff); | |
5395 out_str(T_CE); /* clear rest of this screen line */ | |
5396 screen_start(); /* don't know where cursor is now */ | |
5397 force = TRUE; /* force redraw of rest of the line */ | |
5398 redraw_next = TRUE; /* or else next char would miss out */ | |
5399 | |
5400 /* | |
5401 * If the previous character was highlighted, need to stop | |
5402 * highlighting at this character. | |
5403 */ | |
5404 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5405 { | |
5406 screen_attr = ScreenAttrs[off_to - 1]; | |
5407 term_windgoto(row, col + coloff); | |
5408 screen_stop_highlight(); | |
5409 } | |
5410 else | |
5411 screen_attr = 0; /* highlighting has stopped */ | |
5412 } | |
5413 #ifdef FEAT_MBYTE | |
5414 if (enc_dbcs != 0) | |
5415 { | |
5416 /* Check if overwriting a double-byte with a single-byte or | |
5417 * the other way around requires another character to be | |
5418 * redrawn. For UTF-8 this isn't needed, because comparing | |
5419 * ScreenLinesUC[] is sufficient. */ | |
5420 if (char_cells == 1 | |
5421 && col + 1 < endcol | |
1378 | 5422 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5423 { |
5424 /* Writing a single-cell character over a double-cell | |
5425 * character: need to redraw the next cell. */ | |
5426 ScreenLines[off_to + 1] = 0; | |
5427 redraw_next = TRUE; | |
5428 } | |
5429 else if (char_cells == 2 | |
5430 && col + 2 < endcol | |
1378 | 5431 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5432 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5433 { |
5434 /* Writing the second half of a double-cell character over | |
5435 * a double-cell character: need to redraw the second | |
5436 * cell. */ | |
5437 ScreenLines[off_to + 2] = 0; | |
5438 redraw_next = TRUE; | |
5439 } | |
5440 | |
5441 if (enc_dbcs == DBCS_JPNU) | |
5442 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5443 } | |
5444 /* When writing a single-width character over a double-width | |
5445 * character and at the end of the redrawn text, need to clear out | |
5446 * the right halve of the old character. | |
5447 * Also required when writing the right halve of a double-width | |
5448 * char over the left halve of an existing one. */ | |
5449 if (has_mbyte && col + char_cells == endcol | |
5450 && ((char_cells == 1 | |
1378 | 5451 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5452 || (char_cells == 2 |
1378 | 5453 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5454 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5455 clear_next = TRUE; |
5456 #endif | |
5457 | |
5458 ScreenLines[off_to] = ScreenLines[off_from]; | |
5459 #ifdef FEAT_MBYTE | |
5460 if (enc_utf8) | |
5461 { | |
5462 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5463 if (ScreenLinesUC[off_from] != 0) | |
5464 { | |
714 | 5465 int i; |
5466 | |
5467 for (i = 0; i < Screen_mco; ++i) | |
5468 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5469 } |
5470 } | |
5471 if (char_cells == 2) | |
5472 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5473 #endif | |
5474 | |
5475 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5476 /* The bold trick makes a single column of pixels appear in the |
5477 * next character. When a bold character is removed, the next | |
7 | 5478 * character should be redrawn too. This happens for our own GUI |
5479 * and for some xterms. */ | |
5480 if ( | |
5481 # ifdef FEAT_GUI | |
5482 gui.in_use | |
5483 # endif | |
5484 # if defined(FEAT_GUI) && defined(UNIX) | |
5485 || | |
5486 # endif | |
5487 # ifdef UNIX | |
5488 term_is_xterm | |
5489 # endif | |
5490 ) | |
5491 { | |
5492 hl = ScreenAttrs[off_to]; | |
743 | 5493 if (hl > HL_ALL) |
5494 hl = syn_attr2attr(hl); | |
5495 if (hl & HL_BOLD) | |
7 | 5496 redraw_next = TRUE; |
5497 } | |
5498 #endif | |
5499 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5500 #ifdef FEAT_MBYTE | |
819 | 5501 /* For simplicity set the attributes of second half of a |
5502 * double-wide character equal to the first half. */ | |
5503 if (char_cells == 2) | |
5504 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5505 | |
7 | 5506 if (enc_dbcs != 0 && char_cells == 2) |
5507 screen_char_2(off_to, row, col + coloff); | |
5508 else | |
5509 #endif | |
5510 screen_char(off_to, row, col + coloff); | |
5511 } | |
5512 else if ( p_wiv | |
5513 #ifdef FEAT_GUI | |
5514 && !gui.in_use | |
5515 #endif | |
5516 && col + coloff > 0) | |
5517 { | |
5518 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5519 { | |
5520 /* | |
5521 * Don't output stop-highlight when moving the cursor, it will | |
5522 * stop the highlighting when it should continue. | |
5523 */ | |
5524 screen_attr = 0; | |
5525 } | |
5526 else if (screen_attr != 0) | |
5527 screen_stop_highlight(); | |
5528 } | |
5529 | |
5530 off_to += CHAR_CELLS; | |
5531 off_from += CHAR_CELLS; | |
5532 col += CHAR_CELLS; | |
5533 } | |
5534 | |
5535 #ifdef FEAT_MBYTE | |
5536 if (clear_next) | |
5537 { | |
5538 /* Clear the second half of a double-wide character of which the left | |
5539 * half was overwritten with a single-wide character. */ | |
5540 ScreenLines[off_to] = ' '; | |
5541 if (enc_utf8) | |
5542 ScreenLinesUC[off_to] = 0; | |
5543 screen_char(off_to, row, col + coloff); | |
5544 } | |
5545 #endif | |
5546 | |
5547 if (clear_width > 0 | |
5548 #ifdef FEAT_RIGHTLEFT | |
5549 && !rlflag | |
5550 #endif | |
5551 ) | |
5552 { | |
5553 #ifdef FEAT_GUI | |
5554 int startCol = col; | |
5555 #endif | |
5556 | |
5557 /* blank out the rest of the line */ | |
5558 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5559 && ScreenAttrs[off_to] == 0 | |
5560 #ifdef FEAT_MBYTE | |
5561 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5562 #endif | |
5563 ) | |
5564 { | |
5565 ++off_to; | |
5566 ++col; | |
5567 } | |
5568 if (col < clear_width) | |
5569 { | |
5570 #ifdef FEAT_GUI | |
5571 /* | |
5572 * In the GUI, clearing the rest of the line may leave pixels | |
5573 * behind if the first character cleared was bold. Some bold | |
5574 * fonts spill over the left. In this case we redraw the previous | |
5575 * character too. If we didn't skip any blanks above, then we | |
5576 * only redraw if the character wasn't already redrawn anyway. | |
5577 */ | |
996 | 5578 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5579 { |
5580 hl = ScreenAttrs[off_to]; | |
5581 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5582 { |
5583 int prev_cells = 1; | |
5584 # ifdef FEAT_MBYTE | |
5585 if (enc_utf8) | |
5586 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5587 * that its width is 2. */ | |
5588 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5589 else if (enc_dbcs != 0) | |
5590 { | |
5591 /* find previous character by counting from first | |
5592 * column and get its width. */ | |
5593 unsigned off = LineOffset[row]; | |
1378 | 5594 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5595 |
5596 while (off < off_to) | |
5597 { | |
1378 | 5598 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5599 off += prev_cells; |
5600 } | |
5601 } | |
5602 | |
5603 if (enc_dbcs != 0 && prev_cells > 1) | |
5604 screen_char_2(off_to - prev_cells, row, | |
5605 col + coloff - prev_cells); | |
5606 else | |
5607 # endif | |
5608 screen_char(off_to - prev_cells, row, | |
5609 col + coloff - prev_cells); | |
5610 } | |
7 | 5611 } |
5612 #endif | |
5613 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5614 ' ', ' ', 0); | |
5615 #ifdef FEAT_VERTSPLIT | |
5616 off_to += clear_width - col; | |
5617 col = clear_width; | |
5618 #endif | |
5619 } | |
5620 } | |
5621 | |
5622 if (clear_width > 0) | |
5623 { | |
5624 #ifdef FEAT_VERTSPLIT | |
5625 /* For a window that's left of another, draw the separator char. */ | |
5626 if (col + coloff < Columns) | |
5627 { | |
5628 int c; | |
5629 | |
5630 c = fillchar_vsep(&hl); | |
5631 if (ScreenLines[off_to] != c | |
5632 # ifdef FEAT_MBYTE | |
714 | 5633 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5634 != (c >= 0x80 ? c : 0)) | |
7 | 5635 # endif |
5636 || ScreenAttrs[off_to] != hl) | |
5637 { | |
5638 ScreenLines[off_to] = c; | |
5639 ScreenAttrs[off_to] = hl; | |
5640 # ifdef FEAT_MBYTE | |
5641 if (enc_utf8) | |
5642 { | |
5643 if (c >= 0x80) | |
5644 { | |
5645 ScreenLinesUC[off_to] = c; | |
714 | 5646 ScreenLinesC[0][off_to] = 0; |
7 | 5647 } |
5648 else | |
5649 ScreenLinesUC[off_to] = 0; | |
5650 } | |
5651 # endif | |
5652 screen_char(off_to, row, col + coloff); | |
5653 } | |
5654 } | |
5655 else | |
5656 #endif | |
5657 LineWraps[row] = FALSE; | |
5658 } | |
5659 } | |
5660 | |
474 | 5661 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5662 /* |
474 | 5663 * Mirror text "str" for right-left displaying. |
5664 * Only works for single-byte characters (e.g., numbers). | |
7 | 5665 */ |
474 | 5666 void |
7 | 5667 rl_mirror(str) |
5668 char_u *str; | |
5669 { | |
5670 char_u *p1, *p2; | |
5671 int t; | |
5672 | |
5673 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5674 { | |
5675 t = *p1; | |
5676 *p1 = *p2; | |
5677 *p2 = t; | |
5678 } | |
5679 } | |
5680 #endif | |
5681 | |
5682 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5683 /* | |
5684 * mark all status lines for redraw; used after first :cd | |
5685 */ | |
5686 void | |
5687 status_redraw_all() | |
5688 { | |
5689 win_T *wp; | |
5690 | |
5691 for (wp = firstwin; wp; wp = wp->w_next) | |
5692 if (wp->w_status_height) | |
5693 { | |
5694 wp->w_redr_status = TRUE; | |
5695 redraw_later(VALID); | |
5696 } | |
5697 } | |
5698 | |
5699 /* | |
5700 * mark all status lines of the current buffer for redraw | |
5701 */ | |
5702 void | |
5703 status_redraw_curbuf() | |
5704 { | |
5705 win_T *wp; | |
5706 | |
5707 for (wp = firstwin; wp; wp = wp->w_next) | |
5708 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5709 { | |
5710 wp->w_redr_status = TRUE; | |
5711 redraw_later(VALID); | |
5712 } | |
5713 } | |
5714 | |
5715 /* | |
5716 * Redraw all status lines that need to be redrawn. | |
5717 */ | |
5718 void | |
5719 redraw_statuslines() | |
5720 { | |
5721 win_T *wp; | |
5722 | |
5723 for (wp = firstwin; wp; wp = wp->w_next) | |
5724 if (wp->w_redr_status) | |
5725 win_redr_status(wp); | |
673 | 5726 if (redraw_tabline) |
677 | 5727 draw_tabline(); |
7 | 5728 } |
5729 #endif | |
5730 | |
5731 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5732 /* | |
5733 * Redraw all status lines at the bottom of frame "frp". | |
5734 */ | |
5735 void | |
5736 win_redraw_last_status(frp) | |
5737 frame_T *frp; | |
5738 { | |
5739 if (frp->fr_layout == FR_LEAF) | |
5740 frp->fr_win->w_redr_status = TRUE; | |
5741 else if (frp->fr_layout == FR_ROW) | |
5742 { | |
5743 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5744 win_redraw_last_status(frp); | |
5745 } | |
5746 else /* frp->fr_layout == FR_COL */ | |
5747 { | |
5748 frp = frp->fr_child; | |
5749 while (frp->fr_next != NULL) | |
5750 frp = frp->fr_next; | |
5751 win_redraw_last_status(frp); | |
5752 } | |
5753 } | |
5754 #endif | |
5755 | |
5756 #ifdef FEAT_VERTSPLIT | |
5757 /* | |
5758 * Draw the verticap separator right of window "wp" starting with line "row". | |
5759 */ | |
5760 static void | |
5761 draw_vsep_win(wp, row) | |
5762 win_T *wp; | |
5763 int row; | |
5764 { | |
5765 int hl; | |
5766 int c; | |
5767 | |
5768 if (wp->w_vsep_width) | |
5769 { | |
5770 /* draw the vertical separator right of this window */ | |
5771 c = fillchar_vsep(&hl); | |
5772 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5773 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5774 c, ' ', hl); | |
5775 } | |
5776 } | |
5777 #endif | |
5778 | |
5779 #ifdef FEAT_WILDMENU | |
5780 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5781 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5782 |
5783 /* | |
1378 | 5784 * Get the length of an item as it will be shown in the status line. |
7 | 5785 */ |
5786 static int | |
5787 status_match_len(xp, s) | |
5788 expand_T *xp; | |
5789 char_u *s; | |
5790 { | |
5791 int len = 0; | |
5792 | |
5793 #ifdef FEAT_MENU | |
5794 int emenu = (xp->xp_context == EXPAND_MENUS | |
5795 || xp->xp_context == EXPAND_MENUNAMES); | |
5796 | |
5797 /* Check for menu separators - replace with '|'. */ | |
5798 if (emenu && menu_is_separator(s)) | |
5799 return 1; | |
5800 #endif | |
5801 | |
5802 while (*s != NUL) | |
5803 { | |
1685 | 5804 s += skip_status_match_char(xp, s); |
42 | 5805 len += ptr2cells(s); |
39 | 5806 mb_ptr_adv(s); |
7 | 5807 } |
5808 | |
5809 return len; | |
5810 } | |
5811 | |
5812 /* | |
1685 | 5813 * Return the number of characters that should be skipped in a status match. |
277 | 5814 * These are backslashes used for escaping. Do show backslashes in help tags. |
5815 */ | |
5816 static int | |
5817 skip_status_match_char(xp, s) | |
5818 expand_T *xp; | |
5819 char_u *s; | |
5820 { | |
1685 | 5821 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5822 #ifdef FEAT_MENU |
5823 || ((xp->xp_context == EXPAND_MENUS | |
5824 || xp->xp_context == EXPAND_MENUNAMES) | |
5825 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5826 #endif | |
1685 | 5827 ) |
5828 { | |
5829 #ifndef BACKSLASH_IN_FILENAME | |
5830 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5831 return 2; | |
5832 #endif | |
5833 return 1; | |
5834 } | |
5835 return 0; | |
277 | 5836 } |
5837 | |
5838 /* | |
7 | 5839 * Show wildchar matches in the status line. |
5840 * Show at least the "match" item. | |
5841 * We start at item 'first_match' in the list and show all matches that fit. | |
5842 * | |
5843 * If inversion is possible we use it. Else '=' characters are used. | |
5844 */ | |
5845 void | |
5846 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5847 expand_T *xp; | |
5848 int num_matches; | |
5849 char_u **matches; /* list of matches */ | |
5850 int match; | |
5851 int showtail; | |
5852 { | |
5853 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5854 int row; | |
5855 char_u *buf; | |
5856 int len; | |
1378 | 5857 int clen; /* length in screen cells */ |
7 | 5858 int fillchar; |
5859 int attr; | |
5860 int i; | |
5861 int highlight = TRUE; | |
5862 char_u *selstart = NULL; | |
5863 int selstart_col = 0; | |
5864 char_u *selend = NULL; | |
5865 static int first_match = 0; | |
5866 int add_left = FALSE; | |
5867 char_u *s; | |
5868 #ifdef FEAT_MENU | |
5869 int emenu; | |
5870 #endif | |
5871 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5872 int l; | |
5873 #endif | |
5874 | |
5875 if (matches == NULL) /* interrupted completion? */ | |
5876 return; | |
5877 | |
39 | 5878 #ifdef FEAT_MBYTE |
5879 if (has_mbyte) | |
5880 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5881 else | |
5882 #endif | |
5883 buf = alloc((unsigned)Columns + 1); | |
7 | 5884 if (buf == NULL) |
5885 return; | |
5886 | |
5887 if (match == -1) /* don't show match but original text */ | |
5888 { | |
5889 match = 0; | |
5890 highlight = FALSE; | |
5891 } | |
5892 /* count 1 for the ending ">" */ | |
5893 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5894 if (match == 0) | |
5895 first_match = 0; | |
5896 else if (match < first_match) | |
5897 { | |
5898 /* jumping left, as far as we can go */ | |
5899 first_match = match; | |
5900 add_left = TRUE; | |
5901 } | |
5902 else | |
5903 { | |
5904 /* check if match fits on the screen */ | |
5905 for (i = first_match; i < match; ++i) | |
5906 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5907 if (first_match > 0) | |
5908 clen += 2; | |
5909 /* jumping right, put match at the left */ | |
5910 if ((long)clen > Columns) | |
5911 { | |
5912 first_match = match; | |
5913 /* if showing the last match, we can add some on the left */ | |
5914 clen = 2; | |
5915 for (i = match; i < num_matches; ++i) | |
5916 { | |
5917 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5918 if ((long)clen >= Columns) | |
5919 break; | |
5920 } | |
5921 if (i == num_matches) | |
5922 add_left = TRUE; | |
5923 } | |
5924 } | |
5925 if (add_left) | |
5926 while (first_match > 0) | |
5927 { | |
5928 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5929 if ((long)clen >= Columns) | |
5930 break; | |
5931 --first_match; | |
5932 } | |
5933 | |
5934 fillchar = fillchar_status(&attr, TRUE); | |
5935 | |
5936 if (first_match == 0) | |
5937 { | |
5938 *buf = NUL; | |
5939 len = 0; | |
5940 } | |
5941 else | |
5942 { | |
5943 STRCPY(buf, "< "); | |
5944 len = 2; | |
5945 } | |
5946 clen = len; | |
5947 | |
5948 i = first_match; | |
5949 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
5950 { | |
5951 if (i == match) | |
5952 { | |
5953 selstart = buf + len; | |
5954 selstart_col = clen; | |
5955 } | |
5956 | |
5957 s = L_MATCH(i); | |
5958 /* Check for menu separators - replace with '|' */ | |
5959 #ifdef FEAT_MENU | |
5960 emenu = (xp->xp_context == EXPAND_MENUS | |
5961 || xp->xp_context == EXPAND_MENUNAMES); | |
5962 if (emenu && menu_is_separator(s)) | |
5963 { | |
5964 STRCPY(buf + len, transchar('|')); | |
5965 l = (int)STRLEN(buf + len); | |
5966 len += l; | |
5967 clen += l; | |
5968 } | |
5969 else | |
5970 #endif | |
5971 for ( ; *s != NUL; ++s) | |
5972 { | |
1685 | 5973 s += skip_status_match_char(xp, s); |
7 | 5974 clen += ptr2cells(s); |
5975 #ifdef FEAT_MBYTE | |
474 | 5976 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 5977 { |
5978 STRNCPY(buf + len, s, l); | |
5979 s += l - 1; | |
5980 len += l; | |
5981 } | |
5982 else | |
5983 #endif | |
5984 { | |
5985 STRCPY(buf + len, transchar_byte(*s)); | |
5986 len += (int)STRLEN(buf + len); | |
5987 } | |
5988 } | |
5989 if (i == match) | |
5990 selend = buf + len; | |
5991 | |
5992 *(buf + len++) = ' '; | |
5993 *(buf + len++) = ' '; | |
5994 clen += 2; | |
5995 if (++i == num_matches) | |
5996 break; | |
5997 } | |
5998 | |
5999 if (i != num_matches) | |
6000 { | |
6001 *(buf + len++) = '>'; | |
6002 ++clen; | |
6003 } | |
6004 | |
6005 buf[len] = NUL; | |
6006 | |
6007 row = cmdline_row - 1; | |
6008 if (row >= 0) | |
6009 { | |
6010 if (wild_menu_showing == 0) | |
6011 { | |
6012 if (msg_scrolled > 0) | |
6013 { | |
6014 /* Put the wildmenu just above the command line. If there is | |
6015 * no room, scroll the screen one line up. */ | |
6016 if (cmdline_row == Rows - 1) | |
6017 { | |
6018 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6019 ++msg_scrolled; | |
6020 } | |
6021 else | |
6022 { | |
6023 ++cmdline_row; | |
6024 ++row; | |
6025 } | |
6026 wild_menu_showing = WM_SCROLLED; | |
6027 } | |
6028 else | |
6029 { | |
6030 /* Create status line if needed by setting 'laststatus' to 2. | |
6031 * Set 'winminheight' to zero to avoid that the window is | |
6032 * resized. */ | |
6033 if (lastwin->w_status_height == 0) | |
6034 { | |
6035 save_p_ls = p_ls; | |
6036 save_p_wmh = p_wmh; | |
6037 p_ls = 2; | |
6038 p_wmh = 0; | |
6039 last_status(FALSE); | |
6040 } | |
6041 wild_menu_showing = WM_SHOWN; | |
6042 } | |
6043 } | |
6044 | |
6045 screen_puts(buf, row, 0, attr); | |
6046 if (selstart != NULL && highlight) | |
6047 { | |
6048 *selend = NUL; | |
6049 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6050 } | |
6051 | |
6052 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6053 } | |
6054 | |
6055 #ifdef FEAT_VERTSPLIT | |
6056 win_redraw_last_status(topframe); | |
6057 #else | |
6058 lastwin->w_redr_status = TRUE; | |
6059 #endif | |
6060 vim_free(buf); | |
6061 } | |
6062 #endif | |
6063 | |
6064 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6065 /* | |
6066 * Redraw the status line of window wp. | |
6067 * | |
6068 * If inversion is possible we use it. Else '=' characters are used. | |
6069 */ | |
6070 void | |
6071 win_redr_status(wp) | |
6072 win_T *wp; | |
6073 { | |
6074 int row; | |
6075 char_u *p; | |
6076 int len; | |
6077 int fillchar; | |
6078 int attr; | |
6079 int this_ru_col; | |
1910 | 6080 static int busy = FALSE; |
6081 | |
6082 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6083 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6084 if (busy) | |
6085 return; | |
6086 busy = TRUE; | |
7 | 6087 |
6088 wp->w_redr_status = FALSE; | |
6089 if (wp->w_status_height == 0) | |
6090 { | |
6091 /* no status line, can only be last window */ | |
6092 redraw_cmdline = TRUE; | |
6093 } | |
540 | 6094 else if (!redrawing() |
6095 #ifdef FEAT_INS_EXPAND | |
6096 /* don't update status line when popup menu is visible and may be | |
6097 * drawn over it */ | |
6098 || pum_visible() | |
6099 #endif | |
6100 ) | |
7 | 6101 { |
6102 /* Don't redraw right now, do it later. */ | |
6103 wp->w_redr_status = TRUE; | |
6104 } | |
6105 #ifdef FEAT_STL_OPT | |
40 | 6106 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6107 { |
6108 /* redraw custom status line */ | |
1983 | 6109 redraw_custom_statusline(wp); |
7 | 6110 } |
6111 #endif | |
6112 else | |
6113 { | |
6114 fillchar = fillchar_status(&attr, wp == curwin); | |
6115 | |
685 | 6116 get_trans_bufname(wp->w_buffer); |
7 | 6117 p = NameBuff; |
6118 len = (int)STRLEN(p); | |
6119 | |
6120 if (wp->w_buffer->b_help | |
6121 #ifdef FEAT_QUICKFIX | |
6122 || wp->w_p_pvw | |
6123 #endif | |
6124 || bufIsChanged(wp->w_buffer) | |
6125 || wp->w_buffer->b_p_ro) | |
6126 *(p + len++) = ' '; | |
6127 if (wp->w_buffer->b_help) | |
6128 { | |
809 | 6129 STRCPY(p + len, _("[Help]")); |
7 | 6130 len += (int)STRLEN(p + len); |
6131 } | |
6132 #ifdef FEAT_QUICKFIX | |
6133 if (wp->w_p_pvw) | |
6134 { | |
6135 STRCPY(p + len, _("[Preview]")); | |
6136 len += (int)STRLEN(p + len); | |
6137 } | |
6138 #endif | |
6139 if (bufIsChanged(wp->w_buffer)) | |
6140 { | |
6141 STRCPY(p + len, "[+]"); | |
6142 len += 3; | |
6143 } | |
6144 if (wp->w_buffer->b_p_ro) | |
6145 { | |
6146 STRCPY(p + len, "[RO]"); | |
6147 len += 4; | |
6148 } | |
6149 | |
6150 #ifndef FEAT_VERTSPLIT | |
6151 this_ru_col = ru_col; | |
6152 if (this_ru_col < (Columns + 1) / 2) | |
6153 this_ru_col = (Columns + 1) / 2; | |
6154 #else | |
6155 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6156 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6157 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6158 if (this_ru_col <= 1) | |
6159 { | |
6160 p = (char_u *)"<"; /* No room for file name! */ | |
6161 len = 1; | |
6162 } | |
6163 else | |
6164 #endif | |
6165 #ifdef FEAT_MBYTE | |
6166 if (has_mbyte) | |
6167 { | |
6168 int clen = 0, i; | |
6169 | |
6170 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6171 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6172 |
7 | 6173 /* Find first character that will fit. |
6174 * Going from start to end is much faster for DBCS. */ | |
6175 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6176 i += (*mb_ptr2len)(p + i)) |
7 | 6177 clen -= (*mb_ptr2cells)(p + i); |
6178 len = clen; | |
6179 if (i > 0) | |
6180 { | |
6181 p = p + i - 1; | |
6182 *p = '<'; | |
6183 ++len; | |
6184 } | |
6185 | |
6186 } | |
6187 else | |
6188 #endif | |
6189 if (len > this_ru_col - 1) | |
6190 { | |
6191 p += len - (this_ru_col - 1); | |
6192 *p = '<'; | |
6193 len = this_ru_col - 1; | |
6194 } | |
6195 | |
6196 row = W_WINROW(wp) + wp->w_height; | |
6197 screen_puts(p, row, W_WINCOL(wp), attr); | |
6198 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6199 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6200 | |
6201 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6202 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6203 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6204 - 1 + W_WINCOL(wp)), attr); | |
6205 | |
6206 #ifdef FEAT_CMDL_INFO | |
6207 win_redr_ruler(wp, TRUE); | |
6208 #endif | |
6209 } | |
6210 | |
6211 #ifdef FEAT_VERTSPLIT | |
6212 /* | |
6213 * May need to draw the character below the vertical separator. | |
6214 */ | |
6215 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6216 { | |
6217 if (stl_connected(wp)) | |
6218 fillchar = fillchar_status(&attr, wp == curwin); | |
6219 else | |
6220 fillchar = fillchar_vsep(&attr); | |
6221 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6222 attr); | |
6223 } | |
6224 #endif | |
1910 | 6225 busy = FALSE; |
7 | 6226 } |
6227 | |
680 | 6228 #ifdef FEAT_STL_OPT |
6229 /* | |
6230 * Redraw the status line according to 'statusline' and take care of any | |
6231 * errors encountered. | |
6232 */ | |
6233 static void | |
1983 | 6234 redraw_custom_statusline(wp) |
680 | 6235 win_T *wp; |
6236 { | |
1983 | 6237 static int entered = FALSE; |
6238 int save_called_emsg = called_emsg; | |
6239 | |
6240 /* When called recursively return. This can happen when the statusline | |
6241 * contains an expression that triggers a redraw. */ | |
6242 if (entered) | |
6243 return; | |
6244 entered = TRUE; | |
680 | 6245 |
6246 called_emsg = FALSE; | |
6247 win_redr_custom(wp, FALSE); | |
6248 if (called_emsg) | |
1983 | 6249 { |
6250 /* When there is an error disable the statusline, otherwise the | |
6251 * display is messed up with errors and a redraw triggers the problem | |
6252 * again and again. */ | |
680 | 6253 set_string_option_direct((char_u *)"statusline", -1, |
6254 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6255 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6256 } |
680 | 6257 called_emsg |= save_called_emsg; |
1983 | 6258 entered = FALSE; |
680 | 6259 } |
6260 #endif | |
6261 | |
7 | 6262 # ifdef FEAT_VERTSPLIT |
6263 /* | |
6264 * Return TRUE if the status line of window "wp" is connected to the status | |
6265 * line of the window right of it. If not, then it's a vertical separator. | |
6266 * Only call if (wp->w_vsep_width != 0). | |
6267 */ | |
6268 int | |
6269 stl_connected(wp) | |
6270 win_T *wp; | |
6271 { | |
6272 frame_T *fr; | |
6273 | |
6274 fr = wp->w_frame; | |
6275 while (fr->fr_parent != NULL) | |
6276 { | |
6277 if (fr->fr_parent->fr_layout == FR_COL) | |
6278 { | |
6279 if (fr->fr_next != NULL) | |
6280 break; | |
6281 } | |
6282 else | |
6283 { | |
6284 if (fr->fr_next != NULL) | |
6285 return TRUE; | |
6286 } | |
6287 fr = fr->fr_parent; | |
6288 } | |
6289 return FALSE; | |
6290 } | |
6291 # endif | |
6292 | |
6293 #endif /* FEAT_WINDOWS */ | |
6294 | |
6295 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6296 /* | |
6297 * Get the value to show for the language mappings, active 'keymap'. | |
6298 */ | |
6299 int | |
6300 get_keymap_str(wp, buf, len) | |
6301 win_T *wp; | |
6302 char_u *buf; /* buffer for the result */ | |
6303 int len; /* length of buffer */ | |
6304 { | |
6305 char_u *p; | |
6306 | |
6307 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6308 return FALSE; | |
6309 | |
6310 { | |
6311 #ifdef FEAT_EVAL | |
6312 buf_T *old_curbuf = curbuf; | |
6313 win_T *old_curwin = curwin; | |
6314 char_u *s; | |
6315 | |
6316 curbuf = wp->w_buffer; | |
6317 curwin = wp; | |
6318 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6319 ++emsg_skip; | |
714 | 6320 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6321 --emsg_skip; |
6322 curbuf = old_curbuf; | |
6323 curwin = old_curwin; | |
6324 if (p == NULL || *p == NUL) | |
6325 #endif | |
6326 { | |
6327 #ifdef FEAT_KEYMAP | |
6328 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6329 p = wp->w_buffer->b_p_keymap; | |
6330 else | |
6331 #endif | |
6332 p = (char_u *)"lang"; | |
6333 } | |
6334 if ((int)(STRLEN(p) + 3) < len) | |
6335 sprintf((char *)buf, "<%s>", p); | |
6336 else | |
6337 buf[0] = NUL; | |
6338 #ifdef FEAT_EVAL | |
6339 vim_free(s); | |
6340 #endif | |
6341 } | |
6342 return buf[0] != NUL; | |
6343 } | |
6344 #endif | |
6345 | |
6346 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6347 /* | |
677 | 6348 * Redraw the status line or ruler of window "wp". |
6349 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6350 */ |
6351 static void | |
574 | 6352 win_redr_custom(wp, draw_ruler) |
7 | 6353 win_T *wp; |
574 | 6354 int draw_ruler; /* TRUE or FALSE */ |
7 | 6355 { |
6356 int attr; | |
6357 int curattr; | |
6358 int row; | |
6359 int col = 0; | |
6360 int maxwidth; | |
6361 int width; | |
6362 int n; | |
6363 int len; | |
6364 int fillchar; | |
6365 char_u buf[MAXPATHL]; | |
1983 | 6366 char_u *stl; |
7 | 6367 char_u *p; |
681 | 6368 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6369 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6370 int use_sandbox = FALSE; |
7 | 6371 |
6372 /* setup environment for the task at hand */ | |
677 | 6373 if (wp == NULL) |
6374 { | |
6375 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6376 stl = p_tal; |
677 | 6377 row = 0; |
707 | 6378 fillchar = ' '; |
677 | 6379 attr = hl_attr(HLF_TPF); |
6380 maxwidth = Columns; | |
6381 # ifdef FEAT_EVAL | |
681 | 6382 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6383 # endif |
6384 } | |
40 | 6385 else |
677 | 6386 { |
6387 row = W_WINROW(wp) + wp->w_height; | |
6388 fillchar = fillchar_status(&attr, wp == curwin); | |
6389 maxwidth = W_WIDTH(wp); | |
6390 | |
6391 if (draw_ruler) | |
6392 { | |
1983 | 6393 stl = p_ruf; |
677 | 6394 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6395 if (*stl == '%') |
6396 { | |
6397 if (*++stl == '-') | |
6398 stl++; | |
6399 if (atoi((char *)stl)) | |
6400 while (VIM_ISDIGIT(*stl)) | |
6401 stl++; | |
6402 if (*stl++ != '(') | |
6403 stl = p_ruf; | |
677 | 6404 } |
7 | 6405 #ifdef FEAT_VERTSPLIT |
677 | 6406 col = ru_col - (Columns - W_WIDTH(wp)); |
6407 if (col < (W_WIDTH(wp) + 1) / 2) | |
6408 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6409 #else |
677 | 6410 col = ru_col; |
6411 if (col > (Columns + 1) / 2) | |
6412 col = (Columns + 1) / 2; | |
6413 #endif | |
6414 maxwidth = W_WIDTH(wp) - col; | |
7 | 6415 #ifdef FEAT_WINDOWS |
677 | 6416 if (!wp->w_status_height) |
6417 #endif | |
6418 { | |
6419 row = Rows - 1; | |
6420 --maxwidth; /* writing in last column may cause scrolling */ | |
6421 fillchar = ' '; | |
6422 attr = 0; | |
6423 } | |
6424 | |
6425 # ifdef FEAT_EVAL | |
681 | 6426 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6427 # endif |
6428 } | |
6429 else | |
6430 { | |
6431 if (*wp->w_p_stl != NUL) | |
1983 | 6432 stl = wp->w_p_stl; |
677 | 6433 else |
1983 | 6434 stl = p_stl; |
677 | 6435 # ifdef FEAT_EVAL |
681 | 6436 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6437 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6438 # endif |
6439 } | |
6440 | |
6441 #ifdef FEAT_VERTSPLIT | |
6442 col += W_WINCOL(wp); | |
6443 #endif | |
6444 } | |
6445 | |
7 | 6446 if (maxwidth <= 0) |
6447 return; | |
677 | 6448 |
1983 | 6449 /* Make a copy, because the statusline may include a function call that |
6450 * might change the option value and free the memory. */ | |
6451 stl = vim_strsave(stl); | |
677 | 6452 width = build_stl_str_hl(wp == NULL ? curwin : wp, |
6453 buf, sizeof(buf), | |
1983 | 6454 stl, use_sandbox, |
681 | 6455 fillchar, maxwidth, hltab, tabtab); |
1983 | 6456 vim_free(stl); |
835 | 6457 len = (int)STRLEN(buf); |
7 | 6458 |
1883 | 6459 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6460 { |
6461 #ifdef FEAT_MBYTE | |
6462 len += (*mb_char2bytes)(fillchar, buf + len); | |
6463 #else | |
6464 buf[len++] = fillchar; | |
6465 #endif | |
6466 ++width; | |
6467 } | |
6468 buf[len] = NUL; | |
6469 | |
681 | 6470 /* |
6471 * Draw each snippet with the specified highlighting. | |
6472 */ | |
7 | 6473 curattr = attr; |
6474 p = buf; | |
681 | 6475 for (n = 0; hltab[n].start != NULL; n++) |
6476 { | |
6477 len = (int)(hltab[n].start - p); | |
7 | 6478 screen_puts_len(p, len, row, col, curattr); |
6479 col += vim_strnsize(p, len); | |
681 | 6480 p = hltab[n].start; |
6481 | |
6482 if (hltab[n].userhl == 0) | |
7 | 6483 curattr = attr; |
681 | 6484 else if (hltab[n].userhl < 0) |
6485 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6486 #ifdef FEAT_WINDOWS |
680 | 6487 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6488 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6489 #endif |
6490 else | |
681 | 6491 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6492 } |
6493 screen_puts(p, row, col, curattr); | |
681 | 6494 |
6495 if (wp == NULL) | |
6496 { | |
6497 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6498 col = 0; | |
6499 len = 0; | |
6500 p = buf; | |
6501 fillchar = 0; | |
6502 for (n = 0; tabtab[n].start != NULL; n++) | |
6503 { | |
6504 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6505 while (col < len) | |
6506 TabPageIdxs[col++] = fillchar; | |
6507 p = tabtab[n].start; | |
6508 fillchar = tabtab[n].userhl; | |
6509 } | |
6510 while (col < Columns) | |
6511 TabPageIdxs[col++] = fillchar; | |
6512 } | |
7 | 6513 } |
6514 | |
6515 #endif /* FEAT_STL_OPT */ | |
6516 | |
6517 /* | |
6518 * Output a single character directly to the screen and update ScreenLines. | |
6519 */ | |
6520 void | |
6521 screen_putchar(c, row, col, attr) | |
6522 int c; | |
6523 int row, col; | |
6524 int attr; | |
6525 { | |
6526 #ifdef FEAT_MBYTE | |
6527 char_u buf[MB_MAXBYTES + 1]; | |
6528 | |
6529 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6530 #else | |
6531 char_u buf[2]; | |
6532 | |
6533 buf[0] = c; | |
6534 buf[1] = NUL; | |
6535 #endif | |
6536 screen_puts(buf, row, col, attr); | |
6537 } | |
6538 | |
6539 /* | |
6540 * Get a single character directly from ScreenLines into "bytes[]". | |
6541 * Also return its attribute in *attrp; | |
6542 */ | |
6543 void | |
6544 screen_getbytes(row, col, bytes, attrp) | |
6545 int row, col; | |
6546 char_u *bytes; | |
6547 int *attrp; | |
6548 { | |
6549 unsigned off; | |
6550 | |
6551 /* safety check */ | |
6552 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6553 { | |
6554 off = LineOffset[row] + col; | |
6555 *attrp = ScreenAttrs[off]; | |
6556 bytes[0] = ScreenLines[off]; | |
6557 bytes[1] = NUL; | |
6558 | |
6559 #ifdef FEAT_MBYTE | |
6560 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6561 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6562 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6563 { | |
6564 bytes[0] = ScreenLines[off]; | |
6565 bytes[1] = ScreenLines2[off]; | |
6566 bytes[2] = NUL; | |
6567 } | |
6568 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6569 { | |
6570 bytes[1] = ScreenLines[off + 1]; | |
6571 bytes[2] = NUL; | |
6572 } | |
6573 #endif | |
6574 } | |
6575 } | |
6576 | |
714 | 6577 #ifdef FEAT_MBYTE |
6578 static int screen_comp_differs __ARGS((int, int*)); | |
6579 | |
6580 /* | |
6581 * Return TRUE if composing characters for screen posn "off" differs from | |
6582 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6583 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6584 */ |
6585 static int | |
6586 screen_comp_differs(off, u8cc) | |
6587 int off; | |
6588 int *u8cc; | |
6589 { | |
6590 int i; | |
6591 | |
6592 for (i = 0; i < Screen_mco; ++i) | |
6593 { | |
6594 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6595 return TRUE; | |
6596 if (u8cc[i] == 0) | |
6597 break; | |
6598 } | |
6599 return FALSE; | |
6600 } | |
6601 #endif | |
6602 | |
7 | 6603 /* |
6604 * Put string '*text' on the screen at position 'row' and 'col', with | |
6605 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6606 * Note: only outputs within one row, message is truncated at screen boundary! | |
6607 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6608 */ | |
6609 void | |
6610 screen_puts(text, row, col, attr) | |
6611 char_u *text; | |
6612 int row; | |
6613 int col; | |
6614 int attr; | |
6615 { | |
6616 screen_puts_len(text, -1, row, col, attr); | |
6617 } | |
6618 | |
6619 /* | |
6620 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6621 * a NUL. | |
6622 */ | |
6623 void | |
6624 screen_puts_len(text, len, row, col, attr) | |
6625 char_u *text; | |
6626 int len; | |
6627 int row; | |
6628 int col; | |
6629 int attr; | |
6630 { | |
6631 unsigned off; | |
6632 char_u *ptr = text; | |
6633 int c; | |
6634 #ifdef FEAT_MBYTE | |
1378 | 6635 unsigned max_off; |
7 | 6636 int mbyte_blen = 1; |
6637 int mbyte_cells = 1; | |
6638 int u8c = 0; | |
714 | 6639 int u8cc[MAX_MCO]; |
7 | 6640 int clear_next_cell = FALSE; |
6641 # ifdef FEAT_ARABIC | |
6642 int prev_c = 0; /* previous Arabic character */ | |
714 | 6643 int pc, nc, nc1; |
6644 int pcc[MAX_MCO]; | |
7 | 6645 # endif |
6646 #endif | |
1843 | 6647 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6648 int force_redraw_this; | |
6649 int force_redraw_next = FALSE; | |
6650 #endif | |
6651 int need_redraw; | |
7 | 6652 |
6653 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6654 return; | |
1843 | 6655 off = LineOffset[row] + col; |
7 | 6656 |
1668 | 6657 #ifdef FEAT_MBYTE |
6658 /* When drawing over the right halve of a double-wide char clear out the | |
6659 * left halve. Only needed in a terminal. */ | |
1685 | 6660 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6661 # ifdef FEAT_GUI |
6662 && !gui.in_use | |
6663 # endif | |
6664 && mb_fix_col(col, row) != col) | |
1843 | 6665 { |
6666 ScreenLines[off - 1] = ' '; | |
6667 ScreenAttrs[off - 1] = 0; | |
6668 if (enc_utf8) | |
6669 { | |
6670 ScreenLinesUC[off - 1] = 0; | |
6671 ScreenLinesC[0][off - 1] = 0; | |
6672 } | |
6673 /* redraw the previous cell, make it empty */ | |
6674 screen_char(off - 1, row, col - 1); | |
6675 /* force the cell at "col" to be redrawn */ | |
6676 force_redraw_next = TRUE; | |
6677 } | |
6678 #endif | |
6679 | |
1378 | 6680 #ifdef FEAT_MBYTE |
6681 max_off = LineOffset[row] + screen_Columns; | |
6682 #endif | |
1340 | 6683 while (col < screen_Columns |
6684 && (len < 0 || (int)(ptr - text) < len) | |
6685 && *ptr != NUL) | |
7 | 6686 { |
6687 c = *ptr; | |
6688 #ifdef FEAT_MBYTE | |
6689 /* check if this is the first byte of a multibyte */ | |
6690 if (has_mbyte) | |
6691 { | |
6692 if (enc_utf8 && len > 0) | |
474 | 6693 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6694 else |
474 | 6695 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6696 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6697 mbyte_cells = 1; | |
6698 else if (enc_dbcs != 0) | |
6699 mbyte_cells = mbyte_blen; | |
6700 else /* enc_utf8 */ | |
6701 { | |
6702 if (len >= 0) | |
714 | 6703 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6704 (int)((text + len) - ptr)); |
6705 else | |
714 | 6706 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6707 mbyte_cells = utf_char2cells(u8c); |
1401 | 6708 # ifdef UNICODE16 |
7 | 6709 /* Non-BMP character: display as ? or fullwidth ?. */ |
6710 if (u8c >= 0x10000) | |
6711 { | |
6712 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6713 if (attr == 0) | |
6714 attr = hl_attr(HLF_8); | |
6715 } | |
1401 | 6716 # endif |
7 | 6717 # ifdef FEAT_ARABIC |
6718 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6719 { | |
6720 /* Do Arabic shaping. */ | |
6721 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6722 { | |
6723 /* Past end of string to be displayed. */ | |
6724 nc = NUL; | |
6725 nc1 = NUL; | |
6726 } | |
6727 else | |
714 | 6728 { |
1994 | 6729 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6730 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6731 nc1 = pcc[0]; |
6732 } | |
7 | 6733 pc = prev_c; |
6734 prev_c = u8c; | |
714 | 6735 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6736 } |
6737 else | |
6738 prev_c = u8c; | |
6739 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6740 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6741 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6742 /* 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
|
6743 * 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
|
6744 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6745 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6746 } |
7 | 6747 } |
6748 } | |
6749 #endif | |
6750 | |
1843 | 6751 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6752 force_redraw_this = force_redraw_next; | |
6753 force_redraw_next = FALSE; | |
6754 #endif | |
6755 | |
6756 need_redraw = ScreenLines[off] != c | |
7 | 6757 #ifdef FEAT_MBYTE |
6758 || (mbyte_cells == 2 | |
6759 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6760 || (enc_dbcs == DBCS_JPNU | |
6761 && c == 0x8e | |
6762 && ScreenLines2[off] != ptr[1]) | |
6763 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6764 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6765 (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
|
6766 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6767 && screen_comp_differs(off, u8cc)))) |
7 | 6768 #endif |
6769 || ScreenAttrs[off] != attr | |
1843 | 6770 || exmode_active; |
6771 | |
6772 if (need_redraw | |
6773 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6774 || force_redraw_this | |
6775 #endif | |
7 | 6776 ) |
6777 { | |
6778 #if defined(FEAT_GUI) || defined(UNIX) | |
6779 /* The bold trick makes a single row of pixels appear in the next | |
6780 * character. When a bold character is removed, the next | |
6781 * character should be redrawn too. This happens for our own GUI | |
1843 | 6782 * and for some xterms. */ |
6783 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6784 # ifdef FEAT_GUI |
6785 gui.in_use | |
6786 # endif | |
6787 # if defined(FEAT_GUI) && defined(UNIX) | |
6788 || | |
6789 # endif | |
6790 # ifdef UNIX | |
6791 term_is_xterm | |
6792 # endif | |
1843 | 6793 )) |
6794 { | |
6795 int n = ScreenAttrs[off]; | |
6796 | |
6797 if (n > HL_ALL) | |
6798 n = syn_attr2attr(n); | |
6799 if (n & HL_BOLD) | |
6800 force_redraw_next = TRUE; | |
7 | 6801 } |
6802 #endif | |
6803 #ifdef FEAT_MBYTE | |
6804 /* When at the end of the text and overwriting a two-cell | |
6805 * character with a one-cell character, need to clear the next | |
6806 * cell. Also when overwriting the left halve of a two-cell char | |
6807 * with the right halve of a two-cell char. Do this only once | |
6808 * (mb_off2cells() may return 2 on the right halve). */ | |
6809 if (clear_next_cell) | |
6810 clear_next_cell = FALSE; | |
6811 else if (has_mbyte | |
6812 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6813 : ptr + mbyte_blen >= text + len) | |
1378 | 6814 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6815 || (mbyte_cells == 2 |
1378 | 6816 && (*mb_off2cells)(off, max_off) == 1 |
6817 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6818 clear_next_cell = TRUE; |
6819 | |
6820 /* Make sure we never leave a second byte of a double-byte behind, | |
6821 * it confuses mb_off2cells(). */ | |
6822 if (enc_dbcs | |
1378 | 6823 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6824 || (mbyte_cells == 2 |
1378 | 6825 && (*mb_off2cells)(off, max_off) == 1 |
6826 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6827 ScreenLines[off + mbyte_blen] = 0; |
6828 #endif | |
6829 ScreenLines[off] = c; | |
6830 ScreenAttrs[off] = attr; | |
6831 #ifdef FEAT_MBYTE | |
6832 if (enc_utf8) | |
6833 { | |
714 | 6834 if (c < 0x80 && u8cc[0] == 0) |
7 | 6835 ScreenLinesUC[off] = 0; |
6836 else | |
6837 { | |
714 | 6838 int i; |
6839 | |
7 | 6840 ScreenLinesUC[off] = u8c; |
714 | 6841 for (i = 0; i < Screen_mco; ++i) |
6842 { | |
6843 ScreenLinesC[i][off] = u8cc[i]; | |
6844 if (u8cc[i] == 0) | |
6845 break; | |
6846 } | |
7 | 6847 } |
6848 if (mbyte_cells == 2) | |
6849 { | |
6850 ScreenLines[off + 1] = 0; | |
6851 ScreenAttrs[off + 1] = attr; | |
6852 } | |
6853 screen_char(off, row, col); | |
6854 } | |
6855 else if (mbyte_cells == 2) | |
6856 { | |
6857 ScreenLines[off + 1] = ptr[1]; | |
6858 ScreenAttrs[off + 1] = attr; | |
6859 screen_char_2(off, row, col); | |
6860 } | |
6861 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6862 { | |
6863 ScreenLines2[off] = ptr[1]; | |
6864 screen_char(off, row, col); | |
6865 } | |
6866 else | |
6867 #endif | |
6868 screen_char(off, row, col); | |
6869 } | |
6870 #ifdef FEAT_MBYTE | |
6871 if (has_mbyte) | |
6872 { | |
6873 off += mbyte_cells; | |
6874 col += mbyte_cells; | |
6875 ptr += mbyte_blen; | |
6876 if (clear_next_cell) | |
6877 ptr = (char_u *)" "; | |
6878 } | |
6879 else | |
6880 #endif | |
6881 { | |
6882 ++off; | |
6883 ++col; | |
6884 ++ptr; | |
6885 } | |
6886 } | |
1843 | 6887 |
6888 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6889 /* If we detected the next character needs to be redrawn, but the text | |
6890 * doesn't extend up to there, update the character here. */ | |
6891 if (force_redraw_next && col < screen_Columns) | |
6892 { | |
6893 # ifdef FEAT_MBYTE | |
6894 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6895 screen_char_2(off, row, col); | |
6896 else | |
6897 # endif | |
6898 screen_char(off, row, col); | |
6899 } | |
6900 #endif | |
7 | 6901 } |
6902 | |
6903 #ifdef FEAT_SEARCH_EXTRA | |
6904 /* | |
1326 | 6905 * Prepare for 'hlsearch' highlighting. |
7 | 6906 */ |
6907 static void | |
6908 start_search_hl() | |
6909 { | |
6910 if (p_hls && !no_hlsearch) | |
6911 { | |
6912 last_pat_prog(&search_hl.rm); | |
6913 search_hl.attr = hl_attr(HLF_L); | |
1521 | 6914 # ifdef FEAT_RELTIME |
6915 /* Set the time limit to 'redrawtime'. */ | |
6916 profile_setlimit(p_rdt, &search_hl.tm); | |
6917 # endif | |
7 | 6918 } |
6919 } | |
6920 | |
6921 /* | |
1326 | 6922 * Clean up for 'hlsearch' highlighting. |
7 | 6923 */ |
6924 static void | |
6925 end_search_hl() | |
6926 { | |
6927 if (search_hl.rm.regprog != NULL) | |
6928 { | |
6929 vim_free(search_hl.rm.regprog); | |
6930 search_hl.rm.regprog = NULL; | |
6931 } | |
6932 } | |
6933 | |
6934 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6935 * 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
|
6936 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6937 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6938 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6939 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6940 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6941 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6942 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6943 /* 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
|
6944 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6945 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6946 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6947 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6948 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6949 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6950 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6951 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6952 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
|
6953 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
|
6954 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6955 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6956 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6957 /* 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
|
6958 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
|
6959 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6960 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6961 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6962 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
|
6963 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6964 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6965 /* 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
|
6966 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6967 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6968 /* |
7 | 6969 * Advance to the match in window "wp" line "lnum" or past it. |
6970 */ | |
6971 static void | |
6972 prepare_search_hl(wp, lnum) | |
6973 win_T *wp; | |
6974 linenr_T lnum; | |
6975 { | |
1326 | 6976 matchitem_T *cur; /* points to the match list */ |
6977 match_T *shl; /* points to search_hl or a match */ | |
6978 int shl_flag; /* flag to indicate whether search_hl | |
6979 has been processed or not */ | |
7 | 6980 int n; |
6981 | |
6982 /* | |
6983 * When using a multi-line pattern, start searching at the top | |
6984 * of the window or just after a closed fold. | |
1326 | 6985 * Do this both for search_hl and the match list. |
7 | 6986 */ |
1326 | 6987 cur = wp->w_match_head; |
6988 shl_flag = FALSE; | |
6989 while (cur != NULL || shl_flag == FALSE) | |
6990 { | |
6991 if (shl_flag == FALSE) | |
6992 { | |
6993 shl = &search_hl; | |
6994 shl_flag = TRUE; | |
6995 } | |
6996 else | |
6997 shl = &cur->hl; | |
7 | 6998 if (shl->rm.regprog != NULL |
6999 && shl->lnum == 0 | |
7000 && re_multiline(shl->rm.regprog)) | |
7001 { | |
7002 if (shl->first_lnum == 0) | |
7003 { | |
7004 # ifdef FEAT_FOLDING | |
7005 for (shl->first_lnum = lnum; | |
7006 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7007 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7008 NULL, NULL, TRUE, NULL)) | |
7009 break; | |
7010 # else | |
7011 shl->first_lnum = wp->w_topline; | |
7012 # endif | |
7013 } | |
7014 n = 0; | |
7015 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7016 { | |
7017 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7018 if (shl->lnum != 0) | |
7019 { | |
7020 shl->first_lnum = shl->lnum | |
7021 + shl->rm.endpos[0].lnum | |
7022 - shl->rm.startpos[0].lnum; | |
7023 n = shl->rm.endpos[0].col; | |
7024 } | |
7025 else | |
7026 { | |
7027 ++shl->first_lnum; | |
7028 n = 0; | |
7029 } | |
7030 } | |
7031 } | |
1326 | 7032 if (shl != &search_hl && cur != NULL) |
7033 cur = cur->next; | |
7 | 7034 } |
7035 } | |
7036 | |
7037 /* | |
1326 | 7038 * Search for a next 'hlsearch' or match. |
7 | 7039 * Uses shl->buf. |
7040 * Sets shl->lnum and shl->rm contents. | |
7041 * Note: Assumes a previous match is always before "lnum", unless | |
7042 * shl->lnum is zero. | |
7043 * Careful: Any pointers for buffer lines will become invalid. | |
7044 */ | |
7045 static void | |
7046 next_search_hl(win, shl, lnum, mincol) | |
7047 win_T *win; | |
1326 | 7048 match_T *shl; /* points to search_hl or a match */ |
7 | 7049 linenr_T lnum; |
7050 colnr_T mincol; /* minimal column for a match */ | |
7051 { | |
7052 linenr_T l; | |
7053 colnr_T matchcol; | |
7054 long nmatched; | |
7055 | |
7056 if (shl->lnum != 0) | |
7057 { | |
7058 /* Check for three situations: | |
7059 * 1. If the "lnum" is below a previous match, start a new search. | |
7060 * 2. If the previous match includes "mincol", use it. | |
7061 * 3. Continue after the previous match. | |
7062 */ | |
7063 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7064 if (lnum > l) | |
7065 shl->lnum = 0; | |
7066 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7067 return; | |
7068 } | |
7069 | |
7070 /* | |
7071 * Repeat searching for a match until one is found that includes "mincol" | |
7072 * or none is found in this line. | |
7073 */ | |
7074 called_emsg = FALSE; | |
7075 for (;;) | |
7076 { | |
1521 | 7077 #ifdef FEAT_RELTIME |
7078 /* Stop searching after passing the time limit. */ | |
7079 if (profile_passed_limit(&(shl->tm))) | |
7080 { | |
7081 shl->lnum = 0; /* no match found in time */ | |
7082 break; | |
7083 } | |
7084 #endif | |
7 | 7085 /* Three situations: |
7086 * 1. No useful previous match: search from start of line. | |
7087 * 2. Not Vi compatible or empty match: continue at next character. | |
7088 * Break the loop if this is beyond the end of the line. | |
7089 * 3. Vi compatible searching: continue at end of previous match. | |
7090 */ | |
7091 if (shl->lnum == 0) | |
7092 matchcol = 0; | |
7093 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7094 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7095 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7096 { | |
688 | 7097 char_u *ml; |
685 | 7098 |
7099 matchcol = shl->rm.startpos[0].col; | |
688 | 7100 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7101 if (*ml == NUL) |
7102 { | |
7103 ++matchcol; | |
7 | 7104 shl->lnum = 0; |
7105 break; | |
7106 } | |
685 | 7107 #ifdef FEAT_MBYTE |
7108 if (has_mbyte) | |
7109 matchcol += mb_ptr2len(ml); | |
7110 else | |
7111 #endif | |
7112 ++matchcol; | |
7 | 7113 } |
7114 else | |
7115 matchcol = shl->rm.endpos[0].col; | |
7116 | |
7117 shl->lnum = lnum; | |
1521 | 7118 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7119 #ifdef FEAT_RELTIME | |
7120 &(shl->tm) | |
7121 #else | |
7122 NULL | |
7123 #endif | |
7124 ); | |
7 | 7125 if (called_emsg) |
7126 { | |
7127 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7128 if (shl == &search_hl) |
7129 { | |
1326 | 7130 /* don't free regprog in the match list, it's a copy */ |
1112 | 7131 vim_free(shl->rm.regprog); |
7132 no_hlsearch = TRUE; | |
7133 } | |
7 | 7134 shl->rm.regprog = NULL; |
1112 | 7135 shl->lnum = 0; |
7136 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7137 break; |
7138 } | |
7139 if (nmatched == 0) | |
7140 { | |
7141 shl->lnum = 0; /* no match found */ | |
7142 break; | |
7143 } | |
7144 if (shl->rm.startpos[0].lnum > 0 | |
7145 || shl->rm.startpos[0].col >= mincol | |
7146 || nmatched > 1 | |
7147 || shl->rm.endpos[0].col > mincol) | |
7148 { | |
7149 shl->lnum += shl->rm.startpos[0].lnum; | |
7150 break; /* useful match found */ | |
7151 } | |
7152 } | |
7153 } | |
7154 #endif | |
7155 | |
7156 static void | |
7157 screen_start_highlight(attr) | |
7158 int attr; | |
7159 { | |
7160 attrentry_T *aep = NULL; | |
7161 | |
7162 screen_attr = attr; | |
7163 if (full_screen | |
7164 #ifdef WIN3264 | |
7165 && termcap_active | |
7166 #endif | |
7167 ) | |
7168 { | |
7169 #ifdef FEAT_GUI | |
7170 if (gui.in_use) | |
7171 { | |
7172 char buf[20]; | |
7173 | |
681 | 7174 /* The GUI handles this internally. */ |
7175 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7176 OUT_STR(buf); |
7177 } | |
7178 else | |
7179 #endif | |
7180 { | |
7181 if (attr > HL_ALL) /* special HL attr. */ | |
7182 { | |
7183 if (t_colors > 1) | |
7184 aep = syn_cterm_attr2entry(attr); | |
7185 else | |
7186 aep = syn_term_attr2entry(attr); | |
7187 if (aep == NULL) /* did ":syntax clear" */ | |
7188 attr = 0; | |
7189 else | |
7190 attr = aep->ae_attr; | |
7191 } | |
7192 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7193 out_str(T_MD); | |
681 | 7194 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7195 && cterm_normal_fg_bold) | |
7196 /* If the Normal FG color has BOLD attribute and the new HL | |
7197 * has a FG color defined, clear BOLD. */ | |
7198 out_str(T_ME); | |
7 | 7199 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7200 out_str(T_SO); | |
205 | 7201 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7202 /* underline or undercurl */ | |
7 | 7203 out_str(T_US); |
7204 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7205 out_str(T_CZH); | |
7206 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7207 out_str(T_MR); | |
7208 | |
7209 /* | |
7210 * Output the color or start string after bold etc., in case the | |
7211 * bold etc. override the color setting. | |
7212 */ | |
7213 if (aep != NULL) | |
7214 { | |
7215 if (t_colors > 1) | |
7216 { | |
7217 if (aep->ae_u.cterm.fg_color) | |
7218 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7219 if (aep->ae_u.cterm.bg_color) | |
7220 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7221 } | |
7222 else | |
7223 { | |
7224 if (aep->ae_u.term.start != NULL) | |
7225 out_str(aep->ae_u.term.start); | |
7226 } | |
7227 } | |
7228 } | |
7229 } | |
7230 } | |
7231 | |
7232 void | |
7233 screen_stop_highlight() | |
7234 { | |
7235 int do_ME = FALSE; /* output T_ME code */ | |
7236 | |
7237 if (screen_attr != 0 | |
7238 #ifdef WIN3264 | |
7239 && termcap_active | |
7240 #endif | |
7241 ) | |
7242 { | |
7243 #ifdef FEAT_GUI | |
7244 if (gui.in_use) | |
7245 { | |
7246 char buf[20]; | |
7247 | |
7248 /* use internal GUI code */ | |
7249 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7250 OUT_STR(buf); | |
7251 } | |
7252 else | |
7253 #endif | |
7254 { | |
7255 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7256 { | |
7257 attrentry_T *aep; | |
7258 | |
7259 if (t_colors > 1) | |
7260 { | |
7261 /* | |
7262 * Assume that t_me restores the original colors! | |
7263 */ | |
7264 aep = syn_cterm_attr2entry(screen_attr); | |
7265 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7266 || aep->ae_u.cterm.bg_color)) | |
7267 do_ME = TRUE; | |
7268 } | |
7269 else | |
7270 { | |
7271 aep = syn_term_attr2entry(screen_attr); | |
7272 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7273 { | |
7274 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7275 do_ME = TRUE; | |
7276 else | |
7277 out_str(aep->ae_u.term.stop); | |
7278 } | |
7279 } | |
7280 if (aep == NULL) /* did ":syntax clear" */ | |
7281 screen_attr = 0; | |
7282 else | |
7283 screen_attr = aep->ae_attr; | |
7284 } | |
7285 | |
7286 /* | |
7287 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7288 * same sequence several times. | |
7289 */ | |
7290 if (screen_attr & HL_STANDOUT) | |
7291 { | |
7292 if (STRCMP(T_SE, T_ME) == 0) | |
7293 do_ME = TRUE; | |
7294 else | |
7295 out_str(T_SE); | |
7296 } | |
205 | 7297 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7298 { |
7299 if (STRCMP(T_UE, T_ME) == 0) | |
7300 do_ME = TRUE; | |
7301 else | |
7302 out_str(T_UE); | |
7303 } | |
7304 if (screen_attr & HL_ITALIC) | |
7305 { | |
7306 if (STRCMP(T_CZR, T_ME) == 0) | |
7307 do_ME = TRUE; | |
7308 else | |
7309 out_str(T_CZR); | |
7310 } | |
7311 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7312 out_str(T_ME); | |
7313 | |
7314 if (t_colors > 1) | |
7315 { | |
7316 /* set Normal cterm colors */ | |
7317 if (cterm_normal_fg_color != 0) | |
7318 term_fg_color(cterm_normal_fg_color - 1); | |
7319 if (cterm_normal_bg_color != 0) | |
7320 term_bg_color(cterm_normal_bg_color - 1); | |
7321 if (cterm_normal_fg_bold) | |
7322 out_str(T_MD); | |
7323 } | |
7324 } | |
7325 } | |
7326 screen_attr = 0; | |
7327 } | |
7328 | |
7329 /* | |
7330 * Reset the colors for a cterm. Used when leaving Vim. | |
7331 * The machine specific code may override this again. | |
7332 */ | |
7333 void | |
7334 reset_cterm_colors() | |
7335 { | |
7336 if (t_colors > 1) | |
7337 { | |
7338 /* set Normal cterm colors */ | |
7339 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7340 { | |
7341 out_str(T_OP); | |
7342 screen_attr = -1; | |
7343 } | |
7344 if (cterm_normal_fg_bold) | |
7345 { | |
7346 out_str(T_ME); | |
7347 screen_attr = -1; | |
7348 } | |
7349 } | |
7350 } | |
7351 | |
7352 /* | |
7353 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7354 * using the attributes from ScreenAttrs["off"]. | |
7355 */ | |
7356 static void | |
7357 screen_char(off, row, col) | |
7358 unsigned off; | |
7359 int row; | |
7360 int col; | |
7361 { | |
7362 int attr; | |
7363 | |
7364 /* Check for illegal values, just in case (could happen just after | |
7365 * resizing). */ | |
7366 if (row >= screen_Rows || col >= screen_Columns) | |
7367 return; | |
7368 | |
7369 /* Outputting the last character on the screen may scrollup the screen. | |
7370 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7371 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7372 #ifdef FEAT_RIGHTLEFT | |
7373 /* account for first command-line character in rightleft mode */ | |
7374 && !cmdmsg_rl | |
7375 #endif | |
7376 ) | |
7377 { | |
7378 ScreenAttrs[off] = (sattr_T)-1; | |
7379 return; | |
7380 } | |
7381 | |
7382 /* | |
7383 * Stop highlighting first, so it's easier to move the cursor. | |
7384 */ | |
7385 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7386 if (screen_char_attr != 0) | |
7387 attr = screen_char_attr; | |
7388 else | |
7389 #endif | |
7390 attr = ScreenAttrs[off]; | |
7391 if (screen_attr != attr) | |
7392 screen_stop_highlight(); | |
7393 | |
7394 windgoto(row, col); | |
7395 | |
7396 if (screen_attr != attr) | |
7397 screen_start_highlight(attr); | |
7398 | |
7399 #ifdef FEAT_MBYTE | |
7400 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7401 { | |
7402 char_u buf[MB_MAXBYTES + 1]; | |
7403 | |
7404 /* Convert UTF-8 character to bytes and write it. */ | |
7405 | |
7406 buf[utfc_char2bytes(off, buf)] = NUL; | |
7407 | |
7408 out_str(buf); | |
7409 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7410 ++screen_cur_col; | |
7411 } | |
7412 else | |
7413 #endif | |
7414 { | |
7415 #ifdef FEAT_MBYTE | |
7416 out_flush_check(); | |
7417 #endif | |
7418 out_char(ScreenLines[off]); | |
7419 #ifdef FEAT_MBYTE | |
7420 /* double-byte character in single-width cell */ | |
7421 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7422 out_char(ScreenLines2[off]); | |
7423 #endif | |
7424 } | |
7425 | |
7426 screen_cur_col++; | |
7427 } | |
7428 | |
7429 #ifdef FEAT_MBYTE | |
7430 | |
7431 /* | |
7432 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7433 * on the screen at position 'row' and 'col'. | |
7434 * The attributes of the first byte is used for all. This is required to | |
7435 * output the two bytes of a double-byte character with nothing in between. | |
7436 */ | |
7437 static void | |
7438 screen_char_2(off, row, col) | |
7439 unsigned off; | |
7440 int row; | |
7441 int col; | |
7442 { | |
7443 /* Check for illegal values (could be wrong when screen was resized). */ | |
7444 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7445 return; | |
7446 | |
7447 /* Outputting the last character on the screen may scrollup the screen. | |
7448 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7449 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7450 { | |
7451 ScreenAttrs[off] = (sattr_T)-1; | |
7452 return; | |
7453 } | |
7454 | |
7455 /* Output the first byte normally (positions the cursor), then write the | |
7456 * second byte directly. */ | |
7457 screen_char(off, row, col); | |
7458 out_char(ScreenLines[off + 1]); | |
7459 ++screen_cur_col; | |
7460 } | |
7461 #endif | |
7462 | |
7463 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7464 /* | |
7465 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7466 * This uses the contents of ScreenLines[] and doesn't change it. | |
7467 */ | |
7468 void | |
7469 screen_draw_rectangle(row, col, height, width, invert) | |
7470 int row; | |
7471 int col; | |
7472 int height; | |
7473 int width; | |
7474 int invert; | |
7475 { | |
7476 int r, c; | |
7477 int off; | |
1378 | 7478 #ifdef FEAT_MBYTE |
7479 int max_off; | |
7480 #endif | |
7 | 7481 |
534 | 7482 /* Can't use ScreenLines unless initialized */ |
7483 if (ScreenLines == NULL) | |
7484 return; | |
7485 | |
7 | 7486 if (invert) |
7487 screen_char_attr = HL_INVERSE; | |
7488 for (r = row; r < row + height; ++r) | |
7489 { | |
7490 off = LineOffset[r]; | |
1378 | 7491 #ifdef FEAT_MBYTE |
7492 max_off = off + screen_Columns; | |
7493 #endif | |
7 | 7494 for (c = col; c < col + width; ++c) |
7495 { | |
7496 #ifdef FEAT_MBYTE | |
1378 | 7497 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7498 { |
7499 screen_char_2(off + c, r, c); | |
7500 ++c; | |
7501 } | |
7502 else | |
7503 #endif | |
7504 { | |
7505 screen_char(off + c, r, c); | |
7506 #ifdef FEAT_MBYTE | |
1378 | 7507 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7508 ++c; |
7509 #endif | |
7510 } | |
7511 } | |
7512 } | |
7513 screen_char_attr = 0; | |
7514 } | |
7515 #endif | |
7516 | |
7517 #ifdef FEAT_VERTSPLIT | |
7518 /* | |
7519 * Redraw the characters for a vertically split window. | |
7520 */ | |
7521 static void | |
7522 redraw_block(row, end, wp) | |
7523 int row; | |
7524 int end; | |
7525 win_T *wp; | |
7526 { | |
7527 int col; | |
7528 int width; | |
7529 | |
7530 # ifdef FEAT_CLIPBOARD | |
7531 clip_may_clear_selection(row, end - 1); | |
7532 # endif | |
7533 | |
7534 if (wp == NULL) | |
7535 { | |
7536 col = 0; | |
7537 width = Columns; | |
7538 } | |
7539 else | |
7540 { | |
7541 col = wp->w_wincol; | |
7542 width = wp->w_width; | |
7543 } | |
7544 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7545 } | |
7546 #endif | |
7547 | |
7548 /* | |
7549 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7550 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7551 * Use attributes 'attr'. | |
7552 */ | |
7553 void | |
7554 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7555 int start_row, end_row; | |
7556 int start_col, end_col; | |
7557 int c1, c2; | |
7558 int attr; | |
7559 { | |
7560 int row; | |
7561 int col; | |
7562 int off; | |
7563 int end_off; | |
7564 int did_delete; | |
7565 int c; | |
7566 int norm_term; | |
7567 #if defined(FEAT_GUI) || defined(UNIX) | |
7568 int force_next = FALSE; | |
7569 #endif | |
7570 | |
7571 if (end_row > screen_Rows) /* safety check */ | |
7572 end_row = screen_Rows; | |
7573 if (end_col > screen_Columns) /* safety check */ | |
7574 end_col = screen_Columns; | |
7575 if (ScreenLines == NULL | |
7576 || start_row >= end_row | |
7577 || start_col >= end_col) /* nothing to do */ | |
7578 return; | |
7579 | |
7580 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7581 norm_term = ( | |
7582 #ifdef FEAT_GUI | |
7583 !gui.in_use && | |
7584 #endif | |
7585 t_colors <= 1); | |
7586 for (row = start_row; row < end_row; ++row) | |
7587 { | |
1668 | 7588 #ifdef FEAT_MBYTE |
7589 if (has_mbyte | |
7590 # ifdef FEAT_GUI | |
7591 && !gui.in_use | |
7592 # endif | |
7593 ) | |
7594 { | |
7595 /* When drawing over the right halve of a double-wide char clear | |
7596 * out the left halve. When drawing over the left halve of a | |
7597 * double wide-char clear out the right halve. Only needed in a | |
7598 * terminal. */ | |
1685 | 7599 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7600 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7601 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7602 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7603 } |
7604 #endif | |
7 | 7605 /* |
7606 * Try to use delete-line termcap code, when no attributes or in a | |
7607 * "normal" terminal, where a bold/italic space is just a | |
7608 * space. | |
7609 */ | |
7610 did_delete = FALSE; | |
7611 if (c2 == ' ' | |
7612 && end_col == Columns | |
7613 && can_clear(T_CE) | |
7614 && (attr == 0 | |
7615 || (norm_term | |
7616 && attr <= HL_ALL | |
7617 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7618 { | |
7619 /* | |
7620 * check if we really need to clear something | |
7621 */ | |
7622 col = start_col; | |
7623 if (c1 != ' ') /* don't clear first char */ | |
7624 ++col; | |
7625 | |
7626 off = LineOffset[row] + col; | |
7627 end_off = LineOffset[row] + end_col; | |
7628 | |
7629 /* skip blanks (used often, keep it fast!) */ | |
7630 #ifdef FEAT_MBYTE | |
7631 if (enc_utf8) | |
7632 while (off < end_off && ScreenLines[off] == ' ' | |
7633 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7634 ++off; | |
7635 else | |
7636 #endif | |
7637 while (off < end_off && ScreenLines[off] == ' ' | |
7638 && ScreenAttrs[off] == 0) | |
7639 ++off; | |
7640 if (off < end_off) /* something to be cleared */ | |
7641 { | |
7642 col = off - LineOffset[row]; | |
7643 screen_stop_highlight(); | |
7644 term_windgoto(row, col);/* clear rest of this screen line */ | |
7645 out_str(T_CE); | |
7646 screen_start(); /* don't know where cursor is now */ | |
7647 col = end_col - col; | |
7648 while (col--) /* clear chars in ScreenLines */ | |
7649 { | |
7650 ScreenLines[off] = ' '; | |
7651 #ifdef FEAT_MBYTE | |
7652 if (enc_utf8) | |
7653 ScreenLinesUC[off] = 0; | |
7654 #endif | |
7655 ScreenAttrs[off] = 0; | |
7656 ++off; | |
7657 } | |
7658 } | |
7659 did_delete = TRUE; /* the chars are cleared now */ | |
7660 } | |
7661 | |
7662 off = LineOffset[row] + start_col; | |
7663 c = c1; | |
7664 for (col = start_col; col < end_col; ++col) | |
7665 { | |
7666 if (ScreenLines[off] != c | |
7667 #ifdef FEAT_MBYTE | |
714 | 7668 || (enc_utf8 && (int)ScreenLinesUC[off] |
7669 != (c >= 0x80 ? c : 0)) | |
7 | 7670 #endif |
7671 || ScreenAttrs[off] != attr | |
7672 #if defined(FEAT_GUI) || defined(UNIX) | |
7673 || force_next | |
7674 #endif | |
7675 ) | |
7676 { | |
7677 #if defined(FEAT_GUI) || defined(UNIX) | |
7678 /* The bold trick may make a single row of pixels appear in | |
7679 * the next character. When a bold character is removed, the | |
7680 * next character should be redrawn too. This happens for our | |
7681 * own GUI and for some xterms. */ | |
7682 if ( | |
7683 # ifdef FEAT_GUI | |
7684 gui.in_use | |
7685 # endif | |
7686 # if defined(FEAT_GUI) && defined(UNIX) | |
7687 || | |
7688 # endif | |
7689 # ifdef UNIX | |
7690 term_is_xterm | |
7691 # endif | |
7692 ) | |
7693 { | |
7694 if (ScreenLines[off] != ' ' | |
7695 && (ScreenAttrs[off] > HL_ALL | |
7696 || ScreenAttrs[off] & HL_BOLD)) | |
7697 force_next = TRUE; | |
7698 else | |
7699 force_next = FALSE; | |
7700 } | |
7701 #endif | |
7702 ScreenLines[off] = c; | |
7703 #ifdef FEAT_MBYTE | |
7704 if (enc_utf8) | |
7705 { | |
7706 if (c >= 0x80) | |
7707 { | |
7708 ScreenLinesUC[off] = c; | |
714 | 7709 ScreenLinesC[0][off] = 0; |
7 | 7710 } |
7711 else | |
7712 ScreenLinesUC[off] = 0; | |
7713 } | |
7714 #endif | |
7715 ScreenAttrs[off] = attr; | |
7716 if (!did_delete || c != ' ') | |
7717 screen_char(off, row, col); | |
7718 } | |
7719 ++off; | |
7720 if (col == start_col) | |
7721 { | |
7722 if (did_delete) | |
7723 break; | |
7724 c = c2; | |
7725 } | |
7726 } | |
7727 if (end_col == Columns) | |
7728 LineWraps[row] = FALSE; | |
7729 if (row == Rows - 1) /* overwritten the command line */ | |
7730 { | |
7731 redraw_cmdline = TRUE; | |
7732 if (c1 == ' ' && c2 == ' ') | |
7733 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7734 if (start_col == 0) |
7735 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7736 } |
7737 } | |
7738 } | |
7739 | |
7740 /* | |
7741 * Check if there should be a delay. Used before clearing or redrawing the | |
7742 * screen or the command line. | |
7743 */ | |
7744 void | |
7745 check_for_delay(check_msg_scroll) | |
7746 int check_msg_scroll; | |
7747 { | |
7748 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7749 && !did_wait_return | |
7750 && emsg_silent == 0) | |
7751 { | |
7752 out_flush(); | |
7753 ui_delay(1000L, TRUE); | |
7754 emsg_on_display = FALSE; | |
7755 if (check_msg_scroll) | |
7756 msg_scroll = FALSE; | |
7757 } | |
7758 } | |
7759 | |
7760 /* | |
7761 * screen_valid - allocate screen buffers if size changed | |
7762 * If "clear" is TRUE: clear screen if it has been resized. | |
7763 * Returns TRUE if there is a valid screen to write to. | |
7764 * Returns FALSE when starting up and screen not initialized yet. | |
7765 */ | |
7766 int | |
7767 screen_valid(clear) | |
7768 int clear; | |
7769 { | |
7770 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7771 return (ScreenLines != NULL); | |
7772 } | |
7773 | |
7774 /* | |
7775 * Resize the shell to Rows and Columns. | |
7776 * Allocate ScreenLines[] and associated items. | |
7777 * | |
7778 * There may be some time between setting Rows and Columns and (re)allocating | |
7779 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7780 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7781 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7782 * final size of the shell is needed. | |
7783 */ | |
7784 void | |
7785 screenalloc(clear) | |
7786 int clear; | |
7787 { | |
7788 int new_row, old_row; | |
7789 #ifdef FEAT_GUI | |
7790 int old_Rows; | |
7791 #endif | |
7792 win_T *wp; | |
7793 int outofmem = FALSE; | |
7794 int len; | |
7795 schar_T *new_ScreenLines; | |
7796 #ifdef FEAT_MBYTE | |
7797 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7798 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7799 schar_T *new_ScreenLines2 = NULL; |
714 | 7800 int i; |
7 | 7801 #endif |
7802 sattr_T *new_ScreenAttrs; | |
7803 unsigned *new_LineOffset; | |
7804 char_u *new_LineWraps; | |
671 | 7805 #ifdef FEAT_WINDOWS |
681 | 7806 short *new_TabPageIdxs; |
671 | 7807 tabpage_T *tp; |
7808 #endif | |
7 | 7809 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7810 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7811 #ifdef FEAT_AUTOCMD |
7812 int retry_count = 0; | |
7813 | |
7814 retry: | |
7815 #endif | |
7 | 7816 /* |
7817 * Allocation of the screen buffers is done only when the size changes and | |
7818 * when Rows and Columns have been set and we have started doing full | |
7819 * screen stuff. | |
7820 */ | |
7821 if ((ScreenLines != NULL | |
7822 && Rows == screen_Rows | |
7823 && Columns == screen_Columns | |
7824 #ifdef FEAT_MBYTE | |
7825 && enc_utf8 == (ScreenLinesUC != NULL) | |
7826 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7827 && p_mco == Screen_mco |
7 | 7828 #endif |
7829 ) | |
7830 || Rows == 0 | |
7831 || Columns == 0 | |
7832 || (!full_screen && ScreenLines == NULL)) | |
7833 return; | |
7834 | |
7835 /* | |
7836 * It's possible that we produce an out-of-memory message below, which | |
7837 * will cause this function to be called again. To break the loop, just | |
7838 * return here. | |
7839 */ | |
7840 if (entered) | |
7841 return; | |
7842 entered = TRUE; | |
7843 | |
911 | 7844 /* |
7845 * Note that the window sizes are updated before reallocating the arrays, | |
7846 * thus we must not redraw here! | |
7847 */ | |
7848 ++RedrawingDisabled; | |
7849 | |
7 | 7850 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7851 | |
7852 comp_col(); /* recompute columns for shown command and ruler */ | |
7853 | |
7854 /* | |
7855 * We're changing the size of the screen. | |
7856 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7857 * - Move lines from the old arrays into the new arrays, clear extra | |
7858 * lines (unless the screen is going to be cleared). | |
7859 * - Free the old arrays. | |
7860 * | |
7861 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7862 * Continuing with the old ScreenLines may result in a crash, because the | |
7863 * size is wrong. | |
7864 */ | |
671 | 7865 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7866 win_free_lsize(wp); |
1946 | 7867 #ifdef FEAT_AUTOCMD |
7868 if (aucmd_win != NULL) | |
7869 win_free_lsize(aucmd_win); | |
7870 #endif | |
7 | 7871 |
7872 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7873 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7874 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7875 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7876 if (enc_utf8) |
7877 { | |
7878 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7879 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7880 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7881 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7882 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7883 } | |
7884 if (enc_dbcs == DBCS_JPNU) | |
7885 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7886 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7887 #endif | |
7888 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7889 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7890 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7891 Rows * sizeof(unsigned)), FALSE); | |
7892 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7893 #ifdef FEAT_WINDOWS |
681 | 7894 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7895 #endif |
7 | 7896 |
677 | 7897 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7898 { |
7899 if (win_alloc_lines(wp) == FAIL) | |
7900 { | |
7901 outofmem = TRUE; | |
7902 #ifdef FEAT_WINDOWS | |
1819 | 7903 goto give_up; |
7904 #endif | |
7905 } | |
7906 } | |
1906 | 7907 #ifdef FEAT_AUTOCMD |
1946 | 7908 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7909 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7910 outofmem = TRUE; |
7911 #endif | |
1819 | 7912 #ifdef FEAT_WINDOWS |
7913 give_up: | |
7914 #endif | |
7 | 7915 |
714 | 7916 #ifdef FEAT_MBYTE |
7917 for (i = 0; i < p_mco; ++i) | |
7918 if (new_ScreenLinesC[i] == NULL) | |
7919 break; | |
7920 #endif | |
7 | 7921 if (new_ScreenLines == NULL |
7922 #ifdef FEAT_MBYTE | |
714 | 7923 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 7924 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
7925 #endif | |
7926 || new_ScreenAttrs == NULL | |
7927 || new_LineOffset == NULL | |
7928 || new_LineWraps == NULL | |
671 | 7929 #ifdef FEAT_WINDOWS |
7930 || new_TabPageIdxs == NULL | |
7931 #endif | |
7 | 7932 || outofmem) |
7933 { | |
944 | 7934 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 7935 { |
7936 /* guess the size */ | |
7937 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
7938 | |
7939 /* Remember we did this to avoid getting outofmem messages over | |
7940 * and over again. */ | |
944 | 7941 done_outofmem_msg = TRUE; |
534 | 7942 } |
7 | 7943 vim_free(new_ScreenLines); |
7944 new_ScreenLines = NULL; | |
7945 #ifdef FEAT_MBYTE | |
7946 vim_free(new_ScreenLinesUC); | |
7947 new_ScreenLinesUC = NULL; | |
714 | 7948 for (i = 0; i < p_mco; ++i) |
7949 { | |
7950 vim_free(new_ScreenLinesC[i]); | |
7951 new_ScreenLinesC[i] = NULL; | |
7952 } | |
7 | 7953 vim_free(new_ScreenLines2); |
7954 new_ScreenLines2 = NULL; | |
7955 #endif | |
7956 vim_free(new_ScreenAttrs); | |
7957 new_ScreenAttrs = NULL; | |
7958 vim_free(new_LineOffset); | |
7959 new_LineOffset = NULL; | |
7960 vim_free(new_LineWraps); | |
7961 new_LineWraps = NULL; | |
671 | 7962 #ifdef FEAT_WINDOWS |
7963 vim_free(new_TabPageIdxs); | |
7964 new_TabPageIdxs = NULL; | |
7965 #endif | |
7 | 7966 } |
7967 else | |
7968 { | |
944 | 7969 done_outofmem_msg = FALSE; |
534 | 7970 |
7 | 7971 for (new_row = 0; new_row < Rows; ++new_row) |
7972 { | |
7973 new_LineOffset[new_row] = new_row * Columns; | |
7974 new_LineWraps[new_row] = FALSE; | |
7975 | |
7976 /* | |
7977 * If the screen is not going to be cleared, copy as much as | |
7978 * possible from the old screen to the new one and clear the rest | |
7979 * (used when resizing the window at the "--more--" prompt or when | |
7980 * executing an external command, for the GUI). | |
7981 */ | |
7982 if (!clear) | |
7983 { | |
7984 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
7985 ' ', (size_t)Columns * sizeof(schar_T)); | |
7986 #ifdef FEAT_MBYTE | |
7987 if (enc_utf8) | |
7988 { | |
7989 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
7990 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 7991 for (i = 0; i < p_mco; ++i) |
7992 (void)vim_memset(new_ScreenLinesC[i] | |
7993 + new_row * Columns, | |
7 | 7994 0, (size_t)Columns * sizeof(u8char_T)); |
7995 } | |
7996 if (enc_dbcs == DBCS_JPNU) | |
7997 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
7998 0, (size_t)Columns * sizeof(schar_T)); | |
7999 #endif | |
8000 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8001 0, (size_t)Columns * sizeof(sattr_T)); | |
8002 old_row = new_row + (screen_Rows - Rows); | |
534 | 8003 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8004 { |
8005 if (screen_Columns < Columns) | |
8006 len = screen_Columns; | |
8007 else | |
8008 len = Columns; | |
26 | 8009 #ifdef FEAT_MBYTE |
571 | 8010 /* When switching to utf-8 don't copy characters, they |
714 | 8011 * may be invalid now. Also when p_mco changes. */ |
8012 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8013 && p_mco == Screen_mco) | |
26 | 8014 #endif |
8015 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8016 ScreenLines + LineOffset[old_row], | |
8017 (size_t)len * sizeof(schar_T)); | |
7 | 8018 #ifdef FEAT_MBYTE |
714 | 8019 if (enc_utf8 && ScreenLinesUC != NULL |
8020 && p_mco == Screen_mco) | |
7 | 8021 { |
8022 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8023 ScreenLinesUC + LineOffset[old_row], | |
8024 (size_t)len * sizeof(u8char_T)); | |
714 | 8025 for (i = 0; i < p_mco; ++i) |
8026 mch_memmove(new_ScreenLinesC[i] | |
8027 + new_LineOffset[new_row], | |
8028 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8029 (size_t)len * sizeof(u8char_T)); |
8030 } | |
8031 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8032 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8033 ScreenLines2 + LineOffset[old_row], | |
8034 (size_t)len * sizeof(schar_T)); | |
8035 #endif | |
8036 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8037 ScreenAttrs + LineOffset[old_row], | |
8038 (size_t)len * sizeof(sattr_T)); | |
8039 } | |
8040 } | |
8041 } | |
8042 /* Use the last line of the screen for the current line. */ | |
8043 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8044 } | |
8045 | |
356 | 8046 free_screenlines(); |
8047 | |
7 | 8048 ScreenLines = new_ScreenLines; |
8049 #ifdef FEAT_MBYTE | |
8050 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8051 for (i = 0; i < p_mco; ++i) |
8052 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8053 Screen_mco = p_mco; | |
7 | 8054 ScreenLines2 = new_ScreenLines2; |
8055 #endif | |
8056 ScreenAttrs = new_ScreenAttrs; | |
8057 LineOffset = new_LineOffset; | |
8058 LineWraps = new_LineWraps; | |
671 | 8059 #ifdef FEAT_WINDOWS |
8060 TabPageIdxs = new_TabPageIdxs; | |
8061 #endif | |
7 | 8062 |
8063 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8064 * size of ScreenLines[]. Set them before calling anything. */ | |
8065 #ifdef FEAT_GUI | |
8066 old_Rows = screen_Rows; | |
8067 #endif | |
8068 screen_Rows = Rows; | |
8069 screen_Columns = Columns; | |
8070 | |
8071 must_redraw = CLEAR; /* need to clear the screen later */ | |
8072 if (clear) | |
8073 screenclear2(); | |
8074 | |
8075 #ifdef FEAT_GUI | |
8076 else if (gui.in_use | |
8077 && !gui.starting | |
8078 && ScreenLines != NULL | |
8079 && old_Rows != Rows) | |
8080 { | |
8081 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8082 /* | |
8083 * Adjust the position of the cursor, for when executing an external | |
8084 * command. | |
8085 */ | |
8086 if (msg_row >= Rows) /* Rows got smaller */ | |
8087 msg_row = Rows - 1; /* put cursor at last row */ | |
8088 else if (Rows > old_Rows) /* Rows got bigger */ | |
8089 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8090 if (msg_col >= Columns) /* Columns got smaller */ | |
8091 msg_col = Columns - 1; /* put cursor at last column */ | |
8092 } | |
8093 #endif | |
8094 | |
8095 entered = FALSE; | |
911 | 8096 --RedrawingDisabled; |
766 | 8097 |
8098 #ifdef FEAT_AUTOCMD | |
1824 | 8099 /* |
8100 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8101 * in case applying autocommands always changes Rows or Columns. | |
8102 */ | |
8103 if (starting == 0 && ++retry_count <= 3) | |
8104 { | |
766 | 8105 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8106 /* In rare cases, autocommands may have altered Rows or Columns, |
8107 * jump back to check if we need to allocate the screen again. */ | |
8108 goto retry; | |
8109 } | |
766 | 8110 #endif |
7 | 8111 } |
8112 | |
8113 void | |
356 | 8114 free_screenlines() |
8115 { | |
8116 #ifdef FEAT_MBYTE | |
714 | 8117 int i; |
8118 | |
356 | 8119 vim_free(ScreenLinesUC); |
714 | 8120 for (i = 0; i < Screen_mco; ++i) |
8121 vim_free(ScreenLinesC[i]); | |
356 | 8122 vim_free(ScreenLines2); |
8123 #endif | |
714 | 8124 vim_free(ScreenLines); |
356 | 8125 vim_free(ScreenAttrs); |
8126 vim_free(LineOffset); | |
8127 vim_free(LineWraps); | |
671 | 8128 #ifdef FEAT_WINDOWS |
8129 vim_free(TabPageIdxs); | |
8130 #endif | |
356 | 8131 } |
8132 | |
8133 void | |
7 | 8134 screenclear() |
8135 { | |
8136 check_for_delay(FALSE); | |
8137 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8138 screenclear2(); /* clear the screen */ | |
8139 } | |
8140 | |
8141 static void | |
8142 screenclear2() | |
8143 { | |
8144 int i; | |
8145 | |
8146 if (starting == NO_SCREEN || ScreenLines == NULL | |
8147 #ifdef FEAT_GUI | |
8148 || (gui.in_use && gui.starting) | |
8149 #endif | |
8150 ) | |
8151 return; | |
8152 | |
8153 #ifdef FEAT_GUI | |
8154 if (!gui.in_use) | |
8155 #endif | |
8156 screen_attr = -1; /* force setting the Normal colors */ | |
8157 screen_stop_highlight(); /* don't want highlighting here */ | |
8158 | |
8159 #ifdef FEAT_CLIPBOARD | |
8160 /* disable selection without redrawing it */ | |
8161 clip_scroll_selection(9999); | |
8162 #endif | |
8163 | |
8164 /* blank out ScreenLines */ | |
8165 for (i = 0; i < Rows; ++i) | |
8166 { | |
8167 lineclear(LineOffset[i], (int)Columns); | |
8168 LineWraps[i] = FALSE; | |
8169 } | |
8170 | |
8171 if (can_clear(T_CL)) | |
8172 { | |
8173 out_str(T_CL); /* clear the display */ | |
8174 clear_cmdline = FALSE; | |
644 | 8175 mode_displayed = FALSE; |
7 | 8176 } |
8177 else | |
8178 { | |
8179 /* can't clear the screen, mark all chars with invalid attributes */ | |
8180 for (i = 0; i < Rows; ++i) | |
8181 lineinvalid(LineOffset[i], (int)Columns); | |
8182 clear_cmdline = TRUE; | |
8183 } | |
8184 | |
8185 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8186 | |
8187 win_rest_invalid(firstwin); | |
8188 redraw_cmdline = TRUE; | |
670 | 8189 #ifdef FEAT_WINDOWS |
673 | 8190 redraw_tabline = TRUE; |
670 | 8191 #endif |
7 | 8192 if (must_redraw == CLEAR) /* no need to clear again */ |
8193 must_redraw = NOT_VALID; | |
8194 compute_cmdrow(); | |
8195 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8196 msg_col = 0; | |
8197 screen_start(); /* don't know where cursor is now */ | |
8198 msg_scrolled = 0; /* can't scroll back */ | |
8199 msg_didany = FALSE; | |
8200 msg_didout = FALSE; | |
8201 } | |
8202 | |
8203 /* | |
8204 * Clear one line in ScreenLines. | |
8205 */ | |
8206 static void | |
8207 lineclear(off, width) | |
8208 unsigned off; | |
8209 int width; | |
8210 { | |
8211 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8212 #ifdef FEAT_MBYTE | |
8213 if (enc_utf8) | |
8214 (void)vim_memset(ScreenLinesUC + off, 0, | |
8215 (size_t)width * sizeof(u8char_T)); | |
8216 #endif | |
8217 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8218 } | |
8219 | |
8220 /* | |
8221 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8222 * invalid value. | |
8223 */ | |
8224 static void | |
8225 lineinvalid(off, width) | |
8226 unsigned off; | |
8227 int width; | |
8228 { | |
8229 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8230 } | |
8231 | |
8232 #ifdef FEAT_VERTSPLIT | |
8233 /* | |
8234 * Copy part of a Screenline for vertically split window "wp". | |
8235 */ | |
8236 static void | |
8237 linecopy(to, from, wp) | |
8238 int to; | |
8239 int from; | |
8240 win_T *wp; | |
8241 { | |
8242 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8243 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8244 | |
8245 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8246 wp->w_width * sizeof(schar_T)); | |
8247 # ifdef FEAT_MBYTE | |
8248 if (enc_utf8) | |
8249 { | |
714 | 8250 int i; |
8251 | |
7 | 8252 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8253 wp->w_width * sizeof(u8char_T)); | |
714 | 8254 for (i = 0; i < p_mco; ++i) |
8255 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8256 wp->w_width * sizeof(u8char_T)); | |
7 | 8257 } |
8258 if (enc_dbcs == DBCS_JPNU) | |
8259 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8260 wp->w_width * sizeof(schar_T)); | |
8261 # endif | |
8262 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8263 wp->w_width * sizeof(sattr_T)); | |
8264 } | |
8265 #endif | |
8266 | |
8267 /* | |
8268 * Return TRUE if clearing with term string "p" would work. | |
8269 * It can't work when the string is empty or it won't set the right background. | |
8270 */ | |
8271 int | |
8272 can_clear(p) | |
8273 char_u *p; | |
8274 { | |
8275 return (*p != NUL && (t_colors <= 1 | |
8276 #ifdef FEAT_GUI | |
8277 || gui.in_use | |
8278 #endif | |
8279 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8280 } | |
8281 | |
8282 /* | |
8283 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8284 * something directly to the screen (shell commands) or a terminal control | |
8285 * code. | |
8286 */ | |
8287 void | |
8288 screen_start() | |
8289 { | |
8290 screen_cur_row = screen_cur_col = 9999; | |
8291 } | |
8292 | |
8293 /* | |
8294 * Move the cursor to position "row","col" in the screen. | |
8295 * This tries to find the most efficient way to move, minimizing the number of | |
8296 * characters sent to the terminal. | |
8297 */ | |
8298 void | |
8299 windgoto(row, col) | |
8300 int row; | |
8301 int col; | |
8302 { | |
205 | 8303 sattr_T *p; |
7 | 8304 int i; |
8305 int plan; | |
8306 int cost; | |
8307 int wouldbe_col; | |
8308 int noinvcurs; | |
8309 char_u *bs; | |
8310 int goto_cost; | |
8311 int attr; | |
8312 | |
1213 | 8313 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8314 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8315 | |
8316 #define PLAN_LE 1 | |
8317 #define PLAN_CR 2 | |
8318 #define PLAN_NL 3 | |
8319 #define PLAN_WRITE 4 | |
8320 /* Can't use ScreenLines unless initialized */ | |
8321 if (ScreenLines == NULL) | |
8322 return; | |
8323 | |
8324 if (col != screen_cur_col || row != screen_cur_row) | |
8325 { | |
8326 /* Check for valid position. */ | |
8327 if (row < 0) /* window without text lines? */ | |
8328 row = 0; | |
8329 if (row >= screen_Rows) | |
8330 row = screen_Rows - 1; | |
8331 if (col >= screen_Columns) | |
8332 col = screen_Columns - 1; | |
8333 | |
8334 /* check if no cursor movement is allowed in highlight mode */ | |
8335 if (screen_attr && *T_MS == NUL) | |
8336 noinvcurs = HIGHL_COST; | |
8337 else | |
8338 noinvcurs = 0; | |
8339 goto_cost = GOTO_COST + noinvcurs; | |
8340 | |
8341 /* | |
8342 * Plan how to do the positioning: | |
8343 * 1. Use CR to move it to column 0, same row. | |
8344 * 2. Use T_LE to move it a few columns to the left. | |
8345 * 3. Use NL to move a few lines down, column 0. | |
8346 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8347 * | |
8348 * Don't do this if the cursor went beyond the last column, the cursor | |
8349 * position is unknown then (some terminals wrap, some don't ) | |
8350 * | |
1213 | 8351 * First check if the highlighting attributes allow us to write |
7 | 8352 * characters to move the cursor to the right. |
8353 */ | |
8354 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8355 { | |
8356 /* | |
8357 * If the cursor is in the same row, bigger col, we can use CR | |
8358 * or T_LE. | |
8359 */ | |
8360 bs = NULL; /* init for GCC */ | |
8361 attr = screen_attr; | |
8362 if (row == screen_cur_row && col < screen_cur_col) | |
8363 { | |
8364 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8365 if (*T_LE) | |
8366 bs = T_LE; /* "cursor left" */ | |
8367 else | |
8368 bs = T_BC; /* "backspace character (old) */ | |
8369 if (*bs) | |
8370 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8371 else | |
8372 cost = 999; | |
8373 if (col + 1 < cost) /* using CR is less characters */ | |
8374 { | |
8375 plan = PLAN_CR; | |
8376 wouldbe_col = 0; | |
8377 cost = 1; /* CR is just one character */ | |
8378 } | |
8379 else | |
8380 { | |
8381 plan = PLAN_LE; | |
8382 wouldbe_col = col; | |
8383 } | |
8384 if (noinvcurs) /* will stop highlighting */ | |
8385 { | |
8386 cost += noinvcurs; | |
8387 attr = 0; | |
8388 } | |
8389 } | |
8390 | |
8391 /* | |
8392 * If the cursor is above where we want to be, we can use CR LF. | |
8393 */ | |
8394 else if (row > screen_cur_row) | |
8395 { | |
8396 plan = PLAN_NL; | |
8397 wouldbe_col = 0; | |
8398 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8399 if (noinvcurs) /* will stop highlighting */ | |
8400 { | |
8401 cost += noinvcurs; | |
8402 attr = 0; | |
8403 } | |
8404 } | |
8405 | |
8406 /* | |
8407 * If the cursor is in the same row, smaller col, just use write. | |
8408 */ | |
8409 else | |
8410 { | |
8411 plan = PLAN_WRITE; | |
8412 wouldbe_col = screen_cur_col; | |
8413 cost = 0; | |
8414 } | |
8415 | |
8416 /* | |
8417 * Check if any characters that need to be written have the | |
8418 * correct attributes. Also avoid UTF-8 characters. | |
8419 */ | |
8420 i = col - wouldbe_col; | |
8421 if (i > 0) | |
8422 cost += i; | |
8423 if (cost < goto_cost && i > 0) | |
8424 { | |
8425 /* | |
8426 * Check if the attributes are correct without additionally | |
8427 * stopping highlighting. | |
8428 */ | |
8429 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8430 while (i && *p++ == attr) | |
8431 --i; | |
8432 if (i != 0) | |
8433 { | |
8434 /* | |
8435 * Try if it works when highlighting is stopped here. | |
8436 */ | |
8437 if (*--p == 0) | |
8438 { | |
8439 cost += noinvcurs; | |
8440 while (i && *p++ == 0) | |
8441 --i; | |
8442 } | |
8443 if (i != 0) | |
8444 cost = 999; /* different attributes, don't do it */ | |
8445 } | |
8446 #ifdef FEAT_MBYTE | |
8447 if (enc_utf8) | |
8448 { | |
8449 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8450 for (i = wouldbe_col; i < col; ++i) | |
8451 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8452 { | |
8453 cost = 999; | |
8454 break; | |
8455 } | |
8456 } | |
8457 #endif | |
8458 } | |
8459 | |
8460 /* | |
8461 * We can do it without term_windgoto()! | |
8462 */ | |
8463 if (cost < goto_cost) | |
8464 { | |
8465 if (plan == PLAN_LE) | |
8466 { | |
8467 if (noinvcurs) | |
8468 screen_stop_highlight(); | |
8469 while (screen_cur_col > col) | |
8470 { | |
8471 out_str(bs); | |
8472 --screen_cur_col; | |
8473 } | |
8474 } | |
8475 else if (plan == PLAN_CR) | |
8476 { | |
8477 if (noinvcurs) | |
8478 screen_stop_highlight(); | |
8479 out_char('\r'); | |
8480 screen_cur_col = 0; | |
8481 } | |
8482 else if (plan == PLAN_NL) | |
8483 { | |
8484 if (noinvcurs) | |
8485 screen_stop_highlight(); | |
8486 while (screen_cur_row < row) | |
8487 { | |
8488 out_char('\n'); | |
8489 ++screen_cur_row; | |
8490 } | |
8491 screen_cur_col = 0; | |
8492 } | |
8493 | |
8494 i = col - screen_cur_col; | |
8495 if (i > 0) | |
8496 { | |
8497 /* | |
8498 * Use cursor-right if it's one character only. Avoids | |
8499 * removing a line of pixels from the last bold char, when | |
8500 * using the bold trick in the GUI. | |
8501 */ | |
8502 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8503 { | |
8504 while (i-- > 0) | |
8505 out_char(*T_ND); | |
8506 } | |
8507 else | |
8508 { | |
8509 int off; | |
8510 | |
8511 off = LineOffset[row] + screen_cur_col; | |
8512 while (i-- > 0) | |
8513 { | |
8514 if (ScreenAttrs[off] != screen_attr) | |
8515 screen_stop_highlight(); | |
8516 #ifdef FEAT_MBYTE | |
8517 out_flush_check(); | |
8518 #endif | |
8519 out_char(ScreenLines[off]); | |
8520 #ifdef FEAT_MBYTE | |
8521 if (enc_dbcs == DBCS_JPNU | |
8522 && ScreenLines[off] == 0x8e) | |
8523 out_char(ScreenLines2[off]); | |
8524 #endif | |
8525 ++off; | |
8526 } | |
8527 } | |
8528 } | |
8529 } | |
8530 } | |
8531 else | |
8532 cost = 999; | |
8533 | |
8534 if (cost >= goto_cost) | |
8535 { | |
8536 if (noinvcurs) | |
8537 screen_stop_highlight(); | |
8538 if (row == screen_cur_row && (col > screen_cur_col) && | |
8539 *T_CRI != NUL) | |
8540 term_cursor_right(col - screen_cur_col); | |
8541 else | |
8542 term_windgoto(row, col); | |
8543 } | |
8544 screen_cur_row = row; | |
8545 screen_cur_col = col; | |
8546 } | |
8547 } | |
8548 | |
8549 /* | |
8550 * Set cursor to its position in the current window. | |
8551 */ | |
8552 void | |
8553 setcursor() | |
8554 { | |
8555 if (redrawing()) | |
8556 { | |
8557 validate_cursor(); | |
8558 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8559 W_WINCOL(curwin) + ( | |
8560 #ifdef FEAT_RIGHTLEFT | |
1545 | 8561 /* With 'rightleft' set and the cursor on a double-wide |
8562 * character, position it on the leftmost column. */ | |
7 | 8563 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8564 # ifdef FEAT_MBYTE | |
1545 | 8565 (has_mbyte |
8566 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8567 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8568 # endif |
8569 1)) : | |
8570 #endif | |
8571 curwin->w_wcol)); | |
8572 } | |
8573 } | |
8574 | |
8575 | |
8576 /* | |
8577 * insert 'line_count' lines at 'row' in window 'wp' | |
8578 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8579 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8580 * scrolling. | |
8581 * Returns FAIL if the lines are not inserted, OK for success. | |
8582 */ | |
8583 int | |
8584 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8585 win_T *wp; | |
8586 int row; | |
8587 int line_count; | |
8588 int invalid; | |
8589 int mayclear; | |
8590 { | |
8591 int did_delete; | |
8592 int nextrow; | |
8593 int lastrow; | |
8594 int retval; | |
8595 | |
8596 if (invalid) | |
8597 wp->w_lines_valid = 0; | |
8598 | |
8599 if (wp->w_height < 5) | |
8600 return FAIL; | |
8601 | |
8602 if (line_count > wp->w_height - row) | |
8603 line_count = wp->w_height - row; | |
8604 | |
8605 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8606 if (retval != MAYBE) | |
8607 return retval; | |
8608 | |
8609 /* | |
8610 * If there is a next window or a status line, we first try to delete the | |
8611 * lines at the bottom to avoid messing what is after the window. | |
8612 * If this fails and there are following windows, don't do anything to avoid | |
8613 * messing up those windows, better just redraw. | |
8614 */ | |
8615 did_delete = FALSE; | |
8616 #ifdef FEAT_WINDOWS | |
8617 if (wp->w_next != NULL || wp->w_status_height) | |
8618 { | |
8619 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8620 line_count, (int)Rows, FALSE, NULL) == OK) | |
8621 did_delete = TRUE; | |
8622 else if (wp->w_next) | |
8623 return FAIL; | |
8624 } | |
8625 #endif | |
8626 /* | |
8627 * if no lines deleted, blank the lines that will end up below the window | |
8628 */ | |
8629 if (!did_delete) | |
8630 { | |
8631 #ifdef FEAT_WINDOWS | |
8632 wp->w_redr_status = TRUE; | |
8633 #endif | |
8634 redraw_cmdline = TRUE; | |
8635 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8636 lastrow = nextrow + line_count; | |
8637 if (lastrow > Rows) | |
8638 lastrow = Rows; | |
8639 screen_fill(nextrow - line_count, lastrow - line_count, | |
8640 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8641 ' ', ' ', 0); | |
8642 } | |
8643 | |
8644 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8645 == FAIL) | |
8646 { | |
8647 /* deletion will have messed up other windows */ | |
8648 if (did_delete) | |
8649 { | |
8650 #ifdef FEAT_WINDOWS | |
8651 wp->w_redr_status = TRUE; | |
8652 #endif | |
8653 win_rest_invalid(W_NEXT(wp)); | |
8654 } | |
8655 return FAIL; | |
8656 } | |
8657 | |
8658 return OK; | |
8659 } | |
8660 | |
8661 /* | |
8662 * delete "line_count" window lines at "row" in window "wp" | |
8663 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8664 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8665 * scrolling | |
8666 * Return OK for success, FAIL if the lines are not deleted. | |
8667 */ | |
8668 int | |
8669 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8670 win_T *wp; | |
8671 int row; | |
8672 int line_count; | |
8673 int invalid; | |
8674 int mayclear; | |
8675 { | |
8676 int retval; | |
8677 | |
8678 if (invalid) | |
8679 wp->w_lines_valid = 0; | |
8680 | |
8681 if (line_count > wp->w_height - row) | |
8682 line_count = wp->w_height - row; | |
8683 | |
8684 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8685 if (retval != MAYBE) | |
8686 return retval; | |
8687 | |
8688 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8689 (int)Rows, FALSE, NULL) == FAIL) | |
8690 return FAIL; | |
8691 | |
8692 #ifdef FEAT_WINDOWS | |
8693 /* | |
8694 * If there are windows or status lines below, try to put them at the | |
8695 * correct place. If we can't do that, they have to be redrawn. | |
8696 */ | |
8697 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8698 { | |
8699 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8700 line_count, (int)Rows, NULL) == FAIL) | |
8701 { | |
8702 wp->w_redr_status = TRUE; | |
8703 win_rest_invalid(wp->w_next); | |
8704 } | |
8705 } | |
8706 /* | |
8707 * If this is the last window and there is no status line, redraw the | |
8708 * command line later. | |
8709 */ | |
8710 else | |
8711 #endif | |
8712 redraw_cmdline = TRUE; | |
8713 return OK; | |
8714 } | |
8715 | |
8716 /* | |
8717 * Common code for win_ins_lines() and win_del_lines(). | |
8718 * Returns OK or FAIL when the work has been done. | |
8719 * Returns MAYBE when not finished yet. | |
8720 */ | |
8721 static int | |
8722 win_do_lines(wp, row, line_count, mayclear, del) | |
8723 win_T *wp; | |
8724 int row; | |
8725 int line_count; | |
8726 int mayclear; | |
8727 int del; | |
8728 { | |
8729 int retval; | |
8730 | |
8731 if (!redrawing() || line_count <= 0) | |
8732 return FAIL; | |
8733 | |
8734 /* only a few lines left: redraw is faster */ | |
8735 if (mayclear && Rows - line_count < 5 | |
8736 #ifdef FEAT_VERTSPLIT | |
8737 && wp->w_width == Columns | |
8738 #endif | |
8739 ) | |
8740 { | |
8741 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8742 return FAIL; | |
8743 } | |
8744 | |
8745 /* | |
8746 * Delete all remaining lines | |
8747 */ | |
8748 if (row + line_count >= wp->w_height) | |
8749 { | |
8750 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8751 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8752 ' ', ' ', 0); | |
8753 return OK; | |
8754 } | |
8755 | |
8756 /* | |
8757 * when scrolling, the message on the command line should be cleared, | |
8758 * otherwise it will stay there forever. | |
8759 */ | |
8760 clear_cmdline = TRUE; | |
8761 | |
8762 /* | |
8763 * If the terminal can set a scroll region, use that. | |
8764 * Always do this in a vertically split window. This will redraw from | |
8765 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8766 * win_line(). | |
8767 * Don't use a scroll region when we are going to redraw the text, writing | |
8768 * a character in the lower right corner of the scroll region causes a | |
8769 * scroll-up in the DJGPP version. | |
8770 */ | |
8771 if (scroll_region | |
8772 #ifdef FEAT_VERTSPLIT | |
8773 || W_WIDTH(wp) != Columns | |
8774 #endif | |
8775 ) | |
8776 { | |
8777 #ifdef FEAT_VERTSPLIT | |
8778 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8779 #endif | |
8780 scroll_region_set(wp, row); | |
8781 if (del) | |
8782 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8783 wp->w_height - row, FALSE, wp); | |
8784 else | |
8785 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8786 wp->w_height - row, wp); | |
8787 #ifdef FEAT_VERTSPLIT | |
8788 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8789 #endif | |
8790 scroll_region_reset(); | |
8791 return retval; | |
8792 } | |
8793 | |
8794 #ifdef FEAT_WINDOWS | |
8795 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8796 return FAIL; | |
8797 #endif | |
8798 | |
8799 return MAYBE; | |
8800 } | |
8801 | |
8802 /* | |
8803 * window 'wp' and everything after it is messed up, mark it for redraw | |
8804 */ | |
8805 static void | |
8806 win_rest_invalid(wp) | |
8807 win_T *wp; | |
8808 { | |
8809 #ifdef FEAT_WINDOWS | |
8810 while (wp != NULL) | |
8811 #else | |
8812 if (wp != NULL) | |
8813 #endif | |
8814 { | |
8815 redraw_win_later(wp, NOT_VALID); | |
8816 #ifdef FEAT_WINDOWS | |
8817 wp->w_redr_status = TRUE; | |
8818 wp = wp->w_next; | |
8819 #endif | |
8820 } | |
8821 redraw_cmdline = TRUE; | |
8822 } | |
8823 | |
8824 /* | |
8825 * The rest of the routines in this file perform screen manipulations. The | |
8826 * given operation is performed physically on the screen. The corresponding | |
8827 * change is also made to the internal screen image. In this way, the editor | |
8828 * anticipates the effect of editing changes on the appearance of the screen. | |
8829 * That way, when we call screenupdate a complete redraw isn't usually | |
8830 * necessary. Another advantage is that we can keep adding code to anticipate | |
8831 * screen changes, and in the meantime, everything still works. | |
8832 */ | |
8833 | |
8834 /* | |
8835 * types for inserting or deleting lines | |
8836 */ | |
8837 #define USE_T_CAL 1 | |
8838 #define USE_T_CDL 2 | |
8839 #define USE_T_AL 3 | |
8840 #define USE_T_CE 4 | |
8841 #define USE_T_DL 5 | |
8842 #define USE_T_SR 6 | |
8843 #define USE_NL 7 | |
8844 #define USE_T_CD 8 | |
8845 #define USE_REDRAW 9 | |
8846 | |
8847 /* | |
8848 * insert lines on the screen and update ScreenLines[] | |
8849 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8850 * When scrolling region used 'off' is the offset from the top for the region. | |
8851 * 'row' and 'end' are relative to the start of the region. | |
8852 * | |
8853 * return FAIL for failure, OK for success. | |
8854 */ | |
446 | 8855 int |
7 | 8856 screen_ins_lines(off, row, line_count, end, wp) |
8857 int off; | |
8858 int row; | |
8859 int line_count; | |
8860 int end; | |
8861 win_T *wp; /* NULL or window to use width from */ | |
8862 { | |
8863 int i; | |
8864 int j; | |
8865 unsigned temp; | |
8866 int cursor_row; | |
8867 int type; | |
8868 int result_empty; | |
8869 int can_ce = can_clear(T_CE); | |
8870 | |
8871 /* | |
8872 * FAIL if | |
8873 * - there is no valid screen | |
8874 * - the screen has to be redrawn completely | |
8875 * - the line count is less than one | |
8876 * - the line count is more than 'ttyscroll' | |
8877 */ | |
8878 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8879 return FAIL; | |
8880 | |
8881 /* | |
8882 * There are seven ways to insert lines: | |
8883 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8884 * characters from ScreenLines[]. | |
8885 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8886 * the insert is just empty lines | |
8887 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8888 * present or line_count > 1. It looks better if we do all the inserts | |
8889 * at once. | |
8890 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8891 * insert is just empty lines and T_CE is not present or line_count > | |
8892 * 1. | |
8893 * 4. Use T_AL (insert line) if it exists. | |
8894 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8895 * just empty lines. | |
8896 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8897 * just empty lines. | |
8898 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8899 * the 'da' flag is not set or we have clear line capability. | |
8900 * 8. redraw the characters from ScreenLines[]. | |
8901 * | |
8902 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8903 * the scrollbar for the window. It does have insert line, use that if it | |
8904 * exists. | |
8905 */ | |
8906 result_empty = (row + line_count >= end); | |
8907 #ifdef FEAT_VERTSPLIT | |
8908 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8909 type = USE_REDRAW; | |
8910 else | |
8911 #endif | |
8912 if (can_clear(T_CD) && result_empty) | |
8913 type = USE_T_CD; | |
8914 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
8915 type = USE_T_CAL; | |
8916 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
8917 type = USE_T_CDL; | |
8918 else if (*T_AL != NUL) | |
8919 type = USE_T_AL; | |
8920 else if (can_ce && result_empty) | |
8921 type = USE_T_CE; | |
8922 else if (*T_DL != NUL && result_empty) | |
8923 type = USE_T_DL; | |
8924 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
8925 type = USE_T_SR; | |
8926 else | |
8927 return FAIL; | |
8928 | |
8929 /* | |
8930 * For clearing the lines screen_del_lines() is used. This will also take | |
8931 * care of t_db if necessary. | |
8932 */ | |
8933 if (type == USE_T_CD || type == USE_T_CDL || | |
8934 type == USE_T_CE || type == USE_T_DL) | |
8935 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
8936 | |
8937 /* | |
8938 * If text is retained below the screen, first clear or delete as many | |
8939 * lines at the bottom of the window as are about to be inserted so that | |
8940 * the deleted lines won't later surface during a screen_del_lines. | |
8941 */ | |
8942 if (*T_DB) | |
8943 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
8944 | |
8945 #ifdef FEAT_CLIPBOARD | |
8946 /* Remove a modeless selection when inserting lines halfway the screen | |
8947 * or not the full width of the screen. */ | |
8948 if (off + row > 0 | |
8949 # ifdef FEAT_VERTSPLIT | |
8950 || (wp != NULL && wp->w_width != Columns) | |
8951 # endif | |
8952 ) | |
8953 clip_clear_selection(); | |
8954 else | |
8955 clip_scroll_selection(-line_count); | |
8956 #endif | |
8957 | |
8958 #ifdef FEAT_GUI | |
8959 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
8960 * scrolling is actually carried out. */ | |
8961 gui_dont_update_cursor(); | |
8962 #endif | |
8963 | |
8964 if (*T_CCS != NUL) /* cursor relative to region */ | |
8965 cursor_row = row; | |
8966 else | |
8967 cursor_row = row + off; | |
8968 | |
8969 /* | |
8970 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
8971 * Clear the inserted lines in ScreenLines[]. | |
8972 */ | |
8973 row += off; | |
8974 end += off; | |
8975 for (i = 0; i < line_count; ++i) | |
8976 { | |
8977 #ifdef FEAT_VERTSPLIT | |
8978 if (wp != NULL && wp->w_width != Columns) | |
8979 { | |
8980 /* need to copy part of a line */ | |
8981 j = end - 1 - i; | |
8982 while ((j -= line_count) >= row) | |
8983 linecopy(j + line_count, j, wp); | |
8984 j += line_count; | |
8985 if (can_clear((char_u *)" ")) | |
8986 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8987 else | |
8988 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8989 LineWraps[j] = FALSE; | |
8990 } | |
8991 else | |
8992 #endif | |
8993 { | |
8994 j = end - 1 - i; | |
8995 temp = LineOffset[j]; | |
8996 while ((j -= line_count) >= row) | |
8997 { | |
8998 LineOffset[j + line_count] = LineOffset[j]; | |
8999 LineWraps[j + line_count] = LineWraps[j]; | |
9000 } | |
9001 LineOffset[j + line_count] = temp; | |
9002 LineWraps[j + line_count] = FALSE; | |
9003 if (can_clear((char_u *)" ")) | |
9004 lineclear(temp, (int)Columns); | |
9005 else | |
9006 lineinvalid(temp, (int)Columns); | |
9007 } | |
9008 } | |
9009 | |
9010 screen_stop_highlight(); | |
9011 windgoto(cursor_row, 0); | |
9012 | |
9013 #ifdef FEAT_VERTSPLIT | |
9014 /* redraw the characters */ | |
9015 if (type == USE_REDRAW) | |
9016 redraw_block(row, end, wp); | |
9017 else | |
9018 #endif | |
9019 if (type == USE_T_CAL) | |
9020 { | |
9021 term_append_lines(line_count); | |
9022 screen_start(); /* don't know where cursor is now */ | |
9023 } | |
9024 else | |
9025 { | |
9026 for (i = 0; i < line_count; i++) | |
9027 { | |
9028 if (type == USE_T_AL) | |
9029 { | |
9030 if (i && cursor_row != 0) | |
9031 windgoto(cursor_row, 0); | |
9032 out_str(T_AL); | |
9033 } | |
9034 else /* type == USE_T_SR */ | |
9035 out_str(T_SR); | |
9036 screen_start(); /* don't know where cursor is now */ | |
9037 } | |
9038 } | |
9039 | |
9040 /* | |
9041 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9042 * have been scrolled down into the region. | |
9043 */ | |
9044 if (type == USE_T_SR && *T_DA) | |
9045 { | |
9046 for (i = 0; i < line_count; ++i) | |
9047 { | |
9048 windgoto(off + i, 0); | |
9049 out_str(T_CE); | |
9050 screen_start(); /* don't know where cursor is now */ | |
9051 } | |
9052 } | |
9053 | |
9054 #ifdef FEAT_GUI | |
9055 gui_can_update_cursor(); | |
9056 if (gui.in_use) | |
9057 out_flush(); /* always flush after a scroll */ | |
9058 #endif | |
9059 return OK; | |
9060 } | |
9061 | |
9062 /* | |
9063 * delete lines on the screen and update ScreenLines[] | |
9064 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9065 * When scrolling region used 'off' is the offset from the top for the region. | |
9066 * 'row' and 'end' are relative to the start of the region. | |
9067 * | |
9068 * Return OK for success, FAIL if the lines are not deleted. | |
9069 */ | |
9070 int | |
9071 screen_del_lines(off, row, line_count, end, force, wp) | |
9072 int off; | |
9073 int row; | |
9074 int line_count; | |
9075 int end; | |
9076 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9077 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9078 { |
9079 int j; | |
9080 int i; | |
9081 unsigned temp; | |
9082 int cursor_row; | |
9083 int cursor_end; | |
9084 int result_empty; /* result is empty until end of region */ | |
9085 int can_delete; /* deleting line codes can be used */ | |
9086 int type; | |
9087 | |
9088 /* | |
9089 * FAIL if | |
9090 * - there is no valid screen | |
9091 * - the screen has to be redrawn completely | |
9092 * - the line count is less than one | |
9093 * - the line count is more than 'ttyscroll' | |
9094 */ | |
9095 if (!screen_valid(TRUE) || line_count <= 0 || | |
9096 (!force && line_count > p_ttyscroll)) | |
9097 return FAIL; | |
9098 | |
9099 /* | |
9100 * Check if the rest of the current region will become empty. | |
9101 */ | |
9102 result_empty = row + line_count >= end; | |
9103 | |
9104 /* | |
9105 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9106 * available. | |
9107 */ | |
9108 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9109 | |
9110 /* | |
9111 * There are six ways to delete lines: | |
9112 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9113 * characters from ScreenLines[]. | |
9114 * 1. Use T_CD if it exists and the result is empty. | |
9115 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9116 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9117 * none of the other ways work. | |
9118 * 4. Use T_CE (erase line) if the result is empty. | |
9119 * 5. Use T_DL (delete line) if it exists. | |
9120 * 6. redraw the characters from ScreenLines[]. | |
9121 */ | |
9122 #ifdef FEAT_VERTSPLIT | |
9123 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9124 type = USE_REDRAW; | |
9125 else | |
9126 #endif | |
9127 if (can_clear(T_CD) && result_empty) | |
9128 type = USE_T_CD; | |
9129 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9130 /* | |
9131 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9132 * its internal termcap... this works okay for tests which test *T_DB != | |
9133 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9134 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9135 * the trick... | |
9136 * Anyway, this hack will hopefully go away with the next OS release. | |
9137 * (Olaf Seibert) | |
9138 */ | |
9139 else if (row == 0 && T_DB == empty_option | |
9140 && (line_count == 1 || *T_CDL == NUL)) | |
9141 #else | |
9142 else if (row == 0 && ( | |
9143 #ifndef AMIGA | |
9144 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9145 * up, so use delete-line command */ | |
9146 line_count == 1 || | |
9147 #endif | |
9148 *T_CDL == NUL)) | |
9149 #endif | |
9150 type = USE_NL; | |
9151 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9152 type = USE_T_CDL; | |
9153 else if (can_clear(T_CE) && result_empty | |
9154 #ifdef FEAT_VERTSPLIT | |
9155 && (wp == NULL || wp->w_width == Columns) | |
9156 #endif | |
9157 ) | |
9158 type = USE_T_CE; | |
9159 else if (*T_DL != NUL && can_delete) | |
9160 type = USE_T_DL; | |
9161 else if (*T_CDL != NUL && can_delete) | |
9162 type = USE_T_CDL; | |
9163 else | |
9164 return FAIL; | |
9165 | |
9166 #ifdef FEAT_CLIPBOARD | |
9167 /* Remove a modeless selection when deleting lines halfway the screen or | |
9168 * not the full width of the screen. */ | |
9169 if (off + row > 0 | |
9170 # ifdef FEAT_VERTSPLIT | |
9171 || (wp != NULL && wp->w_width != Columns) | |
9172 # endif | |
9173 ) | |
9174 clip_clear_selection(); | |
9175 else | |
9176 clip_scroll_selection(line_count); | |
9177 #endif | |
9178 | |
9179 #ifdef FEAT_GUI | |
9180 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9181 * scrolling is actually carried out. */ | |
9182 gui_dont_update_cursor(); | |
9183 #endif | |
9184 | |
9185 if (*T_CCS != NUL) /* cursor relative to region */ | |
9186 { | |
9187 cursor_row = row; | |
9188 cursor_end = end; | |
9189 } | |
9190 else | |
9191 { | |
9192 cursor_row = row + off; | |
9193 cursor_end = end + off; | |
9194 } | |
9195 | |
9196 /* | |
9197 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9198 * Clear the inserted lines in ScreenLines[]. | |
9199 */ | |
9200 row += off; | |
9201 end += off; | |
9202 for (i = 0; i < line_count; ++i) | |
9203 { | |
9204 #ifdef FEAT_VERTSPLIT | |
9205 if (wp != NULL && wp->w_width != Columns) | |
9206 { | |
9207 /* need to copy part of a line */ | |
9208 j = row + i; | |
9209 while ((j += line_count) <= end - 1) | |
9210 linecopy(j - line_count, j, wp); | |
9211 j -= line_count; | |
9212 if (can_clear((char_u *)" ")) | |
9213 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9214 else | |
9215 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9216 LineWraps[j] = FALSE; | |
9217 } | |
9218 else | |
9219 #endif | |
9220 { | |
9221 /* whole width, moving the line pointers is faster */ | |
9222 j = row + i; | |
9223 temp = LineOffset[j]; | |
9224 while ((j += line_count) <= end - 1) | |
9225 { | |
9226 LineOffset[j - line_count] = LineOffset[j]; | |
9227 LineWraps[j - line_count] = LineWraps[j]; | |
9228 } | |
9229 LineOffset[j - line_count] = temp; | |
9230 LineWraps[j - line_count] = FALSE; | |
9231 if (can_clear((char_u *)" ")) | |
9232 lineclear(temp, (int)Columns); | |
9233 else | |
9234 lineinvalid(temp, (int)Columns); | |
9235 } | |
9236 } | |
9237 | |
9238 screen_stop_highlight(); | |
9239 | |
9240 #ifdef FEAT_VERTSPLIT | |
9241 /* redraw the characters */ | |
9242 if (type == USE_REDRAW) | |
9243 redraw_block(row, end, wp); | |
9244 else | |
9245 #endif | |
9246 if (type == USE_T_CD) /* delete the lines */ | |
9247 { | |
9248 windgoto(cursor_row, 0); | |
9249 out_str(T_CD); | |
9250 screen_start(); /* don't know where cursor is now */ | |
9251 } | |
9252 else if (type == USE_T_CDL) | |
9253 { | |
9254 windgoto(cursor_row, 0); | |
9255 term_delete_lines(line_count); | |
9256 screen_start(); /* don't know where cursor is now */ | |
9257 } | |
9258 /* | |
9259 * Deleting lines at top of the screen or scroll region: Just scroll | |
9260 * the whole screen (scroll region) up by outputting newlines on the | |
9261 * last line. | |
9262 */ | |
9263 else if (type == USE_NL) | |
9264 { | |
9265 windgoto(cursor_end - 1, 0); | |
9266 for (i = line_count; --i >= 0; ) | |
9267 out_char('\n'); /* cursor will remain on same line */ | |
9268 } | |
9269 else | |
9270 { | |
9271 for (i = line_count; --i >= 0; ) | |
9272 { | |
9273 if (type == USE_T_DL) | |
9274 { | |
9275 windgoto(cursor_row, 0); | |
9276 out_str(T_DL); /* delete a line */ | |
9277 } | |
9278 else /* type == USE_T_CE */ | |
9279 { | |
9280 windgoto(cursor_row + i, 0); | |
9281 out_str(T_CE); /* erase a line */ | |
9282 } | |
9283 screen_start(); /* don't know where cursor is now */ | |
9284 } | |
9285 } | |
9286 | |
9287 /* | |
9288 * If the 'db' flag is set, we need to clear the lines that have been | |
9289 * scrolled up at the bottom of the region. | |
9290 */ | |
9291 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9292 { | |
9293 for (i = line_count; i > 0; --i) | |
9294 { | |
9295 windgoto(cursor_end - i, 0); | |
9296 out_str(T_CE); /* erase a line */ | |
9297 screen_start(); /* don't know where cursor is now */ | |
9298 } | |
9299 } | |
9300 | |
9301 #ifdef FEAT_GUI | |
9302 gui_can_update_cursor(); | |
9303 if (gui.in_use) | |
9304 out_flush(); /* always flush after a scroll */ | |
9305 #endif | |
9306 | |
9307 return OK; | |
9308 } | |
9309 | |
9310 /* | |
9311 * show the current mode and ruler | |
9312 * | |
9313 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9314 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9315 * cleared only if a mode is shown. | |
9316 * Return the length of the message (0 if no message). | |
9317 */ | |
9318 int | |
9319 showmode() | |
9320 { | |
9321 int need_clear; | |
9322 int length = 0; | |
9323 int do_mode; | |
9324 int attr; | |
9325 int nwr_save; | |
9326 #ifdef FEAT_INS_EXPAND | |
9327 int sub_attr; | |
9328 #endif | |
9329 | |
642 | 9330 do_mode = ((p_smd && msg_silent == 0) |
9331 && ((State & INSERT) | |
9332 || restart_edit | |
7 | 9333 #ifdef FEAT_VISUAL |
9334 || VIsual_active | |
9335 #endif | |
9336 )); | |
9337 if (do_mode || Recording) | |
9338 { | |
9339 /* | |
9340 * Don't show mode right now, when not redrawing or inside a mapping. | |
9341 * Call char_avail() only when we are going to show something, because | |
9342 * it takes a bit of time. | |
9343 */ | |
9344 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9345 { | |
9346 redraw_cmdline = TRUE; /* show mode later */ | |
9347 return 0; | |
9348 } | |
9349 | |
9350 nwr_save = need_wait_return; | |
9351 | |
9352 /* wait a bit before overwriting an important message */ | |
9353 check_for_delay(FALSE); | |
9354 | |
9355 /* if the cmdline is more than one line high, erase top lines */ | |
9356 need_clear = clear_cmdline; | |
9357 if (clear_cmdline && cmdline_row < Rows - 1) | |
9358 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9359 | |
9360 /* Position on the last line in the window, column 0 */ | |
9361 msg_pos_mode(); | |
9362 cursor_off(); | |
9363 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9364 if (do_mode) | |
9365 { | |
9366 MSG_PUTS_ATTR("--", attr); | |
9367 #if defined(FEAT_XIM) | |
1668 | 9368 # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
7 | 9369 if (xic != NULL && im_get_status() && !p_imdisable |
9370 && curbuf->b_p_iminsert == B_IMODE_IM) | |
1668 | 9371 # else |
9372 if ( | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9373 # ifdef FEAT_GUI_GTK |
1668 | 9374 preedit_get_status() |
9375 # else | |
9376 im_get_status() | |
9377 # endif | |
9378 ) | |
9379 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9380 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9381 MSG_PUTS_ATTR(" IM", attr); |
9382 # else | |
9383 MSG_PUTS_ATTR(" XIM", attr); | |
9384 # endif | |
9385 #endif | |
9386 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9387 if (gui.in_use) | |
9388 { | |
9389 if (hangul_input_state_get()) | |
236 | 9390 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9391 } |
9392 #endif | |
9393 #ifdef FEAT_INS_EXPAND | |
9394 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9395 { | |
9396 /* These messages can get long, avoid a wrap in a narrow | |
9397 * window. Prefer showing edit_submode_extra. */ | |
9398 length = (Rows - msg_row) * Columns - 3; | |
9399 if (edit_submode_extra != NULL) | |
9400 length -= vim_strsize(edit_submode_extra); | |
9401 if (length > 0) | |
9402 { | |
9403 if (edit_submode_pre != NULL) | |
9404 length -= vim_strsize(edit_submode_pre); | |
9405 if (length - vim_strsize(edit_submode) > 0) | |
9406 { | |
9407 if (edit_submode_pre != NULL) | |
9408 msg_puts_attr(edit_submode_pre, attr); | |
9409 msg_puts_attr(edit_submode, attr); | |
9410 } | |
9411 if (edit_submode_extra != NULL) | |
9412 { | |
9413 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9414 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9415 sub_attr = hl_attr(edit_submode_highl); | |
9416 else | |
9417 sub_attr = attr; | |
9418 msg_puts_attr(edit_submode_extra, sub_attr); | |
9419 } | |
9420 } | |
9421 length = 0; | |
9422 } | |
9423 else | |
9424 #endif | |
9425 { | |
9426 #ifdef FEAT_VREPLACE | |
9427 if (State & VREPLACE_FLAG) | |
9428 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9429 else | |
9430 #endif | |
9431 if (State & REPLACE_FLAG) | |
9432 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9433 else if (State & INSERT) | |
9434 { | |
9435 #ifdef FEAT_RIGHTLEFT | |
9436 if (p_ri) | |
9437 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9438 #endif | |
9439 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9440 } | |
9441 else if (restart_edit == 'I') | |
9442 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9443 else if (restart_edit == 'R') | |
9444 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9445 else if (restart_edit == 'V') | |
9446 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9447 #ifdef FEAT_RIGHTLEFT | |
9448 if (p_hkmap) | |
9449 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9450 # ifdef FEAT_FKMAP | |
9451 if (p_fkmap) | |
9452 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9453 # endif | |
9454 #endif | |
9455 #ifdef FEAT_KEYMAP | |
9456 if (State & LANGMAP) | |
9457 { | |
9458 # ifdef FEAT_ARABIC | |
9459 if (curwin->w_p_arab) | |
9460 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9461 else | |
9462 # endif | |
9463 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9464 } | |
9465 #endif | |
9466 if ((State & INSERT) && p_paste) | |
9467 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9468 | |
9469 #ifdef FEAT_VISUAL | |
9470 if (VIsual_active) | |
9471 { | |
9472 char *p; | |
9473 | |
9474 /* Don't concatenate separate words to avoid translation | |
9475 * problems. */ | |
9476 switch ((VIsual_select ? 4 : 0) | |
9477 + (VIsual_mode == Ctrl_V) * 2 | |
9478 + (VIsual_mode == 'V')) | |
9479 { | |
9480 case 0: p = N_(" VISUAL"); break; | |
9481 case 1: p = N_(" VISUAL LINE"); break; | |
9482 case 2: p = N_(" VISUAL BLOCK"); break; | |
9483 case 4: p = N_(" SELECT"); break; | |
9484 case 5: p = N_(" SELECT LINE"); break; | |
9485 default: p = N_(" SELECT BLOCK"); break; | |
9486 } | |
9487 MSG_PUTS_ATTR(_(p), attr); | |
9488 } | |
9489 #endif | |
9490 MSG_PUTS_ATTR(" --", attr); | |
9491 } | |
644 | 9492 |
7 | 9493 need_clear = TRUE; |
9494 } | |
9495 if (Recording | |
9496 #ifdef FEAT_INS_EXPAND | |
9497 && edit_submode == NULL /* otherwise it gets too long */ | |
9498 #endif | |
9499 ) | |
9500 { | |
9501 MSG_PUTS_ATTR(_("recording"), attr); | |
9502 need_clear = TRUE; | |
9503 } | |
644 | 9504 |
9505 mode_displayed = TRUE; | |
7 | 9506 if (need_clear || clear_cmdline) |
9507 msg_clr_eos(); | |
9508 msg_didout = FALSE; /* overwrite this message */ | |
9509 length = msg_col; | |
9510 msg_col = 0; | |
9511 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9512 } | |
9513 else if (clear_cmdline && msg_silent == 0) | |
9514 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9515 msg_clr_cmdline(); | |
9516 | |
9517 #ifdef FEAT_CMDL_INFO | |
9518 # ifdef FEAT_VISUAL | |
9519 /* In Visual mode the size of the selected area must be redrawn. */ | |
9520 if (VIsual_active) | |
9521 clear_showcmd(); | |
9522 # endif | |
9523 | |
9524 /* If the last window has no status line, the ruler is after the mode | |
9525 * message and must be redrawn */ | |
9526 if (redrawing() | |
9527 # ifdef FEAT_WINDOWS | |
9528 && lastwin->w_status_height == 0 | |
9529 # endif | |
9530 ) | |
9531 win_redr_ruler(lastwin, TRUE); | |
9532 #endif | |
9533 redraw_cmdline = FALSE; | |
9534 clear_cmdline = FALSE; | |
9535 | |
9536 return length; | |
9537 } | |
9538 | |
9539 /* | |
9540 * Position for a mode message. | |
9541 */ | |
9542 static void | |
9543 msg_pos_mode() | |
9544 { | |
9545 msg_col = 0; | |
9546 msg_row = Rows - 1; | |
9547 } | |
9548 | |
9549 /* | |
9550 * Delete mode message. Used when ESC is typed which is expected to end | |
9551 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9552 * Caller should check "mode_displayed". |
7 | 9553 */ |
9554 void | |
9555 unshowmode(force) | |
9556 int force; | |
9557 { | |
9558 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9559 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9560 */ |
9561 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9562 redraw_cmdline = TRUE; /* delete mode later */ | |
9563 else | |
9564 { | |
9565 msg_pos_mode(); | |
9566 if (Recording) | |
9567 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9568 msg_clr_eos(); | |
9569 } | |
9570 } | |
9571 | |
667 | 9572 #if defined(FEAT_WINDOWS) |
9573 /* | |
9574 * Draw the tab pages line at the top of the Vim window. | |
9575 */ | |
9576 static void | |
677 | 9577 draw_tabline() |
667 | 9578 { |
9579 int tabcount = 0; | |
9580 tabpage_T *tp; | |
9581 int tabwidth; | |
9582 int col = 0; | |
673 | 9583 int scol = 0; |
667 | 9584 int attr; |
9585 win_T *wp; | |
671 | 9586 win_T *cwp; |
9587 int wincount; | |
9588 int modified; | |
667 | 9589 int c; |
9590 int len; | |
9591 int attr_sel = hl_attr(HLF_TPS); | |
9592 int attr_nosel = hl_attr(HLF_TP); | |
9593 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9594 char_u *p; |
677 | 9595 int room; |
9596 int use_sep_chars = (t_colors < 8 | |
9597 #ifdef FEAT_GUI | |
9598 && !gui.in_use | |
9599 #endif | |
9600 ); | |
673 | 9601 |
9602 redraw_tabline = FALSE; | |
667 | 9603 |
685 | 9604 #ifdef FEAT_GUI_TABLINE |
798 | 9605 /* Take care of a GUI tabline. */ |
685 | 9606 if (gui_use_tabline()) |
9607 { | |
9608 gui_update_tabline(); | |
9609 return; | |
9610 } | |
9611 #endif | |
9612 | |
9613 if (tabline_height() < 1) | |
667 | 9614 return; |
9615 | |
677 | 9616 #if defined(FEAT_STL_OPT) |
681 | 9617 |
9618 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9619 for (scol = 0; scol < Columns; ++scol) | |
9620 TabPageIdxs[scol] = 0; | |
9621 | |
677 | 9622 /* Use the 'tabline' option if it's set. */ |
9623 if (*p_tal != NUL) | |
9624 { | |
680 | 9625 int save_called_emsg = called_emsg; |
9626 | |
9627 /* Check for an error. If there is one we would loop in redrawing the | |
9628 * screen. Avoid that by making 'tabline' empty. */ | |
9629 called_emsg = FALSE; | |
677 | 9630 win_redr_custom(NULL, FALSE); |
680 | 9631 if (called_emsg) |
9632 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9633 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9634 called_emsg |= save_called_emsg; |
9635 } | |
9636 else | |
9637 #endif | |
9638 { | |
9639 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9640 ++tabcount; | |
9641 | |
9642 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9643 if (tabwidth < 6) | |
9644 tabwidth = 6; | |
9645 | |
9646 attr = attr_nosel; | |
9647 tabcount = 0; | |
681 | 9648 scol = 0; |
699 | 9649 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9650 tp = tp->tp_next) | |
680 | 9651 { |
9652 scol = col; | |
9653 | |
9654 if (tp->tp_topframe == topframe) | |
9655 attr = attr_sel; | |
9656 if (use_sep_chars && col > 0) | |
9657 screen_putchar('|', 0, col++, attr); | |
9658 | |
9659 if (tp->tp_topframe != topframe) | |
9660 attr = attr_nosel; | |
9661 | |
9662 screen_putchar(' ', 0, col++, attr); | |
9663 | |
9664 if (tp == curtab) | |
9665 { | |
9666 cwp = curwin; | |
9667 wp = firstwin; | |
9668 } | |
9669 else | |
9670 { | |
9671 cwp = tp->tp_curwin; | |
9672 wp = tp->tp_firstwin; | |
9673 } | |
9674 | |
9675 modified = FALSE; | |
9676 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9677 if (bufIsChanged(wp->w_buffer)) | |
9678 modified = TRUE; | |
9679 if (modified || wincount > 1) | |
9680 { | |
9681 if (wincount > 1) | |
9682 { | |
9683 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9684 len = (int)STRLEN(NameBuff); |
699 | 9685 if (col + len >= Columns - 3) |
9686 break; | |
680 | 9687 screen_puts_len(NameBuff, len, 0, col, |
677 | 9688 #if defined(FEAT_SYN_HL) |
680 | 9689 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9690 #else |
680 | 9691 attr |
9692 #endif | |
9693 ); | |
9694 col += len; | |
9695 } | |
9696 if (modified) | |
9697 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9698 screen_putchar(' ', 0, col++, attr); | |
9699 } | |
9700 | |
9701 room = scol - col + tabwidth - 1; | |
9702 if (room > 0) | |
9703 { | |
685 | 9704 /* Get buffer name in NameBuff[] */ |
9705 get_trans_bufname(cwp->w_buffer); | |
819 | 9706 shorten_dir(NameBuff); |
680 | 9707 len = vim_strsize(NameBuff); |
9708 p = NameBuff; | |
677 | 9709 #ifdef FEAT_MBYTE |
680 | 9710 if (has_mbyte) |
9711 while (len > room) | |
9712 { | |
9713 len -= ptr2cells(p); | |
9714 mb_ptr_adv(p); | |
9715 } | |
9716 else | |
9717 #endif | |
9718 if (len > room) | |
677 | 9719 { |
680 | 9720 p += len - room; |
9721 len = room; | |
677 | 9722 } |
699 | 9723 if (len > Columns - col - 1) |
9724 len = Columns - col - 1; | |
680 | 9725 |
835 | 9726 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9727 col += len; |
9728 } | |
9729 screen_putchar(' ', 0, col++, attr); | |
9730 | |
9731 /* Store the tab page number in TabPageIdxs[], so that | |
9732 * jump_to_mouse() knows where each one is. */ | |
9733 ++tabcount; | |
9734 while (scol < col) | |
9735 TabPageIdxs[scol++] = tabcount; | |
9736 } | |
9737 | |
9738 if (use_sep_chars) | |
9739 c = '_'; | |
9740 else | |
9741 c = ' '; | |
9742 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9743 |
9744 /* Put an "X" for closing the current tab if there are several. */ | |
9745 if (first_tabpage->tp_next != NULL) | |
9746 { | |
9747 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9748 TabPageIdxs[Columns - 1] = -999; | |
9749 } | |
9750 } | |
834 | 9751 |
9752 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9753 * set. */ | |
9754 redraw_tabline = FALSE; | |
667 | 9755 } |
685 | 9756 |
9757 /* | |
9758 * Get buffer name for "buf" into NameBuff[]. | |
9759 * Takes care of special buffer names and translates special characters. | |
9760 */ | |
9761 void | |
9762 get_trans_bufname(buf) | |
9763 buf_T *buf; | |
9764 { | |
9765 if (buf_spname(buf) != NULL) | |
9766 STRCPY(NameBuff, buf_spname(buf)); | |
9767 else | |
9768 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9769 trans_characters(NameBuff, MAXPATHL); | |
9770 } | |
667 | 9771 #endif |
9772 | |
7 | 9773 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9774 /* | |
9775 * Get the character to use in a status line. Get its attributes in "*attr". | |
9776 */ | |
9777 static int | |
9778 fillchar_status(attr, is_curwin) | |
9779 int *attr; | |
9780 int is_curwin; | |
9781 { | |
9782 int fill; | |
9783 if (is_curwin) | |
9784 { | |
9785 *attr = hl_attr(HLF_S); | |
9786 fill = fill_stl; | |
9787 } | |
9788 else | |
9789 { | |
9790 *attr = hl_attr(HLF_SNC); | |
9791 fill = fill_stlnc; | |
9792 } | |
9793 /* Use fill when there is highlighting, and highlighting of current | |
9794 * window differs, or the fillchars differ, or this is not the | |
9795 * current window */ | |
9796 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9797 || !is_curwin || firstwin == lastwin) | |
9798 || (fill_stl != fill_stlnc))) | |
9799 return fill; | |
9800 if (is_curwin) | |
9801 return '^'; | |
9802 return '='; | |
9803 } | |
9804 #endif | |
9805 | |
9806 #ifdef FEAT_VERTSPLIT | |
9807 /* | |
9808 * Get the character to use in a separator between vertically split windows. | |
9809 * Get its attributes in "*attr". | |
9810 */ | |
9811 static int | |
9812 fillchar_vsep(attr) | |
9813 int *attr; | |
9814 { | |
9815 *attr = hl_attr(HLF_C); | |
9816 if (*attr == 0 && fill_vert == ' ') | |
9817 return '|'; | |
9818 else | |
9819 return fill_vert; | |
9820 } | |
9821 #endif | |
9822 | |
9823 /* | |
9824 * Return TRUE if redrawing should currently be done. | |
9825 */ | |
9826 int | |
9827 redrawing() | |
9828 { | |
9829 return (!RedrawingDisabled | |
9830 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9831 } | |
9832 | |
9833 /* | |
9834 * Return TRUE if printing messages should currently be done. | |
9835 */ | |
9836 int | |
9837 messaging() | |
9838 { | |
9839 return (!(p_lz && char_avail() && !KeyTyped)); | |
9840 } | |
9841 | |
9842 /* | |
9843 * Show current status info in ruler and various other places | |
9844 * If always is FALSE, only show ruler if position has changed. | |
9845 */ | |
9846 void | |
9847 showruler(always) | |
9848 int always; | |
9849 { | |
9850 if (!always && !redrawing()) | |
9851 return; | |
574 | 9852 #ifdef FEAT_INS_EXPAND |
9853 if (pum_visible()) | |
9854 { | |
639 | 9855 # ifdef FEAT_WINDOWS |
574 | 9856 /* Don't redraw right now, do it later. */ |
9857 curwin->w_redr_status = TRUE; | |
639 | 9858 # endif |
574 | 9859 return; |
9860 } | |
9861 #endif | |
7 | 9862 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9863 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9864 { |
1983 | 9865 redraw_custom_statusline(curwin); |
680 | 9866 } |
7 | 9867 else |
9868 #endif | |
9869 #ifdef FEAT_CMDL_INFO | |
9870 win_redr_ruler(curwin, always); | |
9871 #endif | |
9872 | |
9873 #ifdef FEAT_TITLE | |
9874 if (need_maketitle | |
9875 # ifdef FEAT_STL_OPT | |
9876 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9877 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9878 # endif | |
9879 ) | |
9880 maketitle(); | |
9881 #endif | |
1588 | 9882 #ifdef FEAT_WINDOWS |
9883 /* Redraw the tab pages line if needed. */ | |
9884 if (redraw_tabline) | |
9885 draw_tabline(); | |
9886 #endif | |
7 | 9887 } |
9888 | |
9889 #ifdef FEAT_CMDL_INFO | |
9890 static void | |
9891 win_redr_ruler(wp, always) | |
9892 win_T *wp; | |
9893 int always; | |
9894 { | |
1869 | 9895 #define RULER_BUF_LEN 70 |
9896 char_u buffer[RULER_BUF_LEN]; | |
7 | 9897 int row; |
9898 int fillchar; | |
9899 int attr; | |
9900 int empty_line = FALSE; | |
9901 colnr_T virtcol; | |
9902 int i; | |
1869 | 9903 size_t len; |
7 | 9904 int o; |
9905 #ifdef FEAT_VERTSPLIT | |
9906 int this_ru_col; | |
9907 int off = 0; | |
9908 int width = Columns; | |
9909 # define WITH_OFF(x) x | |
9910 # define WITH_WIDTH(x) x | |
9911 #else | |
9912 # define WITH_OFF(x) 0 | |
9913 # define WITH_WIDTH(x) Columns | |
9914 # define this_ru_col ru_col | |
9915 #endif | |
9916 | |
9917 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9918 if (!p_ru) | |
9919 return; | |
9920 | |
9921 /* | |
9922 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
9923 * after deleting lines, before cursor.lnum is corrected. | |
9924 */ | |
9925 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
9926 return; | |
9927 | |
9928 #ifdef FEAT_INS_EXPAND | |
9929 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
9930 * the (long) mode message. */ | |
9931 # ifdef FEAT_WINDOWS | |
9932 if (wp == lastwin && lastwin->w_status_height == 0) | |
9933 # endif | |
9934 if (edit_submode != NULL) | |
9935 return; | |
540 | 9936 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
9937 if (pum_visible()) | |
9938 return; | |
7 | 9939 #endif |
9940 | |
9941 #ifdef FEAT_STL_OPT | |
9942 if (*p_ruf) | |
9943 { | |
680 | 9944 int save_called_emsg = called_emsg; |
9945 | |
9946 called_emsg = FALSE; | |
7 | 9947 win_redr_custom(wp, TRUE); |
680 | 9948 if (called_emsg) |
9949 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 9950 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9951 called_emsg |= save_called_emsg; |
7 | 9952 return; |
9953 } | |
9954 #endif | |
9955 | |
9956 /* | |
9957 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
9958 */ | |
9959 if (!(State & INSERT) | |
9960 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
9961 empty_line = TRUE; | |
9962 | |
9963 /* | |
9964 * Only draw the ruler when something changed. | |
9965 */ | |
9966 validate_virtcol_win(wp); | |
9967 if ( redraw_cmdline | |
9968 || always | |
9969 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
9970 || wp->w_cursor.col != wp->w_ru_cursor.col | |
9971 || wp->w_virtcol != wp->w_ru_virtcol | |
9972 #ifdef FEAT_VIRTUALEDIT | |
9973 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
9974 #endif | |
9975 || wp->w_topline != wp->w_ru_topline | |
9976 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
9977 #ifdef FEAT_DIFF | |
9978 || wp->w_topfill != wp->w_ru_topfill | |
9979 #endif | |
9980 || empty_line != wp->w_ru_empty) | |
9981 { | |
9982 cursor_off(); | |
9983 #ifdef FEAT_WINDOWS | |
9984 if (wp->w_status_height) | |
9985 { | |
9986 row = W_WINROW(wp) + wp->w_height; | |
9987 fillchar = fillchar_status(&attr, wp == curwin); | |
9988 # ifdef FEAT_VERTSPLIT | |
9989 off = W_WINCOL(wp); | |
9990 width = W_WIDTH(wp); | |
9991 # endif | |
9992 } | |
9993 else | |
9994 #endif | |
9995 { | |
9996 row = Rows - 1; | |
9997 fillchar = ' '; | |
9998 attr = 0; | |
9999 #ifdef FEAT_VERTSPLIT | |
10000 width = Columns; | |
10001 off = 0; | |
10002 #endif | |
10003 } | |
10004 | |
10005 /* In list mode virtcol needs to be recomputed */ | |
10006 virtcol = wp->w_virtcol; | |
10007 if (wp->w_p_list && lcs_tab1 == NUL) | |
10008 { | |
10009 wp->w_p_list = FALSE; | |
10010 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10011 wp->w_p_list = TRUE; | |
10012 } | |
10013 | |
10014 /* | |
10015 * Some sprintfs return the length, some return a pointer. | |
10016 * To avoid portability problems we use strlen() here. | |
10017 */ | |
1869 | 10018 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10019 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10020 ? 0L | |
10021 : (long)(wp->w_cursor.lnum)); | |
1869 | 10022 len = STRLEN(buffer); |
10023 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10024 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10025 (int)virtcol + 1); | |
10026 | |
10027 /* | |
10028 * Add a "50%" if there is room for it. | |
10029 * On the last line, don't print in the last column (scrolls the | |
10030 * screen up on some terminals). | |
10031 */ | |
10032 i = (int)STRLEN(buffer); | |
1869 | 10033 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10034 o = i + vim_strsize(buffer + i + 1); |
10035 #ifdef FEAT_WINDOWS | |
10036 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10037 #endif | |
10038 ++o; | |
10039 #ifdef FEAT_VERTSPLIT | |
10040 this_ru_col = ru_col - (Columns - width); | |
10041 if (this_ru_col < 0) | |
10042 this_ru_col = 0; | |
10043 #endif | |
10044 /* Never use more than half the window/screen width, leave the other | |
10045 * half for the filename. */ | |
10046 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10047 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10048 if (this_ru_col + o < WITH_WIDTH(width)) | |
10049 { | |
10050 while (this_ru_col + o < WITH_WIDTH(width)) | |
10051 { | |
10052 #ifdef FEAT_MBYTE | |
10053 if (has_mbyte) | |
10054 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10055 else | |
10056 #endif | |
10057 buffer[i++] = fillchar; | |
10058 ++o; | |
10059 } | |
1869 | 10060 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10061 } |
10062 /* Truncate at window boundary. */ | |
10063 #ifdef FEAT_MBYTE | |
10064 if (has_mbyte) | |
10065 { | |
10066 o = 0; | |
474 | 10067 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10068 { |
10069 o += (*mb_ptr2cells)(buffer + i); | |
10070 if (this_ru_col + o > WITH_WIDTH(width)) | |
10071 { | |
10072 buffer[i] = NUL; | |
10073 break; | |
10074 } | |
10075 } | |
10076 } | |
10077 else | |
10078 #endif | |
10079 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10080 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10081 | |
10082 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10083 i = redraw_cmdline; | |
10084 screen_fill(row, row + 1, | |
10085 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10086 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10087 fillchar, fillchar, attr); | |
10088 /* don't redraw the cmdline because of showing the ruler */ | |
10089 redraw_cmdline = i; | |
10090 wp->w_ru_cursor = wp->w_cursor; | |
10091 wp->w_ru_virtcol = wp->w_virtcol; | |
10092 wp->w_ru_empty = empty_line; | |
10093 wp->w_ru_topline = wp->w_topline; | |
10094 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10095 #ifdef FEAT_DIFF | |
10096 wp->w_ru_topfill = wp->w_topfill; | |
10097 #endif | |
10098 } | |
10099 } | |
10100 #endif | |
13 | 10101 |
10102 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10103 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10104 * 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
|
10105 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10106 * Otherwise it depends on 'numberwidth' and the line count. |
10107 */ | |
10108 int | |
10109 number_width(wp) | |
10110 win_T *wp; | |
10111 { | |
10112 int n; | |
10113 linenr_T lnum; | |
10114 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10115 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10116 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10117 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
|
10118 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10119 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10120 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10121 |
13 | 10122 if (lnum == wp->w_nrwidth_line_count) |
10123 return wp->w_nrwidth_width; | |
10124 wp->w_nrwidth_line_count = lnum; | |
10125 | |
10126 n = 0; | |
10127 do | |
10128 { | |
856 | 10129 lnum /= 10; |
10130 ++n; | |
13 | 10131 } while (lnum > 0); |
10132 | |
10133 /* 'numberwidth' gives the minimal width plus one */ | |
10134 if (n < wp->w_p_nuw - 1) | |
10135 n = wp->w_p_nuw - 1; | |
10136 | |
10137 wp->w_nrwidth_width = n; | |
10138 return n; | |
10139 } | |
10140 #endif |