Mercurial > vim
annotate src/screen.c @ 2378:85b7dc8da5eb vim73
Add the 'concealcursor' option to decide when the cursor line is to be
concealed or not.
Rename 'conc' to 'cole' as the short name for 'conceallevel'.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 23 Jul 2010 22:10:27 +0200 |
parents | a96dd77ce213 |
children | b47748aa3236 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * screen.c: code for displaying on the screen | |
12 * | |
13 * Output to the screen (console, terminal emulator or GUI window) is minimized | |
14 * by remembering what is already on the screen, and only updating the parts | |
15 * that changed. | |
16 * | |
17 * ScreenLines[off] Contains a copy of the whole screen, as it is currently | |
18 * displayed (excluding text written by external commands). | |
19 * ScreenAttrs[off] Contains the associated attributes. | |
20 * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] | |
21 * for each line. | |
22 * LineWraps[row] Flag for each line whether it wraps to the next line. | |
23 * | |
24 * For double-byte characters, two consecutive bytes in ScreenLines[] can form | |
25 * one character which occupies two display cells. | |
26 * For UTF-8 a multi-byte character is converted to Unicode and stored in | |
27 * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
28 * character without composing chars ScreenLinesUC[] will be 0 and |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
29 * ScreenLinesC[][] is not used. When the character occupies two display |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
30 * cells the next byte in ScreenLines[] is 0. |
714 | 31 * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
32 * (drawn on top of the first character). There is 0 after the last one used. |
7 | 33 * ScreenLines2[] is only used for euc-jp to store the second byte if the |
34 * first byte is 0x8e (single-width character). | |
35 * | |
36 * The screen_*() functions write to the screen and handle updating | |
37 * ScreenLines[]. | |
38 * | |
39 * update_screen() is the function that updates all windows and status lines. | |
40 * It is called form the main loop when must_redraw is non-zero. It may be | |
1213 | 41 * called from other places when an immediate screen update is needed. |
7 | 42 * |
43 * The part of the buffer that is displayed in a window is set with: | |
44 * - w_topline (first buffer line in window) | |
45 * - w_topfill (filler line above the first line) | |
46 * - w_leftcol (leftmost window cell in window), | |
47 * - w_skipcol (skipped window cells of first line) | |
48 * | |
49 * Commands that only move the cursor around in a window, do not need to take | |
50 * action to update the display. The main loop will check if w_topline is | |
51 * valid and update it (scroll the window) when needed. | |
52 * | |
53 * Commands that scroll a window change w_topline and must call | |
54 * check_cursor() to move the cursor into the visible part of the window, and | |
55 * call redraw_later(VALID) to have the window displayed by update_screen() | |
56 * later. | |
57 * | |
58 * Commands that change text in the buffer must call changed_bytes() or | |
59 * changed_lines() to mark the area that changed and will require updating | |
60 * later. The main loop will call update_screen(), which will update each | |
61 * window that shows the changed buffer. This assumes text above the change | |
62 * can remain displayed as it is. Text after the change may need updating for | |
63 * scrolling, folding and syntax highlighting. | |
64 * | |
65 * Commands that change how a window is displayed (e.g., setting 'list') or | |
66 * invalidate the contents of a window in another way (e.g., change fold | |
67 * settings), must call redraw_later(NOT_VALID) to have the whole window | |
68 * redisplayed by update_screen() later. | |
69 * | |
70 * Commands that change how a buffer is displayed (e.g., setting 'tabstop') | |
71 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the | |
72 * buffer redisplayed by update_screen() later. | |
73 * | |
743 | 74 * Commands that change highlighting and possibly cause a scroll too must call |
75 * redraw_later(SOME_VALID) to update the whole window but still use scrolling | |
76 * to avoid redrawing everything. But the length of displayed lines must not | |
77 * change, use NOT_VALID then. | |
78 * | |
7 | 79 * Commands that move the window position must call redraw_later(NOT_VALID). |
80 * TODO: should minimize redrawing by scrolling when possible. | |
81 * | |
82 * Commands that change everything (e.g., resizing the screen) must call | |
83 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). | |
84 * | |
85 * Things that are handled indirectly: | |
86 * - When messages scroll the screen up, msg_scrolled will be set and | |
87 * update_screen() called to redraw. | |
88 */ | |
89 | |
90 #include "vim.h" | |
91 | |
92 /* | |
93 * The attributes that are actually active for writing to the screen. | |
94 */ | |
95 static int screen_attr = 0; | |
96 | |
97 /* | |
98 * Positioning the cursor is reduced by remembering the last position. | |
99 * Mostly used by windgoto() and screen_char(). | |
100 */ | |
101 static int screen_cur_row, screen_cur_col; /* last known cursor position */ | |
102 | |
103 #ifdef FEAT_SEARCH_EXTRA | |
104 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
105 #endif | |
106 | |
107 #ifdef FEAT_FOLDING | |
108 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
109 #endif | |
110 | |
111 /* | |
112 * Buffer for one screen line (characters and attributes). | |
113 */ | |
114 static schar_T *current_ScreenLine; | |
115 | |
116 static void win_update __ARGS((win_T *wp)); | |
534 | 117 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 118 #ifdef FEAT_FOLDING |
119 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
120 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
121 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
122 #endif | |
625 | 123 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 124 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
125 #ifdef FEAT_RIGHTLEFT | |
126 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
127 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
128 #else | |
129 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
131 #endif | |
132 #ifdef FEAT_VERTSPLIT | |
133 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
134 #endif | |
680 | 135 #ifdef FEAT_STL_OPT |
1983 | 136 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 137 #endif |
7 | 138 #ifdef FEAT_SEARCH_EXTRA |
1326 | 139 #define SEARCH_HL_PRIORITY 0 |
7 | 140 static void start_search_hl __ARGS((void)); |
141 static void end_search_hl __ARGS((void)); | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
142 static void init_search_hl __ARGS((win_T *wp)); |
7 | 143 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
144 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
145 #endif | |
146 static void screen_start_highlight __ARGS((int attr)); | |
147 static void screen_char __ARGS((unsigned off, int row, int col)); | |
148 #ifdef FEAT_MBYTE | |
149 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
150 #endif | |
151 static void screenclear2 __ARGS((void)); | |
152 static void lineclear __ARGS((unsigned off, int width)); | |
153 static void lineinvalid __ARGS((unsigned off, int width)); | |
154 #ifdef FEAT_VERTSPLIT | |
155 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
156 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
157 #endif | |
158 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
159 static void win_rest_invalid __ARGS((win_T *wp)); | |
160 static void msg_pos_mode __ARGS((void)); | |
667 | 161 #if defined(FEAT_WINDOWS) |
677 | 162 static void draw_tabline __ARGS((void)); |
667 | 163 #endif |
7 | 164 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
165 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
166 #endif | |
167 #ifdef FEAT_VERTSPLIT | |
168 static int fillchar_vsep __ARGS((int *attr)); | |
169 #endif | |
170 #ifdef FEAT_STL_OPT | |
574 | 171 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 172 #endif |
173 #ifdef FEAT_CMDL_INFO | |
174 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
175 #endif | |
176 | |
177 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
178 /* Ugly global: overrule attribute used by screen_char() */ | |
179 static int screen_char_attr = 0; | |
180 #endif | |
181 | |
182 /* | |
183 * Redraw the current window later, with update_screen(type). | |
184 * Set must_redraw only if not already set to a higher value. | |
185 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
186 */ | |
187 void | |
188 redraw_later(type) | |
189 int type; | |
190 { | |
191 redraw_win_later(curwin, type); | |
192 } | |
193 | |
194 void | |
195 redraw_win_later(wp, type) | |
196 win_T *wp; | |
197 int type; | |
198 { | |
199 if (wp->w_redr_type < type) | |
200 { | |
201 wp->w_redr_type = type; | |
202 if (type >= NOT_VALID) | |
203 wp->w_lines_valid = 0; | |
204 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
205 must_redraw = type; | |
206 } | |
207 } | |
208 | |
209 /* | |
210 * Force a complete redraw later. Also resets the highlighting. To be used | |
211 * after executing a shell command that messes up the screen. | |
212 */ | |
213 void | |
214 redraw_later_clear() | |
215 { | |
216 redraw_all_later(CLEAR); | |
826 | 217 #ifdef FEAT_GUI |
218 if (gui.in_use) | |
219 /* Use a code that will reset gui.highlight_mask in | |
220 * gui_stop_highlight(). */ | |
221 screen_attr = HL_ALL + 1; | |
222 else | |
223 #endif | |
224 /* Use attributes that is very unlikely to appear in text. */ | |
225 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 226 } |
227 | |
228 /* | |
229 * Mark all windows to be redrawn later. | |
230 */ | |
231 void | |
232 redraw_all_later(type) | |
233 int type; | |
234 { | |
235 win_T *wp; | |
236 | |
237 FOR_ALL_WINDOWS(wp) | |
238 { | |
239 redraw_win_later(wp, type); | |
240 } | |
241 } | |
242 | |
243 /* | |
301 | 244 * Mark all windows that are editing the current buffer to be updated later. |
7 | 245 */ |
246 void | |
247 redraw_curbuf_later(type) | |
248 int type; | |
249 { | |
250 redraw_buf_later(curbuf, type); | |
251 } | |
252 | |
253 void | |
254 redraw_buf_later(buf, type) | |
255 buf_T *buf; | |
256 int type; | |
257 { | |
258 win_T *wp; | |
259 | |
260 FOR_ALL_WINDOWS(wp) | |
261 { | |
262 if (wp->w_buffer == buf) | |
263 redraw_win_later(wp, type); | |
264 } | |
265 } | |
266 | |
267 /* | |
268 * Changed something in the current window, at buffer line "lnum", that | |
269 * requires that line and possibly other lines to be redrawn. | |
270 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
271 * Used to remove the "$" from a change command. | |
272 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
273 * may become invalid and the whole window will have to be redrawn. | |
274 */ | |
275 void | |
276 redrawWinline(lnum, invalid) | |
277 linenr_T lnum; | |
1883 | 278 int invalid UNUSED; /* window line height is invalid now */ |
7 | 279 { |
280 #ifdef FEAT_FOLDING | |
281 int i; | |
282 #endif | |
283 | |
284 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
285 curwin->w_redraw_top = lnum; | |
286 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
287 curwin->w_redraw_bot = lnum; | |
288 redraw_later(VALID); | |
289 | |
290 #ifdef FEAT_FOLDING | |
291 if (invalid) | |
292 { | |
293 /* A w_lines[] entry for this lnum has become invalid. */ | |
294 i = find_wl_entry(curwin, lnum); | |
295 if (i >= 0) | |
296 curwin->w_lines[i].wl_valid = FALSE; | |
297 } | |
298 #endif | |
299 } | |
300 | |
2255 | 301 #if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \ |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
302 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 303 /* |
304 * update all windows that are editing the current buffer | |
305 */ | |
306 void | |
307 update_curbuf(type) | |
308 int type; | |
309 { | |
310 redraw_curbuf_later(type); | |
311 update_screen(type); | |
312 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
313 #endif |
7 | 314 |
315 /* | |
316 * update_screen() | |
317 * | |
318 * Based on the current value of curwin->w_topline, transfer a screenfull | |
319 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
320 */ | |
321 void | |
322 update_screen(type) | |
323 int type; | |
324 { | |
325 win_T *wp; | |
326 static int did_intro = FALSE; | |
327 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
328 int did_one; | |
329 #endif | |
330 | |
2008 | 331 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 332 if (!screen_valid(TRUE)) |
333 return; | |
334 | |
335 if (must_redraw) | |
336 { | |
337 if (type < must_redraw) /* use maximal type */ | |
338 type = must_redraw; | |
1331 | 339 |
340 /* must_redraw is reset here, so that when we run into some weird | |
341 * reason to redraw while busy redrawing (e.g., asynchronous | |
342 * scrolling), or update_topline() in win_update() will cause a | |
343 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 344 must_redraw = 0; |
345 } | |
346 | |
347 /* Need to update w_lines[]. */ | |
348 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
349 type = NOT_VALID; | |
350 | |
2008 | 351 /* Postpone the redrawing when it's not needed and when being called |
352 * recursively. */ | |
353 if (!redrawing() || updating_screen) | |
7 | 354 { |
355 redraw_later(type); /* remember type for next time */ | |
356 must_redraw = type; | |
357 if (type > INVERTED_ALL) | |
358 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
359 return; | |
360 } | |
361 | |
362 updating_screen = TRUE; | |
363 #ifdef FEAT_SYN_HL | |
364 ++display_tick; /* let syntax code know we're in a next round of | |
365 * display updating */ | |
366 #endif | |
367 | |
368 /* | |
369 * if the screen was scrolled up when displaying a message, scroll it down | |
370 */ | |
371 if (msg_scrolled) | |
372 { | |
373 clear_cmdline = TRUE; | |
374 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
375 type = CLEAR; | |
376 else if (type != CLEAR) | |
377 { | |
378 check_for_delay(FALSE); | |
379 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
380 type = CLEAR; | |
381 FOR_ALL_WINDOWS(wp) | |
382 { | |
383 if (W_WINROW(wp) < msg_scrolled) | |
384 { | |
385 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
386 && wp->w_redr_type < REDRAW_TOP | |
387 && wp->w_lines_valid > 0 | |
388 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
389 { | |
390 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
391 wp->w_redr_type = REDRAW_TOP; | |
392 } | |
393 else | |
394 { | |
395 wp->w_redr_type = NOT_VALID; | |
396 #ifdef FEAT_WINDOWS | |
397 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
398 <= msg_scrolled) | |
399 wp->w_redr_status = TRUE; | |
400 #endif | |
401 } | |
402 } | |
403 } | |
404 redraw_cmdline = TRUE; | |
667 | 405 #ifdef FEAT_WINDOWS |
673 | 406 redraw_tabline = TRUE; |
667 | 407 #endif |
7 | 408 } |
409 msg_scrolled = 0; | |
410 need_wait_return = FALSE; | |
411 } | |
412 | |
413 /* reset cmdline_row now (may have been changed temporarily) */ | |
414 compute_cmdrow(); | |
415 | |
416 /* Check for changed highlighting */ | |
417 if (need_highlight_changed) | |
418 highlight_changed(); | |
419 | |
420 if (type == CLEAR) /* first clear screen */ | |
421 { | |
422 screenclear(); /* will reset clear_cmdline */ | |
423 type = NOT_VALID; | |
424 } | |
425 | |
426 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
427 check_for_delay(FALSE); | |
428 | |
13 | 429 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
430 /* Force redraw when width of 'number' or 'relativenumber' column |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
431 * changes. */ |
13 | 432 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
433 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
434 ? number_width(curwin) : 0)) |
13 | 435 curwin->w_redr_type = NOT_VALID; |
436 #endif | |
437 | |
7 | 438 /* |
439 * Only start redrawing if there is really something to do. | |
440 */ | |
441 if (type == INVERTED) | |
442 update_curswant(); | |
443 if (curwin->w_redr_type < type | |
444 && !((type == VALID | |
445 && curwin->w_lines[0].wl_valid | |
446 #ifdef FEAT_DIFF | |
447 && curwin->w_topfill == curwin->w_old_topfill | |
448 && curwin->w_botfill == curwin->w_old_botfill | |
449 #endif | |
450 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
451 #ifdef FEAT_VISUAL | |
452 || (type == INVERTED | |
1043 | 453 && VIsual_active |
7 | 454 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
455 && curwin->w_old_visual_mode == VIsual_mode | |
456 && (curwin->w_valid & VALID_VIRTCOL) | |
457 && curwin->w_old_curswant == curwin->w_curswant) | |
458 #endif | |
459 )) | |
460 curwin->w_redr_type = type; | |
461 | |
849 | 462 #ifdef FEAT_WINDOWS |
463 /* Redraw the tab pages line if needed. */ | |
464 if (redraw_tabline || type >= NOT_VALID) | |
465 draw_tabline(); | |
466 #endif | |
467 | |
7 | 468 #ifdef FEAT_SYN_HL |
469 /* | |
470 * Correct stored syntax highlighting info for changes in each displayed | |
471 * buffer. Each buffer must only be done once. | |
472 */ | |
473 FOR_ALL_WINDOWS(wp) | |
474 { | |
475 if (wp->w_buffer->b_mod_set) | |
476 { | |
477 # ifdef FEAT_WINDOWS | |
478 win_T *wwp; | |
479 | |
480 /* Check if we already did this buffer. */ | |
481 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
482 if (wwp->w_buffer == wp->w_buffer) | |
483 break; | |
484 # endif | |
485 if ( | |
486 # ifdef FEAT_WINDOWS | |
487 wwp == wp && | |
488 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
489 syntax_present(wp)) |
7 | 490 syn_stack_apply_changes(wp->w_buffer); |
491 } | |
492 } | |
493 #endif | |
494 | |
495 /* | |
496 * Go from top to bottom through the windows, redrawing the ones that need | |
497 * it. | |
498 */ | |
499 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
500 did_one = FALSE; | |
501 #endif | |
502 #ifdef FEAT_SEARCH_EXTRA | |
503 search_hl.rm.regprog = NULL; | |
504 #endif | |
505 FOR_ALL_WINDOWS(wp) | |
506 { | |
507 if (wp->w_redr_type != 0) | |
508 { | |
509 cursor_off(); | |
510 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
511 if (!did_one) | |
512 { | |
513 did_one = TRUE; | |
514 # ifdef FEAT_SEARCH_EXTRA | |
515 start_search_hl(); | |
516 # endif | |
517 # ifdef FEAT_CLIPBOARD | |
518 /* When Visual area changed, may have to update selection. */ | |
519 if (clip_star.available && clip_isautosel()) | |
520 clip_update_selection(); | |
521 # endif | |
522 #ifdef FEAT_GUI | |
523 /* Remove the cursor before starting to do anything, because | |
524 * scrolling may make it difficult to redraw the text under | |
525 * it. */ | |
526 if (gui.in_use) | |
527 gui_undraw_cursor(); | |
528 #endif | |
529 } | |
530 #endif | |
531 win_update(wp); | |
532 } | |
533 | |
534 #ifdef FEAT_WINDOWS | |
535 /* redraw status line after the window to minimize cursor movement */ | |
536 if (wp->w_redr_status) | |
537 { | |
538 cursor_off(); | |
539 win_redr_status(wp); | |
540 } | |
541 #endif | |
542 } | |
543 #if defined(FEAT_SEARCH_EXTRA) | |
544 end_search_hl(); | |
545 #endif | |
546 | |
547 #ifdef FEAT_WINDOWS | |
548 /* Reset b_mod_set flags. Going through all windows is probably faster | |
549 * than going through all buffers (there could be many buffers). */ | |
550 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
551 wp->w_buffer->b_mod_set = FALSE; | |
552 #else | |
553 curbuf->b_mod_set = FALSE; | |
554 #endif | |
555 | |
556 updating_screen = FALSE; | |
557 #ifdef FEAT_GUI | |
558 gui_may_resize_shell(); | |
559 #endif | |
560 | |
561 /* Clear or redraw the command line. Done last, because scrolling may | |
562 * mess up the command line. */ | |
563 if (clear_cmdline || redraw_cmdline) | |
564 showmode(); | |
565 | |
566 /* May put up an introductory message when not editing a file */ | |
567 if (!did_intro && bufempty() | |
568 && curbuf->b_fname == NULL | |
569 #ifdef FEAT_WINDOWS | |
570 && firstwin->w_next == NULL | |
571 #endif | |
572 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
573 intro_message(FALSE); | |
574 did_intro = TRUE; | |
575 | |
576 #ifdef FEAT_GUI | |
577 /* Redraw the cursor and update the scrollbars when all screen updating is | |
578 * done. */ | |
579 if (gui.in_use) | |
580 { | |
581 out_flush(); /* required before updating the cursor */ | |
582 if (did_one) | |
583 gui_update_cursor(FALSE, FALSE); | |
584 gui_update_scrollbars(FALSE); | |
585 } | |
586 #endif | |
587 } | |
588 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
589 #if defined(FEAT_CONCEAL) || defined(PROTO) |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
590 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
591 * Return TRUE if the cursor line in window "wp" may be concealed, according |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
592 * to the 'concealcursor' option. |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
593 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
594 int |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
595 conceal_cursor_line(wp) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
596 win_T *wp; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
597 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
598 int c; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
599 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
600 if (*wp->w_p_cocu == NUL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
601 return FALSE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
602 if (get_real_state() & VISUAL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
603 c = 'v'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
604 else if (State & INSERT) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
605 c = 'i'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
606 else if (State & NORMAL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
607 c = 'n'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
608 else |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
609 return FALSE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
610 return vim_strchr(wp->w_p_cocu, c) != NULL; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
611 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
612 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
613 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
614 * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
615 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
616 void |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
617 conceal_check_cursur_line_redraw() |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
618 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
619 if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
620 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
621 need_cursor_line_redraw = TRUE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
622 /* Need to recompute cursor column, e.g., when starting Visual mode |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
623 * without concealing. */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
624 curs_columns(TRUE); |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
625 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
626 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
627 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
628 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
629 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
630 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
631 linenr_T lnum; |
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 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
634 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
635 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
636 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
|
637 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
638 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
639 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
640 /* 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
|
641 * 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
|
642 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
643 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
644 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
645 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
646 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
|
647 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
648 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
|
649 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
650 screen_start(); /* not sure of screen cursor */ |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
651 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
652 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
653 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
654 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
655 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
656 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
|
657 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
658 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
659 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
660 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
661 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
662 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
663 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
664 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
665 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
666 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
667 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
668 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
669 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
670 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
671 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
672 } |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
673 need_cursor_line_redraw = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
674 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
675 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
676 |
7 | 677 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
678 static void update_prepare __ARGS((void)); | |
679 static void update_finish __ARGS((void)); | |
680 | |
681 /* | |
682 * Prepare for updating one or more windows. | |
2008 | 683 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 684 */ |
685 static void | |
686 update_prepare() | |
687 { | |
688 cursor_off(); | |
689 updating_screen = TRUE; | |
690 #ifdef FEAT_GUI | |
691 /* Remove the cursor before starting to do anything, because scrolling may | |
692 * make it difficult to redraw the text under it. */ | |
693 if (gui.in_use) | |
694 gui_undraw_cursor(); | |
695 #endif | |
696 #ifdef FEAT_SEARCH_EXTRA | |
697 start_search_hl(); | |
698 #endif | |
699 } | |
700 | |
701 /* | |
702 * Finish updating one or more windows. | |
703 */ | |
704 static void | |
705 update_finish() | |
706 { | |
707 if (redraw_cmdline) | |
708 showmode(); | |
709 | |
710 # ifdef FEAT_SEARCH_EXTRA | |
711 end_search_hl(); | |
712 # endif | |
713 | |
714 updating_screen = FALSE; | |
715 | |
716 # ifdef FEAT_GUI | |
717 gui_may_resize_shell(); | |
718 | |
719 /* Redraw the cursor and update the scrollbars when all screen updating is | |
720 * done. */ | |
721 if (gui.in_use) | |
722 { | |
723 out_flush(); /* required before updating the cursor */ | |
724 gui_update_cursor(FALSE, FALSE); | |
725 gui_update_scrollbars(FALSE); | |
726 } | |
727 # endif | |
728 } | |
729 #endif | |
730 | |
731 #if defined(FEAT_SIGNS) || defined(PROTO) | |
732 void | |
733 update_debug_sign(buf, lnum) | |
734 buf_T *buf; | |
735 linenr_T lnum; | |
736 { | |
737 win_T *wp; | |
738 int doit = FALSE; | |
739 | |
740 # ifdef FEAT_FOLDING | |
741 win_foldinfo.fi_level = 0; | |
742 # endif | |
743 | |
744 /* update/delete a specific mark */ | |
745 FOR_ALL_WINDOWS(wp) | |
746 { | |
747 if (buf != NULL && lnum > 0) | |
748 { | |
749 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
750 && lnum < wp->w_botline) | |
751 { | |
752 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
753 wp->w_redraw_top = lnum; | |
754 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
755 wp->w_redraw_bot = lnum; | |
756 redraw_win_later(wp, VALID); | |
757 } | |
758 } | |
759 else | |
760 redraw_win_later(wp, VALID); | |
761 if (wp->w_redr_type != 0) | |
762 doit = TRUE; | |
763 } | |
764 | |
2008 | 765 /* Return when there is nothing to do or screen updating already |
766 * happening. */ | |
767 if (!doit || updating_screen) | |
7 | 768 return; |
769 | |
770 /* update all windows that need updating */ | |
771 update_prepare(); | |
772 | |
773 # ifdef FEAT_WINDOWS | |
774 for (wp = firstwin; wp; wp = wp->w_next) | |
775 { | |
776 if (wp->w_redr_type != 0) | |
777 win_update(wp); | |
778 if (wp->w_redr_status) | |
779 win_redr_status(wp); | |
780 } | |
781 # else | |
782 if (curwin->w_redr_type != 0) | |
783 win_update(curwin); | |
784 # endif | |
785 | |
786 update_finish(); | |
787 } | |
788 #endif | |
789 | |
790 | |
791 #if defined(FEAT_GUI) || defined(PROTO) | |
792 /* | |
793 * Update a single window, its status line and maybe the command line msg. | |
794 * Used for the GUI scrollbar. | |
795 */ | |
796 void | |
797 updateWindow(wp) | |
798 win_T *wp; | |
799 { | |
2008 | 800 /* return if already busy updating */ |
801 if (updating_screen) | |
802 return; | |
803 | |
7 | 804 update_prepare(); |
805 | |
806 #ifdef FEAT_CLIPBOARD | |
807 /* When Visual area changed, may have to update selection. */ | |
808 if (clip_star.available && clip_isautosel()) | |
809 clip_update_selection(); | |
810 #endif | |
670 | 811 |
7 | 812 win_update(wp); |
670 | 813 |
7 | 814 #ifdef FEAT_WINDOWS |
670 | 815 /* When the screen was cleared redraw the tab pages line. */ |
673 | 816 if (redraw_tabline) |
677 | 817 draw_tabline(); |
670 | 818 |
7 | 819 if (wp->w_redr_status |
820 # ifdef FEAT_CMDL_INFO | |
821 || p_ru | |
822 # endif | |
823 # ifdef FEAT_STL_OPT | |
40 | 824 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 825 # endif |
826 ) | |
827 win_redr_status(wp); | |
828 #endif | |
829 | |
830 update_finish(); | |
831 } | |
832 #endif | |
833 | |
834 /* | |
835 * Update a single window. | |
836 * | |
837 * This may cause the windows below it also to be redrawn (when clearing the | |
838 * screen or scrolling lines). | |
839 * | |
840 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
841 * implies the one below it. | |
842 * NOT_VALID redraw the whole window | |
743 | 843 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 844 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
845 * INVERTED redraw the changed part of the Visual area | |
846 * INVERTED_ALL redraw the whole Visual area | |
847 * VALID 1. scroll up/down to adjust for a changed w_topline | |
848 * 2. update lines at the top when scrolled down | |
849 * 3. redraw changed text: | |
301 | 850 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 851 * b_mod_top and b_mod_bot. |
852 * - if wp->w_redraw_top non-zero, redraw lines between | |
853 * wp->w_redraw_top and wp->w_redr_bot. | |
854 * - continue redrawing when syntax status is invalid. | |
855 * 4. if scrolled up, update lines at the bottom. | |
856 * This results in three areas that may need updating: | |
857 * top: from first row to top_end (when scrolled down) | |
858 * mid: from mid_start to mid_end (update inversion or changed text) | |
859 * bot: from bot_start to last row (when scrolled up) | |
860 */ | |
861 static void | |
862 win_update(wp) | |
863 win_T *wp; | |
864 { | |
865 buf_T *buf = wp->w_buffer; | |
866 int type; | |
867 int top_end = 0; /* Below last row of the top area that needs | |
868 updating. 0 when no top area updating. */ | |
869 int mid_start = 999;/* first row of the mid area that needs | |
870 updating. 999 when no mid area updating. */ | |
871 int mid_end = 0; /* Below last row of the mid area that needs | |
872 updating. 0 when no mid area updating. */ | |
873 int bot_start = 999;/* first row of the bot area that needs | |
874 updating. 999 when no bot area updating */ | |
875 #ifdef FEAT_VISUAL | |
876 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
877 w_topline got smaller a bit */ | |
878 #endif | |
879 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 880 matchitem_T *cur; /* points to the match list */ |
7 | 881 int top_to_mod = FALSE; /* redraw above mod_top */ |
882 #endif | |
883 | |
884 int row; /* current window row to display */ | |
885 linenr_T lnum; /* current buffer lnum to display */ | |
886 int idx; /* current index in w_lines[] */ | |
887 int srow; /* starting row of the current line */ | |
888 | |
889 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
890 int didline = FALSE; /* if TRUE, we finished the last line */ | |
891 int i; | |
892 long j; | |
893 static int recursive = FALSE; /* being called recursively */ | |
894 int old_botline = wp->w_botline; | |
895 #ifdef FEAT_FOLDING | |
896 long fold_count; | |
897 #endif | |
898 #ifdef FEAT_SYN_HL | |
899 /* remember what happened to the previous line, to know if | |
900 * check_visual_highlight() can be used */ | |
901 #define DID_NONE 1 /* didn't update a line */ | |
902 #define DID_LINE 2 /* updated a normal line */ | |
903 #define DID_FOLD 3 /* updated a folded line */ | |
904 int did_update = DID_NONE; | |
905 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
906 #endif | |
907 linenr_T mod_top = 0; | |
908 linenr_T mod_bot = 0; | |
909 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
910 int save_got_int; | |
911 #endif | |
912 | |
913 type = wp->w_redr_type; | |
914 | |
915 if (type == NOT_VALID) | |
916 { | |
917 #ifdef FEAT_WINDOWS | |
918 wp->w_redr_status = TRUE; | |
919 #endif | |
920 wp->w_lines_valid = 0; | |
921 } | |
922 | |
923 /* Window is zero-height: nothing to draw. */ | |
924 if (wp->w_height == 0) | |
925 { | |
926 wp->w_redr_type = 0; | |
927 return; | |
928 } | |
929 | |
930 #ifdef FEAT_VERTSPLIT | |
931 /* Window is zero-width: Only need to draw the separator. */ | |
932 if (wp->w_width == 0) | |
933 { | |
934 /* draw the vertical separator right of this window */ | |
935 draw_vsep_win(wp, 0); | |
936 wp->w_redr_type = 0; | |
937 return; | |
938 } | |
939 #endif | |
940 | |
941 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
942 init_search_hl(wp); |
7 | 943 #endif |
944 | |
13 | 945 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
946 /* 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
|
947 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
948 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 949 if (wp->w_nrwidth != i) |
13 | 950 { |
951 type = NOT_VALID; | |
677 | 952 wp->w_nrwidth = i; |
13 | 953 } |
954 else | |
955 #endif | |
956 | |
7 | 957 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
958 { | |
959 /* | |
960 * When there are both inserted/deleted lines and specific lines to be | |
961 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
962 * everything (only happens when redrawing is off for while). | |
963 */ | |
964 type = NOT_VALID; | |
965 } | |
966 else | |
967 { | |
968 /* | |
969 * Set mod_top to the first line that needs displaying because of | |
970 * changes. Set mod_bot to the first line after the changes. | |
971 */ | |
972 mod_top = wp->w_redraw_top; | |
973 if (wp->w_redraw_bot != 0) | |
974 mod_bot = wp->w_redraw_bot + 1; | |
975 else | |
976 mod_bot = 0; | |
977 wp->w_redraw_top = 0; /* reset for next time */ | |
978 wp->w_redraw_bot = 0; | |
979 if (buf->b_mod_set) | |
980 { | |
981 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
982 { | |
983 mod_top = buf->b_mod_top; | |
984 #ifdef FEAT_SYN_HL | |
985 /* Need to redraw lines above the change that may be included | |
986 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
987 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
988 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
989 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 990 if (mod_top < 1) |
991 mod_top = 1; | |
992 } | |
993 #endif | |
994 } | |
995 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
996 mod_bot = buf->b_mod_bot; | |
997 | |
998 #ifdef FEAT_SEARCH_EXTRA | |
999 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
1000 * change in one line may make the Search highlighting in a | |
1001 * previous line invalid. Simple solution: redraw all visible | |
1002 * lines above the change. | |
1326 | 1003 * Same for a match pattern. |
7 | 1004 */ |
699 | 1005 if (search_hl.rm.regprog != NULL |
1006 && re_multiline(search_hl.rm.regprog)) | |
7 | 1007 top_to_mod = TRUE; |
699 | 1008 else |
1326 | 1009 { |
1010 cur = wp->w_match_head; | |
1011 while (cur != NULL) | |
1012 { | |
1013 if (cur->match.regprog != NULL | |
1014 && re_multiline(cur->match.regprog)) | |
699 | 1015 { |
1016 top_to_mod = TRUE; | |
1017 break; | |
1018 } | |
1326 | 1019 cur = cur->next; |
1020 } | |
1021 } | |
7 | 1022 #endif |
1023 } | |
1024 #ifdef FEAT_FOLDING | |
1025 if (mod_top != 0 && hasAnyFolding(wp)) | |
1026 { | |
1027 linenr_T lnumt, lnumb; | |
1028 | |
1029 /* | |
1030 * A change in a line can cause lines above it to become folded or | |
1031 * unfolded. Find the top most buffer line that may be affected. | |
1032 * If the line was previously folded and displayed, get the first | |
1033 * line of that fold. If the line is folded now, get the first | |
1034 * folded line. Use the minimum of these two. | |
1035 */ | |
1036 | |
1037 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
1038 * the line below it. If there is no valid entry, use w_topline. | |
1039 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1040 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1041 lnumt = wp->w_topline; | |
1042 lnumb = MAXLNUM; | |
1043 for (i = 0; i < wp->w_lines_valid; ++i) | |
1044 if (wp->w_lines[i].wl_valid) | |
1045 { | |
1046 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1047 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1048 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1049 { | |
1050 lnumb = wp->w_lines[i].wl_lnum; | |
1051 /* When there is a fold column it might need updating | |
1052 * in the next line ("J" just above an open fold). */ | |
1053 if (wp->w_p_fdc > 0) | |
1054 ++lnumb; | |
1055 } | |
1056 } | |
1057 | |
1058 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1059 if (mod_top > lnumt) | |
1060 mod_top = lnumt; | |
1061 | |
1062 /* Now do the same for the bottom line (one above mod_bot). */ | |
1063 --mod_bot; | |
1064 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1065 ++mod_bot; | |
1066 if (mod_bot < lnumb) | |
1067 mod_bot = lnumb; | |
1068 } | |
1069 #endif | |
1070 | |
1071 /* When a change starts above w_topline and the end is below | |
1072 * w_topline, start redrawing at w_topline. | |
36 | 1073 * If the end of the change is above w_topline: do like no change was |
1074 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1075 if (mod_top != 0 && mod_top < wp->w_topline) |
1076 { | |
1077 if (mod_bot > wp->w_topline) | |
1078 mod_top = wp->w_topline; | |
1079 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1080 else if (syntax_present(wp)) |
7 | 1081 top_end = 1; |
1082 #endif | |
1083 } | |
36 | 1084 |
1085 /* When line numbers are displayed need to redraw all lines below | |
1086 * inserted/deleted lines. */ | |
1087 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1088 mod_bot = MAXLNUM; | |
7 | 1089 } |
1090 | |
1091 /* | |
1092 * When only displaying the lines at the top, set top_end. Used when | |
1093 * window has scrolled down for msg_scrolled. | |
1094 */ | |
1095 if (type == REDRAW_TOP) | |
1096 { | |
1097 j = 0; | |
1098 for (i = 0; i < wp->w_lines_valid; ++i) | |
1099 { | |
1100 j += wp->w_lines[i].wl_size; | |
1101 if (j >= wp->w_upd_rows) | |
1102 { | |
1103 top_end = j; | |
1104 break; | |
1105 } | |
1106 } | |
1107 if (top_end == 0) | |
1108 /* not found (cannot happen?): redraw everything */ | |
1109 type = NOT_VALID; | |
1110 else | |
1111 /* top area defined, the rest is VALID */ | |
1112 type = VALID; | |
1113 } | |
1114 | |
1378 | 1115 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1116 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1117 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1118 * called. */ | |
1119 if (screen_cleared) | |
1120 screen_cleared = MAYBE; | |
1121 | |
7 | 1122 /* |
1123 * If there are no changes on the screen that require a complete redraw, | |
1124 * handle three cases: | |
1125 * 1: we are off the top of the screen by a few lines: scroll down | |
1126 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1127 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1128 * w_lines[] that needs updating. | |
1129 */ | |
743 | 1130 if ((type == VALID || type == SOME_VALID |
1131 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1132 #ifdef FEAT_DIFF |
1133 && !wp->w_botfill && !wp->w_old_botfill | |
1134 #endif | |
1135 ) | |
1136 { | |
1137 if (mod_top != 0 && wp->w_topline == mod_top) | |
1138 { | |
1139 /* | |
1140 * w_topline is the first changed line, the scrolling will be done | |
1141 * further down. | |
1142 */ | |
1143 } | |
1144 else if (wp->w_lines[0].wl_valid | |
1145 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1146 #ifdef FEAT_DIFF | |
1147 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1148 && wp->w_topfill > wp->w_old_topfill) | |
1149 #endif | |
1150 )) | |
1151 { | |
1152 /* | |
1153 * New topline is above old topline: May scroll down. | |
1154 */ | |
1155 #ifdef FEAT_FOLDING | |
1156 if (hasAnyFolding(wp)) | |
1157 { | |
1158 linenr_T ln; | |
1159 | |
1160 /* count the number of lines we are off, counting a sequence | |
1161 * of folded lines as one */ | |
1162 j = 0; | |
1163 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1164 { | |
1165 ++j; | |
1166 if (j >= wp->w_height - 2) | |
1167 break; | |
1168 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1169 } | |
1170 } | |
1171 else | |
1172 #endif | |
1173 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1174 if (j < wp->w_height - 2) /* not too far off */ | |
1175 { | |
1176 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1177 #ifdef FEAT_DIFF | |
1178 /* insert extra lines for previously invisible filler lines */ | |
1179 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1180 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1181 - wp->w_old_topfill; | |
1182 #endif | |
1183 if (i < wp->w_height - 2) /* less than a screen off */ | |
1184 { | |
1185 /* | |
1186 * Try to insert the correct number of lines. | |
1187 * If not the last window, delete the lines at the bottom. | |
1188 * win_ins_lines may fail when the terminal can't do it. | |
1189 */ | |
1190 if (i > 0) | |
1191 check_for_delay(FALSE); | |
1192 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1193 { | |
1194 if (wp->w_lines_valid != 0) | |
1195 { | |
1196 /* Need to update rows that are new, stop at the | |
1197 * first one that scrolled down. */ | |
1198 top_end = i; | |
1199 #ifdef FEAT_VISUAL | |
1200 scrolled_down = TRUE; | |
1201 #endif | |
1202 | |
1203 /* Move the entries that were scrolled, disable | |
1204 * the entries for the lines to be redrawn. */ | |
1205 if ((wp->w_lines_valid += j) > wp->w_height) | |
1206 wp->w_lines_valid = wp->w_height; | |
1207 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1208 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1209 while (idx >= 0) | |
1210 wp->w_lines[idx--].wl_valid = FALSE; | |
1211 } | |
1212 } | |
1213 else | |
1214 mid_start = 0; /* redraw all lines */ | |
1215 } | |
1216 else | |
1217 mid_start = 0; /* redraw all lines */ | |
1218 } | |
1219 else | |
1220 mid_start = 0; /* redraw all lines */ | |
1221 } | |
1222 else | |
1223 { | |
1224 /* | |
1225 * New topline is at or below old topline: May scroll up. | |
1226 * When topline didn't change, find first entry in w_lines[] that | |
1227 * needs updating. | |
1228 */ | |
1229 | |
1230 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1231 j = -1; | |
1232 row = 0; | |
1233 for (i = 0; i < wp->w_lines_valid; i++) | |
1234 { | |
1235 if (wp->w_lines[i].wl_valid | |
1236 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1237 { | |
1238 j = i; | |
1239 break; | |
1240 } | |
1241 row += wp->w_lines[i].wl_size; | |
1242 } | |
1243 if (j == -1) | |
1244 { | |
1245 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1246 * lines */ | |
1247 mid_start = 0; | |
1248 } | |
1249 else | |
1250 { | |
1251 /* | |
1252 * Try to delete the correct number of lines. | |
1253 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1254 */ | |
1255 #ifdef FEAT_DIFF | |
1256 /* If the topline didn't change, delete old filler lines, | |
1257 * otherwise delete filler lines of the new topline... */ | |
1258 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1259 row += wp->w_old_topfill; | |
1260 else | |
1261 row += diff_check_fill(wp, wp->w_topline); | |
1262 /* ... but don't delete new filler lines. */ | |
1263 row -= wp->w_topfill; | |
1264 #endif | |
1265 if (row > 0) | |
1266 { | |
1267 check_for_delay(FALSE); | |
1268 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1269 bot_start = wp->w_height - row; | |
1270 else | |
1271 mid_start = 0; /* redraw all lines */ | |
1272 } | |
1273 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1274 { | |
1275 /* | |
1276 * Skip the lines (below the deleted lines) that are still | |
1277 * valid and don't need redrawing. Copy their info | |
1278 * upwards, to compensate for the deleted lines. Set | |
1279 * bot_start to the first row that needs redrawing. | |
1280 */ | |
1281 bot_start = 0; | |
1282 idx = 0; | |
1283 for (;;) | |
1284 { | |
1285 wp->w_lines[idx] = wp->w_lines[j]; | |
1286 /* stop at line that didn't fit, unless it is still | |
1287 * valid (no lines deleted) */ | |
1288 if (row > 0 && bot_start + row | |
1289 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1290 { | |
1291 wp->w_lines_valid = idx + 1; | |
1292 break; | |
1293 } | |
1294 bot_start += wp->w_lines[idx++].wl_size; | |
1295 | |
1296 /* stop at the last valid entry in w_lines[].wl_size */ | |
1297 if (++j >= wp->w_lines_valid) | |
1298 { | |
1299 wp->w_lines_valid = idx; | |
1300 break; | |
1301 } | |
1302 } | |
1303 #ifdef FEAT_DIFF | |
1304 /* Correct the first entry for filler lines at the top | |
1305 * when it won't get updated below. */ | |
1306 if (wp->w_p_diff && bot_start > 0) | |
1307 wp->w_lines[0].wl_size = | |
1308 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1309 + wp->w_topfill; | |
1310 #endif | |
1311 } | |
1312 } | |
1313 } | |
1314 | |
1315 /* When starting redraw in the first line, redraw all lines. When | |
1316 * there is only one window it's probably faster to clear the screen | |
1317 * first. */ | |
1318 if (mid_start == 0) | |
1319 { | |
1320 mid_end = wp->w_height; | |
1321 if (lastwin == firstwin) | |
981 | 1322 { |
1331 | 1323 /* Clear the screen when it was not done by win_del_lines() or |
1324 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1325 * then. */ | |
1326 if (screen_cleared != TRUE) | |
1327 screenclear(); | |
981 | 1328 #ifdef FEAT_WINDOWS |
1329 /* The screen was cleared, redraw the tab pages line. */ | |
1330 if (redraw_tabline) | |
1331 draw_tabline(); | |
1332 #endif | |
1333 } | |
7 | 1334 } |
1331 | 1335 |
1336 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1337 * cleared (only happens for the first window) or when screenclear() | |
1338 * was called directly above, "must_redraw" will have been set to | |
1339 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1340 if (screen_cleared == TRUE) | |
1341 must_redraw = 0; | |
7 | 1342 } |
1343 else | |
1344 { | |
1345 /* Not VALID or INVERTED: redraw all lines. */ | |
1346 mid_start = 0; | |
1347 mid_end = wp->w_height; | |
1348 } | |
1349 | |
743 | 1350 if (type == SOME_VALID) |
1351 { | |
1352 /* SOME_VALID: redraw all lines. */ | |
1353 mid_start = 0; | |
1354 mid_end = wp->w_height; | |
1355 type = NOT_VALID; | |
1356 } | |
1357 | |
7 | 1358 #ifdef FEAT_VISUAL |
1359 /* check if we are updating or removing the inverted part */ | |
1360 if ((VIsual_active && buf == curwin->w_buffer) | |
1361 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1362 { | |
1363 linenr_T from, to; | |
1364 | |
1365 if (VIsual_active) | |
1366 { | |
1367 if (VIsual_active | |
1368 && (VIsual_mode != wp->w_old_visual_mode | |
1369 || type == INVERTED_ALL)) | |
1370 { | |
1371 /* | |
1372 * If the type of Visual selection changed, redraw the whole | |
1373 * selection. Also when the ownership of the X selection is | |
1374 * gained or lost. | |
1375 */ | |
1376 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1377 { | |
1378 from = curwin->w_cursor.lnum; | |
1379 to = VIsual.lnum; | |
1380 } | |
1381 else | |
1382 { | |
1383 from = VIsual.lnum; | |
1384 to = curwin->w_cursor.lnum; | |
1385 } | |
1386 /* redraw more when the cursor moved as well */ | |
1387 if (wp->w_old_cursor_lnum < from) | |
1388 from = wp->w_old_cursor_lnum; | |
1389 if (wp->w_old_cursor_lnum > to) | |
1390 to = wp->w_old_cursor_lnum; | |
1391 if (wp->w_old_visual_lnum < from) | |
1392 from = wp->w_old_visual_lnum; | |
1393 if (wp->w_old_visual_lnum > to) | |
1394 to = wp->w_old_visual_lnum; | |
1395 } | |
1396 else | |
1397 { | |
1398 /* | |
1399 * Find the line numbers that need to be updated: The lines | |
1400 * between the old cursor position and the current cursor | |
1401 * position. Also check if the Visual position changed. | |
1402 */ | |
1403 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1404 { | |
1405 from = curwin->w_cursor.lnum; | |
1406 to = wp->w_old_cursor_lnum; | |
1407 } | |
1408 else | |
1409 { | |
1410 from = wp->w_old_cursor_lnum; | |
1411 to = curwin->w_cursor.lnum; | |
1412 if (from == 0) /* Visual mode just started */ | |
1413 from = to; | |
1414 } | |
1415 | |
422 | 1416 if (VIsual.lnum != wp->w_old_visual_lnum |
1417 || VIsual.col != wp->w_old_visual_col) | |
7 | 1418 { |
1419 if (wp->w_old_visual_lnum < from | |
1420 && wp->w_old_visual_lnum != 0) | |
1421 from = wp->w_old_visual_lnum; | |
1422 if (wp->w_old_visual_lnum > to) | |
1423 to = wp->w_old_visual_lnum; | |
1424 if (VIsual.lnum < from) | |
1425 from = VIsual.lnum; | |
1426 if (VIsual.lnum > to) | |
1427 to = VIsual.lnum; | |
1428 } | |
1429 } | |
1430 | |
1431 /* | |
1432 * If in block mode and changed column or curwin->w_curswant: | |
1433 * update all lines. | |
1434 * First compute the actual start and end column. | |
1435 */ | |
1436 if (VIsual_mode == Ctrl_V) | |
1437 { | |
1438 colnr_T fromc, toc; | |
1439 | |
1440 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1441 ++toc; | |
1442 if (curwin->w_curswant == MAXCOL) | |
1443 toc = MAXCOL; | |
1444 | |
1445 if (fromc != wp->w_old_cursor_fcol | |
1446 || toc != wp->w_old_cursor_lcol) | |
1447 { | |
1448 if (from > VIsual.lnum) | |
1449 from = VIsual.lnum; | |
1450 if (to < VIsual.lnum) | |
1451 to = VIsual.lnum; | |
1452 } | |
1453 wp->w_old_cursor_fcol = fromc; | |
1454 wp->w_old_cursor_lcol = toc; | |
1455 } | |
1456 } | |
1457 else | |
1458 { | |
1459 /* Use the line numbers of the old Visual area. */ | |
1460 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1461 { | |
1462 from = wp->w_old_cursor_lnum; | |
1463 to = wp->w_old_visual_lnum; | |
1464 } | |
1465 else | |
1466 { | |
1467 from = wp->w_old_visual_lnum; | |
1468 to = wp->w_old_cursor_lnum; | |
1469 } | |
1470 } | |
1471 | |
1472 /* | |
1473 * There is no need to update lines above the top of the window. | |
1474 */ | |
1475 if (from < wp->w_topline) | |
1476 from = wp->w_topline; | |
1477 | |
1478 /* | |
1479 * If we know the value of w_botline, use it to restrict the update to | |
1480 * the lines that are visible in the window. | |
1481 */ | |
1482 if (wp->w_valid & VALID_BOTLINE) | |
1483 { | |
1484 if (from >= wp->w_botline) | |
1485 from = wp->w_botline - 1; | |
1486 if (to >= wp->w_botline) | |
1487 to = wp->w_botline - 1; | |
1488 } | |
1489 | |
1490 /* | |
1491 * Find the minimal part to be updated. | |
1492 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1493 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1494 * top_end; need to redraw from top_end to the "to" line. | |
1495 * A middle mouse click with a Visual selection may change the text | |
1496 * above the Visual area and reset wl_valid, do count these for | |
1497 * mid_end (in srow). | |
1498 */ | |
1499 if (mid_start > 0) | |
1500 { | |
1501 lnum = wp->w_topline; | |
1502 idx = 0; | |
1503 srow = 0; | |
1504 if (scrolled_down) | |
1505 mid_start = top_end; | |
1506 else | |
1507 mid_start = 0; | |
1508 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1509 { | |
1510 if (wp->w_lines[idx].wl_valid) | |
1511 mid_start += wp->w_lines[idx].wl_size; | |
1512 else if (!scrolled_down) | |
1513 srow += wp->w_lines[idx].wl_size; | |
1514 ++idx; | |
1515 # ifdef FEAT_FOLDING | |
1516 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1517 lnum = wp->w_lines[idx].wl_lnum; | |
1518 else | |
1519 # endif | |
1520 ++lnum; | |
1521 } | |
1522 srow += mid_start; | |
1523 mid_end = wp->w_height; | |
1524 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1525 { | |
1526 if (wp->w_lines[idx].wl_valid | |
1527 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1528 { | |
1529 /* Only update until first row of this line */ | |
1530 mid_end = srow; | |
1531 break; | |
1532 } | |
1533 srow += wp->w_lines[idx].wl_size; | |
1534 } | |
1535 } | |
1536 } | |
1537 | |
1538 if (VIsual_active && buf == curwin->w_buffer) | |
1539 { | |
1540 wp->w_old_visual_mode = VIsual_mode; | |
1541 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1542 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1543 wp->w_old_visual_col = VIsual.col; |
7 | 1544 wp->w_old_curswant = curwin->w_curswant; |
1545 } | |
1546 else | |
1547 { | |
1548 wp->w_old_visual_mode = 0; | |
1549 wp->w_old_cursor_lnum = 0; | |
1550 wp->w_old_visual_lnum = 0; | |
422 | 1551 wp->w_old_visual_col = 0; |
7 | 1552 } |
1553 #endif /* FEAT_VISUAL */ | |
1554 | |
1555 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1556 /* reset got_int, otherwise regexp won't work */ | |
1557 save_got_int = got_int; | |
1558 got_int = 0; | |
1559 #endif | |
1560 #ifdef FEAT_FOLDING | |
1561 win_foldinfo.fi_level = 0; | |
1562 #endif | |
1563 | |
1564 /* | |
1565 * Update all the window rows. | |
1566 */ | |
1567 idx = 0; /* first entry in w_lines[].wl_size */ | |
1568 row = 0; | |
1569 srow = 0; | |
1570 lnum = wp->w_topline; /* first line shown in window */ | |
1571 for (;;) | |
1572 { | |
1573 /* stop updating when reached the end of the window (check for _past_ | |
1574 * the end of the window is at the end of the loop) */ | |
1575 if (row == wp->w_height) | |
1576 { | |
1577 didline = TRUE; | |
1578 break; | |
1579 } | |
1580 | |
1581 /* stop updating when hit the end of the file */ | |
1582 if (lnum > buf->b_ml.ml_line_count) | |
1583 { | |
1584 eof = TRUE; | |
1585 break; | |
1586 } | |
1587 | |
1588 /* Remember the starting row of the line that is going to be dealt | |
1589 * with. It is used further down when the line doesn't fit. */ | |
1590 srow = row; | |
1591 | |
1592 /* | |
1593 * Update a line when it is in an area that needs updating, when it | |
1594 * has changes or w_lines[idx] is invalid. | |
1595 * bot_start may be halfway a wrapped line after using | |
1596 * win_del_lines(), check if the current line includes it. | |
1597 * When syntax folding is being used, the saved syntax states will | |
1598 * already have been updated, we can't see where the syntax state is | |
1599 * the same again, just update until the end of the window. | |
1600 */ | |
1601 if (row < top_end | |
1602 || (row >= mid_start && row < mid_end) | |
1603 #ifdef FEAT_SEARCH_EXTRA | |
1604 || top_to_mod | |
1605 #endif | |
1606 || idx >= wp->w_lines_valid | |
1607 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1608 || (mod_top != 0 | |
1609 && (lnum == mod_top | |
1610 || (lnum >= mod_top | |
1611 && (lnum < mod_bot | |
1612 #ifdef FEAT_SYN_HL | |
1613 || did_update == DID_FOLD | |
1614 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1615 && syntax_present(wp) |
7 | 1616 && ( |
1617 # ifdef FEAT_FOLDING | |
1618 (foldmethodIsSyntax(wp) | |
1619 && hasAnyFolding(wp)) || | |
1620 # endif | |
1621 syntax_check_changed(lnum))) | |
1622 #endif | |
1623 ))))) | |
1624 { | |
1625 #ifdef FEAT_SEARCH_EXTRA | |
1626 if (lnum == mod_top) | |
1627 top_to_mod = FALSE; | |
1628 #endif | |
1629 | |
1630 /* | |
1631 * When at start of changed lines: May scroll following lines | |
1632 * up or down to minimize redrawing. | |
1633 * Don't do this when the change continues until the end. | |
1634 * Don't scroll when dollar_vcol is non-zero, keep the "$". | |
1635 */ | |
1636 if (lnum == mod_top | |
1637 && mod_bot != MAXLNUM | |
1638 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) | |
1639 { | |
1640 int old_rows = 0; | |
1641 int new_rows = 0; | |
1642 int xtra_rows; | |
1643 linenr_T l; | |
1644 | |
1645 /* Count the old number of window rows, using w_lines[], which | |
1646 * should still contain the sizes for the lines as they are | |
1647 * currently displayed. */ | |
1648 for (i = idx; i < wp->w_lines_valid; ++i) | |
1649 { | |
1650 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1651 * lines are part of the changed area. */ | |
1652 if (wp->w_lines[i].wl_valid | |
1653 && wp->w_lines[i].wl_lnum == mod_bot) | |
1654 break; | |
1655 old_rows += wp->w_lines[i].wl_size; | |
1656 #ifdef FEAT_FOLDING | |
1657 if (wp->w_lines[i].wl_valid | |
1658 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1659 { | |
1660 /* Must have found the last valid entry above mod_bot. | |
1661 * Add following invalid entries. */ | |
1662 ++i; | |
1663 while (i < wp->w_lines_valid | |
1664 && !wp->w_lines[i].wl_valid) | |
1665 old_rows += wp->w_lines[i++].wl_size; | |
1666 break; | |
1667 } | |
1668 #endif | |
1669 } | |
1670 | |
1671 if (i >= wp->w_lines_valid) | |
1672 { | |
1673 /* We can't find a valid line below the changed lines, | |
1674 * need to redraw until the end of the window. | |
1675 * Inserting/deleting lines has no use. */ | |
1676 bot_start = 0; | |
1677 } | |
1678 else | |
1679 { | |
1680 /* Able to count old number of rows: Count new window | |
1681 * rows, and may insert/delete lines */ | |
1682 j = idx; | |
1683 for (l = lnum; l < mod_bot; ++l) | |
1684 { | |
1685 #ifdef FEAT_FOLDING | |
1686 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1687 ++new_rows; | |
1688 else | |
1689 #endif | |
1690 #ifdef FEAT_DIFF | |
1691 if (l == wp->w_topline) | |
1692 new_rows += plines_win_nofill(wp, l, TRUE) | |
1693 + wp->w_topfill; | |
1694 else | |
1695 #endif | |
1696 new_rows += plines_win(wp, l, TRUE); | |
1697 ++j; | |
1698 if (new_rows > wp->w_height - row - 2) | |
1699 { | |
1700 /* it's getting too much, must redraw the rest */ | |
1701 new_rows = 9999; | |
1702 break; | |
1703 } | |
1704 } | |
1705 xtra_rows = new_rows - old_rows; | |
1706 if (xtra_rows < 0) | |
1707 { | |
1708 /* May scroll text up. If there is not enough | |
1709 * remaining text or scrolling fails, must redraw the | |
1710 * rest. If scrolling works, must redraw the text | |
1711 * below the scrolled text. */ | |
1712 if (row - xtra_rows >= wp->w_height - 2) | |
1713 mod_bot = MAXLNUM; | |
1714 else | |
1715 { | |
1716 check_for_delay(FALSE); | |
1717 if (win_del_lines(wp, row, | |
1718 -xtra_rows, FALSE, FALSE) == FAIL) | |
1719 mod_bot = MAXLNUM; | |
1720 else | |
1721 bot_start = wp->w_height + xtra_rows; | |
1722 } | |
1723 } | |
1724 else if (xtra_rows > 0) | |
1725 { | |
1726 /* May scroll text down. If there is not enough | |
1727 * remaining text of scrolling fails, must redraw the | |
1728 * rest. */ | |
1729 if (row + xtra_rows >= wp->w_height - 2) | |
1730 mod_bot = MAXLNUM; | |
1731 else | |
1732 { | |
1733 check_for_delay(FALSE); | |
1734 if (win_ins_lines(wp, row + old_rows, | |
1735 xtra_rows, FALSE, FALSE) == FAIL) | |
1736 mod_bot = MAXLNUM; | |
1737 else if (top_end > row + old_rows) | |
1738 /* Scrolled the part at the top that requires | |
1739 * updating down. */ | |
1740 top_end += xtra_rows; | |
1741 } | |
1742 } | |
1743 | |
1744 /* When not updating the rest, may need to move w_lines[] | |
1745 * entries. */ | |
1746 if (mod_bot != MAXLNUM && i != j) | |
1747 { | |
1748 if (j < i) | |
1749 { | |
1750 int x = row + new_rows; | |
1751 | |
1752 /* move entries in w_lines[] upwards */ | |
1753 for (;;) | |
1754 { | |
1755 /* stop at last valid entry in w_lines[] */ | |
1756 if (i >= wp->w_lines_valid) | |
1757 { | |
1758 wp->w_lines_valid = j; | |
1759 break; | |
1760 } | |
1761 wp->w_lines[j] = wp->w_lines[i]; | |
1762 /* stop at a line that won't fit */ | |
1763 if (x + (int)wp->w_lines[j].wl_size | |
1764 > wp->w_height) | |
1765 { | |
1766 wp->w_lines_valid = j + 1; | |
1767 break; | |
1768 } | |
1769 x += wp->w_lines[j++].wl_size; | |
1770 ++i; | |
1771 } | |
1772 if (bot_start > x) | |
1773 bot_start = x; | |
1774 } | |
1775 else /* j > i */ | |
1776 { | |
1777 /* move entries in w_lines[] downwards */ | |
1778 j -= i; | |
1779 wp->w_lines_valid += j; | |
1780 if (wp->w_lines_valid > wp->w_height) | |
1781 wp->w_lines_valid = wp->w_height; | |
1782 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1783 wp->w_lines[i] = wp->w_lines[i - j]; | |
1784 | |
1785 /* The w_lines[] entries for inserted lines are | |
1786 * now invalid, but wl_size may be used above. | |
1787 * Reset to zero. */ | |
1788 while (i >= idx) | |
1789 { | |
1790 wp->w_lines[i].wl_size = 0; | |
1791 wp->w_lines[i--].wl_valid = FALSE; | |
1792 } | |
1793 } | |
1794 } | |
1795 } | |
1796 } | |
1797 | |
1798 #ifdef FEAT_FOLDING | |
1799 /* | |
1800 * When lines are folded, display one line for all of them. | |
1801 * Otherwise, display normally (can be several display lines when | |
1802 * 'wrap' is on). | |
1803 */ | |
1804 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1805 if (fold_count != 0) | |
1806 { | |
1807 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1808 ++row; | |
1809 --fold_count; | |
1810 wp->w_lines[idx].wl_folded = TRUE; | |
1811 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1812 # ifdef FEAT_SYN_HL | |
1813 did_update = DID_FOLD; | |
1814 # endif | |
1815 } | |
1816 else | |
1817 #endif | |
1818 if (idx < wp->w_lines_valid | |
1819 && wp->w_lines[idx].wl_valid | |
1820 && wp->w_lines[idx].wl_lnum == lnum | |
1821 && lnum > wp->w_topline | |
1822 && !(dy_flags & DY_LASTLINE) | |
1823 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1824 #ifdef FEAT_DIFF | |
1825 && diff_check_fill(wp, lnum) == 0 | |
1826 #endif | |
1827 ) | |
1828 { | |
1829 /* This line is not going to fit. Don't draw anything here, | |
1830 * will draw "@ " lines below. */ | |
1831 row = wp->w_height + 1; | |
1832 } | |
1833 else | |
1834 { | |
1835 #ifdef FEAT_SEARCH_EXTRA | |
1836 prepare_search_hl(wp, lnum); | |
1837 #endif | |
1838 #ifdef FEAT_SYN_HL | |
1839 /* Let the syntax stuff know we skipped a few lines. */ | |
1840 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
|
1841 && syntax_present(wp)) |
7 | 1842 syntax_end_parsing(syntax_last_parsed + 1); |
1843 #endif | |
1844 | |
1845 /* | |
1846 * Display one line. | |
1847 */ | |
625 | 1848 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1849 |
1850 #ifdef FEAT_FOLDING | |
1851 wp->w_lines[idx].wl_folded = FALSE; | |
1852 wp->w_lines[idx].wl_lastlnum = lnum; | |
1853 #endif | |
1854 #ifdef FEAT_SYN_HL | |
1855 did_update = DID_LINE; | |
1856 syntax_last_parsed = lnum; | |
1857 #endif | |
1858 } | |
1859 | |
1860 wp->w_lines[idx].wl_lnum = lnum; | |
1861 wp->w_lines[idx].wl_valid = TRUE; | |
1862 if (row > wp->w_height) /* past end of screen */ | |
1863 { | |
1864 /* we may need the size of that too long line later on */ | |
1865 if (dollar_vcol == 0) | |
1866 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); | |
1867 ++idx; | |
1868 break; | |
1869 } | |
1870 if (dollar_vcol == 0) | |
1871 wp->w_lines[idx].wl_size = row - srow; | |
1872 ++idx; | |
1873 #ifdef FEAT_FOLDING | |
1874 lnum += fold_count + 1; | |
1875 #else | |
1876 ++lnum; | |
1877 #endif | |
1878 } | |
1879 else | |
1880 { | |
1881 /* This line does not need updating, advance to the next one */ | |
1882 row += wp->w_lines[idx++].wl_size; | |
1883 if (row > wp->w_height) /* past end of screen */ | |
1884 break; | |
1885 #ifdef FEAT_FOLDING | |
1886 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1887 #else | |
1888 ++lnum; | |
1889 #endif | |
1890 #ifdef FEAT_SYN_HL | |
1891 did_update = DID_NONE; | |
1892 #endif | |
1893 } | |
1894 | |
1895 if (lnum > buf->b_ml.ml_line_count) | |
1896 { | |
1897 eof = TRUE; | |
1898 break; | |
1899 } | |
1900 } | |
1901 /* | |
1902 * End of loop over all window lines. | |
1903 */ | |
1904 | |
1905 | |
1906 if (idx > wp->w_lines_valid) | |
1907 wp->w_lines_valid = idx; | |
1908 | |
1909 #ifdef FEAT_SYN_HL | |
1910 /* | |
1911 * Let the syntax stuff know we stop parsing here. | |
1912 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1913 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1914 syntax_end_parsing(syntax_last_parsed + 1); |
1915 #endif | |
1916 | |
1917 /* | |
1918 * If we didn't hit the end of the file, and we didn't finish the last | |
1919 * line we were working on, then the line didn't fit. | |
1920 */ | |
1921 wp->w_empty_rows = 0; | |
1922 #ifdef FEAT_DIFF | |
1923 wp->w_filler_rows = 0; | |
1924 #endif | |
1925 if (!eof && !didline) | |
1926 { | |
1927 if (lnum == wp->w_topline) | |
1928 { | |
1929 /* | |
1930 * Single line that does not fit! | |
1931 * Don't overwrite it, it can be edited. | |
1932 */ | |
1933 wp->w_botline = lnum + 1; | |
1934 } | |
1935 #ifdef FEAT_DIFF | |
1936 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1937 { | |
1938 /* Window ends in filler lines. */ | |
1939 wp->w_botline = lnum; | |
1940 wp->w_filler_rows = wp->w_height - srow; | |
1941 } | |
1942 #endif | |
1943 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1944 { | |
1945 /* | |
1946 * Last line isn't finished: Display "@@@" at the end. | |
1947 */ | |
1948 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1949 W_WINROW(wp) + wp->w_height, | |
1950 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1951 '@', '@', hl_attr(HLF_AT)); | |
1952 set_empty_rows(wp, srow); | |
1953 wp->w_botline = lnum; | |
1954 } | |
1955 else | |
1956 { | |
1957 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1958 wp->w_botline = lnum; | |
1959 } | |
1960 } | |
1961 else | |
1962 { | |
1963 #ifdef FEAT_VERTSPLIT | |
1964 draw_vsep_win(wp, row); | |
1965 #endif | |
1966 if (eof) /* we hit the end of the file */ | |
1967 { | |
1968 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1969 #ifdef FEAT_DIFF | |
1970 j = diff_check_fill(wp, wp->w_botline); | |
1971 if (j > 0 && !wp->w_botfill) | |
1972 { | |
1973 /* | |
1974 * Display filler lines at the end of the file | |
1975 */ | |
1976 if (char2cells(fill_diff) > 1) | |
1977 i = '-'; | |
1978 else | |
1979 i = fill_diff; | |
1980 if (row + j > wp->w_height) | |
1981 j = wp->w_height - row; | |
1982 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1983 row += j; | |
1984 } | |
1985 #endif | |
1986 } | |
1987 else if (dollar_vcol == 0) | |
1988 wp->w_botline = lnum; | |
1989 | |
1990 /* make sure the rest of the screen is blank */ | |
1991 /* put '~'s on rows that aren't part of the file. */ | |
1992 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
1993 } | |
1994 | |
1995 /* Reset the type of redrawing required, the window has been updated. */ | |
1996 wp->w_redr_type = 0; | |
1997 #ifdef FEAT_DIFF | |
1998 wp->w_old_topfill = wp->w_topfill; | |
1999 wp->w_old_botfill = wp->w_botfill; | |
2000 #endif | |
2001 | |
2002 if (dollar_vcol == 0) | |
2003 { | |
2004 /* | |
2005 * There is a trick with w_botline. If we invalidate it on each | |
2006 * change that might modify it, this will cause a lot of expensive | |
2007 * calls to plines() in update_topline() each time. Therefore the | |
2008 * value of w_botline is often approximated, and this value is used to | |
2009 * compute the value of w_topline. If the value of w_botline was | |
2010 * wrong, check that the value of w_topline is correct (cursor is on | |
2011 * the visible part of the text). If it's not, we need to redraw | |
2012 * again. Mostly this just means scrolling up a few lines, so it | |
2013 * doesn't look too bad. Only do this for the current window (where | |
2014 * changes are relevant). | |
2015 */ | |
2016 wp->w_valid |= VALID_BOTLINE; | |
2017 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
2018 { | |
2019 recursive = TRUE; | |
2020 curwin->w_valid &= ~VALID_TOPLINE; | |
2021 update_topline(); /* may invalidate w_botline again */ | |
2022 if (must_redraw != 0) | |
2023 { | |
2024 /* Don't update for changes in buffer again. */ | |
2025 i = curbuf->b_mod_set; | |
2026 curbuf->b_mod_set = FALSE; | |
2027 win_update(curwin); | |
2028 must_redraw = 0; | |
2029 curbuf->b_mod_set = i; | |
2030 } | |
2031 recursive = FALSE; | |
2032 } | |
2033 } | |
2034 | |
2035 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
2036 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
2037 if (!got_int) | |
2038 got_int = save_got_int; | |
2039 #endif | |
2040 } | |
2041 | |
2042 #ifdef FEAT_SIGNS | |
2043 static int draw_signcolumn __ARGS((win_T *wp)); | |
2044 | |
2045 /* | |
2046 * Return TRUE when window "wp" has a column to draw signs in. | |
2047 */ | |
2048 static int | |
2049 draw_signcolumn(wp) | |
2050 win_T *wp; | |
2051 { | |
2052 return (wp->w_buffer->b_signlist != NULL | |
2053 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2054 || netbeans_active() |
7 | 2055 # endif |
2056 ); | |
2057 } | |
2058 #endif | |
2059 | |
2060 /* | |
2061 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2062 * as the filler character. | |
2063 */ | |
2064 static void | |
2065 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2066 win_T *wp; | |
2067 int c1; | |
2068 int c2; | |
2069 int row; | |
2070 int endrow; | |
534 | 2071 hlf_T hl; |
7 | 2072 { |
2073 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2074 int n = 0; | |
2075 # define FDC_OFF n | |
2076 #else | |
2077 # define FDC_OFF 0 | |
2078 #endif | |
2079 | |
2080 #ifdef FEAT_RIGHTLEFT | |
2081 if (wp->w_p_rl) | |
2082 { | |
2083 /* No check for cmdline window: should never be right-left. */ | |
2084 # ifdef FEAT_FOLDING | |
2085 n = wp->w_p_fdc; | |
2086 | |
2087 if (n > 0) | |
2088 { | |
2089 /* draw the fold column at the right */ | |
119 | 2090 if (n > W_WIDTH(wp)) |
2091 n = W_WIDTH(wp); | |
7 | 2092 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2093 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2094 ' ', ' ', hl_attr(HLF_FC)); | |
2095 } | |
2096 # endif | |
2097 # ifdef FEAT_SIGNS | |
2098 if (draw_signcolumn(wp)) | |
2099 { | |
2100 int nn = n + 2; | |
2101 | |
2102 /* draw the sign column left of the fold column */ | |
119 | 2103 if (nn > W_WIDTH(wp)) |
2104 nn = W_WIDTH(wp); | |
7 | 2105 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2106 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2107 ' ', ' ', hl_attr(HLF_SC)); | |
2108 n = nn; | |
2109 } | |
2110 # endif | |
2111 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2112 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2113 c2, c2, hl_attr(hl)); | |
2114 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2115 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2116 c1, c2, hl_attr(hl)); | |
2117 } | |
2118 else | |
2119 #endif | |
2120 { | |
2121 #ifdef FEAT_CMDWIN | |
2122 if (cmdwin_type != 0 && wp == curwin) | |
2123 { | |
2124 /* draw the cmdline character in the leftmost column */ | |
2125 n = 1; | |
2126 if (n > wp->w_width) | |
2127 n = wp->w_width; | |
2128 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2129 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2130 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2131 } | |
2132 #endif | |
2133 #ifdef FEAT_FOLDING | |
2134 if (wp->w_p_fdc > 0) | |
2135 { | |
2136 int nn = n + wp->w_p_fdc; | |
2137 | |
2138 /* draw the fold column at the left */ | |
2139 if (nn > W_WIDTH(wp)) | |
2140 nn = W_WIDTH(wp); | |
2141 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2142 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2143 ' ', ' ', hl_attr(HLF_FC)); | |
2144 n = nn; | |
2145 } | |
2146 #endif | |
2147 #ifdef FEAT_SIGNS | |
2148 if (draw_signcolumn(wp)) | |
2149 { | |
2150 int nn = n + 2; | |
2151 | |
2152 /* draw the sign column after the fold column */ | |
2153 if (nn > W_WIDTH(wp)) | |
2154 nn = W_WIDTH(wp); | |
2155 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2156 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2157 ' ', ' ', hl_attr(HLF_SC)); | |
2158 n = nn; | |
2159 } | |
2160 #endif | |
2161 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2162 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2163 c1, c2, hl_attr(hl)); | |
2164 } | |
2165 set_empty_rows(wp, row); | |
2166 } | |
2167 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2168 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2169 static int advance_color_col __ARGS((int vcol, int **color_cols)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2170 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2171 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2172 * Advance **color_cols and return TRUE when there are columns to draw. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2173 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2174 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2175 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2176 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2177 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2178 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2179 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2180 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2181 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2182 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2183 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2184 |
7 | 2185 #ifdef FEAT_FOLDING |
2186 /* | |
2187 * Display one folded line. | |
2188 */ | |
2189 static void | |
2190 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2191 win_T *wp; | |
2192 long fold_count; | |
2193 foldinfo_T *foldinfo; | |
2194 linenr_T lnum; | |
2195 int row; | |
2196 { | |
2197 char_u buf[51]; | |
2198 pos_T *top, *bot; | |
2199 linenr_T lnume = lnum + fold_count - 1; | |
2200 int len; | |
29 | 2201 char_u *text; |
7 | 2202 int fdc; |
2203 int col; | |
2204 int txtcol; | |
2205 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2206 int ri; |
7 | 2207 |
2208 /* Build the fold line: | |
2209 * 1. Add the cmdwin_type for the command-line window | |
2210 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2211 * 3. Add the 'number' or 'relativenumber' column |
7 | 2212 * 4. Compose the text |
2213 * 5. Add the text | |
2214 * 6. set highlighting for the Visual area an other text | |
2215 */ | |
2216 col = 0; | |
2217 | |
2218 /* | |
2219 * 1. Add the cmdwin_type for the command-line window | |
2220 * Ignores 'rightleft', this window is never right-left. | |
2221 */ | |
2222 #ifdef FEAT_CMDWIN | |
2223 if (cmdwin_type != 0 && wp == curwin) | |
2224 { | |
2225 ScreenLines[off] = cmdwin_type; | |
2226 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2227 #ifdef FEAT_MBYTE | |
2228 if (enc_utf8) | |
2229 ScreenLinesUC[off] = 0; | |
2230 #endif | |
2231 ++col; | |
2232 } | |
2233 #endif | |
2234 | |
2235 /* | |
2236 * 2. Add the 'foldcolumn' | |
2237 */ | |
2238 fdc = wp->w_p_fdc; | |
2239 if (fdc > W_WIDTH(wp) - col) | |
2240 fdc = W_WIDTH(wp) - col; | |
2241 if (fdc > 0) | |
2242 { | |
2243 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2244 #ifdef FEAT_RIGHTLEFT | |
2245 if (wp->w_p_rl) | |
2246 { | |
2247 int i; | |
2248 | |
2249 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2250 hl_attr(HLF_FC)); | |
2251 /* reverse the fold column */ | |
2252 for (i = 0; i < fdc; ++i) | |
2253 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2254 } | |
2255 else | |
2256 #endif | |
2257 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2258 col += fdc; | |
2259 } | |
2260 | |
2261 #ifdef FEAT_RIGHTLEFT | |
216 | 2262 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2263 for (ri = 0; ri < l; ++ri) \ | |
2264 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2265 else \ | |
2266 for (ri = 0; ri < l; ++ri) \ | |
2267 ScreenAttrs[off + (p) + ri] = v | |
7 | 2268 #else |
216 | 2269 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2270 ScreenAttrs[off + (p) + ri] = v | |
7 | 2271 #endif |
2272 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2273 /* 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
|
2274 * text */ |
216 | 2275 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2276 |
2277 #ifdef FEAT_SIGNS | |
2278 /* If signs are being displayed, add two spaces. */ | |
2279 if (draw_signcolumn(wp)) | |
2280 { | |
2281 len = W_WIDTH(wp) - col; | |
2282 if (len > 0) | |
2283 { | |
2284 if (len > 2) | |
2285 len = 2; | |
2286 # ifdef FEAT_RIGHTLEFT | |
2287 if (wp->w_p_rl) | |
2288 /* the line number isn't reversed */ | |
2289 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2290 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2291 else | |
2292 # endif | |
2293 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2294 col += len; | |
2295 } | |
2296 } | |
2297 #endif | |
2298 | |
2299 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2300 * 3. Add the 'number' or 'relativenumber' column |
7 | 2301 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2302 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2303 { |
2304 len = W_WIDTH(wp) - col; | |
2305 if (len > 0) | |
2306 { | |
13 | 2307 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2308 long num; |
13 | 2309 |
2310 if (len > w + 1) | |
2311 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2312 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2313 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2314 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2315 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2316 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2317 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2318 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
|
2319 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2320 sprintf((char *)buf, "%*ld ", w, num); |
7 | 2321 #ifdef FEAT_RIGHTLEFT |
2322 if (wp->w_p_rl) | |
2323 /* the line number isn't reversed */ | |
2324 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2325 hl_attr(HLF_FL)); | |
2326 else | |
2327 #endif | |
2328 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2329 col += len; | |
2330 } | |
2331 } | |
2332 | |
2333 /* | |
2334 * 4. Compose the folded-line string with 'foldtext', if set. | |
2335 */ | |
29 | 2336 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2337 |
2338 txtcol = col; /* remember where text starts */ | |
2339 | |
2340 /* | |
2341 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2342 * Right-left text is put in columns 0 - number-col, normal text is put | |
2343 * in columns number-col - window-width. | |
2344 */ | |
2345 #ifdef FEAT_MBYTE | |
2346 if (has_mbyte) | |
2347 { | |
2348 int cells; | |
714 | 2349 int u8c, u8cc[MAX_MCO]; |
2350 int i; | |
7 | 2351 int idx; |
2352 int c_len; | |
33 | 2353 char_u *p; |
7 | 2354 # ifdef FEAT_ARABIC |
2355 int prev_c = 0; /* previous Arabic character */ | |
2356 int prev_c1 = 0; /* first composing char for prev_c */ | |
2357 # endif | |
2358 | |
2359 # ifdef FEAT_RIGHTLEFT | |
2360 if (wp->w_p_rl) | |
2361 idx = off; | |
2362 else | |
2363 # endif | |
2364 idx = off + col; | |
2365 | |
2366 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2367 for (p = text; *p != NUL; ) | |
2368 { | |
2369 cells = (*mb_ptr2cells)(p); | |
474 | 2370 c_len = (*mb_ptr2len)(p); |
7 | 2371 if (col + cells > W_WIDTH(wp) |
2372 # ifdef FEAT_RIGHTLEFT | |
2373 - (wp->w_p_rl ? col : 0) | |
2374 # endif | |
2375 ) | |
2376 break; | |
2377 ScreenLines[idx] = *p; | |
2378 if (enc_utf8) | |
2379 { | |
714 | 2380 u8c = utfc_ptr2char(p, u8cc); |
2381 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2382 { |
2383 ScreenLinesUC[idx] = 0; | |
2384 #ifdef FEAT_ARABIC | |
2385 prev_c = u8c; | |
2386 #endif | |
2387 } | |
2388 else | |
2389 { | |
2390 #ifdef FEAT_ARABIC | |
2391 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2392 { | |
2393 /* Do Arabic shaping. */ | |
714 | 2394 int pc, pc1, nc; |
2395 int pcc[MAX_MCO]; | |
7 | 2396 int firstbyte = *p; |
2397 | |
2398 /* The idea of what is the previous and next | |
2399 * character depends on 'rightleft'. */ | |
2400 if (wp->w_p_rl) | |
2401 { | |
2402 pc = prev_c; | |
2403 pc1 = prev_c1; | |
2404 nc = utf_ptr2char(p + c_len); | |
714 | 2405 prev_c1 = u8cc[0]; |
7 | 2406 } |
2407 else | |
2408 { | |
714 | 2409 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2410 nc = prev_c; |
714 | 2411 pc1 = pcc[0]; |
7 | 2412 } |
2413 prev_c = u8c; | |
2414 | |
714 | 2415 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2416 pc, pc1, nc); |
2417 ScreenLines[idx] = firstbyte; | |
2418 } | |
2419 else | |
2420 prev_c = u8c; | |
2421 #endif | |
2422 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2423 #ifdef UNICODE16 |
7 | 2424 if (u8c >= 0x10000) |
2425 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2426 else | |
1401 | 2427 #endif |
7 | 2428 ScreenLinesUC[idx] = u8c; |
714 | 2429 for (i = 0; i < Screen_mco; ++i) |
2430 { | |
2431 ScreenLinesC[i][idx] = u8cc[i]; | |
2432 if (u8cc[i] == 0) | |
2433 break; | |
2434 } | |
7 | 2435 } |
2436 if (cells > 1) | |
2437 ScreenLines[idx + 1] = 0; | |
2438 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2439 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2440 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2441 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2442 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2443 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2444 ScreenLines[idx + 1] = p[1]; |
7 | 2445 col += cells; |
2446 idx += cells; | |
2447 p += c_len; | |
2448 } | |
2449 } | |
2450 else | |
2451 #endif | |
2452 { | |
2453 len = (int)STRLEN(text); | |
2454 if (len > W_WIDTH(wp) - col) | |
2455 len = W_WIDTH(wp) - col; | |
2456 if (len > 0) | |
2457 { | |
2458 #ifdef FEAT_RIGHTLEFT | |
2459 if (wp->w_p_rl) | |
2460 STRNCPY(current_ScreenLine, text, len); | |
2461 else | |
2462 #endif | |
2463 STRNCPY(current_ScreenLine + col, text, len); | |
2464 col += len; | |
2465 } | |
2466 } | |
2467 | |
2468 /* Fill the rest of the line with the fold filler */ | |
2469 #ifdef FEAT_RIGHTLEFT | |
2470 if (wp->w_p_rl) | |
2471 col -= txtcol; | |
2472 #endif | |
2473 while (col < W_WIDTH(wp) | |
2474 #ifdef FEAT_RIGHTLEFT | |
2475 - (wp->w_p_rl ? txtcol : 0) | |
2476 #endif | |
2477 ) | |
2478 { | |
2479 #ifdef FEAT_MBYTE | |
2480 if (enc_utf8) | |
2481 { | |
2482 if (fill_fold >= 0x80) | |
2483 { | |
2484 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2485 ScreenLinesC[0][off + col] = 0; |
7 | 2486 } |
2487 else | |
2488 ScreenLinesUC[off + col] = 0; | |
2489 } | |
2490 #endif | |
2491 ScreenLines[off + col++] = fill_fold; | |
2492 } | |
2493 | |
2494 if (text != buf) | |
2495 vim_free(text); | |
2496 | |
2497 /* | |
2498 * 6. set highlighting for the Visual area an other text. | |
2499 * If all folded lines are in the Visual area, highlight the line. | |
2500 */ | |
2501 #ifdef FEAT_VISUAL | |
2502 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2503 { | |
2504 if (ltoreq(curwin->w_cursor, VIsual)) | |
2505 { | |
2506 /* Visual is after curwin->w_cursor */ | |
2507 top = &curwin->w_cursor; | |
2508 bot = &VIsual; | |
2509 } | |
2510 else | |
2511 { | |
2512 /* Visual is before curwin->w_cursor */ | |
2513 top = &VIsual; | |
2514 bot = &curwin->w_cursor; | |
2515 } | |
2516 if (lnum >= top->lnum | |
2517 && lnume <= bot->lnum | |
2518 && (VIsual_mode != 'v' | |
2519 || ((lnum > top->lnum | |
2520 || (lnum == top->lnum | |
2521 && top->col == 0)) | |
2522 && (lnume < bot->lnum | |
2523 || (lnume == bot->lnum | |
2524 && (bot->col - (*p_sel == 'e')) | |
1883 | 2525 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2526 { |
2527 if (VIsual_mode == Ctrl_V) | |
2528 { | |
2529 /* Visual block mode: highlight the chars part of the block */ | |
2530 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2531 { | |
2532 if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2533 len = wp->w_old_cursor_lcol; | |
2534 else | |
2535 len = W_WIDTH(wp) - txtcol; | |
2536 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2537 len - (int)wp->w_old_cursor_fcol); |
7 | 2538 } |
2539 } | |
2540 else | |
216 | 2541 { |
7 | 2542 /* Set all attributes of the text */ |
216 | 2543 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2544 } | |
7 | 2545 } |
2546 } | |
2547 #endif | |
2548 | |
743 | 2549 #ifdef FEAT_SYN_HL |
2550 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2551 if (wp->w_p_cuc) |
2552 { | |
2553 txtcol += wp->w_virtcol; | |
2554 if (wp->w_p_wrap) | |
2555 txtcol -= wp->w_skipcol; | |
2556 else | |
2557 txtcol -= wp->w_leftcol; | |
2558 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2559 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2560 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2561 } | |
743 | 2562 #endif |
7 | 2563 |
2564 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2565 (int)W_WIDTH(wp), FALSE); | |
2566 | |
2567 /* | |
2568 * Update w_cline_height and w_cline_folded if the cursor line was | |
2569 * updated (saves a call to plines() later). | |
2570 */ | |
2571 if (wp == curwin | |
2572 && lnum <= curwin->w_cursor.lnum | |
2573 && lnume >= curwin->w_cursor.lnum) | |
2574 { | |
2575 curwin->w_cline_row = row; | |
2576 curwin->w_cline_height = 1; | |
2577 curwin->w_cline_folded = TRUE; | |
2578 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2579 } | |
2580 } | |
2581 | |
2582 /* | |
2583 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2584 */ | |
2585 static void | |
2586 copy_text_attr(off, buf, len, attr) | |
2587 int off; | |
2588 char_u *buf; | |
2589 int len; | |
2590 int attr; | |
2591 { | |
216 | 2592 int i; |
2593 | |
7 | 2594 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2595 # ifdef FEAT_MBYTE | |
2596 if (enc_utf8) | |
2597 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2598 # endif | |
216 | 2599 for (i = 0; i < len; ++i) |
2600 ScreenAttrs[off + i] = attr; | |
7 | 2601 } |
2602 | |
2603 /* | |
2604 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2605 * Only to be called when 'foldcolumn' > 0. |
7 | 2606 */ |
2607 static void | |
2608 fill_foldcolumn(p, wp, closed, lnum) | |
2609 char_u *p; | |
2610 win_T *wp; | |
2611 int closed; /* TRUE of FALSE */ | |
2612 linenr_T lnum; /* current line number */ | |
2613 { | |
2614 int i = 0; | |
2615 int level; | |
2616 int first_level; | |
519 | 2617 int empty; |
7 | 2618 |
2619 /* Init to all spaces. */ | |
2620 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2621 | |
2622 level = win_foldinfo.fi_level; | |
2623 if (level > 0) | |
2624 { | |
519 | 2625 /* If there is only one column put more info in it. */ |
2626 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2627 | |
7 | 2628 /* If the column is too narrow, we start at the lowest level that |
2629 * fits and use numbers to indicated the depth. */ | |
519 | 2630 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2631 if (first_level < 1) |
2632 first_level = 1; | |
2633 | |
519 | 2634 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2635 { |
2636 if (win_foldinfo.fi_lnum == lnum | |
2637 && first_level + i >= win_foldinfo.fi_low_level) | |
2638 p[i] = '-'; | |
2639 else if (first_level == 1) | |
2640 p[i] = '|'; | |
2641 else if (first_level + i <= 9) | |
2642 p[i] = '0' + first_level + i; | |
2643 else | |
2644 p[i] = '>'; | |
2645 if (first_level + i == level) | |
2646 break; | |
2647 } | |
2648 } | |
2649 if (closed) | |
548 | 2650 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2651 } |
2652 #endif /* FEAT_FOLDING */ | |
2653 | |
2654 /* | |
2655 * Display line "lnum" of window 'wp' on the screen. | |
2656 * Start at row "startrow", stop when "endrow" is reached. | |
2657 * wp->w_virtcol needs to be valid. | |
2658 * | |
2659 * Return the number of last row the line occupies. | |
2660 */ | |
2661 static int | |
625 | 2662 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2663 win_T *wp; |
2664 linenr_T lnum; | |
2665 int startrow; | |
2666 int endrow; | |
1883 | 2667 int nochange UNUSED; /* not updating for changed text */ |
7 | 2668 { |
2669 int col; /* visual column on screen */ | |
2670 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2671 int c = 0; /* init for GCC */ | |
2672 long vcol = 0; /* virtual column (for tabs) */ | |
2673 long vcol_prev = -1; /* "vcol" of previous character */ | |
2674 char_u *line; /* current line */ | |
2675 char_u *ptr; /* current position in "line" */ | |
2676 int row; /* row in the window, excl w_winrow */ | |
2677 int screen_row; /* row on the screen, incl w_winrow */ | |
2678 | |
2679 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2680 int n_extra = 0; /* number of extra chars */ | |
1340 | 2681 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2682 int c_extra = NUL; /* extra chars, all the same */ |
2683 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2684 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2685 displaying lcs_eol at end-of-line */ | |
2686 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2687 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2688 | |
2689 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2690 int saved_n_extra = 0; | |
2691 char_u *saved_p_extra = NULL; | |
2692 int saved_c_extra = 0; | |
2693 int saved_char_attr = 0; | |
2694 | |
2695 int n_attr = 0; /* chars with special attr */ | |
2696 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2697 int n_attr3 = 0; /* chars with overruling special attr */ | |
2698 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2699 | |
2700 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2701 | |
2702 int fromcol, tocol; /* start/end of inverting */ | |
2703 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2704 int noinvcur = FALSE; /* don't invert the cursor */ | |
2705 #ifdef FEAT_VISUAL | |
2706 pos_T *top, *bot; | |
1813 | 2707 int lnum_in_visual_area = FALSE; |
7 | 2708 #endif |
2709 pos_T pos; | |
2710 long v; | |
2711 | |
2712 int char_attr = 0; /* attributes for next character */ | |
674 | 2713 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2714 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2715 in this line */ | |
2716 int attr = 0; /* attributes for area highlighting */ | |
2717 int area_attr = 0; /* attributes desired by highlighting */ | |
2718 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2719 #ifdef FEAT_SYN_HL | |
743 | 2720 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2721 int syntax_attr = 0; /* attributes desired by syntax */ |
2722 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2723 int save_did_emsg; | |
1437 | 2724 int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2725 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2726 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2727 #endif |
2728 #ifdef FEAT_SPELL | |
221 | 2729 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2730 # define SPWORDLEN 150 |
2731 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2732 int nextlinecol = 0; /* column where nextline[] starts */ |
2733 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2734 starts */ |
221 | 2735 int spell_attr = 0; /* attributes desired by spelling */ |
2736 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2737 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2738 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2739 * there are no spell errors */ |
386 | 2740 static int cap_col = -1; /* column to check for Cap word */ |
2741 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2742 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2743 #endif |
2744 int extra_check; /* has syntax or linebreak */ | |
2745 #ifdef FEAT_MBYTE | |
2746 int multi_attr = 0; /* attributes desired by multibyte */ | |
2747 int mb_l = 1; /* multi-byte byte length */ | |
2748 int mb_c = 0; /* decoded multi-byte character */ | |
2749 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2750 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2751 #endif |
2752 #ifdef FEAT_DIFF | |
2753 int filler_lines; /* nr of filler lines to be drawn */ | |
2754 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2755 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2756 int change_start = MAXCOL; /* first col of changed area */ |
2757 int change_end = -1; /* last col of changed area */ | |
2758 #endif | |
2759 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2760 #ifdef FEAT_LINEBREAK | |
2761 int need_showbreak = FALSE; | |
2762 #endif | |
910 | 2763 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2764 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2765 # define LINE_ATTR |
1536 | 2766 int line_attr = 0; /* attribute for the whole line */ |
7 | 2767 #endif |
2768 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2769 matchitem_T *cur; /* points to the match list */ |
2770 match_T *shl; /* points to search_hl or a match */ | |
2771 int shl_flag; /* flag to indicate whether search_hl | |
2772 has been processed or not */ | |
2773 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2774 equals startcol of search_hl or one | |
2775 of the matches */ | |
7 | 2776 #endif |
2777 #ifdef FEAT_ARABIC | |
2778 int prev_c = 0; /* previous Arabic character */ | |
2779 int prev_c1 = 0; /* first composing char for prev_c */ | |
2780 #endif | |
910 | 2781 #if defined(LINE_ATTR) |
867 | 2782 int did_line_attr = 0; |
2783 #endif | |
7 | 2784 |
2785 /* draw_state: items that are drawn in sequence: */ | |
2786 #define WL_START 0 /* nothing done yet */ | |
2787 #ifdef FEAT_CMDWIN | |
2788 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2789 #else | |
2790 # define WL_CMDLINE WL_START | |
2791 #endif | |
2792 #ifdef FEAT_FOLDING | |
2793 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2794 #else | |
2795 # define WL_FOLD WL_CMDLINE | |
2796 #endif | |
2797 #ifdef FEAT_SIGNS | |
2798 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2799 #else | |
2800 # define WL_SIGN WL_FOLD /* column for signs */ | |
2801 #endif | |
2802 #define WL_NR WL_SIGN + 1 /* line number */ | |
2803 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2804 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2805 #else | |
2806 # define WL_SBR WL_NR | |
2807 #endif | |
2808 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2809 int draw_state = WL_START; /* what to draw next */ | |
574 | 2810 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2811 int feedback_col = 0; |
2812 int feedback_old_attr = -1; | |
2813 #endif | |
2814 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2815 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2816 int syntax_flags = 0; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
2817 int syntax_id = 0; |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
2818 int prev_syntax_id = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2819 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2820 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2821 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
|
2822 wrapping */ |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2823 int vcol_off = 0; /* offset for concealed characters */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2824 int did_wcol = FALSE; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2825 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2826 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2827 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2828 #endif |
7 | 2829 |
2830 if (startrow > endrow) /* past the end already! */ | |
2831 return startrow; | |
2832 | |
2833 row = startrow; | |
2834 screen_row = row + W_WINROW(wp); | |
2835 | |
2836 /* | |
2837 * To speed up the loop below, set extra_check when there is linebreak, | |
2838 * trailing white space and/or syntax processing to be done. | |
2839 */ | |
2840 #ifdef FEAT_LINEBREAK | |
2841 extra_check = wp->w_p_lbr; | |
2842 #else | |
2843 extra_check = 0; | |
2844 #endif | |
2845 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2846 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2847 { |
2848 /* Prepare for syntax highlighting in this line. When there is an | |
2849 * error, stop syntax highlighting. */ | |
2850 save_did_emsg = did_emsg; | |
2851 did_emsg = FALSE; | |
2852 syntax_start(wp, lnum); | |
2853 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2854 wp->w_s->b_syn_error = TRUE; |
7 | 2855 else |
2856 { | |
2857 did_emsg = save_did_emsg; | |
2858 has_syntax = TRUE; | |
2859 extra_check = TRUE; | |
2860 } | |
2861 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2862 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2863 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2864 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2865 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2866 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 2867 #endif |
2868 | |
2869 #ifdef FEAT_SPELL | |
258 | 2870 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2871 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2872 && 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
|
2873 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2874 { |
2875 /* Prepare for spell checking. */ | |
2876 has_spell = TRUE; | |
2877 extra_check = TRUE; | |
348 | 2878 |
2879 /* Get the start of the next line, so that words that wrap to the next | |
2880 * line are found too: "et<line-break>al.". | |
2881 * Trick: skip a few chars for C/shell/Vim comments */ | |
2882 nextline[SPWORDLEN] = NUL; | |
2883 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2884 { | |
2885 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2886 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2887 } | |
2888 | |
2889 /* When a word wrapped from the previous line the start of the current | |
2890 * line is valid. */ | |
2891 if (lnum == checked_lnum) | |
2892 cur_checked_col = checked_col; | |
2893 checked_lnum = 0; | |
386 | 2894 |
2895 /* When there was a sentence end in the previous line may require a | |
2896 * word starting with capital in this line. In line 1 always check | |
2897 * the first word. */ | |
2898 if (lnum != capcol_lnum) | |
2899 cap_col = -1; | |
2900 if (lnum == 1) | |
2901 cap_col = 0; | |
2902 capcol_lnum = 0; | |
221 | 2903 } |
7 | 2904 #endif |
2905 | |
2906 /* | |
2907 * handle visual active in this window | |
2908 */ | |
2909 fromcol = -10; | |
2910 tocol = MAXCOL; | |
2911 #ifdef FEAT_VISUAL | |
2912 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2913 { | |
2914 /* Visual is after curwin->w_cursor */ | |
2915 if (ltoreq(curwin->w_cursor, VIsual)) | |
2916 { | |
2917 top = &curwin->w_cursor; | |
2918 bot = &VIsual; | |
2919 } | |
2920 else /* Visual is before curwin->w_cursor */ | |
2921 { | |
2922 top = &VIsual; | |
2923 bot = &curwin->w_cursor; | |
2924 } | |
1813 | 2925 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2926 if (VIsual_mode == Ctrl_V) /* block mode */ |
2927 { | |
1813 | 2928 if (lnum_in_visual_area) |
7 | 2929 { |
2930 fromcol = wp->w_old_cursor_fcol; | |
2931 tocol = wp->w_old_cursor_lcol; | |
2932 } | |
2933 } | |
2934 else /* non-block mode */ | |
2935 { | |
2936 if (lnum > top->lnum && lnum <= bot->lnum) | |
2937 fromcol = 0; | |
2938 else if (lnum == top->lnum) | |
2939 { | |
2940 if (VIsual_mode == 'V') /* linewise */ | |
2941 fromcol = 0; | |
2942 else | |
2943 { | |
2944 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2945 if (gchar_pos(top) == NUL) | |
2946 tocol = fromcol + 1; | |
2947 } | |
2948 } | |
2949 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2950 { | |
2951 if (*p_sel == 'e' && bot->col == 0 | |
2952 #ifdef FEAT_VIRTUALEDIT | |
2953 && bot->coladd == 0 | |
2954 #endif | |
2955 ) | |
2956 { | |
2957 fromcol = -10; | |
2958 tocol = MAXCOL; | |
2959 } | |
36 | 2960 else if (bot->col == MAXCOL) |
2961 tocol = MAXCOL; | |
7 | 2962 else |
2963 { | |
2964 pos = *bot; | |
2965 if (*p_sel == 'e') | |
2966 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2967 else | |
2968 { | |
2969 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2970 ++tocol; | |
2971 } | |
2972 } | |
2973 } | |
2974 } | |
2975 | |
2976 #ifndef MSDOS | |
2977 /* Check if the character under the cursor should not be inverted */ | |
2978 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2979 # ifdef FEAT_GUI | |
2980 && !gui.in_use | |
2981 # endif | |
2982 ) | |
2983 noinvcur = TRUE; | |
2984 #endif | |
2985 | |
2986 /* if inverting in this line set area_highlighting */ | |
2987 if (fromcol >= 0) | |
2988 { | |
2989 area_highlighting = TRUE; | |
2990 attr = hl_attr(HLF_V); | |
2991 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2992 if (clip_star.available && !clip_star.owned && clip_isautosel()) | |
2993 attr = hl_attr(HLF_VNC); | |
2994 #endif | |
2995 } | |
2996 } | |
2997 | |
2998 /* | |
674 | 2999 * handle 'incsearch' and ":s///c" highlighting |
7 | 3000 */ |
3001 else | |
3002 #endif /* FEAT_VISUAL */ | |
3003 if (highlight_match | |
3004 && wp == curwin | |
3005 && lnum >= curwin->w_cursor.lnum | |
3006 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
3007 { | |
3008 if (lnum == curwin->w_cursor.lnum) | |
3009 getvcol(curwin, &(curwin->w_cursor), | |
3010 (colnr_T *)&fromcol, NULL, NULL); | |
3011 else | |
3012 fromcol = 0; | |
3013 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
3014 { | |
3015 pos.lnum = lnum; | |
3016 pos.col = search_match_endcol; | |
3017 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3018 } | |
3019 else | |
3020 tocol = MAXCOL; | |
1850 | 3021 /* do at least one character; happens when past end of line */ |
3022 if (fromcol == tocol) | |
3023 tocol = fromcol + 1; | |
7 | 3024 area_highlighting = TRUE; |
3025 attr = hl_attr(HLF_I); | |
3026 } | |
3027 | |
3028 #ifdef FEAT_DIFF | |
3029 filler_lines = diff_check(wp, lnum); | |
3030 if (filler_lines < 0) | |
3031 { | |
3032 if (filler_lines == -1) | |
3033 { | |
3034 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
3035 diff_hlf = HLF_ADD; /* added line */ | |
3036 else if (change_start == 0) | |
3037 diff_hlf = HLF_TXD; /* changed text */ | |
3038 else | |
3039 diff_hlf = HLF_CHD; /* changed line */ | |
3040 } | |
3041 else | |
3042 diff_hlf = HLF_ADD; /* added line */ | |
3043 filler_lines = 0; | |
3044 area_highlighting = TRUE; | |
3045 } | |
3046 if (lnum == wp->w_topline) | |
3047 filler_lines = wp->w_topfill; | |
3048 filler_todo = filler_lines; | |
3049 #endif | |
3050 | |
3051 #ifdef LINE_ATTR | |
3052 # ifdef FEAT_SIGNS | |
3053 /* If this line has a sign with line highlighting set line_attr. */ | |
3054 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3055 if (v != 0) | |
3056 line_attr = sign_get_attr((int)v, TRUE); | |
3057 # endif | |
3058 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3059 /* Highlight the current line in the quickfix window. */ | |
644 | 3060 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3061 line_attr = hl_attr(HLF_L); |
3062 # endif | |
3063 if (line_attr != 0) | |
3064 area_highlighting = TRUE; | |
3065 #endif | |
3066 | |
3067 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3068 ptr = line; | |
3069 | |
743 | 3070 #ifdef FEAT_SPELL |
348 | 3071 if (has_spell) |
3072 { | |
386 | 3073 /* For checking first word with a capital skip white space. */ |
3074 if (cap_col == 0) | |
835 | 3075 cap_col = (int)(skipwhite(line) - line); |
386 | 3076 |
348 | 3077 /* To be able to spell-check over line boundaries copy the end of the |
3078 * current line into nextline[]. Above the start of the next line was | |
3079 * copied to nextline[SPWORDLEN]. */ | |
3080 if (nextline[SPWORDLEN] == NUL) | |
3081 { | |
3082 /* No next line or it is empty. */ | |
3083 nextlinecol = MAXCOL; | |
3084 nextline_idx = 0; | |
3085 } | |
3086 else | |
3087 { | |
835 | 3088 v = (long)STRLEN(line); |
348 | 3089 if (v < SPWORDLEN) |
3090 { | |
3091 /* Short line, use it completely and append the start of the | |
3092 * next line. */ | |
3093 nextlinecol = 0; | |
3094 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3095 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3096 nextline_idx = v + 1; |
3097 } | |
3098 else | |
3099 { | |
3100 /* Long line, use only the last SPWORDLEN bytes. */ | |
3101 nextlinecol = v - SPWORDLEN; | |
3102 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3103 nextline_idx = SPWORDLEN + 1; | |
3104 } | |
3105 } | |
3106 } | |
3107 #endif | |
3108 | |
7 | 3109 /* find start of trailing whitespace */ |
3110 if (wp->w_p_list && lcs_trail) | |
3111 { | |
3112 trailcol = (colnr_T)STRLEN(ptr); | |
3113 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3114 --trailcol; | |
3115 trailcol += (colnr_T) (ptr - line); | |
3116 extra_check = TRUE; | |
3117 } | |
3118 | |
3119 /* | |
3120 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3121 * first character to be displayed. | |
3122 */ | |
3123 if (wp->w_p_wrap) | |
3124 v = wp->w_skipcol; | |
3125 else | |
3126 v = wp->w_leftcol; | |
3127 if (v > 0) | |
3128 { | |
3129 #ifdef FEAT_MBYTE | |
3130 char_u *prev_ptr = ptr; | |
3131 #endif | |
3132 while (vcol < v && *ptr != NUL) | |
3133 { | |
3134 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3135 vcol += c; | |
3136 #ifdef FEAT_MBYTE | |
3137 prev_ptr = ptr; | |
39 | 3138 #endif |
3139 mb_ptr_adv(ptr); | |
7 | 3140 } |
3141 | |
1984 | 3142 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3143 /* When: | |
3144 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3145 * - 'colorcolumn' is set, or |
1984 | 3146 * - 'virtualedit' is set, or |
3147 * - the visual mode is active, | |
3148 * the end of the line may be before the start of the displayed part. | |
3149 */ | |
3150 if (vcol < v && ( | |
3151 # ifdef FEAT_SYN_HL | |
3152 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3153 || draw_color_col |
1984 | 3154 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3155 || | |
3156 # endif | |
3157 # endif | |
3158 # ifdef FEAT_VIRTUALEDIT | |
3159 virtual_active() | |
3160 # ifdef FEAT_VISUAL | |
3161 || | |
3162 # endif | |
3163 # endif | |
3164 # ifdef FEAT_VISUAL | |
3165 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3166 # endif | |
3167 )) | |
3168 { | |
7 | 3169 vcol = v; |
1984 | 3170 } |
7 | 3171 #endif |
3172 | |
3173 /* Handle a character that's not completely on the screen: Put ptr at | |
3174 * that character but skip the first few screen characters. */ | |
3175 if (vcol > v) | |
3176 { | |
3177 vcol -= c; | |
3178 #ifdef FEAT_MBYTE | |
3179 ptr = prev_ptr; | |
3180 #else | |
3181 --ptr; | |
3182 #endif | |
3183 n_skip = v - vcol; | |
3184 } | |
3185 | |
3186 /* | |
3187 * Adjust for when the inverted text is before the screen, | |
3188 * and when the start of the inverted text is before the screen. | |
3189 */ | |
3190 if (tocol <= vcol) | |
3191 fromcol = 0; | |
3192 else if (fromcol >= 0 && fromcol < vcol) | |
3193 fromcol = vcol; | |
3194 | |
3195 #ifdef FEAT_LINEBREAK | |
3196 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3197 if (wp->w_p_wrap) | |
3198 need_showbreak = TRUE; | |
3199 #endif | |
743 | 3200 #ifdef FEAT_SPELL |
499 | 3201 /* When spell checking a word we need to figure out the start of the |
3202 * word and if it's badly spelled or not. */ | |
3203 if (has_spell) | |
3204 { | |
3205 int len; | |
1536 | 3206 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3207 hlf_T spell_hlf = HLF_COUNT; |
499 | 3208 |
3209 pos = wp->w_cursor; | |
3210 wp->w_cursor.lnum = lnum; | |
1536 | 3211 wp->w_cursor.col = linecol; |
534 | 3212 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3213 |
3214 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3215 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3216 ptr = line + linecol; | |
3217 | |
530 | 3218 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3219 { |
3220 /* no bad word found at line start, don't check until end of a | |
3221 * word */ | |
534 | 3222 spell_hlf = HLF_COUNT; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3223 word_end = (int)(spell_to_word_end(ptr, wp) |
1536 | 3224 - line + 1); |
499 | 3225 } |
3226 else | |
534 | 3227 { |
499 | 3228 /* bad word found, use attributes until end of word */ |
3229 word_end = wp->w_cursor.col + len + 1; | |
3230 | |
534 | 3231 /* Turn index into actual attributes. */ |
3232 if (spell_hlf != HLF_COUNT) | |
3233 spell_attr = highlight_attr[spell_hlf]; | |
3234 } | |
499 | 3235 wp->w_cursor = pos; |
501 | 3236 |
743 | 3237 # ifdef FEAT_SYN_HL |
501 | 3238 /* Need to restart syntax highlighting for this line. */ |
3239 if (has_syntax) | |
3240 syntax_start(wp, lnum); | |
743 | 3241 # endif |
499 | 3242 } |
3243 #endif | |
7 | 3244 } |
3245 | |
3246 /* | |
3247 * Correct highlighting for cursor that can't be disabled. | |
3248 * Avoids having to check this for each character. | |
3249 */ | |
3250 if (fromcol >= 0) | |
3251 { | |
3252 if (noinvcur) | |
3253 { | |
3254 if ((colnr_T)fromcol == wp->w_virtcol) | |
3255 { | |
3256 /* highlighting starts at cursor, let it start just after the | |
3257 * cursor */ | |
3258 fromcol_prev = fromcol; | |
3259 fromcol = -1; | |
3260 } | |
3261 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3262 /* restart highlighting after the cursor */ | |
3263 fromcol_prev = wp->w_virtcol; | |
3264 } | |
3265 if (fromcol >= tocol) | |
3266 fromcol = -1; | |
3267 } | |
3268 | |
3269 #ifdef FEAT_SEARCH_EXTRA | |
3270 /* | |
1326 | 3271 * Handle highlighting the last used search pattern and matches. |
3272 * Do this for both search_hl and the match list. | |
7 | 3273 */ |
1326 | 3274 cur = wp->w_match_head; |
3275 shl_flag = FALSE; | |
3276 while (cur != NULL || shl_flag == FALSE) | |
3277 { | |
3278 if (shl_flag == FALSE) | |
3279 { | |
3280 shl = &search_hl; | |
3281 shl_flag = TRUE; | |
3282 } | |
3283 else | |
3284 shl = &cur->hl; | |
36 | 3285 shl->startcol = MAXCOL; |
3286 shl->endcol = MAXCOL; | |
7 | 3287 shl->attr_cur = 0; |
3288 if (shl->rm.regprog != NULL) | |
3289 { | |
3290 v = (long)(ptr - line); | |
3291 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3292 | |
3293 /* Need to get the line again, a multi-line regexp may have made it | |
3294 * invalid. */ | |
3295 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3296 ptr = line + v; | |
3297 | |
3298 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3299 { | |
3300 if (shl->lnum == lnum) | |
36 | 3301 shl->startcol = shl->rm.startpos[0].col; |
7 | 3302 else |
36 | 3303 shl->startcol = 0; |
7 | 3304 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3305 - shl->rm.startpos[0].lnum) | |
36 | 3306 shl->endcol = shl->rm.endpos[0].col; |
7 | 3307 else |
36 | 3308 shl->endcol = MAXCOL; |
7 | 3309 /* Highlight one character for an empty match. */ |
36 | 3310 if (shl->startcol == shl->endcol) |
7 | 3311 { |
3312 #ifdef FEAT_MBYTE | |
36 | 3313 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3314 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3315 else |
3316 #endif | |
36 | 3317 ++shl->endcol; |
7 | 3318 } |
36 | 3319 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3320 { |
3321 shl->attr_cur = shl->attr; | |
3322 search_attr = shl->attr; | |
3323 } | |
3324 area_highlighting = TRUE; | |
3325 } | |
3326 } | |
1326 | 3327 if (shl != &search_hl && cur != NULL) |
3328 cur = cur->next; | |
7 | 3329 } |
3330 #endif | |
3331 | |
743 | 3332 #ifdef FEAT_SYN_HL |
818 | 3333 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3334 * active, because it's not clear what is selected then. */ | |
3335 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3336 { |
3337 line_attr = hl_attr(HLF_CUL); | |
3338 area_highlighting = TRUE; | |
3339 } | |
3340 #endif | |
3341 | |
504 | 3342 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3343 col = 0; |
3344 #ifdef FEAT_RIGHTLEFT | |
3345 if (wp->w_p_rl) | |
3346 { | |
3347 /* Rightleft window: process the text in the normal direction, but put | |
3348 * it in current_ScreenLine[] from right to left. Start at the | |
3349 * rightmost column of the window. */ | |
3350 col = W_WIDTH(wp) - 1; | |
3351 off += col; | |
3352 } | |
3353 #endif | |
3354 | |
3355 /* | |
3356 * Repeat for the whole displayed line. | |
3357 */ | |
3358 for (;;) | |
3359 { | |
3360 /* Skip this quickly when working on the text. */ | |
3361 if (draw_state != WL_LINE) | |
3362 { | |
3363 #ifdef FEAT_CMDWIN | |
3364 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3365 { | |
3366 draw_state = WL_CMDLINE; | |
3367 if (cmdwin_type != 0 && wp == curwin) | |
3368 { | |
3369 /* Draw the cmdline character. */ | |
3370 n_extra = 1; | |
1340 | 3371 c_extra = cmdwin_type; |
7 | 3372 char_attr = hl_attr(HLF_AT); |
3373 } | |
3374 } | |
3375 #endif | |
3376 | |
3377 #ifdef FEAT_FOLDING | |
3378 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3379 { | |
3380 draw_state = WL_FOLD; | |
3381 if (wp->w_p_fdc > 0) | |
3382 { | |
3383 /* Draw the 'foldcolumn'. */ | |
3384 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3385 n_extra = wp->w_p_fdc; | |
3386 p_extra = extra; | |
1340 | 3387 p_extra[n_extra] = NUL; |
7 | 3388 c_extra = NUL; |
3389 char_attr = hl_attr(HLF_FC); | |
3390 } | |
3391 } | |
3392 #endif | |
3393 | |
3394 #ifdef FEAT_SIGNS | |
3395 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3396 { | |
3397 draw_state = WL_SIGN; | |
3398 /* Show the sign column when there are any signs in this | |
3399 * buffer or when using Netbeans. */ | |
3400 if (draw_signcolumn(wp) | |
3401 # ifdef FEAT_DIFF | |
3402 && filler_todo <= 0 | |
3403 # endif | |
3404 ) | |
3405 { | |
3406 int_u text_sign; | |
3407 # ifdef FEAT_SIGN_ICONS | |
3408 int_u icon_sign; | |
3409 # endif | |
3410 | |
3411 /* Draw two cells with the sign value or blank. */ | |
3412 c_extra = ' '; | |
3413 char_attr = hl_attr(HLF_SC); | |
3414 n_extra = 2; | |
3415 | |
3416 if (row == startrow) | |
3417 { | |
3418 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3419 SIGN_TEXT); | |
3420 # ifdef FEAT_SIGN_ICONS | |
3421 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3422 SIGN_ICON); | |
3423 if (gui.in_use && icon_sign != 0) | |
3424 { | |
3425 /* Use the image in this position. */ | |
3426 c_extra = SIGN_BYTE; | |
3427 # ifdef FEAT_NETBEANS_INTG | |
3428 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3429 c_extra = MULTISIGN_BYTE; | |
3430 # endif | |
3431 char_attr = icon_sign; | |
3432 } | |
3433 else | |
3434 # endif | |
3435 if (text_sign != 0) | |
3436 { | |
3437 p_extra = sign_get_text(text_sign); | |
3438 if (p_extra != NULL) | |
3439 { | |
3440 c_extra = NUL; | |
835 | 3441 n_extra = (int)STRLEN(p_extra); |
7 | 3442 } |
3443 char_attr = sign_get_attr(text_sign, FALSE); | |
3444 } | |
3445 } | |
3446 } | |
3447 } | |
3448 #endif | |
3449 | |
3450 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3451 { | |
3452 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3453 /* 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
|
3454 * 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
|
3455 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3456 && (row == startrow |
3457 #ifdef FEAT_DIFF | |
3458 + filler_lines | |
3459 #endif | |
3460 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3461 { | |
3462 /* Draw the line number (empty space after wrapping). */ | |
3463 if (row == startrow | |
3464 #ifdef FEAT_DIFF | |
3465 + filler_lines | |
3466 #endif | |
3467 ) | |
3468 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3469 long num; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3470 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3471 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3472 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3473 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3474 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3475 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3476 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
|
3477 lnum)); |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3478 |
13 | 3479 sprintf((char *)extra, "%*ld ", |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3480 number_width(wp), num); |
7 | 3481 if (wp->w_skipcol > 0) |
3482 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3483 *p_extra = '-'; | |
3484 #ifdef FEAT_RIGHTLEFT | |
3485 if (wp->w_p_rl) /* reverse line numbers */ | |
3486 rl_mirror(extra); | |
3487 #endif | |
3488 p_extra = extra; | |
3489 c_extra = NUL; | |
3490 } | |
3491 else | |
3492 c_extra = ' '; | |
13 | 3493 n_extra = number_width(wp) + 1; |
7 | 3494 char_attr = hl_attr(HLF_N); |
743 | 3495 #ifdef FEAT_SYN_HL |
3496 /* When 'cursorline' is set highlight the line number of | |
3497 * the current line differently. */ | |
3498 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) | |
3499 char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); | |
3500 #endif | |
7 | 3501 } |
3502 } | |
3503 | |
3504 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3505 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3506 { | |
3507 draw_state = WL_SBR; | |
3508 # ifdef FEAT_DIFF | |
3509 if (filler_todo > 0) | |
3510 { | |
3511 /* Draw "deleted" diff line(s). */ | |
3512 if (char2cells(fill_diff) > 1) | |
3513 c_extra = '-'; | |
3514 else | |
3515 c_extra = fill_diff; | |
3516 # ifdef FEAT_RIGHTLEFT | |
3517 if (wp->w_p_rl) | |
3518 n_extra = col + 1; | |
3519 else | |
3520 # endif | |
3521 n_extra = W_WIDTH(wp) - col; | |
3522 char_attr = hl_attr(HLF_DED); | |
3523 } | |
3524 # endif | |
3525 # ifdef FEAT_LINEBREAK | |
3526 if (*p_sbr != NUL && need_showbreak) | |
3527 { | |
3528 /* Draw 'showbreak' at the start of each broken line. */ | |
3529 p_extra = p_sbr; | |
3530 c_extra = NUL; | |
3531 n_extra = (int)STRLEN(p_sbr); | |
3532 char_attr = hl_attr(HLF_AT); | |
3533 need_showbreak = FALSE; | |
3534 /* Correct end of highlighted area for 'showbreak', | |
3535 * required when 'linebreak' is also set. */ | |
3536 if (tocol == vcol) | |
3537 tocol += n_extra; | |
3538 } | |
3539 # endif | |
3540 } | |
3541 #endif | |
3542 | |
3543 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3544 { | |
3545 draw_state = WL_LINE; | |
3546 if (saved_n_extra) | |
3547 { | |
3548 /* Continue item from end of wrapped line. */ | |
3549 n_extra = saved_n_extra; | |
3550 c_extra = saved_c_extra; | |
3551 p_extra = saved_p_extra; | |
3552 char_attr = saved_char_attr; | |
3553 } | |
3554 else | |
3555 char_attr = 0; | |
3556 } | |
3557 } | |
3558 | |
3559 /* When still displaying '$' of change command, stop at cursor */ | |
819 | 3560 if (dollar_vcol != 0 && wp == curwin |
3561 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol | |
7 | 3562 #ifdef FEAT_DIFF |
3563 && filler_todo <= 0 | |
3564 #endif | |
3565 ) | |
3566 { | |
3567 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3568 wp->w_p_rl); | |
819 | 3569 /* Pretend we have finished updating the window. Except when |
3570 * 'cursorcolumn' is set. */ | |
3571 #ifdef FEAT_SYN_HL | |
3572 if (wp->w_p_cuc) | |
3573 row = wp->w_cline_row + wp->w_cline_height; | |
3574 else | |
3575 #endif | |
3576 row = wp->w_height; | |
7 | 3577 break; |
3578 } | |
3579 | |
3580 if (draw_state == WL_LINE && area_highlighting) | |
3581 { | |
3582 /* handle Visual or match highlighting in this line */ | |
3583 if (vcol == fromcol | |
3584 #ifdef FEAT_MBYTE | |
3585 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3586 && (*mb_ptr2cells)(ptr) > 1) | |
3587 #endif | |
3588 || ((int)vcol_prev == fromcol_prev | |
1814 | 3589 && vcol_prev < vcol /* not at margin */ |
7 | 3590 && vcol < tocol)) |
3591 area_attr = attr; /* start highlighting */ | |
3592 else if (area_attr != 0 | |
3593 && (vcol == tocol | |
3594 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3595 area_attr = 0; /* stop highlighting */ | |
3596 | |
3597 #ifdef FEAT_SEARCH_EXTRA | |
3598 if (!n_extra) | |
3599 { | |
3600 /* | |
3601 * Check for start/end of search pattern match. | |
3602 * After end, check for start/end of next match. | |
3603 * When another match, have to check for start again. | |
3604 * Watch out for matching an empty string! | |
1326 | 3605 * Do this for 'search_hl' and the match list (ordered by |
3606 * priority). | |
7 | 3607 */ |
36 | 3608 v = (long)(ptr - line); |
1326 | 3609 cur = wp->w_match_head; |
3610 shl_flag = FALSE; | |
3611 while (cur != NULL || shl_flag == FALSE) | |
3612 { | |
3613 if (shl_flag == FALSE | |
3614 && ((cur != NULL | |
3615 && cur->priority > SEARCH_HL_PRIORITY) | |
3616 || cur == NULL)) | |
3617 { | |
3618 shl = &search_hl; | |
3619 shl_flag = TRUE; | |
3620 } | |
3621 else | |
3622 shl = &cur->hl; | |
7 | 3623 while (shl->rm.regprog != NULL) |
3624 { | |
36 | 3625 if (shl->startcol != MAXCOL |
3626 && v >= (long)shl->startcol | |
3627 && v < (long)shl->endcol) | |
7 | 3628 { |
3629 shl->attr_cur = shl->attr; | |
3630 } | |
36 | 3631 else if (v == (long)shl->endcol) |
7 | 3632 { |
3633 shl->attr_cur = 0; | |
3634 | |
3635 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3636 | |
3637 /* Need to get the line again, a multi-line regexp | |
3638 * may have made it invalid. */ | |
3639 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3640 ptr = line + v; | |
3641 | |
3642 if (shl->lnum == lnum) | |
3643 { | |
36 | 3644 shl->startcol = shl->rm.startpos[0].col; |
7 | 3645 if (shl->rm.endpos[0].lnum == 0) |
36 | 3646 shl->endcol = shl->rm.endpos[0].col; |
7 | 3647 else |
36 | 3648 shl->endcol = MAXCOL; |
3649 | |
3650 if (shl->startcol == shl->endcol) | |
7 | 3651 { |
3652 /* highlight empty match, try again after | |
3653 * it */ | |
3654 #ifdef FEAT_MBYTE | |
3655 if (has_mbyte) | |
474 | 3656 shl->endcol += (*mb_ptr2len)(line |
36 | 3657 + shl->endcol); |
7 | 3658 else |
3659 #endif | |
36 | 3660 ++shl->endcol; |
7 | 3661 } |
3662 | |
3663 /* Loop to check if the match starts at the | |
3664 * current position */ | |
3665 continue; | |
3666 } | |
3667 } | |
3668 break; | |
3669 } | |
1326 | 3670 if (shl != &search_hl && cur != NULL) |
3671 cur = cur->next; | |
3672 } | |
3673 | |
3674 /* Use attributes from match with highest priority among | |
3675 * 'search_hl' and the match list. */ | |
3676 search_attr = search_hl.attr_cur; | |
3677 cur = wp->w_match_head; | |
3678 shl_flag = FALSE; | |
3679 while (cur != NULL || shl_flag == FALSE) | |
3680 { | |
3681 if (shl_flag == FALSE | |
3682 && ((cur != NULL | |
3683 && cur->priority > SEARCH_HL_PRIORITY) | |
3684 || cur == NULL)) | |
699 | 3685 { |
1326 | 3686 shl = &search_hl; |
3687 shl_flag = TRUE; | |
699 | 3688 } |
1326 | 3689 else |
3690 shl = &cur->hl; | |
3691 if (shl->attr_cur != 0) | |
3692 search_attr = shl->attr_cur; | |
3693 if (shl != &search_hl && cur != NULL) | |
3694 cur = cur->next; | |
3695 } | |
7 | 3696 } |
3697 #endif | |
3698 | |
3699 #ifdef FEAT_DIFF | |
674 | 3700 if (diff_hlf != (hlf_T)0) |
7 | 3701 { |
1295 | 3702 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3703 && n_extra == 0) | |
7 | 3704 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3705 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3706 && n_extra == 0) | |
7 | 3707 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3708 line_attr = hl_attr(diff_hlf); |
3709 } | |
3710 #endif | |
3711 | |
3712 /* Decide which of the highlight attributes to use. */ | |
3713 attr_pri = TRUE; | |
3714 if (area_attr != 0) | |
3715 char_attr = area_attr; | |
3716 else if (search_attr != 0) | |
3717 char_attr = search_attr; | |
3718 #ifdef LINE_ATTR | |
3719 /* Use line_attr when not in the Visual or 'incsearch' area | |
3720 * (area_attr may be 0 when "noinvcur" is set). */ | |
3721 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3722 || vcol < fromcol || vcol_prev < fromcol_prev |
3723 || vcol >= tocol)) | |
674 | 3724 char_attr = line_attr; |
3725 #endif | |
3726 else | |
3727 { | |
3728 attr_pri = FALSE; | |
3729 #ifdef FEAT_SYN_HL | |
3730 if (has_syntax) | |
3731 char_attr = syntax_attr; | |
3732 else | |
3733 #endif | |
3734 char_attr = 0; | |
3735 } | |
7 | 3736 } |
3737 | |
3738 /* | |
3739 * Get the next character to put on the screen. | |
3740 */ | |
3741 /* | |
1340 | 3742 * The "p_extra" points to the extra stuff that is inserted to |
3743 * represent special characters (non-printable stuff) and other | |
3744 * things. When all characters are the same, c_extra is used. | |
3745 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3746 * "p_extra[n_extra]". | |
7 | 3747 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3748 */ | |
3749 if (n_extra > 0) | |
3750 { | |
3751 if (c_extra != NUL) | |
3752 { | |
3753 c = c_extra; | |
3754 #ifdef FEAT_MBYTE | |
3755 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3756 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3757 { | |
3758 mb_utf8 = TRUE; | |
714 | 3759 u8cc[0] = 0; |
819 | 3760 c = 0xc0; |
7 | 3761 } |
3762 else | |
3763 mb_utf8 = FALSE; | |
3764 #endif | |
3765 } | |
3766 else | |
3767 { | |
3768 c = *p_extra; | |
3769 #ifdef FEAT_MBYTE | |
3770 if (has_mbyte) | |
3771 { | |
3772 mb_c = c; | |
3773 if (enc_utf8) | |
3774 { | |
3775 /* If the UTF-8 character is more than one byte: | |
3776 * Decode it into "mb_c". */ | |
474 | 3777 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3778 mb_utf8 = FALSE; |
3779 if (mb_l > n_extra) | |
3780 mb_l = 1; | |
3781 else if (mb_l > 1) | |
3782 { | |
714 | 3783 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3784 mb_utf8 = TRUE; |
819 | 3785 c = 0xc0; |
7 | 3786 } |
3787 } | |
3788 else | |
3789 { | |
3790 /* if this is a DBCS character, put it in "mb_c" */ | |
3791 mb_l = MB_BYTE2LEN(c); | |
3792 if (mb_l >= n_extra) | |
3793 mb_l = 1; | |
3794 else if (mb_l > 1) | |
3795 mb_c = (c << 8) + p_extra[1]; | |
3796 } | |
504 | 3797 if (mb_l == 0) /* at the NUL at end-of-line */ |
3798 mb_l = 1; | |
3799 | |
7 | 3800 /* If a double-width char doesn't fit display a '>' in the |
3801 * last column. */ | |
504 | 3802 if (( |
7 | 3803 # ifdef FEAT_RIGHTLEFT |
3804 wp->w_p_rl ? (col <= 0) : | |
3805 # endif | |
504 | 3806 (col >= W_WIDTH(wp) - 1)) |
7 | 3807 && (*mb_char2cells)(mb_c) == 2) |
3808 { | |
3809 c = '>'; | |
3810 mb_c = c; | |
3811 mb_l = 1; | |
3812 mb_utf8 = FALSE; | |
3813 multi_attr = hl_attr(HLF_AT); | |
3814 /* put the pointer back to output the double-width | |
3815 * character at the start of the next line. */ | |
3816 ++n_extra; | |
3817 --p_extra; | |
3818 } | |
3819 else | |
3820 { | |
3821 n_extra -= mb_l - 1; | |
3822 p_extra += mb_l - 1; | |
3823 } | |
3824 } | |
3825 #endif | |
3826 ++p_extra; | |
3827 } | |
3828 --n_extra; | |
3829 } | |
3830 else | |
3831 { | |
3832 /* | |
3833 * Get a character from the line itself. | |
3834 */ | |
3835 c = *ptr; | |
3836 #ifdef FEAT_MBYTE | |
3837 if (has_mbyte) | |
3838 { | |
3839 mb_c = c; | |
3840 if (enc_utf8) | |
3841 { | |
3842 /* If the UTF-8 character is more than one byte: Decode it | |
3843 * into "mb_c". */ | |
474 | 3844 mb_l = (*mb_ptr2len)(ptr); |
7 | 3845 mb_utf8 = FALSE; |
3846 if (mb_l > 1) | |
3847 { | |
714 | 3848 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3849 /* Overlong encoded ASCII or ASCII with composing char |
3850 * is displayed normally, except a NUL. */ | |
3851 if (mb_c < 0x80) | |
3852 c = mb_c; | |
3853 mb_utf8 = TRUE; | |
507 | 3854 |
3855 /* At start of the line we can have a composing char. | |
3856 * Draw it as a space with a composing char. */ | |
3857 if (utf_iscomposing(mb_c)) | |
3858 { | |
1326 | 3859 int i; |
3860 | |
714 | 3861 for (i = Screen_mco - 1; i > 0; --i) |
3862 u8cc[i] = u8cc[i - 1]; | |
3863 u8cc[0] = mb_c; | |
507 | 3864 mb_c = ' '; |
3865 } | |
7 | 3866 } |
3867 | |
3868 if ((mb_l == 1 && c >= 0x80) | |
3869 || (mb_l >= 1 && mb_c == 0) | |
3870 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3871 # ifdef UNICODE16 |
3872 || mb_c >= 0x10000 | |
3873 # endif | |
3874 ))) | |
7 | 3875 { |
3876 /* | |
3877 * Illegal UTF-8 byte: display as <xx>. | |
3878 * Non-BMP character : display as ? or fullwidth ?. | |
3879 */ | |
1401 | 3880 # ifdef UNICODE16 |
7 | 3881 if (mb_c < 0x10000) |
1401 | 3882 # endif |
7 | 3883 { |
3884 transchar_hex(extra, mb_c); | |
714 | 3885 # ifdef FEAT_RIGHTLEFT |
7 | 3886 if (wp->w_p_rl) /* reverse */ |
3887 rl_mirror(extra); | |
714 | 3888 # endif |
7 | 3889 } |
1401 | 3890 # ifdef UNICODE16 |
7 | 3891 else if (utf_char2cells(mb_c) != 2) |
3892 STRCPY(extra, "?"); | |
3893 else | |
3894 /* 0xff1f in UTF-8: full-width '?' */ | |
3895 STRCPY(extra, "\357\274\237"); | |
1401 | 3896 # endif |
7 | 3897 |
3898 p_extra = extra; | |
3899 c = *p_extra; | |
3900 mb_c = mb_ptr2char_adv(&p_extra); | |
3901 mb_utf8 = (c >= 0x80); | |
3902 n_extra = (int)STRLEN(p_extra); | |
3903 c_extra = NUL; | |
3904 if (area_attr == 0 && search_attr == 0) | |
3905 { | |
3906 n_attr = n_extra + 1; | |
3907 extra_attr = hl_attr(HLF_8); | |
3908 saved_attr2 = char_attr; /* save current attr */ | |
3909 } | |
3910 } | |
3911 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3912 mb_l = 1; | |
3913 #ifdef FEAT_ARABIC | |
3914 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3915 { | |
3916 /* Do Arabic shaping. */ | |
714 | 3917 int pc, pc1, nc; |
3918 int pcc[MAX_MCO]; | |
7 | 3919 |
3920 /* The idea of what is the previous and next | |
3921 * character depends on 'rightleft'. */ | |
3922 if (wp->w_p_rl) | |
3923 { | |
3924 pc = prev_c; | |
3925 pc1 = prev_c1; | |
3926 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3927 prev_c1 = u8cc[0]; |
7 | 3928 } |
3929 else | |
3930 { | |
714 | 3931 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3932 nc = prev_c; |
714 | 3933 pc1 = pcc[0]; |
7 | 3934 } |
3935 prev_c = mb_c; | |
3936 | |
714 | 3937 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3938 } |
3939 else | |
3940 prev_c = mb_c; | |
3941 #endif | |
3942 } | |
3943 else /* enc_dbcs */ | |
3944 { | |
3945 mb_l = MB_BYTE2LEN(c); | |
3946 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3947 mb_l = 1; | |
3948 else if (mb_l > 1) | |
3949 { | |
3950 /* We assume a second byte below 32 is illegal. | |
3951 * Hopefully this is OK for all double-byte encodings! | |
3952 */ | |
3953 if (ptr[1] >= 32) | |
3954 mb_c = (c << 8) + ptr[1]; | |
3955 else | |
3956 { | |
3957 if (ptr[1] == NUL) | |
3958 { | |
3959 /* head byte at end of line */ | |
3960 mb_l = 1; | |
3961 transchar_nonprint(extra, c); | |
3962 } | |
3963 else | |
3964 { | |
3965 /* illegal tail byte */ | |
3966 mb_l = 2; | |
3967 STRCPY(extra, "XX"); | |
3968 } | |
3969 p_extra = extra; | |
3970 n_extra = (int)STRLEN(extra) - 1; | |
3971 c_extra = NUL; | |
3972 c = *p_extra++; | |
3973 if (area_attr == 0 && search_attr == 0) | |
3974 { | |
3975 n_attr = n_extra + 1; | |
3976 extra_attr = hl_attr(HLF_8); | |
3977 saved_attr2 = char_attr; /* save current attr */ | |
3978 } | |
3979 mb_c = c; | |
3980 } | |
3981 } | |
3982 } | |
3983 /* If a double-width char doesn't fit display a '>' in the | |
3984 * last column; the character is displayed at the start of the | |
3985 * next line. */ | |
3986 if (( | |
3987 # ifdef FEAT_RIGHTLEFT | |
3988 wp->w_p_rl ? (col <= 0) : | |
3989 # endif | |
3990 (col >= W_WIDTH(wp) - 1)) | |
3991 && (*mb_char2cells)(mb_c) == 2) | |
3992 { | |
3993 c = '>'; | |
3994 mb_c = c; | |
3995 mb_utf8 = FALSE; | |
3996 mb_l = 1; | |
3997 multi_attr = hl_attr(HLF_AT); | |
3998 /* Put pointer back so that the character will be | |
3999 * displayed at the start of the next line. */ | |
4000 --ptr; | |
4001 } | |
4002 else if (*ptr != NUL) | |
4003 ptr += mb_l - 1; | |
4004 | |
4005 /* If a double-width char doesn't fit at the left side display | |
4006 * a '<' in the first column. */ | |
4007 if (n_skip > 0 && mb_l > 1) | |
4008 { | |
4009 n_extra = 1; | |
1340 | 4010 c_extra = '<'; |
7 | 4011 c = ' '; |
4012 if (area_attr == 0 && search_attr == 0) | |
4013 { | |
4014 n_attr = n_extra + 1; | |
4015 extra_attr = hl_attr(HLF_AT); | |
4016 saved_attr2 = char_attr; /* save current attr */ | |
4017 } | |
4018 mb_c = c; | |
4019 mb_utf8 = FALSE; | |
4020 mb_l = 1; | |
4021 } | |
4022 | |
4023 } | |
4024 #endif | |
4025 ++ptr; | |
4026 | |
12 | 4027 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 4028 if (wp->w_p_list && (c == 160 |
4029 #ifdef FEAT_MBYTE | |
4030 || (mb_utf8 && mb_c == 160) | |
4031 #endif | |
4032 ) && lcs_nbsp) | |
12 | 4033 { |
4034 c = lcs_nbsp; | |
4035 if (area_attr == 0 && search_attr == 0) | |
4036 { | |
4037 n_attr = 1; | |
4038 extra_attr = hl_attr(HLF_8); | |
4039 saved_attr2 = char_attr; /* save current attr */ | |
4040 } | |
4041 #ifdef FEAT_MBYTE | |
4042 mb_c = c; | |
4043 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4044 { | |
4045 mb_utf8 = TRUE; | |
714 | 4046 u8cc[0] = 0; |
819 | 4047 c = 0xc0; |
12 | 4048 } |
4049 else | |
4050 mb_utf8 = FALSE; | |
4051 #endif | |
4052 } | |
4053 | |
7 | 4054 if (extra_check) |
4055 { | |
743 | 4056 #ifdef FEAT_SPELL |
221 | 4057 int can_spell = TRUE; |
743 | 4058 #endif |
4059 | |
4060 #ifdef FEAT_SYN_HL | |
7 | 4061 /* Get syntax attribute, unless still at the start of the line |
4062 * (double-wide char that doesn't fit). */ | |
221 | 4063 v = (long)(ptr - line); |
4064 if (has_syntax && v > 0) | |
7 | 4065 { |
4066 /* Get the syntax attribute for the character. If there | |
4067 * is an error, disable syntax highlighting. */ | |
4068 save_did_emsg = did_emsg; | |
4069 did_emsg = FALSE; | |
4070 | |
221 | 4071 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 4072 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4073 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4074 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4075 NULL, FALSE); |
7 | 4076 |
4077 if (did_emsg) | |
482 | 4078 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4079 wp->w_s->b_syn_error = TRUE; |
482 | 4080 has_syntax = FALSE; |
4081 } | |
7 | 4082 else |
4083 did_emsg = save_did_emsg; | |
4084 | |
4085 /* Need to get the line again, a multi-line regexp may | |
4086 * have made it invalid. */ | |
4087 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4088 ptr = line + v; | |
4089 | |
674 | 4090 if (!attr_pri) |
7 | 4091 char_attr = syntax_attr; |
301 | 4092 else |
303 | 4093 char_attr = hl_combine_attr(syntax_attr, char_attr); |
2364
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4094 # ifdef FEAT_CONCEAL |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4095 /* no concealing past the end of the line, it interferes |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4096 * with line highlighting */ |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4097 if (c == NUL) |
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4098 syntax_flags = 0; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4099 else |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4100 syntax_flags = get_syntax_info(&syntax_id); |
2364
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4101 # endif |
7 | 4102 } |
743 | 4103 #endif |
4104 | |
4105 #ifdef FEAT_SPELL | |
301 | 4106 /* Check spelling (unless at the end of the line). |
319 | 4107 * Only do this when there is no syntax highlighting, the |
4108 * @Spell cluster is not used or the current syntax item | |
4109 * contains the @Spell cluster. */ | |
348 | 4110 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4111 { |
230 | 4112 spell_attr = 0; |
743 | 4113 # ifdef FEAT_SYN_HL |
674 | 4114 if (!attr_pri) |
230 | 4115 char_attr = syntax_attr; |
743 | 4116 # endif |
4117 if (c != 0 && ( | |
4118 # ifdef FEAT_SYN_HL | |
4119 !has_syntax || | |
4120 # endif | |
4121 can_spell)) | |
221 | 4122 { |
348 | 4123 char_u *prev_ptr, *p; |
4124 int len; | |
534 | 4125 hlf_T spell_hlf = HLF_COUNT; |
221 | 4126 # ifdef FEAT_MBYTE |
336 | 4127 if (has_mbyte) |
4128 { | |
4129 prev_ptr = ptr - mb_l; | |
4130 v -= mb_l - 1; | |
4131 } | |
4132 else | |
221 | 4133 # endif |
336 | 4134 prev_ptr = ptr - 1; |
348 | 4135 |
4136 /* Use nextline[] if possible, it has the start of the | |
4137 * next line concatenated. */ | |
4138 if ((prev_ptr - line) - nextlinecol >= 0) | |
4139 p = nextline + (prev_ptr - line) - nextlinecol; | |
4140 else | |
4141 p = prev_ptr; | |
835 | 4142 cap_col -= (int)(prev_ptr - line); |
625 | 4143 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4144 nochange); | |
348 | 4145 word_end = v + len; |
301 | 4146 |
4147 /* In Insert mode only highlight a word that | |
4148 * doesn't touch the cursor. */ | |
534 | 4149 if (spell_hlf != HLF_COUNT |
301 | 4150 && (State & INSERT) != 0 |
4151 && wp->w_cursor.lnum == lnum | |
4152 && wp->w_cursor.col >= | |
4153 (colnr_T)(prev_ptr - line) | |
4154 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4155 { |
534 | 4156 spell_hlf = HLF_COUNT; |
301 | 4157 spell_redraw_lnum = lnum; |
221 | 4158 } |
348 | 4159 |
534 | 4160 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4161 && (p - nextline) + len > nextline_idx) |
4162 { | |
4163 /* Remember that the good word continues at the | |
4164 * start of the next line. */ | |
4165 checked_lnum = lnum + 1; | |
835 | 4166 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4167 } |
386 | 4168 |
534 | 4169 /* Turn index into actual attributes. */ |
4170 if (spell_hlf != HLF_COUNT) | |
4171 spell_attr = highlight_attr[spell_hlf]; | |
4172 | |
386 | 4173 if (cap_col > 0) |
4174 { | |
4175 if (p != prev_ptr | |
4176 && (p - nextline) + cap_col >= nextline_idx) | |
4177 { | |
4178 /* Remember that the word in the next line | |
4179 * must start with a capital. */ | |
4180 capcol_lnum = lnum + 1; | |
835 | 4181 cap_col = (int)((p - nextline) + cap_col |
4182 - nextline_idx); | |
386 | 4183 } |
4184 else | |
4185 /* Compute the actual column. */ | |
835 | 4186 cap_col += (int)(prev_ptr - line); |
386 | 4187 } |
221 | 4188 } |
4189 } | |
4190 if (spell_attr != 0) | |
348 | 4191 { |
674 | 4192 if (!attr_pri) |
348 | 4193 char_attr = hl_combine_attr(char_attr, spell_attr); |
4194 else | |
4195 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4196 } | |
7 | 4197 #endif |
4198 #ifdef FEAT_LINEBREAK | |
4199 /* | |
221 | 4200 * Found last space before word: check for line break. |
7 | 4201 */ |
4202 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4203 && !wp->w_p_list) |
7 | 4204 { |
4205 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4206 # ifdef FEAT_MBYTE | |
4207 has_mbyte ? mb_l : | |
4208 # endif | |
4209 1), (colnr_T)vcol, NULL) - 1; | |
4210 c_extra = ' '; | |
4211 if (vim_iswhite(c)) | |
4212 c = ' '; | |
4213 } | |
4214 #endif | |
4215 | |
4216 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4217 { | |
4218 c = lcs_trail; | |
674 | 4219 if (!attr_pri) |
7 | 4220 { |
4221 n_attr = 1; | |
4222 extra_attr = hl_attr(HLF_8); | |
4223 saved_attr2 = char_attr; /* save current attr */ | |
4224 } | |
4225 #ifdef FEAT_MBYTE | |
4226 mb_c = c; | |
4227 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4228 { | |
4229 mb_utf8 = TRUE; | |
714 | 4230 u8cc[0] = 0; |
819 | 4231 c = 0xc0; |
7 | 4232 } |
4233 else | |
4234 mb_utf8 = FALSE; | |
4235 #endif | |
4236 } | |
4237 } | |
4238 | |
4239 /* | |
4240 * Handling of non-printable characters. | |
4241 */ | |
819 | 4242 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4243 { |
4244 /* | |
4245 * when getting a character from the file, we may have to | |
4246 * turn it into something else on the way to putting it | |
4247 * into "ScreenLines". | |
4248 */ | |
4249 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4250 { | |
4251 /* tab amount depends on current column */ | |
4252 n_extra = (int)wp->w_buffer->b_p_ts | |
4253 - vcol % (int)wp->w_buffer->b_p_ts - 1; | |
4254 #ifdef FEAT_MBYTE | |
4255 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4256 #endif | |
4257 if (wp->w_p_list) | |
4258 { | |
4259 c = lcs_tab1; | |
4260 c_extra = lcs_tab2; | |
4261 n_attr = n_extra + 1; | |
4262 extra_attr = hl_attr(HLF_8); | |
4263 saved_attr2 = char_attr; /* save current attr */ | |
4264 #ifdef FEAT_MBYTE | |
4265 mb_c = c; | |
4266 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4267 { | |
4268 mb_utf8 = TRUE; | |
714 | 4269 u8cc[0] = 0; |
819 | 4270 c = 0xc0; |
7 | 4271 } |
4272 #endif | |
4273 } | |
4274 else | |
4275 { | |
4276 c_extra = ' '; | |
4277 c = ' '; | |
4278 } | |
4279 } | |
36 | 4280 else if (c == NUL |
4281 && ((wp->w_p_list && lcs_eol > 0) | |
4282 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4283 && tocol > vcol | |
39 | 4284 #ifdef FEAT_VISUAL |
36 | 4285 && VIsual_mode != Ctrl_V |
39 | 4286 #endif |
36 | 4287 && ( |
4288 # ifdef FEAT_RIGHTLEFT | |
4289 wp->w_p_rl ? (col >= 0) : | |
4290 # endif | |
4291 (col < W_WIDTH(wp))) | |
4292 && !(noinvcur | |
1850 | 4293 && lnum == wp->w_cursor.lnum |
36 | 4294 && (colnr_T)vcol == wp->w_virtcol))) |
4295 && lcs_eol_one >= 0) | |
7 | 4296 { |
36 | 4297 /* Display a '$' after the line or highlight an extra |
4298 * character if the line break is included. */ | |
7 | 4299 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4300 /* For a diff line the highlighting continues after the | |
4301 * "$". */ | |
4302 if ( | |
4303 # ifdef FEAT_DIFF | |
534 | 4304 diff_hlf == (hlf_T)0 |
7 | 4305 # ifdef LINE_ATTR |
4306 && | |
4307 # endif | |
4308 # endif | |
4309 # ifdef LINE_ATTR | |
4310 line_attr == 0 | |
4311 # endif | |
4312 ) | |
4313 #endif | |
4314 { | |
4315 #ifdef FEAT_VIRTUALEDIT | |
4316 /* In virtualedit, visual selections may extend | |
4317 * beyond end of line. */ | |
4318 if (area_highlighting && virtual_active() | |
4319 && tocol != MAXCOL && vcol < tocol) | |
4320 n_extra = 0; | |
4321 else | |
4322 #endif | |
4323 { | |
4324 p_extra = at_end_str; | |
4325 n_extra = 1; | |
4326 c_extra = NUL; | |
4327 } | |
4328 } | |
36 | 4329 if (wp->w_p_list) |
4330 c = lcs_eol; | |
4331 else | |
4332 c = ' '; | |
7 | 4333 lcs_eol_one = -1; |
4334 --ptr; /* put it back at the NUL */ | |
674 | 4335 if (!attr_pri) |
7 | 4336 { |
4337 extra_attr = hl_attr(HLF_AT); | |
4338 n_attr = 1; | |
4339 } | |
4340 #ifdef FEAT_MBYTE | |
4341 mb_c = c; | |
4342 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4343 { | |
4344 mb_utf8 = TRUE; | |
714 | 4345 u8cc[0] = 0; |
819 | 4346 c = 0xc0; |
7 | 4347 } |
4348 else | |
4349 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4350 #endif | |
4351 } | |
4352 else if (c != NUL) | |
4353 { | |
4354 p_extra = transchar(c); | |
4355 #ifdef FEAT_RIGHTLEFT | |
4356 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4357 rl_mirror(p_extra); /* reverse "<12>" */ | |
4358 #endif | |
4359 n_extra = byte2cells(c) - 1; | |
4360 c_extra = NUL; | |
4361 c = *p_extra++; | |
674 | 4362 if (!attr_pri) |
7 | 4363 { |
4364 n_attr = n_extra + 1; | |
4365 extra_attr = hl_attr(HLF_8); | |
4366 saved_attr2 = char_attr; /* save current attr */ | |
4367 } | |
4368 #ifdef FEAT_MBYTE | |
4369 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4370 #endif | |
4371 } | |
4372 #ifdef FEAT_VIRTUALEDIT | |
4373 else if (VIsual_active | |
4374 && (VIsual_mode == Ctrl_V | |
4375 || VIsual_mode == 'v') | |
4376 && virtual_active() | |
4377 && tocol != MAXCOL | |
4378 && vcol < tocol | |
4379 && ( | |
4380 # ifdef FEAT_RIGHTLEFT | |
4381 wp->w_p_rl ? (col >= 0) : | |
4382 # endif | |
4383 (col < W_WIDTH(wp)))) | |
4384 { | |
4385 c = ' '; | |
4386 --ptr; /* put it back at the NUL */ | |
4387 } | |
4388 #endif | |
910 | 4389 #if defined(LINE_ATTR) |
7 | 4390 else if (( |
4391 # ifdef FEAT_DIFF | |
910 | 4392 diff_hlf != (hlf_T)0 || |
7 | 4393 # endif |
4394 line_attr != 0 | |
4395 ) && ( | |
4396 # ifdef FEAT_RIGHTLEFT | |
4397 wp->w_p_rl ? (col >= 0) : | |
4398 # endif | |
4399 (col < W_WIDTH(wp)))) | |
4400 { | |
4401 /* Highlight until the right side of the window */ | |
4402 c = ' '; | |
4403 --ptr; /* put it back at the NUL */ | |
867 | 4404 |
4405 /* Remember we do the char for line highlighting. */ | |
4406 ++did_line_attr; | |
4407 | |
4408 /* don't do search HL for the rest of the line */ | |
4409 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4410 char_attr = line_attr; | |
7 | 4411 # ifdef FEAT_DIFF |
4412 if (diff_hlf == HLF_TXD) | |
4413 { | |
4414 diff_hlf = HLF_CHD; | |
4415 if (attr == 0 || char_attr != attr) | |
4416 char_attr = hl_attr(diff_hlf); | |
4417 } | |
4418 # endif | |
4419 } | |
4420 #endif | |
4421 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4422 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4423 #ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4424 if ( wp->w_p_cole > 0 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4425 && (wp != curwin || lnum != wp->w_cursor.lnum || |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4426 conceal_cursor_line(wp)) |
2349
586a459f3980
Never hide text for conceal in cursor line. Do hide when there is
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
4427 && (syntax_flags & HL_CONCEAL) != 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4428 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4429 char_attr = conceal_attr; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4430 if (prev_syntax_id != syntax_id |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4431 && (syn_get_sub_char() != NUL || wp->w_p_cole == 1) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4432 && wp->w_p_cole != 3) |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4433 { |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4434 /* First time at this concealed item: display one |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4435 * character. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4436 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4437 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4438 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4439 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4440 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4441 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4442 |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4443 prev_syntax_id = syntax_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4444 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4445 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4446 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4447 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4448 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
|
4449 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4450 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4451 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4452 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4453 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4454 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4455 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4456 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4457 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4458 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4459 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4460 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4461 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4462 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4463 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4464 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4465 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4466 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4467 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4468 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4469 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4470 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4471 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4472 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4473 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4474 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4475 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4476 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4477 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4478 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4479 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4480 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
|
4481 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4482 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4483 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4484 { |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4485 prev_syntax_id = 0; |
2348
8878a9f8db87
Rename w_p_conceal to w_p_conc for consistency.
Bram Moolenaar <bram@vim.org>
parents:
2346
diff
changeset
|
4486 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4487 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4488 #endif /* FEAT_CONCEAL */ |
7 | 4489 } |
4490 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4491 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4492 /* In the cursor line and we may be concealing characters: correct |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4493 * the cursor column when we reach its position. */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4494 if (!did_wcol && wp == curwin && lnum == wp->w_cursor.lnum |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4495 && conceal_cursor_line(wp) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4496 && (int)wp->w_virtcol <= vcol + n_skip) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4497 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4498 wp->w_wcol = col - boguscols; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4499 did_wcol = TRUE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4500 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4501 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4502 |
7 | 4503 /* Don't override visual selection highlighting. */ |
4504 if (n_attr > 0 | |
4505 && draw_state == WL_LINE | |
674 | 4506 && !attr_pri) |
7 | 4507 char_attr = extra_attr; |
4508 | |
42 | 4509 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4510 /* XIM don't send preedit_start and preedit_end, but they send |
4511 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4512 * im_is_preediting() here. */ | |
4513 if (xic != NULL | |
1850 | 4514 && lnum == wp->w_cursor.lnum |
7 | 4515 && (State & INSERT) |
4516 && !p_imdisable | |
4517 && im_is_preediting() | |
4518 && draw_state == WL_LINE) | |
4519 { | |
4520 colnr_T tcol; | |
4521 | |
4522 if (preedit_end_col == MAXCOL) | |
1850 | 4523 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4524 else |
4525 tcol = preedit_end_col; | |
4526 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4527 { | |
4528 if (feedback_old_attr < 0) | |
4529 { | |
4530 feedback_col = 0; | |
4531 feedback_old_attr = char_attr; | |
4532 } | |
4533 char_attr = im_get_feedback_attr(feedback_col); | |
4534 if (char_attr < 0) | |
4535 char_attr = feedback_old_attr; | |
4536 feedback_col++; | |
4537 } | |
4538 else if (feedback_old_attr >= 0) | |
4539 { | |
4540 char_attr = feedback_old_attr; | |
4541 feedback_old_attr = -1; | |
4542 feedback_col = 0; | |
4543 } | |
4544 } | |
4545 #endif | |
4546 /* | |
4547 * Handle the case where we are in column 0 but not on the first | |
4548 * character of the line and the user wants us to show us a | |
4549 * special character (via 'listchars' option "precedes:<char>". | |
4550 */ | |
4551 if (lcs_prec_todo != NUL | |
4552 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4553 #ifdef FEAT_DIFF | |
4554 && filler_todo <= 0 | |
4555 #endif | |
4556 && draw_state > WL_NR | |
4557 && c != NUL) | |
4558 { | |
4559 c = lcs_prec; | |
4560 lcs_prec_todo = NUL; | |
4561 #ifdef FEAT_MBYTE | |
4562 mb_c = c; | |
4563 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4564 { | |
4565 mb_utf8 = TRUE; | |
714 | 4566 u8cc[0] = 0; |
819 | 4567 c = 0xc0; |
7 | 4568 } |
4569 else | |
4570 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4571 #endif | |
674 | 4572 if (!attr_pri) |
7 | 4573 { |
4574 saved_attr3 = char_attr; /* save current attr */ | |
4575 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4576 n_attr3 = 1; | |
4577 } | |
4578 } | |
4579 | |
4580 /* | |
867 | 4581 * At end of the text line or just after the last character. |
7 | 4582 */ |
867 | 4583 if (c == NUL |
910 | 4584 #if defined(LINE_ATTR) |
867 | 4585 || did_line_attr == 1 |
4586 #endif | |
4587 ) | |
4588 { | |
4589 #ifdef FEAT_SEARCH_EXTRA | |
4590 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4591 |
4592 /* we're not really at that column when skipping some text */ | |
1439 | 4593 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4594 ++prevcol; |
867 | 4595 #endif |
4596 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4597 /* Invert at least one char, used for Visual and empty line or |
7 | 4598 * highlight match at end of line. If it's beyond the last |
4599 * char on the screen, just overwrite that one (tricky!) Not | |
4600 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4601 #ifdef FEAT_SEARCH_EXTRA |
4602 prevcol_hl_flag = FALSE; | |
4603 if (prevcol == (long)search_hl.startcol) | |
4604 prevcol_hl_flag = TRUE; | |
4605 else | |
4606 { | |
4607 cur = wp->w_match_head; | |
4608 while (cur != NULL) | |
4609 { | |
4610 if (prevcol == (long)cur->hl.startcol) | |
4611 { | |
4612 prevcol_hl_flag = TRUE; | |
4613 break; | |
4614 } | |
4615 cur = cur->next; | |
4616 } | |
4617 } | |
4618 #endif | |
7 | 4619 if (lcs_eol == lcs_eol_one |
1850 | 4620 && ((area_attr != 0 && vcol == fromcol |
4621 #ifdef FEAT_VISUAL | |
4622 && (VIsual_mode != Ctrl_V | |
4623 || lnum == VIsual.lnum | |
4624 || lnum == curwin->w_cursor.lnum) | |
4625 #endif | |
4626 && c == NUL) | |
7 | 4627 #ifdef FEAT_SEARCH_EXTRA |
4628 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4629 || (prevcol_hl_flag == TRUE |
910 | 4630 # if defined(LINE_ATTR) |
867 | 4631 && did_line_attr <= 1 |
4632 # endif | |
4633 ) | |
7 | 4634 #endif |
4635 )) | |
4636 { | |
4637 int n = 0; | |
4638 | |
4639 #ifdef FEAT_RIGHTLEFT | |
4640 if (wp->w_p_rl) | |
4641 { | |
4642 if (col < 0) | |
4643 n = 1; | |
4644 } | |
4645 else | |
4646 #endif | |
4647 { | |
4648 if (col >= W_WIDTH(wp)) | |
4649 n = -1; | |
4650 } | |
4651 if (n != 0) | |
4652 { | |
4653 /* At the window boundary, highlight the last character | |
4654 * instead (better than nothing). */ | |
4655 off += n; | |
4656 col += n; | |
4657 } | |
4658 else | |
4659 { | |
4660 /* Add a blank character to highlight. */ | |
4661 ScreenLines[off] = ' '; | |
4662 #ifdef FEAT_MBYTE | |
4663 if (enc_utf8) | |
4664 ScreenLinesUC[off] = 0; | |
4665 #endif | |
4666 } | |
4667 #ifdef FEAT_SEARCH_EXTRA | |
4668 if (area_attr == 0) | |
4669 { | |
1326 | 4670 /* Use attributes from match with highest priority among |
4671 * 'search_hl' and the match list. */ | |
4672 char_attr = search_hl.attr; | |
4673 cur = wp->w_match_head; | |
4674 shl_flag = FALSE; | |
4675 while (cur != NULL || shl_flag == FALSE) | |
699 | 4676 { |
1326 | 4677 if (shl_flag == FALSE |
4678 && ((cur != NULL | |
4679 && cur->priority > SEARCH_HL_PRIORITY) | |
4680 || cur == NULL)) | |
699 | 4681 { |
1326 | 4682 shl = &search_hl; |
4683 shl_flag = TRUE; | |
699 | 4684 } |
1326 | 4685 else |
4686 shl = &cur->hl; | |
4687 if ((ptr - line) - 1 == (long)shl->startcol) | |
4688 char_attr = shl->attr; | |
4689 if (shl != &search_hl && cur != NULL) | |
4690 cur = cur->next; | |
699 | 4691 } |
7 | 4692 } |
4693 #endif | |
4694 ScreenAttrs[off] = char_attr; | |
4695 #ifdef FEAT_RIGHTLEFT | |
4696 if (wp->w_p_rl) | |
1437 | 4697 { |
7 | 4698 --col; |
1437 | 4699 --off; |
4700 } | |
7 | 4701 else |
4702 #endif | |
1437 | 4703 { |
7 | 4704 ++col; |
1437 | 4705 ++off; |
4706 } | |
743 | 4707 ++vcol; |
1437 | 4708 #ifdef FEAT_SYN_HL |
4709 eol_hl_off = 1; | |
4710 #endif | |
743 | 4711 } |
867 | 4712 } |
4713 | |
4714 /* | |
4715 * At end of the text line. | |
4716 */ | |
4717 if (c == NUL) | |
4718 { | |
743 | 4719 #ifdef FEAT_SYN_HL |
1850 | 4720 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4721 && lnum == wp->w_cursor.lnum) | |
1437 | 4722 { |
4723 /* highlight last char after line */ | |
4724 --col; | |
4725 --off; | |
4726 --vcol; | |
4727 } | |
4728 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4729 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4730 if (wp->w_p_wrap) |
4731 v = wp->w_skipcol; | |
4732 else | |
4733 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4734 |
820 | 4735 /* check if line ends before left margin */ |
4736 if (vcol < v + col - win_col_off(wp)) | |
4737 vcol = v + col - win_col_off(wp); | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4738 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4739 /* Get rid of the boguscols now, we want to draw until the right |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4740 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4741 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4742 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4743 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4744 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4745 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4746 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4747 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4748 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4749 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4750 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4751 W_WIDTH(wp) * (row - startrow + 1) + v |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4752 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4753 || draw_color_col) |
743 | 4754 # ifdef FEAT_RIGHTLEFT |
4755 && !wp->w_p_rl | |
4756 # endif | |
4757 ) | |
4758 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4759 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4760 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4761 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4762 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4763 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4764 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4765 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4766 for (i = 0; color_cols[i] >= 0; ++i) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4767 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4768 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4769 |
743 | 4770 while (col < W_WIDTH(wp)) |
4771 { | |
4772 ScreenLines[off] = ' '; | |
4773 #ifdef FEAT_MBYTE | |
4774 if (enc_utf8) | |
4775 ScreenLinesUC[off] = 0; | |
4776 #endif | |
4777 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4778 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4779 draw_color_col = advance_color_col(VCOL_HLC, |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4780 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4781 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4782 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4783 ScreenAttrs[off++] = hl_attr(HLF_CUC); |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4784 else if (draw_color_col && VCOL_HLC == *color_cols) |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4785 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4786 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4787 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4788 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4789 if (VCOL_HLC >= rightmost_vcol) |
743 | 4790 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4791 |
743 | 4792 ++vcol; |
4793 } | |
4794 } | |
4795 #endif | |
7 | 4796 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4797 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
|
4798 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4799 row++; |
4800 | |
4801 /* | |
4802 * Update w_cline_height and w_cline_folded if the cursor line was | |
4803 * updated (saves a call to plines() later). | |
4804 */ | |
4805 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4806 { | |
4807 curwin->w_cline_row = startrow; | |
4808 curwin->w_cline_height = row - startrow; | |
4809 #ifdef FEAT_FOLDING | |
4810 curwin->w_cline_folded = FALSE; | |
4811 #endif | |
4812 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4813 } | |
4814 | |
4815 break; | |
4816 } | |
4817 | |
4818 /* line continues beyond line end */ | |
4819 if (lcs_ext | |
4820 && !wp->w_p_wrap | |
4821 #ifdef FEAT_DIFF | |
4822 && filler_todo <= 0 | |
4823 #endif | |
4824 && ( | |
4825 #ifdef FEAT_RIGHTLEFT | |
4826 wp->w_p_rl ? col == 0 : | |
4827 #endif | |
4828 col == W_WIDTH(wp) - 1) | |
4829 && (*ptr != NUL | |
1555 | 4830 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4831 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4832 { | |
4833 c = lcs_ext; | |
4834 char_attr = hl_attr(HLF_AT); | |
4835 #ifdef FEAT_MBYTE | |
4836 mb_c = c; | |
4837 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4838 { | |
4839 mb_utf8 = TRUE; | |
714 | 4840 u8cc[0] = 0; |
819 | 4841 c = 0xc0; |
7 | 4842 } |
4843 else | |
4844 mb_utf8 = FALSE; | |
4845 #endif | |
4846 } | |
4847 | |
743 | 4848 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4849 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4850 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4851 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4852 |
743 | 4853 /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4854 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4855 * Also highlight the 'colorcolumn' if it is different than |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4856 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4857 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4858 if (draw_state == WL_LINE && !lnum_in_visual_area) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4859 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4860 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4861 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4862 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4863 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4864 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4865 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4866 else if (draw_color_col && VCOL_HLC == *color_cols) |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4867 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4868 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4869 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4870 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4871 } |
743 | 4872 #endif |
4873 | |
7 | 4874 /* |
4875 * Store character to be displayed. | |
4876 * Skip characters that are left of the screen for 'nowrap'. | |
4877 */ | |
4878 vcol_prev = vcol; | |
4879 if (draw_state < WL_LINE || n_skip <= 0) | |
4880 { | |
4881 /* | |
4882 * Store the character. | |
4883 */ | |
4884 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4885 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4886 { | |
4887 /* A double-wide character is: put first halve in left cell. */ | |
4888 --off; | |
4889 --col; | |
4890 } | |
4891 #endif | |
4892 ScreenLines[off] = c; | |
4893 #ifdef FEAT_MBYTE | |
4894 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4895 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4896 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4897 ScreenLines[off] = 0x8e; |
7 | 4898 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4899 } |
7 | 4900 else if (enc_utf8) |
4901 { | |
4902 if (mb_utf8) | |
4903 { | |
1326 | 4904 int i; |
4905 | |
7 | 4906 ScreenLinesUC[off] = mb_c; |
819 | 4907 if ((c & 0xff) == 0) |
4908 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4909 for (i = 0; i < Screen_mco; ++i) |
4910 { | |
4911 ScreenLinesC[i][off] = u8cc[i]; | |
4912 if (u8cc[i] == 0) | |
4913 break; | |
4914 } | |
7 | 4915 } |
4916 else | |
4917 ScreenLinesUC[off] = 0; | |
4918 } | |
4919 if (multi_attr) | |
4920 { | |
4921 ScreenAttrs[off] = multi_attr; | |
4922 multi_attr = 0; | |
4923 } | |
4924 else | |
4925 #endif | |
4926 ScreenAttrs[off] = char_attr; | |
4927 | |
4928 #ifdef FEAT_MBYTE | |
4929 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4930 { | |
4931 /* Need to fill two screen columns. */ | |
4932 ++off; | |
4933 ++col; | |
4934 if (enc_utf8) | |
4935 /* UTF-8: Put a 0 in the second screen char. */ | |
4936 ScreenLines[off] = 0; | |
4937 else | |
4938 /* DBCS: Put second byte in the second screen char. */ | |
4939 ScreenLines[off] = mb_c & 0xff; | |
4940 ++vcol; | |
4941 /* When "tocol" is halfway a character, set it to the end of | |
4942 * the character, otherwise highlighting won't stop. */ | |
4943 if (tocol == vcol) | |
4944 ++tocol; | |
4945 #ifdef FEAT_RIGHTLEFT | |
4946 if (wp->w_p_rl) | |
4947 { | |
4948 /* now it's time to backup one cell */ | |
4949 --off; | |
4950 --col; | |
4951 } | |
4952 #endif | |
4953 } | |
4954 #endif | |
4955 #ifdef FEAT_RIGHTLEFT | |
4956 if (wp->w_p_rl) | |
4957 { | |
4958 --off; | |
4959 --col; | |
4960 } | |
4961 else | |
4962 #endif | |
4963 { | |
4964 ++off; | |
4965 ++col; | |
4966 } | |
4967 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4968 #ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4969 else if (wp->w_p_cole > 0 && is_concealing) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4970 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4971 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4972 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4973 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4974 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4975 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4976 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4977 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4978 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4979 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4980 * 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
|
4981 * 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
|
4982 * 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
|
4983 * 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
|
4984 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4985 * 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
|
4986 * 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
|
4987 * 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
|
4988 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4989 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4990 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4991 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4992 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4993 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4994 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4995 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4996 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4997 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4998 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4999 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5000 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5001 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5002 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5003 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5004 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5005 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5006 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5007 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5008 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5009 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5010 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5011 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
|
5012 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5013 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5014 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5015 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5016 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5017 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5018 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5019 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5020 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5021 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5022 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5023 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5024 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5025 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5026 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5027 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5028 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5029 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5030 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5031 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5032 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5033 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5034 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5035 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5036 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5037 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5038 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5039 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5040 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5041 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5043 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5044 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5045 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5046 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5047 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5048 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5049 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5050 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5051 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5052 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5053 #endif /* FEAT_CONCEAL */ |
7 | 5054 else |
5055 --n_skip; | |
5056 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5057 /* 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
|
5058 * column. */ |
1849 | 5059 if (draw_state > WL_NR |
7 | 5060 #ifdef FEAT_DIFF |
5061 && filler_todo <= 0 | |
5062 #endif | |
5063 ) | |
5064 ++vcol; | |
5065 | |
743 | 5066 #ifdef FEAT_SYN_HL |
5067 if (vcol_save_attr >= 0) | |
5068 char_attr = vcol_save_attr; | |
5069 #endif | |
5070 | |
7 | 5071 /* restore attributes after "predeces" in 'listchars' */ |
5072 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5073 char_attr = saved_attr3; | |
5074 | |
5075 /* restore attributes after last 'listchars' or 'number' char */ | |
5076 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5077 char_attr = saved_attr2; | |
5078 | |
5079 /* | |
5080 * At end of screen line and there is more to come: Display the line | |
1378 | 5081 * so far. If there is no more to display it is caught above. |
7 | 5082 */ |
5083 if (( | |
5084 #ifdef FEAT_RIGHTLEFT | |
5085 wp->w_p_rl ? (col < 0) : | |
5086 #endif | |
5087 (col >= W_WIDTH(wp))) | |
5088 && (*ptr != NUL | |
5089 #ifdef FEAT_DIFF | |
5090 || filler_todo > 0 | |
5091 #endif | |
5092 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) | |
5093 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) | |
5094 ) | |
5095 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5096 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5097 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
|
5098 (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
|
5099 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5100 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5101 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
|
5102 (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
|
5103 #endif |
7 | 5104 ++row; |
5105 ++screen_row; | |
5106 | |
5107 /* When not wrapping and finished diff lines, or when displayed | |
5108 * '$' and highlighting until last column, break here. */ | |
5109 if ((!wp->w_p_wrap | |
5110 #ifdef FEAT_DIFF | |
5111 && filler_todo <= 0 | |
5112 #endif | |
5113 ) || lcs_eol_one == -1) | |
5114 break; | |
5115 | |
5116 /* When the window is too narrow draw all "@" lines. */ | |
5117 if (draw_state != WL_LINE | |
5118 #ifdef FEAT_DIFF | |
5119 && filler_todo <= 0 | |
5120 #endif | |
5121 ) | |
5122 { | |
5123 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5124 #ifdef FEAT_VERTSPLIT | |
5125 draw_vsep_win(wp, row); | |
5126 #endif | |
5127 row = endrow; | |
5128 } | |
5129 | |
5130 /* When line got too long for screen break here. */ | |
5131 if (row == endrow) | |
5132 { | |
5133 ++row; | |
5134 break; | |
5135 } | |
5136 | |
5137 if (screen_cur_row == screen_row - 1 | |
5138 #ifdef FEAT_DIFF | |
5139 && filler_todo <= 0 | |
5140 #endif | |
5141 && W_WIDTH(wp) == Columns) | |
5142 { | |
5143 /* Remember that the line wraps, used for modeless copy. */ | |
5144 LineWraps[screen_row - 1] = TRUE; | |
5145 | |
5146 /* | |
5147 * Special trick to make copy/paste of wrapped lines work with | |
5148 * xterm/screen: write an extra character beyond the end of | |
5149 * the line. This will work with all terminal types | |
5150 * (regardless of the xn,am settings). | |
5151 * Only do this on a fast tty. | |
5152 * Only do this if the cursor is on the current line | |
5153 * (something has been written in it). | |
5154 * Don't do this for the GUI. | |
5155 * Don't do this for double-width characters. | |
5156 * Don't do this for a window not at the right screen border. | |
5157 */ | |
5158 if (p_tf | |
5159 #ifdef FEAT_GUI | |
5160 && !gui.in_use | |
5161 #endif | |
5162 #ifdef FEAT_MBYTE | |
5163 && !(has_mbyte | |
1378 | 5164 && ((*mb_off2cells)(LineOffset[screen_row], |
5165 LineOffset[screen_row] + screen_Columns) | |
5166 == 2 | |
7 | 5167 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5168 + (int)Columns - 2, |
5169 LineOffset[screen_row] + screen_Columns) | |
5170 == 2)) | |
7 | 5171 #endif |
5172 ) | |
5173 { | |
5174 /* First make sure we are at the end of the screen line, | |
5175 * then output the same character again to let the | |
5176 * terminal know about the wrap. If the terminal doesn't | |
5177 * auto-wrap, we overwrite the character. */ | |
5178 if (screen_cur_col != W_WIDTH(wp)) | |
5179 screen_char(LineOffset[screen_row - 1] | |
5180 + (unsigned)Columns - 1, | |
5181 screen_row - 1, (int)(Columns - 1)); | |
5182 | |
5183 #ifdef FEAT_MBYTE | |
5184 /* When there is a multi-byte character, just output a | |
5185 * space to keep it simple. */ | |
148 | 5186 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5187 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5188 out_char(' '); |
5189 else | |
5190 #endif | |
5191 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5192 + (Columns - 1)]); | |
5193 /* force a redraw of the first char on the next line */ | |
5194 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5195 screen_start(); /* don't know where cursor is now */ | |
5196 } | |
5197 } | |
5198 | |
5199 col = 0; | |
5200 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5201 #ifdef FEAT_RIGHTLEFT | |
5202 if (wp->w_p_rl) | |
5203 { | |
5204 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5205 off += col; | |
5206 } | |
5207 #endif | |
5208 | |
5209 /* reset the drawing state for the start of a wrapped line */ | |
5210 draw_state = WL_START; | |
5211 saved_n_extra = n_extra; | |
5212 saved_p_extra = p_extra; | |
5213 saved_c_extra = c_extra; | |
5214 saved_char_attr = char_attr; | |
5215 n_extra = 0; | |
5216 lcs_prec_todo = lcs_prec; | |
5217 #ifdef FEAT_LINEBREAK | |
5218 # ifdef FEAT_DIFF | |
5219 if (filler_todo <= 0) | |
5220 # endif | |
5221 need_showbreak = TRUE; | |
5222 #endif | |
5223 #ifdef FEAT_DIFF | |
5224 --filler_todo; | |
5225 /* When the filler lines are actually below the last line of the | |
5226 * file, don't draw the line itself, break here. */ | |
5227 if (filler_todo == 0 && wp->w_botfill) | |
5228 break; | |
5229 #endif | |
5230 } | |
5231 | |
5232 } /* for every character in the line */ | |
5233 | |
743 | 5234 #ifdef FEAT_SPELL |
386 | 5235 /* After an empty line check first word for capital. */ |
5236 if (*skipwhite(line) == NUL) | |
5237 { | |
5238 capcol_lnum = lnum + 1; | |
5239 cap_col = 0; | |
5240 } | |
5241 #endif | |
5242 | |
7 | 5243 return row; |
5244 } | |
5245 | |
714 | 5246 #ifdef FEAT_MBYTE |
5247 static int comp_char_differs __ARGS((int, int)); | |
5248 | |
5249 /* | |
5250 * 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
|
5251 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5252 */ |
5253 static int | |
5254 comp_char_differs(off_from, off_to) | |
5255 int off_from; | |
5256 int off_to; | |
5257 { | |
5258 int i; | |
5259 | |
5260 for (i = 0; i < Screen_mco; ++i) | |
5261 { | |
5262 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5263 return TRUE; | |
5264 if (ScreenLinesC[i][off_from] == 0) | |
5265 break; | |
5266 } | |
5267 return FALSE; | |
5268 } | |
5269 #endif | |
5270 | |
7 | 5271 /* |
5272 * Check whether the given character needs redrawing: | |
5273 * - the (first byte of the) character is different | |
5274 * - the attributes are different | |
5275 * - the character is multi-byte and the next byte is different | |
1616 | 5276 * - the character is two cells wide and the second cell differs. |
7 | 5277 */ |
5278 static int | |
5279 char_needs_redraw(off_from, off_to, cols) | |
5280 int off_from; | |
5281 int off_to; | |
5282 int cols; | |
5283 { | |
5284 if (cols > 0 | |
5285 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5286 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5287 | |
5288 #ifdef FEAT_MBYTE | |
5289 || (enc_dbcs != 0 | |
5290 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5291 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5292 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5293 : (cols > 1 && ScreenLines[off_from + 1] | |
5294 != ScreenLines[off_to + 1]))) | |
5295 || (enc_utf8 | |
5296 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5297 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5298 && comp_char_differs(off_from, off_to)) |
5299 || (cols > 1 && ScreenLines[off_from + 1] | |
5300 != ScreenLines[off_to + 1]))) | |
7 | 5301 #endif |
5302 )) | |
5303 return TRUE; | |
5304 return FALSE; | |
5305 } | |
5306 | |
5307 /* | |
5308 * Move one "cooked" screen line to the screen, but only the characters that | |
5309 * have actually changed. Handle insert/delete character. | |
5310 * "coloff" gives the first column on the screen for this line. | |
5311 * "endcol" gives the columns where valid characters are. | |
5312 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5313 * needs to be cleared, negative otherwise. | |
5314 * "rlflag" is TRUE in a rightleft window: | |
5315 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5316 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5317 */ | |
5318 static void | |
5319 screen_line(row, coloff, endcol, clear_width | |
5320 #ifdef FEAT_RIGHTLEFT | |
5321 , rlflag | |
5322 #endif | |
5323 ) | |
5324 int row; | |
5325 int coloff; | |
5326 int endcol; | |
5327 int clear_width; | |
5328 #ifdef FEAT_RIGHTLEFT | |
5329 int rlflag; | |
5330 #endif | |
5331 { | |
5332 unsigned off_from; | |
5333 unsigned off_to; | |
1378 | 5334 #ifdef FEAT_MBYTE |
5335 unsigned max_off_from; | |
5336 unsigned max_off_to; | |
5337 #endif | |
7 | 5338 int col = 0; |
5339 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5340 int hl; | |
5341 #endif | |
5342 int force = FALSE; /* force update rest of the line */ | |
5343 int redraw_this /* bool: does character need redraw? */ | |
5344 #ifdef FEAT_GUI | |
5345 = TRUE /* For GUI when while-loop empty */ | |
5346 #endif | |
5347 ; | |
5348 int redraw_next; /* redraw_this for next character */ | |
5349 #ifdef FEAT_MBYTE | |
5350 int clear_next = FALSE; | |
5351 int char_cells; /* 1: normal char */ | |
5352 /* 2: occupies two display cells */ | |
5353 # define CHAR_CELLS char_cells | |
5354 #else | |
5355 # define CHAR_CELLS 1 | |
5356 #endif | |
5357 | |
5358 # ifdef FEAT_CLIPBOARD | |
5359 clip_may_clear_selection(row, row); | |
5360 # endif | |
5361 | |
5362 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5363 off_to = LineOffset[row] + coloff; | |
1378 | 5364 #ifdef FEAT_MBYTE |
5365 max_off_from = off_from + screen_Columns; | |
5366 max_off_to = LineOffset[row] + screen_Columns; | |
5367 #endif | |
7 | 5368 |
5369 #ifdef FEAT_RIGHTLEFT | |
5370 if (rlflag) | |
5371 { | |
5372 /* Clear rest first, because it's left of the text. */ | |
5373 if (clear_width > 0) | |
5374 { | |
5375 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5376 && ScreenAttrs[off_to] == 0 | |
5377 # ifdef FEAT_MBYTE | |
5378 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5379 # endif | |
5380 ) | |
5381 { | |
5382 ++off_to; | |
5383 ++col; | |
5384 } | |
5385 if (col <= endcol) | |
5386 screen_fill(row, row + 1, col + coloff, | |
5387 endcol + coloff + 1, ' ', ' ', 0); | |
5388 } | |
5389 col = endcol + 1; | |
5390 off_to = LineOffset[row] + col + coloff; | |
5391 off_from += col; | |
5392 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5393 } | |
5394 #endif /* FEAT_RIGHTLEFT */ | |
5395 | |
5396 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5397 | |
5398 while (col < endcol) | |
5399 { | |
5400 #ifdef FEAT_MBYTE | |
5401 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5402 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5403 else |
5404 char_cells = 1; | |
5405 #endif | |
5406 | |
5407 redraw_this = redraw_next; | |
5408 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5409 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5410 | |
5411 #ifdef FEAT_GUI | |
5412 /* If the next character was bold, then redraw the current character to | |
5413 * remove any pixels that might have spilt over into us. This only | |
5414 * happens in the GUI. | |
5415 */ | |
5416 if (redraw_next && gui.in_use) | |
5417 { | |
5418 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5419 if (hl > HL_ALL) |
5420 hl = syn_attr2attr(hl); | |
5421 if (hl & HL_BOLD) | |
7 | 5422 redraw_this = TRUE; |
5423 } | |
5424 #endif | |
5425 | |
5426 if (redraw_this) | |
5427 { | |
5428 /* | |
5429 * Special handling when 'xs' termcap flag set (hpterm): | |
5430 * Attributes for characters are stored at the position where the | |
5431 * cursor is when writing the highlighting code. The | |
5432 * start-highlighting code must be written with the cursor on the | |
5433 * first highlighted character. The stop-highlighting code must | |
5434 * be written with the cursor just after the last highlighted | |
5435 * character. | |
5436 * Overwriting a character doesn't remove it's highlighting. Need | |
5437 * to clear the rest of the line, and force redrawing it | |
5438 * completely. | |
5439 */ | |
5440 if ( p_wiv | |
5441 && !force | |
5442 #ifdef FEAT_GUI | |
5443 && !gui.in_use | |
5444 #endif | |
5445 && ScreenAttrs[off_to] != 0 | |
5446 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5447 { | |
5448 /* | |
5449 * Need to remove highlighting attributes here. | |
5450 */ | |
5451 windgoto(row, col + coloff); | |
5452 out_str(T_CE); /* clear rest of this screen line */ | |
5453 screen_start(); /* don't know where cursor is now */ | |
5454 force = TRUE; /* force redraw of rest of the line */ | |
5455 redraw_next = TRUE; /* or else next char would miss out */ | |
5456 | |
5457 /* | |
5458 * If the previous character was highlighted, need to stop | |
5459 * highlighting at this character. | |
5460 */ | |
5461 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5462 { | |
5463 screen_attr = ScreenAttrs[off_to - 1]; | |
5464 term_windgoto(row, col + coloff); | |
5465 screen_stop_highlight(); | |
5466 } | |
5467 else | |
5468 screen_attr = 0; /* highlighting has stopped */ | |
5469 } | |
5470 #ifdef FEAT_MBYTE | |
5471 if (enc_dbcs != 0) | |
5472 { | |
5473 /* Check if overwriting a double-byte with a single-byte or | |
5474 * the other way around requires another character to be | |
5475 * redrawn. For UTF-8 this isn't needed, because comparing | |
5476 * ScreenLinesUC[] is sufficient. */ | |
5477 if (char_cells == 1 | |
5478 && col + 1 < endcol | |
1378 | 5479 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5480 { |
5481 /* Writing a single-cell character over a double-cell | |
5482 * character: need to redraw the next cell. */ | |
5483 ScreenLines[off_to + 1] = 0; | |
5484 redraw_next = TRUE; | |
5485 } | |
5486 else if (char_cells == 2 | |
5487 && col + 2 < endcol | |
1378 | 5488 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5489 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5490 { |
5491 /* Writing the second half of a double-cell character over | |
5492 * a double-cell character: need to redraw the second | |
5493 * cell. */ | |
5494 ScreenLines[off_to + 2] = 0; | |
5495 redraw_next = TRUE; | |
5496 } | |
5497 | |
5498 if (enc_dbcs == DBCS_JPNU) | |
5499 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5500 } | |
5501 /* When writing a single-width character over a double-width | |
5502 * character and at the end of the redrawn text, need to clear out | |
5503 * the right halve of the old character. | |
5504 * Also required when writing the right halve of a double-width | |
5505 * char over the left halve of an existing one. */ | |
5506 if (has_mbyte && col + char_cells == endcol | |
5507 && ((char_cells == 1 | |
1378 | 5508 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5509 || (char_cells == 2 |
1378 | 5510 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5511 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5512 clear_next = TRUE; |
5513 #endif | |
5514 | |
5515 ScreenLines[off_to] = ScreenLines[off_from]; | |
5516 #ifdef FEAT_MBYTE | |
5517 if (enc_utf8) | |
5518 { | |
5519 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5520 if (ScreenLinesUC[off_from] != 0) | |
5521 { | |
714 | 5522 int i; |
5523 | |
5524 for (i = 0; i < Screen_mco; ++i) | |
5525 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5526 } |
5527 } | |
5528 if (char_cells == 2) | |
5529 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5530 #endif | |
5531 | |
5532 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5533 /* The bold trick makes a single column of pixels appear in the |
5534 * next character. When a bold character is removed, the next | |
7 | 5535 * character should be redrawn too. This happens for our own GUI |
5536 * and for some xterms. */ | |
5537 if ( | |
5538 # ifdef FEAT_GUI | |
5539 gui.in_use | |
5540 # endif | |
5541 # if defined(FEAT_GUI) && defined(UNIX) | |
5542 || | |
5543 # endif | |
5544 # ifdef UNIX | |
5545 term_is_xterm | |
5546 # endif | |
5547 ) | |
5548 { | |
5549 hl = ScreenAttrs[off_to]; | |
743 | 5550 if (hl > HL_ALL) |
5551 hl = syn_attr2attr(hl); | |
5552 if (hl & HL_BOLD) | |
7 | 5553 redraw_next = TRUE; |
5554 } | |
5555 #endif | |
5556 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5557 #ifdef FEAT_MBYTE | |
819 | 5558 /* For simplicity set the attributes of second half of a |
5559 * double-wide character equal to the first half. */ | |
5560 if (char_cells == 2) | |
5561 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5562 | |
7 | 5563 if (enc_dbcs != 0 && char_cells == 2) |
5564 screen_char_2(off_to, row, col + coloff); | |
5565 else | |
5566 #endif | |
5567 screen_char(off_to, row, col + coloff); | |
5568 } | |
5569 else if ( p_wiv | |
5570 #ifdef FEAT_GUI | |
5571 && !gui.in_use | |
5572 #endif | |
5573 && col + coloff > 0) | |
5574 { | |
5575 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5576 { | |
5577 /* | |
5578 * Don't output stop-highlight when moving the cursor, it will | |
5579 * stop the highlighting when it should continue. | |
5580 */ | |
5581 screen_attr = 0; | |
5582 } | |
5583 else if (screen_attr != 0) | |
5584 screen_stop_highlight(); | |
5585 } | |
5586 | |
5587 off_to += CHAR_CELLS; | |
5588 off_from += CHAR_CELLS; | |
5589 col += CHAR_CELLS; | |
5590 } | |
5591 | |
5592 #ifdef FEAT_MBYTE | |
5593 if (clear_next) | |
5594 { | |
5595 /* Clear the second half of a double-wide character of which the left | |
5596 * half was overwritten with a single-wide character. */ | |
5597 ScreenLines[off_to] = ' '; | |
5598 if (enc_utf8) | |
5599 ScreenLinesUC[off_to] = 0; | |
5600 screen_char(off_to, row, col + coloff); | |
5601 } | |
5602 #endif | |
5603 | |
5604 if (clear_width > 0 | |
5605 #ifdef FEAT_RIGHTLEFT | |
5606 && !rlflag | |
5607 #endif | |
5608 ) | |
5609 { | |
5610 #ifdef FEAT_GUI | |
5611 int startCol = col; | |
5612 #endif | |
5613 | |
5614 /* blank out the rest of the line */ | |
5615 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5616 && ScreenAttrs[off_to] == 0 | |
5617 #ifdef FEAT_MBYTE | |
5618 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5619 #endif | |
5620 ) | |
5621 { | |
5622 ++off_to; | |
5623 ++col; | |
5624 } | |
5625 if (col < clear_width) | |
5626 { | |
5627 #ifdef FEAT_GUI | |
5628 /* | |
5629 * In the GUI, clearing the rest of the line may leave pixels | |
5630 * behind if the first character cleared was bold. Some bold | |
5631 * fonts spill over the left. In this case we redraw the previous | |
5632 * character too. If we didn't skip any blanks above, then we | |
5633 * only redraw if the character wasn't already redrawn anyway. | |
5634 */ | |
996 | 5635 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5636 { |
5637 hl = ScreenAttrs[off_to]; | |
5638 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5639 { |
5640 int prev_cells = 1; | |
5641 # ifdef FEAT_MBYTE | |
5642 if (enc_utf8) | |
5643 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5644 * that its width is 2. */ | |
5645 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5646 else if (enc_dbcs != 0) | |
5647 { | |
5648 /* find previous character by counting from first | |
5649 * column and get its width. */ | |
5650 unsigned off = LineOffset[row]; | |
1378 | 5651 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5652 |
5653 while (off < off_to) | |
5654 { | |
1378 | 5655 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5656 off += prev_cells; |
5657 } | |
5658 } | |
5659 | |
5660 if (enc_dbcs != 0 && prev_cells > 1) | |
5661 screen_char_2(off_to - prev_cells, row, | |
5662 col + coloff - prev_cells); | |
5663 else | |
5664 # endif | |
5665 screen_char(off_to - prev_cells, row, | |
5666 col + coloff - prev_cells); | |
5667 } | |
7 | 5668 } |
5669 #endif | |
5670 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5671 ' ', ' ', 0); | |
5672 #ifdef FEAT_VERTSPLIT | |
5673 off_to += clear_width - col; | |
5674 col = clear_width; | |
5675 #endif | |
5676 } | |
5677 } | |
5678 | |
5679 if (clear_width > 0) | |
5680 { | |
5681 #ifdef FEAT_VERTSPLIT | |
5682 /* For a window that's left of another, draw the separator char. */ | |
5683 if (col + coloff < Columns) | |
5684 { | |
5685 int c; | |
5686 | |
5687 c = fillchar_vsep(&hl); | |
5688 if (ScreenLines[off_to] != c | |
5689 # ifdef FEAT_MBYTE | |
714 | 5690 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5691 != (c >= 0x80 ? c : 0)) | |
7 | 5692 # endif |
5693 || ScreenAttrs[off_to] != hl) | |
5694 { | |
5695 ScreenLines[off_to] = c; | |
5696 ScreenAttrs[off_to] = hl; | |
5697 # ifdef FEAT_MBYTE | |
5698 if (enc_utf8) | |
5699 { | |
5700 if (c >= 0x80) | |
5701 { | |
5702 ScreenLinesUC[off_to] = c; | |
714 | 5703 ScreenLinesC[0][off_to] = 0; |
7 | 5704 } |
5705 else | |
5706 ScreenLinesUC[off_to] = 0; | |
5707 } | |
5708 # endif | |
5709 screen_char(off_to, row, col + coloff); | |
5710 } | |
5711 } | |
5712 else | |
5713 #endif | |
5714 LineWraps[row] = FALSE; | |
5715 } | |
5716 } | |
5717 | |
474 | 5718 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5719 /* |
474 | 5720 * Mirror text "str" for right-left displaying. |
5721 * Only works for single-byte characters (e.g., numbers). | |
7 | 5722 */ |
474 | 5723 void |
7 | 5724 rl_mirror(str) |
5725 char_u *str; | |
5726 { | |
5727 char_u *p1, *p2; | |
5728 int t; | |
5729 | |
5730 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5731 { | |
5732 t = *p1; | |
5733 *p1 = *p2; | |
5734 *p2 = t; | |
5735 } | |
5736 } | |
5737 #endif | |
5738 | |
5739 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5740 /* | |
5741 * mark all status lines for redraw; used after first :cd | |
5742 */ | |
5743 void | |
5744 status_redraw_all() | |
5745 { | |
5746 win_T *wp; | |
5747 | |
5748 for (wp = firstwin; wp; wp = wp->w_next) | |
5749 if (wp->w_status_height) | |
5750 { | |
5751 wp->w_redr_status = TRUE; | |
5752 redraw_later(VALID); | |
5753 } | |
5754 } | |
5755 | |
5756 /* | |
5757 * mark all status lines of the current buffer for redraw | |
5758 */ | |
5759 void | |
5760 status_redraw_curbuf() | |
5761 { | |
5762 win_T *wp; | |
5763 | |
5764 for (wp = firstwin; wp; wp = wp->w_next) | |
5765 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5766 { | |
5767 wp->w_redr_status = TRUE; | |
5768 redraw_later(VALID); | |
5769 } | |
5770 } | |
5771 | |
5772 /* | |
5773 * Redraw all status lines that need to be redrawn. | |
5774 */ | |
5775 void | |
5776 redraw_statuslines() | |
5777 { | |
5778 win_T *wp; | |
5779 | |
5780 for (wp = firstwin; wp; wp = wp->w_next) | |
5781 if (wp->w_redr_status) | |
5782 win_redr_status(wp); | |
673 | 5783 if (redraw_tabline) |
677 | 5784 draw_tabline(); |
7 | 5785 } |
5786 #endif | |
5787 | |
5788 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5789 /* | |
5790 * Redraw all status lines at the bottom of frame "frp". | |
5791 */ | |
5792 void | |
5793 win_redraw_last_status(frp) | |
5794 frame_T *frp; | |
5795 { | |
5796 if (frp->fr_layout == FR_LEAF) | |
5797 frp->fr_win->w_redr_status = TRUE; | |
5798 else if (frp->fr_layout == FR_ROW) | |
5799 { | |
5800 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5801 win_redraw_last_status(frp); | |
5802 } | |
5803 else /* frp->fr_layout == FR_COL */ | |
5804 { | |
5805 frp = frp->fr_child; | |
5806 while (frp->fr_next != NULL) | |
5807 frp = frp->fr_next; | |
5808 win_redraw_last_status(frp); | |
5809 } | |
5810 } | |
5811 #endif | |
5812 | |
5813 #ifdef FEAT_VERTSPLIT | |
5814 /* | |
5815 * Draw the verticap separator right of window "wp" starting with line "row". | |
5816 */ | |
5817 static void | |
5818 draw_vsep_win(wp, row) | |
5819 win_T *wp; | |
5820 int row; | |
5821 { | |
5822 int hl; | |
5823 int c; | |
5824 | |
5825 if (wp->w_vsep_width) | |
5826 { | |
5827 /* draw the vertical separator right of this window */ | |
5828 c = fillchar_vsep(&hl); | |
5829 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5830 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5831 c, ' ', hl); | |
5832 } | |
5833 } | |
5834 #endif | |
5835 | |
5836 #ifdef FEAT_WILDMENU | |
5837 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5838 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5839 |
5840 /* | |
1378 | 5841 * Get the length of an item as it will be shown in the status line. |
7 | 5842 */ |
5843 static int | |
5844 status_match_len(xp, s) | |
5845 expand_T *xp; | |
5846 char_u *s; | |
5847 { | |
5848 int len = 0; | |
5849 | |
5850 #ifdef FEAT_MENU | |
5851 int emenu = (xp->xp_context == EXPAND_MENUS | |
5852 || xp->xp_context == EXPAND_MENUNAMES); | |
5853 | |
5854 /* Check for menu separators - replace with '|'. */ | |
5855 if (emenu && menu_is_separator(s)) | |
5856 return 1; | |
5857 #endif | |
5858 | |
5859 while (*s != NUL) | |
5860 { | |
1685 | 5861 s += skip_status_match_char(xp, s); |
42 | 5862 len += ptr2cells(s); |
39 | 5863 mb_ptr_adv(s); |
7 | 5864 } |
5865 | |
5866 return len; | |
5867 } | |
5868 | |
5869 /* | |
1685 | 5870 * Return the number of characters that should be skipped in a status match. |
277 | 5871 * These are backslashes used for escaping. Do show backslashes in help tags. |
5872 */ | |
5873 static int | |
5874 skip_status_match_char(xp, s) | |
5875 expand_T *xp; | |
5876 char_u *s; | |
5877 { | |
1685 | 5878 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5879 #ifdef FEAT_MENU |
5880 || ((xp->xp_context == EXPAND_MENUS | |
5881 || xp->xp_context == EXPAND_MENUNAMES) | |
5882 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5883 #endif | |
1685 | 5884 ) |
5885 { | |
5886 #ifndef BACKSLASH_IN_FILENAME | |
5887 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5888 return 2; | |
5889 #endif | |
5890 return 1; | |
5891 } | |
5892 return 0; | |
277 | 5893 } |
5894 | |
5895 /* | |
7 | 5896 * Show wildchar matches in the status line. |
5897 * Show at least the "match" item. | |
5898 * We start at item 'first_match' in the list and show all matches that fit. | |
5899 * | |
5900 * If inversion is possible we use it. Else '=' characters are used. | |
5901 */ | |
5902 void | |
5903 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5904 expand_T *xp; | |
5905 int num_matches; | |
5906 char_u **matches; /* list of matches */ | |
5907 int match; | |
5908 int showtail; | |
5909 { | |
5910 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5911 int row; | |
5912 char_u *buf; | |
5913 int len; | |
1378 | 5914 int clen; /* length in screen cells */ |
7 | 5915 int fillchar; |
5916 int attr; | |
5917 int i; | |
5918 int highlight = TRUE; | |
5919 char_u *selstart = NULL; | |
5920 int selstart_col = 0; | |
5921 char_u *selend = NULL; | |
5922 static int first_match = 0; | |
5923 int add_left = FALSE; | |
5924 char_u *s; | |
5925 #ifdef FEAT_MENU | |
5926 int emenu; | |
5927 #endif | |
5928 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5929 int l; | |
5930 #endif | |
5931 | |
5932 if (matches == NULL) /* interrupted completion? */ | |
5933 return; | |
5934 | |
39 | 5935 #ifdef FEAT_MBYTE |
5936 if (has_mbyte) | |
5937 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5938 else | |
5939 #endif | |
5940 buf = alloc((unsigned)Columns + 1); | |
7 | 5941 if (buf == NULL) |
5942 return; | |
5943 | |
5944 if (match == -1) /* don't show match but original text */ | |
5945 { | |
5946 match = 0; | |
5947 highlight = FALSE; | |
5948 } | |
5949 /* count 1 for the ending ">" */ | |
5950 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5951 if (match == 0) | |
5952 first_match = 0; | |
5953 else if (match < first_match) | |
5954 { | |
5955 /* jumping left, as far as we can go */ | |
5956 first_match = match; | |
5957 add_left = TRUE; | |
5958 } | |
5959 else | |
5960 { | |
5961 /* check if match fits on the screen */ | |
5962 for (i = first_match; i < match; ++i) | |
5963 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5964 if (first_match > 0) | |
5965 clen += 2; | |
5966 /* jumping right, put match at the left */ | |
5967 if ((long)clen > Columns) | |
5968 { | |
5969 first_match = match; | |
5970 /* if showing the last match, we can add some on the left */ | |
5971 clen = 2; | |
5972 for (i = match; i < num_matches; ++i) | |
5973 { | |
5974 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5975 if ((long)clen >= Columns) | |
5976 break; | |
5977 } | |
5978 if (i == num_matches) | |
5979 add_left = TRUE; | |
5980 } | |
5981 } | |
5982 if (add_left) | |
5983 while (first_match > 0) | |
5984 { | |
5985 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5986 if ((long)clen >= Columns) | |
5987 break; | |
5988 --first_match; | |
5989 } | |
5990 | |
5991 fillchar = fillchar_status(&attr, TRUE); | |
5992 | |
5993 if (first_match == 0) | |
5994 { | |
5995 *buf = NUL; | |
5996 len = 0; | |
5997 } | |
5998 else | |
5999 { | |
6000 STRCPY(buf, "< "); | |
6001 len = 2; | |
6002 } | |
6003 clen = len; | |
6004 | |
6005 i = first_match; | |
6006 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
6007 { | |
6008 if (i == match) | |
6009 { | |
6010 selstart = buf + len; | |
6011 selstart_col = clen; | |
6012 } | |
6013 | |
6014 s = L_MATCH(i); | |
6015 /* Check for menu separators - replace with '|' */ | |
6016 #ifdef FEAT_MENU | |
6017 emenu = (xp->xp_context == EXPAND_MENUS | |
6018 || xp->xp_context == EXPAND_MENUNAMES); | |
6019 if (emenu && menu_is_separator(s)) | |
6020 { | |
6021 STRCPY(buf + len, transchar('|')); | |
6022 l = (int)STRLEN(buf + len); | |
6023 len += l; | |
6024 clen += l; | |
6025 } | |
6026 else | |
6027 #endif | |
6028 for ( ; *s != NUL; ++s) | |
6029 { | |
1685 | 6030 s += skip_status_match_char(xp, s); |
7 | 6031 clen += ptr2cells(s); |
6032 #ifdef FEAT_MBYTE | |
474 | 6033 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 6034 { |
6035 STRNCPY(buf + len, s, l); | |
6036 s += l - 1; | |
6037 len += l; | |
6038 } | |
6039 else | |
6040 #endif | |
6041 { | |
6042 STRCPY(buf + len, transchar_byte(*s)); | |
6043 len += (int)STRLEN(buf + len); | |
6044 } | |
6045 } | |
6046 if (i == match) | |
6047 selend = buf + len; | |
6048 | |
6049 *(buf + len++) = ' '; | |
6050 *(buf + len++) = ' '; | |
6051 clen += 2; | |
6052 if (++i == num_matches) | |
6053 break; | |
6054 } | |
6055 | |
6056 if (i != num_matches) | |
6057 { | |
6058 *(buf + len++) = '>'; | |
6059 ++clen; | |
6060 } | |
6061 | |
6062 buf[len] = NUL; | |
6063 | |
6064 row = cmdline_row - 1; | |
6065 if (row >= 0) | |
6066 { | |
6067 if (wild_menu_showing == 0) | |
6068 { | |
6069 if (msg_scrolled > 0) | |
6070 { | |
6071 /* Put the wildmenu just above the command line. If there is | |
6072 * no room, scroll the screen one line up. */ | |
6073 if (cmdline_row == Rows - 1) | |
6074 { | |
6075 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6076 ++msg_scrolled; | |
6077 } | |
6078 else | |
6079 { | |
6080 ++cmdline_row; | |
6081 ++row; | |
6082 } | |
6083 wild_menu_showing = WM_SCROLLED; | |
6084 } | |
6085 else | |
6086 { | |
6087 /* Create status line if needed by setting 'laststatus' to 2. | |
6088 * Set 'winminheight' to zero to avoid that the window is | |
6089 * resized. */ | |
6090 if (lastwin->w_status_height == 0) | |
6091 { | |
6092 save_p_ls = p_ls; | |
6093 save_p_wmh = p_wmh; | |
6094 p_ls = 2; | |
6095 p_wmh = 0; | |
6096 last_status(FALSE); | |
6097 } | |
6098 wild_menu_showing = WM_SHOWN; | |
6099 } | |
6100 } | |
6101 | |
6102 screen_puts(buf, row, 0, attr); | |
6103 if (selstart != NULL && highlight) | |
6104 { | |
6105 *selend = NUL; | |
6106 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6107 } | |
6108 | |
6109 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6110 } | |
6111 | |
6112 #ifdef FEAT_VERTSPLIT | |
6113 win_redraw_last_status(topframe); | |
6114 #else | |
6115 lastwin->w_redr_status = TRUE; | |
6116 #endif | |
6117 vim_free(buf); | |
6118 } | |
6119 #endif | |
6120 | |
6121 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6122 /* | |
6123 * Redraw the status line of window wp. | |
6124 * | |
6125 * If inversion is possible we use it. Else '=' characters are used. | |
6126 */ | |
6127 void | |
6128 win_redr_status(wp) | |
6129 win_T *wp; | |
6130 { | |
6131 int row; | |
6132 char_u *p; | |
6133 int len; | |
6134 int fillchar; | |
6135 int attr; | |
6136 int this_ru_col; | |
1910 | 6137 static int busy = FALSE; |
6138 | |
6139 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6140 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6141 if (busy) | |
6142 return; | |
6143 busy = TRUE; | |
7 | 6144 |
6145 wp->w_redr_status = FALSE; | |
6146 if (wp->w_status_height == 0) | |
6147 { | |
6148 /* no status line, can only be last window */ | |
6149 redraw_cmdline = TRUE; | |
6150 } | |
540 | 6151 else if (!redrawing() |
6152 #ifdef FEAT_INS_EXPAND | |
6153 /* don't update status line when popup menu is visible and may be | |
6154 * drawn over it */ | |
6155 || pum_visible() | |
6156 #endif | |
6157 ) | |
7 | 6158 { |
6159 /* Don't redraw right now, do it later. */ | |
6160 wp->w_redr_status = TRUE; | |
6161 } | |
6162 #ifdef FEAT_STL_OPT | |
40 | 6163 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6164 { |
6165 /* redraw custom status line */ | |
1983 | 6166 redraw_custom_statusline(wp); |
7 | 6167 } |
6168 #endif | |
6169 else | |
6170 { | |
6171 fillchar = fillchar_status(&attr, wp == curwin); | |
6172 | |
685 | 6173 get_trans_bufname(wp->w_buffer); |
7 | 6174 p = NameBuff; |
6175 len = (int)STRLEN(p); | |
6176 | |
6177 if (wp->w_buffer->b_help | |
6178 #ifdef FEAT_QUICKFIX | |
6179 || wp->w_p_pvw | |
6180 #endif | |
6181 || bufIsChanged(wp->w_buffer) | |
6182 || wp->w_buffer->b_p_ro) | |
6183 *(p + len++) = ' '; | |
6184 if (wp->w_buffer->b_help) | |
6185 { | |
809 | 6186 STRCPY(p + len, _("[Help]")); |
7 | 6187 len += (int)STRLEN(p + len); |
6188 } | |
6189 #ifdef FEAT_QUICKFIX | |
6190 if (wp->w_p_pvw) | |
6191 { | |
6192 STRCPY(p + len, _("[Preview]")); | |
6193 len += (int)STRLEN(p + len); | |
6194 } | |
6195 #endif | |
6196 if (bufIsChanged(wp->w_buffer)) | |
6197 { | |
6198 STRCPY(p + len, "[+]"); | |
6199 len += 3; | |
6200 } | |
6201 if (wp->w_buffer->b_p_ro) | |
6202 { | |
6203 STRCPY(p + len, "[RO]"); | |
6204 len += 4; | |
6205 } | |
6206 | |
6207 #ifndef FEAT_VERTSPLIT | |
6208 this_ru_col = ru_col; | |
6209 if (this_ru_col < (Columns + 1) / 2) | |
6210 this_ru_col = (Columns + 1) / 2; | |
6211 #else | |
6212 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6213 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6214 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6215 if (this_ru_col <= 1) | |
6216 { | |
6217 p = (char_u *)"<"; /* No room for file name! */ | |
6218 len = 1; | |
6219 } | |
6220 else | |
6221 #endif | |
6222 #ifdef FEAT_MBYTE | |
6223 if (has_mbyte) | |
6224 { | |
6225 int clen = 0, i; | |
6226 | |
6227 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6228 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6229 |
7 | 6230 /* Find first character that will fit. |
6231 * Going from start to end is much faster for DBCS. */ | |
6232 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6233 i += (*mb_ptr2len)(p + i)) |
7 | 6234 clen -= (*mb_ptr2cells)(p + i); |
6235 len = clen; | |
6236 if (i > 0) | |
6237 { | |
6238 p = p + i - 1; | |
6239 *p = '<'; | |
6240 ++len; | |
6241 } | |
6242 | |
6243 } | |
6244 else | |
6245 #endif | |
6246 if (len > this_ru_col - 1) | |
6247 { | |
6248 p += len - (this_ru_col - 1); | |
6249 *p = '<'; | |
6250 len = this_ru_col - 1; | |
6251 } | |
6252 | |
6253 row = W_WINROW(wp) + wp->w_height; | |
6254 screen_puts(p, row, W_WINCOL(wp), attr); | |
6255 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6256 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6257 | |
6258 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6259 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6260 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6261 - 1 + W_WINCOL(wp)), attr); | |
6262 | |
6263 #ifdef FEAT_CMDL_INFO | |
6264 win_redr_ruler(wp, TRUE); | |
6265 #endif | |
6266 } | |
6267 | |
6268 #ifdef FEAT_VERTSPLIT | |
6269 /* | |
6270 * May need to draw the character below the vertical separator. | |
6271 */ | |
6272 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6273 { | |
6274 if (stl_connected(wp)) | |
6275 fillchar = fillchar_status(&attr, wp == curwin); | |
6276 else | |
6277 fillchar = fillchar_vsep(&attr); | |
6278 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6279 attr); | |
6280 } | |
6281 #endif | |
1910 | 6282 busy = FALSE; |
7 | 6283 } |
6284 | |
680 | 6285 #ifdef FEAT_STL_OPT |
6286 /* | |
6287 * Redraw the status line according to 'statusline' and take care of any | |
6288 * errors encountered. | |
6289 */ | |
6290 static void | |
1983 | 6291 redraw_custom_statusline(wp) |
680 | 6292 win_T *wp; |
6293 { | |
1983 | 6294 static int entered = FALSE; |
6295 int save_called_emsg = called_emsg; | |
6296 | |
6297 /* When called recursively return. This can happen when the statusline | |
6298 * contains an expression that triggers a redraw. */ | |
6299 if (entered) | |
6300 return; | |
6301 entered = TRUE; | |
680 | 6302 |
6303 called_emsg = FALSE; | |
6304 win_redr_custom(wp, FALSE); | |
6305 if (called_emsg) | |
1983 | 6306 { |
6307 /* When there is an error disable the statusline, otherwise the | |
6308 * display is messed up with errors and a redraw triggers the problem | |
6309 * again and again. */ | |
680 | 6310 set_string_option_direct((char_u *)"statusline", -1, |
6311 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6312 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6313 } |
680 | 6314 called_emsg |= save_called_emsg; |
1983 | 6315 entered = FALSE; |
680 | 6316 } |
6317 #endif | |
6318 | |
7 | 6319 # ifdef FEAT_VERTSPLIT |
6320 /* | |
6321 * Return TRUE if the status line of window "wp" is connected to the status | |
6322 * line of the window right of it. If not, then it's a vertical separator. | |
6323 * Only call if (wp->w_vsep_width != 0). | |
6324 */ | |
6325 int | |
6326 stl_connected(wp) | |
6327 win_T *wp; | |
6328 { | |
6329 frame_T *fr; | |
6330 | |
6331 fr = wp->w_frame; | |
6332 while (fr->fr_parent != NULL) | |
6333 { | |
6334 if (fr->fr_parent->fr_layout == FR_COL) | |
6335 { | |
6336 if (fr->fr_next != NULL) | |
6337 break; | |
6338 } | |
6339 else | |
6340 { | |
6341 if (fr->fr_next != NULL) | |
6342 return TRUE; | |
6343 } | |
6344 fr = fr->fr_parent; | |
6345 } | |
6346 return FALSE; | |
6347 } | |
6348 # endif | |
6349 | |
6350 #endif /* FEAT_WINDOWS */ | |
6351 | |
6352 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6353 /* | |
6354 * Get the value to show for the language mappings, active 'keymap'. | |
6355 */ | |
6356 int | |
6357 get_keymap_str(wp, buf, len) | |
6358 win_T *wp; | |
6359 char_u *buf; /* buffer for the result */ | |
6360 int len; /* length of buffer */ | |
6361 { | |
6362 char_u *p; | |
6363 | |
6364 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6365 return FALSE; | |
6366 | |
6367 { | |
6368 #ifdef FEAT_EVAL | |
6369 buf_T *old_curbuf = curbuf; | |
6370 win_T *old_curwin = curwin; | |
6371 char_u *s; | |
6372 | |
6373 curbuf = wp->w_buffer; | |
6374 curwin = wp; | |
6375 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6376 ++emsg_skip; | |
714 | 6377 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6378 --emsg_skip; |
6379 curbuf = old_curbuf; | |
6380 curwin = old_curwin; | |
6381 if (p == NULL || *p == NUL) | |
6382 #endif | |
6383 { | |
6384 #ifdef FEAT_KEYMAP | |
6385 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6386 p = wp->w_buffer->b_p_keymap; | |
6387 else | |
6388 #endif | |
6389 p = (char_u *)"lang"; | |
6390 } | |
6391 if ((int)(STRLEN(p) + 3) < len) | |
6392 sprintf((char *)buf, "<%s>", p); | |
6393 else | |
6394 buf[0] = NUL; | |
6395 #ifdef FEAT_EVAL | |
6396 vim_free(s); | |
6397 #endif | |
6398 } | |
6399 return buf[0] != NUL; | |
6400 } | |
6401 #endif | |
6402 | |
6403 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6404 /* | |
677 | 6405 * Redraw the status line or ruler of window "wp". |
6406 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6407 */ |
6408 static void | |
574 | 6409 win_redr_custom(wp, draw_ruler) |
7 | 6410 win_T *wp; |
574 | 6411 int draw_ruler; /* TRUE or FALSE */ |
7 | 6412 { |
6413 int attr; | |
6414 int curattr; | |
6415 int row; | |
6416 int col = 0; | |
6417 int maxwidth; | |
6418 int width; | |
6419 int n; | |
6420 int len; | |
6421 int fillchar; | |
6422 char_u buf[MAXPATHL]; | |
1983 | 6423 char_u *stl; |
7 | 6424 char_u *p; |
681 | 6425 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6426 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6427 int use_sandbox = FALSE; |
7 | 6428 |
6429 /* setup environment for the task at hand */ | |
677 | 6430 if (wp == NULL) |
6431 { | |
6432 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6433 stl = p_tal; |
677 | 6434 row = 0; |
707 | 6435 fillchar = ' '; |
677 | 6436 attr = hl_attr(HLF_TPF); |
6437 maxwidth = Columns; | |
6438 # ifdef FEAT_EVAL | |
681 | 6439 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6440 # endif |
6441 } | |
40 | 6442 else |
677 | 6443 { |
6444 row = W_WINROW(wp) + wp->w_height; | |
6445 fillchar = fillchar_status(&attr, wp == curwin); | |
6446 maxwidth = W_WIDTH(wp); | |
6447 | |
6448 if (draw_ruler) | |
6449 { | |
1983 | 6450 stl = p_ruf; |
677 | 6451 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6452 if (*stl == '%') |
6453 { | |
6454 if (*++stl == '-') | |
6455 stl++; | |
6456 if (atoi((char *)stl)) | |
6457 while (VIM_ISDIGIT(*stl)) | |
6458 stl++; | |
6459 if (*stl++ != '(') | |
6460 stl = p_ruf; | |
677 | 6461 } |
7 | 6462 #ifdef FEAT_VERTSPLIT |
677 | 6463 col = ru_col - (Columns - W_WIDTH(wp)); |
6464 if (col < (W_WIDTH(wp) + 1) / 2) | |
6465 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6466 #else |
677 | 6467 col = ru_col; |
6468 if (col > (Columns + 1) / 2) | |
6469 col = (Columns + 1) / 2; | |
6470 #endif | |
6471 maxwidth = W_WIDTH(wp) - col; | |
7 | 6472 #ifdef FEAT_WINDOWS |
677 | 6473 if (!wp->w_status_height) |
6474 #endif | |
6475 { | |
6476 row = Rows - 1; | |
6477 --maxwidth; /* writing in last column may cause scrolling */ | |
6478 fillchar = ' '; | |
6479 attr = 0; | |
6480 } | |
6481 | |
6482 # ifdef FEAT_EVAL | |
681 | 6483 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6484 # endif |
6485 } | |
6486 else | |
6487 { | |
6488 if (*wp->w_p_stl != NUL) | |
1983 | 6489 stl = wp->w_p_stl; |
677 | 6490 else |
1983 | 6491 stl = p_stl; |
677 | 6492 # ifdef FEAT_EVAL |
681 | 6493 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6494 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6495 # endif |
6496 } | |
6497 | |
6498 #ifdef FEAT_VERTSPLIT | |
6499 col += W_WINCOL(wp); | |
6500 #endif | |
6501 } | |
6502 | |
7 | 6503 if (maxwidth <= 0) |
6504 return; | |
677 | 6505 |
1983 | 6506 /* Make a copy, because the statusline may include a function call that |
6507 * might change the option value and free the memory. */ | |
6508 stl = vim_strsave(stl); | |
677 | 6509 width = build_stl_str_hl(wp == NULL ? curwin : wp, |
6510 buf, sizeof(buf), | |
1983 | 6511 stl, use_sandbox, |
681 | 6512 fillchar, maxwidth, hltab, tabtab); |
1983 | 6513 vim_free(stl); |
835 | 6514 len = (int)STRLEN(buf); |
7 | 6515 |
1883 | 6516 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6517 { |
6518 #ifdef FEAT_MBYTE | |
6519 len += (*mb_char2bytes)(fillchar, buf + len); | |
6520 #else | |
6521 buf[len++] = fillchar; | |
6522 #endif | |
6523 ++width; | |
6524 } | |
6525 buf[len] = NUL; | |
6526 | |
681 | 6527 /* |
6528 * Draw each snippet with the specified highlighting. | |
6529 */ | |
7 | 6530 curattr = attr; |
6531 p = buf; | |
681 | 6532 for (n = 0; hltab[n].start != NULL; n++) |
6533 { | |
6534 len = (int)(hltab[n].start - p); | |
7 | 6535 screen_puts_len(p, len, row, col, curattr); |
6536 col += vim_strnsize(p, len); | |
681 | 6537 p = hltab[n].start; |
6538 | |
6539 if (hltab[n].userhl == 0) | |
7 | 6540 curattr = attr; |
681 | 6541 else if (hltab[n].userhl < 0) |
6542 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6543 #ifdef FEAT_WINDOWS |
680 | 6544 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6545 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6546 #endif |
6547 else | |
681 | 6548 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6549 } |
6550 screen_puts(p, row, col, curattr); | |
681 | 6551 |
6552 if (wp == NULL) | |
6553 { | |
6554 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6555 col = 0; | |
6556 len = 0; | |
6557 p = buf; | |
6558 fillchar = 0; | |
6559 for (n = 0; tabtab[n].start != NULL; n++) | |
6560 { | |
6561 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6562 while (col < len) | |
6563 TabPageIdxs[col++] = fillchar; | |
6564 p = tabtab[n].start; | |
6565 fillchar = tabtab[n].userhl; | |
6566 } | |
6567 while (col < Columns) | |
6568 TabPageIdxs[col++] = fillchar; | |
6569 } | |
7 | 6570 } |
6571 | |
6572 #endif /* FEAT_STL_OPT */ | |
6573 | |
6574 /* | |
6575 * Output a single character directly to the screen and update ScreenLines. | |
6576 */ | |
6577 void | |
6578 screen_putchar(c, row, col, attr) | |
6579 int c; | |
6580 int row, col; | |
6581 int attr; | |
6582 { | |
6583 #ifdef FEAT_MBYTE | |
6584 char_u buf[MB_MAXBYTES + 1]; | |
6585 | |
6586 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6587 #else | |
6588 char_u buf[2]; | |
6589 | |
6590 buf[0] = c; | |
6591 buf[1] = NUL; | |
6592 #endif | |
6593 screen_puts(buf, row, col, attr); | |
6594 } | |
6595 | |
6596 /* | |
6597 * Get a single character directly from ScreenLines into "bytes[]". | |
6598 * Also return its attribute in *attrp; | |
6599 */ | |
6600 void | |
6601 screen_getbytes(row, col, bytes, attrp) | |
6602 int row, col; | |
6603 char_u *bytes; | |
6604 int *attrp; | |
6605 { | |
6606 unsigned off; | |
6607 | |
6608 /* safety check */ | |
6609 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6610 { | |
6611 off = LineOffset[row] + col; | |
6612 *attrp = ScreenAttrs[off]; | |
6613 bytes[0] = ScreenLines[off]; | |
6614 bytes[1] = NUL; | |
6615 | |
6616 #ifdef FEAT_MBYTE | |
6617 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6618 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6619 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6620 { | |
6621 bytes[0] = ScreenLines[off]; | |
6622 bytes[1] = ScreenLines2[off]; | |
6623 bytes[2] = NUL; | |
6624 } | |
6625 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6626 { | |
6627 bytes[1] = ScreenLines[off + 1]; | |
6628 bytes[2] = NUL; | |
6629 } | |
6630 #endif | |
6631 } | |
6632 } | |
6633 | |
714 | 6634 #ifdef FEAT_MBYTE |
6635 static int screen_comp_differs __ARGS((int, int*)); | |
6636 | |
6637 /* | |
6638 * Return TRUE if composing characters for screen posn "off" differs from | |
6639 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6640 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6641 */ |
6642 static int | |
6643 screen_comp_differs(off, u8cc) | |
6644 int off; | |
6645 int *u8cc; | |
6646 { | |
6647 int i; | |
6648 | |
6649 for (i = 0; i < Screen_mco; ++i) | |
6650 { | |
6651 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6652 return TRUE; | |
6653 if (u8cc[i] == 0) | |
6654 break; | |
6655 } | |
6656 return FALSE; | |
6657 } | |
6658 #endif | |
6659 | |
7 | 6660 /* |
6661 * Put string '*text' on the screen at position 'row' and 'col', with | |
6662 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6663 * Note: only outputs within one row, message is truncated at screen boundary! | |
6664 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6665 */ | |
6666 void | |
6667 screen_puts(text, row, col, attr) | |
6668 char_u *text; | |
6669 int row; | |
6670 int col; | |
6671 int attr; | |
6672 { | |
6673 screen_puts_len(text, -1, row, col, attr); | |
6674 } | |
6675 | |
6676 /* | |
6677 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6678 * a NUL. | |
6679 */ | |
6680 void | |
6681 screen_puts_len(text, len, row, col, attr) | |
6682 char_u *text; | |
6683 int len; | |
6684 int row; | |
6685 int col; | |
6686 int attr; | |
6687 { | |
6688 unsigned off; | |
6689 char_u *ptr = text; | |
6690 int c; | |
6691 #ifdef FEAT_MBYTE | |
1378 | 6692 unsigned max_off; |
7 | 6693 int mbyte_blen = 1; |
6694 int mbyte_cells = 1; | |
6695 int u8c = 0; | |
714 | 6696 int u8cc[MAX_MCO]; |
7 | 6697 int clear_next_cell = FALSE; |
6698 # ifdef FEAT_ARABIC | |
6699 int prev_c = 0; /* previous Arabic character */ | |
714 | 6700 int pc, nc, nc1; |
6701 int pcc[MAX_MCO]; | |
7 | 6702 # endif |
6703 #endif | |
1843 | 6704 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6705 int force_redraw_this; | |
6706 int force_redraw_next = FALSE; | |
6707 #endif | |
6708 int need_redraw; | |
7 | 6709 |
6710 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6711 return; | |
1843 | 6712 off = LineOffset[row] + col; |
7 | 6713 |
1668 | 6714 #ifdef FEAT_MBYTE |
6715 /* When drawing over the right halve of a double-wide char clear out the | |
6716 * left halve. Only needed in a terminal. */ | |
1685 | 6717 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6718 # ifdef FEAT_GUI |
6719 && !gui.in_use | |
6720 # endif | |
6721 && mb_fix_col(col, row) != col) | |
1843 | 6722 { |
6723 ScreenLines[off - 1] = ' '; | |
6724 ScreenAttrs[off - 1] = 0; | |
6725 if (enc_utf8) | |
6726 { | |
6727 ScreenLinesUC[off - 1] = 0; | |
6728 ScreenLinesC[0][off - 1] = 0; | |
6729 } | |
6730 /* redraw the previous cell, make it empty */ | |
6731 screen_char(off - 1, row, col - 1); | |
6732 /* force the cell at "col" to be redrawn */ | |
6733 force_redraw_next = TRUE; | |
6734 } | |
6735 #endif | |
6736 | |
1378 | 6737 #ifdef FEAT_MBYTE |
6738 max_off = LineOffset[row] + screen_Columns; | |
6739 #endif | |
1340 | 6740 while (col < screen_Columns |
6741 && (len < 0 || (int)(ptr - text) < len) | |
6742 && *ptr != NUL) | |
7 | 6743 { |
6744 c = *ptr; | |
6745 #ifdef FEAT_MBYTE | |
6746 /* check if this is the first byte of a multibyte */ | |
6747 if (has_mbyte) | |
6748 { | |
6749 if (enc_utf8 && len > 0) | |
474 | 6750 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6751 else |
474 | 6752 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6753 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6754 mbyte_cells = 1; | |
6755 else if (enc_dbcs != 0) | |
6756 mbyte_cells = mbyte_blen; | |
6757 else /* enc_utf8 */ | |
6758 { | |
6759 if (len >= 0) | |
714 | 6760 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6761 (int)((text + len) - ptr)); |
6762 else | |
714 | 6763 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6764 mbyte_cells = utf_char2cells(u8c); |
1401 | 6765 # ifdef UNICODE16 |
7 | 6766 /* Non-BMP character: display as ? or fullwidth ?. */ |
6767 if (u8c >= 0x10000) | |
6768 { | |
6769 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6770 if (attr == 0) | |
6771 attr = hl_attr(HLF_8); | |
6772 } | |
1401 | 6773 # endif |
7 | 6774 # ifdef FEAT_ARABIC |
6775 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6776 { | |
6777 /* Do Arabic shaping. */ | |
6778 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6779 { | |
6780 /* Past end of string to be displayed. */ | |
6781 nc = NUL; | |
6782 nc1 = NUL; | |
6783 } | |
6784 else | |
714 | 6785 { |
1994 | 6786 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6787 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6788 nc1 = pcc[0]; |
6789 } | |
7 | 6790 pc = prev_c; |
6791 prev_c = u8c; | |
714 | 6792 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6793 } |
6794 else | |
6795 prev_c = u8c; | |
6796 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6797 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6798 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6799 /* 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
|
6800 * 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
|
6801 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6802 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6803 } |
7 | 6804 } |
6805 } | |
6806 #endif | |
6807 | |
1843 | 6808 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6809 force_redraw_this = force_redraw_next; | |
6810 force_redraw_next = FALSE; | |
6811 #endif | |
6812 | |
6813 need_redraw = ScreenLines[off] != c | |
7 | 6814 #ifdef FEAT_MBYTE |
6815 || (mbyte_cells == 2 | |
6816 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6817 || (enc_dbcs == DBCS_JPNU | |
6818 && c == 0x8e | |
6819 && ScreenLines2[off] != ptr[1]) | |
6820 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6821 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6822 (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
|
6823 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6824 && screen_comp_differs(off, u8cc)))) |
7 | 6825 #endif |
6826 || ScreenAttrs[off] != attr | |
1843 | 6827 || exmode_active; |
6828 | |
6829 if (need_redraw | |
6830 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6831 || force_redraw_this | |
6832 #endif | |
7 | 6833 ) |
6834 { | |
6835 #if defined(FEAT_GUI) || defined(UNIX) | |
6836 /* The bold trick makes a single row of pixels appear in the next | |
6837 * character. When a bold character is removed, the next | |
6838 * character should be redrawn too. This happens for our own GUI | |
1843 | 6839 * and for some xterms. */ |
6840 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6841 # ifdef FEAT_GUI |
6842 gui.in_use | |
6843 # endif | |
6844 # if defined(FEAT_GUI) && defined(UNIX) | |
6845 || | |
6846 # endif | |
6847 # ifdef UNIX | |
6848 term_is_xterm | |
6849 # endif | |
1843 | 6850 )) |
6851 { | |
6852 int n = ScreenAttrs[off]; | |
6853 | |
6854 if (n > HL_ALL) | |
6855 n = syn_attr2attr(n); | |
6856 if (n & HL_BOLD) | |
6857 force_redraw_next = TRUE; | |
7 | 6858 } |
6859 #endif | |
6860 #ifdef FEAT_MBYTE | |
6861 /* When at the end of the text and overwriting a two-cell | |
6862 * character with a one-cell character, need to clear the next | |
6863 * cell. Also when overwriting the left halve of a two-cell char | |
6864 * with the right halve of a two-cell char. Do this only once | |
6865 * (mb_off2cells() may return 2 on the right halve). */ | |
6866 if (clear_next_cell) | |
6867 clear_next_cell = FALSE; | |
6868 else if (has_mbyte | |
6869 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6870 : ptr + mbyte_blen >= text + len) | |
1378 | 6871 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6872 || (mbyte_cells == 2 |
1378 | 6873 && (*mb_off2cells)(off, max_off) == 1 |
6874 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6875 clear_next_cell = TRUE; |
6876 | |
6877 /* Make sure we never leave a second byte of a double-byte behind, | |
6878 * it confuses mb_off2cells(). */ | |
6879 if (enc_dbcs | |
1378 | 6880 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6881 || (mbyte_cells == 2 |
1378 | 6882 && (*mb_off2cells)(off, max_off) == 1 |
6883 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6884 ScreenLines[off + mbyte_blen] = 0; |
6885 #endif | |
6886 ScreenLines[off] = c; | |
6887 ScreenAttrs[off] = attr; | |
6888 #ifdef FEAT_MBYTE | |
6889 if (enc_utf8) | |
6890 { | |
714 | 6891 if (c < 0x80 && u8cc[0] == 0) |
7 | 6892 ScreenLinesUC[off] = 0; |
6893 else | |
6894 { | |
714 | 6895 int i; |
6896 | |
7 | 6897 ScreenLinesUC[off] = u8c; |
714 | 6898 for (i = 0; i < Screen_mco; ++i) |
6899 { | |
6900 ScreenLinesC[i][off] = u8cc[i]; | |
6901 if (u8cc[i] == 0) | |
6902 break; | |
6903 } | |
7 | 6904 } |
6905 if (mbyte_cells == 2) | |
6906 { | |
6907 ScreenLines[off + 1] = 0; | |
6908 ScreenAttrs[off + 1] = attr; | |
6909 } | |
6910 screen_char(off, row, col); | |
6911 } | |
6912 else if (mbyte_cells == 2) | |
6913 { | |
6914 ScreenLines[off + 1] = ptr[1]; | |
6915 ScreenAttrs[off + 1] = attr; | |
6916 screen_char_2(off, row, col); | |
6917 } | |
6918 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6919 { | |
6920 ScreenLines2[off] = ptr[1]; | |
6921 screen_char(off, row, col); | |
6922 } | |
6923 else | |
6924 #endif | |
6925 screen_char(off, row, col); | |
6926 } | |
6927 #ifdef FEAT_MBYTE | |
6928 if (has_mbyte) | |
6929 { | |
6930 off += mbyte_cells; | |
6931 col += mbyte_cells; | |
6932 ptr += mbyte_blen; | |
6933 if (clear_next_cell) | |
6934 ptr = (char_u *)" "; | |
6935 } | |
6936 else | |
6937 #endif | |
6938 { | |
6939 ++off; | |
6940 ++col; | |
6941 ++ptr; | |
6942 } | |
6943 } | |
1843 | 6944 |
6945 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6946 /* If we detected the next character needs to be redrawn, but the text | |
6947 * doesn't extend up to there, update the character here. */ | |
6948 if (force_redraw_next && col < screen_Columns) | |
6949 { | |
6950 # ifdef FEAT_MBYTE | |
6951 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6952 screen_char_2(off, row, col); | |
6953 else | |
6954 # endif | |
6955 screen_char(off, row, col); | |
6956 } | |
6957 #endif | |
7 | 6958 } |
6959 | |
6960 #ifdef FEAT_SEARCH_EXTRA | |
6961 /* | |
1326 | 6962 * Prepare for 'hlsearch' highlighting. |
7 | 6963 */ |
6964 static void | |
6965 start_search_hl() | |
6966 { | |
6967 if (p_hls && !no_hlsearch) | |
6968 { | |
6969 last_pat_prog(&search_hl.rm); | |
6970 search_hl.attr = hl_attr(HLF_L); | |
1521 | 6971 # ifdef FEAT_RELTIME |
6972 /* Set the time limit to 'redrawtime'. */ | |
6973 profile_setlimit(p_rdt, &search_hl.tm); | |
6974 # endif | |
7 | 6975 } |
6976 } | |
6977 | |
6978 /* | |
1326 | 6979 * Clean up for 'hlsearch' highlighting. |
7 | 6980 */ |
6981 static void | |
6982 end_search_hl() | |
6983 { | |
6984 if (search_hl.rm.regprog != NULL) | |
6985 { | |
6986 vim_free(search_hl.rm.regprog); | |
6987 search_hl.rm.regprog = NULL; | |
6988 } | |
6989 } | |
6990 | |
6991 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6992 * Init for calling prepare_search_hl(). |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6993 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6994 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6995 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6996 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6997 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6998 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6999 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7000 /* Setup for match and 'hlsearch' highlighting. Disable any previous |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7001 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7002 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7003 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7004 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7005 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7006 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7007 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7008 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7009 cur->hl.attr = syn_id2attr(cur->hlg_id); |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7010 cur->hl.buf = wp->w_buffer; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7011 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7012 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7013 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7014 /* Set the time limit to 'redrawtime'. */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7015 profile_setlimit(p_rdt, &(cur->hl.tm)); |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7016 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7017 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7018 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7019 search_hl.buf = wp->w_buffer; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7020 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7021 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7022 /* time limit is set at the toplevel, for all windows */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7023 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7024 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7025 /* |
7 | 7026 * Advance to the match in window "wp" line "lnum" or past it. |
7027 */ | |
7028 static void | |
7029 prepare_search_hl(wp, lnum) | |
7030 win_T *wp; | |
7031 linenr_T lnum; | |
7032 { | |
1326 | 7033 matchitem_T *cur; /* points to the match list */ |
7034 match_T *shl; /* points to search_hl or a match */ | |
7035 int shl_flag; /* flag to indicate whether search_hl | |
7036 has been processed or not */ | |
7 | 7037 int n; |
7038 | |
7039 /* | |
7040 * When using a multi-line pattern, start searching at the top | |
7041 * of the window or just after a closed fold. | |
1326 | 7042 * Do this both for search_hl and the match list. |
7 | 7043 */ |
1326 | 7044 cur = wp->w_match_head; |
7045 shl_flag = FALSE; | |
7046 while (cur != NULL || shl_flag == FALSE) | |
7047 { | |
7048 if (shl_flag == FALSE) | |
7049 { | |
7050 shl = &search_hl; | |
7051 shl_flag = TRUE; | |
7052 } | |
7053 else | |
7054 shl = &cur->hl; | |
7 | 7055 if (shl->rm.regprog != NULL |
7056 && shl->lnum == 0 | |
7057 && re_multiline(shl->rm.regprog)) | |
7058 { | |
7059 if (shl->first_lnum == 0) | |
7060 { | |
7061 # ifdef FEAT_FOLDING | |
7062 for (shl->first_lnum = lnum; | |
7063 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7064 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7065 NULL, NULL, TRUE, NULL)) | |
7066 break; | |
7067 # else | |
7068 shl->first_lnum = wp->w_topline; | |
7069 # endif | |
7070 } | |
7071 n = 0; | |
7072 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7073 { | |
7074 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7075 if (shl->lnum != 0) | |
7076 { | |
7077 shl->first_lnum = shl->lnum | |
7078 + shl->rm.endpos[0].lnum | |
7079 - shl->rm.startpos[0].lnum; | |
7080 n = shl->rm.endpos[0].col; | |
7081 } | |
7082 else | |
7083 { | |
7084 ++shl->first_lnum; | |
7085 n = 0; | |
7086 } | |
7087 } | |
7088 } | |
1326 | 7089 if (shl != &search_hl && cur != NULL) |
7090 cur = cur->next; | |
7 | 7091 } |
7092 } | |
7093 | |
7094 /* | |
1326 | 7095 * Search for a next 'hlsearch' or match. |
7 | 7096 * Uses shl->buf. |
7097 * Sets shl->lnum and shl->rm contents. | |
7098 * Note: Assumes a previous match is always before "lnum", unless | |
7099 * shl->lnum is zero. | |
7100 * Careful: Any pointers for buffer lines will become invalid. | |
7101 */ | |
7102 static void | |
7103 next_search_hl(win, shl, lnum, mincol) | |
7104 win_T *win; | |
1326 | 7105 match_T *shl; /* points to search_hl or a match */ |
7 | 7106 linenr_T lnum; |
7107 colnr_T mincol; /* minimal column for a match */ | |
7108 { | |
7109 linenr_T l; | |
7110 colnr_T matchcol; | |
7111 long nmatched; | |
7112 | |
7113 if (shl->lnum != 0) | |
7114 { | |
7115 /* Check for three situations: | |
7116 * 1. If the "lnum" is below a previous match, start a new search. | |
7117 * 2. If the previous match includes "mincol", use it. | |
7118 * 3. Continue after the previous match. | |
7119 */ | |
7120 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7121 if (lnum > l) | |
7122 shl->lnum = 0; | |
7123 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7124 return; | |
7125 } | |
7126 | |
7127 /* | |
7128 * Repeat searching for a match until one is found that includes "mincol" | |
7129 * or none is found in this line. | |
7130 */ | |
7131 called_emsg = FALSE; | |
7132 for (;;) | |
7133 { | |
1521 | 7134 #ifdef FEAT_RELTIME |
7135 /* Stop searching after passing the time limit. */ | |
7136 if (profile_passed_limit(&(shl->tm))) | |
7137 { | |
7138 shl->lnum = 0; /* no match found in time */ | |
7139 break; | |
7140 } | |
7141 #endif | |
7 | 7142 /* Three situations: |
7143 * 1. No useful previous match: search from start of line. | |
7144 * 2. Not Vi compatible or empty match: continue at next character. | |
7145 * Break the loop if this is beyond the end of the line. | |
7146 * 3. Vi compatible searching: continue at end of previous match. | |
7147 */ | |
7148 if (shl->lnum == 0) | |
7149 matchcol = 0; | |
7150 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7151 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7152 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7153 { | |
688 | 7154 char_u *ml; |
685 | 7155 |
7156 matchcol = shl->rm.startpos[0].col; | |
688 | 7157 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7158 if (*ml == NUL) |
7159 { | |
7160 ++matchcol; | |
7 | 7161 shl->lnum = 0; |
7162 break; | |
7163 } | |
685 | 7164 #ifdef FEAT_MBYTE |
7165 if (has_mbyte) | |
7166 matchcol += mb_ptr2len(ml); | |
7167 else | |
7168 #endif | |
7169 ++matchcol; | |
7 | 7170 } |
7171 else | |
7172 matchcol = shl->rm.endpos[0].col; | |
7173 | |
7174 shl->lnum = lnum; | |
1521 | 7175 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7176 #ifdef FEAT_RELTIME | |
7177 &(shl->tm) | |
7178 #else | |
7179 NULL | |
7180 #endif | |
7181 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7182 if (called_emsg || got_int) |
7 | 7183 { |
7184 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7185 if (shl == &search_hl) |
7186 { | |
1326 | 7187 /* don't free regprog in the match list, it's a copy */ |
1112 | 7188 vim_free(shl->rm.regprog); |
7189 no_hlsearch = TRUE; | |
7190 } | |
7 | 7191 shl->rm.regprog = NULL; |
1112 | 7192 shl->lnum = 0; |
7193 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7194 break; |
7195 } | |
7196 if (nmatched == 0) | |
7197 { | |
7198 shl->lnum = 0; /* no match found */ | |
7199 break; | |
7200 } | |
7201 if (shl->rm.startpos[0].lnum > 0 | |
7202 || shl->rm.startpos[0].col >= mincol | |
7203 || nmatched > 1 | |
7204 || shl->rm.endpos[0].col > mincol) | |
7205 { | |
7206 shl->lnum += shl->rm.startpos[0].lnum; | |
7207 break; /* useful match found */ | |
7208 } | |
7209 } | |
7210 } | |
7211 #endif | |
7212 | |
7213 static void | |
7214 screen_start_highlight(attr) | |
7215 int attr; | |
7216 { | |
7217 attrentry_T *aep = NULL; | |
7218 | |
7219 screen_attr = attr; | |
7220 if (full_screen | |
7221 #ifdef WIN3264 | |
7222 && termcap_active | |
7223 #endif | |
7224 ) | |
7225 { | |
7226 #ifdef FEAT_GUI | |
7227 if (gui.in_use) | |
7228 { | |
7229 char buf[20]; | |
7230 | |
681 | 7231 /* The GUI handles this internally. */ |
7232 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7233 OUT_STR(buf); |
7234 } | |
7235 else | |
7236 #endif | |
7237 { | |
7238 if (attr > HL_ALL) /* special HL attr. */ | |
7239 { | |
7240 if (t_colors > 1) | |
7241 aep = syn_cterm_attr2entry(attr); | |
7242 else | |
7243 aep = syn_term_attr2entry(attr); | |
7244 if (aep == NULL) /* did ":syntax clear" */ | |
7245 attr = 0; | |
7246 else | |
7247 attr = aep->ae_attr; | |
7248 } | |
7249 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7250 out_str(T_MD); | |
681 | 7251 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7252 && cterm_normal_fg_bold) | |
7253 /* If the Normal FG color has BOLD attribute and the new HL | |
7254 * has a FG color defined, clear BOLD. */ | |
7255 out_str(T_ME); | |
7 | 7256 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7257 out_str(T_SO); | |
205 | 7258 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7259 /* underline or undercurl */ | |
7 | 7260 out_str(T_US); |
7261 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7262 out_str(T_CZH); | |
7263 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7264 out_str(T_MR); | |
7265 | |
7266 /* | |
7267 * Output the color or start string after bold etc., in case the | |
7268 * bold etc. override the color setting. | |
7269 */ | |
7270 if (aep != NULL) | |
7271 { | |
7272 if (t_colors > 1) | |
7273 { | |
7274 if (aep->ae_u.cterm.fg_color) | |
7275 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7276 if (aep->ae_u.cterm.bg_color) | |
7277 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7278 } | |
7279 else | |
7280 { | |
7281 if (aep->ae_u.term.start != NULL) | |
7282 out_str(aep->ae_u.term.start); | |
7283 } | |
7284 } | |
7285 } | |
7286 } | |
7287 } | |
7288 | |
7289 void | |
7290 screen_stop_highlight() | |
7291 { | |
7292 int do_ME = FALSE; /* output T_ME code */ | |
7293 | |
7294 if (screen_attr != 0 | |
7295 #ifdef WIN3264 | |
7296 && termcap_active | |
7297 #endif | |
7298 ) | |
7299 { | |
7300 #ifdef FEAT_GUI | |
7301 if (gui.in_use) | |
7302 { | |
7303 char buf[20]; | |
7304 | |
7305 /* use internal GUI code */ | |
7306 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7307 OUT_STR(buf); | |
7308 } | |
7309 else | |
7310 #endif | |
7311 { | |
7312 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7313 { | |
7314 attrentry_T *aep; | |
7315 | |
7316 if (t_colors > 1) | |
7317 { | |
7318 /* | |
7319 * Assume that t_me restores the original colors! | |
7320 */ | |
7321 aep = syn_cterm_attr2entry(screen_attr); | |
7322 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7323 || aep->ae_u.cterm.bg_color)) | |
7324 do_ME = TRUE; | |
7325 } | |
7326 else | |
7327 { | |
7328 aep = syn_term_attr2entry(screen_attr); | |
7329 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7330 { | |
7331 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7332 do_ME = TRUE; | |
7333 else | |
7334 out_str(aep->ae_u.term.stop); | |
7335 } | |
7336 } | |
7337 if (aep == NULL) /* did ":syntax clear" */ | |
7338 screen_attr = 0; | |
7339 else | |
7340 screen_attr = aep->ae_attr; | |
7341 } | |
7342 | |
7343 /* | |
7344 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7345 * same sequence several times. | |
7346 */ | |
7347 if (screen_attr & HL_STANDOUT) | |
7348 { | |
7349 if (STRCMP(T_SE, T_ME) == 0) | |
7350 do_ME = TRUE; | |
7351 else | |
7352 out_str(T_SE); | |
7353 } | |
205 | 7354 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7355 { |
7356 if (STRCMP(T_UE, T_ME) == 0) | |
7357 do_ME = TRUE; | |
7358 else | |
7359 out_str(T_UE); | |
7360 } | |
7361 if (screen_attr & HL_ITALIC) | |
7362 { | |
7363 if (STRCMP(T_CZR, T_ME) == 0) | |
7364 do_ME = TRUE; | |
7365 else | |
7366 out_str(T_CZR); | |
7367 } | |
7368 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7369 out_str(T_ME); | |
7370 | |
7371 if (t_colors > 1) | |
7372 { | |
7373 /* set Normal cterm colors */ | |
7374 if (cterm_normal_fg_color != 0) | |
7375 term_fg_color(cterm_normal_fg_color - 1); | |
7376 if (cterm_normal_bg_color != 0) | |
7377 term_bg_color(cterm_normal_bg_color - 1); | |
7378 if (cterm_normal_fg_bold) | |
7379 out_str(T_MD); | |
7380 } | |
7381 } | |
7382 } | |
7383 screen_attr = 0; | |
7384 } | |
7385 | |
7386 /* | |
7387 * Reset the colors for a cterm. Used when leaving Vim. | |
7388 * The machine specific code may override this again. | |
7389 */ | |
7390 void | |
7391 reset_cterm_colors() | |
7392 { | |
7393 if (t_colors > 1) | |
7394 { | |
7395 /* set Normal cterm colors */ | |
7396 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7397 { | |
7398 out_str(T_OP); | |
7399 screen_attr = -1; | |
7400 } | |
7401 if (cterm_normal_fg_bold) | |
7402 { | |
7403 out_str(T_ME); | |
7404 screen_attr = -1; | |
7405 } | |
7406 } | |
7407 } | |
7408 | |
7409 /* | |
7410 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7411 * using the attributes from ScreenAttrs["off"]. | |
7412 */ | |
7413 static void | |
7414 screen_char(off, row, col) | |
7415 unsigned off; | |
7416 int row; | |
7417 int col; | |
7418 { | |
7419 int attr; | |
7420 | |
7421 /* Check for illegal values, just in case (could happen just after | |
7422 * resizing). */ | |
7423 if (row >= screen_Rows || col >= screen_Columns) | |
7424 return; | |
7425 | |
7426 /* Outputting the last character on the screen may scrollup the screen. | |
7427 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7428 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7429 #ifdef FEAT_RIGHTLEFT | |
7430 /* account for first command-line character in rightleft mode */ | |
7431 && !cmdmsg_rl | |
7432 #endif | |
7433 ) | |
7434 { | |
7435 ScreenAttrs[off] = (sattr_T)-1; | |
7436 return; | |
7437 } | |
7438 | |
7439 /* | |
7440 * Stop highlighting first, so it's easier to move the cursor. | |
7441 */ | |
7442 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7443 if (screen_char_attr != 0) | |
7444 attr = screen_char_attr; | |
7445 else | |
7446 #endif | |
7447 attr = ScreenAttrs[off]; | |
7448 if (screen_attr != attr) | |
7449 screen_stop_highlight(); | |
7450 | |
7451 windgoto(row, col); | |
7452 | |
7453 if (screen_attr != attr) | |
7454 screen_start_highlight(attr); | |
7455 | |
7456 #ifdef FEAT_MBYTE | |
7457 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7458 { | |
7459 char_u buf[MB_MAXBYTES + 1]; | |
7460 | |
7461 /* Convert UTF-8 character to bytes and write it. */ | |
7462 | |
7463 buf[utfc_char2bytes(off, buf)] = NUL; | |
7464 | |
7465 out_str(buf); | |
7466 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7467 ++screen_cur_col; | |
7468 } | |
7469 else | |
7470 #endif | |
7471 { | |
7472 #ifdef FEAT_MBYTE | |
7473 out_flush_check(); | |
7474 #endif | |
7475 out_char(ScreenLines[off]); | |
7476 #ifdef FEAT_MBYTE | |
7477 /* double-byte character in single-width cell */ | |
7478 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7479 out_char(ScreenLines2[off]); | |
7480 #endif | |
7481 } | |
7482 | |
7483 screen_cur_col++; | |
7484 } | |
7485 | |
7486 #ifdef FEAT_MBYTE | |
7487 | |
7488 /* | |
7489 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7490 * on the screen at position 'row' and 'col'. | |
7491 * The attributes of the first byte is used for all. This is required to | |
7492 * output the two bytes of a double-byte character with nothing in between. | |
7493 */ | |
7494 static void | |
7495 screen_char_2(off, row, col) | |
7496 unsigned off; | |
7497 int row; | |
7498 int col; | |
7499 { | |
7500 /* Check for illegal values (could be wrong when screen was resized). */ | |
7501 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7502 return; | |
7503 | |
7504 /* Outputting the last character on the screen may scrollup the screen. | |
7505 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7506 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7507 { | |
7508 ScreenAttrs[off] = (sattr_T)-1; | |
7509 return; | |
7510 } | |
7511 | |
7512 /* Output the first byte normally (positions the cursor), then write the | |
7513 * second byte directly. */ | |
7514 screen_char(off, row, col); | |
7515 out_char(ScreenLines[off + 1]); | |
7516 ++screen_cur_col; | |
7517 } | |
7518 #endif | |
7519 | |
7520 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7521 /* | |
7522 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7523 * This uses the contents of ScreenLines[] and doesn't change it. | |
7524 */ | |
7525 void | |
7526 screen_draw_rectangle(row, col, height, width, invert) | |
7527 int row; | |
7528 int col; | |
7529 int height; | |
7530 int width; | |
7531 int invert; | |
7532 { | |
7533 int r, c; | |
7534 int off; | |
1378 | 7535 #ifdef FEAT_MBYTE |
7536 int max_off; | |
7537 #endif | |
7 | 7538 |
534 | 7539 /* Can't use ScreenLines unless initialized */ |
7540 if (ScreenLines == NULL) | |
7541 return; | |
7542 | |
7 | 7543 if (invert) |
7544 screen_char_attr = HL_INVERSE; | |
7545 for (r = row; r < row + height; ++r) | |
7546 { | |
7547 off = LineOffset[r]; | |
1378 | 7548 #ifdef FEAT_MBYTE |
7549 max_off = off + screen_Columns; | |
7550 #endif | |
7 | 7551 for (c = col; c < col + width; ++c) |
7552 { | |
7553 #ifdef FEAT_MBYTE | |
1378 | 7554 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7555 { |
7556 screen_char_2(off + c, r, c); | |
7557 ++c; | |
7558 } | |
7559 else | |
7560 #endif | |
7561 { | |
7562 screen_char(off + c, r, c); | |
7563 #ifdef FEAT_MBYTE | |
1378 | 7564 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7565 ++c; |
7566 #endif | |
7567 } | |
7568 } | |
7569 } | |
7570 screen_char_attr = 0; | |
7571 } | |
7572 #endif | |
7573 | |
7574 #ifdef FEAT_VERTSPLIT | |
7575 /* | |
7576 * Redraw the characters for a vertically split window. | |
7577 */ | |
7578 static void | |
7579 redraw_block(row, end, wp) | |
7580 int row; | |
7581 int end; | |
7582 win_T *wp; | |
7583 { | |
7584 int col; | |
7585 int width; | |
7586 | |
7587 # ifdef FEAT_CLIPBOARD | |
7588 clip_may_clear_selection(row, end - 1); | |
7589 # endif | |
7590 | |
7591 if (wp == NULL) | |
7592 { | |
7593 col = 0; | |
7594 width = Columns; | |
7595 } | |
7596 else | |
7597 { | |
7598 col = wp->w_wincol; | |
7599 width = wp->w_width; | |
7600 } | |
7601 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7602 } | |
7603 #endif | |
7604 | |
7605 /* | |
7606 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7607 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7608 * Use attributes 'attr'. | |
7609 */ | |
7610 void | |
7611 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7612 int start_row, end_row; | |
7613 int start_col, end_col; | |
7614 int c1, c2; | |
7615 int attr; | |
7616 { | |
7617 int row; | |
7618 int col; | |
7619 int off; | |
7620 int end_off; | |
7621 int did_delete; | |
7622 int c; | |
7623 int norm_term; | |
7624 #if defined(FEAT_GUI) || defined(UNIX) | |
7625 int force_next = FALSE; | |
7626 #endif | |
7627 | |
7628 if (end_row > screen_Rows) /* safety check */ | |
7629 end_row = screen_Rows; | |
7630 if (end_col > screen_Columns) /* safety check */ | |
7631 end_col = screen_Columns; | |
7632 if (ScreenLines == NULL | |
7633 || start_row >= end_row | |
7634 || start_col >= end_col) /* nothing to do */ | |
7635 return; | |
7636 | |
7637 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7638 norm_term = ( | |
7639 #ifdef FEAT_GUI | |
7640 !gui.in_use && | |
7641 #endif | |
7642 t_colors <= 1); | |
7643 for (row = start_row; row < end_row; ++row) | |
7644 { | |
1668 | 7645 #ifdef FEAT_MBYTE |
7646 if (has_mbyte | |
7647 # ifdef FEAT_GUI | |
7648 && !gui.in_use | |
7649 # endif | |
7650 ) | |
7651 { | |
7652 /* When drawing over the right halve of a double-wide char clear | |
7653 * out the left halve. When drawing over the left halve of a | |
7654 * double wide-char clear out the right halve. Only needed in a | |
7655 * terminal. */ | |
1685 | 7656 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7657 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7658 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7659 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7660 } |
7661 #endif | |
7 | 7662 /* |
7663 * Try to use delete-line termcap code, when no attributes or in a | |
7664 * "normal" terminal, where a bold/italic space is just a | |
7665 * space. | |
7666 */ | |
7667 did_delete = FALSE; | |
7668 if (c2 == ' ' | |
7669 && end_col == Columns | |
7670 && can_clear(T_CE) | |
7671 && (attr == 0 | |
7672 || (norm_term | |
7673 && attr <= HL_ALL | |
7674 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7675 { | |
7676 /* | |
7677 * check if we really need to clear something | |
7678 */ | |
7679 col = start_col; | |
7680 if (c1 != ' ') /* don't clear first char */ | |
7681 ++col; | |
7682 | |
7683 off = LineOffset[row] + col; | |
7684 end_off = LineOffset[row] + end_col; | |
7685 | |
7686 /* skip blanks (used often, keep it fast!) */ | |
7687 #ifdef FEAT_MBYTE | |
7688 if (enc_utf8) | |
7689 while (off < end_off && ScreenLines[off] == ' ' | |
7690 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7691 ++off; | |
7692 else | |
7693 #endif | |
7694 while (off < end_off && ScreenLines[off] == ' ' | |
7695 && ScreenAttrs[off] == 0) | |
7696 ++off; | |
7697 if (off < end_off) /* something to be cleared */ | |
7698 { | |
7699 col = off - LineOffset[row]; | |
7700 screen_stop_highlight(); | |
7701 term_windgoto(row, col);/* clear rest of this screen line */ | |
7702 out_str(T_CE); | |
7703 screen_start(); /* don't know where cursor is now */ | |
7704 col = end_col - col; | |
7705 while (col--) /* clear chars in ScreenLines */ | |
7706 { | |
7707 ScreenLines[off] = ' '; | |
7708 #ifdef FEAT_MBYTE | |
7709 if (enc_utf8) | |
7710 ScreenLinesUC[off] = 0; | |
7711 #endif | |
7712 ScreenAttrs[off] = 0; | |
7713 ++off; | |
7714 } | |
7715 } | |
7716 did_delete = TRUE; /* the chars are cleared now */ | |
7717 } | |
7718 | |
7719 off = LineOffset[row] + start_col; | |
7720 c = c1; | |
7721 for (col = start_col; col < end_col; ++col) | |
7722 { | |
7723 if (ScreenLines[off] != c | |
7724 #ifdef FEAT_MBYTE | |
714 | 7725 || (enc_utf8 && (int)ScreenLinesUC[off] |
7726 != (c >= 0x80 ? c : 0)) | |
7 | 7727 #endif |
7728 || ScreenAttrs[off] != attr | |
7729 #if defined(FEAT_GUI) || defined(UNIX) | |
7730 || force_next | |
7731 #endif | |
7732 ) | |
7733 { | |
7734 #if defined(FEAT_GUI) || defined(UNIX) | |
7735 /* The bold trick may make a single row of pixels appear in | |
7736 * the next character. When a bold character is removed, the | |
7737 * next character should be redrawn too. This happens for our | |
7738 * own GUI and for some xterms. */ | |
7739 if ( | |
7740 # ifdef FEAT_GUI | |
7741 gui.in_use | |
7742 # endif | |
7743 # if defined(FEAT_GUI) && defined(UNIX) | |
7744 || | |
7745 # endif | |
7746 # ifdef UNIX | |
7747 term_is_xterm | |
7748 # endif | |
7749 ) | |
7750 { | |
7751 if (ScreenLines[off] != ' ' | |
7752 && (ScreenAttrs[off] > HL_ALL | |
7753 || ScreenAttrs[off] & HL_BOLD)) | |
7754 force_next = TRUE; | |
7755 else | |
7756 force_next = FALSE; | |
7757 } | |
7758 #endif | |
7759 ScreenLines[off] = c; | |
7760 #ifdef FEAT_MBYTE | |
7761 if (enc_utf8) | |
7762 { | |
7763 if (c >= 0x80) | |
7764 { | |
7765 ScreenLinesUC[off] = c; | |
714 | 7766 ScreenLinesC[0][off] = 0; |
7 | 7767 } |
7768 else | |
7769 ScreenLinesUC[off] = 0; | |
7770 } | |
7771 #endif | |
7772 ScreenAttrs[off] = attr; | |
7773 if (!did_delete || c != ' ') | |
7774 screen_char(off, row, col); | |
7775 } | |
7776 ++off; | |
7777 if (col == start_col) | |
7778 { | |
7779 if (did_delete) | |
7780 break; | |
7781 c = c2; | |
7782 } | |
7783 } | |
7784 if (end_col == Columns) | |
7785 LineWraps[row] = FALSE; | |
7786 if (row == Rows - 1) /* overwritten the command line */ | |
7787 { | |
7788 redraw_cmdline = TRUE; | |
7789 if (c1 == ' ' && c2 == ' ') | |
7790 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7791 if (start_col == 0) |
7792 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7793 } |
7794 } | |
7795 } | |
7796 | |
7797 /* | |
7798 * Check if there should be a delay. Used before clearing or redrawing the | |
7799 * screen or the command line. | |
7800 */ | |
7801 void | |
7802 check_for_delay(check_msg_scroll) | |
7803 int check_msg_scroll; | |
7804 { | |
7805 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7806 && !did_wait_return | |
7807 && emsg_silent == 0) | |
7808 { | |
7809 out_flush(); | |
7810 ui_delay(1000L, TRUE); | |
7811 emsg_on_display = FALSE; | |
7812 if (check_msg_scroll) | |
7813 msg_scroll = FALSE; | |
7814 } | |
7815 } | |
7816 | |
7817 /* | |
7818 * screen_valid - allocate screen buffers if size changed | |
7819 * If "clear" is TRUE: clear screen if it has been resized. | |
7820 * Returns TRUE if there is a valid screen to write to. | |
7821 * Returns FALSE when starting up and screen not initialized yet. | |
7822 */ | |
7823 int | |
7824 screen_valid(clear) | |
7825 int clear; | |
7826 { | |
7827 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7828 return (ScreenLines != NULL); | |
7829 } | |
7830 | |
7831 /* | |
7832 * Resize the shell to Rows and Columns. | |
7833 * Allocate ScreenLines[] and associated items. | |
7834 * | |
7835 * There may be some time between setting Rows and Columns and (re)allocating | |
7836 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7837 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7838 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7839 * final size of the shell is needed. | |
7840 */ | |
7841 void | |
7842 screenalloc(clear) | |
7843 int clear; | |
7844 { | |
7845 int new_row, old_row; | |
7846 #ifdef FEAT_GUI | |
7847 int old_Rows; | |
7848 #endif | |
7849 win_T *wp; | |
7850 int outofmem = FALSE; | |
7851 int len; | |
7852 schar_T *new_ScreenLines; | |
7853 #ifdef FEAT_MBYTE | |
7854 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7855 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7856 schar_T *new_ScreenLines2 = NULL; |
714 | 7857 int i; |
7 | 7858 #endif |
7859 sattr_T *new_ScreenAttrs; | |
7860 unsigned *new_LineOffset; | |
7861 char_u *new_LineWraps; | |
671 | 7862 #ifdef FEAT_WINDOWS |
681 | 7863 short *new_TabPageIdxs; |
671 | 7864 tabpage_T *tp; |
7865 #endif | |
7 | 7866 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7867 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7868 #ifdef FEAT_AUTOCMD |
7869 int retry_count = 0; | |
7870 | |
7871 retry: | |
7872 #endif | |
7 | 7873 /* |
7874 * Allocation of the screen buffers is done only when the size changes and | |
7875 * when Rows and Columns have been set and we have started doing full | |
7876 * screen stuff. | |
7877 */ | |
7878 if ((ScreenLines != NULL | |
7879 && Rows == screen_Rows | |
7880 && Columns == screen_Columns | |
7881 #ifdef FEAT_MBYTE | |
7882 && enc_utf8 == (ScreenLinesUC != NULL) | |
7883 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7884 && p_mco == Screen_mco |
7 | 7885 #endif |
7886 ) | |
7887 || Rows == 0 | |
7888 || Columns == 0 | |
7889 || (!full_screen && ScreenLines == NULL)) | |
7890 return; | |
7891 | |
7892 /* | |
7893 * It's possible that we produce an out-of-memory message below, which | |
7894 * will cause this function to be called again. To break the loop, just | |
7895 * return here. | |
7896 */ | |
7897 if (entered) | |
7898 return; | |
7899 entered = TRUE; | |
7900 | |
911 | 7901 /* |
7902 * Note that the window sizes are updated before reallocating the arrays, | |
7903 * thus we must not redraw here! | |
7904 */ | |
7905 ++RedrawingDisabled; | |
7906 | |
7 | 7907 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7908 | |
7909 comp_col(); /* recompute columns for shown command and ruler */ | |
7910 | |
7911 /* | |
7912 * We're changing the size of the screen. | |
7913 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7914 * - Move lines from the old arrays into the new arrays, clear extra | |
7915 * lines (unless the screen is going to be cleared). | |
7916 * - Free the old arrays. | |
7917 * | |
7918 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7919 * Continuing with the old ScreenLines may result in a crash, because the | |
7920 * size is wrong. | |
7921 */ | |
671 | 7922 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7923 win_free_lsize(wp); |
1946 | 7924 #ifdef FEAT_AUTOCMD |
7925 if (aucmd_win != NULL) | |
7926 win_free_lsize(aucmd_win); | |
7927 #endif | |
7 | 7928 |
7929 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7930 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7931 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7932 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7933 if (enc_utf8) |
7934 { | |
7935 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7936 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7937 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7938 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7939 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7940 } | |
7941 if (enc_dbcs == DBCS_JPNU) | |
7942 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7943 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7944 #endif | |
7945 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7946 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7947 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7948 Rows * sizeof(unsigned)), FALSE); | |
7949 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7950 #ifdef FEAT_WINDOWS |
681 | 7951 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7952 #endif |
7 | 7953 |
677 | 7954 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7955 { |
7956 if (win_alloc_lines(wp) == FAIL) | |
7957 { | |
7958 outofmem = TRUE; | |
7959 #ifdef FEAT_WINDOWS | |
1819 | 7960 goto give_up; |
7961 #endif | |
7962 } | |
7963 } | |
1906 | 7964 #ifdef FEAT_AUTOCMD |
1946 | 7965 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7966 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7967 outofmem = TRUE; |
7968 #endif | |
1819 | 7969 #ifdef FEAT_WINDOWS |
7970 give_up: | |
7971 #endif | |
7 | 7972 |
714 | 7973 #ifdef FEAT_MBYTE |
7974 for (i = 0; i < p_mco; ++i) | |
7975 if (new_ScreenLinesC[i] == NULL) | |
7976 break; | |
7977 #endif | |
7 | 7978 if (new_ScreenLines == NULL |
7979 #ifdef FEAT_MBYTE | |
714 | 7980 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 7981 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
7982 #endif | |
7983 || new_ScreenAttrs == NULL | |
7984 || new_LineOffset == NULL | |
7985 || new_LineWraps == NULL | |
671 | 7986 #ifdef FEAT_WINDOWS |
7987 || new_TabPageIdxs == NULL | |
7988 #endif | |
7 | 7989 || outofmem) |
7990 { | |
944 | 7991 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 7992 { |
7993 /* guess the size */ | |
7994 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
7995 | |
7996 /* Remember we did this to avoid getting outofmem messages over | |
7997 * and over again. */ | |
944 | 7998 done_outofmem_msg = TRUE; |
534 | 7999 } |
7 | 8000 vim_free(new_ScreenLines); |
8001 new_ScreenLines = NULL; | |
8002 #ifdef FEAT_MBYTE | |
8003 vim_free(new_ScreenLinesUC); | |
8004 new_ScreenLinesUC = NULL; | |
714 | 8005 for (i = 0; i < p_mco; ++i) |
8006 { | |
8007 vim_free(new_ScreenLinesC[i]); | |
8008 new_ScreenLinesC[i] = NULL; | |
8009 } | |
7 | 8010 vim_free(new_ScreenLines2); |
8011 new_ScreenLines2 = NULL; | |
8012 #endif | |
8013 vim_free(new_ScreenAttrs); | |
8014 new_ScreenAttrs = NULL; | |
8015 vim_free(new_LineOffset); | |
8016 new_LineOffset = NULL; | |
8017 vim_free(new_LineWraps); | |
8018 new_LineWraps = NULL; | |
671 | 8019 #ifdef FEAT_WINDOWS |
8020 vim_free(new_TabPageIdxs); | |
8021 new_TabPageIdxs = NULL; | |
8022 #endif | |
7 | 8023 } |
8024 else | |
8025 { | |
944 | 8026 done_outofmem_msg = FALSE; |
534 | 8027 |
7 | 8028 for (new_row = 0; new_row < Rows; ++new_row) |
8029 { | |
8030 new_LineOffset[new_row] = new_row * Columns; | |
8031 new_LineWraps[new_row] = FALSE; | |
8032 | |
8033 /* | |
8034 * If the screen is not going to be cleared, copy as much as | |
8035 * possible from the old screen to the new one and clear the rest | |
8036 * (used when resizing the window at the "--more--" prompt or when | |
8037 * executing an external command, for the GUI). | |
8038 */ | |
8039 if (!clear) | |
8040 { | |
8041 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
8042 ' ', (size_t)Columns * sizeof(schar_T)); | |
8043 #ifdef FEAT_MBYTE | |
8044 if (enc_utf8) | |
8045 { | |
8046 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
8047 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 8048 for (i = 0; i < p_mco; ++i) |
8049 (void)vim_memset(new_ScreenLinesC[i] | |
8050 + new_row * Columns, | |
7 | 8051 0, (size_t)Columns * sizeof(u8char_T)); |
8052 } | |
8053 if (enc_dbcs == DBCS_JPNU) | |
8054 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8055 0, (size_t)Columns * sizeof(schar_T)); | |
8056 #endif | |
8057 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8058 0, (size_t)Columns * sizeof(sattr_T)); | |
8059 old_row = new_row + (screen_Rows - Rows); | |
534 | 8060 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8061 { |
8062 if (screen_Columns < Columns) | |
8063 len = screen_Columns; | |
8064 else | |
8065 len = Columns; | |
26 | 8066 #ifdef FEAT_MBYTE |
571 | 8067 /* When switching to utf-8 don't copy characters, they |
714 | 8068 * may be invalid now. Also when p_mco changes. */ |
8069 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8070 && p_mco == Screen_mco) | |
26 | 8071 #endif |
8072 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8073 ScreenLines + LineOffset[old_row], | |
8074 (size_t)len * sizeof(schar_T)); | |
7 | 8075 #ifdef FEAT_MBYTE |
714 | 8076 if (enc_utf8 && ScreenLinesUC != NULL |
8077 && p_mco == Screen_mco) | |
7 | 8078 { |
8079 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8080 ScreenLinesUC + LineOffset[old_row], | |
8081 (size_t)len * sizeof(u8char_T)); | |
714 | 8082 for (i = 0; i < p_mco; ++i) |
8083 mch_memmove(new_ScreenLinesC[i] | |
8084 + new_LineOffset[new_row], | |
8085 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8086 (size_t)len * sizeof(u8char_T)); |
8087 } | |
8088 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8089 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8090 ScreenLines2 + LineOffset[old_row], | |
8091 (size_t)len * sizeof(schar_T)); | |
8092 #endif | |
8093 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8094 ScreenAttrs + LineOffset[old_row], | |
8095 (size_t)len * sizeof(sattr_T)); | |
8096 } | |
8097 } | |
8098 } | |
8099 /* Use the last line of the screen for the current line. */ | |
8100 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8101 } | |
8102 | |
356 | 8103 free_screenlines(); |
8104 | |
7 | 8105 ScreenLines = new_ScreenLines; |
8106 #ifdef FEAT_MBYTE | |
8107 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8108 for (i = 0; i < p_mco; ++i) |
8109 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8110 Screen_mco = p_mco; | |
7 | 8111 ScreenLines2 = new_ScreenLines2; |
8112 #endif | |
8113 ScreenAttrs = new_ScreenAttrs; | |
8114 LineOffset = new_LineOffset; | |
8115 LineWraps = new_LineWraps; | |
671 | 8116 #ifdef FEAT_WINDOWS |
8117 TabPageIdxs = new_TabPageIdxs; | |
8118 #endif | |
7 | 8119 |
8120 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8121 * size of ScreenLines[]. Set them before calling anything. */ | |
8122 #ifdef FEAT_GUI | |
8123 old_Rows = screen_Rows; | |
8124 #endif | |
8125 screen_Rows = Rows; | |
8126 screen_Columns = Columns; | |
8127 | |
8128 must_redraw = CLEAR; /* need to clear the screen later */ | |
8129 if (clear) | |
8130 screenclear2(); | |
8131 | |
8132 #ifdef FEAT_GUI | |
8133 else if (gui.in_use | |
8134 && !gui.starting | |
8135 && ScreenLines != NULL | |
8136 && old_Rows != Rows) | |
8137 { | |
8138 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8139 /* | |
8140 * Adjust the position of the cursor, for when executing an external | |
8141 * command. | |
8142 */ | |
8143 if (msg_row >= Rows) /* Rows got smaller */ | |
8144 msg_row = Rows - 1; /* put cursor at last row */ | |
8145 else if (Rows > old_Rows) /* Rows got bigger */ | |
8146 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8147 if (msg_col >= Columns) /* Columns got smaller */ | |
8148 msg_col = Columns - 1; /* put cursor at last column */ | |
8149 } | |
8150 #endif | |
8151 | |
8152 entered = FALSE; | |
911 | 8153 --RedrawingDisabled; |
766 | 8154 |
8155 #ifdef FEAT_AUTOCMD | |
1824 | 8156 /* |
8157 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8158 * in case applying autocommands always changes Rows or Columns. | |
8159 */ | |
8160 if (starting == 0 && ++retry_count <= 3) | |
8161 { | |
766 | 8162 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8163 /* In rare cases, autocommands may have altered Rows or Columns, |
8164 * jump back to check if we need to allocate the screen again. */ | |
8165 goto retry; | |
8166 } | |
766 | 8167 #endif |
7 | 8168 } |
8169 | |
8170 void | |
356 | 8171 free_screenlines() |
8172 { | |
8173 #ifdef FEAT_MBYTE | |
714 | 8174 int i; |
8175 | |
356 | 8176 vim_free(ScreenLinesUC); |
714 | 8177 for (i = 0; i < Screen_mco; ++i) |
8178 vim_free(ScreenLinesC[i]); | |
356 | 8179 vim_free(ScreenLines2); |
8180 #endif | |
714 | 8181 vim_free(ScreenLines); |
356 | 8182 vim_free(ScreenAttrs); |
8183 vim_free(LineOffset); | |
8184 vim_free(LineWraps); | |
671 | 8185 #ifdef FEAT_WINDOWS |
8186 vim_free(TabPageIdxs); | |
8187 #endif | |
356 | 8188 } |
8189 | |
8190 void | |
7 | 8191 screenclear() |
8192 { | |
8193 check_for_delay(FALSE); | |
8194 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8195 screenclear2(); /* clear the screen */ | |
8196 } | |
8197 | |
8198 static void | |
8199 screenclear2() | |
8200 { | |
8201 int i; | |
8202 | |
8203 if (starting == NO_SCREEN || ScreenLines == NULL | |
8204 #ifdef FEAT_GUI | |
8205 || (gui.in_use && gui.starting) | |
8206 #endif | |
8207 ) | |
8208 return; | |
8209 | |
8210 #ifdef FEAT_GUI | |
8211 if (!gui.in_use) | |
8212 #endif | |
8213 screen_attr = -1; /* force setting the Normal colors */ | |
8214 screen_stop_highlight(); /* don't want highlighting here */ | |
8215 | |
8216 #ifdef FEAT_CLIPBOARD | |
8217 /* disable selection without redrawing it */ | |
8218 clip_scroll_selection(9999); | |
8219 #endif | |
8220 | |
8221 /* blank out ScreenLines */ | |
8222 for (i = 0; i < Rows; ++i) | |
8223 { | |
8224 lineclear(LineOffset[i], (int)Columns); | |
8225 LineWraps[i] = FALSE; | |
8226 } | |
8227 | |
8228 if (can_clear(T_CL)) | |
8229 { | |
8230 out_str(T_CL); /* clear the display */ | |
8231 clear_cmdline = FALSE; | |
644 | 8232 mode_displayed = FALSE; |
7 | 8233 } |
8234 else | |
8235 { | |
8236 /* can't clear the screen, mark all chars with invalid attributes */ | |
8237 for (i = 0; i < Rows; ++i) | |
8238 lineinvalid(LineOffset[i], (int)Columns); | |
8239 clear_cmdline = TRUE; | |
8240 } | |
8241 | |
8242 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8243 | |
8244 win_rest_invalid(firstwin); | |
8245 redraw_cmdline = TRUE; | |
670 | 8246 #ifdef FEAT_WINDOWS |
673 | 8247 redraw_tabline = TRUE; |
670 | 8248 #endif |
7 | 8249 if (must_redraw == CLEAR) /* no need to clear again */ |
8250 must_redraw = NOT_VALID; | |
8251 compute_cmdrow(); | |
8252 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8253 msg_col = 0; | |
8254 screen_start(); /* don't know where cursor is now */ | |
8255 msg_scrolled = 0; /* can't scroll back */ | |
8256 msg_didany = FALSE; | |
8257 msg_didout = FALSE; | |
8258 } | |
8259 | |
8260 /* | |
8261 * Clear one line in ScreenLines. | |
8262 */ | |
8263 static void | |
8264 lineclear(off, width) | |
8265 unsigned off; | |
8266 int width; | |
8267 { | |
8268 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8269 #ifdef FEAT_MBYTE | |
8270 if (enc_utf8) | |
8271 (void)vim_memset(ScreenLinesUC + off, 0, | |
8272 (size_t)width * sizeof(u8char_T)); | |
8273 #endif | |
8274 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8275 } | |
8276 | |
8277 /* | |
8278 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8279 * invalid value. | |
8280 */ | |
8281 static void | |
8282 lineinvalid(off, width) | |
8283 unsigned off; | |
8284 int width; | |
8285 { | |
8286 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8287 } | |
8288 | |
8289 #ifdef FEAT_VERTSPLIT | |
8290 /* | |
8291 * Copy part of a Screenline for vertically split window "wp". | |
8292 */ | |
8293 static void | |
8294 linecopy(to, from, wp) | |
8295 int to; | |
8296 int from; | |
8297 win_T *wp; | |
8298 { | |
8299 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8300 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8301 | |
8302 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8303 wp->w_width * sizeof(schar_T)); | |
8304 # ifdef FEAT_MBYTE | |
8305 if (enc_utf8) | |
8306 { | |
714 | 8307 int i; |
8308 | |
7 | 8309 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8310 wp->w_width * sizeof(u8char_T)); | |
714 | 8311 for (i = 0; i < p_mco; ++i) |
8312 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8313 wp->w_width * sizeof(u8char_T)); | |
7 | 8314 } |
8315 if (enc_dbcs == DBCS_JPNU) | |
8316 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8317 wp->w_width * sizeof(schar_T)); | |
8318 # endif | |
8319 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8320 wp->w_width * sizeof(sattr_T)); | |
8321 } | |
8322 #endif | |
8323 | |
8324 /* | |
8325 * Return TRUE if clearing with term string "p" would work. | |
8326 * It can't work when the string is empty or it won't set the right background. | |
8327 */ | |
8328 int | |
8329 can_clear(p) | |
8330 char_u *p; | |
8331 { | |
8332 return (*p != NUL && (t_colors <= 1 | |
8333 #ifdef FEAT_GUI | |
8334 || gui.in_use | |
8335 #endif | |
8336 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8337 } | |
8338 | |
8339 /* | |
8340 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8341 * something directly to the screen (shell commands) or a terminal control | |
8342 * code. | |
8343 */ | |
8344 void | |
8345 screen_start() | |
8346 { | |
8347 screen_cur_row = screen_cur_col = 9999; | |
8348 } | |
8349 | |
8350 /* | |
8351 * Move the cursor to position "row","col" in the screen. | |
8352 * This tries to find the most efficient way to move, minimizing the number of | |
8353 * characters sent to the terminal. | |
8354 */ | |
8355 void | |
8356 windgoto(row, col) | |
8357 int row; | |
8358 int col; | |
8359 { | |
205 | 8360 sattr_T *p; |
7 | 8361 int i; |
8362 int plan; | |
8363 int cost; | |
8364 int wouldbe_col; | |
8365 int noinvcurs; | |
8366 char_u *bs; | |
8367 int goto_cost; | |
8368 int attr; | |
8369 | |
1213 | 8370 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8371 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8372 | |
8373 #define PLAN_LE 1 | |
8374 #define PLAN_CR 2 | |
8375 #define PLAN_NL 3 | |
8376 #define PLAN_WRITE 4 | |
8377 /* Can't use ScreenLines unless initialized */ | |
8378 if (ScreenLines == NULL) | |
8379 return; | |
8380 | |
8381 if (col != screen_cur_col || row != screen_cur_row) | |
8382 { | |
8383 /* Check for valid position. */ | |
8384 if (row < 0) /* window without text lines? */ | |
8385 row = 0; | |
8386 if (row >= screen_Rows) | |
8387 row = screen_Rows - 1; | |
8388 if (col >= screen_Columns) | |
8389 col = screen_Columns - 1; | |
8390 | |
8391 /* check if no cursor movement is allowed in highlight mode */ | |
8392 if (screen_attr && *T_MS == NUL) | |
8393 noinvcurs = HIGHL_COST; | |
8394 else | |
8395 noinvcurs = 0; | |
8396 goto_cost = GOTO_COST + noinvcurs; | |
8397 | |
8398 /* | |
8399 * Plan how to do the positioning: | |
8400 * 1. Use CR to move it to column 0, same row. | |
8401 * 2. Use T_LE to move it a few columns to the left. | |
8402 * 3. Use NL to move a few lines down, column 0. | |
8403 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8404 * | |
8405 * Don't do this if the cursor went beyond the last column, the cursor | |
8406 * position is unknown then (some terminals wrap, some don't ) | |
8407 * | |
1213 | 8408 * First check if the highlighting attributes allow us to write |
7 | 8409 * characters to move the cursor to the right. |
8410 */ | |
8411 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8412 { | |
8413 /* | |
8414 * If the cursor is in the same row, bigger col, we can use CR | |
8415 * or T_LE. | |
8416 */ | |
8417 bs = NULL; /* init for GCC */ | |
8418 attr = screen_attr; | |
8419 if (row == screen_cur_row && col < screen_cur_col) | |
8420 { | |
8421 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8422 if (*T_LE) | |
8423 bs = T_LE; /* "cursor left" */ | |
8424 else | |
8425 bs = T_BC; /* "backspace character (old) */ | |
8426 if (*bs) | |
8427 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8428 else | |
8429 cost = 999; | |
8430 if (col + 1 < cost) /* using CR is less characters */ | |
8431 { | |
8432 plan = PLAN_CR; | |
8433 wouldbe_col = 0; | |
8434 cost = 1; /* CR is just one character */ | |
8435 } | |
8436 else | |
8437 { | |
8438 plan = PLAN_LE; | |
8439 wouldbe_col = col; | |
8440 } | |
8441 if (noinvcurs) /* will stop highlighting */ | |
8442 { | |
8443 cost += noinvcurs; | |
8444 attr = 0; | |
8445 } | |
8446 } | |
8447 | |
8448 /* | |
8449 * If the cursor is above where we want to be, we can use CR LF. | |
8450 */ | |
8451 else if (row > screen_cur_row) | |
8452 { | |
8453 plan = PLAN_NL; | |
8454 wouldbe_col = 0; | |
8455 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8456 if (noinvcurs) /* will stop highlighting */ | |
8457 { | |
8458 cost += noinvcurs; | |
8459 attr = 0; | |
8460 } | |
8461 } | |
8462 | |
8463 /* | |
8464 * If the cursor is in the same row, smaller col, just use write. | |
8465 */ | |
8466 else | |
8467 { | |
8468 plan = PLAN_WRITE; | |
8469 wouldbe_col = screen_cur_col; | |
8470 cost = 0; | |
8471 } | |
8472 | |
8473 /* | |
8474 * Check if any characters that need to be written have the | |
8475 * correct attributes. Also avoid UTF-8 characters. | |
8476 */ | |
8477 i = col - wouldbe_col; | |
8478 if (i > 0) | |
8479 cost += i; | |
8480 if (cost < goto_cost && i > 0) | |
8481 { | |
8482 /* | |
8483 * Check if the attributes are correct without additionally | |
8484 * stopping highlighting. | |
8485 */ | |
8486 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8487 while (i && *p++ == attr) | |
8488 --i; | |
8489 if (i != 0) | |
8490 { | |
8491 /* | |
8492 * Try if it works when highlighting is stopped here. | |
8493 */ | |
8494 if (*--p == 0) | |
8495 { | |
8496 cost += noinvcurs; | |
8497 while (i && *p++ == 0) | |
8498 --i; | |
8499 } | |
8500 if (i != 0) | |
8501 cost = 999; /* different attributes, don't do it */ | |
8502 } | |
8503 #ifdef FEAT_MBYTE | |
8504 if (enc_utf8) | |
8505 { | |
8506 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8507 for (i = wouldbe_col; i < col; ++i) | |
8508 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8509 { | |
8510 cost = 999; | |
8511 break; | |
8512 } | |
8513 } | |
8514 #endif | |
8515 } | |
8516 | |
8517 /* | |
8518 * We can do it without term_windgoto()! | |
8519 */ | |
8520 if (cost < goto_cost) | |
8521 { | |
8522 if (plan == PLAN_LE) | |
8523 { | |
8524 if (noinvcurs) | |
8525 screen_stop_highlight(); | |
8526 while (screen_cur_col > col) | |
8527 { | |
8528 out_str(bs); | |
8529 --screen_cur_col; | |
8530 } | |
8531 } | |
8532 else if (plan == PLAN_CR) | |
8533 { | |
8534 if (noinvcurs) | |
8535 screen_stop_highlight(); | |
8536 out_char('\r'); | |
8537 screen_cur_col = 0; | |
8538 } | |
8539 else if (plan == PLAN_NL) | |
8540 { | |
8541 if (noinvcurs) | |
8542 screen_stop_highlight(); | |
8543 while (screen_cur_row < row) | |
8544 { | |
8545 out_char('\n'); | |
8546 ++screen_cur_row; | |
8547 } | |
8548 screen_cur_col = 0; | |
8549 } | |
8550 | |
8551 i = col - screen_cur_col; | |
8552 if (i > 0) | |
8553 { | |
8554 /* | |
8555 * Use cursor-right if it's one character only. Avoids | |
8556 * removing a line of pixels from the last bold char, when | |
8557 * using the bold trick in the GUI. | |
8558 */ | |
8559 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8560 { | |
8561 while (i-- > 0) | |
8562 out_char(*T_ND); | |
8563 } | |
8564 else | |
8565 { | |
8566 int off; | |
8567 | |
8568 off = LineOffset[row] + screen_cur_col; | |
8569 while (i-- > 0) | |
8570 { | |
8571 if (ScreenAttrs[off] != screen_attr) | |
8572 screen_stop_highlight(); | |
8573 #ifdef FEAT_MBYTE | |
8574 out_flush_check(); | |
8575 #endif | |
8576 out_char(ScreenLines[off]); | |
8577 #ifdef FEAT_MBYTE | |
8578 if (enc_dbcs == DBCS_JPNU | |
8579 && ScreenLines[off] == 0x8e) | |
8580 out_char(ScreenLines2[off]); | |
8581 #endif | |
8582 ++off; | |
8583 } | |
8584 } | |
8585 } | |
8586 } | |
8587 } | |
8588 else | |
8589 cost = 999; | |
8590 | |
8591 if (cost >= goto_cost) | |
8592 { | |
8593 if (noinvcurs) | |
8594 screen_stop_highlight(); | |
8595 if (row == screen_cur_row && (col > screen_cur_col) && | |
8596 *T_CRI != NUL) | |
8597 term_cursor_right(col - screen_cur_col); | |
8598 else | |
8599 term_windgoto(row, col); | |
8600 } | |
8601 screen_cur_row = row; | |
8602 screen_cur_col = col; | |
8603 } | |
8604 } | |
8605 | |
8606 /* | |
8607 * Set cursor to its position in the current window. | |
8608 */ | |
8609 void | |
8610 setcursor() | |
8611 { | |
8612 if (redrawing()) | |
8613 { | |
8614 validate_cursor(); | |
8615 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8616 W_WINCOL(curwin) + ( | |
8617 #ifdef FEAT_RIGHTLEFT | |
1545 | 8618 /* With 'rightleft' set and the cursor on a double-wide |
8619 * character, position it on the leftmost column. */ | |
7 | 8620 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8621 # ifdef FEAT_MBYTE | |
1545 | 8622 (has_mbyte |
8623 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8624 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8625 # endif |
8626 1)) : | |
8627 #endif | |
8628 curwin->w_wcol)); | |
8629 } | |
8630 } | |
8631 | |
8632 | |
8633 /* | |
8634 * insert 'line_count' lines at 'row' in window 'wp' | |
8635 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8636 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8637 * scrolling. | |
8638 * Returns FAIL if the lines are not inserted, OK for success. | |
8639 */ | |
8640 int | |
8641 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8642 win_T *wp; | |
8643 int row; | |
8644 int line_count; | |
8645 int invalid; | |
8646 int mayclear; | |
8647 { | |
8648 int did_delete; | |
8649 int nextrow; | |
8650 int lastrow; | |
8651 int retval; | |
8652 | |
8653 if (invalid) | |
8654 wp->w_lines_valid = 0; | |
8655 | |
8656 if (wp->w_height < 5) | |
8657 return FAIL; | |
8658 | |
8659 if (line_count > wp->w_height - row) | |
8660 line_count = wp->w_height - row; | |
8661 | |
8662 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8663 if (retval != MAYBE) | |
8664 return retval; | |
8665 | |
8666 /* | |
8667 * If there is a next window or a status line, we first try to delete the | |
8668 * lines at the bottom to avoid messing what is after the window. | |
8669 * If this fails and there are following windows, don't do anything to avoid | |
8670 * messing up those windows, better just redraw. | |
8671 */ | |
8672 did_delete = FALSE; | |
8673 #ifdef FEAT_WINDOWS | |
8674 if (wp->w_next != NULL || wp->w_status_height) | |
8675 { | |
8676 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8677 line_count, (int)Rows, FALSE, NULL) == OK) | |
8678 did_delete = TRUE; | |
8679 else if (wp->w_next) | |
8680 return FAIL; | |
8681 } | |
8682 #endif | |
8683 /* | |
8684 * if no lines deleted, blank the lines that will end up below the window | |
8685 */ | |
8686 if (!did_delete) | |
8687 { | |
8688 #ifdef FEAT_WINDOWS | |
8689 wp->w_redr_status = TRUE; | |
8690 #endif | |
8691 redraw_cmdline = TRUE; | |
8692 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8693 lastrow = nextrow + line_count; | |
8694 if (lastrow > Rows) | |
8695 lastrow = Rows; | |
8696 screen_fill(nextrow - line_count, lastrow - line_count, | |
8697 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8698 ' ', ' ', 0); | |
8699 } | |
8700 | |
8701 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8702 == FAIL) | |
8703 { | |
8704 /* deletion will have messed up other windows */ | |
8705 if (did_delete) | |
8706 { | |
8707 #ifdef FEAT_WINDOWS | |
8708 wp->w_redr_status = TRUE; | |
8709 #endif | |
8710 win_rest_invalid(W_NEXT(wp)); | |
8711 } | |
8712 return FAIL; | |
8713 } | |
8714 | |
8715 return OK; | |
8716 } | |
8717 | |
8718 /* | |
8719 * delete "line_count" window lines at "row" in window "wp" | |
8720 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8721 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8722 * scrolling | |
8723 * Return OK for success, FAIL if the lines are not deleted. | |
8724 */ | |
8725 int | |
8726 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8727 win_T *wp; | |
8728 int row; | |
8729 int line_count; | |
8730 int invalid; | |
8731 int mayclear; | |
8732 { | |
8733 int retval; | |
8734 | |
8735 if (invalid) | |
8736 wp->w_lines_valid = 0; | |
8737 | |
8738 if (line_count > wp->w_height - row) | |
8739 line_count = wp->w_height - row; | |
8740 | |
8741 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8742 if (retval != MAYBE) | |
8743 return retval; | |
8744 | |
8745 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8746 (int)Rows, FALSE, NULL) == FAIL) | |
8747 return FAIL; | |
8748 | |
8749 #ifdef FEAT_WINDOWS | |
8750 /* | |
8751 * If there are windows or status lines below, try to put them at the | |
8752 * correct place. If we can't do that, they have to be redrawn. | |
8753 */ | |
8754 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8755 { | |
8756 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8757 line_count, (int)Rows, NULL) == FAIL) | |
8758 { | |
8759 wp->w_redr_status = TRUE; | |
8760 win_rest_invalid(wp->w_next); | |
8761 } | |
8762 } | |
8763 /* | |
8764 * If this is the last window and there is no status line, redraw the | |
8765 * command line later. | |
8766 */ | |
8767 else | |
8768 #endif | |
8769 redraw_cmdline = TRUE; | |
8770 return OK; | |
8771 } | |
8772 | |
8773 /* | |
8774 * Common code for win_ins_lines() and win_del_lines(). | |
8775 * Returns OK or FAIL when the work has been done. | |
8776 * Returns MAYBE when not finished yet. | |
8777 */ | |
8778 static int | |
8779 win_do_lines(wp, row, line_count, mayclear, del) | |
8780 win_T *wp; | |
8781 int row; | |
8782 int line_count; | |
8783 int mayclear; | |
8784 int del; | |
8785 { | |
8786 int retval; | |
8787 | |
8788 if (!redrawing() || line_count <= 0) | |
8789 return FAIL; | |
8790 | |
8791 /* only a few lines left: redraw is faster */ | |
8792 if (mayclear && Rows - line_count < 5 | |
8793 #ifdef FEAT_VERTSPLIT | |
8794 && wp->w_width == Columns | |
8795 #endif | |
8796 ) | |
8797 { | |
8798 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8799 return FAIL; | |
8800 } | |
8801 | |
8802 /* | |
8803 * Delete all remaining lines | |
8804 */ | |
8805 if (row + line_count >= wp->w_height) | |
8806 { | |
8807 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8808 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8809 ' ', ' ', 0); | |
8810 return OK; | |
8811 } | |
8812 | |
8813 /* | |
8814 * when scrolling, the message on the command line should be cleared, | |
8815 * otherwise it will stay there forever. | |
8816 */ | |
8817 clear_cmdline = TRUE; | |
8818 | |
8819 /* | |
8820 * If the terminal can set a scroll region, use that. | |
8821 * Always do this in a vertically split window. This will redraw from | |
8822 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8823 * win_line(). | |
8824 * Don't use a scroll region when we are going to redraw the text, writing | |
8825 * a character in the lower right corner of the scroll region causes a | |
8826 * scroll-up in the DJGPP version. | |
8827 */ | |
8828 if (scroll_region | |
8829 #ifdef FEAT_VERTSPLIT | |
8830 || W_WIDTH(wp) != Columns | |
8831 #endif | |
8832 ) | |
8833 { | |
8834 #ifdef FEAT_VERTSPLIT | |
8835 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8836 #endif | |
8837 scroll_region_set(wp, row); | |
8838 if (del) | |
8839 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8840 wp->w_height - row, FALSE, wp); | |
8841 else | |
8842 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8843 wp->w_height - row, wp); | |
8844 #ifdef FEAT_VERTSPLIT | |
8845 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8846 #endif | |
8847 scroll_region_reset(); | |
8848 return retval; | |
8849 } | |
8850 | |
8851 #ifdef FEAT_WINDOWS | |
8852 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8853 return FAIL; | |
8854 #endif | |
8855 | |
8856 return MAYBE; | |
8857 } | |
8858 | |
8859 /* | |
8860 * window 'wp' and everything after it is messed up, mark it for redraw | |
8861 */ | |
8862 static void | |
8863 win_rest_invalid(wp) | |
8864 win_T *wp; | |
8865 { | |
8866 #ifdef FEAT_WINDOWS | |
8867 while (wp != NULL) | |
8868 #else | |
8869 if (wp != NULL) | |
8870 #endif | |
8871 { | |
8872 redraw_win_later(wp, NOT_VALID); | |
8873 #ifdef FEAT_WINDOWS | |
8874 wp->w_redr_status = TRUE; | |
8875 wp = wp->w_next; | |
8876 #endif | |
8877 } | |
8878 redraw_cmdline = TRUE; | |
8879 } | |
8880 | |
8881 /* | |
8882 * The rest of the routines in this file perform screen manipulations. The | |
8883 * given operation is performed physically on the screen. The corresponding | |
8884 * change is also made to the internal screen image. In this way, the editor | |
8885 * anticipates the effect of editing changes on the appearance of the screen. | |
8886 * That way, when we call screenupdate a complete redraw isn't usually | |
8887 * necessary. Another advantage is that we can keep adding code to anticipate | |
8888 * screen changes, and in the meantime, everything still works. | |
8889 */ | |
8890 | |
8891 /* | |
8892 * types for inserting or deleting lines | |
8893 */ | |
8894 #define USE_T_CAL 1 | |
8895 #define USE_T_CDL 2 | |
8896 #define USE_T_AL 3 | |
8897 #define USE_T_CE 4 | |
8898 #define USE_T_DL 5 | |
8899 #define USE_T_SR 6 | |
8900 #define USE_NL 7 | |
8901 #define USE_T_CD 8 | |
8902 #define USE_REDRAW 9 | |
8903 | |
8904 /* | |
8905 * insert lines on the screen and update ScreenLines[] | |
8906 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8907 * When scrolling region used 'off' is the offset from the top for the region. | |
8908 * 'row' and 'end' are relative to the start of the region. | |
8909 * | |
8910 * return FAIL for failure, OK for success. | |
8911 */ | |
446 | 8912 int |
7 | 8913 screen_ins_lines(off, row, line_count, end, wp) |
8914 int off; | |
8915 int row; | |
8916 int line_count; | |
8917 int end; | |
8918 win_T *wp; /* NULL or window to use width from */ | |
8919 { | |
8920 int i; | |
8921 int j; | |
8922 unsigned temp; | |
8923 int cursor_row; | |
8924 int type; | |
8925 int result_empty; | |
8926 int can_ce = can_clear(T_CE); | |
8927 | |
8928 /* | |
8929 * FAIL if | |
8930 * - there is no valid screen | |
8931 * - the screen has to be redrawn completely | |
8932 * - the line count is less than one | |
8933 * - the line count is more than 'ttyscroll' | |
8934 */ | |
8935 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8936 return FAIL; | |
8937 | |
8938 /* | |
8939 * There are seven ways to insert lines: | |
8940 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8941 * characters from ScreenLines[]. | |
8942 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8943 * the insert is just empty lines | |
8944 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8945 * present or line_count > 1. It looks better if we do all the inserts | |
8946 * at once. | |
8947 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8948 * insert is just empty lines and T_CE is not present or line_count > | |
8949 * 1. | |
8950 * 4. Use T_AL (insert line) if it exists. | |
8951 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8952 * just empty lines. | |
8953 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8954 * just empty lines. | |
8955 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8956 * the 'da' flag is not set or we have clear line capability. | |
8957 * 8. redraw the characters from ScreenLines[]. | |
8958 * | |
8959 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8960 * the scrollbar for the window. It does have insert line, use that if it | |
8961 * exists. | |
8962 */ | |
8963 result_empty = (row + line_count >= end); | |
8964 #ifdef FEAT_VERTSPLIT | |
8965 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8966 type = USE_REDRAW; | |
8967 else | |
8968 #endif | |
8969 if (can_clear(T_CD) && result_empty) | |
8970 type = USE_T_CD; | |
8971 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
8972 type = USE_T_CAL; | |
8973 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
8974 type = USE_T_CDL; | |
8975 else if (*T_AL != NUL) | |
8976 type = USE_T_AL; | |
8977 else if (can_ce && result_empty) | |
8978 type = USE_T_CE; | |
8979 else if (*T_DL != NUL && result_empty) | |
8980 type = USE_T_DL; | |
8981 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
8982 type = USE_T_SR; | |
8983 else | |
8984 return FAIL; | |
8985 | |
8986 /* | |
8987 * For clearing the lines screen_del_lines() is used. This will also take | |
8988 * care of t_db if necessary. | |
8989 */ | |
8990 if (type == USE_T_CD || type == USE_T_CDL || | |
8991 type == USE_T_CE || type == USE_T_DL) | |
8992 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
8993 | |
8994 /* | |
8995 * If text is retained below the screen, first clear or delete as many | |
8996 * lines at the bottom of the window as are about to be inserted so that | |
8997 * the deleted lines won't later surface during a screen_del_lines. | |
8998 */ | |
8999 if (*T_DB) | |
9000 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
9001 | |
9002 #ifdef FEAT_CLIPBOARD | |
9003 /* Remove a modeless selection when inserting lines halfway the screen | |
9004 * or not the full width of the screen. */ | |
9005 if (off + row > 0 | |
9006 # ifdef FEAT_VERTSPLIT | |
9007 || (wp != NULL && wp->w_width != Columns) | |
9008 # endif | |
9009 ) | |
9010 clip_clear_selection(); | |
9011 else | |
9012 clip_scroll_selection(-line_count); | |
9013 #endif | |
9014 | |
9015 #ifdef FEAT_GUI | |
9016 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9017 * scrolling is actually carried out. */ | |
9018 gui_dont_update_cursor(); | |
9019 #endif | |
9020 | |
9021 if (*T_CCS != NUL) /* cursor relative to region */ | |
9022 cursor_row = row; | |
9023 else | |
9024 cursor_row = row + off; | |
9025 | |
9026 /* | |
9027 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
9028 * Clear the inserted lines in ScreenLines[]. | |
9029 */ | |
9030 row += off; | |
9031 end += off; | |
9032 for (i = 0; i < line_count; ++i) | |
9033 { | |
9034 #ifdef FEAT_VERTSPLIT | |
9035 if (wp != NULL && wp->w_width != Columns) | |
9036 { | |
9037 /* need to copy part of a line */ | |
9038 j = end - 1 - i; | |
9039 while ((j -= line_count) >= row) | |
9040 linecopy(j + line_count, j, wp); | |
9041 j += line_count; | |
9042 if (can_clear((char_u *)" ")) | |
9043 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9044 else | |
9045 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9046 LineWraps[j] = FALSE; | |
9047 } | |
9048 else | |
9049 #endif | |
9050 { | |
9051 j = end - 1 - i; | |
9052 temp = LineOffset[j]; | |
9053 while ((j -= line_count) >= row) | |
9054 { | |
9055 LineOffset[j + line_count] = LineOffset[j]; | |
9056 LineWraps[j + line_count] = LineWraps[j]; | |
9057 } | |
9058 LineOffset[j + line_count] = temp; | |
9059 LineWraps[j + line_count] = FALSE; | |
9060 if (can_clear((char_u *)" ")) | |
9061 lineclear(temp, (int)Columns); | |
9062 else | |
9063 lineinvalid(temp, (int)Columns); | |
9064 } | |
9065 } | |
9066 | |
9067 screen_stop_highlight(); | |
9068 windgoto(cursor_row, 0); | |
9069 | |
9070 #ifdef FEAT_VERTSPLIT | |
9071 /* redraw the characters */ | |
9072 if (type == USE_REDRAW) | |
9073 redraw_block(row, end, wp); | |
9074 else | |
9075 #endif | |
9076 if (type == USE_T_CAL) | |
9077 { | |
9078 term_append_lines(line_count); | |
9079 screen_start(); /* don't know where cursor is now */ | |
9080 } | |
9081 else | |
9082 { | |
9083 for (i = 0; i < line_count; i++) | |
9084 { | |
9085 if (type == USE_T_AL) | |
9086 { | |
9087 if (i && cursor_row != 0) | |
9088 windgoto(cursor_row, 0); | |
9089 out_str(T_AL); | |
9090 } | |
9091 else /* type == USE_T_SR */ | |
9092 out_str(T_SR); | |
9093 screen_start(); /* don't know where cursor is now */ | |
9094 } | |
9095 } | |
9096 | |
9097 /* | |
9098 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9099 * have been scrolled down into the region. | |
9100 */ | |
9101 if (type == USE_T_SR && *T_DA) | |
9102 { | |
9103 for (i = 0; i < line_count; ++i) | |
9104 { | |
9105 windgoto(off + i, 0); | |
9106 out_str(T_CE); | |
9107 screen_start(); /* don't know where cursor is now */ | |
9108 } | |
9109 } | |
9110 | |
9111 #ifdef FEAT_GUI | |
9112 gui_can_update_cursor(); | |
9113 if (gui.in_use) | |
9114 out_flush(); /* always flush after a scroll */ | |
9115 #endif | |
9116 return OK; | |
9117 } | |
9118 | |
9119 /* | |
9120 * delete lines on the screen and update ScreenLines[] | |
9121 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9122 * When scrolling region used 'off' is the offset from the top for the region. | |
9123 * 'row' and 'end' are relative to the start of the region. | |
9124 * | |
9125 * Return OK for success, FAIL if the lines are not deleted. | |
9126 */ | |
9127 int | |
9128 screen_del_lines(off, row, line_count, end, force, wp) | |
9129 int off; | |
9130 int row; | |
9131 int line_count; | |
9132 int end; | |
9133 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9134 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9135 { |
9136 int j; | |
9137 int i; | |
9138 unsigned temp; | |
9139 int cursor_row; | |
9140 int cursor_end; | |
9141 int result_empty; /* result is empty until end of region */ | |
9142 int can_delete; /* deleting line codes can be used */ | |
9143 int type; | |
9144 | |
9145 /* | |
9146 * FAIL if | |
9147 * - there is no valid screen | |
9148 * - the screen has to be redrawn completely | |
9149 * - the line count is less than one | |
9150 * - the line count is more than 'ttyscroll' | |
9151 */ | |
9152 if (!screen_valid(TRUE) || line_count <= 0 || | |
9153 (!force && line_count > p_ttyscroll)) | |
9154 return FAIL; | |
9155 | |
9156 /* | |
9157 * Check if the rest of the current region will become empty. | |
9158 */ | |
9159 result_empty = row + line_count >= end; | |
9160 | |
9161 /* | |
9162 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9163 * available. | |
9164 */ | |
9165 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9166 | |
9167 /* | |
9168 * There are six ways to delete lines: | |
9169 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9170 * characters from ScreenLines[]. | |
9171 * 1. Use T_CD if it exists and the result is empty. | |
9172 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9173 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9174 * none of the other ways work. | |
9175 * 4. Use T_CE (erase line) if the result is empty. | |
9176 * 5. Use T_DL (delete line) if it exists. | |
9177 * 6. redraw the characters from ScreenLines[]. | |
9178 */ | |
9179 #ifdef FEAT_VERTSPLIT | |
9180 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9181 type = USE_REDRAW; | |
9182 else | |
9183 #endif | |
9184 if (can_clear(T_CD) && result_empty) | |
9185 type = USE_T_CD; | |
9186 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9187 /* | |
9188 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9189 * its internal termcap... this works okay for tests which test *T_DB != | |
9190 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9191 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9192 * the trick... | |
9193 * Anyway, this hack will hopefully go away with the next OS release. | |
9194 * (Olaf Seibert) | |
9195 */ | |
9196 else if (row == 0 && T_DB == empty_option | |
9197 && (line_count == 1 || *T_CDL == NUL)) | |
9198 #else | |
9199 else if (row == 0 && ( | |
9200 #ifndef AMIGA | |
9201 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9202 * up, so use delete-line command */ | |
9203 line_count == 1 || | |
9204 #endif | |
9205 *T_CDL == NUL)) | |
9206 #endif | |
9207 type = USE_NL; | |
9208 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9209 type = USE_T_CDL; | |
9210 else if (can_clear(T_CE) && result_empty | |
9211 #ifdef FEAT_VERTSPLIT | |
9212 && (wp == NULL || wp->w_width == Columns) | |
9213 #endif | |
9214 ) | |
9215 type = USE_T_CE; | |
9216 else if (*T_DL != NUL && can_delete) | |
9217 type = USE_T_DL; | |
9218 else if (*T_CDL != NUL && can_delete) | |
9219 type = USE_T_CDL; | |
9220 else | |
9221 return FAIL; | |
9222 | |
9223 #ifdef FEAT_CLIPBOARD | |
9224 /* Remove a modeless selection when deleting lines halfway the screen or | |
9225 * not the full width of the screen. */ | |
9226 if (off + row > 0 | |
9227 # ifdef FEAT_VERTSPLIT | |
9228 || (wp != NULL && wp->w_width != Columns) | |
9229 # endif | |
9230 ) | |
9231 clip_clear_selection(); | |
9232 else | |
9233 clip_scroll_selection(line_count); | |
9234 #endif | |
9235 | |
9236 #ifdef FEAT_GUI | |
9237 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9238 * scrolling is actually carried out. */ | |
9239 gui_dont_update_cursor(); | |
9240 #endif | |
9241 | |
9242 if (*T_CCS != NUL) /* cursor relative to region */ | |
9243 { | |
9244 cursor_row = row; | |
9245 cursor_end = end; | |
9246 } | |
9247 else | |
9248 { | |
9249 cursor_row = row + off; | |
9250 cursor_end = end + off; | |
9251 } | |
9252 | |
9253 /* | |
9254 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9255 * Clear the inserted lines in ScreenLines[]. | |
9256 */ | |
9257 row += off; | |
9258 end += off; | |
9259 for (i = 0; i < line_count; ++i) | |
9260 { | |
9261 #ifdef FEAT_VERTSPLIT | |
9262 if (wp != NULL && wp->w_width != Columns) | |
9263 { | |
9264 /* need to copy part of a line */ | |
9265 j = row + i; | |
9266 while ((j += line_count) <= end - 1) | |
9267 linecopy(j - line_count, j, wp); | |
9268 j -= line_count; | |
9269 if (can_clear((char_u *)" ")) | |
9270 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9271 else | |
9272 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9273 LineWraps[j] = FALSE; | |
9274 } | |
9275 else | |
9276 #endif | |
9277 { | |
9278 /* whole width, moving the line pointers is faster */ | |
9279 j = row + i; | |
9280 temp = LineOffset[j]; | |
9281 while ((j += line_count) <= end - 1) | |
9282 { | |
9283 LineOffset[j - line_count] = LineOffset[j]; | |
9284 LineWraps[j - line_count] = LineWraps[j]; | |
9285 } | |
9286 LineOffset[j - line_count] = temp; | |
9287 LineWraps[j - line_count] = FALSE; | |
9288 if (can_clear((char_u *)" ")) | |
9289 lineclear(temp, (int)Columns); | |
9290 else | |
9291 lineinvalid(temp, (int)Columns); | |
9292 } | |
9293 } | |
9294 | |
9295 screen_stop_highlight(); | |
9296 | |
9297 #ifdef FEAT_VERTSPLIT | |
9298 /* redraw the characters */ | |
9299 if (type == USE_REDRAW) | |
9300 redraw_block(row, end, wp); | |
9301 else | |
9302 #endif | |
9303 if (type == USE_T_CD) /* delete the lines */ | |
9304 { | |
9305 windgoto(cursor_row, 0); | |
9306 out_str(T_CD); | |
9307 screen_start(); /* don't know where cursor is now */ | |
9308 } | |
9309 else if (type == USE_T_CDL) | |
9310 { | |
9311 windgoto(cursor_row, 0); | |
9312 term_delete_lines(line_count); | |
9313 screen_start(); /* don't know where cursor is now */ | |
9314 } | |
9315 /* | |
9316 * Deleting lines at top of the screen or scroll region: Just scroll | |
9317 * the whole screen (scroll region) up by outputting newlines on the | |
9318 * last line. | |
9319 */ | |
9320 else if (type == USE_NL) | |
9321 { | |
9322 windgoto(cursor_end - 1, 0); | |
9323 for (i = line_count; --i >= 0; ) | |
9324 out_char('\n'); /* cursor will remain on same line */ | |
9325 } | |
9326 else | |
9327 { | |
9328 for (i = line_count; --i >= 0; ) | |
9329 { | |
9330 if (type == USE_T_DL) | |
9331 { | |
9332 windgoto(cursor_row, 0); | |
9333 out_str(T_DL); /* delete a line */ | |
9334 } | |
9335 else /* type == USE_T_CE */ | |
9336 { | |
9337 windgoto(cursor_row + i, 0); | |
9338 out_str(T_CE); /* erase a line */ | |
9339 } | |
9340 screen_start(); /* don't know where cursor is now */ | |
9341 } | |
9342 } | |
9343 | |
9344 /* | |
9345 * If the 'db' flag is set, we need to clear the lines that have been | |
9346 * scrolled up at the bottom of the region. | |
9347 */ | |
9348 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9349 { | |
9350 for (i = line_count; i > 0; --i) | |
9351 { | |
9352 windgoto(cursor_end - i, 0); | |
9353 out_str(T_CE); /* erase a line */ | |
9354 screen_start(); /* don't know where cursor is now */ | |
9355 } | |
9356 } | |
9357 | |
9358 #ifdef FEAT_GUI | |
9359 gui_can_update_cursor(); | |
9360 if (gui.in_use) | |
9361 out_flush(); /* always flush after a scroll */ | |
9362 #endif | |
9363 | |
9364 return OK; | |
9365 } | |
9366 | |
9367 /* | |
9368 * show the current mode and ruler | |
9369 * | |
9370 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9371 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9372 * cleared only if a mode is shown. | |
9373 * Return the length of the message (0 if no message). | |
9374 */ | |
9375 int | |
9376 showmode() | |
9377 { | |
9378 int need_clear; | |
9379 int length = 0; | |
9380 int do_mode; | |
9381 int attr; | |
9382 int nwr_save; | |
9383 #ifdef FEAT_INS_EXPAND | |
9384 int sub_attr; | |
9385 #endif | |
9386 | |
642 | 9387 do_mode = ((p_smd && msg_silent == 0) |
9388 && ((State & INSERT) | |
9389 || restart_edit | |
7 | 9390 #ifdef FEAT_VISUAL |
9391 || VIsual_active | |
9392 #endif | |
9393 )); | |
9394 if (do_mode || Recording) | |
9395 { | |
9396 /* | |
9397 * Don't show mode right now, when not redrawing or inside a mapping. | |
9398 * Call char_avail() only when we are going to show something, because | |
9399 * it takes a bit of time. | |
9400 */ | |
9401 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9402 { | |
9403 redraw_cmdline = TRUE; /* show mode later */ | |
9404 return 0; | |
9405 } | |
9406 | |
9407 nwr_save = need_wait_return; | |
9408 | |
9409 /* wait a bit before overwriting an important message */ | |
9410 check_for_delay(FALSE); | |
9411 | |
9412 /* if the cmdline is more than one line high, erase top lines */ | |
9413 need_clear = clear_cmdline; | |
9414 if (clear_cmdline && cmdline_row < Rows - 1) | |
9415 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9416 | |
9417 /* Position on the last line in the window, column 0 */ | |
9418 msg_pos_mode(); | |
9419 cursor_off(); | |
9420 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9421 if (do_mode) | |
9422 { | |
9423 MSG_PUTS_ATTR("--", attr); | |
9424 #if defined(FEAT_XIM) | |
1668 | 9425 # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
7 | 9426 if (xic != NULL && im_get_status() && !p_imdisable |
9427 && curbuf->b_p_iminsert == B_IMODE_IM) | |
1668 | 9428 # else |
9429 if ( | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9430 # ifdef FEAT_GUI_GTK |
1668 | 9431 preedit_get_status() |
9432 # else | |
9433 im_get_status() | |
9434 # endif | |
9435 ) | |
9436 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9437 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9438 MSG_PUTS_ATTR(" IM", attr); |
9439 # else | |
9440 MSG_PUTS_ATTR(" XIM", attr); | |
9441 # endif | |
9442 #endif | |
9443 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9444 if (gui.in_use) | |
9445 { | |
9446 if (hangul_input_state_get()) | |
236 | 9447 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9448 } |
9449 #endif | |
9450 #ifdef FEAT_INS_EXPAND | |
9451 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9452 { | |
9453 /* These messages can get long, avoid a wrap in a narrow | |
9454 * window. Prefer showing edit_submode_extra. */ | |
9455 length = (Rows - msg_row) * Columns - 3; | |
9456 if (edit_submode_extra != NULL) | |
9457 length -= vim_strsize(edit_submode_extra); | |
9458 if (length > 0) | |
9459 { | |
9460 if (edit_submode_pre != NULL) | |
9461 length -= vim_strsize(edit_submode_pre); | |
9462 if (length - vim_strsize(edit_submode) > 0) | |
9463 { | |
9464 if (edit_submode_pre != NULL) | |
9465 msg_puts_attr(edit_submode_pre, attr); | |
9466 msg_puts_attr(edit_submode, attr); | |
9467 } | |
9468 if (edit_submode_extra != NULL) | |
9469 { | |
9470 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9471 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9472 sub_attr = hl_attr(edit_submode_highl); | |
9473 else | |
9474 sub_attr = attr; | |
9475 msg_puts_attr(edit_submode_extra, sub_attr); | |
9476 } | |
9477 } | |
9478 length = 0; | |
9479 } | |
9480 else | |
9481 #endif | |
9482 { | |
9483 #ifdef FEAT_VREPLACE | |
9484 if (State & VREPLACE_FLAG) | |
9485 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9486 else | |
9487 #endif | |
9488 if (State & REPLACE_FLAG) | |
9489 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9490 else if (State & INSERT) | |
9491 { | |
9492 #ifdef FEAT_RIGHTLEFT | |
9493 if (p_ri) | |
9494 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9495 #endif | |
9496 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9497 } | |
9498 else if (restart_edit == 'I') | |
9499 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9500 else if (restart_edit == 'R') | |
9501 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9502 else if (restart_edit == 'V') | |
9503 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9504 #ifdef FEAT_RIGHTLEFT | |
9505 if (p_hkmap) | |
9506 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9507 # ifdef FEAT_FKMAP | |
9508 if (p_fkmap) | |
9509 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9510 # endif | |
9511 #endif | |
9512 #ifdef FEAT_KEYMAP | |
9513 if (State & LANGMAP) | |
9514 { | |
9515 # ifdef FEAT_ARABIC | |
9516 if (curwin->w_p_arab) | |
9517 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9518 else | |
9519 # endif | |
9520 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9521 } | |
9522 #endif | |
9523 if ((State & INSERT) && p_paste) | |
9524 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9525 | |
9526 #ifdef FEAT_VISUAL | |
9527 if (VIsual_active) | |
9528 { | |
9529 char *p; | |
9530 | |
9531 /* Don't concatenate separate words to avoid translation | |
9532 * problems. */ | |
9533 switch ((VIsual_select ? 4 : 0) | |
9534 + (VIsual_mode == Ctrl_V) * 2 | |
9535 + (VIsual_mode == 'V')) | |
9536 { | |
9537 case 0: p = N_(" VISUAL"); break; | |
9538 case 1: p = N_(" VISUAL LINE"); break; | |
9539 case 2: p = N_(" VISUAL BLOCK"); break; | |
9540 case 4: p = N_(" SELECT"); break; | |
9541 case 5: p = N_(" SELECT LINE"); break; | |
9542 default: p = N_(" SELECT BLOCK"); break; | |
9543 } | |
9544 MSG_PUTS_ATTR(_(p), attr); | |
9545 } | |
9546 #endif | |
9547 MSG_PUTS_ATTR(" --", attr); | |
9548 } | |
644 | 9549 |
7 | 9550 need_clear = TRUE; |
9551 } | |
9552 if (Recording | |
9553 #ifdef FEAT_INS_EXPAND | |
9554 && edit_submode == NULL /* otherwise it gets too long */ | |
9555 #endif | |
9556 ) | |
9557 { | |
9558 MSG_PUTS_ATTR(_("recording"), attr); | |
9559 need_clear = TRUE; | |
9560 } | |
644 | 9561 |
9562 mode_displayed = TRUE; | |
7 | 9563 if (need_clear || clear_cmdline) |
9564 msg_clr_eos(); | |
9565 msg_didout = FALSE; /* overwrite this message */ | |
9566 length = msg_col; | |
9567 msg_col = 0; | |
9568 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9569 } | |
9570 else if (clear_cmdline && msg_silent == 0) | |
9571 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9572 msg_clr_cmdline(); | |
9573 | |
9574 #ifdef FEAT_CMDL_INFO | |
9575 # ifdef FEAT_VISUAL | |
9576 /* In Visual mode the size of the selected area must be redrawn. */ | |
9577 if (VIsual_active) | |
9578 clear_showcmd(); | |
9579 # endif | |
9580 | |
9581 /* If the last window has no status line, the ruler is after the mode | |
9582 * message and must be redrawn */ | |
9583 if (redrawing() | |
9584 # ifdef FEAT_WINDOWS | |
9585 && lastwin->w_status_height == 0 | |
9586 # endif | |
9587 ) | |
9588 win_redr_ruler(lastwin, TRUE); | |
9589 #endif | |
9590 redraw_cmdline = FALSE; | |
9591 clear_cmdline = FALSE; | |
9592 | |
9593 return length; | |
9594 } | |
9595 | |
9596 /* | |
9597 * Position for a mode message. | |
9598 */ | |
9599 static void | |
9600 msg_pos_mode() | |
9601 { | |
9602 msg_col = 0; | |
9603 msg_row = Rows - 1; | |
9604 } | |
9605 | |
9606 /* | |
9607 * Delete mode message. Used when ESC is typed which is expected to end | |
9608 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9609 * Caller should check "mode_displayed". |
7 | 9610 */ |
9611 void | |
9612 unshowmode(force) | |
9613 int force; | |
9614 { | |
9615 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9616 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9617 */ |
9618 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9619 redraw_cmdline = TRUE; /* delete mode later */ | |
9620 else | |
9621 { | |
9622 msg_pos_mode(); | |
9623 if (Recording) | |
9624 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9625 msg_clr_eos(); | |
9626 } | |
9627 } | |
9628 | |
667 | 9629 #if defined(FEAT_WINDOWS) |
9630 /* | |
9631 * Draw the tab pages line at the top of the Vim window. | |
9632 */ | |
9633 static void | |
677 | 9634 draw_tabline() |
667 | 9635 { |
9636 int tabcount = 0; | |
9637 tabpage_T *tp; | |
9638 int tabwidth; | |
9639 int col = 0; | |
673 | 9640 int scol = 0; |
667 | 9641 int attr; |
9642 win_T *wp; | |
671 | 9643 win_T *cwp; |
9644 int wincount; | |
9645 int modified; | |
667 | 9646 int c; |
9647 int len; | |
9648 int attr_sel = hl_attr(HLF_TPS); | |
9649 int attr_nosel = hl_attr(HLF_TP); | |
9650 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9651 char_u *p; |
677 | 9652 int room; |
9653 int use_sep_chars = (t_colors < 8 | |
9654 #ifdef FEAT_GUI | |
9655 && !gui.in_use | |
9656 #endif | |
9657 ); | |
673 | 9658 |
9659 redraw_tabline = FALSE; | |
667 | 9660 |
685 | 9661 #ifdef FEAT_GUI_TABLINE |
798 | 9662 /* Take care of a GUI tabline. */ |
685 | 9663 if (gui_use_tabline()) |
9664 { | |
9665 gui_update_tabline(); | |
9666 return; | |
9667 } | |
9668 #endif | |
9669 | |
9670 if (tabline_height() < 1) | |
667 | 9671 return; |
9672 | |
677 | 9673 #if defined(FEAT_STL_OPT) |
681 | 9674 |
9675 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9676 for (scol = 0; scol < Columns; ++scol) | |
9677 TabPageIdxs[scol] = 0; | |
9678 | |
677 | 9679 /* Use the 'tabline' option if it's set. */ |
9680 if (*p_tal != NUL) | |
9681 { | |
680 | 9682 int save_called_emsg = called_emsg; |
9683 | |
9684 /* Check for an error. If there is one we would loop in redrawing the | |
9685 * screen. Avoid that by making 'tabline' empty. */ | |
9686 called_emsg = FALSE; | |
677 | 9687 win_redr_custom(NULL, FALSE); |
680 | 9688 if (called_emsg) |
9689 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9690 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9691 called_emsg |= save_called_emsg; |
9692 } | |
9693 else | |
9694 #endif | |
9695 { | |
9696 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9697 ++tabcount; | |
9698 | |
9699 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9700 if (tabwidth < 6) | |
9701 tabwidth = 6; | |
9702 | |
9703 attr = attr_nosel; | |
9704 tabcount = 0; | |
681 | 9705 scol = 0; |
699 | 9706 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9707 tp = tp->tp_next) | |
680 | 9708 { |
9709 scol = col; | |
9710 | |
9711 if (tp->tp_topframe == topframe) | |
9712 attr = attr_sel; | |
9713 if (use_sep_chars && col > 0) | |
9714 screen_putchar('|', 0, col++, attr); | |
9715 | |
9716 if (tp->tp_topframe != topframe) | |
9717 attr = attr_nosel; | |
9718 | |
9719 screen_putchar(' ', 0, col++, attr); | |
9720 | |
9721 if (tp == curtab) | |
9722 { | |
9723 cwp = curwin; | |
9724 wp = firstwin; | |
9725 } | |
9726 else | |
9727 { | |
9728 cwp = tp->tp_curwin; | |
9729 wp = tp->tp_firstwin; | |
9730 } | |
9731 | |
9732 modified = FALSE; | |
9733 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9734 if (bufIsChanged(wp->w_buffer)) | |
9735 modified = TRUE; | |
9736 if (modified || wincount > 1) | |
9737 { | |
9738 if (wincount > 1) | |
9739 { | |
9740 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9741 len = (int)STRLEN(NameBuff); |
699 | 9742 if (col + len >= Columns - 3) |
9743 break; | |
680 | 9744 screen_puts_len(NameBuff, len, 0, col, |
677 | 9745 #if defined(FEAT_SYN_HL) |
680 | 9746 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9747 #else |
680 | 9748 attr |
9749 #endif | |
9750 ); | |
9751 col += len; | |
9752 } | |
9753 if (modified) | |
9754 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9755 screen_putchar(' ', 0, col++, attr); | |
9756 } | |
9757 | |
9758 room = scol - col + tabwidth - 1; | |
9759 if (room > 0) | |
9760 { | |
685 | 9761 /* Get buffer name in NameBuff[] */ |
9762 get_trans_bufname(cwp->w_buffer); | |
819 | 9763 shorten_dir(NameBuff); |
680 | 9764 len = vim_strsize(NameBuff); |
9765 p = NameBuff; | |
677 | 9766 #ifdef FEAT_MBYTE |
680 | 9767 if (has_mbyte) |
9768 while (len > room) | |
9769 { | |
9770 len -= ptr2cells(p); | |
9771 mb_ptr_adv(p); | |
9772 } | |
9773 else | |
9774 #endif | |
9775 if (len > room) | |
677 | 9776 { |
680 | 9777 p += len - room; |
9778 len = room; | |
677 | 9779 } |
699 | 9780 if (len > Columns - col - 1) |
9781 len = Columns - col - 1; | |
680 | 9782 |
835 | 9783 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9784 col += len; |
9785 } | |
9786 screen_putchar(' ', 0, col++, attr); | |
9787 | |
9788 /* Store the tab page number in TabPageIdxs[], so that | |
9789 * jump_to_mouse() knows where each one is. */ | |
9790 ++tabcount; | |
9791 while (scol < col) | |
9792 TabPageIdxs[scol++] = tabcount; | |
9793 } | |
9794 | |
9795 if (use_sep_chars) | |
9796 c = '_'; | |
9797 else | |
9798 c = ' '; | |
9799 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9800 |
9801 /* Put an "X" for closing the current tab if there are several. */ | |
9802 if (first_tabpage->tp_next != NULL) | |
9803 { | |
9804 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9805 TabPageIdxs[Columns - 1] = -999; | |
9806 } | |
9807 } | |
834 | 9808 |
9809 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9810 * set. */ | |
9811 redraw_tabline = FALSE; | |
667 | 9812 } |
685 | 9813 |
9814 /* | |
9815 * Get buffer name for "buf" into NameBuff[]. | |
9816 * Takes care of special buffer names and translates special characters. | |
9817 */ | |
9818 void | |
9819 get_trans_bufname(buf) | |
9820 buf_T *buf; | |
9821 { | |
9822 if (buf_spname(buf) != NULL) | |
9823 STRCPY(NameBuff, buf_spname(buf)); | |
9824 else | |
9825 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9826 trans_characters(NameBuff, MAXPATHL); | |
9827 } | |
667 | 9828 #endif |
9829 | |
7 | 9830 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9831 /* | |
9832 * Get the character to use in a status line. Get its attributes in "*attr". | |
9833 */ | |
9834 static int | |
9835 fillchar_status(attr, is_curwin) | |
9836 int *attr; | |
9837 int is_curwin; | |
9838 { | |
9839 int fill; | |
9840 if (is_curwin) | |
9841 { | |
9842 *attr = hl_attr(HLF_S); | |
9843 fill = fill_stl; | |
9844 } | |
9845 else | |
9846 { | |
9847 *attr = hl_attr(HLF_SNC); | |
9848 fill = fill_stlnc; | |
9849 } | |
9850 /* Use fill when there is highlighting, and highlighting of current | |
9851 * window differs, or the fillchars differ, or this is not the | |
9852 * current window */ | |
9853 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9854 || !is_curwin || firstwin == lastwin) | |
9855 || (fill_stl != fill_stlnc))) | |
9856 return fill; | |
9857 if (is_curwin) | |
9858 return '^'; | |
9859 return '='; | |
9860 } | |
9861 #endif | |
9862 | |
9863 #ifdef FEAT_VERTSPLIT | |
9864 /* | |
9865 * Get the character to use in a separator between vertically split windows. | |
9866 * Get its attributes in "*attr". | |
9867 */ | |
9868 static int | |
9869 fillchar_vsep(attr) | |
9870 int *attr; | |
9871 { | |
9872 *attr = hl_attr(HLF_C); | |
9873 if (*attr == 0 && fill_vert == ' ') | |
9874 return '|'; | |
9875 else | |
9876 return fill_vert; | |
9877 } | |
9878 #endif | |
9879 | |
9880 /* | |
9881 * Return TRUE if redrawing should currently be done. | |
9882 */ | |
9883 int | |
9884 redrawing() | |
9885 { | |
9886 return (!RedrawingDisabled | |
9887 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9888 } | |
9889 | |
9890 /* | |
9891 * Return TRUE if printing messages should currently be done. | |
9892 */ | |
9893 int | |
9894 messaging() | |
9895 { | |
9896 return (!(p_lz && char_avail() && !KeyTyped)); | |
9897 } | |
9898 | |
9899 /* | |
9900 * Show current status info in ruler and various other places | |
9901 * If always is FALSE, only show ruler if position has changed. | |
9902 */ | |
9903 void | |
9904 showruler(always) | |
9905 int always; | |
9906 { | |
9907 if (!always && !redrawing()) | |
9908 return; | |
574 | 9909 #ifdef FEAT_INS_EXPAND |
9910 if (pum_visible()) | |
9911 { | |
639 | 9912 # ifdef FEAT_WINDOWS |
574 | 9913 /* Don't redraw right now, do it later. */ |
9914 curwin->w_redr_status = TRUE; | |
639 | 9915 # endif |
574 | 9916 return; |
9917 } | |
9918 #endif | |
7 | 9919 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9920 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9921 { |
1983 | 9922 redraw_custom_statusline(curwin); |
680 | 9923 } |
7 | 9924 else |
9925 #endif | |
9926 #ifdef FEAT_CMDL_INFO | |
9927 win_redr_ruler(curwin, always); | |
9928 #endif | |
9929 | |
9930 #ifdef FEAT_TITLE | |
9931 if (need_maketitle | |
9932 # ifdef FEAT_STL_OPT | |
9933 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9934 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9935 # endif | |
9936 ) | |
9937 maketitle(); | |
9938 #endif | |
1588 | 9939 #ifdef FEAT_WINDOWS |
9940 /* Redraw the tab pages line if needed. */ | |
9941 if (redraw_tabline) | |
9942 draw_tabline(); | |
9943 #endif | |
7 | 9944 } |
9945 | |
9946 #ifdef FEAT_CMDL_INFO | |
9947 static void | |
9948 win_redr_ruler(wp, always) | |
9949 win_T *wp; | |
9950 int always; | |
9951 { | |
1869 | 9952 #define RULER_BUF_LEN 70 |
9953 char_u buffer[RULER_BUF_LEN]; | |
7 | 9954 int row; |
9955 int fillchar; | |
9956 int attr; | |
9957 int empty_line = FALSE; | |
9958 colnr_T virtcol; | |
9959 int i; | |
1869 | 9960 size_t len; |
7 | 9961 int o; |
9962 #ifdef FEAT_VERTSPLIT | |
9963 int this_ru_col; | |
9964 int off = 0; | |
9965 int width = Columns; | |
9966 # define WITH_OFF(x) x | |
9967 # define WITH_WIDTH(x) x | |
9968 #else | |
9969 # define WITH_OFF(x) 0 | |
9970 # define WITH_WIDTH(x) Columns | |
9971 # define this_ru_col ru_col | |
9972 #endif | |
9973 | |
9974 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9975 if (!p_ru) | |
9976 return; | |
9977 | |
9978 /* | |
9979 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
9980 * after deleting lines, before cursor.lnum is corrected. | |
9981 */ | |
9982 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
9983 return; | |
9984 | |
9985 #ifdef FEAT_INS_EXPAND | |
9986 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
9987 * the (long) mode message. */ | |
9988 # ifdef FEAT_WINDOWS | |
9989 if (wp == lastwin && lastwin->w_status_height == 0) | |
9990 # endif | |
9991 if (edit_submode != NULL) | |
9992 return; | |
540 | 9993 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
9994 if (pum_visible()) | |
9995 return; | |
7 | 9996 #endif |
9997 | |
9998 #ifdef FEAT_STL_OPT | |
9999 if (*p_ruf) | |
10000 { | |
680 | 10001 int save_called_emsg = called_emsg; |
10002 | |
10003 called_emsg = FALSE; | |
7 | 10004 win_redr_custom(wp, TRUE); |
680 | 10005 if (called_emsg) |
10006 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 10007 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 10008 called_emsg |= save_called_emsg; |
7 | 10009 return; |
10010 } | |
10011 #endif | |
10012 | |
10013 /* | |
10014 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
10015 */ | |
10016 if (!(State & INSERT) | |
10017 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
10018 empty_line = TRUE; | |
10019 | |
10020 /* | |
10021 * Only draw the ruler when something changed. | |
10022 */ | |
10023 validate_virtcol_win(wp); | |
10024 if ( redraw_cmdline | |
10025 || always | |
10026 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
10027 || wp->w_cursor.col != wp->w_ru_cursor.col | |
10028 || wp->w_virtcol != wp->w_ru_virtcol | |
10029 #ifdef FEAT_VIRTUALEDIT | |
10030 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
10031 #endif | |
10032 || wp->w_topline != wp->w_ru_topline | |
10033 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
10034 #ifdef FEAT_DIFF | |
10035 || wp->w_topfill != wp->w_ru_topfill | |
10036 #endif | |
10037 || empty_line != wp->w_ru_empty) | |
10038 { | |
10039 cursor_off(); | |
10040 #ifdef FEAT_WINDOWS | |
10041 if (wp->w_status_height) | |
10042 { | |
10043 row = W_WINROW(wp) + wp->w_height; | |
10044 fillchar = fillchar_status(&attr, wp == curwin); | |
10045 # ifdef FEAT_VERTSPLIT | |
10046 off = W_WINCOL(wp); | |
10047 width = W_WIDTH(wp); | |
10048 # endif | |
10049 } | |
10050 else | |
10051 #endif | |
10052 { | |
10053 row = Rows - 1; | |
10054 fillchar = ' '; | |
10055 attr = 0; | |
10056 #ifdef FEAT_VERTSPLIT | |
10057 width = Columns; | |
10058 off = 0; | |
10059 #endif | |
10060 } | |
10061 | |
10062 /* In list mode virtcol needs to be recomputed */ | |
10063 virtcol = wp->w_virtcol; | |
10064 if (wp->w_p_list && lcs_tab1 == NUL) | |
10065 { | |
10066 wp->w_p_list = FALSE; | |
10067 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10068 wp->w_p_list = TRUE; | |
10069 } | |
10070 | |
10071 /* | |
10072 * Some sprintfs return the length, some return a pointer. | |
10073 * To avoid portability problems we use strlen() here. | |
10074 */ | |
1869 | 10075 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10076 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10077 ? 0L | |
10078 : (long)(wp->w_cursor.lnum)); | |
1869 | 10079 len = STRLEN(buffer); |
10080 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10081 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10082 (int)virtcol + 1); | |
10083 | |
10084 /* | |
10085 * Add a "50%" if there is room for it. | |
10086 * On the last line, don't print in the last column (scrolls the | |
10087 * screen up on some terminals). | |
10088 */ | |
10089 i = (int)STRLEN(buffer); | |
1869 | 10090 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10091 o = i + vim_strsize(buffer + i + 1); |
10092 #ifdef FEAT_WINDOWS | |
10093 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10094 #endif | |
10095 ++o; | |
10096 #ifdef FEAT_VERTSPLIT | |
10097 this_ru_col = ru_col - (Columns - width); | |
10098 if (this_ru_col < 0) | |
10099 this_ru_col = 0; | |
10100 #endif | |
10101 /* Never use more than half the window/screen width, leave the other | |
10102 * half for the filename. */ | |
10103 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10104 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10105 if (this_ru_col + o < WITH_WIDTH(width)) | |
10106 { | |
10107 while (this_ru_col + o < WITH_WIDTH(width)) | |
10108 { | |
10109 #ifdef FEAT_MBYTE | |
10110 if (has_mbyte) | |
10111 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10112 else | |
10113 #endif | |
10114 buffer[i++] = fillchar; | |
10115 ++o; | |
10116 } | |
1869 | 10117 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10118 } |
10119 /* Truncate at window boundary. */ | |
10120 #ifdef FEAT_MBYTE | |
10121 if (has_mbyte) | |
10122 { | |
10123 o = 0; | |
474 | 10124 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10125 { |
10126 o += (*mb_ptr2cells)(buffer + i); | |
10127 if (this_ru_col + o > WITH_WIDTH(width)) | |
10128 { | |
10129 buffer[i] = NUL; | |
10130 break; | |
10131 } | |
10132 } | |
10133 } | |
10134 else | |
10135 #endif | |
10136 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10137 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10138 | |
10139 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10140 i = redraw_cmdline; | |
10141 screen_fill(row, row + 1, | |
10142 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10143 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10144 fillchar, fillchar, attr); | |
10145 /* don't redraw the cmdline because of showing the ruler */ | |
10146 redraw_cmdline = i; | |
10147 wp->w_ru_cursor = wp->w_cursor; | |
10148 wp->w_ru_virtcol = wp->w_virtcol; | |
10149 wp->w_ru_empty = empty_line; | |
10150 wp->w_ru_topline = wp->w_topline; | |
10151 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10152 #ifdef FEAT_DIFF | |
10153 wp->w_ru_topfill = wp->w_topfill; | |
10154 #endif | |
10155 } | |
10156 } | |
10157 #endif | |
13 | 10158 |
10159 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10160 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10161 * 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
|
10162 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10163 * Otherwise it depends on 'numberwidth' and the line count. |
10164 */ | |
10165 int | |
10166 number_width(wp) | |
10167 win_T *wp; | |
10168 { | |
10169 int n; | |
10170 linenr_T lnum; | |
10171 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10172 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10173 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10174 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
|
10175 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10176 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10177 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10178 |
13 | 10179 if (lnum == wp->w_nrwidth_line_count) |
10180 return wp->w_nrwidth_width; | |
10181 wp->w_nrwidth_line_count = lnum; | |
10182 | |
10183 n = 0; | |
10184 do | |
10185 { | |
856 | 10186 lnum /= 10; |
10187 ++n; | |
13 | 10188 } while (lnum > 0); |
10189 | |
10190 /* 'numberwidth' gives the minimal width plus one */ | |
10191 if (n < wp->w_p_nuw - 1) | |
10192 n = wp->w_p_nuw - 1; | |
10193 | |
10194 wp->w_nrwidth_width = n; | |
10195 return n; | |
10196 } | |
10197 #endif |