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