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