Mercurial > vim
annotate src/screen.c @ 3674:b9aa7fb4a928 v7.3.597
updated for version 7.3.597
Problem: 'clipboard' "autoselect" only applies to the * register. (Sergey
Vakulenko)
Solution: Make 'autoselect' work for the + register. (Christian Brabant)
Add the "autoselectplus" option in 'clipboard' and the "P" flag in
'guioptions'.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 10 Jul 2012 16:49:23 +0200 |
parents | 583e46e4a56c |
children | c0256c4bd91e |
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 | |
3586 | 92 #define MB_FILLER_CHAR '<' /* character used when a double-width character |
93 * doesn't fit. */ | |
94 | |
7 | 95 /* |
96 * The attributes that are actually active for writing to the screen. | |
97 */ | |
98 static int screen_attr = 0; | |
99 | |
100 /* | |
101 * Positioning the cursor is reduced by remembering the last position. | |
102 * Mostly used by windgoto() and screen_char(). | |
103 */ | |
104 static int screen_cur_row, screen_cur_col; /* last known cursor position */ | |
105 | |
106 #ifdef FEAT_SEARCH_EXTRA | |
107 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
108 #endif | |
109 | |
110 #ifdef FEAT_FOLDING | |
111 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
112 #endif | |
113 | |
114 /* | |
115 * Buffer for one screen line (characters and attributes). | |
116 */ | |
117 static schar_T *current_ScreenLine; | |
118 | |
119 static void win_update __ARGS((win_T *wp)); | |
534 | 120 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 121 #ifdef FEAT_FOLDING |
122 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
123 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
124 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
125 #endif | |
625 | 126 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 127 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
128 #ifdef FEAT_RIGHTLEFT | |
129 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
131 #else | |
132 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
133 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
134 #endif | |
135 #ifdef FEAT_VERTSPLIT | |
136 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
137 #endif | |
680 | 138 #ifdef FEAT_STL_OPT |
1983 | 139 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 140 #endif |
7 | 141 #ifdef FEAT_SEARCH_EXTRA |
1326 | 142 #define SEARCH_HL_PRIORITY 0 |
7 | 143 static void start_search_hl __ARGS((void)); |
144 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
|
145 static void init_search_hl __ARGS((win_T *wp)); |
7 | 146 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
147 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
148 #endif | |
149 static void screen_start_highlight __ARGS((int attr)); | |
150 static void screen_char __ARGS((unsigned off, int row, int col)); | |
151 #ifdef FEAT_MBYTE | |
152 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
153 #endif | |
154 static void screenclear2 __ARGS((void)); | |
155 static void lineclear __ARGS((unsigned off, int width)); | |
156 static void lineinvalid __ARGS((unsigned off, int width)); | |
157 #ifdef FEAT_VERTSPLIT | |
158 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
159 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
160 #endif | |
161 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
162 static void win_rest_invalid __ARGS((win_T *wp)); | |
163 static void msg_pos_mode __ARGS((void)); | |
667 | 164 #if defined(FEAT_WINDOWS) |
677 | 165 static void draw_tabline __ARGS((void)); |
667 | 166 #endif |
7 | 167 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
168 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
169 #endif | |
170 #ifdef FEAT_VERTSPLIT | |
171 static int fillchar_vsep __ARGS((int *attr)); | |
172 #endif | |
173 #ifdef FEAT_STL_OPT | |
574 | 174 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 175 #endif |
176 #ifdef FEAT_CMDL_INFO | |
177 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
178 #endif | |
179 | |
180 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
181 /* Ugly global: overrule attribute used by screen_char() */ | |
182 static int screen_char_attr = 0; | |
183 #endif | |
184 | |
185 /* | |
186 * Redraw the current window later, with update_screen(type). | |
187 * Set must_redraw only if not already set to a higher value. | |
188 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
189 */ | |
190 void | |
191 redraw_later(type) | |
192 int type; | |
193 { | |
194 redraw_win_later(curwin, type); | |
195 } | |
196 | |
197 void | |
198 redraw_win_later(wp, type) | |
199 win_T *wp; | |
200 int type; | |
201 { | |
202 if (wp->w_redr_type < type) | |
203 { | |
204 wp->w_redr_type = type; | |
205 if (type >= NOT_VALID) | |
206 wp->w_lines_valid = 0; | |
207 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
208 must_redraw = type; | |
209 } | |
210 } | |
211 | |
212 /* | |
213 * Force a complete redraw later. Also resets the highlighting. To be used | |
214 * after executing a shell command that messes up the screen. | |
215 */ | |
216 void | |
217 redraw_later_clear() | |
218 { | |
219 redraw_all_later(CLEAR); | |
826 | 220 #ifdef FEAT_GUI |
221 if (gui.in_use) | |
222 /* Use a code that will reset gui.highlight_mask in | |
223 * gui_stop_highlight(). */ | |
224 screen_attr = HL_ALL + 1; | |
225 else | |
226 #endif | |
227 /* Use attributes that is very unlikely to appear in text. */ | |
228 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 229 } |
230 | |
231 /* | |
232 * Mark all windows to be redrawn later. | |
233 */ | |
234 void | |
235 redraw_all_later(type) | |
236 int type; | |
237 { | |
238 win_T *wp; | |
239 | |
240 FOR_ALL_WINDOWS(wp) | |
241 { | |
242 redraw_win_later(wp, type); | |
243 } | |
244 } | |
245 | |
246 /* | |
301 | 247 * Mark all windows that are editing the current buffer to be updated later. |
7 | 248 */ |
249 void | |
250 redraw_curbuf_later(type) | |
251 int type; | |
252 { | |
253 redraw_buf_later(curbuf, type); | |
254 } | |
255 | |
256 void | |
257 redraw_buf_later(buf, type) | |
258 buf_T *buf; | |
259 int type; | |
260 { | |
261 win_T *wp; | |
262 | |
263 FOR_ALL_WINDOWS(wp) | |
264 { | |
265 if (wp->w_buffer == buf) | |
266 redraw_win_later(wp, type); | |
267 } | |
268 } | |
269 | |
270 /* | |
271 * Changed something in the current window, at buffer line "lnum", that | |
272 * requires that line and possibly other lines to be redrawn. | |
273 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
274 * Used to remove the "$" from a change command. | |
275 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
276 * may become invalid and the whole window will have to be redrawn. | |
277 */ | |
278 void | |
279 redrawWinline(lnum, invalid) | |
280 linenr_T lnum; | |
1883 | 281 int invalid UNUSED; /* window line height is invalid now */ |
7 | 282 { |
283 #ifdef FEAT_FOLDING | |
284 int i; | |
285 #endif | |
286 | |
287 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
288 curwin->w_redraw_top = lnum; | |
289 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
290 curwin->w_redraw_bot = lnum; | |
291 redraw_later(VALID); | |
292 | |
293 #ifdef FEAT_FOLDING | |
294 if (invalid) | |
295 { | |
296 /* A w_lines[] entry for this lnum has become invalid. */ | |
297 i = find_wl_entry(curwin, lnum); | |
298 if (i >= 0) | |
299 curwin->w_lines[i].wl_valid = FALSE; | |
300 } | |
301 #endif | |
302 } | |
303 | |
2255 | 304 #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
|
305 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 306 /* |
307 * update all windows that are editing the current buffer | |
308 */ | |
309 void | |
310 update_curbuf(type) | |
311 int type; | |
312 { | |
313 redraw_curbuf_later(type); | |
314 update_screen(type); | |
315 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
316 #endif |
7 | 317 |
318 /* | |
319 * update_screen() | |
320 * | |
321 * Based on the current value of curwin->w_topline, transfer a screenfull | |
322 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
323 */ | |
324 void | |
325 update_screen(type) | |
326 int type; | |
327 { | |
328 win_T *wp; | |
329 static int did_intro = FALSE; | |
330 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
331 int did_one; | |
332 #endif | |
333 | |
2008 | 334 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 335 if (!screen_valid(TRUE)) |
336 return; | |
337 | |
338 if (must_redraw) | |
339 { | |
340 if (type < must_redraw) /* use maximal type */ | |
341 type = must_redraw; | |
1331 | 342 |
343 /* must_redraw is reset here, so that when we run into some weird | |
344 * reason to redraw while busy redrawing (e.g., asynchronous | |
345 * scrolling), or update_topline() in win_update() will cause a | |
346 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 347 must_redraw = 0; |
348 } | |
349 | |
350 /* Need to update w_lines[]. */ | |
351 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
352 type = NOT_VALID; | |
353 | |
2008 | 354 /* Postpone the redrawing when it's not needed and when being called |
355 * recursively. */ | |
356 if (!redrawing() || updating_screen) | |
7 | 357 { |
358 redraw_later(type); /* remember type for next time */ | |
359 must_redraw = type; | |
360 if (type > INVERTED_ALL) | |
361 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
362 return; | |
363 } | |
364 | |
365 updating_screen = TRUE; | |
366 #ifdef FEAT_SYN_HL | |
367 ++display_tick; /* let syntax code know we're in a next round of | |
368 * display updating */ | |
369 #endif | |
370 | |
371 /* | |
372 * if the screen was scrolled up when displaying a message, scroll it down | |
373 */ | |
374 if (msg_scrolled) | |
375 { | |
376 clear_cmdline = TRUE; | |
377 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
378 type = CLEAR; | |
379 else if (type != CLEAR) | |
380 { | |
381 check_for_delay(FALSE); | |
382 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
383 type = CLEAR; | |
384 FOR_ALL_WINDOWS(wp) | |
385 { | |
386 if (W_WINROW(wp) < msg_scrolled) | |
387 { | |
388 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
389 && wp->w_redr_type < REDRAW_TOP | |
390 && wp->w_lines_valid > 0 | |
391 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
392 { | |
393 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
394 wp->w_redr_type = REDRAW_TOP; | |
395 } | |
396 else | |
397 { | |
398 wp->w_redr_type = NOT_VALID; | |
399 #ifdef FEAT_WINDOWS | |
400 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
401 <= msg_scrolled) | |
402 wp->w_redr_status = TRUE; | |
403 #endif | |
404 } | |
405 } | |
406 } | |
407 redraw_cmdline = TRUE; | |
667 | 408 #ifdef FEAT_WINDOWS |
673 | 409 redraw_tabline = TRUE; |
667 | 410 #endif |
7 | 411 } |
412 msg_scrolled = 0; | |
413 need_wait_return = FALSE; | |
414 } | |
415 | |
416 /* reset cmdline_row now (may have been changed temporarily) */ | |
417 compute_cmdrow(); | |
418 | |
419 /* Check for changed highlighting */ | |
420 if (need_highlight_changed) | |
421 highlight_changed(); | |
422 | |
423 if (type == CLEAR) /* first clear screen */ | |
424 { | |
425 screenclear(); /* will reset clear_cmdline */ | |
426 type = NOT_VALID; | |
427 } | |
428 | |
429 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
430 check_for_delay(FALSE); | |
431 | |
13 | 432 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
433 /* 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
|
434 * changes. */ |
13 | 435 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
436 && 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
|
437 ? number_width(curwin) : 0)) |
13 | 438 curwin->w_redr_type = NOT_VALID; |
439 #endif | |
440 | |
7 | 441 /* |
442 * Only start redrawing if there is really something to do. | |
443 */ | |
444 if (type == INVERTED) | |
445 update_curswant(); | |
446 if (curwin->w_redr_type < type | |
447 && !((type == VALID | |
448 && curwin->w_lines[0].wl_valid | |
449 #ifdef FEAT_DIFF | |
450 && curwin->w_topfill == curwin->w_old_topfill | |
451 && curwin->w_botfill == curwin->w_old_botfill | |
452 #endif | |
453 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
454 #ifdef FEAT_VISUAL | |
455 || (type == INVERTED | |
1043 | 456 && VIsual_active |
7 | 457 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
458 && curwin->w_old_visual_mode == VIsual_mode | |
459 && (curwin->w_valid & VALID_VIRTCOL) | |
460 && curwin->w_old_curswant == curwin->w_curswant) | |
461 #endif | |
462 )) | |
463 curwin->w_redr_type = type; | |
464 | |
849 | 465 #ifdef FEAT_WINDOWS |
466 /* Redraw the tab pages line if needed. */ | |
467 if (redraw_tabline || type >= NOT_VALID) | |
468 draw_tabline(); | |
469 #endif | |
470 | |
7 | 471 #ifdef FEAT_SYN_HL |
472 /* | |
473 * Correct stored syntax highlighting info for changes in each displayed | |
474 * buffer. Each buffer must only be done once. | |
475 */ | |
476 FOR_ALL_WINDOWS(wp) | |
477 { | |
478 if (wp->w_buffer->b_mod_set) | |
479 { | |
480 # ifdef FEAT_WINDOWS | |
481 win_T *wwp; | |
482 | |
483 /* Check if we already did this buffer. */ | |
484 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
485 if (wwp->w_buffer == wp->w_buffer) | |
486 break; | |
487 # endif | |
488 if ( | |
489 # ifdef FEAT_WINDOWS | |
490 wwp == wp && | |
491 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
492 syntax_present(wp)) |
7 | 493 syn_stack_apply_changes(wp->w_buffer); |
494 } | |
495 } | |
496 #endif | |
497 | |
498 /* | |
499 * Go from top to bottom through the windows, redrawing the ones that need | |
500 * it. | |
501 */ | |
502 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
503 did_one = FALSE; | |
504 #endif | |
505 #ifdef FEAT_SEARCH_EXTRA | |
506 search_hl.rm.regprog = NULL; | |
507 #endif | |
508 FOR_ALL_WINDOWS(wp) | |
509 { | |
510 if (wp->w_redr_type != 0) | |
511 { | |
512 cursor_off(); | |
513 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
514 if (!did_one) | |
515 { | |
516 did_one = TRUE; | |
517 # ifdef FEAT_SEARCH_EXTRA | |
518 start_search_hl(); | |
519 # endif | |
520 # ifdef FEAT_CLIPBOARD | |
521 /* When Visual area changed, may have to update selection. */ | |
3674 | 522 if (clip_star.available && clip_isautosel_star()) |
523 clip_update_selection(&clip_star); | |
524 if (clip_plus.available && clip_isautosel_plus()) | |
525 clip_update_selection(&clip_plus); | |
7 | 526 # endif |
527 #ifdef FEAT_GUI | |
528 /* Remove the cursor before starting to do anything, because | |
529 * scrolling may make it difficult to redraw the text under | |
530 * it. */ | |
531 if (gui.in_use) | |
532 gui_undraw_cursor(); | |
533 #endif | |
534 } | |
535 #endif | |
536 win_update(wp); | |
537 } | |
538 | |
539 #ifdef FEAT_WINDOWS | |
540 /* redraw status line after the window to minimize cursor movement */ | |
541 if (wp->w_redr_status) | |
542 { | |
543 cursor_off(); | |
544 win_redr_status(wp); | |
545 } | |
546 #endif | |
547 } | |
548 #if defined(FEAT_SEARCH_EXTRA) | |
549 end_search_hl(); | |
550 #endif | |
551 | |
552 #ifdef FEAT_WINDOWS | |
553 /* Reset b_mod_set flags. Going through all windows is probably faster | |
554 * than going through all buffers (there could be many buffers). */ | |
555 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
556 wp->w_buffer->b_mod_set = FALSE; | |
557 #else | |
558 curbuf->b_mod_set = FALSE; | |
559 #endif | |
560 | |
561 updating_screen = FALSE; | |
562 #ifdef FEAT_GUI | |
563 gui_may_resize_shell(); | |
564 #endif | |
565 | |
566 /* Clear or redraw the command line. Done last, because scrolling may | |
567 * mess up the command line. */ | |
568 if (clear_cmdline || redraw_cmdline) | |
569 showmode(); | |
570 | |
571 /* May put up an introductory message when not editing a file */ | |
572 if (!did_intro && bufempty() | |
573 && curbuf->b_fname == NULL | |
574 #ifdef FEAT_WINDOWS | |
575 && firstwin->w_next == NULL | |
576 #endif | |
577 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
578 intro_message(FALSE); | |
579 did_intro = TRUE; | |
580 | |
581 #ifdef FEAT_GUI | |
582 /* Redraw the cursor and update the scrollbars when all screen updating is | |
583 * done. */ | |
584 if (gui.in_use) | |
585 { | |
586 out_flush(); /* required before updating the cursor */ | |
587 if (did_one) | |
588 gui_update_cursor(FALSE, FALSE); | |
589 gui_update_scrollbars(FALSE); | |
590 } | |
591 #endif | |
592 } | |
593 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
594 #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
|
595 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
596 * 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
|
597 * 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
|
598 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
599 int |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
600 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
|
601 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
|
602 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
603 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
|
604 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 c = 'n'; |
2382
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
613 else if (State & CMDLINE) |
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
614 c = 'c'; |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
615 else |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
616 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
|
617 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
|
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 |
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 * 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
|
622 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
623 void |
2428
33148c37f3c9
Changes for VMS. Mostly by Zoltan Arpadffy.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
624 conceal_check_cursur_line() |
2378
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 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
|
627 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
628 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
|
629 /* 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
|
630 * 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
|
631 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
|
632 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
633 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
634 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
635 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
636 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
637 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
638 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
639 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
640 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
641 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
642 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
643 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
|
644 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
645 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
646 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
647 /* 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
|
648 * 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
|
649 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
650 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
651 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
652 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
653 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
|
654 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
655 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
|
656 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
657 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
|
658 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
659 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
660 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
661 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
662 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
663 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
|
664 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
665 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
666 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
667 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
668 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
669 row += wp->w_lines[j].wl_size; |
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 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
672 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
673 if (gui.in_use) |
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 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
676 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
677 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
678 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
679 } |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
680 need_cursor_line_redraw = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
681 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
682 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
683 |
7 | 684 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
685 static void update_prepare __ARGS((void)); | |
686 static void update_finish __ARGS((void)); | |
687 | |
688 /* | |
689 * Prepare for updating one or more windows. | |
2008 | 690 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 691 */ |
692 static void | |
693 update_prepare() | |
694 { | |
695 cursor_off(); | |
696 updating_screen = TRUE; | |
697 #ifdef FEAT_GUI | |
698 /* Remove the cursor before starting to do anything, because scrolling may | |
699 * make it difficult to redraw the text under it. */ | |
700 if (gui.in_use) | |
701 gui_undraw_cursor(); | |
702 #endif | |
703 #ifdef FEAT_SEARCH_EXTRA | |
704 start_search_hl(); | |
705 #endif | |
706 } | |
707 | |
708 /* | |
709 * Finish updating one or more windows. | |
710 */ | |
711 static void | |
712 update_finish() | |
713 { | |
714 if (redraw_cmdline) | |
715 showmode(); | |
716 | |
717 # ifdef FEAT_SEARCH_EXTRA | |
718 end_search_hl(); | |
719 # endif | |
720 | |
721 updating_screen = FALSE; | |
722 | |
723 # ifdef FEAT_GUI | |
724 gui_may_resize_shell(); | |
725 | |
726 /* Redraw the cursor and update the scrollbars when all screen updating is | |
727 * done. */ | |
728 if (gui.in_use) | |
729 { | |
730 out_flush(); /* required before updating the cursor */ | |
731 gui_update_cursor(FALSE, FALSE); | |
732 gui_update_scrollbars(FALSE); | |
733 } | |
734 # endif | |
735 } | |
736 #endif | |
737 | |
738 #if defined(FEAT_SIGNS) || defined(PROTO) | |
739 void | |
740 update_debug_sign(buf, lnum) | |
741 buf_T *buf; | |
742 linenr_T lnum; | |
743 { | |
744 win_T *wp; | |
745 int doit = FALSE; | |
746 | |
747 # ifdef FEAT_FOLDING | |
748 win_foldinfo.fi_level = 0; | |
749 # endif | |
750 | |
751 /* update/delete a specific mark */ | |
752 FOR_ALL_WINDOWS(wp) | |
753 { | |
754 if (buf != NULL && lnum > 0) | |
755 { | |
756 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
757 && lnum < wp->w_botline) | |
758 { | |
759 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
760 wp->w_redraw_top = lnum; | |
761 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
762 wp->w_redraw_bot = lnum; | |
763 redraw_win_later(wp, VALID); | |
764 } | |
765 } | |
766 else | |
767 redraw_win_later(wp, VALID); | |
768 if (wp->w_redr_type != 0) | |
769 doit = TRUE; | |
770 } | |
771 | |
3250 | 772 /* Return when there is nothing to do, screen updating is already |
773 * happening (recursive call) or still starting up. */ | |
774 if (!doit || updating_screen | |
775 #ifdef FEAT_GUI | |
776 || gui.starting | |
777 #endif | |
778 || starting) | |
7 | 779 return; |
780 | |
781 /* update all windows that need updating */ | |
782 update_prepare(); | |
783 | |
784 # ifdef FEAT_WINDOWS | |
785 for (wp = firstwin; wp; wp = wp->w_next) | |
786 { | |
787 if (wp->w_redr_type != 0) | |
788 win_update(wp); | |
789 if (wp->w_redr_status) | |
790 win_redr_status(wp); | |
791 } | |
792 # else | |
793 if (curwin->w_redr_type != 0) | |
794 win_update(curwin); | |
795 # endif | |
796 | |
797 update_finish(); | |
798 } | |
799 #endif | |
800 | |
801 | |
802 #if defined(FEAT_GUI) || defined(PROTO) | |
803 /* | |
804 * Update a single window, its status line and maybe the command line msg. | |
805 * Used for the GUI scrollbar. | |
806 */ | |
807 void | |
808 updateWindow(wp) | |
809 win_T *wp; | |
810 { | |
2008 | 811 /* return if already busy updating */ |
812 if (updating_screen) | |
813 return; | |
814 | |
7 | 815 update_prepare(); |
816 | |
817 #ifdef FEAT_CLIPBOARD | |
818 /* When Visual area changed, may have to update selection. */ | |
3674 | 819 if (clip_star.available && clip_isautosel_star()) |
820 clip_update_selection(&clip_star); | |
821 if (clip_plus.available && clip_isautosel_plus()) | |
822 clip_update_selection(&clip_plus); | |
7 | 823 #endif |
670 | 824 |
7 | 825 win_update(wp); |
670 | 826 |
7 | 827 #ifdef FEAT_WINDOWS |
670 | 828 /* When the screen was cleared redraw the tab pages line. */ |
673 | 829 if (redraw_tabline) |
677 | 830 draw_tabline(); |
670 | 831 |
7 | 832 if (wp->w_redr_status |
833 # ifdef FEAT_CMDL_INFO | |
834 || p_ru | |
835 # endif | |
836 # ifdef FEAT_STL_OPT | |
40 | 837 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 838 # endif |
839 ) | |
840 win_redr_status(wp); | |
841 #endif | |
842 | |
843 update_finish(); | |
844 } | |
845 #endif | |
846 | |
847 /* | |
848 * Update a single window. | |
849 * | |
850 * This may cause the windows below it also to be redrawn (when clearing the | |
851 * screen or scrolling lines). | |
852 * | |
853 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
854 * implies the one below it. | |
855 * NOT_VALID redraw the whole window | |
743 | 856 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 857 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
858 * INVERTED redraw the changed part of the Visual area | |
859 * INVERTED_ALL redraw the whole Visual area | |
860 * VALID 1. scroll up/down to adjust for a changed w_topline | |
861 * 2. update lines at the top when scrolled down | |
862 * 3. redraw changed text: | |
301 | 863 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 864 * b_mod_top and b_mod_bot. |
865 * - if wp->w_redraw_top non-zero, redraw lines between | |
866 * wp->w_redraw_top and wp->w_redr_bot. | |
867 * - continue redrawing when syntax status is invalid. | |
868 * 4. if scrolled up, update lines at the bottom. | |
869 * This results in three areas that may need updating: | |
870 * top: from first row to top_end (when scrolled down) | |
871 * mid: from mid_start to mid_end (update inversion or changed text) | |
872 * bot: from bot_start to last row (when scrolled up) | |
873 */ | |
874 static void | |
875 win_update(wp) | |
876 win_T *wp; | |
877 { | |
878 buf_T *buf = wp->w_buffer; | |
879 int type; | |
880 int top_end = 0; /* Below last row of the top area that needs | |
881 updating. 0 when no top area updating. */ | |
882 int mid_start = 999;/* first row of the mid area that needs | |
883 updating. 999 when no mid area updating. */ | |
884 int mid_end = 0; /* Below last row of the mid area that needs | |
885 updating. 0 when no mid area updating. */ | |
886 int bot_start = 999;/* first row of the bot area that needs | |
887 updating. 999 when no bot area updating */ | |
888 #ifdef FEAT_VISUAL | |
889 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
890 w_topline got smaller a bit */ | |
891 #endif | |
892 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 893 matchitem_T *cur; /* points to the match list */ |
7 | 894 int top_to_mod = FALSE; /* redraw above mod_top */ |
895 #endif | |
896 | |
897 int row; /* current window row to display */ | |
898 linenr_T lnum; /* current buffer lnum to display */ | |
899 int idx; /* current index in w_lines[] */ | |
900 int srow; /* starting row of the current line */ | |
901 | |
902 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
903 int didline = FALSE; /* if TRUE, we finished the last line */ | |
904 int i; | |
905 long j; | |
906 static int recursive = FALSE; /* being called recursively */ | |
907 int old_botline = wp->w_botline; | |
908 #ifdef FEAT_FOLDING | |
909 long fold_count; | |
910 #endif | |
911 #ifdef FEAT_SYN_HL | |
912 /* remember what happened to the previous line, to know if | |
913 * check_visual_highlight() can be used */ | |
914 #define DID_NONE 1 /* didn't update a line */ | |
915 #define DID_LINE 2 /* updated a normal line */ | |
916 #define DID_FOLD 3 /* updated a folded line */ | |
917 int did_update = DID_NONE; | |
918 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
919 #endif | |
920 linenr_T mod_top = 0; | |
921 linenr_T mod_bot = 0; | |
922 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
923 int save_got_int; | |
924 #endif | |
925 | |
926 type = wp->w_redr_type; | |
927 | |
928 if (type == NOT_VALID) | |
929 { | |
930 #ifdef FEAT_WINDOWS | |
931 wp->w_redr_status = TRUE; | |
932 #endif | |
933 wp->w_lines_valid = 0; | |
934 } | |
935 | |
936 /* Window is zero-height: nothing to draw. */ | |
937 if (wp->w_height == 0) | |
938 { | |
939 wp->w_redr_type = 0; | |
940 return; | |
941 } | |
942 | |
943 #ifdef FEAT_VERTSPLIT | |
944 /* Window is zero-width: Only need to draw the separator. */ | |
945 if (wp->w_width == 0) | |
946 { | |
947 /* draw the vertical separator right of this window */ | |
948 draw_vsep_win(wp, 0); | |
949 wp->w_redr_type = 0; | |
950 return; | |
951 } | |
952 #endif | |
953 | |
954 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
955 init_search_hl(wp); |
7 | 956 #endif |
957 | |
13 | 958 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
959 /* 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
|
960 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
961 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 962 if (wp->w_nrwidth != i) |
13 | 963 { |
964 type = NOT_VALID; | |
677 | 965 wp->w_nrwidth = i; |
13 | 966 } |
967 else | |
968 #endif | |
969 | |
7 | 970 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
971 { | |
972 /* | |
973 * When there are both inserted/deleted lines and specific lines to be | |
974 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
975 * everything (only happens when redrawing is off for while). | |
976 */ | |
977 type = NOT_VALID; | |
978 } | |
979 else | |
980 { | |
981 /* | |
982 * Set mod_top to the first line that needs displaying because of | |
983 * changes. Set mod_bot to the first line after the changes. | |
984 */ | |
985 mod_top = wp->w_redraw_top; | |
986 if (wp->w_redraw_bot != 0) | |
987 mod_bot = wp->w_redraw_bot + 1; | |
988 else | |
989 mod_bot = 0; | |
990 wp->w_redraw_top = 0; /* reset for next time */ | |
991 wp->w_redraw_bot = 0; | |
992 if (buf->b_mod_set) | |
993 { | |
994 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
995 { | |
996 mod_top = buf->b_mod_top; | |
997 #ifdef FEAT_SYN_HL | |
998 /* Need to redraw lines above the change that may be included | |
999 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1000 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1001 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1002 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 1003 if (mod_top < 1) |
1004 mod_top = 1; | |
1005 } | |
1006 #endif | |
1007 } | |
1008 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
1009 mod_bot = buf->b_mod_bot; | |
1010 | |
1011 #ifdef FEAT_SEARCH_EXTRA | |
1012 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
1013 * change in one line may make the Search highlighting in a | |
1014 * previous line invalid. Simple solution: redraw all visible | |
1015 * lines above the change. | |
1326 | 1016 * Same for a match pattern. |
7 | 1017 */ |
699 | 1018 if (search_hl.rm.regprog != NULL |
1019 && re_multiline(search_hl.rm.regprog)) | |
7 | 1020 top_to_mod = TRUE; |
699 | 1021 else |
1326 | 1022 { |
1023 cur = wp->w_match_head; | |
1024 while (cur != NULL) | |
1025 { | |
1026 if (cur->match.regprog != NULL | |
1027 && re_multiline(cur->match.regprog)) | |
699 | 1028 { |
1029 top_to_mod = TRUE; | |
1030 break; | |
1031 } | |
1326 | 1032 cur = cur->next; |
1033 } | |
1034 } | |
7 | 1035 #endif |
1036 } | |
1037 #ifdef FEAT_FOLDING | |
1038 if (mod_top != 0 && hasAnyFolding(wp)) | |
1039 { | |
1040 linenr_T lnumt, lnumb; | |
1041 | |
1042 /* | |
1043 * A change in a line can cause lines above it to become folded or | |
1044 * unfolded. Find the top most buffer line that may be affected. | |
1045 * If the line was previously folded and displayed, get the first | |
1046 * line of that fold. If the line is folded now, get the first | |
1047 * folded line. Use the minimum of these two. | |
1048 */ | |
1049 | |
1050 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
1051 * the line below it. If there is no valid entry, use w_topline. | |
1052 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1053 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1054 lnumt = wp->w_topline; | |
1055 lnumb = MAXLNUM; | |
1056 for (i = 0; i < wp->w_lines_valid; ++i) | |
1057 if (wp->w_lines[i].wl_valid) | |
1058 { | |
1059 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1060 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1061 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1062 { | |
1063 lnumb = wp->w_lines[i].wl_lnum; | |
1064 /* When there is a fold column it might need updating | |
1065 * in the next line ("J" just above an open fold). */ | |
1066 if (wp->w_p_fdc > 0) | |
1067 ++lnumb; | |
1068 } | |
1069 } | |
1070 | |
1071 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1072 if (mod_top > lnumt) | |
1073 mod_top = lnumt; | |
1074 | |
1075 /* Now do the same for the bottom line (one above mod_bot). */ | |
1076 --mod_bot; | |
1077 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1078 ++mod_bot; | |
1079 if (mod_bot < lnumb) | |
1080 mod_bot = lnumb; | |
1081 } | |
1082 #endif | |
1083 | |
1084 /* When a change starts above w_topline and the end is below | |
1085 * w_topline, start redrawing at w_topline. | |
36 | 1086 * If the end of the change is above w_topline: do like no change was |
1087 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1088 if (mod_top != 0 && mod_top < wp->w_topline) |
1089 { | |
1090 if (mod_bot > wp->w_topline) | |
1091 mod_top = wp->w_topline; | |
1092 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1093 else if (syntax_present(wp)) |
7 | 1094 top_end = 1; |
1095 #endif | |
1096 } | |
36 | 1097 |
1098 /* When line numbers are displayed need to redraw all lines below | |
1099 * inserted/deleted lines. */ | |
1100 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1101 mod_bot = MAXLNUM; | |
7 | 1102 } |
1103 | |
1104 /* | |
1105 * When only displaying the lines at the top, set top_end. Used when | |
1106 * window has scrolled down for msg_scrolled. | |
1107 */ | |
1108 if (type == REDRAW_TOP) | |
1109 { | |
1110 j = 0; | |
1111 for (i = 0; i < wp->w_lines_valid; ++i) | |
1112 { | |
1113 j += wp->w_lines[i].wl_size; | |
1114 if (j >= wp->w_upd_rows) | |
1115 { | |
1116 top_end = j; | |
1117 break; | |
1118 } | |
1119 } | |
1120 if (top_end == 0) | |
1121 /* not found (cannot happen?): redraw everything */ | |
1122 type = NOT_VALID; | |
1123 else | |
1124 /* top area defined, the rest is VALID */ | |
1125 type = VALID; | |
1126 } | |
1127 | |
1378 | 1128 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1129 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1130 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1131 * called. */ | |
1132 if (screen_cleared) | |
1133 screen_cleared = MAYBE; | |
1134 | |
7 | 1135 /* |
1136 * If there are no changes on the screen that require a complete redraw, | |
1137 * handle three cases: | |
1138 * 1: we are off the top of the screen by a few lines: scroll down | |
1139 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1140 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1141 * w_lines[] that needs updating. | |
1142 */ | |
743 | 1143 if ((type == VALID || type == SOME_VALID |
1144 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1145 #ifdef FEAT_DIFF |
1146 && !wp->w_botfill && !wp->w_old_botfill | |
1147 #endif | |
1148 ) | |
1149 { | |
1150 if (mod_top != 0 && wp->w_topline == mod_top) | |
1151 { | |
1152 /* | |
1153 * w_topline is the first changed line, the scrolling will be done | |
1154 * further down. | |
1155 */ | |
1156 } | |
1157 else if (wp->w_lines[0].wl_valid | |
1158 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1159 #ifdef FEAT_DIFF | |
1160 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1161 && wp->w_topfill > wp->w_old_topfill) | |
1162 #endif | |
1163 )) | |
1164 { | |
1165 /* | |
1166 * New topline is above old topline: May scroll down. | |
1167 */ | |
1168 #ifdef FEAT_FOLDING | |
1169 if (hasAnyFolding(wp)) | |
1170 { | |
1171 linenr_T ln; | |
1172 | |
1173 /* count the number of lines we are off, counting a sequence | |
1174 * of folded lines as one */ | |
1175 j = 0; | |
1176 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1177 { | |
1178 ++j; | |
1179 if (j >= wp->w_height - 2) | |
1180 break; | |
1181 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1182 } | |
1183 } | |
1184 else | |
1185 #endif | |
1186 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1187 if (j < wp->w_height - 2) /* not too far off */ | |
1188 { | |
1189 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1190 #ifdef FEAT_DIFF | |
1191 /* insert extra lines for previously invisible filler lines */ | |
1192 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1193 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1194 - wp->w_old_topfill; | |
1195 #endif | |
1196 if (i < wp->w_height - 2) /* less than a screen off */ | |
1197 { | |
1198 /* | |
1199 * Try to insert the correct number of lines. | |
1200 * If not the last window, delete the lines at the bottom. | |
1201 * win_ins_lines may fail when the terminal can't do it. | |
1202 */ | |
1203 if (i > 0) | |
1204 check_for_delay(FALSE); | |
1205 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1206 { | |
1207 if (wp->w_lines_valid != 0) | |
1208 { | |
1209 /* Need to update rows that are new, stop at the | |
1210 * first one that scrolled down. */ | |
1211 top_end = i; | |
1212 #ifdef FEAT_VISUAL | |
1213 scrolled_down = TRUE; | |
1214 #endif | |
1215 | |
1216 /* Move the entries that were scrolled, disable | |
1217 * the entries for the lines to be redrawn. */ | |
1218 if ((wp->w_lines_valid += j) > wp->w_height) | |
1219 wp->w_lines_valid = wp->w_height; | |
1220 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1221 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1222 while (idx >= 0) | |
1223 wp->w_lines[idx--].wl_valid = FALSE; | |
1224 } | |
1225 } | |
1226 else | |
1227 mid_start = 0; /* redraw all lines */ | |
1228 } | |
1229 else | |
1230 mid_start = 0; /* redraw all lines */ | |
1231 } | |
1232 else | |
1233 mid_start = 0; /* redraw all lines */ | |
1234 } | |
1235 else | |
1236 { | |
1237 /* | |
1238 * New topline is at or below old topline: May scroll up. | |
1239 * When topline didn't change, find first entry in w_lines[] that | |
1240 * needs updating. | |
1241 */ | |
1242 | |
1243 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1244 j = -1; | |
1245 row = 0; | |
1246 for (i = 0; i < wp->w_lines_valid; i++) | |
1247 { | |
1248 if (wp->w_lines[i].wl_valid | |
1249 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1250 { | |
1251 j = i; | |
1252 break; | |
1253 } | |
1254 row += wp->w_lines[i].wl_size; | |
1255 } | |
1256 if (j == -1) | |
1257 { | |
1258 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1259 * lines */ | |
1260 mid_start = 0; | |
1261 } | |
1262 else | |
1263 { | |
1264 /* | |
1265 * Try to delete the correct number of lines. | |
1266 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1267 */ | |
1268 #ifdef FEAT_DIFF | |
1269 /* If the topline didn't change, delete old filler lines, | |
1270 * otherwise delete filler lines of the new topline... */ | |
1271 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1272 row += wp->w_old_topfill; | |
1273 else | |
1274 row += diff_check_fill(wp, wp->w_topline); | |
1275 /* ... but don't delete new filler lines. */ | |
1276 row -= wp->w_topfill; | |
1277 #endif | |
1278 if (row > 0) | |
1279 { | |
1280 check_for_delay(FALSE); | |
1281 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1282 bot_start = wp->w_height - row; | |
1283 else | |
1284 mid_start = 0; /* redraw all lines */ | |
1285 } | |
1286 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1287 { | |
1288 /* | |
1289 * Skip the lines (below the deleted lines) that are still | |
1290 * valid and don't need redrawing. Copy their info | |
1291 * upwards, to compensate for the deleted lines. Set | |
1292 * bot_start to the first row that needs redrawing. | |
1293 */ | |
1294 bot_start = 0; | |
1295 idx = 0; | |
1296 for (;;) | |
1297 { | |
1298 wp->w_lines[idx] = wp->w_lines[j]; | |
1299 /* stop at line that didn't fit, unless it is still | |
1300 * valid (no lines deleted) */ | |
1301 if (row > 0 && bot_start + row | |
1302 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1303 { | |
1304 wp->w_lines_valid = idx + 1; | |
1305 break; | |
1306 } | |
1307 bot_start += wp->w_lines[idx++].wl_size; | |
1308 | |
1309 /* stop at the last valid entry in w_lines[].wl_size */ | |
1310 if (++j >= wp->w_lines_valid) | |
1311 { | |
1312 wp->w_lines_valid = idx; | |
1313 break; | |
1314 } | |
1315 } | |
1316 #ifdef FEAT_DIFF | |
1317 /* Correct the first entry for filler lines at the top | |
1318 * when it won't get updated below. */ | |
1319 if (wp->w_p_diff && bot_start > 0) | |
1320 wp->w_lines[0].wl_size = | |
1321 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1322 + wp->w_topfill; | |
1323 #endif | |
1324 } | |
1325 } | |
1326 } | |
1327 | |
1328 /* When starting redraw in the first line, redraw all lines. When | |
1329 * there is only one window it's probably faster to clear the screen | |
1330 * first. */ | |
1331 if (mid_start == 0) | |
1332 { | |
1333 mid_end = wp->w_height; | |
1334 if (lastwin == firstwin) | |
981 | 1335 { |
1331 | 1336 /* Clear the screen when it was not done by win_del_lines() or |
1337 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1338 * then. */ | |
1339 if (screen_cleared != TRUE) | |
1340 screenclear(); | |
981 | 1341 #ifdef FEAT_WINDOWS |
1342 /* The screen was cleared, redraw the tab pages line. */ | |
1343 if (redraw_tabline) | |
1344 draw_tabline(); | |
1345 #endif | |
1346 } | |
7 | 1347 } |
1331 | 1348 |
1349 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1350 * cleared (only happens for the first window) or when screenclear() | |
1351 * was called directly above, "must_redraw" will have been set to | |
1352 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1353 if (screen_cleared == TRUE) | |
1354 must_redraw = 0; | |
7 | 1355 } |
1356 else | |
1357 { | |
1358 /* Not VALID or INVERTED: redraw all lines. */ | |
1359 mid_start = 0; | |
1360 mid_end = wp->w_height; | |
1361 } | |
1362 | |
743 | 1363 if (type == SOME_VALID) |
1364 { | |
1365 /* SOME_VALID: redraw all lines. */ | |
1366 mid_start = 0; | |
1367 mid_end = wp->w_height; | |
1368 type = NOT_VALID; | |
1369 } | |
1370 | |
7 | 1371 #ifdef FEAT_VISUAL |
1372 /* check if we are updating or removing the inverted part */ | |
1373 if ((VIsual_active && buf == curwin->w_buffer) | |
1374 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1375 { | |
1376 linenr_T from, to; | |
1377 | |
1378 if (VIsual_active) | |
1379 { | |
1380 if (VIsual_active | |
1381 && (VIsual_mode != wp->w_old_visual_mode | |
1382 || type == INVERTED_ALL)) | |
1383 { | |
1384 /* | |
1385 * If the type of Visual selection changed, redraw the whole | |
1386 * selection. Also when the ownership of the X selection is | |
1387 * gained or lost. | |
1388 */ | |
1389 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1390 { | |
1391 from = curwin->w_cursor.lnum; | |
1392 to = VIsual.lnum; | |
1393 } | |
1394 else | |
1395 { | |
1396 from = VIsual.lnum; | |
1397 to = curwin->w_cursor.lnum; | |
1398 } | |
1399 /* redraw more when the cursor moved as well */ | |
1400 if (wp->w_old_cursor_lnum < from) | |
1401 from = wp->w_old_cursor_lnum; | |
1402 if (wp->w_old_cursor_lnum > to) | |
1403 to = wp->w_old_cursor_lnum; | |
1404 if (wp->w_old_visual_lnum < from) | |
1405 from = wp->w_old_visual_lnum; | |
1406 if (wp->w_old_visual_lnum > to) | |
1407 to = wp->w_old_visual_lnum; | |
1408 } | |
1409 else | |
1410 { | |
1411 /* | |
1412 * Find the line numbers that need to be updated: The lines | |
1413 * between the old cursor position and the current cursor | |
1414 * position. Also check if the Visual position changed. | |
1415 */ | |
1416 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1417 { | |
1418 from = curwin->w_cursor.lnum; | |
1419 to = wp->w_old_cursor_lnum; | |
1420 } | |
1421 else | |
1422 { | |
1423 from = wp->w_old_cursor_lnum; | |
1424 to = curwin->w_cursor.lnum; | |
1425 if (from == 0) /* Visual mode just started */ | |
1426 from = to; | |
1427 } | |
1428 | |
422 | 1429 if (VIsual.lnum != wp->w_old_visual_lnum |
1430 || VIsual.col != wp->w_old_visual_col) | |
7 | 1431 { |
1432 if (wp->w_old_visual_lnum < from | |
1433 && wp->w_old_visual_lnum != 0) | |
1434 from = wp->w_old_visual_lnum; | |
1435 if (wp->w_old_visual_lnum > to) | |
1436 to = wp->w_old_visual_lnum; | |
1437 if (VIsual.lnum < from) | |
1438 from = VIsual.lnum; | |
1439 if (VIsual.lnum > to) | |
1440 to = VIsual.lnum; | |
1441 } | |
1442 } | |
1443 | |
1444 /* | |
1445 * If in block mode and changed column or curwin->w_curswant: | |
1446 * update all lines. | |
1447 * First compute the actual start and end column. | |
1448 */ | |
1449 if (VIsual_mode == Ctrl_V) | |
1450 { | |
1451 colnr_T fromc, toc; | |
1452 | |
1453 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1454 ++toc; | |
1455 if (curwin->w_curswant == MAXCOL) | |
1456 toc = MAXCOL; | |
1457 | |
1458 if (fromc != wp->w_old_cursor_fcol | |
1459 || toc != wp->w_old_cursor_lcol) | |
1460 { | |
1461 if (from > VIsual.lnum) | |
1462 from = VIsual.lnum; | |
1463 if (to < VIsual.lnum) | |
1464 to = VIsual.lnum; | |
1465 } | |
1466 wp->w_old_cursor_fcol = fromc; | |
1467 wp->w_old_cursor_lcol = toc; | |
1468 } | |
1469 } | |
1470 else | |
1471 { | |
1472 /* Use the line numbers of the old Visual area. */ | |
1473 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1474 { | |
1475 from = wp->w_old_cursor_lnum; | |
1476 to = wp->w_old_visual_lnum; | |
1477 } | |
1478 else | |
1479 { | |
1480 from = wp->w_old_visual_lnum; | |
1481 to = wp->w_old_cursor_lnum; | |
1482 } | |
1483 } | |
1484 | |
1485 /* | |
1486 * There is no need to update lines above the top of the window. | |
1487 */ | |
1488 if (from < wp->w_topline) | |
1489 from = wp->w_topline; | |
1490 | |
1491 /* | |
1492 * If we know the value of w_botline, use it to restrict the update to | |
1493 * the lines that are visible in the window. | |
1494 */ | |
1495 if (wp->w_valid & VALID_BOTLINE) | |
1496 { | |
1497 if (from >= wp->w_botline) | |
1498 from = wp->w_botline - 1; | |
1499 if (to >= wp->w_botline) | |
1500 to = wp->w_botline - 1; | |
1501 } | |
1502 | |
1503 /* | |
1504 * Find the minimal part to be updated. | |
1505 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1506 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1507 * top_end; need to redraw from top_end to the "to" line. | |
1508 * A middle mouse click with a Visual selection may change the text | |
1509 * above the Visual area and reset wl_valid, do count these for | |
1510 * mid_end (in srow). | |
1511 */ | |
1512 if (mid_start > 0) | |
1513 { | |
1514 lnum = wp->w_topline; | |
1515 idx = 0; | |
1516 srow = 0; | |
1517 if (scrolled_down) | |
1518 mid_start = top_end; | |
1519 else | |
1520 mid_start = 0; | |
1521 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1522 { | |
1523 if (wp->w_lines[idx].wl_valid) | |
1524 mid_start += wp->w_lines[idx].wl_size; | |
1525 else if (!scrolled_down) | |
1526 srow += wp->w_lines[idx].wl_size; | |
1527 ++idx; | |
1528 # ifdef FEAT_FOLDING | |
1529 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1530 lnum = wp->w_lines[idx].wl_lnum; | |
1531 else | |
1532 # endif | |
1533 ++lnum; | |
1534 } | |
1535 srow += mid_start; | |
1536 mid_end = wp->w_height; | |
1537 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1538 { | |
1539 if (wp->w_lines[idx].wl_valid | |
1540 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1541 { | |
1542 /* Only update until first row of this line */ | |
1543 mid_end = srow; | |
1544 break; | |
1545 } | |
1546 srow += wp->w_lines[idx].wl_size; | |
1547 } | |
1548 } | |
1549 } | |
1550 | |
1551 if (VIsual_active && buf == curwin->w_buffer) | |
1552 { | |
1553 wp->w_old_visual_mode = VIsual_mode; | |
1554 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1555 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1556 wp->w_old_visual_col = VIsual.col; |
7 | 1557 wp->w_old_curswant = curwin->w_curswant; |
1558 } | |
1559 else | |
1560 { | |
1561 wp->w_old_visual_mode = 0; | |
1562 wp->w_old_cursor_lnum = 0; | |
1563 wp->w_old_visual_lnum = 0; | |
422 | 1564 wp->w_old_visual_col = 0; |
7 | 1565 } |
1566 #endif /* FEAT_VISUAL */ | |
1567 | |
1568 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1569 /* reset got_int, otherwise regexp won't work */ | |
1570 save_got_int = got_int; | |
1571 got_int = 0; | |
1572 #endif | |
1573 #ifdef FEAT_FOLDING | |
1574 win_foldinfo.fi_level = 0; | |
1575 #endif | |
1576 | |
1577 /* | |
1578 * Update all the window rows. | |
1579 */ | |
1580 idx = 0; /* first entry in w_lines[].wl_size */ | |
1581 row = 0; | |
1582 srow = 0; | |
1583 lnum = wp->w_topline; /* first line shown in window */ | |
1584 for (;;) | |
1585 { | |
1586 /* stop updating when reached the end of the window (check for _past_ | |
1587 * the end of the window is at the end of the loop) */ | |
1588 if (row == wp->w_height) | |
1589 { | |
1590 didline = TRUE; | |
1591 break; | |
1592 } | |
1593 | |
1594 /* stop updating when hit the end of the file */ | |
1595 if (lnum > buf->b_ml.ml_line_count) | |
1596 { | |
1597 eof = TRUE; | |
1598 break; | |
1599 } | |
1600 | |
1601 /* Remember the starting row of the line that is going to be dealt | |
1602 * with. It is used further down when the line doesn't fit. */ | |
1603 srow = row; | |
1604 | |
1605 /* | |
1606 * Update a line when it is in an area that needs updating, when it | |
1607 * has changes or w_lines[idx] is invalid. | |
1608 * bot_start may be halfway a wrapped line after using | |
1609 * win_del_lines(), check if the current line includes it. | |
1610 * When syntax folding is being used, the saved syntax states will | |
1611 * already have been updated, we can't see where the syntax state is | |
1612 * the same again, just update until the end of the window. | |
1613 */ | |
1614 if (row < top_end | |
1615 || (row >= mid_start && row < mid_end) | |
1616 #ifdef FEAT_SEARCH_EXTRA | |
1617 || top_to_mod | |
1618 #endif | |
1619 || idx >= wp->w_lines_valid | |
1620 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1621 || (mod_top != 0 | |
1622 && (lnum == mod_top | |
1623 || (lnum >= mod_top | |
1624 && (lnum < mod_bot | |
1625 #ifdef FEAT_SYN_HL | |
1626 || did_update == DID_FOLD | |
1627 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1628 && syntax_present(wp) |
7 | 1629 && ( |
1630 # ifdef FEAT_FOLDING | |
1631 (foldmethodIsSyntax(wp) | |
1632 && hasAnyFolding(wp)) || | |
1633 # endif | |
1634 syntax_check_changed(lnum))) | |
1635 #endif | |
1636 ))))) | |
1637 { | |
1638 #ifdef FEAT_SEARCH_EXTRA | |
1639 if (lnum == mod_top) | |
1640 top_to_mod = FALSE; | |
1641 #endif | |
1642 | |
1643 /* | |
1644 * When at start of changed lines: May scroll following lines | |
1645 * up or down to minimize redrawing. | |
1646 * Don't do this when the change continues until the end. | |
3318 | 1647 * Don't scroll when dollar_vcol >= 0, keep the "$". |
7 | 1648 */ |
1649 if (lnum == mod_top | |
1650 && mod_bot != MAXLNUM | |
3318 | 1651 && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
7 | 1652 { |
1653 int old_rows = 0; | |
1654 int new_rows = 0; | |
1655 int xtra_rows; | |
1656 linenr_T l; | |
1657 | |
1658 /* Count the old number of window rows, using w_lines[], which | |
1659 * should still contain the sizes for the lines as they are | |
1660 * currently displayed. */ | |
1661 for (i = idx; i < wp->w_lines_valid; ++i) | |
1662 { | |
1663 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1664 * lines are part of the changed area. */ | |
1665 if (wp->w_lines[i].wl_valid | |
1666 && wp->w_lines[i].wl_lnum == mod_bot) | |
1667 break; | |
1668 old_rows += wp->w_lines[i].wl_size; | |
1669 #ifdef FEAT_FOLDING | |
1670 if (wp->w_lines[i].wl_valid | |
1671 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1672 { | |
1673 /* Must have found the last valid entry above mod_bot. | |
1674 * Add following invalid entries. */ | |
1675 ++i; | |
1676 while (i < wp->w_lines_valid | |
1677 && !wp->w_lines[i].wl_valid) | |
1678 old_rows += wp->w_lines[i++].wl_size; | |
1679 break; | |
1680 } | |
1681 #endif | |
1682 } | |
1683 | |
1684 if (i >= wp->w_lines_valid) | |
1685 { | |
1686 /* We can't find a valid line below the changed lines, | |
1687 * need to redraw until the end of the window. | |
1688 * Inserting/deleting lines has no use. */ | |
1689 bot_start = 0; | |
1690 } | |
1691 else | |
1692 { | |
1693 /* Able to count old number of rows: Count new window | |
1694 * rows, and may insert/delete lines */ | |
1695 j = idx; | |
1696 for (l = lnum; l < mod_bot; ++l) | |
1697 { | |
1698 #ifdef FEAT_FOLDING | |
1699 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1700 ++new_rows; | |
1701 else | |
1702 #endif | |
1703 #ifdef FEAT_DIFF | |
1704 if (l == wp->w_topline) | |
1705 new_rows += plines_win_nofill(wp, l, TRUE) | |
1706 + wp->w_topfill; | |
1707 else | |
1708 #endif | |
1709 new_rows += plines_win(wp, l, TRUE); | |
1710 ++j; | |
1711 if (new_rows > wp->w_height - row - 2) | |
1712 { | |
1713 /* it's getting too much, must redraw the rest */ | |
1714 new_rows = 9999; | |
1715 break; | |
1716 } | |
1717 } | |
1718 xtra_rows = new_rows - old_rows; | |
1719 if (xtra_rows < 0) | |
1720 { | |
1721 /* May scroll text up. If there is not enough | |
1722 * remaining text or scrolling fails, must redraw the | |
1723 * rest. If scrolling works, must redraw the text | |
1724 * below the scrolled text. */ | |
1725 if (row - xtra_rows >= wp->w_height - 2) | |
1726 mod_bot = MAXLNUM; | |
1727 else | |
1728 { | |
1729 check_for_delay(FALSE); | |
1730 if (win_del_lines(wp, row, | |
1731 -xtra_rows, FALSE, FALSE) == FAIL) | |
1732 mod_bot = MAXLNUM; | |
1733 else | |
1734 bot_start = wp->w_height + xtra_rows; | |
1735 } | |
1736 } | |
1737 else if (xtra_rows > 0) | |
1738 { | |
1739 /* May scroll text down. If there is not enough | |
1740 * remaining text of scrolling fails, must redraw the | |
1741 * rest. */ | |
1742 if (row + xtra_rows >= wp->w_height - 2) | |
1743 mod_bot = MAXLNUM; | |
1744 else | |
1745 { | |
1746 check_for_delay(FALSE); | |
1747 if (win_ins_lines(wp, row + old_rows, | |
1748 xtra_rows, FALSE, FALSE) == FAIL) | |
1749 mod_bot = MAXLNUM; | |
1750 else if (top_end > row + old_rows) | |
1751 /* Scrolled the part at the top that requires | |
1752 * updating down. */ | |
1753 top_end += xtra_rows; | |
1754 } | |
1755 } | |
1756 | |
1757 /* When not updating the rest, may need to move w_lines[] | |
1758 * entries. */ | |
1759 if (mod_bot != MAXLNUM && i != j) | |
1760 { | |
1761 if (j < i) | |
1762 { | |
1763 int x = row + new_rows; | |
1764 | |
1765 /* move entries in w_lines[] upwards */ | |
1766 for (;;) | |
1767 { | |
1768 /* stop at last valid entry in w_lines[] */ | |
1769 if (i >= wp->w_lines_valid) | |
1770 { | |
1771 wp->w_lines_valid = j; | |
1772 break; | |
1773 } | |
1774 wp->w_lines[j] = wp->w_lines[i]; | |
1775 /* stop at a line that won't fit */ | |
1776 if (x + (int)wp->w_lines[j].wl_size | |
1777 > wp->w_height) | |
1778 { | |
1779 wp->w_lines_valid = j + 1; | |
1780 break; | |
1781 } | |
1782 x += wp->w_lines[j++].wl_size; | |
1783 ++i; | |
1784 } | |
1785 if (bot_start > x) | |
1786 bot_start = x; | |
1787 } | |
1788 else /* j > i */ | |
1789 { | |
1790 /* move entries in w_lines[] downwards */ | |
1791 j -= i; | |
1792 wp->w_lines_valid += j; | |
1793 if (wp->w_lines_valid > wp->w_height) | |
1794 wp->w_lines_valid = wp->w_height; | |
1795 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1796 wp->w_lines[i] = wp->w_lines[i - j]; | |
1797 | |
1798 /* The w_lines[] entries for inserted lines are | |
1799 * now invalid, but wl_size may be used above. | |
1800 * Reset to zero. */ | |
1801 while (i >= idx) | |
1802 { | |
1803 wp->w_lines[i].wl_size = 0; | |
1804 wp->w_lines[i--].wl_valid = FALSE; | |
1805 } | |
1806 } | |
1807 } | |
1808 } | |
1809 } | |
1810 | |
1811 #ifdef FEAT_FOLDING | |
1812 /* | |
1813 * When lines are folded, display one line for all of them. | |
1814 * Otherwise, display normally (can be several display lines when | |
1815 * 'wrap' is on). | |
1816 */ | |
1817 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1818 if (fold_count != 0) | |
1819 { | |
1820 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1821 ++row; | |
1822 --fold_count; | |
1823 wp->w_lines[idx].wl_folded = TRUE; | |
1824 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1825 # ifdef FEAT_SYN_HL | |
1826 did_update = DID_FOLD; | |
1827 # endif | |
1828 } | |
1829 else | |
1830 #endif | |
1831 if (idx < wp->w_lines_valid | |
1832 && wp->w_lines[idx].wl_valid | |
1833 && wp->w_lines[idx].wl_lnum == lnum | |
1834 && lnum > wp->w_topline | |
1835 && !(dy_flags & DY_LASTLINE) | |
1836 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1837 #ifdef FEAT_DIFF | |
1838 && diff_check_fill(wp, lnum) == 0 | |
1839 #endif | |
1840 ) | |
1841 { | |
1842 /* This line is not going to fit. Don't draw anything here, | |
1843 * will draw "@ " lines below. */ | |
1844 row = wp->w_height + 1; | |
1845 } | |
1846 else | |
1847 { | |
1848 #ifdef FEAT_SEARCH_EXTRA | |
1849 prepare_search_hl(wp, lnum); | |
1850 #endif | |
1851 #ifdef FEAT_SYN_HL | |
1852 /* Let the syntax stuff know we skipped a few lines. */ | |
1853 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
|
1854 && syntax_present(wp)) |
7 | 1855 syntax_end_parsing(syntax_last_parsed + 1); |
1856 #endif | |
1857 | |
1858 /* | |
1859 * Display one line. | |
1860 */ | |
625 | 1861 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1862 |
1863 #ifdef FEAT_FOLDING | |
1864 wp->w_lines[idx].wl_folded = FALSE; | |
1865 wp->w_lines[idx].wl_lastlnum = lnum; | |
1866 #endif | |
1867 #ifdef FEAT_SYN_HL | |
1868 did_update = DID_LINE; | |
1869 syntax_last_parsed = lnum; | |
1870 #endif | |
1871 } | |
1872 | |
1873 wp->w_lines[idx].wl_lnum = lnum; | |
1874 wp->w_lines[idx].wl_valid = TRUE; | |
1875 if (row > wp->w_height) /* past end of screen */ | |
1876 { | |
1877 /* we may need the size of that too long line later on */ | |
3318 | 1878 if (dollar_vcol == -1) |
7 | 1879 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
1880 ++idx; | |
1881 break; | |
1882 } | |
3318 | 1883 if (dollar_vcol == -1) |
7 | 1884 wp->w_lines[idx].wl_size = row - srow; |
1885 ++idx; | |
1886 #ifdef FEAT_FOLDING | |
1887 lnum += fold_count + 1; | |
1888 #else | |
1889 ++lnum; | |
1890 #endif | |
1891 } | |
1892 else | |
1893 { | |
1894 /* This line does not need updating, advance to the next one */ | |
1895 row += wp->w_lines[idx++].wl_size; | |
1896 if (row > wp->w_height) /* past end of screen */ | |
1897 break; | |
1898 #ifdef FEAT_FOLDING | |
1899 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1900 #else | |
1901 ++lnum; | |
1902 #endif | |
1903 #ifdef FEAT_SYN_HL | |
1904 did_update = DID_NONE; | |
1905 #endif | |
1906 } | |
1907 | |
1908 if (lnum > buf->b_ml.ml_line_count) | |
1909 { | |
1910 eof = TRUE; | |
1911 break; | |
1912 } | |
1913 } | |
1914 /* | |
1915 * End of loop over all window lines. | |
1916 */ | |
1917 | |
1918 | |
1919 if (idx > wp->w_lines_valid) | |
1920 wp->w_lines_valid = idx; | |
1921 | |
1922 #ifdef FEAT_SYN_HL | |
1923 /* | |
1924 * Let the syntax stuff know we stop parsing here. | |
1925 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1926 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1927 syntax_end_parsing(syntax_last_parsed + 1); |
1928 #endif | |
1929 | |
1930 /* | |
1931 * If we didn't hit the end of the file, and we didn't finish the last | |
1932 * line we were working on, then the line didn't fit. | |
1933 */ | |
1934 wp->w_empty_rows = 0; | |
1935 #ifdef FEAT_DIFF | |
1936 wp->w_filler_rows = 0; | |
1937 #endif | |
1938 if (!eof && !didline) | |
1939 { | |
1940 if (lnum == wp->w_topline) | |
1941 { | |
1942 /* | |
1943 * Single line that does not fit! | |
1944 * Don't overwrite it, it can be edited. | |
1945 */ | |
1946 wp->w_botline = lnum + 1; | |
1947 } | |
1948 #ifdef FEAT_DIFF | |
1949 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1950 { | |
1951 /* Window ends in filler lines. */ | |
1952 wp->w_botline = lnum; | |
1953 wp->w_filler_rows = wp->w_height - srow; | |
1954 } | |
1955 #endif | |
1956 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1957 { | |
1958 /* | |
1959 * Last line isn't finished: Display "@@@" at the end. | |
1960 */ | |
1961 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1962 W_WINROW(wp) + wp->w_height, | |
1963 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1964 '@', '@', hl_attr(HLF_AT)); | |
1965 set_empty_rows(wp, srow); | |
1966 wp->w_botline = lnum; | |
1967 } | |
1968 else | |
1969 { | |
1970 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1971 wp->w_botline = lnum; | |
1972 } | |
1973 } | |
1974 else | |
1975 { | |
1976 #ifdef FEAT_VERTSPLIT | |
1977 draw_vsep_win(wp, row); | |
1978 #endif | |
1979 if (eof) /* we hit the end of the file */ | |
1980 { | |
1981 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1982 #ifdef FEAT_DIFF | |
1983 j = diff_check_fill(wp, wp->w_botline); | |
1984 if (j > 0 && !wp->w_botfill) | |
1985 { | |
1986 /* | |
1987 * Display filler lines at the end of the file | |
1988 */ | |
1989 if (char2cells(fill_diff) > 1) | |
1990 i = '-'; | |
1991 else | |
1992 i = fill_diff; | |
1993 if (row + j > wp->w_height) | |
1994 j = wp->w_height - row; | |
1995 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1996 row += j; | |
1997 } | |
1998 #endif | |
1999 } | |
3318 | 2000 else if (dollar_vcol == -1) |
7 | 2001 wp->w_botline = lnum; |
2002 | |
2003 /* make sure the rest of the screen is blank */ | |
2004 /* put '~'s on rows that aren't part of the file. */ | |
2005 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
2006 } | |
2007 | |
2008 /* Reset the type of redrawing required, the window has been updated. */ | |
2009 wp->w_redr_type = 0; | |
2010 #ifdef FEAT_DIFF | |
2011 wp->w_old_topfill = wp->w_topfill; | |
2012 wp->w_old_botfill = wp->w_botfill; | |
2013 #endif | |
2014 | |
3318 | 2015 if (dollar_vcol == -1) |
7 | 2016 { |
2017 /* | |
2018 * There is a trick with w_botline. If we invalidate it on each | |
2019 * change that might modify it, this will cause a lot of expensive | |
2020 * calls to plines() in update_topline() each time. Therefore the | |
2021 * value of w_botline is often approximated, and this value is used to | |
2022 * compute the value of w_topline. If the value of w_botline was | |
2023 * wrong, check that the value of w_topline is correct (cursor is on | |
2024 * the visible part of the text). If it's not, we need to redraw | |
2025 * again. Mostly this just means scrolling up a few lines, so it | |
2026 * doesn't look too bad. Only do this for the current window (where | |
2027 * changes are relevant). | |
2028 */ | |
2029 wp->w_valid |= VALID_BOTLINE; | |
2030 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
2031 { | |
2032 recursive = TRUE; | |
2033 curwin->w_valid &= ~VALID_TOPLINE; | |
2034 update_topline(); /* may invalidate w_botline again */ | |
2035 if (must_redraw != 0) | |
2036 { | |
2037 /* Don't update for changes in buffer again. */ | |
2038 i = curbuf->b_mod_set; | |
2039 curbuf->b_mod_set = FALSE; | |
2040 win_update(curwin); | |
2041 must_redraw = 0; | |
2042 curbuf->b_mod_set = i; | |
2043 } | |
2044 recursive = FALSE; | |
2045 } | |
2046 } | |
2047 | |
2048 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
2049 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
2050 if (!got_int) | |
2051 got_int = save_got_int; | |
2052 #endif | |
2053 } | |
2054 | |
2055 #ifdef FEAT_SIGNS | |
2056 static int draw_signcolumn __ARGS((win_T *wp)); | |
2057 | |
2058 /* | |
2059 * Return TRUE when window "wp" has a column to draw signs in. | |
2060 */ | |
2061 static int | |
2062 draw_signcolumn(wp) | |
2063 win_T *wp; | |
2064 { | |
2065 return (wp->w_buffer->b_signlist != NULL | |
2066 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2067 || netbeans_active() |
7 | 2068 # endif |
2069 ); | |
2070 } | |
2071 #endif | |
2072 | |
2073 /* | |
2074 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2075 * as the filler character. | |
2076 */ | |
2077 static void | |
2078 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2079 win_T *wp; | |
2080 int c1; | |
2081 int c2; | |
2082 int row; | |
2083 int endrow; | |
534 | 2084 hlf_T hl; |
7 | 2085 { |
2086 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2087 int n = 0; | |
2088 # define FDC_OFF n | |
2089 #else | |
2090 # define FDC_OFF 0 | |
2091 #endif | |
2092 | |
2093 #ifdef FEAT_RIGHTLEFT | |
2094 if (wp->w_p_rl) | |
2095 { | |
2096 /* No check for cmdline window: should never be right-left. */ | |
2097 # ifdef FEAT_FOLDING | |
2098 n = wp->w_p_fdc; | |
2099 | |
2100 if (n > 0) | |
2101 { | |
2102 /* draw the fold column at the right */ | |
119 | 2103 if (n > W_WIDTH(wp)) |
2104 n = W_WIDTH(wp); | |
7 | 2105 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2106 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2107 ' ', ' ', hl_attr(HLF_FC)); | |
2108 } | |
2109 # endif | |
2110 # ifdef FEAT_SIGNS | |
2111 if (draw_signcolumn(wp)) | |
2112 { | |
2113 int nn = n + 2; | |
2114 | |
2115 /* draw the sign column left of the fold column */ | |
119 | 2116 if (nn > W_WIDTH(wp)) |
2117 nn = W_WIDTH(wp); | |
7 | 2118 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2119 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2120 ' ', ' ', hl_attr(HLF_SC)); | |
2121 n = nn; | |
2122 } | |
2123 # endif | |
2124 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2125 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2126 c2, c2, hl_attr(hl)); | |
2127 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2128 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2129 c1, c2, hl_attr(hl)); | |
2130 } | |
2131 else | |
2132 #endif | |
2133 { | |
2134 #ifdef FEAT_CMDWIN | |
2135 if (cmdwin_type != 0 && wp == curwin) | |
2136 { | |
2137 /* draw the cmdline character in the leftmost column */ | |
2138 n = 1; | |
2139 if (n > wp->w_width) | |
2140 n = wp->w_width; | |
2141 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2142 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2143 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2144 } | |
2145 #endif | |
2146 #ifdef FEAT_FOLDING | |
2147 if (wp->w_p_fdc > 0) | |
2148 { | |
2149 int nn = n + wp->w_p_fdc; | |
2150 | |
2151 /* draw the fold column at the left */ | |
2152 if (nn > W_WIDTH(wp)) | |
2153 nn = W_WIDTH(wp); | |
2154 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2155 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2156 ' ', ' ', hl_attr(HLF_FC)); | |
2157 n = nn; | |
2158 } | |
2159 #endif | |
2160 #ifdef FEAT_SIGNS | |
2161 if (draw_signcolumn(wp)) | |
2162 { | |
2163 int nn = n + 2; | |
2164 | |
2165 /* draw the sign column after the fold column */ | |
2166 if (nn > W_WIDTH(wp)) | |
2167 nn = W_WIDTH(wp); | |
2168 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2169 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2170 ' ', ' ', hl_attr(HLF_SC)); | |
2171 n = nn; | |
2172 } | |
2173 #endif | |
2174 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2175 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2176 c1, c2, hl_attr(hl)); | |
2177 } | |
2178 set_empty_rows(wp, row); | |
2179 } | |
2180 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2181 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2182 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
|
2183 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2184 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2185 * 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
|
2186 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2187 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2188 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2189 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2190 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2191 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2192 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2193 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2194 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2195 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2196 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2197 |
7 | 2198 #ifdef FEAT_FOLDING |
2199 /* | |
2200 * Display one folded line. | |
2201 */ | |
2202 static void | |
2203 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2204 win_T *wp; | |
2205 long fold_count; | |
2206 foldinfo_T *foldinfo; | |
2207 linenr_T lnum; | |
2208 int row; | |
2209 { | |
2210 char_u buf[51]; | |
2211 pos_T *top, *bot; | |
2212 linenr_T lnume = lnum + fold_count - 1; | |
2213 int len; | |
29 | 2214 char_u *text; |
7 | 2215 int fdc; |
2216 int col; | |
2217 int txtcol; | |
2218 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2219 int ri; |
7 | 2220 |
2221 /* Build the fold line: | |
2222 * 1. Add the cmdwin_type for the command-line window | |
2223 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2224 * 3. Add the 'number' or 'relativenumber' column |
7 | 2225 * 4. Compose the text |
2226 * 5. Add the text | |
2227 * 6. set highlighting for the Visual area an other text | |
2228 */ | |
2229 col = 0; | |
2230 | |
2231 /* | |
2232 * 1. Add the cmdwin_type for the command-line window | |
2233 * Ignores 'rightleft', this window is never right-left. | |
2234 */ | |
2235 #ifdef FEAT_CMDWIN | |
2236 if (cmdwin_type != 0 && wp == curwin) | |
2237 { | |
2238 ScreenLines[off] = cmdwin_type; | |
2239 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2240 #ifdef FEAT_MBYTE | |
2241 if (enc_utf8) | |
2242 ScreenLinesUC[off] = 0; | |
2243 #endif | |
2244 ++col; | |
2245 } | |
2246 #endif | |
2247 | |
2248 /* | |
2249 * 2. Add the 'foldcolumn' | |
2250 */ | |
2251 fdc = wp->w_p_fdc; | |
2252 if (fdc > W_WIDTH(wp) - col) | |
2253 fdc = W_WIDTH(wp) - col; | |
2254 if (fdc > 0) | |
2255 { | |
2256 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2257 #ifdef FEAT_RIGHTLEFT | |
2258 if (wp->w_p_rl) | |
2259 { | |
2260 int i; | |
2261 | |
2262 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2263 hl_attr(HLF_FC)); | |
2264 /* reverse the fold column */ | |
2265 for (i = 0; i < fdc; ++i) | |
2266 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2267 } | |
2268 else | |
2269 #endif | |
2270 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2271 col += fdc; | |
2272 } | |
2273 | |
2274 #ifdef FEAT_RIGHTLEFT | |
216 | 2275 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2276 for (ri = 0; ri < l; ++ri) \ | |
2277 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2278 else \ | |
2279 for (ri = 0; ri < l; ++ri) \ | |
2280 ScreenAttrs[off + (p) + ri] = v | |
7 | 2281 #else |
216 | 2282 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2283 ScreenAttrs[off + (p) + ri] = v | |
7 | 2284 #endif |
2285 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2286 /* 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
|
2287 * text */ |
216 | 2288 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2289 |
2290 #ifdef FEAT_SIGNS | |
2291 /* If signs are being displayed, add two spaces. */ | |
2292 if (draw_signcolumn(wp)) | |
2293 { | |
2294 len = W_WIDTH(wp) - col; | |
2295 if (len > 0) | |
2296 { | |
2297 if (len > 2) | |
2298 len = 2; | |
2299 # ifdef FEAT_RIGHTLEFT | |
2300 if (wp->w_p_rl) | |
2301 /* the line number isn't reversed */ | |
2302 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2303 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2304 else | |
2305 # endif | |
2306 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2307 col += len; | |
2308 } | |
2309 } | |
2310 #endif | |
2311 | |
2312 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2313 * 3. Add the 'number' or 'relativenumber' column |
7 | 2314 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2315 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2316 { |
2317 len = W_WIDTH(wp) - col; | |
2318 if (len > 0) | |
2319 { | |
13 | 2320 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2321 long num; |
13 | 2322 |
2323 if (len > w + 1) | |
2324 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2325 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2326 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2327 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2328 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2329 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2330 /* 'relativenumber', don't use negative numbers */ |
2675 | 2331 num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2332 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2333 sprintf((char *)buf, "%*ld ", w, num); |
7 | 2334 #ifdef FEAT_RIGHTLEFT |
2335 if (wp->w_p_rl) | |
2336 /* the line number isn't reversed */ | |
2337 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2338 hl_attr(HLF_FL)); | |
2339 else | |
2340 #endif | |
2341 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2342 col += len; | |
2343 } | |
2344 } | |
2345 | |
2346 /* | |
2347 * 4. Compose the folded-line string with 'foldtext', if set. | |
2348 */ | |
29 | 2349 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2350 |
2351 txtcol = col; /* remember where text starts */ | |
2352 | |
2353 /* | |
2354 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2355 * Right-left text is put in columns 0 - number-col, normal text is put | |
2356 * in columns number-col - window-width. | |
2357 */ | |
2358 #ifdef FEAT_MBYTE | |
2359 if (has_mbyte) | |
2360 { | |
2361 int cells; | |
714 | 2362 int u8c, u8cc[MAX_MCO]; |
2363 int i; | |
7 | 2364 int idx; |
2365 int c_len; | |
33 | 2366 char_u *p; |
7 | 2367 # ifdef FEAT_ARABIC |
2368 int prev_c = 0; /* previous Arabic character */ | |
2369 int prev_c1 = 0; /* first composing char for prev_c */ | |
2370 # endif | |
2371 | |
2372 # ifdef FEAT_RIGHTLEFT | |
2373 if (wp->w_p_rl) | |
2374 idx = off; | |
2375 else | |
2376 # endif | |
2377 idx = off + col; | |
2378 | |
2379 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2380 for (p = text; *p != NUL; ) | |
2381 { | |
2382 cells = (*mb_ptr2cells)(p); | |
474 | 2383 c_len = (*mb_ptr2len)(p); |
7 | 2384 if (col + cells > W_WIDTH(wp) |
2385 # ifdef FEAT_RIGHTLEFT | |
2386 - (wp->w_p_rl ? col : 0) | |
2387 # endif | |
2388 ) | |
2389 break; | |
2390 ScreenLines[idx] = *p; | |
2391 if (enc_utf8) | |
2392 { | |
714 | 2393 u8c = utfc_ptr2char(p, u8cc); |
2394 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2395 { |
2396 ScreenLinesUC[idx] = 0; | |
2397 #ifdef FEAT_ARABIC | |
2398 prev_c = u8c; | |
2399 #endif | |
2400 } | |
2401 else | |
2402 { | |
2403 #ifdef FEAT_ARABIC | |
2404 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2405 { | |
2406 /* Do Arabic shaping. */ | |
714 | 2407 int pc, pc1, nc; |
2408 int pcc[MAX_MCO]; | |
7 | 2409 int firstbyte = *p; |
2410 | |
2411 /* The idea of what is the previous and next | |
2412 * character depends on 'rightleft'. */ | |
2413 if (wp->w_p_rl) | |
2414 { | |
2415 pc = prev_c; | |
2416 pc1 = prev_c1; | |
2417 nc = utf_ptr2char(p + c_len); | |
714 | 2418 prev_c1 = u8cc[0]; |
7 | 2419 } |
2420 else | |
2421 { | |
714 | 2422 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2423 nc = prev_c; |
714 | 2424 pc1 = pcc[0]; |
7 | 2425 } |
2426 prev_c = u8c; | |
2427 | |
714 | 2428 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2429 pc, pc1, nc); |
2430 ScreenLines[idx] = firstbyte; | |
2431 } | |
2432 else | |
2433 prev_c = u8c; | |
2434 #endif | |
2435 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2436 #ifdef UNICODE16 |
7 | 2437 if (u8c >= 0x10000) |
2438 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2439 else | |
1401 | 2440 #endif |
7 | 2441 ScreenLinesUC[idx] = u8c; |
714 | 2442 for (i = 0; i < Screen_mco; ++i) |
2443 { | |
2444 ScreenLinesC[i][idx] = u8cc[i]; | |
2445 if (u8cc[i] == 0) | |
2446 break; | |
2447 } | |
7 | 2448 } |
2449 if (cells > 1) | |
2450 ScreenLines[idx + 1] = 0; | |
2451 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2452 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2453 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2454 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2455 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2456 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2457 ScreenLines[idx + 1] = p[1]; |
7 | 2458 col += cells; |
2459 idx += cells; | |
2460 p += c_len; | |
2461 } | |
2462 } | |
2463 else | |
2464 #endif | |
2465 { | |
2466 len = (int)STRLEN(text); | |
2467 if (len > W_WIDTH(wp) - col) | |
2468 len = W_WIDTH(wp) - col; | |
2469 if (len > 0) | |
2470 { | |
2471 #ifdef FEAT_RIGHTLEFT | |
2472 if (wp->w_p_rl) | |
2473 STRNCPY(current_ScreenLine, text, len); | |
2474 else | |
2475 #endif | |
2476 STRNCPY(current_ScreenLine + col, text, len); | |
2477 col += len; | |
2478 } | |
2479 } | |
2480 | |
2481 /* Fill the rest of the line with the fold filler */ | |
2482 #ifdef FEAT_RIGHTLEFT | |
2483 if (wp->w_p_rl) | |
2484 col -= txtcol; | |
2485 #endif | |
2486 while (col < W_WIDTH(wp) | |
2487 #ifdef FEAT_RIGHTLEFT | |
2488 - (wp->w_p_rl ? txtcol : 0) | |
2489 #endif | |
2490 ) | |
2491 { | |
2492 #ifdef FEAT_MBYTE | |
2493 if (enc_utf8) | |
2494 { | |
2495 if (fill_fold >= 0x80) | |
2496 { | |
2497 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2498 ScreenLinesC[0][off + col] = 0; |
7 | 2499 } |
2500 else | |
2501 ScreenLinesUC[off + col] = 0; | |
2502 } | |
2503 #endif | |
2504 ScreenLines[off + col++] = fill_fold; | |
2505 } | |
2506 | |
2507 if (text != buf) | |
2508 vim_free(text); | |
2509 | |
2510 /* | |
2511 * 6. set highlighting for the Visual area an other text. | |
2512 * If all folded lines are in the Visual area, highlight the line. | |
2513 */ | |
2514 #ifdef FEAT_VISUAL | |
2515 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2516 { | |
2517 if (ltoreq(curwin->w_cursor, VIsual)) | |
2518 { | |
2519 /* Visual is after curwin->w_cursor */ | |
2520 top = &curwin->w_cursor; | |
2521 bot = &VIsual; | |
2522 } | |
2523 else | |
2524 { | |
2525 /* Visual is before curwin->w_cursor */ | |
2526 top = &VIsual; | |
2527 bot = &curwin->w_cursor; | |
2528 } | |
2529 if (lnum >= top->lnum | |
2530 && lnume <= bot->lnum | |
2531 && (VIsual_mode != 'v' | |
2532 || ((lnum > top->lnum | |
2533 || (lnum == top->lnum | |
2534 && top->col == 0)) | |
2535 && (lnume < bot->lnum | |
2536 || (lnume == bot->lnum | |
2537 && (bot->col - (*p_sel == 'e')) | |
1883 | 2538 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2539 { |
2540 if (VIsual_mode == Ctrl_V) | |
2541 { | |
2542 /* Visual block mode: highlight the chars part of the block */ | |
2543 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2544 { | |
3040 | 2545 if (wp->w_old_cursor_lcol != MAXCOL |
2546 && wp->w_old_cursor_lcol + txtcol | |
2547 < (colnr_T)W_WIDTH(wp)) | |
7 | 2548 len = wp->w_old_cursor_lcol; |
2549 else | |
2550 len = W_WIDTH(wp) - txtcol; | |
2551 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2552 len - (int)wp->w_old_cursor_fcol); |
7 | 2553 } |
2554 } | |
2555 else | |
216 | 2556 { |
7 | 2557 /* Set all attributes of the text */ |
216 | 2558 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2559 } | |
7 | 2560 } |
2561 } | |
2562 #endif | |
2563 | |
743 | 2564 #ifdef FEAT_SYN_HL |
2565 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2566 if (wp->w_p_cuc) |
2567 { | |
2568 txtcol += wp->w_virtcol; | |
2569 if (wp->w_p_wrap) | |
2570 txtcol -= wp->w_skipcol; | |
2571 else | |
2572 txtcol -= wp->w_leftcol; | |
2573 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2574 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2575 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2576 } | |
743 | 2577 #endif |
7 | 2578 |
2579 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2580 (int)W_WIDTH(wp), FALSE); | |
2581 | |
2582 /* | |
2583 * Update w_cline_height and w_cline_folded if the cursor line was | |
2584 * updated (saves a call to plines() later). | |
2585 */ | |
2586 if (wp == curwin | |
2587 && lnum <= curwin->w_cursor.lnum | |
2588 && lnume >= curwin->w_cursor.lnum) | |
2589 { | |
2590 curwin->w_cline_row = row; | |
2591 curwin->w_cline_height = 1; | |
2592 curwin->w_cline_folded = TRUE; | |
2593 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2594 } | |
2595 } | |
2596 | |
2597 /* | |
2598 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2599 */ | |
2600 static void | |
2601 copy_text_attr(off, buf, len, attr) | |
2602 int off; | |
2603 char_u *buf; | |
2604 int len; | |
2605 int attr; | |
2606 { | |
216 | 2607 int i; |
2608 | |
7 | 2609 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2610 # ifdef FEAT_MBYTE | |
2611 if (enc_utf8) | |
2612 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2613 # endif | |
216 | 2614 for (i = 0; i < len; ++i) |
2615 ScreenAttrs[off + i] = attr; | |
7 | 2616 } |
2617 | |
2618 /* | |
2619 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2620 * Only to be called when 'foldcolumn' > 0. |
7 | 2621 */ |
2622 static void | |
2623 fill_foldcolumn(p, wp, closed, lnum) | |
2624 char_u *p; | |
2625 win_T *wp; | |
2626 int closed; /* TRUE of FALSE */ | |
2627 linenr_T lnum; /* current line number */ | |
2628 { | |
2629 int i = 0; | |
2630 int level; | |
2631 int first_level; | |
519 | 2632 int empty; |
7 | 2633 |
2634 /* Init to all spaces. */ | |
2635 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2636 | |
2637 level = win_foldinfo.fi_level; | |
2638 if (level > 0) | |
2639 { | |
519 | 2640 /* If there is only one column put more info in it. */ |
2641 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2642 | |
7 | 2643 /* If the column is too narrow, we start at the lowest level that |
2644 * fits and use numbers to indicated the depth. */ | |
519 | 2645 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2646 if (first_level < 1) |
2647 first_level = 1; | |
2648 | |
519 | 2649 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2650 { |
2651 if (win_foldinfo.fi_lnum == lnum | |
2652 && first_level + i >= win_foldinfo.fi_low_level) | |
2653 p[i] = '-'; | |
2654 else if (first_level == 1) | |
2655 p[i] = '|'; | |
2656 else if (first_level + i <= 9) | |
2657 p[i] = '0' + first_level + i; | |
2658 else | |
2659 p[i] = '>'; | |
2660 if (first_level + i == level) | |
2661 break; | |
2662 } | |
2663 } | |
2664 if (closed) | |
548 | 2665 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2666 } |
2667 #endif /* FEAT_FOLDING */ | |
2668 | |
2669 /* | |
2670 * Display line "lnum" of window 'wp' on the screen. | |
2671 * Start at row "startrow", stop when "endrow" is reached. | |
2672 * wp->w_virtcol needs to be valid. | |
2673 * | |
2674 * Return the number of last row the line occupies. | |
2675 */ | |
2676 static int | |
625 | 2677 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2678 win_T *wp; |
2679 linenr_T lnum; | |
2680 int startrow; | |
2681 int endrow; | |
1883 | 2682 int nochange UNUSED; /* not updating for changed text */ |
7 | 2683 { |
2684 int col; /* visual column on screen */ | |
2685 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2686 int c = 0; /* init for GCC */ | |
2687 long vcol = 0; /* virtual column (for tabs) */ | |
2688 long vcol_prev = -1; /* "vcol" of previous character */ | |
2689 char_u *line; /* current line */ | |
2690 char_u *ptr; /* current position in "line" */ | |
2691 int row; /* row in the window, excl w_winrow */ | |
2692 int screen_row; /* row on the screen, incl w_winrow */ | |
2693 | |
2694 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2695 int n_extra = 0; /* number of extra chars */ | |
1340 | 2696 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2697 int c_extra = NUL; /* extra chars, all the same */ |
2698 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2699 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2700 displaying lcs_eol at end-of-line */ | |
2701 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2702 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2703 | |
2704 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2705 int saved_n_extra = 0; | |
2706 char_u *saved_p_extra = NULL; | |
2707 int saved_c_extra = 0; | |
2708 int saved_char_attr = 0; | |
2709 | |
2710 int n_attr = 0; /* chars with special attr */ | |
2711 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2712 int n_attr3 = 0; /* chars with overruling special attr */ | |
2713 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2714 | |
2715 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2716 | |
2717 int fromcol, tocol; /* start/end of inverting */ | |
2718 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2719 int noinvcur = FALSE; /* don't invert the cursor */ | |
2720 #ifdef FEAT_VISUAL | |
2721 pos_T *top, *bot; | |
1813 | 2722 int lnum_in_visual_area = FALSE; |
7 | 2723 #endif |
2724 pos_T pos; | |
2725 long v; | |
2726 | |
2727 int char_attr = 0; /* attributes for next character */ | |
674 | 2728 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2729 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2730 in this line */ | |
2731 int attr = 0; /* attributes for area highlighting */ | |
2732 int area_attr = 0; /* attributes desired by highlighting */ | |
2733 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2734 #ifdef FEAT_SYN_HL | |
743 | 2735 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2736 int syntax_attr = 0; /* attributes desired by syntax */ |
2737 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2738 int save_did_emsg; | |
1437 | 2739 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
|
2740 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2741 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2742 #endif |
2743 #ifdef FEAT_SPELL | |
221 | 2744 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2745 # define SPWORDLEN 150 |
2746 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2747 int nextlinecol = 0; /* column where nextline[] starts */ |
2748 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2749 starts */ |
221 | 2750 int spell_attr = 0; /* attributes desired by spelling */ |
2751 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2752 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2753 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2754 * there are no spell errors */ |
386 | 2755 static int cap_col = -1; /* column to check for Cap word */ |
2756 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2757 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2758 #endif |
2759 int extra_check; /* has syntax or linebreak */ | |
2760 #ifdef FEAT_MBYTE | |
2761 int multi_attr = 0; /* attributes desired by multibyte */ | |
2762 int mb_l = 1; /* multi-byte byte length */ | |
2763 int mb_c = 0; /* decoded multi-byte character */ | |
2764 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2765 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2766 #endif |
2767 #ifdef FEAT_DIFF | |
2768 int filler_lines; /* nr of filler lines to be drawn */ | |
2769 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2770 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2771 int change_start = MAXCOL; /* first col of changed area */ |
2772 int change_end = -1; /* last col of changed area */ | |
2773 #endif | |
2774 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2775 #ifdef FEAT_LINEBREAK | |
2776 int need_showbreak = FALSE; | |
2777 #endif | |
910 | 2778 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2779 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2780 # define LINE_ATTR |
1536 | 2781 int line_attr = 0; /* attribute for the whole line */ |
7 | 2782 #endif |
2783 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2784 matchitem_T *cur; /* points to the match list */ |
2785 match_T *shl; /* points to search_hl or a match */ | |
2786 int shl_flag; /* flag to indicate whether search_hl | |
2787 has been processed or not */ | |
2788 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2789 equals startcol of search_hl or one | |
2790 of the matches */ | |
7 | 2791 #endif |
2792 #ifdef FEAT_ARABIC | |
2793 int prev_c = 0; /* previous Arabic character */ | |
2794 int prev_c1 = 0; /* first composing char for prev_c */ | |
2795 #endif | |
910 | 2796 #if defined(LINE_ATTR) |
867 | 2797 int did_line_attr = 0; |
2798 #endif | |
7 | 2799 |
2800 /* draw_state: items that are drawn in sequence: */ | |
2801 #define WL_START 0 /* nothing done yet */ | |
2802 #ifdef FEAT_CMDWIN | |
2803 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2804 #else | |
2805 # define WL_CMDLINE WL_START | |
2806 #endif | |
2807 #ifdef FEAT_FOLDING | |
2808 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2809 #else | |
2810 # define WL_FOLD WL_CMDLINE | |
2811 #endif | |
2812 #ifdef FEAT_SIGNS | |
2813 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2814 #else | |
2815 # define WL_SIGN WL_FOLD /* column for signs */ | |
2816 #endif | |
2817 #define WL_NR WL_SIGN + 1 /* line number */ | |
2818 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2819 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2820 #else | |
2821 # define WL_SBR WL_NR | |
2822 #endif | |
2823 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2824 int draw_state = WL_START; /* what to draw next */ | |
574 | 2825 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2826 int feedback_col = 0; |
2827 int feedback_old_attr = -1; | |
2828 #endif | |
2829 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2830 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2831 int syntax_flags = 0; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
2832 int syntax_seqnr = 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
|
2833 int prev_syntax_id = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2834 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2835 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2836 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
|
2837 wrapping */ |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2400
diff
changeset
|
2838 int vcol_off = 0; /* offset for concealed characters */ |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2839 int did_wcol = FALSE; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2840 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2841 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2842 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2843 #endif |
7 | 2844 |
2845 if (startrow > endrow) /* past the end already! */ | |
2846 return startrow; | |
2847 | |
2848 row = startrow; | |
2849 screen_row = row + W_WINROW(wp); | |
2850 | |
2851 /* | |
2852 * To speed up the loop below, set extra_check when there is linebreak, | |
2853 * trailing white space and/or syntax processing to be done. | |
2854 */ | |
2855 #ifdef FEAT_LINEBREAK | |
2856 extra_check = wp->w_p_lbr; | |
2857 #else | |
2858 extra_check = 0; | |
2859 #endif | |
2860 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2861 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2862 { |
2863 /* Prepare for syntax highlighting in this line. When there is an | |
2864 * error, stop syntax highlighting. */ | |
2865 save_did_emsg = did_emsg; | |
2866 did_emsg = FALSE; | |
2867 syntax_start(wp, lnum); | |
2868 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2869 wp->w_s->b_syn_error = TRUE; |
7 | 2870 else |
2871 { | |
2872 did_emsg = save_did_emsg; | |
2873 has_syntax = TRUE; | |
2874 extra_check = TRUE; | |
2875 } | |
2876 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2877 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2878 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2879 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2880 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2881 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 2882 #endif |
2883 | |
2884 #ifdef FEAT_SPELL | |
258 | 2885 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2886 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2887 && 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
|
2888 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2889 { |
2890 /* Prepare for spell checking. */ | |
2891 has_spell = TRUE; | |
2892 extra_check = TRUE; | |
348 | 2893 |
2894 /* Get the start of the next line, so that words that wrap to the next | |
2895 * line are found too: "et<line-break>al.". | |
2896 * Trick: skip a few chars for C/shell/Vim comments */ | |
2897 nextline[SPWORDLEN] = NUL; | |
2898 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2899 { | |
2900 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2901 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2902 } | |
2903 | |
2904 /* When a word wrapped from the previous line the start of the current | |
2905 * line is valid. */ | |
2906 if (lnum == checked_lnum) | |
2907 cur_checked_col = checked_col; | |
2908 checked_lnum = 0; | |
386 | 2909 |
2910 /* When there was a sentence end in the previous line may require a | |
2911 * word starting with capital in this line. In line 1 always check | |
2912 * the first word. */ | |
2913 if (lnum != capcol_lnum) | |
2914 cap_col = -1; | |
2915 if (lnum == 1) | |
2916 cap_col = 0; | |
2917 capcol_lnum = 0; | |
221 | 2918 } |
7 | 2919 #endif |
2920 | |
2921 /* | |
2922 * handle visual active in this window | |
2923 */ | |
2924 fromcol = -10; | |
2925 tocol = MAXCOL; | |
2926 #ifdef FEAT_VISUAL | |
2927 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2928 { | |
2929 /* Visual is after curwin->w_cursor */ | |
2930 if (ltoreq(curwin->w_cursor, VIsual)) | |
2931 { | |
2932 top = &curwin->w_cursor; | |
2933 bot = &VIsual; | |
2934 } | |
2935 else /* Visual is before curwin->w_cursor */ | |
2936 { | |
2937 top = &VIsual; | |
2938 bot = &curwin->w_cursor; | |
2939 } | |
1813 | 2940 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2941 if (VIsual_mode == Ctrl_V) /* block mode */ |
2942 { | |
1813 | 2943 if (lnum_in_visual_area) |
7 | 2944 { |
2945 fromcol = wp->w_old_cursor_fcol; | |
2946 tocol = wp->w_old_cursor_lcol; | |
2947 } | |
2948 } | |
2949 else /* non-block mode */ | |
2950 { | |
2951 if (lnum > top->lnum && lnum <= bot->lnum) | |
2952 fromcol = 0; | |
2953 else if (lnum == top->lnum) | |
2954 { | |
2955 if (VIsual_mode == 'V') /* linewise */ | |
2956 fromcol = 0; | |
2957 else | |
2958 { | |
2959 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2960 if (gchar_pos(top) == NUL) | |
2961 tocol = fromcol + 1; | |
2962 } | |
2963 } | |
2964 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2965 { | |
2966 if (*p_sel == 'e' && bot->col == 0 | |
2967 #ifdef FEAT_VIRTUALEDIT | |
2968 && bot->coladd == 0 | |
2969 #endif | |
2970 ) | |
2971 { | |
2972 fromcol = -10; | |
2973 tocol = MAXCOL; | |
2974 } | |
36 | 2975 else if (bot->col == MAXCOL) |
2976 tocol = MAXCOL; | |
7 | 2977 else |
2978 { | |
2979 pos = *bot; | |
2980 if (*p_sel == 'e') | |
2981 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2982 else | |
2983 { | |
2984 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2985 ++tocol; | |
2986 } | |
2987 } | |
2988 } | |
2989 } | |
2990 | |
2991 #ifndef MSDOS | |
2992 /* Check if the character under the cursor should not be inverted */ | |
2993 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2994 # ifdef FEAT_GUI | |
2995 && !gui.in_use | |
2996 # endif | |
2997 ) | |
2998 noinvcur = TRUE; | |
2999 #endif | |
3000 | |
3001 /* if inverting in this line set area_highlighting */ | |
3002 if (fromcol >= 0) | |
3003 { | |
3004 area_highlighting = TRUE; | |
3005 attr = hl_attr(HLF_V); | |
3006 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
3674 | 3007 if ((clip_star.available && !clip_star.owned |
3008 && clip_isautosel_star()) | |
3009 || (clip_plus.available && !clip_plus.owned | |
3010 && clip_isautosel_plus())) | |
7 | 3011 attr = hl_attr(HLF_VNC); |
3012 #endif | |
3013 } | |
3014 } | |
3015 | |
3016 /* | |
674 | 3017 * handle 'incsearch' and ":s///c" highlighting |
7 | 3018 */ |
3019 else | |
3020 #endif /* FEAT_VISUAL */ | |
3021 if (highlight_match | |
3022 && wp == curwin | |
3023 && lnum >= curwin->w_cursor.lnum | |
3024 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
3025 { | |
3026 if (lnum == curwin->w_cursor.lnum) | |
3027 getvcol(curwin, &(curwin->w_cursor), | |
3028 (colnr_T *)&fromcol, NULL, NULL); | |
3029 else | |
3030 fromcol = 0; | |
3031 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
3032 { | |
3033 pos.lnum = lnum; | |
3034 pos.col = search_match_endcol; | |
3035 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3036 } | |
3037 else | |
3038 tocol = MAXCOL; | |
1850 | 3039 /* do at least one character; happens when past end of line */ |
3040 if (fromcol == tocol) | |
3041 tocol = fromcol + 1; | |
7 | 3042 area_highlighting = TRUE; |
3043 attr = hl_attr(HLF_I); | |
3044 } | |
3045 | |
3046 #ifdef FEAT_DIFF | |
3047 filler_lines = diff_check(wp, lnum); | |
3048 if (filler_lines < 0) | |
3049 { | |
3050 if (filler_lines == -1) | |
3051 { | |
3052 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
3053 diff_hlf = HLF_ADD; /* added line */ | |
3054 else if (change_start == 0) | |
3055 diff_hlf = HLF_TXD; /* changed text */ | |
3056 else | |
3057 diff_hlf = HLF_CHD; /* changed line */ | |
3058 } | |
3059 else | |
3060 diff_hlf = HLF_ADD; /* added line */ | |
3061 filler_lines = 0; | |
3062 area_highlighting = TRUE; | |
3063 } | |
3064 if (lnum == wp->w_topline) | |
3065 filler_lines = wp->w_topfill; | |
3066 filler_todo = filler_lines; | |
3067 #endif | |
3068 | |
3069 #ifdef LINE_ATTR | |
3070 # ifdef FEAT_SIGNS | |
3071 /* If this line has a sign with line highlighting set line_attr. */ | |
3072 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3073 if (v != 0) | |
3074 line_attr = sign_get_attr((int)v, TRUE); | |
3075 # endif | |
3076 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3077 /* Highlight the current line in the quickfix window. */ | |
644 | 3078 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3079 line_attr = hl_attr(HLF_L); |
3080 # endif | |
3081 if (line_attr != 0) | |
3082 area_highlighting = TRUE; | |
3083 #endif | |
3084 | |
3085 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3086 ptr = line; | |
3087 | |
743 | 3088 #ifdef FEAT_SPELL |
348 | 3089 if (has_spell) |
3090 { | |
386 | 3091 /* For checking first word with a capital skip white space. */ |
3092 if (cap_col == 0) | |
835 | 3093 cap_col = (int)(skipwhite(line) - line); |
386 | 3094 |
348 | 3095 /* To be able to spell-check over line boundaries copy the end of the |
3096 * current line into nextline[]. Above the start of the next line was | |
3097 * copied to nextline[SPWORDLEN]. */ | |
3098 if (nextline[SPWORDLEN] == NUL) | |
3099 { | |
3100 /* No next line or it is empty. */ | |
3101 nextlinecol = MAXCOL; | |
3102 nextline_idx = 0; | |
3103 } | |
3104 else | |
3105 { | |
835 | 3106 v = (long)STRLEN(line); |
348 | 3107 if (v < SPWORDLEN) |
3108 { | |
3109 /* Short line, use it completely and append the start of the | |
3110 * next line. */ | |
3111 nextlinecol = 0; | |
3112 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3113 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3114 nextline_idx = v + 1; |
3115 } | |
3116 else | |
3117 { | |
3118 /* Long line, use only the last SPWORDLEN bytes. */ | |
3119 nextlinecol = v - SPWORDLEN; | |
3120 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3121 nextline_idx = SPWORDLEN + 1; | |
3122 } | |
3123 } | |
3124 } | |
3125 #endif | |
3126 | |
7 | 3127 /* find start of trailing whitespace */ |
3128 if (wp->w_p_list && lcs_trail) | |
3129 { | |
3130 trailcol = (colnr_T)STRLEN(ptr); | |
3131 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3132 --trailcol; | |
3133 trailcol += (colnr_T) (ptr - line); | |
3134 extra_check = TRUE; | |
3135 } | |
3136 | |
3137 /* | |
3138 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3139 * first character to be displayed. | |
3140 */ | |
3141 if (wp->w_p_wrap) | |
3142 v = wp->w_skipcol; | |
3143 else | |
3144 v = wp->w_leftcol; | |
3145 if (v > 0) | |
3146 { | |
3147 #ifdef FEAT_MBYTE | |
3148 char_u *prev_ptr = ptr; | |
3149 #endif | |
3150 while (vcol < v && *ptr != NUL) | |
3151 { | |
3152 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3153 vcol += c; | |
3154 #ifdef FEAT_MBYTE | |
3155 prev_ptr = ptr; | |
39 | 3156 #endif |
3157 mb_ptr_adv(ptr); | |
7 | 3158 } |
3159 | |
1984 | 3160 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3161 /* When: | |
3162 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3163 * - 'colorcolumn' is set, or |
1984 | 3164 * - 'virtualedit' is set, or |
3165 * - the visual mode is active, | |
3166 * the end of the line may be before the start of the displayed part. | |
3167 */ | |
3168 if (vcol < v && ( | |
3169 # ifdef FEAT_SYN_HL | |
3170 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3171 || draw_color_col |
1984 | 3172 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3173 || | |
3174 # endif | |
3175 # endif | |
3176 # ifdef FEAT_VIRTUALEDIT | |
3177 virtual_active() | |
3178 # ifdef FEAT_VISUAL | |
3179 || | |
3180 # endif | |
3181 # endif | |
3182 # ifdef FEAT_VISUAL | |
3183 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3184 # endif | |
3185 )) | |
3186 { | |
7 | 3187 vcol = v; |
1984 | 3188 } |
7 | 3189 #endif |
3190 | |
3191 /* Handle a character that's not completely on the screen: Put ptr at | |
3192 * that character but skip the first few screen characters. */ | |
3193 if (vcol > v) | |
3194 { | |
3195 vcol -= c; | |
3196 #ifdef FEAT_MBYTE | |
3197 ptr = prev_ptr; | |
3198 #else | |
3199 --ptr; | |
3200 #endif | |
3201 n_skip = v - vcol; | |
3202 } | |
3203 | |
3204 /* | |
3205 * Adjust for when the inverted text is before the screen, | |
3206 * and when the start of the inverted text is before the screen. | |
3207 */ | |
3208 if (tocol <= vcol) | |
3209 fromcol = 0; | |
3210 else if (fromcol >= 0 && fromcol < vcol) | |
3211 fromcol = vcol; | |
3212 | |
3213 #ifdef FEAT_LINEBREAK | |
3214 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3215 if (wp->w_p_wrap) | |
3216 need_showbreak = TRUE; | |
3217 #endif | |
743 | 3218 #ifdef FEAT_SPELL |
499 | 3219 /* When spell checking a word we need to figure out the start of the |
3220 * word and if it's badly spelled or not. */ | |
3221 if (has_spell) | |
3222 { | |
3223 int len; | |
1536 | 3224 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3225 hlf_T spell_hlf = HLF_COUNT; |
499 | 3226 |
3227 pos = wp->w_cursor; | |
3228 wp->w_cursor.lnum = lnum; | |
1536 | 3229 wp->w_cursor.col = linecol; |
534 | 3230 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3231 |
3232 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3233 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3234 ptr = line + linecol; | |
3235 | |
530 | 3236 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3237 { |
3238 /* no bad word found at line start, don't check until end of a | |
3239 * word */ | |
534 | 3240 spell_hlf = HLF_COUNT; |
3572 | 3241 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
499 | 3242 } |
3243 else | |
534 | 3244 { |
499 | 3245 /* bad word found, use attributes until end of word */ |
3246 word_end = wp->w_cursor.col + len + 1; | |
3247 | |
534 | 3248 /* Turn index into actual attributes. */ |
3249 if (spell_hlf != HLF_COUNT) | |
3250 spell_attr = highlight_attr[spell_hlf]; | |
3251 } | |
499 | 3252 wp->w_cursor = pos; |
501 | 3253 |
743 | 3254 # ifdef FEAT_SYN_HL |
501 | 3255 /* Need to restart syntax highlighting for this line. */ |
3256 if (has_syntax) | |
3257 syntax_start(wp, lnum); | |
743 | 3258 # endif |
499 | 3259 } |
3260 #endif | |
7 | 3261 } |
3262 | |
3263 /* | |
3264 * Correct highlighting for cursor that can't be disabled. | |
3265 * Avoids having to check this for each character. | |
3266 */ | |
3267 if (fromcol >= 0) | |
3268 { | |
3269 if (noinvcur) | |
3270 { | |
3271 if ((colnr_T)fromcol == wp->w_virtcol) | |
3272 { | |
3273 /* highlighting starts at cursor, let it start just after the | |
3274 * cursor */ | |
3275 fromcol_prev = fromcol; | |
3276 fromcol = -1; | |
3277 } | |
3278 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3279 /* restart highlighting after the cursor */ | |
3280 fromcol_prev = wp->w_virtcol; | |
3281 } | |
3282 if (fromcol >= tocol) | |
3283 fromcol = -1; | |
3284 } | |
3285 | |
3286 #ifdef FEAT_SEARCH_EXTRA | |
3287 /* | |
1326 | 3288 * Handle highlighting the last used search pattern and matches. |
3289 * Do this for both search_hl and the match list. | |
7 | 3290 */ |
1326 | 3291 cur = wp->w_match_head; |
3292 shl_flag = FALSE; | |
3293 while (cur != NULL || shl_flag == FALSE) | |
3294 { | |
3295 if (shl_flag == FALSE) | |
3296 { | |
3297 shl = &search_hl; | |
3298 shl_flag = TRUE; | |
3299 } | |
3300 else | |
3301 shl = &cur->hl; | |
36 | 3302 shl->startcol = MAXCOL; |
3303 shl->endcol = MAXCOL; | |
7 | 3304 shl->attr_cur = 0; |
3305 if (shl->rm.regprog != NULL) | |
3306 { | |
3307 v = (long)(ptr - line); | |
3308 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3309 | |
3310 /* Need to get the line again, a multi-line regexp may have made it | |
3311 * invalid. */ | |
3312 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3313 ptr = line + v; | |
3314 | |
3315 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3316 { | |
3317 if (shl->lnum == lnum) | |
36 | 3318 shl->startcol = shl->rm.startpos[0].col; |
7 | 3319 else |
36 | 3320 shl->startcol = 0; |
7 | 3321 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3322 - shl->rm.startpos[0].lnum) | |
36 | 3323 shl->endcol = shl->rm.endpos[0].col; |
7 | 3324 else |
36 | 3325 shl->endcol = MAXCOL; |
7 | 3326 /* Highlight one character for an empty match. */ |
36 | 3327 if (shl->startcol == shl->endcol) |
7 | 3328 { |
3329 #ifdef FEAT_MBYTE | |
36 | 3330 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3331 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3332 else |
3333 #endif | |
36 | 3334 ++shl->endcol; |
7 | 3335 } |
36 | 3336 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3337 { |
3338 shl->attr_cur = shl->attr; | |
3339 search_attr = shl->attr; | |
3340 } | |
3341 area_highlighting = TRUE; | |
3342 } | |
3343 } | |
1326 | 3344 if (shl != &search_hl && cur != NULL) |
3345 cur = cur->next; | |
7 | 3346 } |
3347 #endif | |
3348 | |
743 | 3349 #ifdef FEAT_SYN_HL |
818 | 3350 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3351 * active, because it's not clear what is selected then. */ | |
3352 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3353 { |
3354 line_attr = hl_attr(HLF_CUL); | |
3355 area_highlighting = TRUE; | |
3356 } | |
3357 #endif | |
3358 | |
504 | 3359 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3360 col = 0; |
3361 #ifdef FEAT_RIGHTLEFT | |
3362 if (wp->w_p_rl) | |
3363 { | |
3364 /* Rightleft window: process the text in the normal direction, but put | |
3365 * it in current_ScreenLine[] from right to left. Start at the | |
3366 * rightmost column of the window. */ | |
3367 col = W_WIDTH(wp) - 1; | |
3368 off += col; | |
3369 } | |
3370 #endif | |
3371 | |
3372 /* | |
3373 * Repeat for the whole displayed line. | |
3374 */ | |
3375 for (;;) | |
3376 { | |
3377 /* Skip this quickly when working on the text. */ | |
3378 if (draw_state != WL_LINE) | |
3379 { | |
3380 #ifdef FEAT_CMDWIN | |
3381 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3382 { | |
3383 draw_state = WL_CMDLINE; | |
3384 if (cmdwin_type != 0 && wp == curwin) | |
3385 { | |
3386 /* Draw the cmdline character. */ | |
3387 n_extra = 1; | |
1340 | 3388 c_extra = cmdwin_type; |
7 | 3389 char_attr = hl_attr(HLF_AT); |
3390 } | |
3391 } | |
3392 #endif | |
3393 | |
3394 #ifdef FEAT_FOLDING | |
3395 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3396 { | |
3397 draw_state = WL_FOLD; | |
3398 if (wp->w_p_fdc > 0) | |
3399 { | |
3400 /* Draw the 'foldcolumn'. */ | |
3401 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3402 n_extra = wp->w_p_fdc; | |
3403 p_extra = extra; | |
1340 | 3404 p_extra[n_extra] = NUL; |
7 | 3405 c_extra = NUL; |
3406 char_attr = hl_attr(HLF_FC); | |
3407 } | |
3408 } | |
3409 #endif | |
3410 | |
3411 #ifdef FEAT_SIGNS | |
3412 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3413 { | |
3414 draw_state = WL_SIGN; | |
3415 /* Show the sign column when there are any signs in this | |
3416 * buffer or when using Netbeans. */ | |
3417 if (draw_signcolumn(wp) | |
3418 # ifdef FEAT_DIFF | |
3419 && filler_todo <= 0 | |
3420 # endif | |
3421 ) | |
3422 { | |
2661 | 3423 int text_sign; |
7 | 3424 # ifdef FEAT_SIGN_ICONS |
2661 | 3425 int icon_sign; |
7 | 3426 # endif |
3427 | |
3428 /* Draw two cells with the sign value or blank. */ | |
3429 c_extra = ' '; | |
3430 char_attr = hl_attr(HLF_SC); | |
3431 n_extra = 2; | |
3432 | |
3433 if (row == startrow) | |
3434 { | |
3435 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3436 SIGN_TEXT); | |
3437 # ifdef FEAT_SIGN_ICONS | |
3438 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3439 SIGN_ICON); | |
3440 if (gui.in_use && icon_sign != 0) | |
3441 { | |
3442 /* Use the image in this position. */ | |
3443 c_extra = SIGN_BYTE; | |
3444 # ifdef FEAT_NETBEANS_INTG | |
3445 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3446 c_extra = MULTISIGN_BYTE; | |
3447 # endif | |
3448 char_attr = icon_sign; | |
3449 } | |
3450 else | |
3451 # endif | |
3452 if (text_sign != 0) | |
3453 { | |
3454 p_extra = sign_get_text(text_sign); | |
3455 if (p_extra != NULL) | |
3456 { | |
3457 c_extra = NUL; | |
835 | 3458 n_extra = (int)STRLEN(p_extra); |
7 | 3459 } |
3460 char_attr = sign_get_attr(text_sign, FALSE); | |
3461 } | |
3462 } | |
3463 } | |
3464 } | |
3465 #endif | |
3466 | |
3467 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3468 { | |
3469 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3470 /* 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
|
3471 * 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
|
3472 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3473 && (row == startrow |
3474 #ifdef FEAT_DIFF | |
3475 + filler_lines | |
3476 #endif | |
3477 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3478 { | |
3479 /* Draw the line number (empty space after wrapping). */ | |
3480 if (row == startrow | |
3481 #ifdef FEAT_DIFF | |
3482 + filler_lines | |
3483 #endif | |
3484 ) | |
3485 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3486 long num; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3487 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3488 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3489 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3490 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3491 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3492 /* 'relativenumber', don't use negative numbers */ |
2675 | 3493 num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3494 |
13 | 3495 sprintf((char *)extra, "%*ld ", |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3496 number_width(wp), num); |
7 | 3497 if (wp->w_skipcol > 0) |
3498 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3499 *p_extra = '-'; | |
3500 #ifdef FEAT_RIGHTLEFT | |
3501 if (wp->w_p_rl) /* reverse line numbers */ | |
3502 rl_mirror(extra); | |
3503 #endif | |
3504 p_extra = extra; | |
3505 c_extra = NUL; | |
3506 } | |
3507 else | |
3508 c_extra = ' '; | |
13 | 3509 n_extra = number_width(wp) + 1; |
7 | 3510 char_attr = hl_attr(HLF_N); |
743 | 3511 #ifdef FEAT_SYN_HL |
3512 /* When 'cursorline' is set highlight the line number of | |
3427 | 3513 * the current line differently. |
3514 * TODO: Can we use CursorLine instead of CursorLineNr | |
3515 * when CursorLineNr isn't set? */ | |
743 | 3516 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
3427 | 3517 char_attr = hl_attr(HLF_CLN); |
743 | 3518 #endif |
7 | 3519 } |
3520 } | |
3521 | |
3522 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3523 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3524 { | |
3525 draw_state = WL_SBR; | |
3526 # ifdef FEAT_DIFF | |
3527 if (filler_todo > 0) | |
3528 { | |
3529 /* Draw "deleted" diff line(s). */ | |
3530 if (char2cells(fill_diff) > 1) | |
3531 c_extra = '-'; | |
3532 else | |
3533 c_extra = fill_diff; | |
3534 # ifdef FEAT_RIGHTLEFT | |
3535 if (wp->w_p_rl) | |
3536 n_extra = col + 1; | |
3537 else | |
3538 # endif | |
3539 n_extra = W_WIDTH(wp) - col; | |
3540 char_attr = hl_attr(HLF_DED); | |
3541 } | |
3542 # endif | |
3543 # ifdef FEAT_LINEBREAK | |
3544 if (*p_sbr != NUL && need_showbreak) | |
3545 { | |
3546 /* Draw 'showbreak' at the start of each broken line. */ | |
3547 p_extra = p_sbr; | |
3548 c_extra = NUL; | |
3549 n_extra = (int)STRLEN(p_sbr); | |
3550 char_attr = hl_attr(HLF_AT); | |
3551 need_showbreak = FALSE; | |
3552 /* Correct end of highlighted area for 'showbreak', | |
3553 * required when 'linebreak' is also set. */ | |
3554 if (tocol == vcol) | |
3555 tocol += n_extra; | |
3556 } | |
3557 # endif | |
3558 } | |
3559 #endif | |
3560 | |
3561 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3562 { | |
3563 draw_state = WL_LINE; | |
3564 if (saved_n_extra) | |
3565 { | |
3566 /* Continue item from end of wrapped line. */ | |
3567 n_extra = saved_n_extra; | |
3568 c_extra = saved_c_extra; | |
3569 p_extra = saved_p_extra; | |
3570 char_attr = saved_char_attr; | |
3571 } | |
3572 else | |
3573 char_attr = 0; | |
3574 } | |
3575 } | |
3576 | |
3577 /* When still displaying '$' of change command, stop at cursor */ | |
3318 | 3578 if (dollar_vcol >= 0 && wp == curwin |
819 | 3579 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
7 | 3580 #ifdef FEAT_DIFF |
3581 && filler_todo <= 0 | |
3582 #endif | |
3583 ) | |
3584 { | |
3585 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3586 wp->w_p_rl); | |
819 | 3587 /* Pretend we have finished updating the window. Except when |
3588 * 'cursorcolumn' is set. */ | |
3589 #ifdef FEAT_SYN_HL | |
3590 if (wp->w_p_cuc) | |
3591 row = wp->w_cline_row + wp->w_cline_height; | |
3592 else | |
3593 #endif | |
3594 row = wp->w_height; | |
7 | 3595 break; |
3596 } | |
3597 | |
3598 if (draw_state == WL_LINE && area_highlighting) | |
3599 { | |
3600 /* handle Visual or match highlighting in this line */ | |
3601 if (vcol == fromcol | |
3602 #ifdef FEAT_MBYTE | |
3603 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3604 && (*mb_ptr2cells)(ptr) > 1) | |
3605 #endif | |
3606 || ((int)vcol_prev == fromcol_prev | |
1814 | 3607 && vcol_prev < vcol /* not at margin */ |
7 | 3608 && vcol < tocol)) |
3609 area_attr = attr; /* start highlighting */ | |
3610 else if (area_attr != 0 | |
3611 && (vcol == tocol | |
3612 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3613 area_attr = 0; /* stop highlighting */ | |
3614 | |
3615 #ifdef FEAT_SEARCH_EXTRA | |
3616 if (!n_extra) | |
3617 { | |
3618 /* | |
3619 * Check for start/end of search pattern match. | |
3620 * After end, check for start/end of next match. | |
3621 * When another match, have to check for start again. | |
3622 * Watch out for matching an empty string! | |
1326 | 3623 * Do this for 'search_hl' and the match list (ordered by |
3624 * priority). | |
7 | 3625 */ |
36 | 3626 v = (long)(ptr - line); |
1326 | 3627 cur = wp->w_match_head; |
3628 shl_flag = FALSE; | |
3629 while (cur != NULL || shl_flag == FALSE) | |
3630 { | |
3631 if (shl_flag == FALSE | |
3632 && ((cur != NULL | |
3633 && cur->priority > SEARCH_HL_PRIORITY) | |
3634 || cur == NULL)) | |
3635 { | |
3636 shl = &search_hl; | |
3637 shl_flag = TRUE; | |
3638 } | |
3639 else | |
3640 shl = &cur->hl; | |
7 | 3641 while (shl->rm.regprog != NULL) |
3642 { | |
36 | 3643 if (shl->startcol != MAXCOL |
3644 && v >= (long)shl->startcol | |
3645 && v < (long)shl->endcol) | |
7 | 3646 { |
3647 shl->attr_cur = shl->attr; | |
3648 } | |
36 | 3649 else if (v == (long)shl->endcol) |
7 | 3650 { |
3651 shl->attr_cur = 0; | |
3652 | |
3653 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3654 | |
3655 /* Need to get the line again, a multi-line regexp | |
3656 * may have made it invalid. */ | |
3657 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3658 ptr = line + v; | |
3659 | |
3660 if (shl->lnum == lnum) | |
3661 { | |
36 | 3662 shl->startcol = shl->rm.startpos[0].col; |
7 | 3663 if (shl->rm.endpos[0].lnum == 0) |
36 | 3664 shl->endcol = shl->rm.endpos[0].col; |
7 | 3665 else |
36 | 3666 shl->endcol = MAXCOL; |
3667 | |
3668 if (shl->startcol == shl->endcol) | |
7 | 3669 { |
3670 /* highlight empty match, try again after | |
3671 * it */ | |
3672 #ifdef FEAT_MBYTE | |
3673 if (has_mbyte) | |
474 | 3674 shl->endcol += (*mb_ptr2len)(line |
36 | 3675 + shl->endcol); |
7 | 3676 else |
3677 #endif | |
36 | 3678 ++shl->endcol; |
7 | 3679 } |
3680 | |
3681 /* Loop to check if the match starts at the | |
3682 * current position */ | |
3683 continue; | |
3684 } | |
3685 } | |
3686 break; | |
3687 } | |
1326 | 3688 if (shl != &search_hl && cur != NULL) |
3689 cur = cur->next; | |
3690 } | |
3691 | |
3692 /* Use attributes from match with highest priority among | |
3693 * 'search_hl' and the match list. */ | |
3694 search_attr = search_hl.attr_cur; | |
3695 cur = wp->w_match_head; | |
3696 shl_flag = FALSE; | |
3697 while (cur != NULL || shl_flag == FALSE) | |
3698 { | |
3699 if (shl_flag == FALSE | |
3700 && ((cur != NULL | |
3701 && cur->priority > SEARCH_HL_PRIORITY) | |
3702 || cur == NULL)) | |
699 | 3703 { |
1326 | 3704 shl = &search_hl; |
3705 shl_flag = TRUE; | |
699 | 3706 } |
1326 | 3707 else |
3708 shl = &cur->hl; | |
3709 if (shl->attr_cur != 0) | |
3710 search_attr = shl->attr_cur; | |
3711 if (shl != &search_hl && cur != NULL) | |
3712 cur = cur->next; | |
3713 } | |
7 | 3714 } |
3715 #endif | |
3716 | |
3717 #ifdef FEAT_DIFF | |
674 | 3718 if (diff_hlf != (hlf_T)0) |
7 | 3719 { |
1295 | 3720 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3721 && n_extra == 0) | |
7 | 3722 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3723 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3724 && n_extra == 0) | |
7 | 3725 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3726 line_attr = hl_attr(diff_hlf); |
3727 } | |
3728 #endif | |
3729 | |
3730 /* Decide which of the highlight attributes to use. */ | |
3731 attr_pri = TRUE; | |
3732 if (area_attr != 0) | |
3733 char_attr = area_attr; | |
3734 else if (search_attr != 0) | |
3735 char_attr = search_attr; | |
3736 #ifdef LINE_ATTR | |
3737 /* Use line_attr when not in the Visual or 'incsearch' area | |
3738 * (area_attr may be 0 when "noinvcur" is set). */ | |
3739 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3740 || vcol < fromcol || vcol_prev < fromcol_prev |
3741 || vcol >= tocol)) | |
674 | 3742 char_attr = line_attr; |
3743 #endif | |
3744 else | |
3745 { | |
3746 attr_pri = FALSE; | |
3747 #ifdef FEAT_SYN_HL | |
3748 if (has_syntax) | |
3749 char_attr = syntax_attr; | |
3750 else | |
3751 #endif | |
3752 char_attr = 0; | |
3753 } | |
7 | 3754 } |
3755 | |
3756 /* | |
3757 * Get the next character to put on the screen. | |
3758 */ | |
3759 /* | |
1340 | 3760 * The "p_extra" points to the extra stuff that is inserted to |
3761 * represent special characters (non-printable stuff) and other | |
3762 * things. When all characters are the same, c_extra is used. | |
3763 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3764 * "p_extra[n_extra]". | |
7 | 3765 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3766 */ | |
3767 if (n_extra > 0) | |
3768 { | |
3769 if (c_extra != NUL) | |
3770 { | |
3771 c = c_extra; | |
3772 #ifdef FEAT_MBYTE | |
3773 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3774 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3775 { | |
3776 mb_utf8 = TRUE; | |
714 | 3777 u8cc[0] = 0; |
819 | 3778 c = 0xc0; |
7 | 3779 } |
3780 else | |
3781 mb_utf8 = FALSE; | |
3782 #endif | |
3783 } | |
3784 else | |
3785 { | |
3786 c = *p_extra; | |
3787 #ifdef FEAT_MBYTE | |
3788 if (has_mbyte) | |
3789 { | |
3790 mb_c = c; | |
3791 if (enc_utf8) | |
3792 { | |
3793 /* If the UTF-8 character is more than one byte: | |
3794 * Decode it into "mb_c". */ | |
474 | 3795 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3796 mb_utf8 = FALSE; |
3797 if (mb_l > n_extra) | |
3798 mb_l = 1; | |
3799 else if (mb_l > 1) | |
3800 { | |
714 | 3801 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3802 mb_utf8 = TRUE; |
819 | 3803 c = 0xc0; |
7 | 3804 } |
3805 } | |
3806 else | |
3807 { | |
3808 /* if this is a DBCS character, put it in "mb_c" */ | |
3809 mb_l = MB_BYTE2LEN(c); | |
3810 if (mb_l >= n_extra) | |
3811 mb_l = 1; | |
3812 else if (mb_l > 1) | |
3813 mb_c = (c << 8) + p_extra[1]; | |
3814 } | |
504 | 3815 if (mb_l == 0) /* at the NUL at end-of-line */ |
3816 mb_l = 1; | |
3817 | |
7 | 3818 /* If a double-width char doesn't fit display a '>' in the |
3819 * last column. */ | |
504 | 3820 if (( |
7 | 3821 # ifdef FEAT_RIGHTLEFT |
3822 wp->w_p_rl ? (col <= 0) : | |
3823 # endif | |
504 | 3824 (col >= W_WIDTH(wp) - 1)) |
7 | 3825 && (*mb_char2cells)(mb_c) == 2) |
3826 { | |
3827 c = '>'; | |
3828 mb_c = c; | |
3829 mb_l = 1; | |
3830 mb_utf8 = FALSE; | |
3831 multi_attr = hl_attr(HLF_AT); | |
3832 /* put the pointer back to output the double-width | |
3833 * character at the start of the next line. */ | |
3834 ++n_extra; | |
3835 --p_extra; | |
3836 } | |
3837 else | |
3838 { | |
3839 n_extra -= mb_l - 1; | |
3840 p_extra += mb_l - 1; | |
3841 } | |
3842 } | |
3843 #endif | |
3844 ++p_extra; | |
3845 } | |
3846 --n_extra; | |
3847 } | |
3848 else | |
3849 { | |
3850 /* | |
3851 * Get a character from the line itself. | |
3852 */ | |
3853 c = *ptr; | |
3854 #ifdef FEAT_MBYTE | |
3855 if (has_mbyte) | |
3856 { | |
3857 mb_c = c; | |
3858 if (enc_utf8) | |
3859 { | |
3860 /* If the UTF-8 character is more than one byte: Decode it | |
3861 * into "mb_c". */ | |
474 | 3862 mb_l = (*mb_ptr2len)(ptr); |
7 | 3863 mb_utf8 = FALSE; |
3864 if (mb_l > 1) | |
3865 { | |
714 | 3866 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3867 /* Overlong encoded ASCII or ASCII with composing char |
3868 * is displayed normally, except a NUL. */ | |
3869 if (mb_c < 0x80) | |
3870 c = mb_c; | |
3871 mb_utf8 = TRUE; | |
507 | 3872 |
3873 /* At start of the line we can have a composing char. | |
3874 * Draw it as a space with a composing char. */ | |
3875 if (utf_iscomposing(mb_c)) | |
3876 { | |
1326 | 3877 int i; |
3878 | |
714 | 3879 for (i = Screen_mco - 1; i > 0; --i) |
3880 u8cc[i] = u8cc[i - 1]; | |
3881 u8cc[0] = mb_c; | |
507 | 3882 mb_c = ' '; |
3883 } | |
7 | 3884 } |
3885 | |
3886 if ((mb_l == 1 && c >= 0x80) | |
3887 || (mb_l >= 1 && mb_c == 0) | |
3888 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3889 # ifdef UNICODE16 |
3890 || mb_c >= 0x10000 | |
3891 # endif | |
3892 ))) | |
7 | 3893 { |
3894 /* | |
3895 * Illegal UTF-8 byte: display as <xx>. | |
3896 * Non-BMP character : display as ? or fullwidth ?. | |
3897 */ | |
1401 | 3898 # ifdef UNICODE16 |
7 | 3899 if (mb_c < 0x10000) |
1401 | 3900 # endif |
7 | 3901 { |
3902 transchar_hex(extra, mb_c); | |
714 | 3903 # ifdef FEAT_RIGHTLEFT |
7 | 3904 if (wp->w_p_rl) /* reverse */ |
3905 rl_mirror(extra); | |
714 | 3906 # endif |
7 | 3907 } |
1401 | 3908 # ifdef UNICODE16 |
7 | 3909 else if (utf_char2cells(mb_c) != 2) |
3910 STRCPY(extra, "?"); | |
3911 else | |
3912 /* 0xff1f in UTF-8: full-width '?' */ | |
3913 STRCPY(extra, "\357\274\237"); | |
1401 | 3914 # endif |
7 | 3915 |
3916 p_extra = extra; | |
3917 c = *p_extra; | |
3918 mb_c = mb_ptr2char_adv(&p_extra); | |
3919 mb_utf8 = (c >= 0x80); | |
3920 n_extra = (int)STRLEN(p_extra); | |
3921 c_extra = NUL; | |
3922 if (area_attr == 0 && search_attr == 0) | |
3923 { | |
3924 n_attr = n_extra + 1; | |
3925 extra_attr = hl_attr(HLF_8); | |
3926 saved_attr2 = char_attr; /* save current attr */ | |
3927 } | |
3928 } | |
3929 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3930 mb_l = 1; | |
3931 #ifdef FEAT_ARABIC | |
3932 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3933 { | |
3934 /* Do Arabic shaping. */ | |
714 | 3935 int pc, pc1, nc; |
3936 int pcc[MAX_MCO]; | |
7 | 3937 |
3938 /* The idea of what is the previous and next | |
3939 * character depends on 'rightleft'. */ | |
3940 if (wp->w_p_rl) | |
3941 { | |
3942 pc = prev_c; | |
3943 pc1 = prev_c1; | |
3944 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3945 prev_c1 = u8cc[0]; |
7 | 3946 } |
3947 else | |
3948 { | |
714 | 3949 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3950 nc = prev_c; |
714 | 3951 pc1 = pcc[0]; |
7 | 3952 } |
3953 prev_c = mb_c; | |
3954 | |
714 | 3955 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3956 } |
3957 else | |
3958 prev_c = mb_c; | |
3959 #endif | |
3960 } | |
3961 else /* enc_dbcs */ | |
3962 { | |
3963 mb_l = MB_BYTE2LEN(c); | |
3964 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3965 mb_l = 1; | |
3966 else if (mb_l > 1) | |
3967 { | |
3968 /* We assume a second byte below 32 is illegal. | |
3969 * Hopefully this is OK for all double-byte encodings! | |
3970 */ | |
3971 if (ptr[1] >= 32) | |
3972 mb_c = (c << 8) + ptr[1]; | |
3973 else | |
3974 { | |
3975 if (ptr[1] == NUL) | |
3976 { | |
3977 /* head byte at end of line */ | |
3978 mb_l = 1; | |
3979 transchar_nonprint(extra, c); | |
3980 } | |
3981 else | |
3982 { | |
3983 /* illegal tail byte */ | |
3984 mb_l = 2; | |
3985 STRCPY(extra, "XX"); | |
3986 } | |
3987 p_extra = extra; | |
3988 n_extra = (int)STRLEN(extra) - 1; | |
3989 c_extra = NUL; | |
3990 c = *p_extra++; | |
3991 if (area_attr == 0 && search_attr == 0) | |
3992 { | |
3993 n_attr = n_extra + 1; | |
3994 extra_attr = hl_attr(HLF_8); | |
3995 saved_attr2 = char_attr; /* save current attr */ | |
3996 } | |
3997 mb_c = c; | |
3998 } | |
3999 } | |
4000 } | |
4001 /* If a double-width char doesn't fit display a '>' in the | |
4002 * last column; the character is displayed at the start of the | |
4003 * next line. */ | |
4004 if (( | |
4005 # ifdef FEAT_RIGHTLEFT | |
4006 wp->w_p_rl ? (col <= 0) : | |
4007 # endif | |
4008 (col >= W_WIDTH(wp) - 1)) | |
4009 && (*mb_char2cells)(mb_c) == 2) | |
4010 { | |
4011 c = '>'; | |
4012 mb_c = c; | |
4013 mb_utf8 = FALSE; | |
4014 mb_l = 1; | |
4015 multi_attr = hl_attr(HLF_AT); | |
4016 /* Put pointer back so that the character will be | |
4017 * displayed at the start of the next line. */ | |
4018 --ptr; | |
4019 } | |
4020 else if (*ptr != NUL) | |
4021 ptr += mb_l - 1; | |
4022 | |
4023 /* If a double-width char doesn't fit at the left side display | |
2509
6d6378ba18cb
Fix: An unprintable multi-byte character at the start of the screen line
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
4024 * a '<' in the first column. Don't do this for unprintable |
6d6378ba18cb
Fix: An unprintable multi-byte character at the start of the screen line
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
4025 * charactes. */ |
6d6378ba18cb
Fix: An unprintable multi-byte character at the start of the screen line
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
4026 if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
7 | 4027 { |
4028 n_extra = 1; | |
3586 | 4029 c_extra = MB_FILLER_CHAR; |
7 | 4030 c = ' '; |
4031 if (area_attr == 0 && search_attr == 0) | |
4032 { | |
4033 n_attr = n_extra + 1; | |
4034 extra_attr = hl_attr(HLF_AT); | |
4035 saved_attr2 = char_attr; /* save current attr */ | |
4036 } | |
4037 mb_c = c; | |
4038 mb_utf8 = FALSE; | |
4039 mb_l = 1; | |
4040 } | |
4041 | |
4042 } | |
4043 #endif | |
4044 ++ptr; | |
4045 | |
12 | 4046 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 4047 if (wp->w_p_list && (c == 160 |
4048 #ifdef FEAT_MBYTE | |
4049 || (mb_utf8 && mb_c == 160) | |
4050 #endif | |
4051 ) && lcs_nbsp) | |
12 | 4052 { |
4053 c = lcs_nbsp; | |
4054 if (area_attr == 0 && search_attr == 0) | |
4055 { | |
4056 n_attr = 1; | |
4057 extra_attr = hl_attr(HLF_8); | |
4058 saved_attr2 = char_attr; /* save current attr */ | |
4059 } | |
4060 #ifdef FEAT_MBYTE | |
4061 mb_c = c; | |
4062 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4063 { | |
4064 mb_utf8 = TRUE; | |
714 | 4065 u8cc[0] = 0; |
819 | 4066 c = 0xc0; |
12 | 4067 } |
4068 else | |
4069 mb_utf8 = FALSE; | |
4070 #endif | |
4071 } | |
4072 | |
7 | 4073 if (extra_check) |
4074 { | |
743 | 4075 #ifdef FEAT_SPELL |
221 | 4076 int can_spell = TRUE; |
743 | 4077 #endif |
4078 | |
4079 #ifdef FEAT_SYN_HL | |
7 | 4080 /* Get syntax attribute, unless still at the start of the line |
4081 * (double-wide char that doesn't fit). */ | |
221 | 4082 v = (long)(ptr - line); |
4083 if (has_syntax && v > 0) | |
7 | 4084 { |
4085 /* Get the syntax attribute for the character. If there | |
4086 * is an error, disable syntax highlighting. */ | |
4087 save_did_emsg = did_emsg; | |
4088 did_emsg = FALSE; | |
4089 | |
221 | 4090 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 4091 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4092 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4093 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4094 NULL, FALSE); |
7 | 4095 |
4096 if (did_emsg) | |
482 | 4097 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4098 wp->w_s->b_syn_error = TRUE; |
482 | 4099 has_syntax = FALSE; |
4100 } | |
7 | 4101 else |
4102 did_emsg = save_did_emsg; | |
4103 | |
4104 /* Need to get the line again, a multi-line regexp may | |
4105 * have made it invalid. */ | |
4106 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4107 ptr = line + v; | |
4108 | |
674 | 4109 if (!attr_pri) |
7 | 4110 char_attr = syntax_attr; |
301 | 4111 else |
303 | 4112 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
|
4113 # 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
|
4114 /* 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
|
4115 * 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
|
4116 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
|
4117 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
|
4118 else |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
4119 syntax_flags = get_syntax_info(&syntax_seqnr); |
2364
151b037b7e74
Fix hang when resizing in diff mode and there are concealed items.
Bram Moolenaar <bram@vim.org>
parents:
2359
diff
changeset
|
4120 # endif |
7 | 4121 } |
743 | 4122 #endif |
4123 | |
4124 #ifdef FEAT_SPELL | |
301 | 4125 /* Check spelling (unless at the end of the line). |
319 | 4126 * Only do this when there is no syntax highlighting, the |
4127 * @Spell cluster is not used or the current syntax item | |
4128 * contains the @Spell cluster. */ | |
348 | 4129 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4130 { |
230 | 4131 spell_attr = 0; |
743 | 4132 # ifdef FEAT_SYN_HL |
674 | 4133 if (!attr_pri) |
230 | 4134 char_attr = syntax_attr; |
743 | 4135 # endif |
4136 if (c != 0 && ( | |
4137 # ifdef FEAT_SYN_HL | |
4138 !has_syntax || | |
4139 # endif | |
4140 can_spell)) | |
221 | 4141 { |
348 | 4142 char_u *prev_ptr, *p; |
4143 int len; | |
534 | 4144 hlf_T spell_hlf = HLF_COUNT; |
221 | 4145 # ifdef FEAT_MBYTE |
336 | 4146 if (has_mbyte) |
4147 { | |
4148 prev_ptr = ptr - mb_l; | |
4149 v -= mb_l - 1; | |
4150 } | |
4151 else | |
221 | 4152 # endif |
336 | 4153 prev_ptr = ptr - 1; |
348 | 4154 |
4155 /* Use nextline[] if possible, it has the start of the | |
4156 * next line concatenated. */ | |
4157 if ((prev_ptr - line) - nextlinecol >= 0) | |
4158 p = nextline + (prev_ptr - line) - nextlinecol; | |
4159 else | |
4160 p = prev_ptr; | |
835 | 4161 cap_col -= (int)(prev_ptr - line); |
625 | 4162 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4163 nochange); | |
348 | 4164 word_end = v + len; |
301 | 4165 |
4166 /* In Insert mode only highlight a word that | |
4167 * doesn't touch the cursor. */ | |
534 | 4168 if (spell_hlf != HLF_COUNT |
301 | 4169 && (State & INSERT) != 0 |
4170 && wp->w_cursor.lnum == lnum | |
4171 && wp->w_cursor.col >= | |
4172 (colnr_T)(prev_ptr - line) | |
4173 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4174 { |
534 | 4175 spell_hlf = HLF_COUNT; |
301 | 4176 spell_redraw_lnum = lnum; |
221 | 4177 } |
348 | 4178 |
534 | 4179 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4180 && (p - nextline) + len > nextline_idx) |
4181 { | |
4182 /* Remember that the good word continues at the | |
4183 * start of the next line. */ | |
4184 checked_lnum = lnum + 1; | |
835 | 4185 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4186 } |
386 | 4187 |
534 | 4188 /* Turn index into actual attributes. */ |
4189 if (spell_hlf != HLF_COUNT) | |
4190 spell_attr = highlight_attr[spell_hlf]; | |
4191 | |
386 | 4192 if (cap_col > 0) |
4193 { | |
4194 if (p != prev_ptr | |
4195 && (p - nextline) + cap_col >= nextline_idx) | |
4196 { | |
4197 /* Remember that the word in the next line | |
4198 * must start with a capital. */ | |
4199 capcol_lnum = lnum + 1; | |
835 | 4200 cap_col = (int)((p - nextline) + cap_col |
4201 - nextline_idx); | |
386 | 4202 } |
4203 else | |
4204 /* Compute the actual column. */ | |
835 | 4205 cap_col += (int)(prev_ptr - line); |
386 | 4206 } |
221 | 4207 } |
4208 } | |
4209 if (spell_attr != 0) | |
348 | 4210 { |
674 | 4211 if (!attr_pri) |
348 | 4212 char_attr = hl_combine_attr(char_attr, spell_attr); |
4213 else | |
4214 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4215 } | |
7 | 4216 #endif |
4217 #ifdef FEAT_LINEBREAK | |
4218 /* | |
221 | 4219 * Found last space before word: check for line break. |
7 | 4220 */ |
4221 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4222 && !wp->w_p_list) |
7 | 4223 { |
4224 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4225 # ifdef FEAT_MBYTE | |
4226 has_mbyte ? mb_l : | |
4227 # endif | |
4228 1), (colnr_T)vcol, NULL) - 1; | |
4229 c_extra = ' '; | |
4230 if (vim_iswhite(c)) | |
4231 c = ' '; | |
4232 } | |
4233 #endif | |
4234 | |
4235 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4236 { | |
4237 c = lcs_trail; | |
674 | 4238 if (!attr_pri) |
7 | 4239 { |
4240 n_attr = 1; | |
4241 extra_attr = hl_attr(HLF_8); | |
4242 saved_attr2 = char_attr; /* save current attr */ | |
4243 } | |
4244 #ifdef FEAT_MBYTE | |
4245 mb_c = c; | |
4246 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4247 { | |
4248 mb_utf8 = TRUE; | |
714 | 4249 u8cc[0] = 0; |
819 | 4250 c = 0xc0; |
7 | 4251 } |
4252 else | |
4253 mb_utf8 = FALSE; | |
4254 #endif | |
4255 } | |
4256 } | |
4257 | |
4258 /* | |
4259 * Handling of non-printable characters. | |
4260 */ | |
819 | 4261 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4262 { |
4263 /* | |
4264 * when getting a character from the file, we may have to | |
4265 * turn it into something else on the way to putting it | |
4266 * into "ScreenLines". | |
4267 */ | |
4268 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4269 { | |
4270 /* tab amount depends on current column */ | |
4271 n_extra = (int)wp->w_buffer->b_p_ts | |
3004 | 4272 - VCOL_HLC % (int)wp->w_buffer->b_p_ts - 1; |
7 | 4273 #ifdef FEAT_MBYTE |
4274 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4275 #endif | |
4276 if (wp->w_p_list) | |
4277 { | |
4278 c = lcs_tab1; | |
4279 c_extra = lcs_tab2; | |
4280 n_attr = n_extra + 1; | |
4281 extra_attr = hl_attr(HLF_8); | |
4282 saved_attr2 = char_attr; /* save current attr */ | |
4283 #ifdef FEAT_MBYTE | |
4284 mb_c = c; | |
4285 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4286 { | |
4287 mb_utf8 = TRUE; | |
714 | 4288 u8cc[0] = 0; |
819 | 4289 c = 0xc0; |
7 | 4290 } |
4291 #endif | |
4292 } | |
4293 else | |
4294 { | |
4295 c_extra = ' '; | |
4296 c = ' '; | |
4297 } | |
4298 } | |
36 | 4299 else if (c == NUL |
4300 && ((wp->w_p_list && lcs_eol > 0) | |
4301 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4302 && tocol > vcol | |
39 | 4303 #ifdef FEAT_VISUAL |
36 | 4304 && VIsual_mode != Ctrl_V |
39 | 4305 #endif |
36 | 4306 && ( |
4307 # ifdef FEAT_RIGHTLEFT | |
4308 wp->w_p_rl ? (col >= 0) : | |
4309 # endif | |
4310 (col < W_WIDTH(wp))) | |
4311 && !(noinvcur | |
1850 | 4312 && lnum == wp->w_cursor.lnum |
36 | 4313 && (colnr_T)vcol == wp->w_virtcol))) |
4314 && lcs_eol_one >= 0) | |
7 | 4315 { |
36 | 4316 /* Display a '$' after the line or highlight an extra |
4317 * character if the line break is included. */ | |
7 | 4318 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4319 /* For a diff line the highlighting continues after the | |
4320 * "$". */ | |
4321 if ( | |
4322 # ifdef FEAT_DIFF | |
534 | 4323 diff_hlf == (hlf_T)0 |
7 | 4324 # ifdef LINE_ATTR |
4325 && | |
4326 # endif | |
4327 # endif | |
4328 # ifdef LINE_ATTR | |
4329 line_attr == 0 | |
4330 # endif | |
4331 ) | |
4332 #endif | |
4333 { | |
4334 #ifdef FEAT_VIRTUALEDIT | |
4335 /* In virtualedit, visual selections may extend | |
4336 * beyond end of line. */ | |
4337 if (area_highlighting && virtual_active() | |
4338 && tocol != MAXCOL && vcol < tocol) | |
4339 n_extra = 0; | |
4340 else | |
4341 #endif | |
4342 { | |
4343 p_extra = at_end_str; | |
4344 n_extra = 1; | |
4345 c_extra = NUL; | |
4346 } | |
4347 } | |
36 | 4348 if (wp->w_p_list) |
4349 c = lcs_eol; | |
4350 else | |
4351 c = ' '; | |
7 | 4352 lcs_eol_one = -1; |
4353 --ptr; /* put it back at the NUL */ | |
674 | 4354 if (!attr_pri) |
7 | 4355 { |
4356 extra_attr = hl_attr(HLF_AT); | |
4357 n_attr = 1; | |
4358 } | |
4359 #ifdef FEAT_MBYTE | |
4360 mb_c = c; | |
4361 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4362 { | |
4363 mb_utf8 = TRUE; | |
714 | 4364 u8cc[0] = 0; |
819 | 4365 c = 0xc0; |
7 | 4366 } |
4367 else | |
4368 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4369 #endif | |
4370 } | |
4371 else if (c != NUL) | |
4372 { | |
4373 p_extra = transchar(c); | |
4374 #ifdef FEAT_RIGHTLEFT | |
4375 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4376 rl_mirror(p_extra); /* reverse "<12>" */ | |
4377 #endif | |
4378 n_extra = byte2cells(c) - 1; | |
4379 c_extra = NUL; | |
4380 c = *p_extra++; | |
674 | 4381 if (!attr_pri) |
7 | 4382 { |
4383 n_attr = n_extra + 1; | |
4384 extra_attr = hl_attr(HLF_8); | |
4385 saved_attr2 = char_attr; /* save current attr */ | |
4386 } | |
4387 #ifdef FEAT_MBYTE | |
4388 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4389 #endif | |
4390 } | |
4391 #ifdef FEAT_VIRTUALEDIT | |
4392 else if (VIsual_active | |
4393 && (VIsual_mode == Ctrl_V | |
4394 || VIsual_mode == 'v') | |
4395 && virtual_active() | |
4396 && tocol != MAXCOL | |
4397 && vcol < tocol | |
4398 && ( | |
4399 # ifdef FEAT_RIGHTLEFT | |
4400 wp->w_p_rl ? (col >= 0) : | |
4401 # endif | |
4402 (col < W_WIDTH(wp)))) | |
4403 { | |
4404 c = ' '; | |
4405 --ptr; /* put it back at the NUL */ | |
4406 } | |
4407 #endif | |
910 | 4408 #if defined(LINE_ATTR) |
7 | 4409 else if (( |
4410 # ifdef FEAT_DIFF | |
910 | 4411 diff_hlf != (hlf_T)0 || |
7 | 4412 # endif |
4413 line_attr != 0 | |
4414 ) && ( | |
4415 # ifdef FEAT_RIGHTLEFT | |
4416 wp->w_p_rl ? (col >= 0) : | |
4417 # endif | |
2553
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4418 (col |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4419 # ifdef FEAT_CONCEAL |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4420 - boguscols |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4421 # endif |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4422 < W_WIDTH(wp)))) |
7 | 4423 { |
4424 /* Highlight until the right side of the window */ | |
4425 c = ' '; | |
4426 --ptr; /* put it back at the NUL */ | |
867 | 4427 |
4428 /* Remember we do the char for line highlighting. */ | |
4429 ++did_line_attr; | |
4430 | |
4431 /* don't do search HL for the rest of the line */ | |
4432 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4433 char_attr = line_attr; | |
7 | 4434 # ifdef FEAT_DIFF |
4435 if (diff_hlf == HLF_TXD) | |
4436 { | |
4437 diff_hlf = HLF_CHD; | |
4438 if (attr == 0 || char_attr != attr) | |
4439 char_attr = hl_attr(diff_hlf); | |
4440 } | |
4441 # endif | |
4442 } | |
4443 #endif | |
4444 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4445 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4446 #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
|
4447 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
|
4448 && (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
|
4449 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
|
4450 && (syntax_flags & HL_CONCEAL) != 0 |
2400
e6f1424dd66a
Let 'v' flag in 'concealcursor' apply to all lines in the Visual area.
Bram Moolenaar <bram@vim.org>
parents:
2393
diff
changeset
|
4451 && !(lnum_in_visual_area |
e6f1424dd66a
Let 'v' flag in 'concealcursor' apply to all lines in the Visual area.
Bram Moolenaar <bram@vim.org>
parents:
2393
diff
changeset
|
4452 && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
2250
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 char_attr = conceal_attr; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
4455 if (prev_syntax_id != syntax_seqnr |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4456 && (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
|
4457 && 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
|
4458 { |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4459 /* 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
|
4460 * character. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4461 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4462 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4463 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4464 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4465 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4466 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4467 |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2382
diff
changeset
|
4468 prev_syntax_id = syntax_seqnr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4469 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4470 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4471 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4472 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4473 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
|
4474 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4475 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4476 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4477 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4478 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4479 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4480 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4481 else |
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 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4485 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4486 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4487 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4488 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4489 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4490 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4491 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4492 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4493 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4494 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4495 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4496 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4497 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4498 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4499 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4500 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4501 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4502 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4503 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4504 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4505 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
|
4506 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4507 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4508 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4509 { |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4510 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
|
4511 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4512 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4513 #endif /* FEAT_CONCEAL */ |
7 | 4514 } |
4515 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4516 #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
|
4517 /* 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
|
4518 * the cursor column when we reach its position. */ |
2381
17bbb52ae218
Another conceal fix: cursor in wrong column when 'number' set.
Bram Moolenaar <bram@vim.org>
parents:
2380
diff
changeset
|
4519 if (!did_wcol && draw_state == WL_LINE |
17bbb52ae218
Another conceal fix: cursor in wrong column when 'number' set.
Bram Moolenaar <bram@vim.org>
parents:
2380
diff
changeset
|
4520 && wp == curwin && lnum == wp->w_cursor.lnum |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4521 && 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
|
4522 && (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
|
4523 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4524 wp->w_wcol = col - boguscols; |
2393
210a5605e126
Fix for cursor position in wrapped line with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
4525 wp->w_wrow = row; |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4526 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
|
4527 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4528 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4529 |
7 | 4530 /* Don't override visual selection highlighting. */ |
4531 if (n_attr > 0 | |
4532 && draw_state == WL_LINE | |
674 | 4533 && !attr_pri) |
7 | 4534 char_attr = extra_attr; |
4535 | |
42 | 4536 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4537 /* XIM don't send preedit_start and preedit_end, but they send |
4538 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4539 * im_is_preediting() here. */ | |
4540 if (xic != NULL | |
1850 | 4541 && lnum == wp->w_cursor.lnum |
7 | 4542 && (State & INSERT) |
4543 && !p_imdisable | |
4544 && im_is_preediting() | |
4545 && draw_state == WL_LINE) | |
4546 { | |
4547 colnr_T tcol; | |
4548 | |
4549 if (preedit_end_col == MAXCOL) | |
1850 | 4550 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4551 else |
4552 tcol = preedit_end_col; | |
4553 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4554 { | |
4555 if (feedback_old_attr < 0) | |
4556 { | |
4557 feedback_col = 0; | |
4558 feedback_old_attr = char_attr; | |
4559 } | |
4560 char_attr = im_get_feedback_attr(feedback_col); | |
4561 if (char_attr < 0) | |
4562 char_attr = feedback_old_attr; | |
4563 feedback_col++; | |
4564 } | |
4565 else if (feedback_old_attr >= 0) | |
4566 { | |
4567 char_attr = feedback_old_attr; | |
4568 feedback_old_attr = -1; | |
4569 feedback_col = 0; | |
4570 } | |
4571 } | |
4572 #endif | |
4573 /* | |
4574 * Handle the case where we are in column 0 but not on the first | |
4575 * character of the line and the user wants us to show us a | |
4576 * special character (via 'listchars' option "precedes:<char>". | |
4577 */ | |
4578 if (lcs_prec_todo != NUL | |
4579 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4580 #ifdef FEAT_DIFF | |
4581 && filler_todo <= 0 | |
4582 #endif | |
4583 && draw_state > WL_NR | |
4584 && c != NUL) | |
4585 { | |
4586 c = lcs_prec; | |
4587 lcs_prec_todo = NUL; | |
4588 #ifdef FEAT_MBYTE | |
3586 | 4589 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
4590 { | |
4591 /* Double-width character being overwritten by the "precedes" | |
4592 * character, need to fill up half the character. */ | |
4593 c_extra = MB_FILLER_CHAR; | |
4594 n_extra = 1; | |
4595 n_attr = 2; | |
4596 extra_attr = hl_attr(HLF_AT); | |
4597 } | |
7 | 4598 mb_c = c; |
4599 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4600 { | |
4601 mb_utf8 = TRUE; | |
714 | 4602 u8cc[0] = 0; |
819 | 4603 c = 0xc0; |
7 | 4604 } |
4605 else | |
4606 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4607 #endif | |
674 | 4608 if (!attr_pri) |
7 | 4609 { |
4610 saved_attr3 = char_attr; /* save current attr */ | |
4611 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4612 n_attr3 = 1; | |
4613 } | |
4614 } | |
4615 | |
4616 /* | |
867 | 4617 * At end of the text line or just after the last character. |
7 | 4618 */ |
867 | 4619 if (c == NUL |
910 | 4620 #if defined(LINE_ATTR) |
867 | 4621 || did_line_attr == 1 |
4622 #endif | |
4623 ) | |
4624 { | |
4625 #ifdef FEAT_SEARCH_EXTRA | |
4626 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4627 |
4628 /* we're not really at that column when skipping some text */ | |
1439 | 4629 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4630 ++prevcol; |
867 | 4631 #endif |
4632 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4633 /* Invert at least one char, used for Visual and empty line or |
7 | 4634 * highlight match at end of line. If it's beyond the last |
4635 * char on the screen, just overwrite that one (tricky!) Not | |
4636 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4637 #ifdef FEAT_SEARCH_EXTRA |
4638 prevcol_hl_flag = FALSE; | |
4639 if (prevcol == (long)search_hl.startcol) | |
4640 prevcol_hl_flag = TRUE; | |
4641 else | |
4642 { | |
4643 cur = wp->w_match_head; | |
4644 while (cur != NULL) | |
4645 { | |
4646 if (prevcol == (long)cur->hl.startcol) | |
4647 { | |
4648 prevcol_hl_flag = TRUE; | |
4649 break; | |
4650 } | |
4651 cur = cur->next; | |
4652 } | |
4653 } | |
4654 #endif | |
7 | 4655 if (lcs_eol == lcs_eol_one |
1850 | 4656 && ((area_attr != 0 && vcol == fromcol |
4657 #ifdef FEAT_VISUAL | |
4658 && (VIsual_mode != Ctrl_V | |
4659 || lnum == VIsual.lnum | |
4660 || lnum == curwin->w_cursor.lnum) | |
4661 #endif | |
4662 && c == NUL) | |
7 | 4663 #ifdef FEAT_SEARCH_EXTRA |
4664 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4665 || (prevcol_hl_flag == TRUE |
910 | 4666 # if defined(LINE_ATTR) |
867 | 4667 && did_line_attr <= 1 |
4668 # endif | |
4669 ) | |
7 | 4670 #endif |
4671 )) | |
4672 { | |
4673 int n = 0; | |
4674 | |
4675 #ifdef FEAT_RIGHTLEFT | |
4676 if (wp->w_p_rl) | |
4677 { | |
4678 if (col < 0) | |
4679 n = 1; | |
4680 } | |
4681 else | |
4682 #endif | |
4683 { | |
4684 if (col >= W_WIDTH(wp)) | |
4685 n = -1; | |
4686 } | |
4687 if (n != 0) | |
4688 { | |
4689 /* At the window boundary, highlight the last character | |
4690 * instead (better than nothing). */ | |
4691 off += n; | |
4692 col += n; | |
4693 } | |
4694 else | |
4695 { | |
4696 /* Add a blank character to highlight. */ | |
4697 ScreenLines[off] = ' '; | |
4698 #ifdef FEAT_MBYTE | |
4699 if (enc_utf8) | |
4700 ScreenLinesUC[off] = 0; | |
4701 #endif | |
4702 } | |
4703 #ifdef FEAT_SEARCH_EXTRA | |
4704 if (area_attr == 0) | |
4705 { | |
1326 | 4706 /* Use attributes from match with highest priority among |
4707 * 'search_hl' and the match list. */ | |
4708 char_attr = search_hl.attr; | |
4709 cur = wp->w_match_head; | |
4710 shl_flag = FALSE; | |
4711 while (cur != NULL || shl_flag == FALSE) | |
699 | 4712 { |
1326 | 4713 if (shl_flag == FALSE |
4714 && ((cur != NULL | |
4715 && cur->priority > SEARCH_HL_PRIORITY) | |
4716 || cur == NULL)) | |
699 | 4717 { |
1326 | 4718 shl = &search_hl; |
4719 shl_flag = TRUE; | |
699 | 4720 } |
1326 | 4721 else |
4722 shl = &cur->hl; | |
4723 if ((ptr - line) - 1 == (long)shl->startcol) | |
4724 char_attr = shl->attr; | |
4725 if (shl != &search_hl && cur != NULL) | |
4726 cur = cur->next; | |
699 | 4727 } |
7 | 4728 } |
4729 #endif | |
4730 ScreenAttrs[off] = char_attr; | |
4731 #ifdef FEAT_RIGHTLEFT | |
4732 if (wp->w_p_rl) | |
1437 | 4733 { |
7 | 4734 --col; |
1437 | 4735 --off; |
4736 } | |
7 | 4737 else |
4738 #endif | |
1437 | 4739 { |
7 | 4740 ++col; |
1437 | 4741 ++off; |
4742 } | |
743 | 4743 ++vcol; |
1437 | 4744 #ifdef FEAT_SYN_HL |
4745 eol_hl_off = 1; | |
4746 #endif | |
743 | 4747 } |
867 | 4748 } |
4749 | |
4750 /* | |
4751 * At end of the text line. | |
4752 */ | |
4753 if (c == NUL) | |
4754 { | |
743 | 4755 #ifdef FEAT_SYN_HL |
1850 | 4756 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4757 && lnum == wp->w_cursor.lnum) | |
1437 | 4758 { |
4759 /* highlight last char after line */ | |
4760 --col; | |
4761 --off; | |
4762 --vcol; | |
4763 } | |
4764 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4765 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4766 if (wp->w_p_wrap) |
4767 v = wp->w_skipcol; | |
4768 else | |
4769 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4770 |
820 | 4771 /* check if line ends before left margin */ |
4772 if (vcol < v + col - win_col_off(wp)) | |
4773 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
|
4774 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4775 /* 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
|
4776 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4777 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4778 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4779 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4780 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4781 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4782 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
|
4783 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4784 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4785 && (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
|
4786 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4787 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
|
4788 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4789 || draw_color_col) |
743 | 4790 # ifdef FEAT_RIGHTLEFT |
4791 && !wp->w_p_rl | |
4792 # endif | |
4793 ) | |
4794 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4795 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4796 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4797 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4798 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4799 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4800 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4801 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4802 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
|
4803 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4804 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4805 |
743 | 4806 while (col < W_WIDTH(wp)) |
4807 { | |
4808 ScreenLines[off] = ' '; | |
4809 #ifdef FEAT_MBYTE | |
4810 if (enc_utf8) | |
4811 ScreenLinesUC[off] = 0; | |
4812 #endif | |
4813 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4814 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4815 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
|
4816 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4817 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4818 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
|
4819 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
|
4820 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
|
4821 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4822 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4823 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4824 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4825 if (VCOL_HLC >= rightmost_vcol) |
743 | 4826 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4827 |
743 | 4828 ++vcol; |
4829 } | |
4830 } | |
4831 #endif | |
7 | 4832 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4833 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
|
4834 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4835 row++; |
4836 | |
4837 /* | |
4838 * Update w_cline_height and w_cline_folded if the cursor line was | |
4839 * updated (saves a call to plines() later). | |
4840 */ | |
4841 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4842 { | |
4843 curwin->w_cline_row = startrow; | |
4844 curwin->w_cline_height = row - startrow; | |
4845 #ifdef FEAT_FOLDING | |
4846 curwin->w_cline_folded = FALSE; | |
4847 #endif | |
4848 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4849 } | |
4850 | |
4851 break; | |
4852 } | |
4853 | |
4854 /* line continues beyond line end */ | |
4855 if (lcs_ext | |
4856 && !wp->w_p_wrap | |
4857 #ifdef FEAT_DIFF | |
4858 && filler_todo <= 0 | |
4859 #endif | |
4860 && ( | |
4861 #ifdef FEAT_RIGHTLEFT | |
4862 wp->w_p_rl ? col == 0 : | |
4863 #endif | |
4864 col == W_WIDTH(wp) - 1) | |
4865 && (*ptr != NUL | |
1555 | 4866 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4867 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4868 { | |
4869 c = lcs_ext; | |
4870 char_attr = hl_attr(HLF_AT); | |
4871 #ifdef FEAT_MBYTE | |
4872 mb_c = c; | |
4873 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4874 { | |
4875 mb_utf8 = TRUE; | |
714 | 4876 u8cc[0] = 0; |
819 | 4877 c = 0xc0; |
7 | 4878 } |
4879 else | |
4880 mb_utf8 = FALSE; | |
4881 #endif | |
4882 } | |
4883 | |
743 | 4884 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4885 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4886 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4887 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
|
4888 |
743 | 4889 /* 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
|
4890 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4891 * 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
|
4892 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4893 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4894 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
|
4895 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4896 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
|
4897 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4898 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4899 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4900 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
|
4901 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4902 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
|
4903 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4904 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4905 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
|
4906 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4907 } |
743 | 4908 #endif |
4909 | |
7 | 4910 /* |
4911 * Store character to be displayed. | |
4912 * Skip characters that are left of the screen for 'nowrap'. | |
4913 */ | |
4914 vcol_prev = vcol; | |
4915 if (draw_state < WL_LINE || n_skip <= 0) | |
4916 { | |
4917 /* | |
4918 * Store the character. | |
4919 */ | |
4920 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4921 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4922 { | |
4923 /* A double-wide character is: put first halve in left cell. */ | |
4924 --off; | |
4925 --col; | |
4926 } | |
4927 #endif | |
4928 ScreenLines[off] = c; | |
4929 #ifdef FEAT_MBYTE | |
4930 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4931 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4932 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4933 ScreenLines[off] = 0x8e; |
7 | 4934 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4935 } |
7 | 4936 else if (enc_utf8) |
4937 { | |
4938 if (mb_utf8) | |
4939 { | |
1326 | 4940 int i; |
4941 | |
7 | 4942 ScreenLinesUC[off] = mb_c; |
819 | 4943 if ((c & 0xff) == 0) |
4944 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4945 for (i = 0; i < Screen_mco; ++i) |
4946 { | |
4947 ScreenLinesC[i][off] = u8cc[i]; | |
4948 if (u8cc[i] == 0) | |
4949 break; | |
4950 } | |
7 | 4951 } |
4952 else | |
4953 ScreenLinesUC[off] = 0; | |
4954 } | |
4955 if (multi_attr) | |
4956 { | |
4957 ScreenAttrs[off] = multi_attr; | |
4958 multi_attr = 0; | |
4959 } | |
4960 else | |
4961 #endif | |
4962 ScreenAttrs[off] = char_attr; | |
4963 | |
4964 #ifdef FEAT_MBYTE | |
4965 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4966 { | |
4967 /* Need to fill two screen columns. */ | |
4968 ++off; | |
4969 ++col; | |
4970 if (enc_utf8) | |
4971 /* UTF-8: Put a 0 in the second screen char. */ | |
4972 ScreenLines[off] = 0; | |
4973 else | |
4974 /* DBCS: Put second byte in the second screen char. */ | |
4975 ScreenLines[off] = mb_c & 0xff; | |
4976 ++vcol; | |
4977 /* When "tocol" is halfway a character, set it to the end of | |
4978 * the character, otherwise highlighting won't stop. */ | |
4979 if (tocol == vcol) | |
4980 ++tocol; | |
4981 #ifdef FEAT_RIGHTLEFT | |
4982 if (wp->w_p_rl) | |
4983 { | |
4984 /* now it's time to backup one cell */ | |
4985 --off; | |
4986 --col; | |
4987 } | |
4988 #endif | |
4989 } | |
4990 #endif | |
4991 #ifdef FEAT_RIGHTLEFT | |
4992 if (wp->w_p_rl) | |
4993 { | |
4994 --off; | |
4995 --col; | |
4996 } | |
4997 else | |
4998 #endif | |
4999 { | |
5000 ++off; | |
5001 ++col; | |
5002 } | |
5003 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5004 #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
|
5005 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
|
5006 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5007 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5008 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5009 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
5010 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5011 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5012 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5013 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5014 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5015 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5016 * 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
|
5017 * 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
|
5018 * 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
|
5019 * 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
|
5020 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5021 * 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
|
5022 * 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
|
5023 * 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
|
5024 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5025 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5026 if (n_extra > 0) |
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 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5029 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5030 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5031 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5032 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5033 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5034 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5035 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5036 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5037 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5038 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5039 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5040 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5041 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5043 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5044 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5045 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5046 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5047 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
|
5048 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5049 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5050 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5051 if (wp->w_p_rl) |
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 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5054 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5055 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5056 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5057 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5058 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5059 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5060 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5061 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5062 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5063 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5064 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5065 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5066 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5067 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5068 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5069 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5070 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5071 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5072 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5073 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5074 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5075 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5076 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5077 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5078 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5079 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5080 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5081 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5082 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5083 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5084 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5085 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5086 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5087 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5088 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5089 #endif /* FEAT_CONCEAL */ |
7 | 5090 else |
5091 --n_skip; | |
5092 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5093 /* 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
|
5094 * column. */ |
1849 | 5095 if (draw_state > WL_NR |
7 | 5096 #ifdef FEAT_DIFF |
5097 && filler_todo <= 0 | |
5098 #endif | |
5099 ) | |
5100 ++vcol; | |
5101 | |
743 | 5102 #ifdef FEAT_SYN_HL |
5103 if (vcol_save_attr >= 0) | |
5104 char_attr = vcol_save_attr; | |
5105 #endif | |
5106 | |
7 | 5107 /* restore attributes after "predeces" in 'listchars' */ |
5108 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5109 char_attr = saved_attr3; | |
5110 | |
5111 /* restore attributes after last 'listchars' or 'number' char */ | |
5112 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5113 char_attr = saved_attr2; | |
5114 | |
5115 /* | |
5116 * At end of screen line and there is more to come: Display the line | |
1378 | 5117 * so far. If there is no more to display it is caught above. |
7 | 5118 */ |
5119 if (( | |
5120 #ifdef FEAT_RIGHTLEFT | |
5121 wp->w_p_rl ? (col < 0) : | |
5122 #endif | |
5123 (col >= W_WIDTH(wp))) | |
5124 && (*ptr != NUL | |
5125 #ifdef FEAT_DIFF | |
5126 || filler_todo > 0 | |
5127 #endif | |
2724 | 5128 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
7 | 5129 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
5130 ) | |
5131 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5132 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5133 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
|
5134 (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
|
5135 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5136 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5137 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
|
5138 (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
|
5139 #endif |
7 | 5140 ++row; |
5141 ++screen_row; | |
5142 | |
5143 /* When not wrapping and finished diff lines, or when displayed | |
5144 * '$' and highlighting until last column, break here. */ | |
5145 if ((!wp->w_p_wrap | |
5146 #ifdef FEAT_DIFF | |
5147 && filler_todo <= 0 | |
5148 #endif | |
5149 ) || lcs_eol_one == -1) | |
5150 break; | |
5151 | |
5152 /* When the window is too narrow draw all "@" lines. */ | |
5153 if (draw_state != WL_LINE | |
5154 #ifdef FEAT_DIFF | |
5155 && filler_todo <= 0 | |
5156 #endif | |
5157 ) | |
5158 { | |
5159 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5160 #ifdef FEAT_VERTSPLIT | |
5161 draw_vsep_win(wp, row); | |
5162 #endif | |
5163 row = endrow; | |
5164 } | |
5165 | |
5166 /* When line got too long for screen break here. */ | |
5167 if (row == endrow) | |
5168 { | |
5169 ++row; | |
5170 break; | |
5171 } | |
5172 | |
5173 if (screen_cur_row == screen_row - 1 | |
5174 #ifdef FEAT_DIFF | |
5175 && filler_todo <= 0 | |
5176 #endif | |
5177 && W_WIDTH(wp) == Columns) | |
5178 { | |
5179 /* Remember that the line wraps, used for modeless copy. */ | |
5180 LineWraps[screen_row - 1] = TRUE; | |
5181 | |
5182 /* | |
5183 * Special trick to make copy/paste of wrapped lines work with | |
5184 * xterm/screen: write an extra character beyond the end of | |
5185 * the line. This will work with all terminal types | |
5186 * (regardless of the xn,am settings). | |
5187 * Only do this on a fast tty. | |
5188 * Only do this if the cursor is on the current line | |
5189 * (something has been written in it). | |
5190 * Don't do this for the GUI. | |
5191 * Don't do this for double-width characters. | |
5192 * Don't do this for a window not at the right screen border. | |
5193 */ | |
5194 if (p_tf | |
5195 #ifdef FEAT_GUI | |
5196 && !gui.in_use | |
5197 #endif | |
5198 #ifdef FEAT_MBYTE | |
5199 && !(has_mbyte | |
1378 | 5200 && ((*mb_off2cells)(LineOffset[screen_row], |
5201 LineOffset[screen_row] + screen_Columns) | |
5202 == 2 | |
7 | 5203 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5204 + (int)Columns - 2, |
5205 LineOffset[screen_row] + screen_Columns) | |
5206 == 2)) | |
7 | 5207 #endif |
5208 ) | |
5209 { | |
5210 /* First make sure we are at the end of the screen line, | |
5211 * then output the same character again to let the | |
5212 * terminal know about the wrap. If the terminal doesn't | |
5213 * auto-wrap, we overwrite the character. */ | |
5214 if (screen_cur_col != W_WIDTH(wp)) | |
5215 screen_char(LineOffset[screen_row - 1] | |
5216 + (unsigned)Columns - 1, | |
5217 screen_row - 1, (int)(Columns - 1)); | |
5218 | |
5219 #ifdef FEAT_MBYTE | |
5220 /* When there is a multi-byte character, just output a | |
5221 * space to keep it simple. */ | |
148 | 5222 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5223 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5224 out_char(' '); |
5225 else | |
5226 #endif | |
5227 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5228 + (Columns - 1)]); | |
5229 /* force a redraw of the first char on the next line */ | |
5230 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5231 screen_start(); /* don't know where cursor is now */ | |
5232 } | |
5233 } | |
5234 | |
5235 col = 0; | |
5236 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5237 #ifdef FEAT_RIGHTLEFT | |
5238 if (wp->w_p_rl) | |
5239 { | |
5240 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5241 off += col; | |
5242 } | |
5243 #endif | |
5244 | |
5245 /* reset the drawing state for the start of a wrapped line */ | |
5246 draw_state = WL_START; | |
5247 saved_n_extra = n_extra; | |
5248 saved_p_extra = p_extra; | |
5249 saved_c_extra = c_extra; | |
5250 saved_char_attr = char_attr; | |
5251 n_extra = 0; | |
5252 lcs_prec_todo = lcs_prec; | |
5253 #ifdef FEAT_LINEBREAK | |
5254 # ifdef FEAT_DIFF | |
5255 if (filler_todo <= 0) | |
5256 # endif | |
5257 need_showbreak = TRUE; | |
5258 #endif | |
5259 #ifdef FEAT_DIFF | |
5260 --filler_todo; | |
5261 /* When the filler lines are actually below the last line of the | |
5262 * file, don't draw the line itself, break here. */ | |
5263 if (filler_todo == 0 && wp->w_botfill) | |
5264 break; | |
5265 #endif | |
5266 } | |
5267 | |
5268 } /* for every character in the line */ | |
5269 | |
743 | 5270 #ifdef FEAT_SPELL |
386 | 5271 /* After an empty line check first word for capital. */ |
5272 if (*skipwhite(line) == NUL) | |
5273 { | |
5274 capcol_lnum = lnum + 1; | |
5275 cap_col = 0; | |
5276 } | |
5277 #endif | |
5278 | |
7 | 5279 return row; |
5280 } | |
5281 | |
714 | 5282 #ifdef FEAT_MBYTE |
5283 static int comp_char_differs __ARGS((int, int)); | |
5284 | |
5285 /* | |
5286 * 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
|
5287 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5288 */ |
5289 static int | |
5290 comp_char_differs(off_from, off_to) | |
5291 int off_from; | |
5292 int off_to; | |
5293 { | |
5294 int i; | |
5295 | |
5296 for (i = 0; i < Screen_mco; ++i) | |
5297 { | |
5298 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5299 return TRUE; | |
5300 if (ScreenLinesC[i][off_from] == 0) | |
5301 break; | |
5302 } | |
5303 return FALSE; | |
5304 } | |
5305 #endif | |
5306 | |
7 | 5307 /* |
5308 * Check whether the given character needs redrawing: | |
5309 * - the (first byte of the) character is different | |
5310 * - the attributes are different | |
5311 * - the character is multi-byte and the next byte is different | |
1616 | 5312 * - the character is two cells wide and the second cell differs. |
7 | 5313 */ |
5314 static int | |
5315 char_needs_redraw(off_from, off_to, cols) | |
5316 int off_from; | |
5317 int off_to; | |
5318 int cols; | |
5319 { | |
5320 if (cols > 0 | |
5321 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5322 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5323 | |
5324 #ifdef FEAT_MBYTE | |
5325 || (enc_dbcs != 0 | |
5326 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5327 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5328 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5329 : (cols > 1 && ScreenLines[off_from + 1] | |
5330 != ScreenLines[off_to + 1]))) | |
5331 || (enc_utf8 | |
5332 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5333 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5334 && comp_char_differs(off_from, off_to)) |
5335 || (cols > 1 && ScreenLines[off_from + 1] | |
5336 != ScreenLines[off_to + 1]))) | |
7 | 5337 #endif |
5338 )) | |
5339 return TRUE; | |
5340 return FALSE; | |
5341 } | |
5342 | |
5343 /* | |
5344 * Move one "cooked" screen line to the screen, but only the characters that | |
5345 * have actually changed. Handle insert/delete character. | |
5346 * "coloff" gives the first column on the screen for this line. | |
5347 * "endcol" gives the columns where valid characters are. | |
5348 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5349 * needs to be cleared, negative otherwise. | |
5350 * "rlflag" is TRUE in a rightleft window: | |
5351 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5352 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5353 */ | |
5354 static void | |
5355 screen_line(row, coloff, endcol, clear_width | |
5356 #ifdef FEAT_RIGHTLEFT | |
5357 , rlflag | |
5358 #endif | |
5359 ) | |
5360 int row; | |
5361 int coloff; | |
5362 int endcol; | |
5363 int clear_width; | |
5364 #ifdef FEAT_RIGHTLEFT | |
5365 int rlflag; | |
5366 #endif | |
5367 { | |
5368 unsigned off_from; | |
5369 unsigned off_to; | |
1378 | 5370 #ifdef FEAT_MBYTE |
5371 unsigned max_off_from; | |
5372 unsigned max_off_to; | |
5373 #endif | |
7 | 5374 int col = 0; |
5375 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5376 int hl; | |
5377 #endif | |
5378 int force = FALSE; /* force update rest of the line */ | |
5379 int redraw_this /* bool: does character need redraw? */ | |
5380 #ifdef FEAT_GUI | |
5381 = TRUE /* For GUI when while-loop empty */ | |
5382 #endif | |
5383 ; | |
5384 int redraw_next; /* redraw_this for next character */ | |
5385 #ifdef FEAT_MBYTE | |
5386 int clear_next = FALSE; | |
5387 int char_cells; /* 1: normal char */ | |
5388 /* 2: occupies two display cells */ | |
5389 # define CHAR_CELLS char_cells | |
5390 #else | |
5391 # define CHAR_CELLS 1 | |
5392 #endif | |
5393 | |
3413 | 5394 /* Check for illegal row and col, just in case. */ |
5395 if (row >= Rows) | |
5396 row = Rows - 1; | |
5397 if (endcol > Columns) | |
5398 endcol = Columns; | |
5399 | |
7 | 5400 # ifdef FEAT_CLIPBOARD |
5401 clip_may_clear_selection(row, row); | |
5402 # endif | |
5403 | |
5404 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5405 off_to = LineOffset[row] + coloff; | |
1378 | 5406 #ifdef FEAT_MBYTE |
5407 max_off_from = off_from + screen_Columns; | |
5408 max_off_to = LineOffset[row] + screen_Columns; | |
5409 #endif | |
7 | 5410 |
5411 #ifdef FEAT_RIGHTLEFT | |
5412 if (rlflag) | |
5413 { | |
5414 /* Clear rest first, because it's left of the text. */ | |
5415 if (clear_width > 0) | |
5416 { | |
5417 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5418 && ScreenAttrs[off_to] == 0 | |
5419 # ifdef FEAT_MBYTE | |
5420 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5421 # endif | |
5422 ) | |
5423 { | |
5424 ++off_to; | |
5425 ++col; | |
5426 } | |
5427 if (col <= endcol) | |
5428 screen_fill(row, row + 1, col + coloff, | |
5429 endcol + coloff + 1, ' ', ' ', 0); | |
5430 } | |
5431 col = endcol + 1; | |
5432 off_to = LineOffset[row] + col + coloff; | |
5433 off_from += col; | |
5434 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5435 } | |
5436 #endif /* FEAT_RIGHTLEFT */ | |
5437 | |
5438 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5439 | |
5440 while (col < endcol) | |
5441 { | |
5442 #ifdef FEAT_MBYTE | |
5443 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5444 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5445 else |
5446 char_cells = 1; | |
5447 #endif | |
5448 | |
5449 redraw_this = redraw_next; | |
5450 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5451 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5452 | |
5453 #ifdef FEAT_GUI | |
5454 /* If the next character was bold, then redraw the current character to | |
5455 * remove any pixels that might have spilt over into us. This only | |
5456 * happens in the GUI. | |
5457 */ | |
5458 if (redraw_next && gui.in_use) | |
5459 { | |
5460 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5461 if (hl > HL_ALL) |
5462 hl = syn_attr2attr(hl); | |
5463 if (hl & HL_BOLD) | |
7 | 5464 redraw_this = TRUE; |
5465 } | |
5466 #endif | |
5467 | |
5468 if (redraw_this) | |
5469 { | |
5470 /* | |
5471 * Special handling when 'xs' termcap flag set (hpterm): | |
5472 * Attributes for characters are stored at the position where the | |
5473 * cursor is when writing the highlighting code. The | |
5474 * start-highlighting code must be written with the cursor on the | |
5475 * first highlighted character. The stop-highlighting code must | |
5476 * be written with the cursor just after the last highlighted | |
5477 * character. | |
5478 * Overwriting a character doesn't remove it's highlighting. Need | |
5479 * to clear the rest of the line, and force redrawing it | |
5480 * completely. | |
5481 */ | |
5482 if ( p_wiv | |
5483 && !force | |
5484 #ifdef FEAT_GUI | |
5485 && !gui.in_use | |
5486 #endif | |
5487 && ScreenAttrs[off_to] != 0 | |
5488 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5489 { | |
5490 /* | |
5491 * Need to remove highlighting attributes here. | |
5492 */ | |
5493 windgoto(row, col + coloff); | |
5494 out_str(T_CE); /* clear rest of this screen line */ | |
5495 screen_start(); /* don't know where cursor is now */ | |
5496 force = TRUE; /* force redraw of rest of the line */ | |
5497 redraw_next = TRUE; /* or else next char would miss out */ | |
5498 | |
5499 /* | |
5500 * If the previous character was highlighted, need to stop | |
5501 * highlighting at this character. | |
5502 */ | |
5503 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5504 { | |
5505 screen_attr = ScreenAttrs[off_to - 1]; | |
5506 term_windgoto(row, col + coloff); | |
5507 screen_stop_highlight(); | |
5508 } | |
5509 else | |
5510 screen_attr = 0; /* highlighting has stopped */ | |
5511 } | |
5512 #ifdef FEAT_MBYTE | |
5513 if (enc_dbcs != 0) | |
5514 { | |
5515 /* Check if overwriting a double-byte with a single-byte or | |
5516 * the other way around requires another character to be | |
5517 * redrawn. For UTF-8 this isn't needed, because comparing | |
5518 * ScreenLinesUC[] is sufficient. */ | |
5519 if (char_cells == 1 | |
5520 && col + 1 < endcol | |
1378 | 5521 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5522 { |
5523 /* Writing a single-cell character over a double-cell | |
5524 * character: need to redraw the next cell. */ | |
5525 ScreenLines[off_to + 1] = 0; | |
5526 redraw_next = TRUE; | |
5527 } | |
5528 else if (char_cells == 2 | |
5529 && col + 2 < endcol | |
1378 | 5530 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5531 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5532 { |
5533 /* Writing the second half of a double-cell character over | |
5534 * a double-cell character: need to redraw the second | |
5535 * cell. */ | |
5536 ScreenLines[off_to + 2] = 0; | |
5537 redraw_next = TRUE; | |
5538 } | |
5539 | |
5540 if (enc_dbcs == DBCS_JPNU) | |
5541 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5542 } | |
5543 /* When writing a single-width character over a double-width | |
5544 * character and at the end of the redrawn text, need to clear out | |
5545 * the right halve of the old character. | |
5546 * Also required when writing the right halve of a double-width | |
5547 * char over the left halve of an existing one. */ | |
5548 if (has_mbyte && col + char_cells == endcol | |
5549 && ((char_cells == 1 | |
1378 | 5550 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5551 || (char_cells == 2 |
1378 | 5552 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5553 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5554 clear_next = TRUE; |
5555 #endif | |
5556 | |
5557 ScreenLines[off_to] = ScreenLines[off_from]; | |
5558 #ifdef FEAT_MBYTE | |
5559 if (enc_utf8) | |
5560 { | |
5561 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5562 if (ScreenLinesUC[off_from] != 0) | |
5563 { | |
714 | 5564 int i; |
5565 | |
5566 for (i = 0; i < Screen_mco; ++i) | |
5567 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5568 } |
5569 } | |
5570 if (char_cells == 2) | |
5571 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5572 #endif | |
5573 | |
5574 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5575 /* The bold trick makes a single column of pixels appear in the |
5576 * next character. When a bold character is removed, the next | |
7 | 5577 * character should be redrawn too. This happens for our own GUI |
5578 * and for some xterms. */ | |
5579 if ( | |
5580 # ifdef FEAT_GUI | |
5581 gui.in_use | |
5582 # endif | |
5583 # if defined(FEAT_GUI) && defined(UNIX) | |
5584 || | |
5585 # endif | |
5586 # ifdef UNIX | |
5587 term_is_xterm | |
5588 # endif | |
5589 ) | |
5590 { | |
5591 hl = ScreenAttrs[off_to]; | |
743 | 5592 if (hl > HL_ALL) |
5593 hl = syn_attr2attr(hl); | |
5594 if (hl & HL_BOLD) | |
7 | 5595 redraw_next = TRUE; |
5596 } | |
5597 #endif | |
5598 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5599 #ifdef FEAT_MBYTE | |
819 | 5600 /* For simplicity set the attributes of second half of a |
5601 * double-wide character equal to the first half. */ | |
5602 if (char_cells == 2) | |
5603 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5604 | |
7 | 5605 if (enc_dbcs != 0 && char_cells == 2) |
5606 screen_char_2(off_to, row, col + coloff); | |
5607 else | |
5608 #endif | |
5609 screen_char(off_to, row, col + coloff); | |
5610 } | |
5611 else if ( p_wiv | |
5612 #ifdef FEAT_GUI | |
5613 && !gui.in_use | |
5614 #endif | |
5615 && col + coloff > 0) | |
5616 { | |
5617 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5618 { | |
5619 /* | |
5620 * Don't output stop-highlight when moving the cursor, it will | |
5621 * stop the highlighting when it should continue. | |
5622 */ | |
5623 screen_attr = 0; | |
5624 } | |
5625 else if (screen_attr != 0) | |
5626 screen_stop_highlight(); | |
5627 } | |
5628 | |
5629 off_to += CHAR_CELLS; | |
5630 off_from += CHAR_CELLS; | |
5631 col += CHAR_CELLS; | |
5632 } | |
5633 | |
5634 #ifdef FEAT_MBYTE | |
5635 if (clear_next) | |
5636 { | |
5637 /* Clear the second half of a double-wide character of which the left | |
5638 * half was overwritten with a single-wide character. */ | |
5639 ScreenLines[off_to] = ' '; | |
5640 if (enc_utf8) | |
5641 ScreenLinesUC[off_to] = 0; | |
5642 screen_char(off_to, row, col + coloff); | |
5643 } | |
5644 #endif | |
5645 | |
5646 if (clear_width > 0 | |
5647 #ifdef FEAT_RIGHTLEFT | |
5648 && !rlflag | |
5649 #endif | |
5650 ) | |
5651 { | |
5652 #ifdef FEAT_GUI | |
5653 int startCol = col; | |
5654 #endif | |
5655 | |
5656 /* blank out the rest of the line */ | |
5657 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5658 && ScreenAttrs[off_to] == 0 | |
5659 #ifdef FEAT_MBYTE | |
5660 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5661 #endif | |
5662 ) | |
5663 { | |
5664 ++off_to; | |
5665 ++col; | |
5666 } | |
5667 if (col < clear_width) | |
5668 { | |
5669 #ifdef FEAT_GUI | |
5670 /* | |
5671 * In the GUI, clearing the rest of the line may leave pixels | |
5672 * behind if the first character cleared was bold. Some bold | |
5673 * fonts spill over the left. In this case we redraw the previous | |
5674 * character too. If we didn't skip any blanks above, then we | |
5675 * only redraw if the character wasn't already redrawn anyway. | |
5676 */ | |
996 | 5677 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5678 { |
5679 hl = ScreenAttrs[off_to]; | |
5680 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5681 { |
5682 int prev_cells = 1; | |
5683 # ifdef FEAT_MBYTE | |
5684 if (enc_utf8) | |
5685 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5686 * that its width is 2. */ | |
5687 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5688 else if (enc_dbcs != 0) | |
5689 { | |
5690 /* find previous character by counting from first | |
5691 * column and get its width. */ | |
5692 unsigned off = LineOffset[row]; | |
1378 | 5693 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5694 |
5695 while (off < off_to) | |
5696 { | |
1378 | 5697 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5698 off += prev_cells; |
5699 } | |
5700 } | |
5701 | |
5702 if (enc_dbcs != 0 && prev_cells > 1) | |
5703 screen_char_2(off_to - prev_cells, row, | |
5704 col + coloff - prev_cells); | |
5705 else | |
5706 # endif | |
5707 screen_char(off_to - prev_cells, row, | |
5708 col + coloff - prev_cells); | |
5709 } | |
7 | 5710 } |
5711 #endif | |
5712 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5713 ' ', ' ', 0); | |
5714 #ifdef FEAT_VERTSPLIT | |
5715 off_to += clear_width - col; | |
5716 col = clear_width; | |
5717 #endif | |
5718 } | |
5719 } | |
5720 | |
5721 if (clear_width > 0) | |
5722 { | |
5723 #ifdef FEAT_VERTSPLIT | |
5724 /* For a window that's left of another, draw the separator char. */ | |
5725 if (col + coloff < Columns) | |
5726 { | |
5727 int c; | |
5728 | |
5729 c = fillchar_vsep(&hl); | |
5730 if (ScreenLines[off_to] != c | |
5731 # ifdef FEAT_MBYTE | |
714 | 5732 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5733 != (c >= 0x80 ? c : 0)) | |
7 | 5734 # endif |
5735 || ScreenAttrs[off_to] != hl) | |
5736 { | |
5737 ScreenLines[off_to] = c; | |
5738 ScreenAttrs[off_to] = hl; | |
5739 # ifdef FEAT_MBYTE | |
5740 if (enc_utf8) | |
5741 { | |
5742 if (c >= 0x80) | |
5743 { | |
5744 ScreenLinesUC[off_to] = c; | |
714 | 5745 ScreenLinesC[0][off_to] = 0; |
7 | 5746 } |
5747 else | |
5748 ScreenLinesUC[off_to] = 0; | |
5749 } | |
5750 # endif | |
5751 screen_char(off_to, row, col + coloff); | |
5752 } | |
5753 } | |
5754 else | |
5755 #endif | |
5756 LineWraps[row] = FALSE; | |
5757 } | |
5758 } | |
5759 | |
474 | 5760 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5761 /* |
474 | 5762 * Mirror text "str" for right-left displaying. |
5763 * Only works for single-byte characters (e.g., numbers). | |
7 | 5764 */ |
474 | 5765 void |
7 | 5766 rl_mirror(str) |
5767 char_u *str; | |
5768 { | |
5769 char_u *p1, *p2; | |
5770 int t; | |
5771 | |
5772 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5773 { | |
5774 t = *p1; | |
5775 *p1 = *p2; | |
5776 *p2 = t; | |
5777 } | |
5778 } | |
5779 #endif | |
5780 | |
5781 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5782 /* | |
5783 * mark all status lines for redraw; used after first :cd | |
5784 */ | |
5785 void | |
5786 status_redraw_all() | |
5787 { | |
5788 win_T *wp; | |
5789 | |
5790 for (wp = firstwin; wp; wp = wp->w_next) | |
5791 if (wp->w_status_height) | |
5792 { | |
5793 wp->w_redr_status = TRUE; | |
5794 redraw_later(VALID); | |
5795 } | |
5796 } | |
5797 | |
5798 /* | |
5799 * mark all status lines of the current buffer for redraw | |
5800 */ | |
5801 void | |
5802 status_redraw_curbuf() | |
5803 { | |
5804 win_T *wp; | |
5805 | |
5806 for (wp = firstwin; wp; wp = wp->w_next) | |
5807 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5808 { | |
5809 wp->w_redr_status = TRUE; | |
5810 redraw_later(VALID); | |
5811 } | |
5812 } | |
5813 | |
5814 /* | |
5815 * Redraw all status lines that need to be redrawn. | |
5816 */ | |
5817 void | |
5818 redraw_statuslines() | |
5819 { | |
5820 win_T *wp; | |
5821 | |
5822 for (wp = firstwin; wp; wp = wp->w_next) | |
5823 if (wp->w_redr_status) | |
5824 win_redr_status(wp); | |
673 | 5825 if (redraw_tabline) |
677 | 5826 draw_tabline(); |
7 | 5827 } |
5828 #endif | |
5829 | |
5830 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5831 /* | |
5832 * Redraw all status lines at the bottom of frame "frp". | |
5833 */ | |
5834 void | |
5835 win_redraw_last_status(frp) | |
5836 frame_T *frp; | |
5837 { | |
5838 if (frp->fr_layout == FR_LEAF) | |
5839 frp->fr_win->w_redr_status = TRUE; | |
5840 else if (frp->fr_layout == FR_ROW) | |
5841 { | |
5842 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5843 win_redraw_last_status(frp); | |
5844 } | |
5845 else /* frp->fr_layout == FR_COL */ | |
5846 { | |
5847 frp = frp->fr_child; | |
5848 while (frp->fr_next != NULL) | |
5849 frp = frp->fr_next; | |
5850 win_redraw_last_status(frp); | |
5851 } | |
5852 } | |
5853 #endif | |
5854 | |
5855 #ifdef FEAT_VERTSPLIT | |
5856 /* | |
5857 * Draw the verticap separator right of window "wp" starting with line "row". | |
5858 */ | |
5859 static void | |
5860 draw_vsep_win(wp, row) | |
5861 win_T *wp; | |
5862 int row; | |
5863 { | |
5864 int hl; | |
5865 int c; | |
5866 | |
5867 if (wp->w_vsep_width) | |
5868 { | |
5869 /* draw the vertical separator right of this window */ | |
5870 c = fillchar_vsep(&hl); | |
5871 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5872 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5873 c, ' ', hl); | |
5874 } | |
5875 } | |
5876 #endif | |
5877 | |
5878 #ifdef FEAT_WILDMENU | |
5879 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5880 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5881 |
5882 /* | |
1378 | 5883 * Get the length of an item as it will be shown in the status line. |
7 | 5884 */ |
5885 static int | |
5886 status_match_len(xp, s) | |
5887 expand_T *xp; | |
5888 char_u *s; | |
5889 { | |
5890 int len = 0; | |
5891 | |
5892 #ifdef FEAT_MENU | |
5893 int emenu = (xp->xp_context == EXPAND_MENUS | |
5894 || xp->xp_context == EXPAND_MENUNAMES); | |
5895 | |
5896 /* Check for menu separators - replace with '|'. */ | |
5897 if (emenu && menu_is_separator(s)) | |
5898 return 1; | |
5899 #endif | |
5900 | |
5901 while (*s != NUL) | |
5902 { | |
1685 | 5903 s += skip_status_match_char(xp, s); |
42 | 5904 len += ptr2cells(s); |
39 | 5905 mb_ptr_adv(s); |
7 | 5906 } |
5907 | |
5908 return len; | |
5909 } | |
5910 | |
5911 /* | |
1685 | 5912 * Return the number of characters that should be skipped in a status match. |
277 | 5913 * These are backslashes used for escaping. Do show backslashes in help tags. |
5914 */ | |
5915 static int | |
5916 skip_status_match_char(xp, s) | |
5917 expand_T *xp; | |
5918 char_u *s; | |
5919 { | |
1685 | 5920 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5921 #ifdef FEAT_MENU |
5922 || ((xp->xp_context == EXPAND_MENUS | |
5923 || xp->xp_context == EXPAND_MENUNAMES) | |
5924 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5925 #endif | |
1685 | 5926 ) |
5927 { | |
5928 #ifndef BACKSLASH_IN_FILENAME | |
5929 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5930 return 2; | |
5931 #endif | |
5932 return 1; | |
5933 } | |
5934 return 0; | |
277 | 5935 } |
5936 | |
5937 /* | |
7 | 5938 * Show wildchar matches in the status line. |
5939 * Show at least the "match" item. | |
5940 * We start at item 'first_match' in the list and show all matches that fit. | |
5941 * | |
5942 * If inversion is possible we use it. Else '=' characters are used. | |
5943 */ | |
5944 void | |
5945 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5946 expand_T *xp; | |
5947 int num_matches; | |
5948 char_u **matches; /* list of matches */ | |
5949 int match; | |
5950 int showtail; | |
5951 { | |
5952 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5953 int row; | |
5954 char_u *buf; | |
5955 int len; | |
1378 | 5956 int clen; /* length in screen cells */ |
7 | 5957 int fillchar; |
5958 int attr; | |
5959 int i; | |
5960 int highlight = TRUE; | |
5961 char_u *selstart = NULL; | |
5962 int selstart_col = 0; | |
5963 char_u *selend = NULL; | |
5964 static int first_match = 0; | |
5965 int add_left = FALSE; | |
5966 char_u *s; | |
5967 #ifdef FEAT_MENU | |
5968 int emenu; | |
5969 #endif | |
5970 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5971 int l; | |
5972 #endif | |
5973 | |
5974 if (matches == NULL) /* interrupted completion? */ | |
5975 return; | |
5976 | |
39 | 5977 #ifdef FEAT_MBYTE |
5978 if (has_mbyte) | |
5979 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5980 else | |
5981 #endif | |
5982 buf = alloc((unsigned)Columns + 1); | |
7 | 5983 if (buf == NULL) |
5984 return; | |
5985 | |
5986 if (match == -1) /* don't show match but original text */ | |
5987 { | |
5988 match = 0; | |
5989 highlight = FALSE; | |
5990 } | |
5991 /* count 1 for the ending ">" */ | |
5992 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5993 if (match == 0) | |
5994 first_match = 0; | |
5995 else if (match < first_match) | |
5996 { | |
5997 /* jumping left, as far as we can go */ | |
5998 first_match = match; | |
5999 add_left = TRUE; | |
6000 } | |
6001 else | |
6002 { | |
6003 /* check if match fits on the screen */ | |
6004 for (i = first_match; i < match; ++i) | |
6005 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
6006 if (first_match > 0) | |
6007 clen += 2; | |
6008 /* jumping right, put match at the left */ | |
6009 if ((long)clen > Columns) | |
6010 { | |
6011 first_match = match; | |
6012 /* if showing the last match, we can add some on the left */ | |
6013 clen = 2; | |
6014 for (i = match; i < num_matches; ++i) | |
6015 { | |
6016 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
6017 if ((long)clen >= Columns) | |
6018 break; | |
6019 } | |
6020 if (i == num_matches) | |
6021 add_left = TRUE; | |
6022 } | |
6023 } | |
6024 if (add_left) | |
6025 while (first_match > 0) | |
6026 { | |
6027 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
6028 if ((long)clen >= Columns) | |
6029 break; | |
6030 --first_match; | |
6031 } | |
6032 | |
6033 fillchar = fillchar_status(&attr, TRUE); | |
6034 | |
6035 if (first_match == 0) | |
6036 { | |
6037 *buf = NUL; | |
6038 len = 0; | |
6039 } | |
6040 else | |
6041 { | |
6042 STRCPY(buf, "< "); | |
6043 len = 2; | |
6044 } | |
6045 clen = len; | |
6046 | |
6047 i = first_match; | |
6048 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
6049 { | |
6050 if (i == match) | |
6051 { | |
6052 selstart = buf + len; | |
6053 selstart_col = clen; | |
6054 } | |
6055 | |
6056 s = L_MATCH(i); | |
6057 /* Check for menu separators - replace with '|' */ | |
6058 #ifdef FEAT_MENU | |
6059 emenu = (xp->xp_context == EXPAND_MENUS | |
6060 || xp->xp_context == EXPAND_MENUNAMES); | |
6061 if (emenu && menu_is_separator(s)) | |
6062 { | |
6063 STRCPY(buf + len, transchar('|')); | |
6064 l = (int)STRLEN(buf + len); | |
6065 len += l; | |
6066 clen += l; | |
6067 } | |
6068 else | |
6069 #endif | |
6070 for ( ; *s != NUL; ++s) | |
6071 { | |
1685 | 6072 s += skip_status_match_char(xp, s); |
7 | 6073 clen += ptr2cells(s); |
6074 #ifdef FEAT_MBYTE | |
474 | 6075 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 6076 { |
6077 STRNCPY(buf + len, s, l); | |
6078 s += l - 1; | |
6079 len += l; | |
6080 } | |
6081 else | |
6082 #endif | |
6083 { | |
6084 STRCPY(buf + len, transchar_byte(*s)); | |
6085 len += (int)STRLEN(buf + len); | |
6086 } | |
6087 } | |
6088 if (i == match) | |
6089 selend = buf + len; | |
6090 | |
6091 *(buf + len++) = ' '; | |
6092 *(buf + len++) = ' '; | |
6093 clen += 2; | |
6094 if (++i == num_matches) | |
6095 break; | |
6096 } | |
6097 | |
6098 if (i != num_matches) | |
6099 { | |
6100 *(buf + len++) = '>'; | |
6101 ++clen; | |
6102 } | |
6103 | |
6104 buf[len] = NUL; | |
6105 | |
6106 row = cmdline_row - 1; | |
6107 if (row >= 0) | |
6108 { | |
6109 if (wild_menu_showing == 0) | |
6110 { | |
6111 if (msg_scrolled > 0) | |
6112 { | |
6113 /* Put the wildmenu just above the command line. If there is | |
6114 * no room, scroll the screen one line up. */ | |
6115 if (cmdline_row == Rows - 1) | |
6116 { | |
6117 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6118 ++msg_scrolled; | |
6119 } | |
6120 else | |
6121 { | |
6122 ++cmdline_row; | |
6123 ++row; | |
6124 } | |
6125 wild_menu_showing = WM_SCROLLED; | |
6126 } | |
6127 else | |
6128 { | |
6129 /* Create status line if needed by setting 'laststatus' to 2. | |
6130 * Set 'winminheight' to zero to avoid that the window is | |
6131 * resized. */ | |
6132 if (lastwin->w_status_height == 0) | |
6133 { | |
6134 save_p_ls = p_ls; | |
6135 save_p_wmh = p_wmh; | |
6136 p_ls = 2; | |
6137 p_wmh = 0; | |
6138 last_status(FALSE); | |
6139 } | |
6140 wild_menu_showing = WM_SHOWN; | |
6141 } | |
6142 } | |
6143 | |
6144 screen_puts(buf, row, 0, attr); | |
6145 if (selstart != NULL && highlight) | |
6146 { | |
6147 *selend = NUL; | |
6148 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6149 } | |
6150 | |
6151 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6152 } | |
6153 | |
6154 #ifdef FEAT_VERTSPLIT | |
6155 win_redraw_last_status(topframe); | |
6156 #else | |
6157 lastwin->w_redr_status = TRUE; | |
6158 #endif | |
6159 vim_free(buf); | |
6160 } | |
6161 #endif | |
6162 | |
6163 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6164 /* | |
6165 * Redraw the status line of window wp. | |
6166 * | |
6167 * If inversion is possible we use it. Else '=' characters are used. | |
6168 */ | |
6169 void | |
6170 win_redr_status(wp) | |
6171 win_T *wp; | |
6172 { | |
6173 int row; | |
6174 char_u *p; | |
6175 int len; | |
6176 int fillchar; | |
6177 int attr; | |
6178 int this_ru_col; | |
1910 | 6179 static int busy = FALSE; |
6180 | |
6181 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6182 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6183 if (busy) | |
6184 return; | |
6185 busy = TRUE; | |
7 | 6186 |
6187 wp->w_redr_status = FALSE; | |
6188 if (wp->w_status_height == 0) | |
6189 { | |
6190 /* no status line, can only be last window */ | |
6191 redraw_cmdline = TRUE; | |
6192 } | |
540 | 6193 else if (!redrawing() |
6194 #ifdef FEAT_INS_EXPAND | |
6195 /* don't update status line when popup menu is visible and may be | |
6196 * drawn over it */ | |
6197 || pum_visible() | |
6198 #endif | |
6199 ) | |
7 | 6200 { |
6201 /* Don't redraw right now, do it later. */ | |
6202 wp->w_redr_status = TRUE; | |
6203 } | |
6204 #ifdef FEAT_STL_OPT | |
40 | 6205 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6206 { |
6207 /* redraw custom status line */ | |
1983 | 6208 redraw_custom_statusline(wp); |
7 | 6209 } |
6210 #endif | |
6211 else | |
6212 { | |
6213 fillchar = fillchar_status(&attr, wp == curwin); | |
6214 | |
685 | 6215 get_trans_bufname(wp->w_buffer); |
7 | 6216 p = NameBuff; |
6217 len = (int)STRLEN(p); | |
6218 | |
6219 if (wp->w_buffer->b_help | |
6220 #ifdef FEAT_QUICKFIX | |
6221 || wp->w_p_pvw | |
6222 #endif | |
6223 || bufIsChanged(wp->w_buffer) | |
6224 || wp->w_buffer->b_p_ro) | |
6225 *(p + len++) = ' '; | |
6226 if (wp->w_buffer->b_help) | |
6227 { | |
809 | 6228 STRCPY(p + len, _("[Help]")); |
7 | 6229 len += (int)STRLEN(p + len); |
6230 } | |
6231 #ifdef FEAT_QUICKFIX | |
6232 if (wp->w_p_pvw) | |
6233 { | |
6234 STRCPY(p + len, _("[Preview]")); | |
6235 len += (int)STRLEN(p + len); | |
6236 } | |
6237 #endif | |
6238 if (bufIsChanged(wp->w_buffer)) | |
6239 { | |
6240 STRCPY(p + len, "[+]"); | |
6241 len += 3; | |
6242 } | |
6243 if (wp->w_buffer->b_p_ro) | |
6244 { | |
6245 STRCPY(p + len, "[RO]"); | |
6246 len += 4; | |
6247 } | |
6248 | |
6249 #ifndef FEAT_VERTSPLIT | |
6250 this_ru_col = ru_col; | |
6251 if (this_ru_col < (Columns + 1) / 2) | |
6252 this_ru_col = (Columns + 1) / 2; | |
6253 #else | |
6254 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6255 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6256 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6257 if (this_ru_col <= 1) | |
6258 { | |
6259 p = (char_u *)"<"; /* No room for file name! */ | |
6260 len = 1; | |
6261 } | |
6262 else | |
6263 #endif | |
6264 #ifdef FEAT_MBYTE | |
6265 if (has_mbyte) | |
6266 { | |
6267 int clen = 0, i; | |
6268 | |
6269 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6270 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6271 |
7 | 6272 /* Find first character that will fit. |
6273 * Going from start to end is much faster for DBCS. */ | |
6274 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6275 i += (*mb_ptr2len)(p + i)) |
7 | 6276 clen -= (*mb_ptr2cells)(p + i); |
6277 len = clen; | |
6278 if (i > 0) | |
6279 { | |
6280 p = p + i - 1; | |
6281 *p = '<'; | |
6282 ++len; | |
6283 } | |
6284 | |
6285 } | |
6286 else | |
6287 #endif | |
6288 if (len > this_ru_col - 1) | |
6289 { | |
6290 p += len - (this_ru_col - 1); | |
6291 *p = '<'; | |
6292 len = this_ru_col - 1; | |
6293 } | |
6294 | |
6295 row = W_WINROW(wp) + wp->w_height; | |
6296 screen_puts(p, row, W_WINCOL(wp), attr); | |
6297 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6298 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6299 | |
6300 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6301 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6302 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6303 - 1 + W_WINCOL(wp)), attr); | |
6304 | |
6305 #ifdef FEAT_CMDL_INFO | |
6306 win_redr_ruler(wp, TRUE); | |
6307 #endif | |
6308 } | |
6309 | |
6310 #ifdef FEAT_VERTSPLIT | |
6311 /* | |
6312 * May need to draw the character below the vertical separator. | |
6313 */ | |
6314 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6315 { | |
6316 if (stl_connected(wp)) | |
6317 fillchar = fillchar_status(&attr, wp == curwin); | |
6318 else | |
6319 fillchar = fillchar_vsep(&attr); | |
6320 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6321 attr); | |
6322 } | |
6323 #endif | |
1910 | 6324 busy = FALSE; |
7 | 6325 } |
6326 | |
680 | 6327 #ifdef FEAT_STL_OPT |
6328 /* | |
6329 * Redraw the status line according to 'statusline' and take care of any | |
6330 * errors encountered. | |
6331 */ | |
6332 static void | |
1983 | 6333 redraw_custom_statusline(wp) |
680 | 6334 win_T *wp; |
6335 { | |
1983 | 6336 static int entered = FALSE; |
6337 int save_called_emsg = called_emsg; | |
6338 | |
6339 /* When called recursively return. This can happen when the statusline | |
6340 * contains an expression that triggers a redraw. */ | |
6341 if (entered) | |
6342 return; | |
6343 entered = TRUE; | |
680 | 6344 |
6345 called_emsg = FALSE; | |
6346 win_redr_custom(wp, FALSE); | |
6347 if (called_emsg) | |
1983 | 6348 { |
6349 /* When there is an error disable the statusline, otherwise the | |
6350 * display is messed up with errors and a redraw triggers the problem | |
6351 * again and again. */ | |
680 | 6352 set_string_option_direct((char_u *)"statusline", -1, |
6353 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6354 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6355 } |
680 | 6356 called_emsg |= save_called_emsg; |
1983 | 6357 entered = FALSE; |
680 | 6358 } |
6359 #endif | |
6360 | |
7 | 6361 # ifdef FEAT_VERTSPLIT |
6362 /* | |
6363 * Return TRUE if the status line of window "wp" is connected to the status | |
6364 * line of the window right of it. If not, then it's a vertical separator. | |
6365 * Only call if (wp->w_vsep_width != 0). | |
6366 */ | |
6367 int | |
6368 stl_connected(wp) | |
6369 win_T *wp; | |
6370 { | |
6371 frame_T *fr; | |
6372 | |
6373 fr = wp->w_frame; | |
6374 while (fr->fr_parent != NULL) | |
6375 { | |
6376 if (fr->fr_parent->fr_layout == FR_COL) | |
6377 { | |
6378 if (fr->fr_next != NULL) | |
6379 break; | |
6380 } | |
6381 else | |
6382 { | |
6383 if (fr->fr_next != NULL) | |
6384 return TRUE; | |
6385 } | |
6386 fr = fr->fr_parent; | |
6387 } | |
6388 return FALSE; | |
6389 } | |
6390 # endif | |
6391 | |
6392 #endif /* FEAT_WINDOWS */ | |
6393 | |
6394 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6395 /* | |
6396 * Get the value to show for the language mappings, active 'keymap'. | |
6397 */ | |
6398 int | |
6399 get_keymap_str(wp, buf, len) | |
6400 win_T *wp; | |
6401 char_u *buf; /* buffer for the result */ | |
6402 int len; /* length of buffer */ | |
6403 { | |
6404 char_u *p; | |
6405 | |
6406 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6407 return FALSE; | |
6408 | |
6409 { | |
6410 #ifdef FEAT_EVAL | |
6411 buf_T *old_curbuf = curbuf; | |
6412 win_T *old_curwin = curwin; | |
6413 char_u *s; | |
6414 | |
6415 curbuf = wp->w_buffer; | |
6416 curwin = wp; | |
6417 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6418 ++emsg_skip; | |
714 | 6419 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6420 --emsg_skip; |
6421 curbuf = old_curbuf; | |
6422 curwin = old_curwin; | |
6423 if (p == NULL || *p == NUL) | |
6424 #endif | |
6425 { | |
6426 #ifdef FEAT_KEYMAP | |
6427 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6428 p = wp->w_buffer->b_p_keymap; | |
6429 else | |
6430 #endif | |
6431 p = (char_u *)"lang"; | |
6432 } | |
6433 if ((int)(STRLEN(p) + 3) < len) | |
6434 sprintf((char *)buf, "<%s>", p); | |
6435 else | |
6436 buf[0] = NUL; | |
6437 #ifdef FEAT_EVAL | |
6438 vim_free(s); | |
6439 #endif | |
6440 } | |
6441 return buf[0] != NUL; | |
6442 } | |
6443 #endif | |
6444 | |
6445 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6446 /* | |
677 | 6447 * Redraw the status line or ruler of window "wp". |
6448 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6449 */ |
6450 static void | |
574 | 6451 win_redr_custom(wp, draw_ruler) |
7 | 6452 win_T *wp; |
574 | 6453 int draw_ruler; /* TRUE or FALSE */ |
7 | 6454 { |
6455 int attr; | |
6456 int curattr; | |
6457 int row; | |
6458 int col = 0; | |
6459 int maxwidth; | |
6460 int width; | |
6461 int n; | |
6462 int len; | |
6463 int fillchar; | |
6464 char_u buf[MAXPATHL]; | |
1983 | 6465 char_u *stl; |
7 | 6466 char_u *p; |
681 | 6467 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6468 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6469 int use_sandbox = FALSE; |
2693 | 6470 win_T *ewp; |
6471 int p_crb_save; | |
7 | 6472 |
6473 /* setup environment for the task at hand */ | |
677 | 6474 if (wp == NULL) |
6475 { | |
6476 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6477 stl = p_tal; |
677 | 6478 row = 0; |
707 | 6479 fillchar = ' '; |
677 | 6480 attr = hl_attr(HLF_TPF); |
6481 maxwidth = Columns; | |
6482 # ifdef FEAT_EVAL | |
681 | 6483 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6484 # endif |
6485 } | |
40 | 6486 else |
677 | 6487 { |
6488 row = W_WINROW(wp) + wp->w_height; | |
6489 fillchar = fillchar_status(&attr, wp == curwin); | |
6490 maxwidth = W_WIDTH(wp); | |
6491 | |
6492 if (draw_ruler) | |
6493 { | |
1983 | 6494 stl = p_ruf; |
677 | 6495 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6496 if (*stl == '%') |
6497 { | |
6498 if (*++stl == '-') | |
6499 stl++; | |
6500 if (atoi((char *)stl)) | |
6501 while (VIM_ISDIGIT(*stl)) | |
6502 stl++; | |
6503 if (*stl++ != '(') | |
6504 stl = p_ruf; | |
677 | 6505 } |
7 | 6506 #ifdef FEAT_VERTSPLIT |
677 | 6507 col = ru_col - (Columns - W_WIDTH(wp)); |
6508 if (col < (W_WIDTH(wp) + 1) / 2) | |
6509 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6510 #else |
677 | 6511 col = ru_col; |
6512 if (col > (Columns + 1) / 2) | |
6513 col = (Columns + 1) / 2; | |
6514 #endif | |
6515 maxwidth = W_WIDTH(wp) - col; | |
7 | 6516 #ifdef FEAT_WINDOWS |
677 | 6517 if (!wp->w_status_height) |
6518 #endif | |
6519 { | |
6520 row = Rows - 1; | |
6521 --maxwidth; /* writing in last column may cause scrolling */ | |
6522 fillchar = ' '; | |
6523 attr = 0; | |
6524 } | |
6525 | |
6526 # ifdef FEAT_EVAL | |
681 | 6527 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6528 # endif |
6529 } | |
6530 else | |
6531 { | |
6532 if (*wp->w_p_stl != NUL) | |
1983 | 6533 stl = wp->w_p_stl; |
677 | 6534 else |
1983 | 6535 stl = p_stl; |
677 | 6536 # ifdef FEAT_EVAL |
681 | 6537 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6538 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6539 # endif |
6540 } | |
6541 | |
6542 #ifdef FEAT_VERTSPLIT | |
6543 col += W_WINCOL(wp); | |
6544 #endif | |
6545 } | |
6546 | |
7 | 6547 if (maxwidth <= 0) |
6548 return; | |
677 | 6549 |
2693 | 6550 /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
6551 * the cursor away and back. */ | |
6552 ewp = wp == NULL ? curwin : wp; | |
6553 p_crb_save = ewp->w_p_crb; | |
6554 ewp->w_p_crb = FALSE; | |
6555 | |
1983 | 6556 /* Make a copy, because the statusline may include a function call that |
6557 * might change the option value and free the memory. */ | |
6558 stl = vim_strsave(stl); | |
2693 | 6559 width = build_stl_str_hl(ewp, buf, sizeof(buf), |
1983 | 6560 stl, use_sandbox, |
681 | 6561 fillchar, maxwidth, hltab, tabtab); |
1983 | 6562 vim_free(stl); |
2693 | 6563 ewp->w_p_crb = p_crb_save; |
2661 | 6564 |
6565 /* Make all characters printable. */ | |
6566 p = transstr(buf); | |
6567 if (p != NULL) | |
6568 { | |
6569 vim_strncpy(buf, p, sizeof(buf) - 1); | |
6570 vim_free(p); | |
6571 } | |
6572 | |
6573 /* fill up with "fillchar" */ | |
835 | 6574 len = (int)STRLEN(buf); |
1883 | 6575 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6576 { |
6577 #ifdef FEAT_MBYTE | |
6578 len += (*mb_char2bytes)(fillchar, buf + len); | |
6579 #else | |
6580 buf[len++] = fillchar; | |
6581 #endif | |
6582 ++width; | |
6583 } | |
6584 buf[len] = NUL; | |
6585 | |
681 | 6586 /* |
6587 * Draw each snippet with the specified highlighting. | |
6588 */ | |
7 | 6589 curattr = attr; |
6590 p = buf; | |
681 | 6591 for (n = 0; hltab[n].start != NULL; n++) |
6592 { | |
6593 len = (int)(hltab[n].start - p); | |
7 | 6594 screen_puts_len(p, len, row, col, curattr); |
6595 col += vim_strnsize(p, len); | |
681 | 6596 p = hltab[n].start; |
6597 | |
6598 if (hltab[n].userhl == 0) | |
7 | 6599 curattr = attr; |
681 | 6600 else if (hltab[n].userhl < 0) |
6601 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6602 #ifdef FEAT_WINDOWS |
680 | 6603 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6604 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6605 #endif |
6606 else | |
681 | 6607 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6608 } |
6609 screen_puts(p, row, col, curattr); | |
681 | 6610 |
6611 if (wp == NULL) | |
6612 { | |
6613 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6614 col = 0; | |
6615 len = 0; | |
6616 p = buf; | |
6617 fillchar = 0; | |
6618 for (n = 0; tabtab[n].start != NULL; n++) | |
6619 { | |
6620 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6621 while (col < len) | |
6622 TabPageIdxs[col++] = fillchar; | |
6623 p = tabtab[n].start; | |
6624 fillchar = tabtab[n].userhl; | |
6625 } | |
6626 while (col < Columns) | |
6627 TabPageIdxs[col++] = fillchar; | |
6628 } | |
7 | 6629 } |
6630 | |
6631 #endif /* FEAT_STL_OPT */ | |
6632 | |
6633 /* | |
6634 * Output a single character directly to the screen and update ScreenLines. | |
6635 */ | |
6636 void | |
6637 screen_putchar(c, row, col, attr) | |
6638 int c; | |
6639 int row, col; | |
6640 int attr; | |
6641 { | |
3549 | 6642 char_u buf[MB_MAXBYTES + 1]; |
6643 | |
7 | 6644 #ifdef FEAT_MBYTE |
3549 | 6645 if (has_mbyte) |
6646 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6647 else | |
6648 #endif | |
6649 { | |
6650 buf[0] = c; | |
6651 buf[1] = NUL; | |
6652 } | |
7 | 6653 screen_puts(buf, row, col, attr); |
6654 } | |
6655 | |
6656 /* | |
6657 * Get a single character directly from ScreenLines into "bytes[]". | |
6658 * Also return its attribute in *attrp; | |
6659 */ | |
6660 void | |
6661 screen_getbytes(row, col, bytes, attrp) | |
6662 int row, col; | |
6663 char_u *bytes; | |
6664 int *attrp; | |
6665 { | |
6666 unsigned off; | |
6667 | |
6668 /* safety check */ | |
6669 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6670 { | |
6671 off = LineOffset[row] + col; | |
6672 *attrp = ScreenAttrs[off]; | |
6673 bytes[0] = ScreenLines[off]; | |
6674 bytes[1] = NUL; | |
6675 | |
6676 #ifdef FEAT_MBYTE | |
6677 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6678 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6679 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6680 { | |
6681 bytes[0] = ScreenLines[off]; | |
6682 bytes[1] = ScreenLines2[off]; | |
6683 bytes[2] = NUL; | |
6684 } | |
6685 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6686 { | |
6687 bytes[1] = ScreenLines[off + 1]; | |
6688 bytes[2] = NUL; | |
6689 } | |
6690 #endif | |
6691 } | |
6692 } | |
6693 | |
714 | 6694 #ifdef FEAT_MBYTE |
6695 static int screen_comp_differs __ARGS((int, int*)); | |
6696 | |
6697 /* | |
6698 * Return TRUE if composing characters for screen posn "off" differs from | |
6699 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6700 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6701 */ |
6702 static int | |
6703 screen_comp_differs(off, u8cc) | |
6704 int off; | |
6705 int *u8cc; | |
6706 { | |
6707 int i; | |
6708 | |
6709 for (i = 0; i < Screen_mco; ++i) | |
6710 { | |
6711 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6712 return TRUE; | |
6713 if (u8cc[i] == 0) | |
6714 break; | |
6715 } | |
6716 return FALSE; | |
6717 } | |
6718 #endif | |
6719 | |
7 | 6720 /* |
6721 * Put string '*text' on the screen at position 'row' and 'col', with | |
6722 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6723 * Note: only outputs within one row, message is truncated at screen boundary! | |
6724 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6725 */ | |
6726 void | |
6727 screen_puts(text, row, col, attr) | |
6728 char_u *text; | |
6729 int row; | |
6730 int col; | |
6731 int attr; | |
6732 { | |
6733 screen_puts_len(text, -1, row, col, attr); | |
6734 } | |
6735 | |
6736 /* | |
6737 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6738 * a NUL. | |
6739 */ | |
6740 void | |
6741 screen_puts_len(text, len, row, col, attr) | |
6742 char_u *text; | |
6743 int len; | |
6744 int row; | |
6745 int col; | |
6746 int attr; | |
6747 { | |
6748 unsigned off; | |
6749 char_u *ptr = text; | |
6750 int c; | |
6751 #ifdef FEAT_MBYTE | |
1378 | 6752 unsigned max_off; |
7 | 6753 int mbyte_blen = 1; |
6754 int mbyte_cells = 1; | |
6755 int u8c = 0; | |
714 | 6756 int u8cc[MAX_MCO]; |
7 | 6757 int clear_next_cell = FALSE; |
6758 # ifdef FEAT_ARABIC | |
6759 int prev_c = 0; /* previous Arabic character */ | |
714 | 6760 int pc, nc, nc1; |
6761 int pcc[MAX_MCO]; | |
7 | 6762 # endif |
6763 #endif | |
1843 | 6764 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6765 int force_redraw_this; | |
6766 int force_redraw_next = FALSE; | |
6767 #endif | |
6768 int need_redraw; | |
7 | 6769 |
6770 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6771 return; | |
1843 | 6772 off = LineOffset[row] + col; |
7 | 6773 |
1668 | 6774 #ifdef FEAT_MBYTE |
6775 /* When drawing over the right halve of a double-wide char clear out the | |
6776 * left halve. Only needed in a terminal. */ | |
1685 | 6777 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6778 # ifdef FEAT_GUI |
6779 && !gui.in_use | |
6780 # endif | |
6781 && mb_fix_col(col, row) != col) | |
1843 | 6782 { |
6783 ScreenLines[off - 1] = ' '; | |
6784 ScreenAttrs[off - 1] = 0; | |
6785 if (enc_utf8) | |
6786 { | |
6787 ScreenLinesUC[off - 1] = 0; | |
6788 ScreenLinesC[0][off - 1] = 0; | |
6789 } | |
6790 /* redraw the previous cell, make it empty */ | |
6791 screen_char(off - 1, row, col - 1); | |
6792 /* force the cell at "col" to be redrawn */ | |
6793 force_redraw_next = TRUE; | |
6794 } | |
6795 #endif | |
6796 | |
1378 | 6797 #ifdef FEAT_MBYTE |
6798 max_off = LineOffset[row] + screen_Columns; | |
6799 #endif | |
1340 | 6800 while (col < screen_Columns |
6801 && (len < 0 || (int)(ptr - text) < len) | |
6802 && *ptr != NUL) | |
7 | 6803 { |
6804 c = *ptr; | |
6805 #ifdef FEAT_MBYTE | |
6806 /* check if this is the first byte of a multibyte */ | |
6807 if (has_mbyte) | |
6808 { | |
6809 if (enc_utf8 && len > 0) | |
474 | 6810 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6811 else |
474 | 6812 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6813 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6814 mbyte_cells = 1; | |
6815 else if (enc_dbcs != 0) | |
6816 mbyte_cells = mbyte_blen; | |
6817 else /* enc_utf8 */ | |
6818 { | |
6819 if (len >= 0) | |
714 | 6820 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6821 (int)((text + len) - ptr)); |
6822 else | |
714 | 6823 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6824 mbyte_cells = utf_char2cells(u8c); |
1401 | 6825 # ifdef UNICODE16 |
7 | 6826 /* Non-BMP character: display as ? or fullwidth ?. */ |
6827 if (u8c >= 0x10000) | |
6828 { | |
6829 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6830 if (attr == 0) | |
6831 attr = hl_attr(HLF_8); | |
6832 } | |
1401 | 6833 # endif |
7 | 6834 # ifdef FEAT_ARABIC |
6835 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6836 { | |
6837 /* Do Arabic shaping. */ | |
6838 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6839 { | |
6840 /* Past end of string to be displayed. */ | |
6841 nc = NUL; | |
6842 nc1 = NUL; | |
6843 } | |
6844 else | |
714 | 6845 { |
1994 | 6846 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6847 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6848 nc1 = pcc[0]; |
6849 } | |
7 | 6850 pc = prev_c; |
6851 prev_c = u8c; | |
714 | 6852 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6853 } |
6854 else | |
6855 prev_c = u8c; | |
6856 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6857 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6858 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6859 /* 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
|
6860 * 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
|
6861 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6862 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6863 } |
7 | 6864 } |
6865 } | |
6866 #endif | |
6867 | |
1843 | 6868 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6869 force_redraw_this = force_redraw_next; | |
6870 force_redraw_next = FALSE; | |
6871 #endif | |
6872 | |
6873 need_redraw = ScreenLines[off] != c | |
7 | 6874 #ifdef FEAT_MBYTE |
6875 || (mbyte_cells == 2 | |
6876 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6877 || (enc_dbcs == DBCS_JPNU | |
6878 && c == 0x8e | |
6879 && ScreenLines2[off] != ptr[1]) | |
6880 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6881 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6882 (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
|
6883 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6884 && screen_comp_differs(off, u8cc)))) |
7 | 6885 #endif |
6886 || ScreenAttrs[off] != attr | |
1843 | 6887 || exmode_active; |
6888 | |
6889 if (need_redraw | |
6890 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6891 || force_redraw_this | |
6892 #endif | |
7 | 6893 ) |
6894 { | |
6895 #if defined(FEAT_GUI) || defined(UNIX) | |
6896 /* The bold trick makes a single row of pixels appear in the next | |
6897 * character. When a bold character is removed, the next | |
6898 * character should be redrawn too. This happens for our own GUI | |
1843 | 6899 * and for some xterms. */ |
6900 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6901 # ifdef FEAT_GUI |
6902 gui.in_use | |
6903 # endif | |
6904 # if defined(FEAT_GUI) && defined(UNIX) | |
6905 || | |
6906 # endif | |
6907 # ifdef UNIX | |
6908 term_is_xterm | |
6909 # endif | |
1843 | 6910 )) |
6911 { | |
6912 int n = ScreenAttrs[off]; | |
6913 | |
6914 if (n > HL_ALL) | |
6915 n = syn_attr2attr(n); | |
6916 if (n & HL_BOLD) | |
6917 force_redraw_next = TRUE; | |
7 | 6918 } |
6919 #endif | |
6920 #ifdef FEAT_MBYTE | |
6921 /* When at the end of the text and overwriting a two-cell | |
6922 * character with a one-cell character, need to clear the next | |
6923 * cell. Also when overwriting the left halve of a two-cell char | |
6924 * with the right halve of a two-cell char. Do this only once | |
6925 * (mb_off2cells() may return 2 on the right halve). */ | |
6926 if (clear_next_cell) | |
6927 clear_next_cell = FALSE; | |
6928 else if (has_mbyte | |
6929 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6930 : ptr + mbyte_blen >= text + len) | |
1378 | 6931 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6932 || (mbyte_cells == 2 |
1378 | 6933 && (*mb_off2cells)(off, max_off) == 1 |
6934 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6935 clear_next_cell = TRUE; |
6936 | |
6937 /* Make sure we never leave a second byte of a double-byte behind, | |
6938 * it confuses mb_off2cells(). */ | |
6939 if (enc_dbcs | |
1378 | 6940 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6941 || (mbyte_cells == 2 |
1378 | 6942 && (*mb_off2cells)(off, max_off) == 1 |
6943 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6944 ScreenLines[off + mbyte_blen] = 0; |
6945 #endif | |
6946 ScreenLines[off] = c; | |
6947 ScreenAttrs[off] = attr; | |
6948 #ifdef FEAT_MBYTE | |
6949 if (enc_utf8) | |
6950 { | |
714 | 6951 if (c < 0x80 && u8cc[0] == 0) |
7 | 6952 ScreenLinesUC[off] = 0; |
6953 else | |
6954 { | |
714 | 6955 int i; |
6956 | |
7 | 6957 ScreenLinesUC[off] = u8c; |
714 | 6958 for (i = 0; i < Screen_mco; ++i) |
6959 { | |
6960 ScreenLinesC[i][off] = u8cc[i]; | |
6961 if (u8cc[i] == 0) | |
6962 break; | |
6963 } | |
7 | 6964 } |
6965 if (mbyte_cells == 2) | |
6966 { | |
6967 ScreenLines[off + 1] = 0; | |
6968 ScreenAttrs[off + 1] = attr; | |
6969 } | |
6970 screen_char(off, row, col); | |
6971 } | |
6972 else if (mbyte_cells == 2) | |
6973 { | |
6974 ScreenLines[off + 1] = ptr[1]; | |
6975 ScreenAttrs[off + 1] = attr; | |
6976 screen_char_2(off, row, col); | |
6977 } | |
6978 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6979 { | |
6980 ScreenLines2[off] = ptr[1]; | |
6981 screen_char(off, row, col); | |
6982 } | |
6983 else | |
6984 #endif | |
6985 screen_char(off, row, col); | |
6986 } | |
6987 #ifdef FEAT_MBYTE | |
6988 if (has_mbyte) | |
6989 { | |
6990 off += mbyte_cells; | |
6991 col += mbyte_cells; | |
6992 ptr += mbyte_blen; | |
6993 if (clear_next_cell) | |
6994 ptr = (char_u *)" "; | |
6995 } | |
6996 else | |
6997 #endif | |
6998 { | |
6999 ++off; | |
7000 ++col; | |
7001 ++ptr; | |
7002 } | |
7003 } | |
1843 | 7004 |
7005 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
7006 /* If we detected the next character needs to be redrawn, but the text | |
7007 * doesn't extend up to there, update the character here. */ | |
7008 if (force_redraw_next && col < screen_Columns) | |
7009 { | |
7010 # ifdef FEAT_MBYTE | |
7011 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
7012 screen_char_2(off, row, col); | |
7013 else | |
7014 # endif | |
7015 screen_char(off, row, col); | |
7016 } | |
7017 #endif | |
7 | 7018 } |
7019 | |
7020 #ifdef FEAT_SEARCH_EXTRA | |
7021 /* | |
1326 | 7022 * Prepare for 'hlsearch' highlighting. |
7 | 7023 */ |
7024 static void | |
7025 start_search_hl() | |
7026 { | |
7027 if (p_hls && !no_hlsearch) | |
7028 { | |
7029 last_pat_prog(&search_hl.rm); | |
7030 search_hl.attr = hl_attr(HLF_L); | |
1521 | 7031 # ifdef FEAT_RELTIME |
7032 /* Set the time limit to 'redrawtime'. */ | |
7033 profile_setlimit(p_rdt, &search_hl.tm); | |
7034 # endif | |
7 | 7035 } |
7036 } | |
7037 | |
7038 /* | |
1326 | 7039 * Clean up for 'hlsearch' highlighting. |
7 | 7040 */ |
7041 static void | |
7042 end_search_hl() | |
7043 { | |
7044 if (search_hl.rm.regprog != NULL) | |
7045 { | |
7046 vim_free(search_hl.rm.regprog); | |
7047 search_hl.rm.regprog = NULL; | |
7048 } | |
7049 } | |
7050 | |
7051 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7052 * 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
|
7053 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7054 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7055 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7056 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7057 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7058 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7059 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7060 /* 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
|
7061 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7062 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7063 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7064 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7065 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7066 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7067 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7068 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7069 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
|
7070 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
|
7071 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7072 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7073 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7074 /* 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
|
7075 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
|
7076 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7077 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7078 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7079 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
|
7080 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7081 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7082 /* 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
|
7083 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7084 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7085 /* |
7 | 7086 * Advance to the match in window "wp" line "lnum" or past it. |
7087 */ | |
7088 static void | |
7089 prepare_search_hl(wp, lnum) | |
7090 win_T *wp; | |
7091 linenr_T lnum; | |
7092 { | |
1326 | 7093 matchitem_T *cur; /* points to the match list */ |
7094 match_T *shl; /* points to search_hl or a match */ | |
7095 int shl_flag; /* flag to indicate whether search_hl | |
7096 has been processed or not */ | |
7 | 7097 int n; |
7098 | |
7099 /* | |
7100 * When using a multi-line pattern, start searching at the top | |
7101 * of the window or just after a closed fold. | |
1326 | 7102 * Do this both for search_hl and the match list. |
7 | 7103 */ |
1326 | 7104 cur = wp->w_match_head; |
7105 shl_flag = FALSE; | |
7106 while (cur != NULL || shl_flag == FALSE) | |
7107 { | |
7108 if (shl_flag == FALSE) | |
7109 { | |
7110 shl = &search_hl; | |
7111 shl_flag = TRUE; | |
7112 } | |
7113 else | |
7114 shl = &cur->hl; | |
7 | 7115 if (shl->rm.regprog != NULL |
7116 && shl->lnum == 0 | |
7117 && re_multiline(shl->rm.regprog)) | |
7118 { | |
7119 if (shl->first_lnum == 0) | |
7120 { | |
7121 # ifdef FEAT_FOLDING | |
7122 for (shl->first_lnum = lnum; | |
7123 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7124 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7125 NULL, NULL, TRUE, NULL)) | |
7126 break; | |
7127 # else | |
7128 shl->first_lnum = wp->w_topline; | |
7129 # endif | |
7130 } | |
7131 n = 0; | |
7132 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7133 { | |
7134 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7135 if (shl->lnum != 0) | |
7136 { | |
7137 shl->first_lnum = shl->lnum | |
7138 + shl->rm.endpos[0].lnum | |
7139 - shl->rm.startpos[0].lnum; | |
7140 n = shl->rm.endpos[0].col; | |
7141 } | |
7142 else | |
7143 { | |
7144 ++shl->first_lnum; | |
7145 n = 0; | |
7146 } | |
7147 } | |
7148 } | |
1326 | 7149 if (shl != &search_hl && cur != NULL) |
7150 cur = cur->next; | |
7 | 7151 } |
7152 } | |
7153 | |
7154 /* | |
1326 | 7155 * Search for a next 'hlsearch' or match. |
7 | 7156 * Uses shl->buf. |
7157 * Sets shl->lnum and shl->rm contents. | |
7158 * Note: Assumes a previous match is always before "lnum", unless | |
7159 * shl->lnum is zero. | |
7160 * Careful: Any pointers for buffer lines will become invalid. | |
7161 */ | |
7162 static void | |
7163 next_search_hl(win, shl, lnum, mincol) | |
7164 win_T *win; | |
1326 | 7165 match_T *shl; /* points to search_hl or a match */ |
7 | 7166 linenr_T lnum; |
7167 colnr_T mincol; /* minimal column for a match */ | |
7168 { | |
7169 linenr_T l; | |
7170 colnr_T matchcol; | |
7171 long nmatched; | |
7172 | |
7173 if (shl->lnum != 0) | |
7174 { | |
7175 /* Check for three situations: | |
7176 * 1. If the "lnum" is below a previous match, start a new search. | |
7177 * 2. If the previous match includes "mincol", use it. | |
7178 * 3. Continue after the previous match. | |
7179 */ | |
7180 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7181 if (lnum > l) | |
7182 shl->lnum = 0; | |
7183 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7184 return; | |
7185 } | |
7186 | |
7187 /* | |
7188 * Repeat searching for a match until one is found that includes "mincol" | |
7189 * or none is found in this line. | |
7190 */ | |
7191 called_emsg = FALSE; | |
7192 for (;;) | |
7193 { | |
1521 | 7194 #ifdef FEAT_RELTIME |
7195 /* Stop searching after passing the time limit. */ | |
7196 if (profile_passed_limit(&(shl->tm))) | |
7197 { | |
7198 shl->lnum = 0; /* no match found in time */ | |
7199 break; | |
7200 } | |
7201 #endif | |
7 | 7202 /* Three situations: |
7203 * 1. No useful previous match: search from start of line. | |
7204 * 2. Not Vi compatible or empty match: continue at next character. | |
7205 * Break the loop if this is beyond the end of the line. | |
7206 * 3. Vi compatible searching: continue at end of previous match. | |
7207 */ | |
7208 if (shl->lnum == 0) | |
7209 matchcol = 0; | |
7210 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7211 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7212 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7213 { | |
688 | 7214 char_u *ml; |
685 | 7215 |
7216 matchcol = shl->rm.startpos[0].col; | |
688 | 7217 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7218 if (*ml == NUL) |
7219 { | |
7220 ++matchcol; | |
7 | 7221 shl->lnum = 0; |
7222 break; | |
7223 } | |
685 | 7224 #ifdef FEAT_MBYTE |
7225 if (has_mbyte) | |
7226 matchcol += mb_ptr2len(ml); | |
7227 else | |
7228 #endif | |
7229 ++matchcol; | |
7 | 7230 } |
7231 else | |
7232 matchcol = shl->rm.endpos[0].col; | |
7233 | |
7234 shl->lnum = lnum; | |
1521 | 7235 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7236 #ifdef FEAT_RELTIME | |
7237 &(shl->tm) | |
7238 #else | |
7239 NULL | |
7240 #endif | |
7241 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7242 if (called_emsg || got_int) |
7 | 7243 { |
7244 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7245 if (shl == &search_hl) |
7246 { | |
1326 | 7247 /* don't free regprog in the match list, it's a copy */ |
1112 | 7248 vim_free(shl->rm.regprog); |
7249 no_hlsearch = TRUE; | |
7250 } | |
7 | 7251 shl->rm.regprog = NULL; |
1112 | 7252 shl->lnum = 0; |
7253 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7254 break; |
7255 } | |
7256 if (nmatched == 0) | |
7257 { | |
7258 shl->lnum = 0; /* no match found */ | |
7259 break; | |
7260 } | |
7261 if (shl->rm.startpos[0].lnum > 0 | |
7262 || shl->rm.startpos[0].col >= mincol | |
7263 || nmatched > 1 | |
7264 || shl->rm.endpos[0].col > mincol) | |
7265 { | |
7266 shl->lnum += shl->rm.startpos[0].lnum; | |
7267 break; /* useful match found */ | |
7268 } | |
7269 } | |
7270 } | |
7271 #endif | |
7272 | |
7273 static void | |
7274 screen_start_highlight(attr) | |
7275 int attr; | |
7276 { | |
7277 attrentry_T *aep = NULL; | |
7278 | |
7279 screen_attr = attr; | |
7280 if (full_screen | |
7281 #ifdef WIN3264 | |
7282 && termcap_active | |
7283 #endif | |
7284 ) | |
7285 { | |
7286 #ifdef FEAT_GUI | |
7287 if (gui.in_use) | |
7288 { | |
7289 char buf[20]; | |
7290 | |
681 | 7291 /* The GUI handles this internally. */ |
7292 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7293 OUT_STR(buf); |
7294 } | |
7295 else | |
7296 #endif | |
7297 { | |
7298 if (attr > HL_ALL) /* special HL attr. */ | |
7299 { | |
7300 if (t_colors > 1) | |
7301 aep = syn_cterm_attr2entry(attr); | |
7302 else | |
7303 aep = syn_term_attr2entry(attr); | |
7304 if (aep == NULL) /* did ":syntax clear" */ | |
7305 attr = 0; | |
7306 else | |
7307 attr = aep->ae_attr; | |
7308 } | |
7309 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7310 out_str(T_MD); | |
681 | 7311 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7312 && cterm_normal_fg_bold) | |
7313 /* If the Normal FG color has BOLD attribute and the new HL | |
7314 * has a FG color defined, clear BOLD. */ | |
7315 out_str(T_ME); | |
7 | 7316 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7317 out_str(T_SO); | |
205 | 7318 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7319 /* underline or undercurl */ | |
7 | 7320 out_str(T_US); |
7321 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7322 out_str(T_CZH); | |
7323 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7324 out_str(T_MR); | |
7325 | |
7326 /* | |
7327 * Output the color or start string after bold etc., in case the | |
7328 * bold etc. override the color setting. | |
7329 */ | |
7330 if (aep != NULL) | |
7331 { | |
7332 if (t_colors > 1) | |
7333 { | |
7334 if (aep->ae_u.cterm.fg_color) | |
7335 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7336 if (aep->ae_u.cterm.bg_color) | |
7337 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7338 } | |
7339 else | |
7340 { | |
7341 if (aep->ae_u.term.start != NULL) | |
7342 out_str(aep->ae_u.term.start); | |
7343 } | |
7344 } | |
7345 } | |
7346 } | |
7347 } | |
7348 | |
7349 void | |
7350 screen_stop_highlight() | |
7351 { | |
7352 int do_ME = FALSE; /* output T_ME code */ | |
7353 | |
7354 if (screen_attr != 0 | |
7355 #ifdef WIN3264 | |
7356 && termcap_active | |
7357 #endif | |
7358 ) | |
7359 { | |
7360 #ifdef FEAT_GUI | |
7361 if (gui.in_use) | |
7362 { | |
7363 char buf[20]; | |
7364 | |
7365 /* use internal GUI code */ | |
7366 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7367 OUT_STR(buf); | |
7368 } | |
7369 else | |
7370 #endif | |
7371 { | |
7372 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7373 { | |
7374 attrentry_T *aep; | |
7375 | |
7376 if (t_colors > 1) | |
7377 { | |
7378 /* | |
7379 * Assume that t_me restores the original colors! | |
7380 */ | |
7381 aep = syn_cterm_attr2entry(screen_attr); | |
7382 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7383 || aep->ae_u.cterm.bg_color)) | |
7384 do_ME = TRUE; | |
7385 } | |
7386 else | |
7387 { | |
7388 aep = syn_term_attr2entry(screen_attr); | |
7389 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7390 { | |
7391 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7392 do_ME = TRUE; | |
7393 else | |
7394 out_str(aep->ae_u.term.stop); | |
7395 } | |
7396 } | |
7397 if (aep == NULL) /* did ":syntax clear" */ | |
7398 screen_attr = 0; | |
7399 else | |
7400 screen_attr = aep->ae_attr; | |
7401 } | |
7402 | |
7403 /* | |
7404 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7405 * same sequence several times. | |
7406 */ | |
7407 if (screen_attr & HL_STANDOUT) | |
7408 { | |
7409 if (STRCMP(T_SE, T_ME) == 0) | |
7410 do_ME = TRUE; | |
7411 else | |
7412 out_str(T_SE); | |
7413 } | |
205 | 7414 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7415 { |
7416 if (STRCMP(T_UE, T_ME) == 0) | |
7417 do_ME = TRUE; | |
7418 else | |
7419 out_str(T_UE); | |
7420 } | |
7421 if (screen_attr & HL_ITALIC) | |
7422 { | |
7423 if (STRCMP(T_CZR, T_ME) == 0) | |
7424 do_ME = TRUE; | |
7425 else | |
7426 out_str(T_CZR); | |
7427 } | |
7428 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7429 out_str(T_ME); | |
7430 | |
7431 if (t_colors > 1) | |
7432 { | |
7433 /* set Normal cterm colors */ | |
7434 if (cterm_normal_fg_color != 0) | |
7435 term_fg_color(cterm_normal_fg_color - 1); | |
7436 if (cterm_normal_bg_color != 0) | |
7437 term_bg_color(cterm_normal_bg_color - 1); | |
7438 if (cterm_normal_fg_bold) | |
7439 out_str(T_MD); | |
7440 } | |
7441 } | |
7442 } | |
7443 screen_attr = 0; | |
7444 } | |
7445 | |
7446 /* | |
7447 * Reset the colors for a cterm. Used when leaving Vim. | |
7448 * The machine specific code may override this again. | |
7449 */ | |
7450 void | |
7451 reset_cterm_colors() | |
7452 { | |
7453 if (t_colors > 1) | |
7454 { | |
7455 /* set Normal cterm colors */ | |
7456 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7457 { | |
7458 out_str(T_OP); | |
7459 screen_attr = -1; | |
7460 } | |
7461 if (cterm_normal_fg_bold) | |
7462 { | |
7463 out_str(T_ME); | |
7464 screen_attr = -1; | |
7465 } | |
7466 } | |
7467 } | |
7468 | |
7469 /* | |
7470 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7471 * using the attributes from ScreenAttrs["off"]. | |
7472 */ | |
7473 static void | |
7474 screen_char(off, row, col) | |
7475 unsigned off; | |
7476 int row; | |
7477 int col; | |
7478 { | |
7479 int attr; | |
7480 | |
7481 /* Check for illegal values, just in case (could happen just after | |
7482 * resizing). */ | |
7483 if (row >= screen_Rows || col >= screen_Columns) | |
7484 return; | |
7485 | |
7486 /* Outputting the last character on the screen may scrollup the screen. | |
7487 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7488 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7489 #ifdef FEAT_RIGHTLEFT | |
7490 /* account for first command-line character in rightleft mode */ | |
7491 && !cmdmsg_rl | |
7492 #endif | |
7493 ) | |
7494 { | |
7495 ScreenAttrs[off] = (sattr_T)-1; | |
7496 return; | |
7497 } | |
7498 | |
7499 /* | |
7500 * Stop highlighting first, so it's easier to move the cursor. | |
7501 */ | |
7502 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7503 if (screen_char_attr != 0) | |
7504 attr = screen_char_attr; | |
7505 else | |
7506 #endif | |
7507 attr = ScreenAttrs[off]; | |
7508 if (screen_attr != attr) | |
7509 screen_stop_highlight(); | |
7510 | |
7511 windgoto(row, col); | |
7512 | |
7513 if (screen_attr != attr) | |
7514 screen_start_highlight(attr); | |
7515 | |
7516 #ifdef FEAT_MBYTE | |
7517 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7518 { | |
7519 char_u buf[MB_MAXBYTES + 1]; | |
7520 | |
7521 /* Convert UTF-8 character to bytes and write it. */ | |
7522 | |
7523 buf[utfc_char2bytes(off, buf)] = NUL; | |
7524 | |
7525 out_str(buf); | |
7526 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7527 ++screen_cur_col; | |
7528 } | |
7529 else | |
7530 #endif | |
7531 { | |
7532 #ifdef FEAT_MBYTE | |
7533 out_flush_check(); | |
7534 #endif | |
7535 out_char(ScreenLines[off]); | |
7536 #ifdef FEAT_MBYTE | |
7537 /* double-byte character in single-width cell */ | |
7538 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7539 out_char(ScreenLines2[off]); | |
7540 #endif | |
7541 } | |
7542 | |
7543 screen_cur_col++; | |
7544 } | |
7545 | |
7546 #ifdef FEAT_MBYTE | |
7547 | |
7548 /* | |
7549 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7550 * on the screen at position 'row' and 'col'. | |
7551 * The attributes of the first byte is used for all. This is required to | |
7552 * output the two bytes of a double-byte character with nothing in between. | |
7553 */ | |
7554 static void | |
7555 screen_char_2(off, row, col) | |
7556 unsigned off; | |
7557 int row; | |
7558 int col; | |
7559 { | |
7560 /* Check for illegal values (could be wrong when screen was resized). */ | |
7561 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7562 return; | |
7563 | |
7564 /* Outputting the last character on the screen may scrollup the screen. | |
7565 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7566 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7567 { | |
7568 ScreenAttrs[off] = (sattr_T)-1; | |
7569 return; | |
7570 } | |
7571 | |
7572 /* Output the first byte normally (positions the cursor), then write the | |
7573 * second byte directly. */ | |
7574 screen_char(off, row, col); | |
7575 out_char(ScreenLines[off + 1]); | |
7576 ++screen_cur_col; | |
7577 } | |
7578 #endif | |
7579 | |
7580 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7581 /* | |
7582 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7583 * This uses the contents of ScreenLines[] and doesn't change it. | |
7584 */ | |
7585 void | |
7586 screen_draw_rectangle(row, col, height, width, invert) | |
7587 int row; | |
7588 int col; | |
7589 int height; | |
7590 int width; | |
7591 int invert; | |
7592 { | |
7593 int r, c; | |
7594 int off; | |
1378 | 7595 #ifdef FEAT_MBYTE |
7596 int max_off; | |
7597 #endif | |
7 | 7598 |
534 | 7599 /* Can't use ScreenLines unless initialized */ |
7600 if (ScreenLines == NULL) | |
7601 return; | |
7602 | |
7 | 7603 if (invert) |
7604 screen_char_attr = HL_INVERSE; | |
7605 for (r = row; r < row + height; ++r) | |
7606 { | |
7607 off = LineOffset[r]; | |
1378 | 7608 #ifdef FEAT_MBYTE |
7609 max_off = off + screen_Columns; | |
7610 #endif | |
7 | 7611 for (c = col; c < col + width; ++c) |
7612 { | |
7613 #ifdef FEAT_MBYTE | |
1378 | 7614 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7615 { |
7616 screen_char_2(off + c, r, c); | |
7617 ++c; | |
7618 } | |
7619 else | |
7620 #endif | |
7621 { | |
7622 screen_char(off + c, r, c); | |
7623 #ifdef FEAT_MBYTE | |
1378 | 7624 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7625 ++c; |
7626 #endif | |
7627 } | |
7628 } | |
7629 } | |
7630 screen_char_attr = 0; | |
7631 } | |
7632 #endif | |
7633 | |
7634 #ifdef FEAT_VERTSPLIT | |
7635 /* | |
7636 * Redraw the characters for a vertically split window. | |
7637 */ | |
7638 static void | |
7639 redraw_block(row, end, wp) | |
7640 int row; | |
7641 int end; | |
7642 win_T *wp; | |
7643 { | |
7644 int col; | |
7645 int width; | |
7646 | |
7647 # ifdef FEAT_CLIPBOARD | |
7648 clip_may_clear_selection(row, end - 1); | |
7649 # endif | |
7650 | |
7651 if (wp == NULL) | |
7652 { | |
7653 col = 0; | |
7654 width = Columns; | |
7655 } | |
7656 else | |
7657 { | |
7658 col = wp->w_wincol; | |
7659 width = wp->w_width; | |
7660 } | |
7661 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7662 } | |
7663 #endif | |
7664 | |
7665 /* | |
7666 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7667 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7668 * Use attributes 'attr'. | |
7669 */ | |
7670 void | |
7671 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7672 int start_row, end_row; | |
7673 int start_col, end_col; | |
7674 int c1, c2; | |
7675 int attr; | |
7676 { | |
7677 int row; | |
7678 int col; | |
7679 int off; | |
7680 int end_off; | |
7681 int did_delete; | |
7682 int c; | |
7683 int norm_term; | |
7684 #if defined(FEAT_GUI) || defined(UNIX) | |
7685 int force_next = FALSE; | |
7686 #endif | |
7687 | |
7688 if (end_row > screen_Rows) /* safety check */ | |
7689 end_row = screen_Rows; | |
7690 if (end_col > screen_Columns) /* safety check */ | |
7691 end_col = screen_Columns; | |
7692 if (ScreenLines == NULL | |
7693 || start_row >= end_row | |
7694 || start_col >= end_col) /* nothing to do */ | |
7695 return; | |
7696 | |
7697 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7698 norm_term = ( | |
7699 #ifdef FEAT_GUI | |
7700 !gui.in_use && | |
7701 #endif | |
7702 t_colors <= 1); | |
7703 for (row = start_row; row < end_row; ++row) | |
7704 { | |
1668 | 7705 #ifdef FEAT_MBYTE |
7706 if (has_mbyte | |
7707 # ifdef FEAT_GUI | |
7708 && !gui.in_use | |
7709 # endif | |
7710 ) | |
7711 { | |
7712 /* When drawing over the right halve of a double-wide char clear | |
7713 * out the left halve. When drawing over the left halve of a | |
7714 * double wide-char clear out the right halve. Only needed in a | |
7715 * terminal. */ | |
1685 | 7716 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7717 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7718 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7719 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7720 } |
7721 #endif | |
7 | 7722 /* |
7723 * Try to use delete-line termcap code, when no attributes or in a | |
7724 * "normal" terminal, where a bold/italic space is just a | |
7725 * space. | |
7726 */ | |
7727 did_delete = FALSE; | |
7728 if (c2 == ' ' | |
7729 && end_col == Columns | |
7730 && can_clear(T_CE) | |
7731 && (attr == 0 | |
7732 || (norm_term | |
7733 && attr <= HL_ALL | |
7734 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7735 { | |
7736 /* | |
7737 * check if we really need to clear something | |
7738 */ | |
7739 col = start_col; | |
7740 if (c1 != ' ') /* don't clear first char */ | |
7741 ++col; | |
7742 | |
7743 off = LineOffset[row] + col; | |
7744 end_off = LineOffset[row] + end_col; | |
7745 | |
7746 /* skip blanks (used often, keep it fast!) */ | |
7747 #ifdef FEAT_MBYTE | |
7748 if (enc_utf8) | |
7749 while (off < end_off && ScreenLines[off] == ' ' | |
7750 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7751 ++off; | |
7752 else | |
7753 #endif | |
7754 while (off < end_off && ScreenLines[off] == ' ' | |
7755 && ScreenAttrs[off] == 0) | |
7756 ++off; | |
7757 if (off < end_off) /* something to be cleared */ | |
7758 { | |
7759 col = off - LineOffset[row]; | |
7760 screen_stop_highlight(); | |
7761 term_windgoto(row, col);/* clear rest of this screen line */ | |
7762 out_str(T_CE); | |
7763 screen_start(); /* don't know where cursor is now */ | |
7764 col = end_col - col; | |
7765 while (col--) /* clear chars in ScreenLines */ | |
7766 { | |
7767 ScreenLines[off] = ' '; | |
7768 #ifdef FEAT_MBYTE | |
7769 if (enc_utf8) | |
7770 ScreenLinesUC[off] = 0; | |
7771 #endif | |
7772 ScreenAttrs[off] = 0; | |
7773 ++off; | |
7774 } | |
7775 } | |
7776 did_delete = TRUE; /* the chars are cleared now */ | |
7777 } | |
7778 | |
7779 off = LineOffset[row] + start_col; | |
7780 c = c1; | |
7781 for (col = start_col; col < end_col; ++col) | |
7782 { | |
7783 if (ScreenLines[off] != c | |
7784 #ifdef FEAT_MBYTE | |
714 | 7785 || (enc_utf8 && (int)ScreenLinesUC[off] |
7786 != (c >= 0x80 ? c : 0)) | |
7 | 7787 #endif |
7788 || ScreenAttrs[off] != attr | |
7789 #if defined(FEAT_GUI) || defined(UNIX) | |
7790 || force_next | |
7791 #endif | |
7792 ) | |
7793 { | |
7794 #if defined(FEAT_GUI) || defined(UNIX) | |
7795 /* The bold trick may make a single row of pixels appear in | |
7796 * the next character. When a bold character is removed, the | |
7797 * next character should be redrawn too. This happens for our | |
7798 * own GUI and for some xterms. */ | |
7799 if ( | |
7800 # ifdef FEAT_GUI | |
7801 gui.in_use | |
7802 # endif | |
7803 # if defined(FEAT_GUI) && defined(UNIX) | |
7804 || | |
7805 # endif | |
7806 # ifdef UNIX | |
7807 term_is_xterm | |
7808 # endif | |
7809 ) | |
7810 { | |
7811 if (ScreenLines[off] != ' ' | |
7812 && (ScreenAttrs[off] > HL_ALL | |
7813 || ScreenAttrs[off] & HL_BOLD)) | |
7814 force_next = TRUE; | |
7815 else | |
7816 force_next = FALSE; | |
7817 } | |
7818 #endif | |
7819 ScreenLines[off] = c; | |
7820 #ifdef FEAT_MBYTE | |
7821 if (enc_utf8) | |
7822 { | |
7823 if (c >= 0x80) | |
7824 { | |
7825 ScreenLinesUC[off] = c; | |
714 | 7826 ScreenLinesC[0][off] = 0; |
7 | 7827 } |
7828 else | |
7829 ScreenLinesUC[off] = 0; | |
7830 } | |
7831 #endif | |
7832 ScreenAttrs[off] = attr; | |
7833 if (!did_delete || c != ' ') | |
7834 screen_char(off, row, col); | |
7835 } | |
7836 ++off; | |
7837 if (col == start_col) | |
7838 { | |
7839 if (did_delete) | |
7840 break; | |
7841 c = c2; | |
7842 } | |
7843 } | |
7844 if (end_col == Columns) | |
7845 LineWraps[row] = FALSE; | |
7846 if (row == Rows - 1) /* overwritten the command line */ | |
7847 { | |
7848 redraw_cmdline = TRUE; | |
7849 if (c1 == ' ' && c2 == ' ') | |
7850 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7851 if (start_col == 0) |
7852 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7853 } |
7854 } | |
7855 } | |
7856 | |
7857 /* | |
7858 * Check if there should be a delay. Used before clearing or redrawing the | |
7859 * screen or the command line. | |
7860 */ | |
7861 void | |
7862 check_for_delay(check_msg_scroll) | |
7863 int check_msg_scroll; | |
7864 { | |
7865 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7866 && !did_wait_return | |
7867 && emsg_silent == 0) | |
7868 { | |
7869 out_flush(); | |
7870 ui_delay(1000L, TRUE); | |
7871 emsg_on_display = FALSE; | |
7872 if (check_msg_scroll) | |
7873 msg_scroll = FALSE; | |
7874 } | |
7875 } | |
7876 | |
7877 /* | |
7878 * screen_valid - allocate screen buffers if size changed | |
3263 | 7879 * If "doclear" is TRUE: clear screen if it has been resized. |
7 | 7880 * Returns TRUE if there is a valid screen to write to. |
7881 * Returns FALSE when starting up and screen not initialized yet. | |
7882 */ | |
7883 int | |
3263 | 7884 screen_valid(doclear) |
7885 int doclear; | |
7 | 7886 { |
3263 | 7887 screenalloc(doclear); /* allocate screen buffers if size changed */ |
7 | 7888 return (ScreenLines != NULL); |
7889 } | |
7890 | |
7891 /* | |
7892 * Resize the shell to Rows and Columns. | |
7893 * Allocate ScreenLines[] and associated items. | |
7894 * | |
7895 * There may be some time between setting Rows and Columns and (re)allocating | |
7896 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7897 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7898 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7899 * final size of the shell is needed. | |
7900 */ | |
7901 void | |
3263 | 7902 screenalloc(doclear) |
7903 int doclear; | |
7 | 7904 { |
7905 int new_row, old_row; | |
7906 #ifdef FEAT_GUI | |
7907 int old_Rows; | |
7908 #endif | |
7909 win_T *wp; | |
7910 int outofmem = FALSE; | |
7911 int len; | |
7912 schar_T *new_ScreenLines; | |
7913 #ifdef FEAT_MBYTE | |
7914 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7915 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7916 schar_T *new_ScreenLines2 = NULL; |
714 | 7917 int i; |
7 | 7918 #endif |
7919 sattr_T *new_ScreenAttrs; | |
7920 unsigned *new_LineOffset; | |
7921 char_u *new_LineWraps; | |
671 | 7922 #ifdef FEAT_WINDOWS |
681 | 7923 short *new_TabPageIdxs; |
671 | 7924 tabpage_T *tp; |
7925 #endif | |
7 | 7926 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7927 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7928 #ifdef FEAT_AUTOCMD |
7929 int retry_count = 0; | |
7930 | |
7931 retry: | |
7932 #endif | |
7 | 7933 /* |
7934 * Allocation of the screen buffers is done only when the size changes and | |
7935 * when Rows and Columns have been set and we have started doing full | |
7936 * screen stuff. | |
7937 */ | |
7938 if ((ScreenLines != NULL | |
7939 && Rows == screen_Rows | |
7940 && Columns == screen_Columns | |
7941 #ifdef FEAT_MBYTE | |
7942 && enc_utf8 == (ScreenLinesUC != NULL) | |
7943 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7944 && p_mco == Screen_mco |
7 | 7945 #endif |
7946 ) | |
7947 || Rows == 0 | |
7948 || Columns == 0 | |
7949 || (!full_screen && ScreenLines == NULL)) | |
7950 return; | |
7951 | |
7952 /* | |
7953 * It's possible that we produce an out-of-memory message below, which | |
7954 * will cause this function to be called again. To break the loop, just | |
7955 * return here. | |
7956 */ | |
7957 if (entered) | |
7958 return; | |
7959 entered = TRUE; | |
7960 | |
911 | 7961 /* |
7962 * Note that the window sizes are updated before reallocating the arrays, | |
7963 * thus we must not redraw here! | |
7964 */ | |
7965 ++RedrawingDisabled; | |
7966 | |
7 | 7967 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7968 | |
7969 comp_col(); /* recompute columns for shown command and ruler */ | |
7970 | |
7971 /* | |
7972 * We're changing the size of the screen. | |
7973 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7974 * - Move lines from the old arrays into the new arrays, clear extra | |
7975 * lines (unless the screen is going to be cleared). | |
7976 * - Free the old arrays. | |
7977 * | |
7978 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7979 * Continuing with the old ScreenLines may result in a crash, because the | |
7980 * size is wrong. | |
7981 */ | |
671 | 7982 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7983 win_free_lsize(wp); |
1946 | 7984 #ifdef FEAT_AUTOCMD |
7985 if (aucmd_win != NULL) | |
7986 win_free_lsize(aucmd_win); | |
7987 #endif | |
7 | 7988 |
7989 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7990 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7991 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7992 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7993 if (enc_utf8) |
7994 { | |
7995 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7996 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7997 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7998 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7999 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
8000 } | |
8001 if (enc_dbcs == DBCS_JPNU) | |
8002 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
8003 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
8004 #endif | |
8005 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
8006 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
8007 new_LineOffset = (unsigned *)lalloc((long_u)( | |
8008 Rows * sizeof(unsigned)), FALSE); | |
8009 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 8010 #ifdef FEAT_WINDOWS |
681 | 8011 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 8012 #endif |
7 | 8013 |
677 | 8014 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 8015 { |
8016 if (win_alloc_lines(wp) == FAIL) | |
8017 { | |
8018 outofmem = TRUE; | |
8019 #ifdef FEAT_WINDOWS | |
1819 | 8020 goto give_up; |
8021 #endif | |
8022 } | |
8023 } | |
1906 | 8024 #ifdef FEAT_AUTOCMD |
1946 | 8025 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
8026 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 8027 outofmem = TRUE; |
8028 #endif | |
1819 | 8029 #ifdef FEAT_WINDOWS |
8030 give_up: | |
8031 #endif | |
7 | 8032 |
714 | 8033 #ifdef FEAT_MBYTE |
8034 for (i = 0; i < p_mco; ++i) | |
8035 if (new_ScreenLinesC[i] == NULL) | |
8036 break; | |
8037 #endif | |
7 | 8038 if (new_ScreenLines == NULL |
8039 #ifdef FEAT_MBYTE | |
714 | 8040 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 8041 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
8042 #endif | |
8043 || new_ScreenAttrs == NULL | |
8044 || new_LineOffset == NULL | |
8045 || new_LineWraps == NULL | |
671 | 8046 #ifdef FEAT_WINDOWS |
8047 || new_TabPageIdxs == NULL | |
8048 #endif | |
7 | 8049 || outofmem) |
8050 { | |
944 | 8051 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 8052 { |
8053 /* guess the size */ | |
8054 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
8055 | |
8056 /* Remember we did this to avoid getting outofmem messages over | |
8057 * and over again. */ | |
944 | 8058 done_outofmem_msg = TRUE; |
534 | 8059 } |
7 | 8060 vim_free(new_ScreenLines); |
8061 new_ScreenLines = NULL; | |
8062 #ifdef FEAT_MBYTE | |
8063 vim_free(new_ScreenLinesUC); | |
8064 new_ScreenLinesUC = NULL; | |
714 | 8065 for (i = 0; i < p_mco; ++i) |
8066 { | |
8067 vim_free(new_ScreenLinesC[i]); | |
8068 new_ScreenLinesC[i] = NULL; | |
8069 } | |
7 | 8070 vim_free(new_ScreenLines2); |
8071 new_ScreenLines2 = NULL; | |
8072 #endif | |
8073 vim_free(new_ScreenAttrs); | |
8074 new_ScreenAttrs = NULL; | |
8075 vim_free(new_LineOffset); | |
8076 new_LineOffset = NULL; | |
8077 vim_free(new_LineWraps); | |
8078 new_LineWraps = NULL; | |
671 | 8079 #ifdef FEAT_WINDOWS |
8080 vim_free(new_TabPageIdxs); | |
8081 new_TabPageIdxs = NULL; | |
8082 #endif | |
7 | 8083 } |
8084 else | |
8085 { | |
944 | 8086 done_outofmem_msg = FALSE; |
534 | 8087 |
7 | 8088 for (new_row = 0; new_row < Rows; ++new_row) |
8089 { | |
8090 new_LineOffset[new_row] = new_row * Columns; | |
8091 new_LineWraps[new_row] = FALSE; | |
8092 | |
8093 /* | |
8094 * If the screen is not going to be cleared, copy as much as | |
8095 * possible from the old screen to the new one and clear the rest | |
8096 * (used when resizing the window at the "--more--" prompt or when | |
8097 * executing an external command, for the GUI). | |
8098 */ | |
3263 | 8099 if (!doclear) |
7 | 8100 { |
8101 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
8102 ' ', (size_t)Columns * sizeof(schar_T)); | |
8103 #ifdef FEAT_MBYTE | |
8104 if (enc_utf8) | |
8105 { | |
8106 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
8107 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 8108 for (i = 0; i < p_mco; ++i) |
8109 (void)vim_memset(new_ScreenLinesC[i] | |
8110 + new_row * Columns, | |
7 | 8111 0, (size_t)Columns * sizeof(u8char_T)); |
8112 } | |
8113 if (enc_dbcs == DBCS_JPNU) | |
8114 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8115 0, (size_t)Columns * sizeof(schar_T)); | |
8116 #endif | |
8117 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8118 0, (size_t)Columns * sizeof(sattr_T)); | |
8119 old_row = new_row + (screen_Rows - Rows); | |
534 | 8120 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8121 { |
8122 if (screen_Columns < Columns) | |
8123 len = screen_Columns; | |
8124 else | |
8125 len = Columns; | |
26 | 8126 #ifdef FEAT_MBYTE |
571 | 8127 /* When switching to utf-8 don't copy characters, they |
714 | 8128 * may be invalid now. Also when p_mco changes. */ |
8129 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8130 && p_mco == Screen_mco) | |
26 | 8131 #endif |
8132 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8133 ScreenLines + LineOffset[old_row], | |
8134 (size_t)len * sizeof(schar_T)); | |
7 | 8135 #ifdef FEAT_MBYTE |
714 | 8136 if (enc_utf8 && ScreenLinesUC != NULL |
8137 && p_mco == Screen_mco) | |
7 | 8138 { |
8139 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8140 ScreenLinesUC + LineOffset[old_row], | |
8141 (size_t)len * sizeof(u8char_T)); | |
714 | 8142 for (i = 0; i < p_mco; ++i) |
8143 mch_memmove(new_ScreenLinesC[i] | |
8144 + new_LineOffset[new_row], | |
8145 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8146 (size_t)len * sizeof(u8char_T)); |
8147 } | |
8148 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8149 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8150 ScreenLines2 + LineOffset[old_row], | |
8151 (size_t)len * sizeof(schar_T)); | |
8152 #endif | |
8153 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8154 ScreenAttrs + LineOffset[old_row], | |
8155 (size_t)len * sizeof(sattr_T)); | |
8156 } | |
8157 } | |
8158 } | |
8159 /* Use the last line of the screen for the current line. */ | |
8160 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8161 } | |
8162 | |
356 | 8163 free_screenlines(); |
8164 | |
7 | 8165 ScreenLines = new_ScreenLines; |
8166 #ifdef FEAT_MBYTE | |
8167 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8168 for (i = 0; i < p_mco; ++i) |
8169 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8170 Screen_mco = p_mco; | |
7 | 8171 ScreenLines2 = new_ScreenLines2; |
8172 #endif | |
8173 ScreenAttrs = new_ScreenAttrs; | |
8174 LineOffset = new_LineOffset; | |
8175 LineWraps = new_LineWraps; | |
671 | 8176 #ifdef FEAT_WINDOWS |
8177 TabPageIdxs = new_TabPageIdxs; | |
8178 #endif | |
7 | 8179 |
8180 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8181 * size of ScreenLines[]. Set them before calling anything. */ | |
8182 #ifdef FEAT_GUI | |
8183 old_Rows = screen_Rows; | |
8184 #endif | |
8185 screen_Rows = Rows; | |
8186 screen_Columns = Columns; | |
8187 | |
8188 must_redraw = CLEAR; /* need to clear the screen later */ | |
3263 | 8189 if (doclear) |
7 | 8190 screenclear2(); |
8191 | |
8192 #ifdef FEAT_GUI | |
8193 else if (gui.in_use | |
8194 && !gui.starting | |
8195 && ScreenLines != NULL | |
8196 && old_Rows != Rows) | |
8197 { | |
8198 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8199 /* | |
8200 * Adjust the position of the cursor, for when executing an external | |
8201 * command. | |
8202 */ | |
8203 if (msg_row >= Rows) /* Rows got smaller */ | |
8204 msg_row = Rows - 1; /* put cursor at last row */ | |
8205 else if (Rows > old_Rows) /* Rows got bigger */ | |
8206 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8207 if (msg_col >= Columns) /* Columns got smaller */ | |
8208 msg_col = Columns - 1; /* put cursor at last column */ | |
8209 } | |
8210 #endif | |
8211 | |
8212 entered = FALSE; | |
911 | 8213 --RedrawingDisabled; |
766 | 8214 |
8215 #ifdef FEAT_AUTOCMD | |
1824 | 8216 /* |
8217 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8218 * in case applying autocommands always changes Rows or Columns. | |
8219 */ | |
8220 if (starting == 0 && ++retry_count <= 3) | |
8221 { | |
766 | 8222 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8223 /* In rare cases, autocommands may have altered Rows or Columns, |
8224 * jump back to check if we need to allocate the screen again. */ | |
8225 goto retry; | |
8226 } | |
766 | 8227 #endif |
7 | 8228 } |
8229 | |
8230 void | |
356 | 8231 free_screenlines() |
8232 { | |
8233 #ifdef FEAT_MBYTE | |
714 | 8234 int i; |
8235 | |
356 | 8236 vim_free(ScreenLinesUC); |
714 | 8237 for (i = 0; i < Screen_mco; ++i) |
8238 vim_free(ScreenLinesC[i]); | |
356 | 8239 vim_free(ScreenLines2); |
8240 #endif | |
714 | 8241 vim_free(ScreenLines); |
356 | 8242 vim_free(ScreenAttrs); |
8243 vim_free(LineOffset); | |
8244 vim_free(LineWraps); | |
671 | 8245 #ifdef FEAT_WINDOWS |
8246 vim_free(TabPageIdxs); | |
8247 #endif | |
356 | 8248 } |
8249 | |
8250 void | |
7 | 8251 screenclear() |
8252 { | |
8253 check_for_delay(FALSE); | |
8254 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8255 screenclear2(); /* clear the screen */ | |
8256 } | |
8257 | |
8258 static void | |
8259 screenclear2() | |
8260 { | |
8261 int i; | |
8262 | |
8263 if (starting == NO_SCREEN || ScreenLines == NULL | |
8264 #ifdef FEAT_GUI | |
8265 || (gui.in_use && gui.starting) | |
8266 #endif | |
8267 ) | |
8268 return; | |
8269 | |
8270 #ifdef FEAT_GUI | |
8271 if (!gui.in_use) | |
8272 #endif | |
8273 screen_attr = -1; /* force setting the Normal colors */ | |
8274 screen_stop_highlight(); /* don't want highlighting here */ | |
8275 | |
8276 #ifdef FEAT_CLIPBOARD | |
8277 /* disable selection without redrawing it */ | |
8278 clip_scroll_selection(9999); | |
8279 #endif | |
8280 | |
8281 /* blank out ScreenLines */ | |
8282 for (i = 0; i < Rows; ++i) | |
8283 { | |
8284 lineclear(LineOffset[i], (int)Columns); | |
8285 LineWraps[i] = FALSE; | |
8286 } | |
8287 | |
8288 if (can_clear(T_CL)) | |
8289 { | |
8290 out_str(T_CL); /* clear the display */ | |
8291 clear_cmdline = FALSE; | |
644 | 8292 mode_displayed = FALSE; |
7 | 8293 } |
8294 else | |
8295 { | |
8296 /* can't clear the screen, mark all chars with invalid attributes */ | |
8297 for (i = 0; i < Rows; ++i) | |
8298 lineinvalid(LineOffset[i], (int)Columns); | |
8299 clear_cmdline = TRUE; | |
8300 } | |
8301 | |
8302 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8303 | |
8304 win_rest_invalid(firstwin); | |
8305 redraw_cmdline = TRUE; | |
670 | 8306 #ifdef FEAT_WINDOWS |
673 | 8307 redraw_tabline = TRUE; |
670 | 8308 #endif |
7 | 8309 if (must_redraw == CLEAR) /* no need to clear again */ |
8310 must_redraw = NOT_VALID; | |
8311 compute_cmdrow(); | |
8312 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8313 msg_col = 0; | |
8314 screen_start(); /* don't know where cursor is now */ | |
8315 msg_scrolled = 0; /* can't scroll back */ | |
8316 msg_didany = FALSE; | |
8317 msg_didout = FALSE; | |
8318 } | |
8319 | |
8320 /* | |
8321 * Clear one line in ScreenLines. | |
8322 */ | |
8323 static void | |
8324 lineclear(off, width) | |
8325 unsigned off; | |
8326 int width; | |
8327 { | |
8328 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8329 #ifdef FEAT_MBYTE | |
8330 if (enc_utf8) | |
8331 (void)vim_memset(ScreenLinesUC + off, 0, | |
8332 (size_t)width * sizeof(u8char_T)); | |
8333 #endif | |
8334 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8335 } | |
8336 | |
8337 /* | |
8338 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8339 * invalid value. | |
8340 */ | |
8341 static void | |
8342 lineinvalid(off, width) | |
8343 unsigned off; | |
8344 int width; | |
8345 { | |
8346 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8347 } | |
8348 | |
8349 #ifdef FEAT_VERTSPLIT | |
8350 /* | |
8351 * Copy part of a Screenline for vertically split window "wp". | |
8352 */ | |
8353 static void | |
8354 linecopy(to, from, wp) | |
8355 int to; | |
8356 int from; | |
8357 win_T *wp; | |
8358 { | |
8359 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8360 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8361 | |
8362 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8363 wp->w_width * sizeof(schar_T)); | |
8364 # ifdef FEAT_MBYTE | |
8365 if (enc_utf8) | |
8366 { | |
714 | 8367 int i; |
8368 | |
7 | 8369 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8370 wp->w_width * sizeof(u8char_T)); | |
714 | 8371 for (i = 0; i < p_mco; ++i) |
8372 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8373 wp->w_width * sizeof(u8char_T)); | |
7 | 8374 } |
8375 if (enc_dbcs == DBCS_JPNU) | |
8376 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8377 wp->w_width * sizeof(schar_T)); | |
8378 # endif | |
8379 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8380 wp->w_width * sizeof(sattr_T)); | |
8381 } | |
8382 #endif | |
8383 | |
8384 /* | |
8385 * Return TRUE if clearing with term string "p" would work. | |
8386 * It can't work when the string is empty or it won't set the right background. | |
8387 */ | |
8388 int | |
8389 can_clear(p) | |
8390 char_u *p; | |
8391 { | |
8392 return (*p != NUL && (t_colors <= 1 | |
8393 #ifdef FEAT_GUI | |
8394 || gui.in_use | |
8395 #endif | |
8396 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8397 } | |
8398 | |
8399 /* | |
8400 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8401 * something directly to the screen (shell commands) or a terminal control | |
8402 * code. | |
8403 */ | |
8404 void | |
8405 screen_start() | |
8406 { | |
8407 screen_cur_row = screen_cur_col = 9999; | |
8408 } | |
8409 | |
8410 /* | |
8411 * Move the cursor to position "row","col" in the screen. | |
8412 * This tries to find the most efficient way to move, minimizing the number of | |
8413 * characters sent to the terminal. | |
8414 */ | |
8415 void | |
8416 windgoto(row, col) | |
8417 int row; | |
8418 int col; | |
8419 { | |
205 | 8420 sattr_T *p; |
7 | 8421 int i; |
8422 int plan; | |
8423 int cost; | |
8424 int wouldbe_col; | |
8425 int noinvcurs; | |
8426 char_u *bs; | |
8427 int goto_cost; | |
8428 int attr; | |
8429 | |
1213 | 8430 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8431 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8432 | |
8433 #define PLAN_LE 1 | |
8434 #define PLAN_CR 2 | |
8435 #define PLAN_NL 3 | |
8436 #define PLAN_WRITE 4 | |
8437 /* Can't use ScreenLines unless initialized */ | |
8438 if (ScreenLines == NULL) | |
8439 return; | |
8440 | |
8441 if (col != screen_cur_col || row != screen_cur_row) | |
8442 { | |
8443 /* Check for valid position. */ | |
8444 if (row < 0) /* window without text lines? */ | |
8445 row = 0; | |
8446 if (row >= screen_Rows) | |
8447 row = screen_Rows - 1; | |
8448 if (col >= screen_Columns) | |
8449 col = screen_Columns - 1; | |
8450 | |
8451 /* check if no cursor movement is allowed in highlight mode */ | |
8452 if (screen_attr && *T_MS == NUL) | |
8453 noinvcurs = HIGHL_COST; | |
8454 else | |
8455 noinvcurs = 0; | |
8456 goto_cost = GOTO_COST + noinvcurs; | |
8457 | |
8458 /* | |
8459 * Plan how to do the positioning: | |
8460 * 1. Use CR to move it to column 0, same row. | |
8461 * 2. Use T_LE to move it a few columns to the left. | |
8462 * 3. Use NL to move a few lines down, column 0. | |
8463 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8464 * | |
8465 * Don't do this if the cursor went beyond the last column, the cursor | |
8466 * position is unknown then (some terminals wrap, some don't ) | |
8467 * | |
1213 | 8468 * First check if the highlighting attributes allow us to write |
7 | 8469 * characters to move the cursor to the right. |
8470 */ | |
8471 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8472 { | |
8473 /* | |
8474 * If the cursor is in the same row, bigger col, we can use CR | |
8475 * or T_LE. | |
8476 */ | |
8477 bs = NULL; /* init for GCC */ | |
8478 attr = screen_attr; | |
8479 if (row == screen_cur_row && col < screen_cur_col) | |
8480 { | |
8481 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8482 if (*T_LE) | |
8483 bs = T_LE; /* "cursor left" */ | |
8484 else | |
8485 bs = T_BC; /* "backspace character (old) */ | |
8486 if (*bs) | |
8487 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8488 else | |
8489 cost = 999; | |
8490 if (col + 1 < cost) /* using CR is less characters */ | |
8491 { | |
8492 plan = PLAN_CR; | |
8493 wouldbe_col = 0; | |
8494 cost = 1; /* CR is just one character */ | |
8495 } | |
8496 else | |
8497 { | |
8498 plan = PLAN_LE; | |
8499 wouldbe_col = col; | |
8500 } | |
8501 if (noinvcurs) /* will stop highlighting */ | |
8502 { | |
8503 cost += noinvcurs; | |
8504 attr = 0; | |
8505 } | |
8506 } | |
8507 | |
8508 /* | |
8509 * If the cursor is above where we want to be, we can use CR LF. | |
8510 */ | |
8511 else if (row > screen_cur_row) | |
8512 { | |
8513 plan = PLAN_NL; | |
8514 wouldbe_col = 0; | |
8515 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8516 if (noinvcurs) /* will stop highlighting */ | |
8517 { | |
8518 cost += noinvcurs; | |
8519 attr = 0; | |
8520 } | |
8521 } | |
8522 | |
8523 /* | |
8524 * If the cursor is in the same row, smaller col, just use write. | |
8525 */ | |
8526 else | |
8527 { | |
8528 plan = PLAN_WRITE; | |
8529 wouldbe_col = screen_cur_col; | |
8530 cost = 0; | |
8531 } | |
8532 | |
8533 /* | |
8534 * Check if any characters that need to be written have the | |
8535 * correct attributes. Also avoid UTF-8 characters. | |
8536 */ | |
8537 i = col - wouldbe_col; | |
8538 if (i > 0) | |
8539 cost += i; | |
8540 if (cost < goto_cost && i > 0) | |
8541 { | |
8542 /* | |
8543 * Check if the attributes are correct without additionally | |
8544 * stopping highlighting. | |
8545 */ | |
8546 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8547 while (i && *p++ == attr) | |
8548 --i; | |
8549 if (i != 0) | |
8550 { | |
8551 /* | |
8552 * Try if it works when highlighting is stopped here. | |
8553 */ | |
8554 if (*--p == 0) | |
8555 { | |
8556 cost += noinvcurs; | |
8557 while (i && *p++ == 0) | |
8558 --i; | |
8559 } | |
8560 if (i != 0) | |
8561 cost = 999; /* different attributes, don't do it */ | |
8562 } | |
8563 #ifdef FEAT_MBYTE | |
8564 if (enc_utf8) | |
8565 { | |
8566 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8567 for (i = wouldbe_col; i < col; ++i) | |
8568 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8569 { | |
8570 cost = 999; | |
8571 break; | |
8572 } | |
8573 } | |
8574 #endif | |
8575 } | |
8576 | |
8577 /* | |
8578 * We can do it without term_windgoto()! | |
8579 */ | |
8580 if (cost < goto_cost) | |
8581 { | |
8582 if (plan == PLAN_LE) | |
8583 { | |
8584 if (noinvcurs) | |
8585 screen_stop_highlight(); | |
8586 while (screen_cur_col > col) | |
8587 { | |
8588 out_str(bs); | |
8589 --screen_cur_col; | |
8590 } | |
8591 } | |
8592 else if (plan == PLAN_CR) | |
8593 { | |
8594 if (noinvcurs) | |
8595 screen_stop_highlight(); | |
8596 out_char('\r'); | |
8597 screen_cur_col = 0; | |
8598 } | |
8599 else if (plan == PLAN_NL) | |
8600 { | |
8601 if (noinvcurs) | |
8602 screen_stop_highlight(); | |
8603 while (screen_cur_row < row) | |
8604 { | |
8605 out_char('\n'); | |
8606 ++screen_cur_row; | |
8607 } | |
8608 screen_cur_col = 0; | |
8609 } | |
8610 | |
8611 i = col - screen_cur_col; | |
8612 if (i > 0) | |
8613 { | |
8614 /* | |
8615 * Use cursor-right if it's one character only. Avoids | |
8616 * removing a line of pixels from the last bold char, when | |
8617 * using the bold trick in the GUI. | |
8618 */ | |
8619 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8620 { | |
8621 while (i-- > 0) | |
8622 out_char(*T_ND); | |
8623 } | |
8624 else | |
8625 { | |
8626 int off; | |
8627 | |
8628 off = LineOffset[row] + screen_cur_col; | |
8629 while (i-- > 0) | |
8630 { | |
8631 if (ScreenAttrs[off] != screen_attr) | |
8632 screen_stop_highlight(); | |
8633 #ifdef FEAT_MBYTE | |
8634 out_flush_check(); | |
8635 #endif | |
8636 out_char(ScreenLines[off]); | |
8637 #ifdef FEAT_MBYTE | |
8638 if (enc_dbcs == DBCS_JPNU | |
8639 && ScreenLines[off] == 0x8e) | |
8640 out_char(ScreenLines2[off]); | |
8641 #endif | |
8642 ++off; | |
8643 } | |
8644 } | |
8645 } | |
8646 } | |
8647 } | |
8648 else | |
8649 cost = 999; | |
8650 | |
8651 if (cost >= goto_cost) | |
8652 { | |
8653 if (noinvcurs) | |
8654 screen_stop_highlight(); | |
8655 if (row == screen_cur_row && (col > screen_cur_col) && | |
8656 *T_CRI != NUL) | |
8657 term_cursor_right(col - screen_cur_col); | |
8658 else | |
8659 term_windgoto(row, col); | |
8660 } | |
8661 screen_cur_row = row; | |
8662 screen_cur_col = col; | |
8663 } | |
8664 } | |
8665 | |
8666 /* | |
8667 * Set cursor to its position in the current window. | |
8668 */ | |
8669 void | |
8670 setcursor() | |
8671 { | |
8672 if (redrawing()) | |
8673 { | |
8674 validate_cursor(); | |
8675 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8676 W_WINCOL(curwin) + ( | |
8677 #ifdef FEAT_RIGHTLEFT | |
1545 | 8678 /* With 'rightleft' set and the cursor on a double-wide |
8679 * character, position it on the leftmost column. */ | |
7 | 8680 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8681 # ifdef FEAT_MBYTE | |
1545 | 8682 (has_mbyte |
8683 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8684 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8685 # endif |
8686 1)) : | |
8687 #endif | |
8688 curwin->w_wcol)); | |
8689 } | |
8690 } | |
8691 | |
8692 | |
8693 /* | |
8694 * insert 'line_count' lines at 'row' in window 'wp' | |
8695 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8696 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8697 * scrolling. | |
8698 * Returns FAIL if the lines are not inserted, OK for success. | |
8699 */ | |
8700 int | |
8701 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8702 win_T *wp; | |
8703 int row; | |
8704 int line_count; | |
8705 int invalid; | |
8706 int mayclear; | |
8707 { | |
8708 int did_delete; | |
8709 int nextrow; | |
8710 int lastrow; | |
8711 int retval; | |
8712 | |
8713 if (invalid) | |
8714 wp->w_lines_valid = 0; | |
8715 | |
8716 if (wp->w_height < 5) | |
8717 return FAIL; | |
8718 | |
8719 if (line_count > wp->w_height - row) | |
8720 line_count = wp->w_height - row; | |
8721 | |
8722 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8723 if (retval != MAYBE) | |
8724 return retval; | |
8725 | |
8726 /* | |
8727 * If there is a next window or a status line, we first try to delete the | |
8728 * lines at the bottom to avoid messing what is after the window. | |
8729 * If this fails and there are following windows, don't do anything to avoid | |
8730 * messing up those windows, better just redraw. | |
8731 */ | |
8732 did_delete = FALSE; | |
8733 #ifdef FEAT_WINDOWS | |
8734 if (wp->w_next != NULL || wp->w_status_height) | |
8735 { | |
8736 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8737 line_count, (int)Rows, FALSE, NULL) == OK) | |
8738 did_delete = TRUE; | |
8739 else if (wp->w_next) | |
8740 return FAIL; | |
8741 } | |
8742 #endif | |
8743 /* | |
8744 * if no lines deleted, blank the lines that will end up below the window | |
8745 */ | |
8746 if (!did_delete) | |
8747 { | |
8748 #ifdef FEAT_WINDOWS | |
8749 wp->w_redr_status = TRUE; | |
8750 #endif | |
8751 redraw_cmdline = TRUE; | |
8752 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8753 lastrow = nextrow + line_count; | |
8754 if (lastrow > Rows) | |
8755 lastrow = Rows; | |
8756 screen_fill(nextrow - line_count, lastrow - line_count, | |
8757 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8758 ' ', ' ', 0); | |
8759 } | |
8760 | |
8761 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8762 == FAIL) | |
8763 { | |
8764 /* deletion will have messed up other windows */ | |
8765 if (did_delete) | |
8766 { | |
8767 #ifdef FEAT_WINDOWS | |
8768 wp->w_redr_status = TRUE; | |
8769 #endif | |
8770 win_rest_invalid(W_NEXT(wp)); | |
8771 } | |
8772 return FAIL; | |
8773 } | |
8774 | |
8775 return OK; | |
8776 } | |
8777 | |
8778 /* | |
8779 * delete "line_count" window lines at "row" in window "wp" | |
8780 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8781 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8782 * scrolling | |
8783 * Return OK for success, FAIL if the lines are not deleted. | |
8784 */ | |
8785 int | |
8786 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8787 win_T *wp; | |
8788 int row; | |
8789 int line_count; | |
8790 int invalid; | |
8791 int mayclear; | |
8792 { | |
8793 int retval; | |
8794 | |
8795 if (invalid) | |
8796 wp->w_lines_valid = 0; | |
8797 | |
8798 if (line_count > wp->w_height - row) | |
8799 line_count = wp->w_height - row; | |
8800 | |
8801 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8802 if (retval != MAYBE) | |
8803 return retval; | |
8804 | |
8805 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8806 (int)Rows, FALSE, NULL) == FAIL) | |
8807 return FAIL; | |
8808 | |
8809 #ifdef FEAT_WINDOWS | |
8810 /* | |
8811 * If there are windows or status lines below, try to put them at the | |
8812 * correct place. If we can't do that, they have to be redrawn. | |
8813 */ | |
8814 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8815 { | |
8816 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8817 line_count, (int)Rows, NULL) == FAIL) | |
8818 { | |
8819 wp->w_redr_status = TRUE; | |
8820 win_rest_invalid(wp->w_next); | |
8821 } | |
8822 } | |
8823 /* | |
8824 * If this is the last window and there is no status line, redraw the | |
8825 * command line later. | |
8826 */ | |
8827 else | |
8828 #endif | |
8829 redraw_cmdline = TRUE; | |
8830 return OK; | |
8831 } | |
8832 | |
8833 /* | |
8834 * Common code for win_ins_lines() and win_del_lines(). | |
8835 * Returns OK or FAIL when the work has been done. | |
8836 * Returns MAYBE when not finished yet. | |
8837 */ | |
8838 static int | |
8839 win_do_lines(wp, row, line_count, mayclear, del) | |
8840 win_T *wp; | |
8841 int row; | |
8842 int line_count; | |
8843 int mayclear; | |
8844 int del; | |
8845 { | |
8846 int retval; | |
8847 | |
8848 if (!redrawing() || line_count <= 0) | |
8849 return FAIL; | |
8850 | |
8851 /* only a few lines left: redraw is faster */ | |
8852 if (mayclear && Rows - line_count < 5 | |
8853 #ifdef FEAT_VERTSPLIT | |
8854 && wp->w_width == Columns | |
8855 #endif | |
8856 ) | |
8857 { | |
8858 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8859 return FAIL; | |
8860 } | |
8861 | |
8862 /* | |
8863 * Delete all remaining lines | |
8864 */ | |
8865 if (row + line_count >= wp->w_height) | |
8866 { | |
8867 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8868 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8869 ' ', ' ', 0); | |
8870 return OK; | |
8871 } | |
8872 | |
8873 /* | |
8874 * when scrolling, the message on the command line should be cleared, | |
8875 * otherwise it will stay there forever. | |
8876 */ | |
8877 clear_cmdline = TRUE; | |
8878 | |
8879 /* | |
8880 * If the terminal can set a scroll region, use that. | |
8881 * Always do this in a vertically split window. This will redraw from | |
8882 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8883 * win_line(). | |
8884 * Don't use a scroll region when we are going to redraw the text, writing | |
8885 * a character in the lower right corner of the scroll region causes a | |
8886 * scroll-up in the DJGPP version. | |
8887 */ | |
8888 if (scroll_region | |
8889 #ifdef FEAT_VERTSPLIT | |
8890 || W_WIDTH(wp) != Columns | |
8891 #endif | |
8892 ) | |
8893 { | |
8894 #ifdef FEAT_VERTSPLIT | |
8895 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8896 #endif | |
8897 scroll_region_set(wp, row); | |
8898 if (del) | |
8899 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8900 wp->w_height - row, FALSE, wp); | |
8901 else | |
8902 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8903 wp->w_height - row, wp); | |
8904 #ifdef FEAT_VERTSPLIT | |
8905 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8906 #endif | |
8907 scroll_region_reset(); | |
8908 return retval; | |
8909 } | |
8910 | |
8911 #ifdef FEAT_WINDOWS | |
8912 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8913 return FAIL; | |
8914 #endif | |
8915 | |
8916 return MAYBE; | |
8917 } | |
8918 | |
8919 /* | |
8920 * window 'wp' and everything after it is messed up, mark it for redraw | |
8921 */ | |
8922 static void | |
8923 win_rest_invalid(wp) | |
8924 win_T *wp; | |
8925 { | |
8926 #ifdef FEAT_WINDOWS | |
8927 while (wp != NULL) | |
8928 #else | |
8929 if (wp != NULL) | |
8930 #endif | |
8931 { | |
8932 redraw_win_later(wp, NOT_VALID); | |
8933 #ifdef FEAT_WINDOWS | |
8934 wp->w_redr_status = TRUE; | |
8935 wp = wp->w_next; | |
8936 #endif | |
8937 } | |
8938 redraw_cmdline = TRUE; | |
8939 } | |
8940 | |
8941 /* | |
8942 * The rest of the routines in this file perform screen manipulations. The | |
8943 * given operation is performed physically on the screen. The corresponding | |
8944 * change is also made to the internal screen image. In this way, the editor | |
8945 * anticipates the effect of editing changes on the appearance of the screen. | |
8946 * That way, when we call screenupdate a complete redraw isn't usually | |
8947 * necessary. Another advantage is that we can keep adding code to anticipate | |
8948 * screen changes, and in the meantime, everything still works. | |
8949 */ | |
8950 | |
8951 /* | |
8952 * types for inserting or deleting lines | |
8953 */ | |
8954 #define USE_T_CAL 1 | |
8955 #define USE_T_CDL 2 | |
8956 #define USE_T_AL 3 | |
8957 #define USE_T_CE 4 | |
8958 #define USE_T_DL 5 | |
8959 #define USE_T_SR 6 | |
8960 #define USE_NL 7 | |
8961 #define USE_T_CD 8 | |
8962 #define USE_REDRAW 9 | |
8963 | |
8964 /* | |
8965 * insert lines on the screen and update ScreenLines[] | |
8966 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8967 * When scrolling region used 'off' is the offset from the top for the region. | |
8968 * 'row' and 'end' are relative to the start of the region. | |
8969 * | |
8970 * return FAIL for failure, OK for success. | |
8971 */ | |
446 | 8972 int |
7 | 8973 screen_ins_lines(off, row, line_count, end, wp) |
8974 int off; | |
8975 int row; | |
8976 int line_count; | |
8977 int end; | |
8978 win_T *wp; /* NULL or window to use width from */ | |
8979 { | |
8980 int i; | |
8981 int j; | |
8982 unsigned temp; | |
8983 int cursor_row; | |
8984 int type; | |
8985 int result_empty; | |
8986 int can_ce = can_clear(T_CE); | |
8987 | |
8988 /* | |
8989 * FAIL if | |
8990 * - there is no valid screen | |
8991 * - the screen has to be redrawn completely | |
8992 * - the line count is less than one | |
8993 * - the line count is more than 'ttyscroll' | |
8994 */ | |
8995 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8996 return FAIL; | |
8997 | |
8998 /* | |
8999 * There are seven ways to insert lines: | |
9000 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9001 * characters from ScreenLines[]. | |
9002 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
9003 * the insert is just empty lines | |
9004 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
9005 * present or line_count > 1. It looks better if we do all the inserts | |
9006 * at once. | |
9007 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
9008 * insert is just empty lines and T_CE is not present or line_count > | |
9009 * 1. | |
9010 * 4. Use T_AL (insert line) if it exists. | |
9011 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
9012 * just empty lines. | |
9013 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
9014 * just empty lines. | |
9015 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
9016 * the 'da' flag is not set or we have clear line capability. | |
9017 * 8. redraw the characters from ScreenLines[]. | |
9018 * | |
9019 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
9020 * the scrollbar for the window. It does have insert line, use that if it | |
9021 * exists. | |
9022 */ | |
9023 result_empty = (row + line_count >= end); | |
9024 #ifdef FEAT_VERTSPLIT | |
9025 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9026 type = USE_REDRAW; | |
9027 else | |
9028 #endif | |
9029 if (can_clear(T_CD) && result_empty) | |
9030 type = USE_T_CD; | |
9031 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
9032 type = USE_T_CAL; | |
9033 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
9034 type = USE_T_CDL; | |
9035 else if (*T_AL != NUL) | |
9036 type = USE_T_AL; | |
9037 else if (can_ce && result_empty) | |
9038 type = USE_T_CE; | |
9039 else if (*T_DL != NUL && result_empty) | |
9040 type = USE_T_DL; | |
9041 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
9042 type = USE_T_SR; | |
9043 else | |
9044 return FAIL; | |
9045 | |
9046 /* | |
9047 * For clearing the lines screen_del_lines() is used. This will also take | |
9048 * care of t_db if necessary. | |
9049 */ | |
9050 if (type == USE_T_CD || type == USE_T_CDL || | |
9051 type == USE_T_CE || type == USE_T_DL) | |
9052 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
9053 | |
9054 /* | |
9055 * If text is retained below the screen, first clear or delete as many | |
9056 * lines at the bottom of the window as are about to be inserted so that | |
9057 * the deleted lines won't later surface during a screen_del_lines. | |
9058 */ | |
9059 if (*T_DB) | |
9060 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
9061 | |
9062 #ifdef FEAT_CLIPBOARD | |
9063 /* Remove a modeless selection when inserting lines halfway the screen | |
9064 * or not the full width of the screen. */ | |
9065 if (off + row > 0 | |
9066 # ifdef FEAT_VERTSPLIT | |
9067 || (wp != NULL && wp->w_width != Columns) | |
9068 # endif | |
9069 ) | |
3674 | 9070 clip_clear_selection(&clip_star); |
7 | 9071 else |
9072 clip_scroll_selection(-line_count); | |
9073 #endif | |
9074 | |
9075 #ifdef FEAT_GUI | |
9076 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9077 * scrolling is actually carried out. */ | |
9078 gui_dont_update_cursor(); | |
9079 #endif | |
9080 | |
9081 if (*T_CCS != NUL) /* cursor relative to region */ | |
9082 cursor_row = row; | |
9083 else | |
9084 cursor_row = row + off; | |
9085 | |
9086 /* | |
9087 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
9088 * Clear the inserted lines in ScreenLines[]. | |
9089 */ | |
9090 row += off; | |
9091 end += off; | |
9092 for (i = 0; i < line_count; ++i) | |
9093 { | |
9094 #ifdef FEAT_VERTSPLIT | |
9095 if (wp != NULL && wp->w_width != Columns) | |
9096 { | |
9097 /* need to copy part of a line */ | |
9098 j = end - 1 - i; | |
9099 while ((j -= line_count) >= row) | |
9100 linecopy(j + line_count, j, wp); | |
9101 j += line_count; | |
9102 if (can_clear((char_u *)" ")) | |
9103 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9104 else | |
9105 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9106 LineWraps[j] = FALSE; | |
9107 } | |
9108 else | |
9109 #endif | |
9110 { | |
9111 j = end - 1 - i; | |
9112 temp = LineOffset[j]; | |
9113 while ((j -= line_count) >= row) | |
9114 { | |
9115 LineOffset[j + line_count] = LineOffset[j]; | |
9116 LineWraps[j + line_count] = LineWraps[j]; | |
9117 } | |
9118 LineOffset[j + line_count] = temp; | |
9119 LineWraps[j + line_count] = FALSE; | |
9120 if (can_clear((char_u *)" ")) | |
9121 lineclear(temp, (int)Columns); | |
9122 else | |
9123 lineinvalid(temp, (int)Columns); | |
9124 } | |
9125 } | |
9126 | |
9127 screen_stop_highlight(); | |
9128 windgoto(cursor_row, 0); | |
9129 | |
9130 #ifdef FEAT_VERTSPLIT | |
9131 /* redraw the characters */ | |
9132 if (type == USE_REDRAW) | |
9133 redraw_block(row, end, wp); | |
9134 else | |
9135 #endif | |
9136 if (type == USE_T_CAL) | |
9137 { | |
9138 term_append_lines(line_count); | |
9139 screen_start(); /* don't know where cursor is now */ | |
9140 } | |
9141 else | |
9142 { | |
9143 for (i = 0; i < line_count; i++) | |
9144 { | |
9145 if (type == USE_T_AL) | |
9146 { | |
9147 if (i && cursor_row != 0) | |
9148 windgoto(cursor_row, 0); | |
9149 out_str(T_AL); | |
9150 } | |
9151 else /* type == USE_T_SR */ | |
9152 out_str(T_SR); | |
9153 screen_start(); /* don't know where cursor is now */ | |
9154 } | |
9155 } | |
9156 | |
9157 /* | |
9158 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9159 * have been scrolled down into the region. | |
9160 */ | |
9161 if (type == USE_T_SR && *T_DA) | |
9162 { | |
9163 for (i = 0; i < line_count; ++i) | |
9164 { | |
9165 windgoto(off + i, 0); | |
9166 out_str(T_CE); | |
9167 screen_start(); /* don't know where cursor is now */ | |
9168 } | |
9169 } | |
9170 | |
9171 #ifdef FEAT_GUI | |
9172 gui_can_update_cursor(); | |
9173 if (gui.in_use) | |
9174 out_flush(); /* always flush after a scroll */ | |
9175 #endif | |
9176 return OK; | |
9177 } | |
9178 | |
9179 /* | |
9180 * delete lines on the screen and update ScreenLines[] | |
9181 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9182 * When scrolling region used 'off' is the offset from the top for the region. | |
9183 * 'row' and 'end' are relative to the start of the region. | |
9184 * | |
9185 * Return OK for success, FAIL if the lines are not deleted. | |
9186 */ | |
9187 int | |
9188 screen_del_lines(off, row, line_count, end, force, wp) | |
9189 int off; | |
9190 int row; | |
9191 int line_count; | |
9192 int end; | |
9193 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9194 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9195 { |
9196 int j; | |
9197 int i; | |
9198 unsigned temp; | |
9199 int cursor_row; | |
9200 int cursor_end; | |
9201 int result_empty; /* result is empty until end of region */ | |
9202 int can_delete; /* deleting line codes can be used */ | |
9203 int type; | |
9204 | |
9205 /* | |
9206 * FAIL if | |
9207 * - there is no valid screen | |
9208 * - the screen has to be redrawn completely | |
9209 * - the line count is less than one | |
9210 * - the line count is more than 'ttyscroll' | |
9211 */ | |
9212 if (!screen_valid(TRUE) || line_count <= 0 || | |
9213 (!force && line_count > p_ttyscroll)) | |
9214 return FAIL; | |
9215 | |
9216 /* | |
9217 * Check if the rest of the current region will become empty. | |
9218 */ | |
9219 result_empty = row + line_count >= end; | |
9220 | |
9221 /* | |
9222 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9223 * available. | |
9224 */ | |
9225 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9226 | |
9227 /* | |
9228 * There are six ways to delete lines: | |
9229 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9230 * characters from ScreenLines[]. | |
9231 * 1. Use T_CD if it exists and the result is empty. | |
9232 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9233 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9234 * none of the other ways work. | |
9235 * 4. Use T_CE (erase line) if the result is empty. | |
9236 * 5. Use T_DL (delete line) if it exists. | |
9237 * 6. redraw the characters from ScreenLines[]. | |
9238 */ | |
9239 #ifdef FEAT_VERTSPLIT | |
9240 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9241 type = USE_REDRAW; | |
9242 else | |
9243 #endif | |
9244 if (can_clear(T_CD) && result_empty) | |
9245 type = USE_T_CD; | |
9246 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9247 /* | |
9248 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9249 * its internal termcap... this works okay for tests which test *T_DB != | |
9250 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9251 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9252 * the trick... | |
9253 * Anyway, this hack will hopefully go away with the next OS release. | |
9254 * (Olaf Seibert) | |
9255 */ | |
9256 else if (row == 0 && T_DB == empty_option | |
9257 && (line_count == 1 || *T_CDL == NUL)) | |
9258 #else | |
9259 else if (row == 0 && ( | |
9260 #ifndef AMIGA | |
9261 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9262 * up, so use delete-line command */ | |
9263 line_count == 1 || | |
9264 #endif | |
9265 *T_CDL == NUL)) | |
9266 #endif | |
9267 type = USE_NL; | |
9268 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9269 type = USE_T_CDL; | |
9270 else if (can_clear(T_CE) && result_empty | |
9271 #ifdef FEAT_VERTSPLIT | |
9272 && (wp == NULL || wp->w_width == Columns) | |
9273 #endif | |
9274 ) | |
9275 type = USE_T_CE; | |
9276 else if (*T_DL != NUL && can_delete) | |
9277 type = USE_T_DL; | |
9278 else if (*T_CDL != NUL && can_delete) | |
9279 type = USE_T_CDL; | |
9280 else | |
9281 return FAIL; | |
9282 | |
9283 #ifdef FEAT_CLIPBOARD | |
9284 /* Remove a modeless selection when deleting lines halfway the screen or | |
9285 * not the full width of the screen. */ | |
9286 if (off + row > 0 | |
9287 # ifdef FEAT_VERTSPLIT | |
9288 || (wp != NULL && wp->w_width != Columns) | |
9289 # endif | |
9290 ) | |
3674 | 9291 clip_clear_selection(&clip_star); |
7 | 9292 else |
9293 clip_scroll_selection(line_count); | |
9294 #endif | |
9295 | |
9296 #ifdef FEAT_GUI | |
9297 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9298 * scrolling is actually carried out. */ | |
9299 gui_dont_update_cursor(); | |
9300 #endif | |
9301 | |
9302 if (*T_CCS != NUL) /* cursor relative to region */ | |
9303 { | |
9304 cursor_row = row; | |
9305 cursor_end = end; | |
9306 } | |
9307 else | |
9308 { | |
9309 cursor_row = row + off; | |
9310 cursor_end = end + off; | |
9311 } | |
9312 | |
9313 /* | |
9314 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9315 * Clear the inserted lines in ScreenLines[]. | |
9316 */ | |
9317 row += off; | |
9318 end += off; | |
9319 for (i = 0; i < line_count; ++i) | |
9320 { | |
9321 #ifdef FEAT_VERTSPLIT | |
9322 if (wp != NULL && wp->w_width != Columns) | |
9323 { | |
9324 /* need to copy part of a line */ | |
9325 j = row + i; | |
9326 while ((j += line_count) <= end - 1) | |
9327 linecopy(j - line_count, j, wp); | |
9328 j -= line_count; | |
9329 if (can_clear((char_u *)" ")) | |
9330 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9331 else | |
9332 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9333 LineWraps[j] = FALSE; | |
9334 } | |
9335 else | |
9336 #endif | |
9337 { | |
9338 /* whole width, moving the line pointers is faster */ | |
9339 j = row + i; | |
9340 temp = LineOffset[j]; | |
9341 while ((j += line_count) <= end - 1) | |
9342 { | |
9343 LineOffset[j - line_count] = LineOffset[j]; | |
9344 LineWraps[j - line_count] = LineWraps[j]; | |
9345 } | |
9346 LineOffset[j - line_count] = temp; | |
9347 LineWraps[j - line_count] = FALSE; | |
9348 if (can_clear((char_u *)" ")) | |
9349 lineclear(temp, (int)Columns); | |
9350 else | |
9351 lineinvalid(temp, (int)Columns); | |
9352 } | |
9353 } | |
9354 | |
9355 screen_stop_highlight(); | |
9356 | |
9357 #ifdef FEAT_VERTSPLIT | |
9358 /* redraw the characters */ | |
9359 if (type == USE_REDRAW) | |
9360 redraw_block(row, end, wp); | |
9361 else | |
9362 #endif | |
9363 if (type == USE_T_CD) /* delete the lines */ | |
9364 { | |
9365 windgoto(cursor_row, 0); | |
9366 out_str(T_CD); | |
9367 screen_start(); /* don't know where cursor is now */ | |
9368 } | |
9369 else if (type == USE_T_CDL) | |
9370 { | |
9371 windgoto(cursor_row, 0); | |
9372 term_delete_lines(line_count); | |
9373 screen_start(); /* don't know where cursor is now */ | |
9374 } | |
9375 /* | |
9376 * Deleting lines at top of the screen or scroll region: Just scroll | |
9377 * the whole screen (scroll region) up by outputting newlines on the | |
9378 * last line. | |
9379 */ | |
9380 else if (type == USE_NL) | |
9381 { | |
9382 windgoto(cursor_end - 1, 0); | |
9383 for (i = line_count; --i >= 0; ) | |
9384 out_char('\n'); /* cursor will remain on same line */ | |
9385 } | |
9386 else | |
9387 { | |
9388 for (i = line_count; --i >= 0; ) | |
9389 { | |
9390 if (type == USE_T_DL) | |
9391 { | |
9392 windgoto(cursor_row, 0); | |
9393 out_str(T_DL); /* delete a line */ | |
9394 } | |
9395 else /* type == USE_T_CE */ | |
9396 { | |
9397 windgoto(cursor_row + i, 0); | |
9398 out_str(T_CE); /* erase a line */ | |
9399 } | |
9400 screen_start(); /* don't know where cursor is now */ | |
9401 } | |
9402 } | |
9403 | |
9404 /* | |
9405 * If the 'db' flag is set, we need to clear the lines that have been | |
9406 * scrolled up at the bottom of the region. | |
9407 */ | |
9408 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9409 { | |
9410 for (i = line_count; i > 0; --i) | |
9411 { | |
9412 windgoto(cursor_end - i, 0); | |
9413 out_str(T_CE); /* erase a line */ | |
9414 screen_start(); /* don't know where cursor is now */ | |
9415 } | |
9416 } | |
9417 | |
9418 #ifdef FEAT_GUI | |
9419 gui_can_update_cursor(); | |
9420 if (gui.in_use) | |
9421 out_flush(); /* always flush after a scroll */ | |
9422 #endif | |
9423 | |
9424 return OK; | |
9425 } | |
9426 | |
9427 /* | |
9428 * show the current mode and ruler | |
9429 * | |
9430 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9431 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9432 * cleared only if a mode is shown. | |
9433 * Return the length of the message (0 if no message). | |
9434 */ | |
9435 int | |
9436 showmode() | |
9437 { | |
9438 int need_clear; | |
9439 int length = 0; | |
9440 int do_mode; | |
9441 int attr; | |
9442 int nwr_save; | |
9443 #ifdef FEAT_INS_EXPAND | |
9444 int sub_attr; | |
9445 #endif | |
9446 | |
642 | 9447 do_mode = ((p_smd && msg_silent == 0) |
9448 && ((State & INSERT) | |
9449 || restart_edit | |
7 | 9450 #ifdef FEAT_VISUAL |
9451 || VIsual_active | |
9452 #endif | |
9453 )); | |
9454 if (do_mode || Recording) | |
9455 { | |
9456 /* | |
9457 * Don't show mode right now, when not redrawing or inside a mapping. | |
9458 * Call char_avail() only when we are going to show something, because | |
9459 * it takes a bit of time. | |
9460 */ | |
9461 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9462 { | |
9463 redraw_cmdline = TRUE; /* show mode later */ | |
9464 return 0; | |
9465 } | |
9466 | |
9467 nwr_save = need_wait_return; | |
9468 | |
9469 /* wait a bit before overwriting an important message */ | |
9470 check_for_delay(FALSE); | |
9471 | |
9472 /* if the cmdline is more than one line high, erase top lines */ | |
9473 need_clear = clear_cmdline; | |
9474 if (clear_cmdline && cmdline_row < Rows - 1) | |
9475 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9476 | |
9477 /* Position on the last line in the window, column 0 */ | |
9478 msg_pos_mode(); | |
9479 cursor_off(); | |
9480 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9481 if (do_mode) | |
9482 { | |
9483 MSG_PUTS_ATTR("--", attr); | |
9484 #if defined(FEAT_XIM) | |
2520 | 9485 if ( |
9486 # ifdef FEAT_GUI_GTK | |
9487 preedit_get_status() | |
1668 | 9488 # else |
9489 im_get_status() | |
2520 | 9490 # endif |
1668 | 9491 ) |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9492 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9493 MSG_PUTS_ATTR(" IM", attr); |
9494 # else | |
9495 MSG_PUTS_ATTR(" XIM", attr); | |
9496 # endif | |
9497 #endif | |
9498 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9499 if (gui.in_use) | |
9500 { | |
9501 if (hangul_input_state_get()) | |
236 | 9502 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9503 } |
9504 #endif | |
9505 #ifdef FEAT_INS_EXPAND | |
9506 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9507 { | |
9508 /* These messages can get long, avoid a wrap in a narrow | |
9509 * window. Prefer showing edit_submode_extra. */ | |
9510 length = (Rows - msg_row) * Columns - 3; | |
9511 if (edit_submode_extra != NULL) | |
9512 length -= vim_strsize(edit_submode_extra); | |
9513 if (length > 0) | |
9514 { | |
9515 if (edit_submode_pre != NULL) | |
9516 length -= vim_strsize(edit_submode_pre); | |
9517 if (length - vim_strsize(edit_submode) > 0) | |
9518 { | |
9519 if (edit_submode_pre != NULL) | |
9520 msg_puts_attr(edit_submode_pre, attr); | |
9521 msg_puts_attr(edit_submode, attr); | |
9522 } | |
9523 if (edit_submode_extra != NULL) | |
9524 { | |
9525 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9526 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9527 sub_attr = hl_attr(edit_submode_highl); | |
9528 else | |
9529 sub_attr = attr; | |
9530 msg_puts_attr(edit_submode_extra, sub_attr); | |
9531 } | |
9532 } | |
9533 length = 0; | |
9534 } | |
9535 else | |
9536 #endif | |
9537 { | |
9538 #ifdef FEAT_VREPLACE | |
9539 if (State & VREPLACE_FLAG) | |
9540 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9541 else | |
9542 #endif | |
9543 if (State & REPLACE_FLAG) | |
9544 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9545 else if (State & INSERT) | |
9546 { | |
9547 #ifdef FEAT_RIGHTLEFT | |
9548 if (p_ri) | |
9549 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9550 #endif | |
9551 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9552 } | |
9553 else if (restart_edit == 'I') | |
9554 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9555 else if (restart_edit == 'R') | |
9556 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9557 else if (restart_edit == 'V') | |
9558 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9559 #ifdef FEAT_RIGHTLEFT | |
9560 if (p_hkmap) | |
9561 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9562 # ifdef FEAT_FKMAP | |
9563 if (p_fkmap) | |
9564 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9565 # endif | |
9566 #endif | |
9567 #ifdef FEAT_KEYMAP | |
9568 if (State & LANGMAP) | |
9569 { | |
9570 # ifdef FEAT_ARABIC | |
9571 if (curwin->w_p_arab) | |
9572 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9573 else | |
9574 # endif | |
9575 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9576 } | |
9577 #endif | |
9578 if ((State & INSERT) && p_paste) | |
9579 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9580 | |
9581 #ifdef FEAT_VISUAL | |
9582 if (VIsual_active) | |
9583 { | |
9584 char *p; | |
9585 | |
9586 /* Don't concatenate separate words to avoid translation | |
9587 * problems. */ | |
9588 switch ((VIsual_select ? 4 : 0) | |
9589 + (VIsual_mode == Ctrl_V) * 2 | |
9590 + (VIsual_mode == 'V')) | |
9591 { | |
9592 case 0: p = N_(" VISUAL"); break; | |
9593 case 1: p = N_(" VISUAL LINE"); break; | |
9594 case 2: p = N_(" VISUAL BLOCK"); break; | |
9595 case 4: p = N_(" SELECT"); break; | |
9596 case 5: p = N_(" SELECT LINE"); break; | |
9597 default: p = N_(" SELECT BLOCK"); break; | |
9598 } | |
9599 MSG_PUTS_ATTR(_(p), attr); | |
9600 } | |
9601 #endif | |
9602 MSG_PUTS_ATTR(" --", attr); | |
9603 } | |
644 | 9604 |
7 | 9605 need_clear = TRUE; |
9606 } | |
9607 if (Recording | |
9608 #ifdef FEAT_INS_EXPAND | |
9609 && edit_submode == NULL /* otherwise it gets too long */ | |
9610 #endif | |
9611 ) | |
9612 { | |
9613 MSG_PUTS_ATTR(_("recording"), attr); | |
9614 need_clear = TRUE; | |
9615 } | |
644 | 9616 |
9617 mode_displayed = TRUE; | |
7 | 9618 if (need_clear || clear_cmdline) |
9619 msg_clr_eos(); | |
9620 msg_didout = FALSE; /* overwrite this message */ | |
9621 length = msg_col; | |
9622 msg_col = 0; | |
9623 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9624 } | |
9625 else if (clear_cmdline && msg_silent == 0) | |
9626 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9627 msg_clr_cmdline(); | |
9628 | |
9629 #ifdef FEAT_CMDL_INFO | |
9630 # ifdef FEAT_VISUAL | |
9631 /* In Visual mode the size of the selected area must be redrawn. */ | |
9632 if (VIsual_active) | |
9633 clear_showcmd(); | |
9634 # endif | |
9635 | |
9636 /* If the last window has no status line, the ruler is after the mode | |
9637 * message and must be redrawn */ | |
9638 if (redrawing() | |
9639 # ifdef FEAT_WINDOWS | |
9640 && lastwin->w_status_height == 0 | |
9641 # endif | |
9642 ) | |
9643 win_redr_ruler(lastwin, TRUE); | |
9644 #endif | |
9645 redraw_cmdline = FALSE; | |
9646 clear_cmdline = FALSE; | |
9647 | |
9648 return length; | |
9649 } | |
9650 | |
9651 /* | |
9652 * Position for a mode message. | |
9653 */ | |
9654 static void | |
9655 msg_pos_mode() | |
9656 { | |
9657 msg_col = 0; | |
9658 msg_row = Rows - 1; | |
9659 } | |
9660 | |
9661 /* | |
9662 * Delete mode message. Used when ESC is typed which is expected to end | |
9663 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9664 * Caller should check "mode_displayed". |
7 | 9665 */ |
9666 void | |
9667 unshowmode(force) | |
9668 int force; | |
9669 { | |
9670 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9671 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9672 */ |
9673 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9674 redraw_cmdline = TRUE; /* delete mode later */ | |
9675 else | |
9676 { | |
9677 msg_pos_mode(); | |
9678 if (Recording) | |
9679 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9680 msg_clr_eos(); | |
9681 } | |
9682 } | |
9683 | |
667 | 9684 #if defined(FEAT_WINDOWS) |
9685 /* | |
9686 * Draw the tab pages line at the top of the Vim window. | |
9687 */ | |
9688 static void | |
677 | 9689 draw_tabline() |
667 | 9690 { |
9691 int tabcount = 0; | |
9692 tabpage_T *tp; | |
9693 int tabwidth; | |
9694 int col = 0; | |
673 | 9695 int scol = 0; |
667 | 9696 int attr; |
9697 win_T *wp; | |
671 | 9698 win_T *cwp; |
9699 int wincount; | |
9700 int modified; | |
667 | 9701 int c; |
9702 int len; | |
9703 int attr_sel = hl_attr(HLF_TPS); | |
9704 int attr_nosel = hl_attr(HLF_TP); | |
9705 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9706 char_u *p; |
677 | 9707 int room; |
9708 int use_sep_chars = (t_colors < 8 | |
9709 #ifdef FEAT_GUI | |
9710 && !gui.in_use | |
9711 #endif | |
9712 ); | |
673 | 9713 |
9714 redraw_tabline = FALSE; | |
667 | 9715 |
685 | 9716 #ifdef FEAT_GUI_TABLINE |
798 | 9717 /* Take care of a GUI tabline. */ |
685 | 9718 if (gui_use_tabline()) |
9719 { | |
9720 gui_update_tabline(); | |
9721 return; | |
9722 } | |
9723 #endif | |
9724 | |
9725 if (tabline_height() < 1) | |
667 | 9726 return; |
9727 | |
677 | 9728 #if defined(FEAT_STL_OPT) |
681 | 9729 |
9730 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9731 for (scol = 0; scol < Columns; ++scol) | |
9732 TabPageIdxs[scol] = 0; | |
9733 | |
677 | 9734 /* Use the 'tabline' option if it's set. */ |
9735 if (*p_tal != NUL) | |
9736 { | |
680 | 9737 int save_called_emsg = called_emsg; |
9738 | |
9739 /* Check for an error. If there is one we would loop in redrawing the | |
9740 * screen. Avoid that by making 'tabline' empty. */ | |
9741 called_emsg = FALSE; | |
677 | 9742 win_redr_custom(NULL, FALSE); |
680 | 9743 if (called_emsg) |
9744 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9745 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9746 called_emsg |= save_called_emsg; |
9747 } | |
9748 else | |
9749 #endif | |
9750 { | |
9751 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9752 ++tabcount; | |
9753 | |
9754 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9755 if (tabwidth < 6) | |
9756 tabwidth = 6; | |
9757 | |
9758 attr = attr_nosel; | |
9759 tabcount = 0; | |
681 | 9760 scol = 0; |
699 | 9761 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9762 tp = tp->tp_next) | |
680 | 9763 { |
9764 scol = col; | |
9765 | |
9766 if (tp->tp_topframe == topframe) | |
9767 attr = attr_sel; | |
9768 if (use_sep_chars && col > 0) | |
9769 screen_putchar('|', 0, col++, attr); | |
9770 | |
9771 if (tp->tp_topframe != topframe) | |
9772 attr = attr_nosel; | |
9773 | |
9774 screen_putchar(' ', 0, col++, attr); | |
9775 | |
9776 if (tp == curtab) | |
9777 { | |
9778 cwp = curwin; | |
9779 wp = firstwin; | |
9780 } | |
9781 else | |
9782 { | |
9783 cwp = tp->tp_curwin; | |
9784 wp = tp->tp_firstwin; | |
9785 } | |
9786 | |
9787 modified = FALSE; | |
9788 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9789 if (bufIsChanged(wp->w_buffer)) | |
9790 modified = TRUE; | |
9791 if (modified || wincount > 1) | |
9792 { | |
9793 if (wincount > 1) | |
9794 { | |
9795 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9796 len = (int)STRLEN(NameBuff); |
699 | 9797 if (col + len >= Columns - 3) |
9798 break; | |
680 | 9799 screen_puts_len(NameBuff, len, 0, col, |
677 | 9800 #if defined(FEAT_SYN_HL) |
680 | 9801 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9802 #else |
680 | 9803 attr |
9804 #endif | |
9805 ); | |
9806 col += len; | |
9807 } | |
9808 if (modified) | |
9809 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9810 screen_putchar(' ', 0, col++, attr); | |
9811 } | |
9812 | |
9813 room = scol - col + tabwidth - 1; | |
9814 if (room > 0) | |
9815 { | |
685 | 9816 /* Get buffer name in NameBuff[] */ |
9817 get_trans_bufname(cwp->w_buffer); | |
819 | 9818 shorten_dir(NameBuff); |
680 | 9819 len = vim_strsize(NameBuff); |
9820 p = NameBuff; | |
677 | 9821 #ifdef FEAT_MBYTE |
680 | 9822 if (has_mbyte) |
9823 while (len > room) | |
9824 { | |
9825 len -= ptr2cells(p); | |
9826 mb_ptr_adv(p); | |
9827 } | |
9828 else | |
9829 #endif | |
9830 if (len > room) | |
677 | 9831 { |
680 | 9832 p += len - room; |
9833 len = room; | |
677 | 9834 } |
699 | 9835 if (len > Columns - col - 1) |
9836 len = Columns - col - 1; | |
680 | 9837 |
835 | 9838 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9839 col += len; |
9840 } | |
9841 screen_putchar(' ', 0, col++, attr); | |
9842 | |
9843 /* Store the tab page number in TabPageIdxs[], so that | |
9844 * jump_to_mouse() knows where each one is. */ | |
9845 ++tabcount; | |
9846 while (scol < col) | |
9847 TabPageIdxs[scol++] = tabcount; | |
9848 } | |
9849 | |
9850 if (use_sep_chars) | |
9851 c = '_'; | |
9852 else | |
9853 c = ' '; | |
9854 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9855 |
9856 /* Put an "X" for closing the current tab if there are several. */ | |
9857 if (first_tabpage->tp_next != NULL) | |
9858 { | |
9859 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9860 TabPageIdxs[Columns - 1] = -999; | |
9861 } | |
9862 } | |
834 | 9863 |
9864 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9865 * set. */ | |
9866 redraw_tabline = FALSE; | |
667 | 9867 } |
685 | 9868 |
9869 /* | |
9870 * Get buffer name for "buf" into NameBuff[]. | |
9871 * Takes care of special buffer names and translates special characters. | |
9872 */ | |
9873 void | |
9874 get_trans_bufname(buf) | |
9875 buf_T *buf; | |
9876 { | |
9877 if (buf_spname(buf) != NULL) | |
9878 STRCPY(NameBuff, buf_spname(buf)); | |
9879 else | |
9880 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9881 trans_characters(NameBuff, MAXPATHL); | |
9882 } | |
667 | 9883 #endif |
9884 | |
7 | 9885 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9886 /* | |
9887 * Get the character to use in a status line. Get its attributes in "*attr". | |
9888 */ | |
9889 static int | |
9890 fillchar_status(attr, is_curwin) | |
9891 int *attr; | |
9892 int is_curwin; | |
9893 { | |
9894 int fill; | |
9895 if (is_curwin) | |
9896 { | |
9897 *attr = hl_attr(HLF_S); | |
9898 fill = fill_stl; | |
9899 } | |
9900 else | |
9901 { | |
9902 *attr = hl_attr(HLF_SNC); | |
9903 fill = fill_stlnc; | |
9904 } | |
9905 /* Use fill when there is highlighting, and highlighting of current | |
9906 * window differs, or the fillchars differ, or this is not the | |
9907 * current window */ | |
9908 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9909 || !is_curwin || firstwin == lastwin) | |
9910 || (fill_stl != fill_stlnc))) | |
9911 return fill; | |
9912 if (is_curwin) | |
9913 return '^'; | |
9914 return '='; | |
9915 } | |
9916 #endif | |
9917 | |
9918 #ifdef FEAT_VERTSPLIT | |
9919 /* | |
9920 * Get the character to use in a separator between vertically split windows. | |
9921 * Get its attributes in "*attr". | |
9922 */ | |
9923 static int | |
9924 fillchar_vsep(attr) | |
9925 int *attr; | |
9926 { | |
9927 *attr = hl_attr(HLF_C); | |
9928 if (*attr == 0 && fill_vert == ' ') | |
9929 return '|'; | |
9930 else | |
9931 return fill_vert; | |
9932 } | |
9933 #endif | |
9934 | |
9935 /* | |
9936 * Return TRUE if redrawing should currently be done. | |
9937 */ | |
9938 int | |
9939 redrawing() | |
9940 { | |
9941 return (!RedrawingDisabled | |
9942 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9943 } | |
9944 | |
9945 /* | |
9946 * Return TRUE if printing messages should currently be done. | |
9947 */ | |
9948 int | |
9949 messaging() | |
9950 { | |
9951 return (!(p_lz && char_avail() && !KeyTyped)); | |
9952 } | |
9953 | |
9954 /* | |
9955 * Show current status info in ruler and various other places | |
9956 * If always is FALSE, only show ruler if position has changed. | |
9957 */ | |
9958 void | |
9959 showruler(always) | |
9960 int always; | |
9961 { | |
9962 if (!always && !redrawing()) | |
9963 return; | |
574 | 9964 #ifdef FEAT_INS_EXPAND |
9965 if (pum_visible()) | |
9966 { | |
639 | 9967 # ifdef FEAT_WINDOWS |
574 | 9968 /* Don't redraw right now, do it later. */ |
9969 curwin->w_redr_status = TRUE; | |
639 | 9970 # endif |
574 | 9971 return; |
9972 } | |
9973 #endif | |
7 | 9974 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9975 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9976 { |
1983 | 9977 redraw_custom_statusline(curwin); |
680 | 9978 } |
7 | 9979 else |
9980 #endif | |
9981 #ifdef FEAT_CMDL_INFO | |
9982 win_redr_ruler(curwin, always); | |
9983 #endif | |
9984 | |
9985 #ifdef FEAT_TITLE | |
9986 if (need_maketitle | |
9987 # ifdef FEAT_STL_OPT | |
9988 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9989 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9990 # endif | |
9991 ) | |
9992 maketitle(); | |
9993 #endif | |
1588 | 9994 #ifdef FEAT_WINDOWS |
9995 /* Redraw the tab pages line if needed. */ | |
9996 if (redraw_tabline) | |
9997 draw_tabline(); | |
9998 #endif | |
7 | 9999 } |
10000 | |
10001 #ifdef FEAT_CMDL_INFO | |
10002 static void | |
10003 win_redr_ruler(wp, always) | |
10004 win_T *wp; | |
10005 int always; | |
10006 { | |
1869 | 10007 #define RULER_BUF_LEN 70 |
10008 char_u buffer[RULER_BUF_LEN]; | |
7 | 10009 int row; |
10010 int fillchar; | |
10011 int attr; | |
10012 int empty_line = FALSE; | |
10013 colnr_T virtcol; | |
10014 int i; | |
1869 | 10015 size_t len; |
7 | 10016 int o; |
10017 #ifdef FEAT_VERTSPLIT | |
10018 int this_ru_col; | |
10019 int off = 0; | |
10020 int width = Columns; | |
10021 # define WITH_OFF(x) x | |
10022 # define WITH_WIDTH(x) x | |
10023 #else | |
10024 # define WITH_OFF(x) 0 | |
10025 # define WITH_WIDTH(x) Columns | |
10026 # define this_ru_col ru_col | |
10027 #endif | |
10028 | |
10029 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
10030 if (!p_ru) | |
10031 return; | |
10032 | |
10033 /* | |
10034 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
10035 * after deleting lines, before cursor.lnum is corrected. | |
10036 */ | |
10037 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
10038 return; | |
10039 | |
10040 #ifdef FEAT_INS_EXPAND | |
10041 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
10042 * the (long) mode message. */ | |
10043 # ifdef FEAT_WINDOWS | |
10044 if (wp == lastwin && lastwin->w_status_height == 0) | |
10045 # endif | |
10046 if (edit_submode != NULL) | |
10047 return; | |
540 | 10048 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
10049 if (pum_visible()) | |
10050 return; | |
7 | 10051 #endif |
10052 | |
10053 #ifdef FEAT_STL_OPT | |
10054 if (*p_ruf) | |
10055 { | |
680 | 10056 int save_called_emsg = called_emsg; |
10057 | |
10058 called_emsg = FALSE; | |
7 | 10059 win_redr_custom(wp, TRUE); |
680 | 10060 if (called_emsg) |
10061 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 10062 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 10063 called_emsg |= save_called_emsg; |
7 | 10064 return; |
10065 } | |
10066 #endif | |
10067 | |
10068 /* | |
10069 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
10070 */ | |
10071 if (!(State & INSERT) | |
10072 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
10073 empty_line = TRUE; | |
10074 | |
10075 /* | |
10076 * Only draw the ruler when something changed. | |
10077 */ | |
10078 validate_virtcol_win(wp); | |
10079 if ( redraw_cmdline | |
10080 || always | |
10081 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
10082 || wp->w_cursor.col != wp->w_ru_cursor.col | |
10083 || wp->w_virtcol != wp->w_ru_virtcol | |
10084 #ifdef FEAT_VIRTUALEDIT | |
10085 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
10086 #endif | |
10087 || wp->w_topline != wp->w_ru_topline | |
10088 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
10089 #ifdef FEAT_DIFF | |
10090 || wp->w_topfill != wp->w_ru_topfill | |
10091 #endif | |
10092 || empty_line != wp->w_ru_empty) | |
10093 { | |
10094 cursor_off(); | |
10095 #ifdef FEAT_WINDOWS | |
10096 if (wp->w_status_height) | |
10097 { | |
10098 row = W_WINROW(wp) + wp->w_height; | |
10099 fillchar = fillchar_status(&attr, wp == curwin); | |
10100 # ifdef FEAT_VERTSPLIT | |
10101 off = W_WINCOL(wp); | |
10102 width = W_WIDTH(wp); | |
10103 # endif | |
10104 } | |
10105 else | |
10106 #endif | |
10107 { | |
10108 row = Rows - 1; | |
10109 fillchar = ' '; | |
10110 attr = 0; | |
10111 #ifdef FEAT_VERTSPLIT | |
10112 width = Columns; | |
10113 off = 0; | |
10114 #endif | |
10115 } | |
10116 | |
10117 /* In list mode virtcol needs to be recomputed */ | |
10118 virtcol = wp->w_virtcol; | |
10119 if (wp->w_p_list && lcs_tab1 == NUL) | |
10120 { | |
10121 wp->w_p_list = FALSE; | |
10122 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10123 wp->w_p_list = TRUE; | |
10124 } | |
10125 | |
10126 /* | |
10127 * Some sprintfs return the length, some return a pointer. | |
10128 * To avoid portability problems we use strlen() here. | |
10129 */ | |
1869 | 10130 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10131 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10132 ? 0L | |
10133 : (long)(wp->w_cursor.lnum)); | |
1869 | 10134 len = STRLEN(buffer); |
10135 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10136 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10137 (int)virtcol + 1); | |
10138 | |
10139 /* | |
10140 * Add a "50%" if there is room for it. | |
10141 * On the last line, don't print in the last column (scrolls the | |
10142 * screen up on some terminals). | |
10143 */ | |
10144 i = (int)STRLEN(buffer); | |
1869 | 10145 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10146 o = i + vim_strsize(buffer + i + 1); |
10147 #ifdef FEAT_WINDOWS | |
10148 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10149 #endif | |
10150 ++o; | |
10151 #ifdef FEAT_VERTSPLIT | |
10152 this_ru_col = ru_col - (Columns - width); | |
10153 if (this_ru_col < 0) | |
10154 this_ru_col = 0; | |
10155 #endif | |
10156 /* Never use more than half the window/screen width, leave the other | |
10157 * half for the filename. */ | |
10158 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10159 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10160 if (this_ru_col + o < WITH_WIDTH(width)) | |
10161 { | |
10162 while (this_ru_col + o < WITH_WIDTH(width)) | |
10163 { | |
10164 #ifdef FEAT_MBYTE | |
10165 if (has_mbyte) | |
10166 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10167 else | |
10168 #endif | |
10169 buffer[i++] = fillchar; | |
10170 ++o; | |
10171 } | |
1869 | 10172 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10173 } |
10174 /* Truncate at window boundary. */ | |
10175 #ifdef FEAT_MBYTE | |
10176 if (has_mbyte) | |
10177 { | |
10178 o = 0; | |
474 | 10179 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10180 { |
10181 o += (*mb_ptr2cells)(buffer + i); | |
10182 if (this_ru_col + o > WITH_WIDTH(width)) | |
10183 { | |
10184 buffer[i] = NUL; | |
10185 break; | |
10186 } | |
10187 } | |
10188 } | |
10189 else | |
10190 #endif | |
10191 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10192 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10193 | |
10194 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10195 i = redraw_cmdline; | |
10196 screen_fill(row, row + 1, | |
10197 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10198 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10199 fillchar, fillchar, attr); | |
10200 /* don't redraw the cmdline because of showing the ruler */ | |
10201 redraw_cmdline = i; | |
10202 wp->w_ru_cursor = wp->w_cursor; | |
10203 wp->w_ru_virtcol = wp->w_virtcol; | |
10204 wp->w_ru_empty = empty_line; | |
10205 wp->w_ru_topline = wp->w_topline; | |
10206 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10207 #ifdef FEAT_DIFF | |
10208 wp->w_ru_topfill = wp->w_topfill; | |
10209 #endif | |
10210 } | |
10211 } | |
10212 #endif | |
13 | 10213 |
10214 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10215 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10216 * 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
|
10217 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10218 * Otherwise it depends on 'numberwidth' and the line count. |
10219 */ | |
10220 int | |
10221 number_width(wp) | |
10222 win_T *wp; | |
10223 { | |
10224 int n; | |
10225 linenr_T lnum; | |
10226 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10227 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10228 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10229 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
|
10230 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10231 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10232 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10233 |
13 | 10234 if (lnum == wp->w_nrwidth_line_count) |
10235 return wp->w_nrwidth_width; | |
10236 wp->w_nrwidth_line_count = lnum; | |
10237 | |
10238 n = 0; | |
10239 do | |
10240 { | |
856 | 10241 lnum /= 10; |
10242 ++n; | |
13 | 10243 } while (lnum > 0); |
10244 | |
10245 /* 'numberwidth' gives the minimal width plus one */ | |
10246 if (n < wp->w_p_nuw - 1) | |
10247 n = wp->w_p_nuw - 1; | |
10248 | |
10249 wp->w_nrwidth_width = n; | |
10250 return n; | |
10251 } | |
10252 #endif |