Mercurial > vim
annotate src/screen.c @ 3040:b6af1c5dd22f v7.3.292
updated for version 7.3.292
Problem: Crash when using fold markers and selecting a visual block that
includes a folded line and goes to end of line. (Sam Lidder)
Solution: Check for the column to be MAXCOL. (James Vega)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 02 Sep 2011 14:07:36 +0200 |
parents | 1bb6776fa8c4 |
children | 927c7377cf49 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * screen.c: code for displaying on the screen | |
12 * | |
13 * Output to the screen (console, terminal emulator or GUI window) is minimized | |
14 * by remembering what is already on the screen, and only updating the parts | |
15 * that changed. | |
16 * | |
17 * ScreenLines[off] Contains a copy of the whole screen, as it is currently | |
18 * displayed (excluding text written by external commands). | |
19 * ScreenAttrs[off] Contains the associated attributes. | |
20 * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] | |
21 * for each line. | |
22 * LineWraps[row] Flag for each line whether it wraps to the next line. | |
23 * | |
24 * For double-byte characters, two consecutive bytes in ScreenLines[] can form | |
25 * one character which occupies two display cells. | |
26 * For UTF-8 a multi-byte character is converted to Unicode and stored in | |
27 * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
28 * character without composing chars ScreenLinesUC[] will be 0 and |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
29 * ScreenLinesC[][] is not used. When the character occupies two display |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
30 * cells the next byte in ScreenLines[] is 0. |
714 | 31 * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
32 * (drawn on top of the first character). There is 0 after the last one used. |
7 | 33 * ScreenLines2[] is only used for euc-jp to store the second byte if the |
34 * first byte is 0x8e (single-width character). | |
35 * | |
36 * The screen_*() functions write to the screen and handle updating | |
37 * ScreenLines[]. | |
38 * | |
39 * update_screen() is the function that updates all windows and status lines. | |
40 * It is called form the main loop when must_redraw is non-zero. It may be | |
1213 | 41 * called from other places when an immediate screen update is needed. |
7 | 42 * |
43 * The part of the buffer that is displayed in a window is set with: | |
44 * - w_topline (first buffer line in window) | |
45 * - w_topfill (filler line above the first line) | |
46 * - w_leftcol (leftmost window cell in window), | |
47 * - w_skipcol (skipped window cells of first line) | |
48 * | |
49 * Commands that only move the cursor around in a window, do not need to take | |
50 * action to update the display. The main loop will check if w_topline is | |
51 * valid and update it (scroll the window) when needed. | |
52 * | |
53 * Commands that scroll a window change w_topline and must call | |
54 * check_cursor() to move the cursor into the visible part of the window, and | |
55 * call redraw_later(VALID) to have the window displayed by update_screen() | |
56 * later. | |
57 * | |
58 * Commands that change text in the buffer must call changed_bytes() or | |
59 * changed_lines() to mark the area that changed and will require updating | |
60 * later. The main loop will call update_screen(), which will update each | |
61 * window that shows the changed buffer. This assumes text above the change | |
62 * can remain displayed as it is. Text after the change may need updating for | |
63 * scrolling, folding and syntax highlighting. | |
64 * | |
65 * Commands that change how a window is displayed (e.g., setting 'list') or | |
66 * invalidate the contents of a window in another way (e.g., change fold | |
67 * settings), must call redraw_later(NOT_VALID) to have the whole window | |
68 * redisplayed by update_screen() later. | |
69 * | |
70 * Commands that change how a buffer is displayed (e.g., setting 'tabstop') | |
71 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the | |
72 * buffer redisplayed by update_screen() later. | |
73 * | |
743 | 74 * Commands that change highlighting and possibly cause a scroll too must call |
75 * redraw_later(SOME_VALID) to update the whole window but still use scrolling | |
76 * to avoid redrawing everything. But the length of displayed lines must not | |
77 * change, use NOT_VALID then. | |
78 * | |
7 | 79 * Commands that move the window position must call redraw_later(NOT_VALID). |
80 * TODO: should minimize redrawing by scrolling when possible. | |
81 * | |
82 * Commands that change everything (e.g., resizing the screen) must call | |
83 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). | |
84 * | |
85 * Things that are handled indirectly: | |
86 * - When messages scroll the screen up, msg_scrolled will be set and | |
87 * update_screen() called to redraw. | |
88 */ | |
89 | |
90 #include "vim.h" | |
91 | |
92 /* | |
93 * The attributes that are actually active for writing to the screen. | |
94 */ | |
95 static int screen_attr = 0; | |
96 | |
97 /* | |
98 * Positioning the cursor is reduced by remembering the last position. | |
99 * Mostly used by windgoto() and screen_char(). | |
100 */ | |
101 static int screen_cur_row, screen_cur_col; /* last known cursor position */ | |
102 | |
103 #ifdef FEAT_SEARCH_EXTRA | |
104 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
105 #endif | |
106 | |
107 #ifdef FEAT_FOLDING | |
108 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
109 #endif | |
110 | |
111 /* | |
112 * Buffer for one screen line (characters and attributes). | |
113 */ | |
114 static schar_T *current_ScreenLine; | |
115 | |
116 static void win_update __ARGS((win_T *wp)); | |
534 | 117 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 118 #ifdef FEAT_FOLDING |
119 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
120 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
121 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
122 #endif | |
625 | 123 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 124 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
125 #ifdef FEAT_RIGHTLEFT | |
126 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
127 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
128 #else | |
129 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
131 #endif | |
132 #ifdef FEAT_VERTSPLIT | |
133 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
134 #endif | |
680 | 135 #ifdef FEAT_STL_OPT |
1983 | 136 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 137 #endif |
7 | 138 #ifdef FEAT_SEARCH_EXTRA |
1326 | 139 #define SEARCH_HL_PRIORITY 0 |
7 | 140 static void start_search_hl __ARGS((void)); |
141 static void end_search_hl __ARGS((void)); | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
142 static void init_search_hl __ARGS((win_T *wp)); |
7 | 143 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
144 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
145 #endif | |
146 static void screen_start_highlight __ARGS((int attr)); | |
147 static void screen_char __ARGS((unsigned off, int row, int col)); | |
148 #ifdef FEAT_MBYTE | |
149 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
150 #endif | |
151 static void screenclear2 __ARGS((void)); | |
152 static void lineclear __ARGS((unsigned off, int width)); | |
153 static void lineinvalid __ARGS((unsigned off, int width)); | |
154 #ifdef FEAT_VERTSPLIT | |
155 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
156 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
157 #endif | |
158 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
159 static void win_rest_invalid __ARGS((win_T *wp)); | |
160 static void msg_pos_mode __ARGS((void)); | |
667 | 161 #if defined(FEAT_WINDOWS) |
677 | 162 static void draw_tabline __ARGS((void)); |
667 | 163 #endif |
7 | 164 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
165 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
166 #endif | |
167 #ifdef FEAT_VERTSPLIT | |
168 static int fillchar_vsep __ARGS((int *attr)); | |
169 #endif | |
170 #ifdef FEAT_STL_OPT | |
574 | 171 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 172 #endif |
173 #ifdef FEAT_CMDL_INFO | |
174 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
175 #endif | |
176 | |
177 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
178 /* Ugly global: overrule attribute used by screen_char() */ | |
179 static int screen_char_attr = 0; | |
180 #endif | |
181 | |
182 /* | |
183 * Redraw the current window later, with update_screen(type). | |
184 * Set must_redraw only if not already set to a higher value. | |
185 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
186 */ | |
187 void | |
188 redraw_later(type) | |
189 int type; | |
190 { | |
191 redraw_win_later(curwin, type); | |
192 } | |
193 | |
194 void | |
195 redraw_win_later(wp, type) | |
196 win_T *wp; | |
197 int type; | |
198 { | |
199 if (wp->w_redr_type < type) | |
200 { | |
201 wp->w_redr_type = type; | |
202 if (type >= NOT_VALID) | |
203 wp->w_lines_valid = 0; | |
204 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
205 must_redraw = type; | |
206 } | |
207 } | |
208 | |
209 /* | |
210 * Force a complete redraw later. Also resets the highlighting. To be used | |
211 * after executing a shell command that messes up the screen. | |
212 */ | |
213 void | |
214 redraw_later_clear() | |
215 { | |
216 redraw_all_later(CLEAR); | |
826 | 217 #ifdef FEAT_GUI |
218 if (gui.in_use) | |
219 /* Use a code that will reset gui.highlight_mask in | |
220 * gui_stop_highlight(). */ | |
221 screen_attr = HL_ALL + 1; | |
222 else | |
223 #endif | |
224 /* Use attributes that is very unlikely to appear in text. */ | |
225 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 226 } |
227 | |
228 /* | |
229 * Mark all windows to be redrawn later. | |
230 */ | |
231 void | |
232 redraw_all_later(type) | |
233 int type; | |
234 { | |
235 win_T *wp; | |
236 | |
237 FOR_ALL_WINDOWS(wp) | |
238 { | |
239 redraw_win_later(wp, type); | |
240 } | |
241 } | |
242 | |
243 /* | |
301 | 244 * Mark all windows that are editing the current buffer to be updated later. |
7 | 245 */ |
246 void | |
247 redraw_curbuf_later(type) | |
248 int type; | |
249 { | |
250 redraw_buf_later(curbuf, type); | |
251 } | |
252 | |
253 void | |
254 redraw_buf_later(buf, type) | |
255 buf_T *buf; | |
256 int type; | |
257 { | |
258 win_T *wp; | |
259 | |
260 FOR_ALL_WINDOWS(wp) | |
261 { | |
262 if (wp->w_buffer == buf) | |
263 redraw_win_later(wp, type); | |
264 } | |
265 } | |
266 | |
267 /* | |
268 * Changed something in the current window, at buffer line "lnum", that | |
269 * requires that line and possibly other lines to be redrawn. | |
270 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
271 * Used to remove the "$" from a change command. | |
272 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
273 * may become invalid and the whole window will have to be redrawn. | |
274 */ | |
275 void | |
276 redrawWinline(lnum, invalid) | |
277 linenr_T lnum; | |
1883 | 278 int invalid UNUSED; /* window line height is invalid now */ |
7 | 279 { |
280 #ifdef FEAT_FOLDING | |
281 int i; | |
282 #endif | |
283 | |
284 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
285 curwin->w_redraw_top = lnum; | |
286 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
287 curwin->w_redraw_bot = lnum; | |
288 redraw_later(VALID); | |
289 | |
290 #ifdef FEAT_FOLDING | |
291 if (invalid) | |
292 { | |
293 /* A w_lines[] entry for this lnum has become invalid. */ | |
294 i = find_wl_entry(curwin, lnum); | |
295 if (i >= 0) | |
296 curwin->w_lines[i].wl_valid = FALSE; | |
297 } | |
298 #endif | |
299 } | |
300 | |
2255 | 301 #if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \ |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
302 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 303 /* |
304 * update all windows that are editing the current buffer | |
305 */ | |
306 void | |
307 update_curbuf(type) | |
308 int type; | |
309 { | |
310 redraw_curbuf_later(type); | |
311 update_screen(type); | |
312 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
313 #endif |
7 | 314 |
315 /* | |
316 * update_screen() | |
317 * | |
318 * Based on the current value of curwin->w_topline, transfer a screenfull | |
319 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
320 */ | |
321 void | |
322 update_screen(type) | |
323 int type; | |
324 { | |
325 win_T *wp; | |
326 static int did_intro = FALSE; | |
327 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
328 int did_one; | |
329 #endif | |
330 | |
2008 | 331 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 332 if (!screen_valid(TRUE)) |
333 return; | |
334 | |
335 if (must_redraw) | |
336 { | |
337 if (type < must_redraw) /* use maximal type */ | |
338 type = must_redraw; | |
1331 | 339 |
340 /* must_redraw is reset here, so that when we run into some weird | |
341 * reason to redraw while busy redrawing (e.g., asynchronous | |
342 * scrolling), or update_topline() in win_update() will cause a | |
343 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 344 must_redraw = 0; |
345 } | |
346 | |
347 /* Need to update w_lines[]. */ | |
348 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
349 type = NOT_VALID; | |
350 | |
2008 | 351 /* Postpone the redrawing when it's not needed and when being called |
352 * recursively. */ | |
353 if (!redrawing() || updating_screen) | |
7 | 354 { |
355 redraw_later(type); /* remember type for next time */ | |
356 must_redraw = type; | |
357 if (type > INVERTED_ALL) | |
358 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
359 return; | |
360 } | |
361 | |
362 updating_screen = TRUE; | |
363 #ifdef FEAT_SYN_HL | |
364 ++display_tick; /* let syntax code know we're in a next round of | |
365 * display updating */ | |
366 #endif | |
367 | |
368 /* | |
369 * if the screen was scrolled up when displaying a message, scroll it down | |
370 */ | |
371 if (msg_scrolled) | |
372 { | |
373 clear_cmdline = TRUE; | |
374 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
375 type = CLEAR; | |
376 else if (type != CLEAR) | |
377 { | |
378 check_for_delay(FALSE); | |
379 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
380 type = CLEAR; | |
381 FOR_ALL_WINDOWS(wp) | |
382 { | |
383 if (W_WINROW(wp) < msg_scrolled) | |
384 { | |
385 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
386 && wp->w_redr_type < REDRAW_TOP | |
387 && wp->w_lines_valid > 0 | |
388 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
389 { | |
390 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
391 wp->w_redr_type = REDRAW_TOP; | |
392 } | |
393 else | |
394 { | |
395 wp->w_redr_type = NOT_VALID; | |
396 #ifdef FEAT_WINDOWS | |
397 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
398 <= msg_scrolled) | |
399 wp->w_redr_status = TRUE; | |
400 #endif | |
401 } | |
402 } | |
403 } | |
404 redraw_cmdline = TRUE; | |
667 | 405 #ifdef FEAT_WINDOWS |
673 | 406 redraw_tabline = TRUE; |
667 | 407 #endif |
7 | 408 } |
409 msg_scrolled = 0; | |
410 need_wait_return = FALSE; | |
411 } | |
412 | |
413 /* reset cmdline_row now (may have been changed temporarily) */ | |
414 compute_cmdrow(); | |
415 | |
416 /* Check for changed highlighting */ | |
417 if (need_highlight_changed) | |
418 highlight_changed(); | |
419 | |
420 if (type == CLEAR) /* first clear screen */ | |
421 { | |
422 screenclear(); /* will reset clear_cmdline */ | |
423 type = NOT_VALID; | |
424 } | |
425 | |
426 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
427 check_for_delay(FALSE); | |
428 | |
13 | 429 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
430 /* Force redraw when width of 'number' or 'relativenumber' column |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
431 * changes. */ |
13 | 432 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
433 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
434 ? number_width(curwin) : 0)) |
13 | 435 curwin->w_redr_type = NOT_VALID; |
436 #endif | |
437 | |
7 | 438 /* |
439 * Only start redrawing if there is really something to do. | |
440 */ | |
441 if (type == INVERTED) | |
442 update_curswant(); | |
443 if (curwin->w_redr_type < type | |
444 && !((type == VALID | |
445 && curwin->w_lines[0].wl_valid | |
446 #ifdef FEAT_DIFF | |
447 && curwin->w_topfill == curwin->w_old_topfill | |
448 && curwin->w_botfill == curwin->w_old_botfill | |
449 #endif | |
450 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
451 #ifdef FEAT_VISUAL | |
452 || (type == INVERTED | |
1043 | 453 && VIsual_active |
7 | 454 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
455 && curwin->w_old_visual_mode == VIsual_mode | |
456 && (curwin->w_valid & VALID_VIRTCOL) | |
457 && curwin->w_old_curswant == curwin->w_curswant) | |
458 #endif | |
459 )) | |
460 curwin->w_redr_type = type; | |
461 | |
849 | 462 #ifdef FEAT_WINDOWS |
463 /* Redraw the tab pages line if needed. */ | |
464 if (redraw_tabline || type >= NOT_VALID) | |
465 draw_tabline(); | |
466 #endif | |
467 | |
7 | 468 #ifdef FEAT_SYN_HL |
469 /* | |
470 * Correct stored syntax highlighting info for changes in each displayed | |
471 * buffer. Each buffer must only be done once. | |
472 */ | |
473 FOR_ALL_WINDOWS(wp) | |
474 { | |
475 if (wp->w_buffer->b_mod_set) | |
476 { | |
477 # ifdef FEAT_WINDOWS | |
478 win_T *wwp; | |
479 | |
480 /* Check if we already did this buffer. */ | |
481 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
482 if (wwp->w_buffer == wp->w_buffer) | |
483 break; | |
484 # endif | |
485 if ( | |
486 # ifdef FEAT_WINDOWS | |
487 wwp == wp && | |
488 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
489 syntax_present(wp)) |
7 | 490 syn_stack_apply_changes(wp->w_buffer); |
491 } | |
492 } | |
493 #endif | |
494 | |
495 /* | |
496 * Go from top to bottom through the windows, redrawing the ones that need | |
497 * it. | |
498 */ | |
499 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
500 did_one = FALSE; | |
501 #endif | |
502 #ifdef FEAT_SEARCH_EXTRA | |
503 search_hl.rm.regprog = NULL; | |
504 #endif | |
505 FOR_ALL_WINDOWS(wp) | |
506 { | |
507 if (wp->w_redr_type != 0) | |
508 { | |
509 cursor_off(); | |
510 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
511 if (!did_one) | |
512 { | |
513 did_one = TRUE; | |
514 # ifdef FEAT_SEARCH_EXTRA | |
515 start_search_hl(); | |
516 # endif | |
517 # ifdef FEAT_CLIPBOARD | |
518 /* When Visual area changed, may have to update selection. */ | |
519 if (clip_star.available && clip_isautosel()) | |
520 clip_update_selection(); | |
521 # endif | |
522 #ifdef FEAT_GUI | |
523 /* Remove the cursor before starting to do anything, because | |
524 * scrolling may make it difficult to redraw the text under | |
525 * it. */ | |
526 if (gui.in_use) | |
527 gui_undraw_cursor(); | |
528 #endif | |
529 } | |
530 #endif | |
531 win_update(wp); | |
532 } | |
533 | |
534 #ifdef FEAT_WINDOWS | |
535 /* redraw status line after the window to minimize cursor movement */ | |
536 if (wp->w_redr_status) | |
537 { | |
538 cursor_off(); | |
539 win_redr_status(wp); | |
540 } | |
541 #endif | |
542 } | |
543 #if defined(FEAT_SEARCH_EXTRA) | |
544 end_search_hl(); | |
545 #endif | |
546 | |
547 #ifdef FEAT_WINDOWS | |
548 /* Reset b_mod_set flags. Going through all windows is probably faster | |
549 * than going through all buffers (there could be many buffers). */ | |
550 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
551 wp->w_buffer->b_mod_set = FALSE; | |
552 #else | |
553 curbuf->b_mod_set = FALSE; | |
554 #endif | |
555 | |
556 updating_screen = FALSE; | |
557 #ifdef FEAT_GUI | |
558 gui_may_resize_shell(); | |
559 #endif | |
560 | |
561 /* Clear or redraw the command line. Done last, because scrolling may | |
562 * mess up the command line. */ | |
563 if (clear_cmdline || redraw_cmdline) | |
564 showmode(); | |
565 | |
566 /* May put up an introductory message when not editing a file */ | |
567 if (!did_intro && bufempty() | |
568 && curbuf->b_fname == NULL | |
569 #ifdef FEAT_WINDOWS | |
570 && firstwin->w_next == NULL | |
571 #endif | |
572 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
573 intro_message(FALSE); | |
574 did_intro = TRUE; | |
575 | |
576 #ifdef FEAT_GUI | |
577 /* Redraw the cursor and update the scrollbars when all screen updating is | |
578 * done. */ | |
579 if (gui.in_use) | |
580 { | |
581 out_flush(); /* required before updating the cursor */ | |
582 if (did_one) | |
583 gui_update_cursor(FALSE, FALSE); | |
584 gui_update_scrollbars(FALSE); | |
585 } | |
586 #endif | |
587 } | |
588 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
589 #if defined(FEAT_CONCEAL) || defined(PROTO) |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
590 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
591 * Return TRUE if the cursor line in window "wp" may be concealed, according |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
592 * to the 'concealcursor' option. |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
593 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
594 int |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
595 conceal_cursor_line(wp) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
596 win_T *wp; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
597 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
598 int c; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
599 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
600 if (*wp->w_p_cocu == NUL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
601 return FALSE; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
602 if (get_real_state() & VISUAL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
603 c = 'v'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
604 else if (State & INSERT) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
605 c = 'i'; |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
606 else if (State & NORMAL) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
607 c = 'n'; |
2382
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
608 else if (State & CMDLINE) |
3a5ededa240a
Add the 'c' flag to 'concealcursor'.
Bram Moolenaar <bram@vim.org>
parents:
2381
diff
changeset
|
609 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
|
610 else |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
611 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
|
612 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
|
613 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
614 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
615 /* |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
616 * 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
|
617 */ |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
618 void |
2428
33148c37f3c9
Changes for VMS. Mostly by Zoltan Arpadffy.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
619 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
|
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 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
|
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 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
|
624 /* 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
|
625 * 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
|
626 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
|
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 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
629 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
630 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
631 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
632 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
633 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
634 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
635 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
636 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
637 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
638 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
|
639 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
640 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
641 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
642 /* 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
|
643 * 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
|
644 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
645 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
646 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
647 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
648 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
|
649 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
650 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
|
651 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
652 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
|
653 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
654 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
655 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
656 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
657 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
658 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
|
659 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
660 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
661 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
662 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
663 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
664 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
665 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
666 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
667 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
668 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
669 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
670 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
671 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
672 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
673 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
674 } |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
675 need_cursor_line_redraw = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
676 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
677 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
678 |
7 | 679 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
680 static void update_prepare __ARGS((void)); | |
681 static void update_finish __ARGS((void)); | |
682 | |
683 /* | |
684 * Prepare for updating one or more windows. | |
2008 | 685 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 686 */ |
687 static void | |
688 update_prepare() | |
689 { | |
690 cursor_off(); | |
691 updating_screen = TRUE; | |
692 #ifdef FEAT_GUI | |
693 /* Remove the cursor before starting to do anything, because scrolling may | |
694 * make it difficult to redraw the text under it. */ | |
695 if (gui.in_use) | |
696 gui_undraw_cursor(); | |
697 #endif | |
698 #ifdef FEAT_SEARCH_EXTRA | |
699 start_search_hl(); | |
700 #endif | |
701 } | |
702 | |
703 /* | |
704 * Finish updating one or more windows. | |
705 */ | |
706 static void | |
707 update_finish() | |
708 { | |
709 if (redraw_cmdline) | |
710 showmode(); | |
711 | |
712 # ifdef FEAT_SEARCH_EXTRA | |
713 end_search_hl(); | |
714 # endif | |
715 | |
716 updating_screen = FALSE; | |
717 | |
718 # ifdef FEAT_GUI | |
719 gui_may_resize_shell(); | |
720 | |
721 /* Redraw the cursor and update the scrollbars when all screen updating is | |
722 * done. */ | |
723 if (gui.in_use) | |
724 { | |
725 out_flush(); /* required before updating the cursor */ | |
726 gui_update_cursor(FALSE, FALSE); | |
727 gui_update_scrollbars(FALSE); | |
728 } | |
729 # endif | |
730 } | |
731 #endif | |
732 | |
733 #if defined(FEAT_SIGNS) || defined(PROTO) | |
734 void | |
735 update_debug_sign(buf, lnum) | |
736 buf_T *buf; | |
737 linenr_T lnum; | |
738 { | |
739 win_T *wp; | |
740 int doit = FALSE; | |
741 | |
742 # ifdef FEAT_FOLDING | |
743 win_foldinfo.fi_level = 0; | |
744 # endif | |
745 | |
746 /* update/delete a specific mark */ | |
747 FOR_ALL_WINDOWS(wp) | |
748 { | |
749 if (buf != NULL && lnum > 0) | |
750 { | |
751 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
752 && lnum < wp->w_botline) | |
753 { | |
754 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
755 wp->w_redraw_top = lnum; | |
756 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
757 wp->w_redraw_bot = lnum; | |
758 redraw_win_later(wp, VALID); | |
759 } | |
760 } | |
761 else | |
762 redraw_win_later(wp, VALID); | |
763 if (wp->w_redr_type != 0) | |
764 doit = TRUE; | |
765 } | |
766 | |
2008 | 767 /* Return when there is nothing to do or screen updating already |
768 * happening. */ | |
769 if (!doit || updating_screen) | |
7 | 770 return; |
771 | |
772 /* update all windows that need updating */ | |
773 update_prepare(); | |
774 | |
775 # ifdef FEAT_WINDOWS | |
776 for (wp = firstwin; wp; wp = wp->w_next) | |
777 { | |
778 if (wp->w_redr_type != 0) | |
779 win_update(wp); | |
780 if (wp->w_redr_status) | |
781 win_redr_status(wp); | |
782 } | |
783 # else | |
784 if (curwin->w_redr_type != 0) | |
785 win_update(curwin); | |
786 # endif | |
787 | |
788 update_finish(); | |
789 } | |
790 #endif | |
791 | |
792 | |
793 #if defined(FEAT_GUI) || defined(PROTO) | |
794 /* | |
795 * Update a single window, its status line and maybe the command line msg. | |
796 * Used for the GUI scrollbar. | |
797 */ | |
798 void | |
799 updateWindow(wp) | |
800 win_T *wp; | |
801 { | |
2008 | 802 /* return if already busy updating */ |
803 if (updating_screen) | |
804 return; | |
805 | |
7 | 806 update_prepare(); |
807 | |
808 #ifdef FEAT_CLIPBOARD | |
809 /* When Visual area changed, may have to update selection. */ | |
810 if (clip_star.available && clip_isautosel()) | |
811 clip_update_selection(); | |
812 #endif | |
670 | 813 |
7 | 814 win_update(wp); |
670 | 815 |
7 | 816 #ifdef FEAT_WINDOWS |
670 | 817 /* When the screen was cleared redraw the tab pages line. */ |
673 | 818 if (redraw_tabline) |
677 | 819 draw_tabline(); |
670 | 820 |
7 | 821 if (wp->w_redr_status |
822 # ifdef FEAT_CMDL_INFO | |
823 || p_ru | |
824 # endif | |
825 # ifdef FEAT_STL_OPT | |
40 | 826 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 827 # endif |
828 ) | |
829 win_redr_status(wp); | |
830 #endif | |
831 | |
832 update_finish(); | |
833 } | |
834 #endif | |
835 | |
836 /* | |
837 * Update a single window. | |
838 * | |
839 * This may cause the windows below it also to be redrawn (when clearing the | |
840 * screen or scrolling lines). | |
841 * | |
842 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
843 * implies the one below it. | |
844 * NOT_VALID redraw the whole window | |
743 | 845 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 846 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
847 * INVERTED redraw the changed part of the Visual area | |
848 * INVERTED_ALL redraw the whole Visual area | |
849 * VALID 1. scroll up/down to adjust for a changed w_topline | |
850 * 2. update lines at the top when scrolled down | |
851 * 3. redraw changed text: | |
301 | 852 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 853 * b_mod_top and b_mod_bot. |
854 * - if wp->w_redraw_top non-zero, redraw lines between | |
855 * wp->w_redraw_top and wp->w_redr_bot. | |
856 * - continue redrawing when syntax status is invalid. | |
857 * 4. if scrolled up, update lines at the bottom. | |
858 * This results in three areas that may need updating: | |
859 * top: from first row to top_end (when scrolled down) | |
860 * mid: from mid_start to mid_end (update inversion or changed text) | |
861 * bot: from bot_start to last row (when scrolled up) | |
862 */ | |
863 static void | |
864 win_update(wp) | |
865 win_T *wp; | |
866 { | |
867 buf_T *buf = wp->w_buffer; | |
868 int type; | |
869 int top_end = 0; /* Below last row of the top area that needs | |
870 updating. 0 when no top area updating. */ | |
871 int mid_start = 999;/* first row of the mid area that needs | |
872 updating. 999 when no mid area updating. */ | |
873 int mid_end = 0; /* Below last row of the mid area that needs | |
874 updating. 0 when no mid area updating. */ | |
875 int bot_start = 999;/* first row of the bot area that needs | |
876 updating. 999 when no bot area updating */ | |
877 #ifdef FEAT_VISUAL | |
878 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
879 w_topline got smaller a bit */ | |
880 #endif | |
881 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 882 matchitem_T *cur; /* points to the match list */ |
7 | 883 int top_to_mod = FALSE; /* redraw above mod_top */ |
884 #endif | |
885 | |
886 int row; /* current window row to display */ | |
887 linenr_T lnum; /* current buffer lnum to display */ | |
888 int idx; /* current index in w_lines[] */ | |
889 int srow; /* starting row of the current line */ | |
890 | |
891 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
892 int didline = FALSE; /* if TRUE, we finished the last line */ | |
893 int i; | |
894 long j; | |
895 static int recursive = FALSE; /* being called recursively */ | |
896 int old_botline = wp->w_botline; | |
897 #ifdef FEAT_FOLDING | |
898 long fold_count; | |
899 #endif | |
900 #ifdef FEAT_SYN_HL | |
901 /* remember what happened to the previous line, to know if | |
902 * check_visual_highlight() can be used */ | |
903 #define DID_NONE 1 /* didn't update a line */ | |
904 #define DID_LINE 2 /* updated a normal line */ | |
905 #define DID_FOLD 3 /* updated a folded line */ | |
906 int did_update = DID_NONE; | |
907 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
908 #endif | |
909 linenr_T mod_top = 0; | |
910 linenr_T mod_bot = 0; | |
911 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
912 int save_got_int; | |
913 #endif | |
914 | |
915 type = wp->w_redr_type; | |
916 | |
917 if (type == NOT_VALID) | |
918 { | |
919 #ifdef FEAT_WINDOWS | |
920 wp->w_redr_status = TRUE; | |
921 #endif | |
922 wp->w_lines_valid = 0; | |
923 } | |
924 | |
925 /* Window is zero-height: nothing to draw. */ | |
926 if (wp->w_height == 0) | |
927 { | |
928 wp->w_redr_type = 0; | |
929 return; | |
930 } | |
931 | |
932 #ifdef FEAT_VERTSPLIT | |
933 /* Window is zero-width: Only need to draw the separator. */ | |
934 if (wp->w_width == 0) | |
935 { | |
936 /* draw the vertical separator right of this window */ | |
937 draw_vsep_win(wp, 0); | |
938 wp->w_redr_type = 0; | |
939 return; | |
940 } | |
941 #endif | |
942 | |
943 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
944 init_search_hl(wp); |
7 | 945 #endif |
946 | |
13 | 947 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
948 /* 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
|
949 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
950 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 951 if (wp->w_nrwidth != i) |
13 | 952 { |
953 type = NOT_VALID; | |
677 | 954 wp->w_nrwidth = i; |
13 | 955 } |
956 else | |
957 #endif | |
958 | |
7 | 959 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
960 { | |
961 /* | |
962 * When there are both inserted/deleted lines and specific lines to be | |
963 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
964 * everything (only happens when redrawing is off for while). | |
965 */ | |
966 type = NOT_VALID; | |
967 } | |
968 else | |
969 { | |
970 /* | |
971 * Set mod_top to the first line that needs displaying because of | |
972 * changes. Set mod_bot to the first line after the changes. | |
973 */ | |
974 mod_top = wp->w_redraw_top; | |
975 if (wp->w_redraw_bot != 0) | |
976 mod_bot = wp->w_redraw_bot + 1; | |
977 else | |
978 mod_bot = 0; | |
979 wp->w_redraw_top = 0; /* reset for next time */ | |
980 wp->w_redraw_bot = 0; | |
981 if (buf->b_mod_set) | |
982 { | |
983 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
984 { | |
985 mod_top = buf->b_mod_top; | |
986 #ifdef FEAT_SYN_HL | |
987 /* Need to redraw lines above the change that may be included | |
988 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
989 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
990 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
991 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 992 if (mod_top < 1) |
993 mod_top = 1; | |
994 } | |
995 #endif | |
996 } | |
997 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
998 mod_bot = buf->b_mod_bot; | |
999 | |
1000 #ifdef FEAT_SEARCH_EXTRA | |
1001 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
1002 * change in one line may make the Search highlighting in a | |
1003 * previous line invalid. Simple solution: redraw all visible | |
1004 * lines above the change. | |
1326 | 1005 * Same for a match pattern. |
7 | 1006 */ |
699 | 1007 if (search_hl.rm.regprog != NULL |
1008 && re_multiline(search_hl.rm.regprog)) | |
7 | 1009 top_to_mod = TRUE; |
699 | 1010 else |
1326 | 1011 { |
1012 cur = wp->w_match_head; | |
1013 while (cur != NULL) | |
1014 { | |
1015 if (cur->match.regprog != NULL | |
1016 && re_multiline(cur->match.regprog)) | |
699 | 1017 { |
1018 top_to_mod = TRUE; | |
1019 break; | |
1020 } | |
1326 | 1021 cur = cur->next; |
1022 } | |
1023 } | |
7 | 1024 #endif |
1025 } | |
1026 #ifdef FEAT_FOLDING | |
1027 if (mod_top != 0 && hasAnyFolding(wp)) | |
1028 { | |
1029 linenr_T lnumt, lnumb; | |
1030 | |
1031 /* | |
1032 * A change in a line can cause lines above it to become folded or | |
1033 * unfolded. Find the top most buffer line that may be affected. | |
1034 * If the line was previously folded and displayed, get the first | |
1035 * line of that fold. If the line is folded now, get the first | |
1036 * folded line. Use the minimum of these two. | |
1037 */ | |
1038 | |
1039 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
1040 * the line below it. If there is no valid entry, use w_topline. | |
1041 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1042 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1043 lnumt = wp->w_topline; | |
1044 lnumb = MAXLNUM; | |
1045 for (i = 0; i < wp->w_lines_valid; ++i) | |
1046 if (wp->w_lines[i].wl_valid) | |
1047 { | |
1048 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1049 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1050 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1051 { | |
1052 lnumb = wp->w_lines[i].wl_lnum; | |
1053 /* When there is a fold column it might need updating | |
1054 * in the next line ("J" just above an open fold). */ | |
1055 if (wp->w_p_fdc > 0) | |
1056 ++lnumb; | |
1057 } | |
1058 } | |
1059 | |
1060 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1061 if (mod_top > lnumt) | |
1062 mod_top = lnumt; | |
1063 | |
1064 /* Now do the same for the bottom line (one above mod_bot). */ | |
1065 --mod_bot; | |
1066 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1067 ++mod_bot; | |
1068 if (mod_bot < lnumb) | |
1069 mod_bot = lnumb; | |
1070 } | |
1071 #endif | |
1072 | |
1073 /* When a change starts above w_topline and the end is below | |
1074 * w_topline, start redrawing at w_topline. | |
36 | 1075 * If the end of the change is above w_topline: do like no change was |
1076 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1077 if (mod_top != 0 && mod_top < wp->w_topline) |
1078 { | |
1079 if (mod_bot > wp->w_topline) | |
1080 mod_top = wp->w_topline; | |
1081 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1082 else if (syntax_present(wp)) |
7 | 1083 top_end = 1; |
1084 #endif | |
1085 } | |
36 | 1086 |
1087 /* When line numbers are displayed need to redraw all lines below | |
1088 * inserted/deleted lines. */ | |
1089 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1090 mod_bot = MAXLNUM; | |
7 | 1091 } |
1092 | |
1093 /* | |
1094 * When only displaying the lines at the top, set top_end. Used when | |
1095 * window has scrolled down for msg_scrolled. | |
1096 */ | |
1097 if (type == REDRAW_TOP) | |
1098 { | |
1099 j = 0; | |
1100 for (i = 0; i < wp->w_lines_valid; ++i) | |
1101 { | |
1102 j += wp->w_lines[i].wl_size; | |
1103 if (j >= wp->w_upd_rows) | |
1104 { | |
1105 top_end = j; | |
1106 break; | |
1107 } | |
1108 } | |
1109 if (top_end == 0) | |
1110 /* not found (cannot happen?): redraw everything */ | |
1111 type = NOT_VALID; | |
1112 else | |
1113 /* top area defined, the rest is VALID */ | |
1114 type = VALID; | |
1115 } | |
1116 | |
1378 | 1117 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1118 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1119 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1120 * called. */ | |
1121 if (screen_cleared) | |
1122 screen_cleared = MAYBE; | |
1123 | |
7 | 1124 /* |
1125 * If there are no changes on the screen that require a complete redraw, | |
1126 * handle three cases: | |
1127 * 1: we are off the top of the screen by a few lines: scroll down | |
1128 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1129 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1130 * w_lines[] that needs updating. | |
1131 */ | |
743 | 1132 if ((type == VALID || type == SOME_VALID |
1133 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1134 #ifdef FEAT_DIFF |
1135 && !wp->w_botfill && !wp->w_old_botfill | |
1136 #endif | |
1137 ) | |
1138 { | |
1139 if (mod_top != 0 && wp->w_topline == mod_top) | |
1140 { | |
1141 /* | |
1142 * w_topline is the first changed line, the scrolling will be done | |
1143 * further down. | |
1144 */ | |
1145 } | |
1146 else if (wp->w_lines[0].wl_valid | |
1147 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1148 #ifdef FEAT_DIFF | |
1149 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1150 && wp->w_topfill > wp->w_old_topfill) | |
1151 #endif | |
1152 )) | |
1153 { | |
1154 /* | |
1155 * New topline is above old topline: May scroll down. | |
1156 */ | |
1157 #ifdef FEAT_FOLDING | |
1158 if (hasAnyFolding(wp)) | |
1159 { | |
1160 linenr_T ln; | |
1161 | |
1162 /* count the number of lines we are off, counting a sequence | |
1163 * of folded lines as one */ | |
1164 j = 0; | |
1165 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1166 { | |
1167 ++j; | |
1168 if (j >= wp->w_height - 2) | |
1169 break; | |
1170 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1171 } | |
1172 } | |
1173 else | |
1174 #endif | |
1175 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1176 if (j < wp->w_height - 2) /* not too far off */ | |
1177 { | |
1178 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1179 #ifdef FEAT_DIFF | |
1180 /* insert extra lines for previously invisible filler lines */ | |
1181 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1182 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1183 - wp->w_old_topfill; | |
1184 #endif | |
1185 if (i < wp->w_height - 2) /* less than a screen off */ | |
1186 { | |
1187 /* | |
1188 * Try to insert the correct number of lines. | |
1189 * If not the last window, delete the lines at the bottom. | |
1190 * win_ins_lines may fail when the terminal can't do it. | |
1191 */ | |
1192 if (i > 0) | |
1193 check_for_delay(FALSE); | |
1194 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1195 { | |
1196 if (wp->w_lines_valid != 0) | |
1197 { | |
1198 /* Need to update rows that are new, stop at the | |
1199 * first one that scrolled down. */ | |
1200 top_end = i; | |
1201 #ifdef FEAT_VISUAL | |
1202 scrolled_down = TRUE; | |
1203 #endif | |
1204 | |
1205 /* Move the entries that were scrolled, disable | |
1206 * the entries for the lines to be redrawn. */ | |
1207 if ((wp->w_lines_valid += j) > wp->w_height) | |
1208 wp->w_lines_valid = wp->w_height; | |
1209 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1210 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1211 while (idx >= 0) | |
1212 wp->w_lines[idx--].wl_valid = FALSE; | |
1213 } | |
1214 } | |
1215 else | |
1216 mid_start = 0; /* redraw all lines */ | |
1217 } | |
1218 else | |
1219 mid_start = 0; /* redraw all lines */ | |
1220 } | |
1221 else | |
1222 mid_start = 0; /* redraw all lines */ | |
1223 } | |
1224 else | |
1225 { | |
1226 /* | |
1227 * New topline is at or below old topline: May scroll up. | |
1228 * When topline didn't change, find first entry in w_lines[] that | |
1229 * needs updating. | |
1230 */ | |
1231 | |
1232 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1233 j = -1; | |
1234 row = 0; | |
1235 for (i = 0; i < wp->w_lines_valid; i++) | |
1236 { | |
1237 if (wp->w_lines[i].wl_valid | |
1238 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1239 { | |
1240 j = i; | |
1241 break; | |
1242 } | |
1243 row += wp->w_lines[i].wl_size; | |
1244 } | |
1245 if (j == -1) | |
1246 { | |
1247 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1248 * lines */ | |
1249 mid_start = 0; | |
1250 } | |
1251 else | |
1252 { | |
1253 /* | |
1254 * Try to delete the correct number of lines. | |
1255 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1256 */ | |
1257 #ifdef FEAT_DIFF | |
1258 /* If the topline didn't change, delete old filler lines, | |
1259 * otherwise delete filler lines of the new topline... */ | |
1260 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1261 row += wp->w_old_topfill; | |
1262 else | |
1263 row += diff_check_fill(wp, wp->w_topline); | |
1264 /* ... but don't delete new filler lines. */ | |
1265 row -= wp->w_topfill; | |
1266 #endif | |
1267 if (row > 0) | |
1268 { | |
1269 check_for_delay(FALSE); | |
1270 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1271 bot_start = wp->w_height - row; | |
1272 else | |
1273 mid_start = 0; /* redraw all lines */ | |
1274 } | |
1275 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1276 { | |
1277 /* | |
1278 * Skip the lines (below the deleted lines) that are still | |
1279 * valid and don't need redrawing. Copy their info | |
1280 * upwards, to compensate for the deleted lines. Set | |
1281 * bot_start to the first row that needs redrawing. | |
1282 */ | |
1283 bot_start = 0; | |
1284 idx = 0; | |
1285 for (;;) | |
1286 { | |
1287 wp->w_lines[idx] = wp->w_lines[j]; | |
1288 /* stop at line that didn't fit, unless it is still | |
1289 * valid (no lines deleted) */ | |
1290 if (row > 0 && bot_start + row | |
1291 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1292 { | |
1293 wp->w_lines_valid = idx + 1; | |
1294 break; | |
1295 } | |
1296 bot_start += wp->w_lines[idx++].wl_size; | |
1297 | |
1298 /* stop at the last valid entry in w_lines[].wl_size */ | |
1299 if (++j >= wp->w_lines_valid) | |
1300 { | |
1301 wp->w_lines_valid = idx; | |
1302 break; | |
1303 } | |
1304 } | |
1305 #ifdef FEAT_DIFF | |
1306 /* Correct the first entry for filler lines at the top | |
1307 * when it won't get updated below. */ | |
1308 if (wp->w_p_diff && bot_start > 0) | |
1309 wp->w_lines[0].wl_size = | |
1310 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1311 + wp->w_topfill; | |
1312 #endif | |
1313 } | |
1314 } | |
1315 } | |
1316 | |
1317 /* When starting redraw in the first line, redraw all lines. When | |
1318 * there is only one window it's probably faster to clear the screen | |
1319 * first. */ | |
1320 if (mid_start == 0) | |
1321 { | |
1322 mid_end = wp->w_height; | |
1323 if (lastwin == firstwin) | |
981 | 1324 { |
1331 | 1325 /* Clear the screen when it was not done by win_del_lines() or |
1326 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1327 * then. */ | |
1328 if (screen_cleared != TRUE) | |
1329 screenclear(); | |
981 | 1330 #ifdef FEAT_WINDOWS |
1331 /* The screen was cleared, redraw the tab pages line. */ | |
1332 if (redraw_tabline) | |
1333 draw_tabline(); | |
1334 #endif | |
1335 } | |
7 | 1336 } |
1331 | 1337 |
1338 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1339 * cleared (only happens for the first window) or when screenclear() | |
1340 * was called directly above, "must_redraw" will have been set to | |
1341 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1342 if (screen_cleared == TRUE) | |
1343 must_redraw = 0; | |
7 | 1344 } |
1345 else | |
1346 { | |
1347 /* Not VALID or INVERTED: redraw all lines. */ | |
1348 mid_start = 0; | |
1349 mid_end = wp->w_height; | |
1350 } | |
1351 | |
743 | 1352 if (type == SOME_VALID) |
1353 { | |
1354 /* SOME_VALID: redraw all lines. */ | |
1355 mid_start = 0; | |
1356 mid_end = wp->w_height; | |
1357 type = NOT_VALID; | |
1358 } | |
1359 | |
7 | 1360 #ifdef FEAT_VISUAL |
1361 /* check if we are updating or removing the inverted part */ | |
1362 if ((VIsual_active && buf == curwin->w_buffer) | |
1363 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1364 { | |
1365 linenr_T from, to; | |
1366 | |
1367 if (VIsual_active) | |
1368 { | |
1369 if (VIsual_active | |
1370 && (VIsual_mode != wp->w_old_visual_mode | |
1371 || type == INVERTED_ALL)) | |
1372 { | |
1373 /* | |
1374 * If the type of Visual selection changed, redraw the whole | |
1375 * selection. Also when the ownership of the X selection is | |
1376 * gained or lost. | |
1377 */ | |
1378 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1379 { | |
1380 from = curwin->w_cursor.lnum; | |
1381 to = VIsual.lnum; | |
1382 } | |
1383 else | |
1384 { | |
1385 from = VIsual.lnum; | |
1386 to = curwin->w_cursor.lnum; | |
1387 } | |
1388 /* redraw more when the cursor moved as well */ | |
1389 if (wp->w_old_cursor_lnum < from) | |
1390 from = wp->w_old_cursor_lnum; | |
1391 if (wp->w_old_cursor_lnum > to) | |
1392 to = wp->w_old_cursor_lnum; | |
1393 if (wp->w_old_visual_lnum < from) | |
1394 from = wp->w_old_visual_lnum; | |
1395 if (wp->w_old_visual_lnum > to) | |
1396 to = wp->w_old_visual_lnum; | |
1397 } | |
1398 else | |
1399 { | |
1400 /* | |
1401 * Find the line numbers that need to be updated: The lines | |
1402 * between the old cursor position and the current cursor | |
1403 * position. Also check if the Visual position changed. | |
1404 */ | |
1405 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1406 { | |
1407 from = curwin->w_cursor.lnum; | |
1408 to = wp->w_old_cursor_lnum; | |
1409 } | |
1410 else | |
1411 { | |
1412 from = wp->w_old_cursor_lnum; | |
1413 to = curwin->w_cursor.lnum; | |
1414 if (from == 0) /* Visual mode just started */ | |
1415 from = to; | |
1416 } | |
1417 | |
422 | 1418 if (VIsual.lnum != wp->w_old_visual_lnum |
1419 || VIsual.col != wp->w_old_visual_col) | |
7 | 1420 { |
1421 if (wp->w_old_visual_lnum < from | |
1422 && wp->w_old_visual_lnum != 0) | |
1423 from = wp->w_old_visual_lnum; | |
1424 if (wp->w_old_visual_lnum > to) | |
1425 to = wp->w_old_visual_lnum; | |
1426 if (VIsual.lnum < from) | |
1427 from = VIsual.lnum; | |
1428 if (VIsual.lnum > to) | |
1429 to = VIsual.lnum; | |
1430 } | |
1431 } | |
1432 | |
1433 /* | |
1434 * If in block mode and changed column or curwin->w_curswant: | |
1435 * update all lines. | |
1436 * First compute the actual start and end column. | |
1437 */ | |
1438 if (VIsual_mode == Ctrl_V) | |
1439 { | |
1440 colnr_T fromc, toc; | |
1441 | |
1442 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1443 ++toc; | |
1444 if (curwin->w_curswant == MAXCOL) | |
1445 toc = MAXCOL; | |
1446 | |
1447 if (fromc != wp->w_old_cursor_fcol | |
1448 || toc != wp->w_old_cursor_lcol) | |
1449 { | |
1450 if (from > VIsual.lnum) | |
1451 from = VIsual.lnum; | |
1452 if (to < VIsual.lnum) | |
1453 to = VIsual.lnum; | |
1454 } | |
1455 wp->w_old_cursor_fcol = fromc; | |
1456 wp->w_old_cursor_lcol = toc; | |
1457 } | |
1458 } | |
1459 else | |
1460 { | |
1461 /* Use the line numbers of the old Visual area. */ | |
1462 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1463 { | |
1464 from = wp->w_old_cursor_lnum; | |
1465 to = wp->w_old_visual_lnum; | |
1466 } | |
1467 else | |
1468 { | |
1469 from = wp->w_old_visual_lnum; | |
1470 to = wp->w_old_cursor_lnum; | |
1471 } | |
1472 } | |
1473 | |
1474 /* | |
1475 * There is no need to update lines above the top of the window. | |
1476 */ | |
1477 if (from < wp->w_topline) | |
1478 from = wp->w_topline; | |
1479 | |
1480 /* | |
1481 * If we know the value of w_botline, use it to restrict the update to | |
1482 * the lines that are visible in the window. | |
1483 */ | |
1484 if (wp->w_valid & VALID_BOTLINE) | |
1485 { | |
1486 if (from >= wp->w_botline) | |
1487 from = wp->w_botline - 1; | |
1488 if (to >= wp->w_botline) | |
1489 to = wp->w_botline - 1; | |
1490 } | |
1491 | |
1492 /* | |
1493 * Find the minimal part to be updated. | |
1494 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1495 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1496 * top_end; need to redraw from top_end to the "to" line. | |
1497 * A middle mouse click with a Visual selection may change the text | |
1498 * above the Visual area and reset wl_valid, do count these for | |
1499 * mid_end (in srow). | |
1500 */ | |
1501 if (mid_start > 0) | |
1502 { | |
1503 lnum = wp->w_topline; | |
1504 idx = 0; | |
1505 srow = 0; | |
1506 if (scrolled_down) | |
1507 mid_start = top_end; | |
1508 else | |
1509 mid_start = 0; | |
1510 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1511 { | |
1512 if (wp->w_lines[idx].wl_valid) | |
1513 mid_start += wp->w_lines[idx].wl_size; | |
1514 else if (!scrolled_down) | |
1515 srow += wp->w_lines[idx].wl_size; | |
1516 ++idx; | |
1517 # ifdef FEAT_FOLDING | |
1518 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1519 lnum = wp->w_lines[idx].wl_lnum; | |
1520 else | |
1521 # endif | |
1522 ++lnum; | |
1523 } | |
1524 srow += mid_start; | |
1525 mid_end = wp->w_height; | |
1526 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1527 { | |
1528 if (wp->w_lines[idx].wl_valid | |
1529 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1530 { | |
1531 /* Only update until first row of this line */ | |
1532 mid_end = srow; | |
1533 break; | |
1534 } | |
1535 srow += wp->w_lines[idx].wl_size; | |
1536 } | |
1537 } | |
1538 } | |
1539 | |
1540 if (VIsual_active && buf == curwin->w_buffer) | |
1541 { | |
1542 wp->w_old_visual_mode = VIsual_mode; | |
1543 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1544 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1545 wp->w_old_visual_col = VIsual.col; |
7 | 1546 wp->w_old_curswant = curwin->w_curswant; |
1547 } | |
1548 else | |
1549 { | |
1550 wp->w_old_visual_mode = 0; | |
1551 wp->w_old_cursor_lnum = 0; | |
1552 wp->w_old_visual_lnum = 0; | |
422 | 1553 wp->w_old_visual_col = 0; |
7 | 1554 } |
1555 #endif /* FEAT_VISUAL */ | |
1556 | |
1557 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1558 /* reset got_int, otherwise regexp won't work */ | |
1559 save_got_int = got_int; | |
1560 got_int = 0; | |
1561 #endif | |
1562 #ifdef FEAT_FOLDING | |
1563 win_foldinfo.fi_level = 0; | |
1564 #endif | |
1565 | |
1566 /* | |
1567 * Update all the window rows. | |
1568 */ | |
1569 idx = 0; /* first entry in w_lines[].wl_size */ | |
1570 row = 0; | |
1571 srow = 0; | |
1572 lnum = wp->w_topline; /* first line shown in window */ | |
1573 for (;;) | |
1574 { | |
1575 /* stop updating when reached the end of the window (check for _past_ | |
1576 * the end of the window is at the end of the loop) */ | |
1577 if (row == wp->w_height) | |
1578 { | |
1579 didline = TRUE; | |
1580 break; | |
1581 } | |
1582 | |
1583 /* stop updating when hit the end of the file */ | |
1584 if (lnum > buf->b_ml.ml_line_count) | |
1585 { | |
1586 eof = TRUE; | |
1587 break; | |
1588 } | |
1589 | |
1590 /* Remember the starting row of the line that is going to be dealt | |
1591 * with. It is used further down when the line doesn't fit. */ | |
1592 srow = row; | |
1593 | |
1594 /* | |
1595 * Update a line when it is in an area that needs updating, when it | |
1596 * has changes or w_lines[idx] is invalid. | |
1597 * bot_start may be halfway a wrapped line after using | |
1598 * win_del_lines(), check if the current line includes it. | |
1599 * When syntax folding is being used, the saved syntax states will | |
1600 * already have been updated, we can't see where the syntax state is | |
1601 * the same again, just update until the end of the window. | |
1602 */ | |
1603 if (row < top_end | |
1604 || (row >= mid_start && row < mid_end) | |
1605 #ifdef FEAT_SEARCH_EXTRA | |
1606 || top_to_mod | |
1607 #endif | |
1608 || idx >= wp->w_lines_valid | |
1609 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1610 || (mod_top != 0 | |
1611 && (lnum == mod_top | |
1612 || (lnum >= mod_top | |
1613 && (lnum < mod_bot | |
1614 #ifdef FEAT_SYN_HL | |
1615 || did_update == DID_FOLD | |
1616 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1617 && syntax_present(wp) |
7 | 1618 && ( |
1619 # ifdef FEAT_FOLDING | |
1620 (foldmethodIsSyntax(wp) | |
1621 && hasAnyFolding(wp)) || | |
1622 # endif | |
1623 syntax_check_changed(lnum))) | |
1624 #endif | |
1625 ))))) | |
1626 { | |
1627 #ifdef FEAT_SEARCH_EXTRA | |
1628 if (lnum == mod_top) | |
1629 top_to_mod = FALSE; | |
1630 #endif | |
1631 | |
1632 /* | |
1633 * When at start of changed lines: May scroll following lines | |
1634 * up or down to minimize redrawing. | |
1635 * Don't do this when the change continues until the end. | |
1636 * Don't scroll when dollar_vcol is non-zero, keep the "$". | |
1637 */ | |
1638 if (lnum == mod_top | |
1639 && mod_bot != MAXLNUM | |
1640 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) | |
1641 { | |
1642 int old_rows = 0; | |
1643 int new_rows = 0; | |
1644 int xtra_rows; | |
1645 linenr_T l; | |
1646 | |
1647 /* Count the old number of window rows, using w_lines[], which | |
1648 * should still contain the sizes for the lines as they are | |
1649 * currently displayed. */ | |
1650 for (i = idx; i < wp->w_lines_valid; ++i) | |
1651 { | |
1652 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1653 * lines are part of the changed area. */ | |
1654 if (wp->w_lines[i].wl_valid | |
1655 && wp->w_lines[i].wl_lnum == mod_bot) | |
1656 break; | |
1657 old_rows += wp->w_lines[i].wl_size; | |
1658 #ifdef FEAT_FOLDING | |
1659 if (wp->w_lines[i].wl_valid | |
1660 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1661 { | |
1662 /* Must have found the last valid entry above mod_bot. | |
1663 * Add following invalid entries. */ | |
1664 ++i; | |
1665 while (i < wp->w_lines_valid | |
1666 && !wp->w_lines[i].wl_valid) | |
1667 old_rows += wp->w_lines[i++].wl_size; | |
1668 break; | |
1669 } | |
1670 #endif | |
1671 } | |
1672 | |
1673 if (i >= wp->w_lines_valid) | |
1674 { | |
1675 /* We can't find a valid line below the changed lines, | |
1676 * need to redraw until the end of the window. | |
1677 * Inserting/deleting lines has no use. */ | |
1678 bot_start = 0; | |
1679 } | |
1680 else | |
1681 { | |
1682 /* Able to count old number of rows: Count new window | |
1683 * rows, and may insert/delete lines */ | |
1684 j = idx; | |
1685 for (l = lnum; l < mod_bot; ++l) | |
1686 { | |
1687 #ifdef FEAT_FOLDING | |
1688 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1689 ++new_rows; | |
1690 else | |
1691 #endif | |
1692 #ifdef FEAT_DIFF | |
1693 if (l == wp->w_topline) | |
1694 new_rows += plines_win_nofill(wp, l, TRUE) | |
1695 + wp->w_topfill; | |
1696 else | |
1697 #endif | |
1698 new_rows += plines_win(wp, l, TRUE); | |
1699 ++j; | |
1700 if (new_rows > wp->w_height - row - 2) | |
1701 { | |
1702 /* it's getting too much, must redraw the rest */ | |
1703 new_rows = 9999; | |
1704 break; | |
1705 } | |
1706 } | |
1707 xtra_rows = new_rows - old_rows; | |
1708 if (xtra_rows < 0) | |
1709 { | |
1710 /* May scroll text up. If there is not enough | |
1711 * remaining text or scrolling fails, must redraw the | |
1712 * rest. If scrolling works, must redraw the text | |
1713 * below the scrolled text. */ | |
1714 if (row - xtra_rows >= wp->w_height - 2) | |
1715 mod_bot = MAXLNUM; | |
1716 else | |
1717 { | |
1718 check_for_delay(FALSE); | |
1719 if (win_del_lines(wp, row, | |
1720 -xtra_rows, FALSE, FALSE) == FAIL) | |
1721 mod_bot = MAXLNUM; | |
1722 else | |
1723 bot_start = wp->w_height + xtra_rows; | |
1724 } | |
1725 } | |
1726 else if (xtra_rows > 0) | |
1727 { | |
1728 /* May scroll text down. If there is not enough | |
1729 * remaining text of scrolling fails, must redraw the | |
1730 * rest. */ | |
1731 if (row + xtra_rows >= wp->w_height - 2) | |
1732 mod_bot = MAXLNUM; | |
1733 else | |
1734 { | |
1735 check_for_delay(FALSE); | |
1736 if (win_ins_lines(wp, row + old_rows, | |
1737 xtra_rows, FALSE, FALSE) == FAIL) | |
1738 mod_bot = MAXLNUM; | |
1739 else if (top_end > row + old_rows) | |
1740 /* Scrolled the part at the top that requires | |
1741 * updating down. */ | |
1742 top_end += xtra_rows; | |
1743 } | |
1744 } | |
1745 | |
1746 /* When not updating the rest, may need to move w_lines[] | |
1747 * entries. */ | |
1748 if (mod_bot != MAXLNUM && i != j) | |
1749 { | |
1750 if (j < i) | |
1751 { | |
1752 int x = row + new_rows; | |
1753 | |
1754 /* move entries in w_lines[] upwards */ | |
1755 for (;;) | |
1756 { | |
1757 /* stop at last valid entry in w_lines[] */ | |
1758 if (i >= wp->w_lines_valid) | |
1759 { | |
1760 wp->w_lines_valid = j; | |
1761 break; | |
1762 } | |
1763 wp->w_lines[j] = wp->w_lines[i]; | |
1764 /* stop at a line that won't fit */ | |
1765 if (x + (int)wp->w_lines[j].wl_size | |
1766 > wp->w_height) | |
1767 { | |
1768 wp->w_lines_valid = j + 1; | |
1769 break; | |
1770 } | |
1771 x += wp->w_lines[j++].wl_size; | |
1772 ++i; | |
1773 } | |
1774 if (bot_start > x) | |
1775 bot_start = x; | |
1776 } | |
1777 else /* j > i */ | |
1778 { | |
1779 /* move entries in w_lines[] downwards */ | |
1780 j -= i; | |
1781 wp->w_lines_valid += j; | |
1782 if (wp->w_lines_valid > wp->w_height) | |
1783 wp->w_lines_valid = wp->w_height; | |
1784 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1785 wp->w_lines[i] = wp->w_lines[i - j]; | |
1786 | |
1787 /* The w_lines[] entries for inserted lines are | |
1788 * now invalid, but wl_size may be used above. | |
1789 * Reset to zero. */ | |
1790 while (i >= idx) | |
1791 { | |
1792 wp->w_lines[i].wl_size = 0; | |
1793 wp->w_lines[i--].wl_valid = FALSE; | |
1794 } | |
1795 } | |
1796 } | |
1797 } | |
1798 } | |
1799 | |
1800 #ifdef FEAT_FOLDING | |
1801 /* | |
1802 * When lines are folded, display one line for all of them. | |
1803 * Otherwise, display normally (can be several display lines when | |
1804 * 'wrap' is on). | |
1805 */ | |
1806 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1807 if (fold_count != 0) | |
1808 { | |
1809 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1810 ++row; | |
1811 --fold_count; | |
1812 wp->w_lines[idx].wl_folded = TRUE; | |
1813 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1814 # ifdef FEAT_SYN_HL | |
1815 did_update = DID_FOLD; | |
1816 # endif | |
1817 } | |
1818 else | |
1819 #endif | |
1820 if (idx < wp->w_lines_valid | |
1821 && wp->w_lines[idx].wl_valid | |
1822 && wp->w_lines[idx].wl_lnum == lnum | |
1823 && lnum > wp->w_topline | |
1824 && !(dy_flags & DY_LASTLINE) | |
1825 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1826 #ifdef FEAT_DIFF | |
1827 && diff_check_fill(wp, lnum) == 0 | |
1828 #endif | |
1829 ) | |
1830 { | |
1831 /* This line is not going to fit. Don't draw anything here, | |
1832 * will draw "@ " lines below. */ | |
1833 row = wp->w_height + 1; | |
1834 } | |
1835 else | |
1836 { | |
1837 #ifdef FEAT_SEARCH_EXTRA | |
1838 prepare_search_hl(wp, lnum); | |
1839 #endif | |
1840 #ifdef FEAT_SYN_HL | |
1841 /* Let the syntax stuff know we skipped a few lines. */ | |
1842 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
|
1843 && syntax_present(wp)) |
7 | 1844 syntax_end_parsing(syntax_last_parsed + 1); |
1845 #endif | |
1846 | |
1847 /* | |
1848 * Display one line. | |
1849 */ | |
625 | 1850 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1851 |
1852 #ifdef FEAT_FOLDING | |
1853 wp->w_lines[idx].wl_folded = FALSE; | |
1854 wp->w_lines[idx].wl_lastlnum = lnum; | |
1855 #endif | |
1856 #ifdef FEAT_SYN_HL | |
1857 did_update = DID_LINE; | |
1858 syntax_last_parsed = lnum; | |
1859 #endif | |
1860 } | |
1861 | |
1862 wp->w_lines[idx].wl_lnum = lnum; | |
1863 wp->w_lines[idx].wl_valid = TRUE; | |
1864 if (row > wp->w_height) /* past end of screen */ | |
1865 { | |
1866 /* we may need the size of that too long line later on */ | |
1867 if (dollar_vcol == 0) | |
1868 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); | |
1869 ++idx; | |
1870 break; | |
1871 } | |
1872 if (dollar_vcol == 0) | |
1873 wp->w_lines[idx].wl_size = row - srow; | |
1874 ++idx; | |
1875 #ifdef FEAT_FOLDING | |
1876 lnum += fold_count + 1; | |
1877 #else | |
1878 ++lnum; | |
1879 #endif | |
1880 } | |
1881 else | |
1882 { | |
1883 /* This line does not need updating, advance to the next one */ | |
1884 row += wp->w_lines[idx++].wl_size; | |
1885 if (row > wp->w_height) /* past end of screen */ | |
1886 break; | |
1887 #ifdef FEAT_FOLDING | |
1888 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1889 #else | |
1890 ++lnum; | |
1891 #endif | |
1892 #ifdef FEAT_SYN_HL | |
1893 did_update = DID_NONE; | |
1894 #endif | |
1895 } | |
1896 | |
1897 if (lnum > buf->b_ml.ml_line_count) | |
1898 { | |
1899 eof = TRUE; | |
1900 break; | |
1901 } | |
1902 } | |
1903 /* | |
1904 * End of loop over all window lines. | |
1905 */ | |
1906 | |
1907 | |
1908 if (idx > wp->w_lines_valid) | |
1909 wp->w_lines_valid = idx; | |
1910 | |
1911 #ifdef FEAT_SYN_HL | |
1912 /* | |
1913 * Let the syntax stuff know we stop parsing here. | |
1914 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1915 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1916 syntax_end_parsing(syntax_last_parsed + 1); |
1917 #endif | |
1918 | |
1919 /* | |
1920 * If we didn't hit the end of the file, and we didn't finish the last | |
1921 * line we were working on, then the line didn't fit. | |
1922 */ | |
1923 wp->w_empty_rows = 0; | |
1924 #ifdef FEAT_DIFF | |
1925 wp->w_filler_rows = 0; | |
1926 #endif | |
1927 if (!eof && !didline) | |
1928 { | |
1929 if (lnum == wp->w_topline) | |
1930 { | |
1931 /* | |
1932 * Single line that does not fit! | |
1933 * Don't overwrite it, it can be edited. | |
1934 */ | |
1935 wp->w_botline = lnum + 1; | |
1936 } | |
1937 #ifdef FEAT_DIFF | |
1938 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1939 { | |
1940 /* Window ends in filler lines. */ | |
1941 wp->w_botline = lnum; | |
1942 wp->w_filler_rows = wp->w_height - srow; | |
1943 } | |
1944 #endif | |
1945 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1946 { | |
1947 /* | |
1948 * Last line isn't finished: Display "@@@" at the end. | |
1949 */ | |
1950 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1951 W_WINROW(wp) + wp->w_height, | |
1952 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1953 '@', '@', hl_attr(HLF_AT)); | |
1954 set_empty_rows(wp, srow); | |
1955 wp->w_botline = lnum; | |
1956 } | |
1957 else | |
1958 { | |
1959 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1960 wp->w_botline = lnum; | |
1961 } | |
1962 } | |
1963 else | |
1964 { | |
1965 #ifdef FEAT_VERTSPLIT | |
1966 draw_vsep_win(wp, row); | |
1967 #endif | |
1968 if (eof) /* we hit the end of the file */ | |
1969 { | |
1970 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1971 #ifdef FEAT_DIFF | |
1972 j = diff_check_fill(wp, wp->w_botline); | |
1973 if (j > 0 && !wp->w_botfill) | |
1974 { | |
1975 /* | |
1976 * Display filler lines at the end of the file | |
1977 */ | |
1978 if (char2cells(fill_diff) > 1) | |
1979 i = '-'; | |
1980 else | |
1981 i = fill_diff; | |
1982 if (row + j > wp->w_height) | |
1983 j = wp->w_height - row; | |
1984 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1985 row += j; | |
1986 } | |
1987 #endif | |
1988 } | |
1989 else if (dollar_vcol == 0) | |
1990 wp->w_botline = lnum; | |
1991 | |
1992 /* make sure the rest of the screen is blank */ | |
1993 /* put '~'s on rows that aren't part of the file. */ | |
1994 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
1995 } | |
1996 | |
1997 /* Reset the type of redrawing required, the window has been updated. */ | |
1998 wp->w_redr_type = 0; | |
1999 #ifdef FEAT_DIFF | |
2000 wp->w_old_topfill = wp->w_topfill; | |
2001 wp->w_old_botfill = wp->w_botfill; | |
2002 #endif | |
2003 | |
2004 if (dollar_vcol == 0) | |
2005 { | |
2006 /* | |
2007 * There is a trick with w_botline. If we invalidate it on each | |
2008 * change that might modify it, this will cause a lot of expensive | |
2009 * calls to plines() in update_topline() each time. Therefore the | |
2010 * value of w_botline is often approximated, and this value is used to | |
2011 * compute the value of w_topline. If the value of w_botline was | |
2012 * wrong, check that the value of w_topline is correct (cursor is on | |
2013 * the visible part of the text). If it's not, we need to redraw | |
2014 * again. Mostly this just means scrolling up a few lines, so it | |
2015 * doesn't look too bad. Only do this for the current window (where | |
2016 * changes are relevant). | |
2017 */ | |
2018 wp->w_valid |= VALID_BOTLINE; | |
2019 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
2020 { | |
2021 recursive = TRUE; | |
2022 curwin->w_valid &= ~VALID_TOPLINE; | |
2023 update_topline(); /* may invalidate w_botline again */ | |
2024 if (must_redraw != 0) | |
2025 { | |
2026 /* Don't update for changes in buffer again. */ | |
2027 i = curbuf->b_mod_set; | |
2028 curbuf->b_mod_set = FALSE; | |
2029 win_update(curwin); | |
2030 must_redraw = 0; | |
2031 curbuf->b_mod_set = i; | |
2032 } | |
2033 recursive = FALSE; | |
2034 } | |
2035 } | |
2036 | |
2037 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
2038 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
2039 if (!got_int) | |
2040 got_int = save_got_int; | |
2041 #endif | |
2042 } | |
2043 | |
2044 #ifdef FEAT_SIGNS | |
2045 static int draw_signcolumn __ARGS((win_T *wp)); | |
2046 | |
2047 /* | |
2048 * Return TRUE when window "wp" has a column to draw signs in. | |
2049 */ | |
2050 static int | |
2051 draw_signcolumn(wp) | |
2052 win_T *wp; | |
2053 { | |
2054 return (wp->w_buffer->b_signlist != NULL | |
2055 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2056 || netbeans_active() |
7 | 2057 # endif |
2058 ); | |
2059 } | |
2060 #endif | |
2061 | |
2062 /* | |
2063 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2064 * as the filler character. | |
2065 */ | |
2066 static void | |
2067 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2068 win_T *wp; | |
2069 int c1; | |
2070 int c2; | |
2071 int row; | |
2072 int endrow; | |
534 | 2073 hlf_T hl; |
7 | 2074 { |
2075 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2076 int n = 0; | |
2077 # define FDC_OFF n | |
2078 #else | |
2079 # define FDC_OFF 0 | |
2080 #endif | |
2081 | |
2082 #ifdef FEAT_RIGHTLEFT | |
2083 if (wp->w_p_rl) | |
2084 { | |
2085 /* No check for cmdline window: should never be right-left. */ | |
2086 # ifdef FEAT_FOLDING | |
2087 n = wp->w_p_fdc; | |
2088 | |
2089 if (n > 0) | |
2090 { | |
2091 /* draw the fold column at the right */ | |
119 | 2092 if (n > W_WIDTH(wp)) |
2093 n = W_WIDTH(wp); | |
7 | 2094 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2095 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2096 ' ', ' ', hl_attr(HLF_FC)); | |
2097 } | |
2098 # endif | |
2099 # ifdef FEAT_SIGNS | |
2100 if (draw_signcolumn(wp)) | |
2101 { | |
2102 int nn = n + 2; | |
2103 | |
2104 /* draw the sign column left of the fold column */ | |
119 | 2105 if (nn > W_WIDTH(wp)) |
2106 nn = W_WIDTH(wp); | |
7 | 2107 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2108 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2109 ' ', ' ', hl_attr(HLF_SC)); | |
2110 n = nn; | |
2111 } | |
2112 # endif | |
2113 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2114 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2115 c2, c2, hl_attr(hl)); | |
2116 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2117 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2118 c1, c2, hl_attr(hl)); | |
2119 } | |
2120 else | |
2121 #endif | |
2122 { | |
2123 #ifdef FEAT_CMDWIN | |
2124 if (cmdwin_type != 0 && wp == curwin) | |
2125 { | |
2126 /* draw the cmdline character in the leftmost column */ | |
2127 n = 1; | |
2128 if (n > wp->w_width) | |
2129 n = wp->w_width; | |
2130 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2131 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2132 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2133 } | |
2134 #endif | |
2135 #ifdef FEAT_FOLDING | |
2136 if (wp->w_p_fdc > 0) | |
2137 { | |
2138 int nn = n + wp->w_p_fdc; | |
2139 | |
2140 /* draw the fold column at the left */ | |
2141 if (nn > W_WIDTH(wp)) | |
2142 nn = W_WIDTH(wp); | |
2143 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2144 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2145 ' ', ' ', hl_attr(HLF_FC)); | |
2146 n = nn; | |
2147 } | |
2148 #endif | |
2149 #ifdef FEAT_SIGNS | |
2150 if (draw_signcolumn(wp)) | |
2151 { | |
2152 int nn = n + 2; | |
2153 | |
2154 /* draw the sign column after the fold column */ | |
2155 if (nn > W_WIDTH(wp)) | |
2156 nn = W_WIDTH(wp); | |
2157 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2158 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2159 ' ', ' ', hl_attr(HLF_SC)); | |
2160 n = nn; | |
2161 } | |
2162 #endif | |
2163 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2164 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2165 c1, c2, hl_attr(hl)); | |
2166 } | |
2167 set_empty_rows(wp, row); | |
2168 } | |
2169 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2170 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2171 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
|
2172 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2173 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2174 * 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
|
2175 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2176 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2177 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2178 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2179 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2180 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2181 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2182 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2183 return (**color_cols >= 0); |
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 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2186 |
7 | 2187 #ifdef FEAT_FOLDING |
2188 /* | |
2189 * Display one folded line. | |
2190 */ | |
2191 static void | |
2192 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2193 win_T *wp; | |
2194 long fold_count; | |
2195 foldinfo_T *foldinfo; | |
2196 linenr_T lnum; | |
2197 int row; | |
2198 { | |
2199 char_u buf[51]; | |
2200 pos_T *top, *bot; | |
2201 linenr_T lnume = lnum + fold_count - 1; | |
2202 int len; | |
29 | 2203 char_u *text; |
7 | 2204 int fdc; |
2205 int col; | |
2206 int txtcol; | |
2207 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2208 int ri; |
7 | 2209 |
2210 /* Build the fold line: | |
2211 * 1. Add the cmdwin_type for the command-line window | |
2212 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2213 * 3. Add the 'number' or 'relativenumber' column |
7 | 2214 * 4. Compose the text |
2215 * 5. Add the text | |
2216 * 6. set highlighting for the Visual area an other text | |
2217 */ | |
2218 col = 0; | |
2219 | |
2220 /* | |
2221 * 1. Add the cmdwin_type for the command-line window | |
2222 * Ignores 'rightleft', this window is never right-left. | |
2223 */ | |
2224 #ifdef FEAT_CMDWIN | |
2225 if (cmdwin_type != 0 && wp == curwin) | |
2226 { | |
2227 ScreenLines[off] = cmdwin_type; | |
2228 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2229 #ifdef FEAT_MBYTE | |
2230 if (enc_utf8) | |
2231 ScreenLinesUC[off] = 0; | |
2232 #endif | |
2233 ++col; | |
2234 } | |
2235 #endif | |
2236 | |
2237 /* | |
2238 * 2. Add the 'foldcolumn' | |
2239 */ | |
2240 fdc = wp->w_p_fdc; | |
2241 if (fdc > W_WIDTH(wp) - col) | |
2242 fdc = W_WIDTH(wp) - col; | |
2243 if (fdc > 0) | |
2244 { | |
2245 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2246 #ifdef FEAT_RIGHTLEFT | |
2247 if (wp->w_p_rl) | |
2248 { | |
2249 int i; | |
2250 | |
2251 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2252 hl_attr(HLF_FC)); | |
2253 /* reverse the fold column */ | |
2254 for (i = 0; i < fdc; ++i) | |
2255 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2256 } | |
2257 else | |
2258 #endif | |
2259 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2260 col += fdc; | |
2261 } | |
2262 | |
2263 #ifdef FEAT_RIGHTLEFT | |
216 | 2264 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2265 for (ri = 0; ri < l; ++ri) \ | |
2266 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2267 else \ | |
2268 for (ri = 0; ri < l; ++ri) \ | |
2269 ScreenAttrs[off + (p) + ri] = v | |
7 | 2270 #else |
216 | 2271 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2272 ScreenAttrs[off + (p) + ri] = v | |
7 | 2273 #endif |
2274 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2275 /* 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
|
2276 * text */ |
216 | 2277 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2278 |
2279 #ifdef FEAT_SIGNS | |
2280 /* If signs are being displayed, add two spaces. */ | |
2281 if (draw_signcolumn(wp)) | |
2282 { | |
2283 len = W_WIDTH(wp) - col; | |
2284 if (len > 0) | |
2285 { | |
2286 if (len > 2) | |
2287 len = 2; | |
2288 # ifdef FEAT_RIGHTLEFT | |
2289 if (wp->w_p_rl) | |
2290 /* the line number isn't reversed */ | |
2291 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2292 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2293 else | |
2294 # endif | |
2295 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2296 col += len; | |
2297 } | |
2298 } | |
2299 #endif | |
2300 | |
2301 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2302 * 3. Add the 'number' or 'relativenumber' column |
7 | 2303 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2304 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2305 { |
2306 len = W_WIDTH(wp) - col; | |
2307 if (len > 0) | |
2308 { | |
13 | 2309 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2310 long num; |
13 | 2311 |
2312 if (len > w + 1) | |
2313 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2314 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2315 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2316 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2317 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2318 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2319 /* 'relativenumber', don't use negative numbers */ |
2675 | 2320 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
|
2321 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2322 sprintf((char *)buf, "%*ld ", w, num); |
7 | 2323 #ifdef FEAT_RIGHTLEFT |
2324 if (wp->w_p_rl) | |
2325 /* the line number isn't reversed */ | |
2326 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2327 hl_attr(HLF_FL)); | |
2328 else | |
2329 #endif | |
2330 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2331 col += len; | |
2332 } | |
2333 } | |
2334 | |
2335 /* | |
2336 * 4. Compose the folded-line string with 'foldtext', if set. | |
2337 */ | |
29 | 2338 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2339 |
2340 txtcol = col; /* remember where text starts */ | |
2341 | |
2342 /* | |
2343 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2344 * Right-left text is put in columns 0 - number-col, normal text is put | |
2345 * in columns number-col - window-width. | |
2346 */ | |
2347 #ifdef FEAT_MBYTE | |
2348 if (has_mbyte) | |
2349 { | |
2350 int cells; | |
714 | 2351 int u8c, u8cc[MAX_MCO]; |
2352 int i; | |
7 | 2353 int idx; |
2354 int c_len; | |
33 | 2355 char_u *p; |
7 | 2356 # ifdef FEAT_ARABIC |
2357 int prev_c = 0; /* previous Arabic character */ | |
2358 int prev_c1 = 0; /* first composing char for prev_c */ | |
2359 # endif | |
2360 | |
2361 # ifdef FEAT_RIGHTLEFT | |
2362 if (wp->w_p_rl) | |
2363 idx = off; | |
2364 else | |
2365 # endif | |
2366 idx = off + col; | |
2367 | |
2368 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2369 for (p = text; *p != NUL; ) | |
2370 { | |
2371 cells = (*mb_ptr2cells)(p); | |
474 | 2372 c_len = (*mb_ptr2len)(p); |
7 | 2373 if (col + cells > W_WIDTH(wp) |
2374 # ifdef FEAT_RIGHTLEFT | |
2375 - (wp->w_p_rl ? col : 0) | |
2376 # endif | |
2377 ) | |
2378 break; | |
2379 ScreenLines[idx] = *p; | |
2380 if (enc_utf8) | |
2381 { | |
714 | 2382 u8c = utfc_ptr2char(p, u8cc); |
2383 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2384 { |
2385 ScreenLinesUC[idx] = 0; | |
2386 #ifdef FEAT_ARABIC | |
2387 prev_c = u8c; | |
2388 #endif | |
2389 } | |
2390 else | |
2391 { | |
2392 #ifdef FEAT_ARABIC | |
2393 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2394 { | |
2395 /* Do Arabic shaping. */ | |
714 | 2396 int pc, pc1, nc; |
2397 int pcc[MAX_MCO]; | |
7 | 2398 int firstbyte = *p; |
2399 | |
2400 /* The idea of what is the previous and next | |
2401 * character depends on 'rightleft'. */ | |
2402 if (wp->w_p_rl) | |
2403 { | |
2404 pc = prev_c; | |
2405 pc1 = prev_c1; | |
2406 nc = utf_ptr2char(p + c_len); | |
714 | 2407 prev_c1 = u8cc[0]; |
7 | 2408 } |
2409 else | |
2410 { | |
714 | 2411 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2412 nc = prev_c; |
714 | 2413 pc1 = pcc[0]; |
7 | 2414 } |
2415 prev_c = u8c; | |
2416 | |
714 | 2417 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2418 pc, pc1, nc); |
2419 ScreenLines[idx] = firstbyte; | |
2420 } | |
2421 else | |
2422 prev_c = u8c; | |
2423 #endif | |
2424 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2425 #ifdef UNICODE16 |
7 | 2426 if (u8c >= 0x10000) |
2427 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2428 else | |
1401 | 2429 #endif |
7 | 2430 ScreenLinesUC[idx] = u8c; |
714 | 2431 for (i = 0; i < Screen_mco; ++i) |
2432 { | |
2433 ScreenLinesC[i][idx] = u8cc[i]; | |
2434 if (u8cc[i] == 0) | |
2435 break; | |
2436 } | |
7 | 2437 } |
2438 if (cells > 1) | |
2439 ScreenLines[idx + 1] = 0; | |
2440 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2441 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2442 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2443 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2444 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2445 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2446 ScreenLines[idx + 1] = p[1]; |
7 | 2447 col += cells; |
2448 idx += cells; | |
2449 p += c_len; | |
2450 } | |
2451 } | |
2452 else | |
2453 #endif | |
2454 { | |
2455 len = (int)STRLEN(text); | |
2456 if (len > W_WIDTH(wp) - col) | |
2457 len = W_WIDTH(wp) - col; | |
2458 if (len > 0) | |
2459 { | |
2460 #ifdef FEAT_RIGHTLEFT | |
2461 if (wp->w_p_rl) | |
2462 STRNCPY(current_ScreenLine, text, len); | |
2463 else | |
2464 #endif | |
2465 STRNCPY(current_ScreenLine + col, text, len); | |
2466 col += len; | |
2467 } | |
2468 } | |
2469 | |
2470 /* Fill the rest of the line with the fold filler */ | |
2471 #ifdef FEAT_RIGHTLEFT | |
2472 if (wp->w_p_rl) | |
2473 col -= txtcol; | |
2474 #endif | |
2475 while (col < W_WIDTH(wp) | |
2476 #ifdef FEAT_RIGHTLEFT | |
2477 - (wp->w_p_rl ? txtcol : 0) | |
2478 #endif | |
2479 ) | |
2480 { | |
2481 #ifdef FEAT_MBYTE | |
2482 if (enc_utf8) | |
2483 { | |
2484 if (fill_fold >= 0x80) | |
2485 { | |
2486 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2487 ScreenLinesC[0][off + col] = 0; |
7 | 2488 } |
2489 else | |
2490 ScreenLinesUC[off + col] = 0; | |
2491 } | |
2492 #endif | |
2493 ScreenLines[off + col++] = fill_fold; | |
2494 } | |
2495 | |
2496 if (text != buf) | |
2497 vim_free(text); | |
2498 | |
2499 /* | |
2500 * 6. set highlighting for the Visual area an other text. | |
2501 * If all folded lines are in the Visual area, highlight the line. | |
2502 */ | |
2503 #ifdef FEAT_VISUAL | |
2504 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2505 { | |
2506 if (ltoreq(curwin->w_cursor, VIsual)) | |
2507 { | |
2508 /* Visual is after curwin->w_cursor */ | |
2509 top = &curwin->w_cursor; | |
2510 bot = &VIsual; | |
2511 } | |
2512 else | |
2513 { | |
2514 /* Visual is before curwin->w_cursor */ | |
2515 top = &VIsual; | |
2516 bot = &curwin->w_cursor; | |
2517 } | |
2518 if (lnum >= top->lnum | |
2519 && lnume <= bot->lnum | |
2520 && (VIsual_mode != 'v' | |
2521 || ((lnum > top->lnum | |
2522 || (lnum == top->lnum | |
2523 && top->col == 0)) | |
2524 && (lnume < bot->lnum | |
2525 || (lnume == bot->lnum | |
2526 && (bot->col - (*p_sel == 'e')) | |
1883 | 2527 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2528 { |
2529 if (VIsual_mode == Ctrl_V) | |
2530 { | |
2531 /* Visual block mode: highlight the chars part of the block */ | |
2532 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2533 { | |
3040 | 2534 if (wp->w_old_cursor_lcol != MAXCOL |
2535 && wp->w_old_cursor_lcol + txtcol | |
2536 < (colnr_T)W_WIDTH(wp)) | |
7 | 2537 len = wp->w_old_cursor_lcol; |
2538 else | |
2539 len = W_WIDTH(wp) - txtcol; | |
2540 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2541 len - (int)wp->w_old_cursor_fcol); |
7 | 2542 } |
2543 } | |
2544 else | |
216 | 2545 { |
7 | 2546 /* Set all attributes of the text */ |
216 | 2547 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2548 } | |
7 | 2549 } |
2550 } | |
2551 #endif | |
2552 | |
743 | 2553 #ifdef FEAT_SYN_HL |
2554 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2555 if (wp->w_p_cuc) |
2556 { | |
2557 txtcol += wp->w_virtcol; | |
2558 if (wp->w_p_wrap) | |
2559 txtcol -= wp->w_skipcol; | |
2560 else | |
2561 txtcol -= wp->w_leftcol; | |
2562 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2563 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2564 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2565 } | |
743 | 2566 #endif |
7 | 2567 |
2568 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2569 (int)W_WIDTH(wp), FALSE); | |
2570 | |
2571 /* | |
2572 * Update w_cline_height and w_cline_folded if the cursor line was | |
2573 * updated (saves a call to plines() later). | |
2574 */ | |
2575 if (wp == curwin | |
2576 && lnum <= curwin->w_cursor.lnum | |
2577 && lnume >= curwin->w_cursor.lnum) | |
2578 { | |
2579 curwin->w_cline_row = row; | |
2580 curwin->w_cline_height = 1; | |
2581 curwin->w_cline_folded = TRUE; | |
2582 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2583 } | |
2584 } | |
2585 | |
2586 /* | |
2587 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2588 */ | |
2589 static void | |
2590 copy_text_attr(off, buf, len, attr) | |
2591 int off; | |
2592 char_u *buf; | |
2593 int len; | |
2594 int attr; | |
2595 { | |
216 | 2596 int i; |
2597 | |
7 | 2598 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2599 # ifdef FEAT_MBYTE | |
2600 if (enc_utf8) | |
2601 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2602 # endif | |
216 | 2603 for (i = 0; i < len; ++i) |
2604 ScreenAttrs[off + i] = attr; | |
7 | 2605 } |
2606 | |
2607 /* | |
2608 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2609 * Only to be called when 'foldcolumn' > 0. |
7 | 2610 */ |
2611 static void | |
2612 fill_foldcolumn(p, wp, closed, lnum) | |
2613 char_u *p; | |
2614 win_T *wp; | |
2615 int closed; /* TRUE of FALSE */ | |
2616 linenr_T lnum; /* current line number */ | |
2617 { | |
2618 int i = 0; | |
2619 int level; | |
2620 int first_level; | |
519 | 2621 int empty; |
7 | 2622 |
2623 /* Init to all spaces. */ | |
2624 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2625 | |
2626 level = win_foldinfo.fi_level; | |
2627 if (level > 0) | |
2628 { | |
519 | 2629 /* If there is only one column put more info in it. */ |
2630 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2631 | |
7 | 2632 /* If the column is too narrow, we start at the lowest level that |
2633 * fits and use numbers to indicated the depth. */ | |
519 | 2634 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2635 if (first_level < 1) |
2636 first_level = 1; | |
2637 | |
519 | 2638 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2639 { |
2640 if (win_foldinfo.fi_lnum == lnum | |
2641 && first_level + i >= win_foldinfo.fi_low_level) | |
2642 p[i] = '-'; | |
2643 else if (first_level == 1) | |
2644 p[i] = '|'; | |
2645 else if (first_level + i <= 9) | |
2646 p[i] = '0' + first_level + i; | |
2647 else | |
2648 p[i] = '>'; | |
2649 if (first_level + i == level) | |
2650 break; | |
2651 } | |
2652 } | |
2653 if (closed) | |
548 | 2654 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2655 } |
2656 #endif /* FEAT_FOLDING */ | |
2657 | |
2658 /* | |
2659 * Display line "lnum" of window 'wp' on the screen. | |
2660 * Start at row "startrow", stop when "endrow" is reached. | |
2661 * wp->w_virtcol needs to be valid. | |
2662 * | |
2663 * Return the number of last row the line occupies. | |
2664 */ | |
2665 static int | |
625 | 2666 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2667 win_T *wp; |
2668 linenr_T lnum; | |
2669 int startrow; | |
2670 int endrow; | |
1883 | 2671 int nochange UNUSED; /* not updating for changed text */ |
7 | 2672 { |
2673 int col; /* visual column on screen */ | |
2674 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2675 int c = 0; /* init for GCC */ | |
2676 long vcol = 0; /* virtual column (for tabs) */ | |
2677 long vcol_prev = -1; /* "vcol" of previous character */ | |
2678 char_u *line; /* current line */ | |
2679 char_u *ptr; /* current position in "line" */ | |
2680 int row; /* row in the window, excl w_winrow */ | |
2681 int screen_row; /* row on the screen, incl w_winrow */ | |
2682 | |
2683 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2684 int n_extra = 0; /* number of extra chars */ | |
1340 | 2685 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2686 int c_extra = NUL; /* extra chars, all the same */ |
2687 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2688 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2689 displaying lcs_eol at end-of-line */ | |
2690 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2691 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2692 | |
2693 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2694 int saved_n_extra = 0; | |
2695 char_u *saved_p_extra = NULL; | |
2696 int saved_c_extra = 0; | |
2697 int saved_char_attr = 0; | |
2698 | |
2699 int n_attr = 0; /* chars with special attr */ | |
2700 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2701 int n_attr3 = 0; /* chars with overruling special attr */ | |
2702 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2703 | |
2704 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2705 | |
2706 int fromcol, tocol; /* start/end of inverting */ | |
2707 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2708 int noinvcur = FALSE; /* don't invert the cursor */ | |
2709 #ifdef FEAT_VISUAL | |
2710 pos_T *top, *bot; | |
1813 | 2711 int lnum_in_visual_area = FALSE; |
7 | 2712 #endif |
2713 pos_T pos; | |
2714 long v; | |
2715 | |
2716 int char_attr = 0; /* attributes for next character */ | |
674 | 2717 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2718 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2719 in this line */ | |
2720 int attr = 0; /* attributes for area highlighting */ | |
2721 int area_attr = 0; /* attributes desired by highlighting */ | |
2722 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2723 #ifdef FEAT_SYN_HL | |
743 | 2724 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2725 int syntax_attr = 0; /* attributes desired by syntax */ |
2726 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2727 int save_did_emsg; | |
1437 | 2728 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
|
2729 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2730 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2731 #endif |
2732 #ifdef FEAT_SPELL | |
221 | 2733 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2734 # define SPWORDLEN 150 |
2735 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2736 int nextlinecol = 0; /* column where nextline[] starts */ |
2737 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2738 starts */ |
221 | 2739 int spell_attr = 0; /* attributes desired by spelling */ |
2740 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2741 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2742 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2743 * there are no spell errors */ |
386 | 2744 static int cap_col = -1; /* column to check for Cap word */ |
2745 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2746 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2747 #endif |
2748 int extra_check; /* has syntax or linebreak */ | |
2749 #ifdef FEAT_MBYTE | |
2750 int multi_attr = 0; /* attributes desired by multibyte */ | |
2751 int mb_l = 1; /* multi-byte byte length */ | |
2752 int mb_c = 0; /* decoded multi-byte character */ | |
2753 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2754 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2755 #endif |
2756 #ifdef FEAT_DIFF | |
2757 int filler_lines; /* nr of filler lines to be drawn */ | |
2758 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2759 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2760 int change_start = MAXCOL; /* first col of changed area */ |
2761 int change_end = -1; /* last col of changed area */ | |
2762 #endif | |
2763 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2764 #ifdef FEAT_LINEBREAK | |
2765 int need_showbreak = FALSE; | |
2766 #endif | |
910 | 2767 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2768 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2769 # define LINE_ATTR |
1536 | 2770 int line_attr = 0; /* attribute for the whole line */ |
7 | 2771 #endif |
2772 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2773 matchitem_T *cur; /* points to the match list */ |
2774 match_T *shl; /* points to search_hl or a match */ | |
2775 int shl_flag; /* flag to indicate whether search_hl | |
2776 has been processed or not */ | |
2777 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2778 equals startcol of search_hl or one | |
2779 of the matches */ | |
7 | 2780 #endif |
2781 #ifdef FEAT_ARABIC | |
2782 int prev_c = 0; /* previous Arabic character */ | |
2783 int prev_c1 = 0; /* first composing char for prev_c */ | |
2784 #endif | |
910 | 2785 #if defined(LINE_ATTR) |
867 | 2786 int did_line_attr = 0; |
2787 #endif | |
7 | 2788 |
2789 /* draw_state: items that are drawn in sequence: */ | |
2790 #define WL_START 0 /* nothing done yet */ | |
2791 #ifdef FEAT_CMDWIN | |
2792 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2793 #else | |
2794 # define WL_CMDLINE WL_START | |
2795 #endif | |
2796 #ifdef FEAT_FOLDING | |
2797 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2798 #else | |
2799 # define WL_FOLD WL_CMDLINE | |
2800 #endif | |
2801 #ifdef FEAT_SIGNS | |
2802 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2803 #else | |
2804 # define WL_SIGN WL_FOLD /* column for signs */ | |
2805 #endif | |
2806 #define WL_NR WL_SIGN + 1 /* line number */ | |
2807 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2808 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2809 #else | |
2810 # define WL_SBR WL_NR | |
2811 #endif | |
2812 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2813 int draw_state = WL_START; /* what to draw next */ | |
574 | 2814 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2815 int feedback_col = 0; |
2816 int feedback_old_attr = -1; | |
2817 #endif | |
2818 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2819 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2820 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
|
2821 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
|
2822 int prev_syntax_id = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2823 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2824 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2825 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
|
2826 wrapping */ |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2400
diff
changeset
|
2827 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
|
2828 int did_wcol = FALSE; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2829 # define VCOL_HLC (vcol - vcol_off) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2830 #else |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2831 # define VCOL_HLC (vcol) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2832 #endif |
7 | 2833 |
2834 if (startrow > endrow) /* past the end already! */ | |
2835 return startrow; | |
2836 | |
2837 row = startrow; | |
2838 screen_row = row + W_WINROW(wp); | |
2839 | |
2840 /* | |
2841 * To speed up the loop below, set extra_check when there is linebreak, | |
2842 * trailing white space and/or syntax processing to be done. | |
2843 */ | |
2844 #ifdef FEAT_LINEBREAK | |
2845 extra_check = wp->w_p_lbr; | |
2846 #else | |
2847 extra_check = 0; | |
2848 #endif | |
2849 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2850 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2851 { |
2852 /* Prepare for syntax highlighting in this line. When there is an | |
2853 * error, stop syntax highlighting. */ | |
2854 save_did_emsg = did_emsg; | |
2855 did_emsg = FALSE; | |
2856 syntax_start(wp, lnum); | |
2857 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2858 wp->w_s->b_syn_error = TRUE; |
7 | 2859 else |
2860 { | |
2861 did_emsg = save_did_emsg; | |
2862 has_syntax = TRUE; | |
2863 extra_check = TRUE; | |
2864 } | |
2865 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2866 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2867 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2868 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2869 if (color_cols != NULL) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
2870 draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
743 | 2871 #endif |
2872 | |
2873 #ifdef FEAT_SPELL | |
258 | 2874 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2875 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2876 && 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
|
2877 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2878 { |
2879 /* Prepare for spell checking. */ | |
2880 has_spell = TRUE; | |
2881 extra_check = TRUE; | |
348 | 2882 |
2883 /* Get the start of the next line, so that words that wrap to the next | |
2884 * line are found too: "et<line-break>al.". | |
2885 * Trick: skip a few chars for C/shell/Vim comments */ | |
2886 nextline[SPWORDLEN] = NUL; | |
2887 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2888 { | |
2889 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2890 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2891 } | |
2892 | |
2893 /* When a word wrapped from the previous line the start of the current | |
2894 * line is valid. */ | |
2895 if (lnum == checked_lnum) | |
2896 cur_checked_col = checked_col; | |
2897 checked_lnum = 0; | |
386 | 2898 |
2899 /* When there was a sentence end in the previous line may require a | |
2900 * word starting with capital in this line. In line 1 always check | |
2901 * the first word. */ | |
2902 if (lnum != capcol_lnum) | |
2903 cap_col = -1; | |
2904 if (lnum == 1) | |
2905 cap_col = 0; | |
2906 capcol_lnum = 0; | |
221 | 2907 } |
7 | 2908 #endif |
2909 | |
2910 /* | |
2911 * handle visual active in this window | |
2912 */ | |
2913 fromcol = -10; | |
2914 tocol = MAXCOL; | |
2915 #ifdef FEAT_VISUAL | |
2916 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2917 { | |
2918 /* Visual is after curwin->w_cursor */ | |
2919 if (ltoreq(curwin->w_cursor, VIsual)) | |
2920 { | |
2921 top = &curwin->w_cursor; | |
2922 bot = &VIsual; | |
2923 } | |
2924 else /* Visual is before curwin->w_cursor */ | |
2925 { | |
2926 top = &VIsual; | |
2927 bot = &curwin->w_cursor; | |
2928 } | |
1813 | 2929 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2930 if (VIsual_mode == Ctrl_V) /* block mode */ |
2931 { | |
1813 | 2932 if (lnum_in_visual_area) |
7 | 2933 { |
2934 fromcol = wp->w_old_cursor_fcol; | |
2935 tocol = wp->w_old_cursor_lcol; | |
2936 } | |
2937 } | |
2938 else /* non-block mode */ | |
2939 { | |
2940 if (lnum > top->lnum && lnum <= bot->lnum) | |
2941 fromcol = 0; | |
2942 else if (lnum == top->lnum) | |
2943 { | |
2944 if (VIsual_mode == 'V') /* linewise */ | |
2945 fromcol = 0; | |
2946 else | |
2947 { | |
2948 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2949 if (gchar_pos(top) == NUL) | |
2950 tocol = fromcol + 1; | |
2951 } | |
2952 } | |
2953 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2954 { | |
2955 if (*p_sel == 'e' && bot->col == 0 | |
2956 #ifdef FEAT_VIRTUALEDIT | |
2957 && bot->coladd == 0 | |
2958 #endif | |
2959 ) | |
2960 { | |
2961 fromcol = -10; | |
2962 tocol = MAXCOL; | |
2963 } | |
36 | 2964 else if (bot->col == MAXCOL) |
2965 tocol = MAXCOL; | |
7 | 2966 else |
2967 { | |
2968 pos = *bot; | |
2969 if (*p_sel == 'e') | |
2970 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2971 else | |
2972 { | |
2973 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2974 ++tocol; | |
2975 } | |
2976 } | |
2977 } | |
2978 } | |
2979 | |
2980 #ifndef MSDOS | |
2981 /* Check if the character under the cursor should not be inverted */ | |
2982 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2983 # ifdef FEAT_GUI | |
2984 && !gui.in_use | |
2985 # endif | |
2986 ) | |
2987 noinvcur = TRUE; | |
2988 #endif | |
2989 | |
2990 /* if inverting in this line set area_highlighting */ | |
2991 if (fromcol >= 0) | |
2992 { | |
2993 area_highlighting = TRUE; | |
2994 attr = hl_attr(HLF_V); | |
2995 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2996 if (clip_star.available && !clip_star.owned && clip_isautosel()) | |
2997 attr = hl_attr(HLF_VNC); | |
2998 #endif | |
2999 } | |
3000 } | |
3001 | |
3002 /* | |
674 | 3003 * handle 'incsearch' and ":s///c" highlighting |
7 | 3004 */ |
3005 else | |
3006 #endif /* FEAT_VISUAL */ | |
3007 if (highlight_match | |
3008 && wp == curwin | |
3009 && lnum >= curwin->w_cursor.lnum | |
3010 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
3011 { | |
3012 if (lnum == curwin->w_cursor.lnum) | |
3013 getvcol(curwin, &(curwin->w_cursor), | |
3014 (colnr_T *)&fromcol, NULL, NULL); | |
3015 else | |
3016 fromcol = 0; | |
3017 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
3018 { | |
3019 pos.lnum = lnum; | |
3020 pos.col = search_match_endcol; | |
3021 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
3022 } | |
3023 else | |
3024 tocol = MAXCOL; | |
1850 | 3025 /* do at least one character; happens when past end of line */ |
3026 if (fromcol == tocol) | |
3027 tocol = fromcol + 1; | |
7 | 3028 area_highlighting = TRUE; |
3029 attr = hl_attr(HLF_I); | |
3030 } | |
3031 | |
3032 #ifdef FEAT_DIFF | |
3033 filler_lines = diff_check(wp, lnum); | |
3034 if (filler_lines < 0) | |
3035 { | |
3036 if (filler_lines == -1) | |
3037 { | |
3038 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
3039 diff_hlf = HLF_ADD; /* added line */ | |
3040 else if (change_start == 0) | |
3041 diff_hlf = HLF_TXD; /* changed text */ | |
3042 else | |
3043 diff_hlf = HLF_CHD; /* changed line */ | |
3044 } | |
3045 else | |
3046 diff_hlf = HLF_ADD; /* added line */ | |
3047 filler_lines = 0; | |
3048 area_highlighting = TRUE; | |
3049 } | |
3050 if (lnum == wp->w_topline) | |
3051 filler_lines = wp->w_topfill; | |
3052 filler_todo = filler_lines; | |
3053 #endif | |
3054 | |
3055 #ifdef LINE_ATTR | |
3056 # ifdef FEAT_SIGNS | |
3057 /* If this line has a sign with line highlighting set line_attr. */ | |
3058 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3059 if (v != 0) | |
3060 line_attr = sign_get_attr((int)v, TRUE); | |
3061 # endif | |
3062 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3063 /* Highlight the current line in the quickfix window. */ | |
644 | 3064 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3065 line_attr = hl_attr(HLF_L); |
3066 # endif | |
3067 if (line_attr != 0) | |
3068 area_highlighting = TRUE; | |
3069 #endif | |
3070 | |
3071 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3072 ptr = line; | |
3073 | |
743 | 3074 #ifdef FEAT_SPELL |
348 | 3075 if (has_spell) |
3076 { | |
386 | 3077 /* For checking first word with a capital skip white space. */ |
3078 if (cap_col == 0) | |
835 | 3079 cap_col = (int)(skipwhite(line) - line); |
386 | 3080 |
348 | 3081 /* To be able to spell-check over line boundaries copy the end of the |
3082 * current line into nextline[]. Above the start of the next line was | |
3083 * copied to nextline[SPWORDLEN]. */ | |
3084 if (nextline[SPWORDLEN] == NUL) | |
3085 { | |
3086 /* No next line or it is empty. */ | |
3087 nextlinecol = MAXCOL; | |
3088 nextline_idx = 0; | |
3089 } | |
3090 else | |
3091 { | |
835 | 3092 v = (long)STRLEN(line); |
348 | 3093 if (v < SPWORDLEN) |
3094 { | |
3095 /* Short line, use it completely and append the start of the | |
3096 * next line. */ | |
3097 nextlinecol = 0; | |
3098 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3099 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3100 nextline_idx = v + 1; |
3101 } | |
3102 else | |
3103 { | |
3104 /* Long line, use only the last SPWORDLEN bytes. */ | |
3105 nextlinecol = v - SPWORDLEN; | |
3106 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3107 nextline_idx = SPWORDLEN + 1; | |
3108 } | |
3109 } | |
3110 } | |
3111 #endif | |
3112 | |
7 | 3113 /* find start of trailing whitespace */ |
3114 if (wp->w_p_list && lcs_trail) | |
3115 { | |
3116 trailcol = (colnr_T)STRLEN(ptr); | |
3117 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3118 --trailcol; | |
3119 trailcol += (colnr_T) (ptr - line); | |
3120 extra_check = TRUE; | |
3121 } | |
3122 | |
3123 /* | |
3124 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3125 * first character to be displayed. | |
3126 */ | |
3127 if (wp->w_p_wrap) | |
3128 v = wp->w_skipcol; | |
3129 else | |
3130 v = wp->w_leftcol; | |
3131 if (v > 0) | |
3132 { | |
3133 #ifdef FEAT_MBYTE | |
3134 char_u *prev_ptr = ptr; | |
3135 #endif | |
3136 while (vcol < v && *ptr != NUL) | |
3137 { | |
3138 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3139 vcol += c; | |
3140 #ifdef FEAT_MBYTE | |
3141 prev_ptr = ptr; | |
39 | 3142 #endif |
3143 mb_ptr_adv(ptr); | |
7 | 3144 } |
3145 | |
1984 | 3146 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3147 /* When: | |
3148 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3149 * - 'colorcolumn' is set, or |
1984 | 3150 * - 'virtualedit' is set, or |
3151 * - the visual mode is active, | |
3152 * the end of the line may be before the start of the displayed part. | |
3153 */ | |
3154 if (vcol < v && ( | |
3155 # ifdef FEAT_SYN_HL | |
3156 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3157 || draw_color_col |
1984 | 3158 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3159 || | |
3160 # endif | |
3161 # endif | |
3162 # ifdef FEAT_VIRTUALEDIT | |
3163 virtual_active() | |
3164 # ifdef FEAT_VISUAL | |
3165 || | |
3166 # endif | |
3167 # endif | |
3168 # ifdef FEAT_VISUAL | |
3169 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3170 # endif | |
3171 )) | |
3172 { | |
7 | 3173 vcol = v; |
1984 | 3174 } |
7 | 3175 #endif |
3176 | |
3177 /* Handle a character that's not completely on the screen: Put ptr at | |
3178 * that character but skip the first few screen characters. */ | |
3179 if (vcol > v) | |
3180 { | |
3181 vcol -= c; | |
3182 #ifdef FEAT_MBYTE | |
3183 ptr = prev_ptr; | |
3184 #else | |
3185 --ptr; | |
3186 #endif | |
3187 n_skip = v - vcol; | |
3188 } | |
3189 | |
3190 /* | |
3191 * Adjust for when the inverted text is before the screen, | |
3192 * and when the start of the inverted text is before the screen. | |
3193 */ | |
3194 if (tocol <= vcol) | |
3195 fromcol = 0; | |
3196 else if (fromcol >= 0 && fromcol < vcol) | |
3197 fromcol = vcol; | |
3198 | |
3199 #ifdef FEAT_LINEBREAK | |
3200 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3201 if (wp->w_p_wrap) | |
3202 need_showbreak = TRUE; | |
3203 #endif | |
743 | 3204 #ifdef FEAT_SPELL |
499 | 3205 /* When spell checking a word we need to figure out the start of the |
3206 * word and if it's badly spelled or not. */ | |
3207 if (has_spell) | |
3208 { | |
3209 int len; | |
1536 | 3210 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3211 hlf_T spell_hlf = HLF_COUNT; |
499 | 3212 |
3213 pos = wp->w_cursor; | |
3214 wp->w_cursor.lnum = lnum; | |
1536 | 3215 wp->w_cursor.col = linecol; |
534 | 3216 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3217 |
3218 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3219 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3220 ptr = line + linecol; | |
3221 | |
530 | 3222 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3223 { |
3224 /* no bad word found at line start, don't check until end of a | |
3225 * word */ | |
534 | 3226 spell_hlf = HLF_COUNT; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3227 word_end = (int)(spell_to_word_end(ptr, wp) |
1536 | 3228 - line + 1); |
499 | 3229 } |
3230 else | |
534 | 3231 { |
499 | 3232 /* bad word found, use attributes until end of word */ |
3233 word_end = wp->w_cursor.col + len + 1; | |
3234 | |
534 | 3235 /* Turn index into actual attributes. */ |
3236 if (spell_hlf != HLF_COUNT) | |
3237 spell_attr = highlight_attr[spell_hlf]; | |
3238 } | |
499 | 3239 wp->w_cursor = pos; |
501 | 3240 |
743 | 3241 # ifdef FEAT_SYN_HL |
501 | 3242 /* Need to restart syntax highlighting for this line. */ |
3243 if (has_syntax) | |
3244 syntax_start(wp, lnum); | |
743 | 3245 # endif |
499 | 3246 } |
3247 #endif | |
7 | 3248 } |
3249 | |
3250 /* | |
3251 * Correct highlighting for cursor that can't be disabled. | |
3252 * Avoids having to check this for each character. | |
3253 */ | |
3254 if (fromcol >= 0) | |
3255 { | |
3256 if (noinvcur) | |
3257 { | |
3258 if ((colnr_T)fromcol == wp->w_virtcol) | |
3259 { | |
3260 /* highlighting starts at cursor, let it start just after the | |
3261 * cursor */ | |
3262 fromcol_prev = fromcol; | |
3263 fromcol = -1; | |
3264 } | |
3265 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3266 /* restart highlighting after the cursor */ | |
3267 fromcol_prev = wp->w_virtcol; | |
3268 } | |
3269 if (fromcol >= tocol) | |
3270 fromcol = -1; | |
3271 } | |
3272 | |
3273 #ifdef FEAT_SEARCH_EXTRA | |
3274 /* | |
1326 | 3275 * Handle highlighting the last used search pattern and matches. |
3276 * Do this for both search_hl and the match list. | |
7 | 3277 */ |
1326 | 3278 cur = wp->w_match_head; |
3279 shl_flag = FALSE; | |
3280 while (cur != NULL || shl_flag == FALSE) | |
3281 { | |
3282 if (shl_flag == FALSE) | |
3283 { | |
3284 shl = &search_hl; | |
3285 shl_flag = TRUE; | |
3286 } | |
3287 else | |
3288 shl = &cur->hl; | |
36 | 3289 shl->startcol = MAXCOL; |
3290 shl->endcol = MAXCOL; | |
7 | 3291 shl->attr_cur = 0; |
3292 if (shl->rm.regprog != NULL) | |
3293 { | |
3294 v = (long)(ptr - line); | |
3295 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3296 | |
3297 /* Need to get the line again, a multi-line regexp may have made it | |
3298 * invalid. */ | |
3299 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3300 ptr = line + v; | |
3301 | |
3302 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3303 { | |
3304 if (shl->lnum == lnum) | |
36 | 3305 shl->startcol = shl->rm.startpos[0].col; |
7 | 3306 else |
36 | 3307 shl->startcol = 0; |
7 | 3308 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3309 - shl->rm.startpos[0].lnum) | |
36 | 3310 shl->endcol = shl->rm.endpos[0].col; |
7 | 3311 else |
36 | 3312 shl->endcol = MAXCOL; |
7 | 3313 /* Highlight one character for an empty match. */ |
36 | 3314 if (shl->startcol == shl->endcol) |
7 | 3315 { |
3316 #ifdef FEAT_MBYTE | |
36 | 3317 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3318 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3319 else |
3320 #endif | |
36 | 3321 ++shl->endcol; |
7 | 3322 } |
36 | 3323 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3324 { |
3325 shl->attr_cur = shl->attr; | |
3326 search_attr = shl->attr; | |
3327 } | |
3328 area_highlighting = TRUE; | |
3329 } | |
3330 } | |
1326 | 3331 if (shl != &search_hl && cur != NULL) |
3332 cur = cur->next; | |
7 | 3333 } |
3334 #endif | |
3335 | |
743 | 3336 #ifdef FEAT_SYN_HL |
818 | 3337 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3338 * active, because it's not clear what is selected then. */ | |
3339 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3340 { |
3341 line_attr = hl_attr(HLF_CUL); | |
3342 area_highlighting = TRUE; | |
3343 } | |
3344 #endif | |
3345 | |
504 | 3346 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3347 col = 0; |
3348 #ifdef FEAT_RIGHTLEFT | |
3349 if (wp->w_p_rl) | |
3350 { | |
3351 /* Rightleft window: process the text in the normal direction, but put | |
3352 * it in current_ScreenLine[] from right to left. Start at the | |
3353 * rightmost column of the window. */ | |
3354 col = W_WIDTH(wp) - 1; | |
3355 off += col; | |
3356 } | |
3357 #endif | |
3358 | |
3359 /* | |
3360 * Repeat for the whole displayed line. | |
3361 */ | |
3362 for (;;) | |
3363 { | |
3364 /* Skip this quickly when working on the text. */ | |
3365 if (draw_state != WL_LINE) | |
3366 { | |
3367 #ifdef FEAT_CMDWIN | |
3368 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3369 { | |
3370 draw_state = WL_CMDLINE; | |
3371 if (cmdwin_type != 0 && wp == curwin) | |
3372 { | |
3373 /* Draw the cmdline character. */ | |
3374 n_extra = 1; | |
1340 | 3375 c_extra = cmdwin_type; |
7 | 3376 char_attr = hl_attr(HLF_AT); |
3377 } | |
3378 } | |
3379 #endif | |
3380 | |
3381 #ifdef FEAT_FOLDING | |
3382 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3383 { | |
3384 draw_state = WL_FOLD; | |
3385 if (wp->w_p_fdc > 0) | |
3386 { | |
3387 /* Draw the 'foldcolumn'. */ | |
3388 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3389 n_extra = wp->w_p_fdc; | |
3390 p_extra = extra; | |
1340 | 3391 p_extra[n_extra] = NUL; |
7 | 3392 c_extra = NUL; |
3393 char_attr = hl_attr(HLF_FC); | |
3394 } | |
3395 } | |
3396 #endif | |
3397 | |
3398 #ifdef FEAT_SIGNS | |
3399 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3400 { | |
3401 draw_state = WL_SIGN; | |
3402 /* Show the sign column when there are any signs in this | |
3403 * buffer or when using Netbeans. */ | |
3404 if (draw_signcolumn(wp) | |
3405 # ifdef FEAT_DIFF | |
3406 && filler_todo <= 0 | |
3407 # endif | |
3408 ) | |
3409 { | |
2661 | 3410 int text_sign; |
7 | 3411 # ifdef FEAT_SIGN_ICONS |
2661 | 3412 int icon_sign; |
7 | 3413 # endif |
3414 | |
3415 /* Draw two cells with the sign value or blank. */ | |
3416 c_extra = ' '; | |
3417 char_attr = hl_attr(HLF_SC); | |
3418 n_extra = 2; | |
3419 | |
3420 if (row == startrow) | |
3421 { | |
3422 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3423 SIGN_TEXT); | |
3424 # ifdef FEAT_SIGN_ICONS | |
3425 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3426 SIGN_ICON); | |
3427 if (gui.in_use && icon_sign != 0) | |
3428 { | |
3429 /* Use the image in this position. */ | |
3430 c_extra = SIGN_BYTE; | |
3431 # ifdef FEAT_NETBEANS_INTG | |
3432 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3433 c_extra = MULTISIGN_BYTE; | |
3434 # endif | |
3435 char_attr = icon_sign; | |
3436 } | |
3437 else | |
3438 # endif | |
3439 if (text_sign != 0) | |
3440 { | |
3441 p_extra = sign_get_text(text_sign); | |
3442 if (p_extra != NULL) | |
3443 { | |
3444 c_extra = NUL; | |
835 | 3445 n_extra = (int)STRLEN(p_extra); |
7 | 3446 } |
3447 char_attr = sign_get_attr(text_sign, FALSE); | |
3448 } | |
3449 } | |
3450 } | |
3451 } | |
3452 #endif | |
3453 | |
3454 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3455 { | |
3456 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3457 /* 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
|
3458 * 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
|
3459 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3460 && (row == startrow |
3461 #ifdef FEAT_DIFF | |
3462 + filler_lines | |
3463 #endif | |
3464 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3465 { | |
3466 /* Draw the line number (empty space after wrapping). */ | |
3467 if (row == startrow | |
3468 #ifdef FEAT_DIFF | |
3469 + filler_lines | |
3470 #endif | |
3471 ) | |
3472 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3473 long num; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3474 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3475 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3476 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3477 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3478 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3479 /* 'relativenumber', don't use negative numbers */ |
2675 | 3480 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
|
3481 |
13 | 3482 sprintf((char *)extra, "%*ld ", |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3483 number_width(wp), num); |
7 | 3484 if (wp->w_skipcol > 0) |
3485 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3486 *p_extra = '-'; | |
3487 #ifdef FEAT_RIGHTLEFT | |
3488 if (wp->w_p_rl) /* reverse line numbers */ | |
3489 rl_mirror(extra); | |
3490 #endif | |
3491 p_extra = extra; | |
3492 c_extra = NUL; | |
3493 } | |
3494 else | |
3495 c_extra = ' '; | |
13 | 3496 n_extra = number_width(wp) + 1; |
7 | 3497 char_attr = hl_attr(HLF_N); |
743 | 3498 #ifdef FEAT_SYN_HL |
3499 /* When 'cursorline' is set highlight the line number of | |
3500 * the current line differently. */ | |
3501 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) | |
3502 char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); | |
3503 #endif | |
7 | 3504 } |
3505 } | |
3506 | |
3507 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3508 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3509 { | |
3510 draw_state = WL_SBR; | |
3511 # ifdef FEAT_DIFF | |
3512 if (filler_todo > 0) | |
3513 { | |
3514 /* Draw "deleted" diff line(s). */ | |
3515 if (char2cells(fill_diff) > 1) | |
3516 c_extra = '-'; | |
3517 else | |
3518 c_extra = fill_diff; | |
3519 # ifdef FEAT_RIGHTLEFT | |
3520 if (wp->w_p_rl) | |
3521 n_extra = col + 1; | |
3522 else | |
3523 # endif | |
3524 n_extra = W_WIDTH(wp) - col; | |
3525 char_attr = hl_attr(HLF_DED); | |
3526 } | |
3527 # endif | |
3528 # ifdef FEAT_LINEBREAK | |
3529 if (*p_sbr != NUL && need_showbreak) | |
3530 { | |
3531 /* Draw 'showbreak' at the start of each broken line. */ | |
3532 p_extra = p_sbr; | |
3533 c_extra = NUL; | |
3534 n_extra = (int)STRLEN(p_sbr); | |
3535 char_attr = hl_attr(HLF_AT); | |
3536 need_showbreak = FALSE; | |
3537 /* Correct end of highlighted area for 'showbreak', | |
3538 * required when 'linebreak' is also set. */ | |
3539 if (tocol == vcol) | |
3540 tocol += n_extra; | |
3541 } | |
3542 # endif | |
3543 } | |
3544 #endif | |
3545 | |
3546 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3547 { | |
3548 draw_state = WL_LINE; | |
3549 if (saved_n_extra) | |
3550 { | |
3551 /* Continue item from end of wrapped line. */ | |
3552 n_extra = saved_n_extra; | |
3553 c_extra = saved_c_extra; | |
3554 p_extra = saved_p_extra; | |
3555 char_attr = saved_char_attr; | |
3556 } | |
3557 else | |
3558 char_attr = 0; | |
3559 } | |
3560 } | |
3561 | |
3562 /* When still displaying '$' of change command, stop at cursor */ | |
819 | 3563 if (dollar_vcol != 0 && wp == curwin |
3564 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol | |
7 | 3565 #ifdef FEAT_DIFF |
3566 && filler_todo <= 0 | |
3567 #endif | |
3568 ) | |
3569 { | |
3570 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3571 wp->w_p_rl); | |
819 | 3572 /* Pretend we have finished updating the window. Except when |
3573 * 'cursorcolumn' is set. */ | |
3574 #ifdef FEAT_SYN_HL | |
3575 if (wp->w_p_cuc) | |
3576 row = wp->w_cline_row + wp->w_cline_height; | |
3577 else | |
3578 #endif | |
3579 row = wp->w_height; | |
7 | 3580 break; |
3581 } | |
3582 | |
3583 if (draw_state == WL_LINE && area_highlighting) | |
3584 { | |
3585 /* handle Visual or match highlighting in this line */ | |
3586 if (vcol == fromcol | |
3587 #ifdef FEAT_MBYTE | |
3588 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3589 && (*mb_ptr2cells)(ptr) > 1) | |
3590 #endif | |
3591 || ((int)vcol_prev == fromcol_prev | |
1814 | 3592 && vcol_prev < vcol /* not at margin */ |
7 | 3593 && vcol < tocol)) |
3594 area_attr = attr; /* start highlighting */ | |
3595 else if (area_attr != 0 | |
3596 && (vcol == tocol | |
3597 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3598 area_attr = 0; /* stop highlighting */ | |
3599 | |
3600 #ifdef FEAT_SEARCH_EXTRA | |
3601 if (!n_extra) | |
3602 { | |
3603 /* | |
3604 * Check for start/end of search pattern match. | |
3605 * After end, check for start/end of next match. | |
3606 * When another match, have to check for start again. | |
3607 * Watch out for matching an empty string! | |
1326 | 3608 * Do this for 'search_hl' and the match list (ordered by |
3609 * priority). | |
7 | 3610 */ |
36 | 3611 v = (long)(ptr - line); |
1326 | 3612 cur = wp->w_match_head; |
3613 shl_flag = FALSE; | |
3614 while (cur != NULL || shl_flag == FALSE) | |
3615 { | |
3616 if (shl_flag == FALSE | |
3617 && ((cur != NULL | |
3618 && cur->priority > SEARCH_HL_PRIORITY) | |
3619 || cur == NULL)) | |
3620 { | |
3621 shl = &search_hl; | |
3622 shl_flag = TRUE; | |
3623 } | |
3624 else | |
3625 shl = &cur->hl; | |
7 | 3626 while (shl->rm.regprog != NULL) |
3627 { | |
36 | 3628 if (shl->startcol != MAXCOL |
3629 && v >= (long)shl->startcol | |
3630 && v < (long)shl->endcol) | |
7 | 3631 { |
3632 shl->attr_cur = shl->attr; | |
3633 } | |
36 | 3634 else if (v == (long)shl->endcol) |
7 | 3635 { |
3636 shl->attr_cur = 0; | |
3637 | |
3638 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3639 | |
3640 /* Need to get the line again, a multi-line regexp | |
3641 * may have made it invalid. */ | |
3642 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3643 ptr = line + v; | |
3644 | |
3645 if (shl->lnum == lnum) | |
3646 { | |
36 | 3647 shl->startcol = shl->rm.startpos[0].col; |
7 | 3648 if (shl->rm.endpos[0].lnum == 0) |
36 | 3649 shl->endcol = shl->rm.endpos[0].col; |
7 | 3650 else |
36 | 3651 shl->endcol = MAXCOL; |
3652 | |
3653 if (shl->startcol == shl->endcol) | |
7 | 3654 { |
3655 /* highlight empty match, try again after | |
3656 * it */ | |
3657 #ifdef FEAT_MBYTE | |
3658 if (has_mbyte) | |
474 | 3659 shl->endcol += (*mb_ptr2len)(line |
36 | 3660 + shl->endcol); |
7 | 3661 else |
3662 #endif | |
36 | 3663 ++shl->endcol; |
7 | 3664 } |
3665 | |
3666 /* Loop to check if the match starts at the | |
3667 * current position */ | |
3668 continue; | |
3669 } | |
3670 } | |
3671 break; | |
3672 } | |
1326 | 3673 if (shl != &search_hl && cur != NULL) |
3674 cur = cur->next; | |
3675 } | |
3676 | |
3677 /* Use attributes from match with highest priority among | |
3678 * 'search_hl' and the match list. */ | |
3679 search_attr = search_hl.attr_cur; | |
3680 cur = wp->w_match_head; | |
3681 shl_flag = FALSE; | |
3682 while (cur != NULL || shl_flag == FALSE) | |
3683 { | |
3684 if (shl_flag == FALSE | |
3685 && ((cur != NULL | |
3686 && cur->priority > SEARCH_HL_PRIORITY) | |
3687 || cur == NULL)) | |
699 | 3688 { |
1326 | 3689 shl = &search_hl; |
3690 shl_flag = TRUE; | |
699 | 3691 } |
1326 | 3692 else |
3693 shl = &cur->hl; | |
3694 if (shl->attr_cur != 0) | |
3695 search_attr = shl->attr_cur; | |
3696 if (shl != &search_hl && cur != NULL) | |
3697 cur = cur->next; | |
3698 } | |
7 | 3699 } |
3700 #endif | |
3701 | |
3702 #ifdef FEAT_DIFF | |
674 | 3703 if (diff_hlf != (hlf_T)0) |
7 | 3704 { |
1295 | 3705 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3706 && n_extra == 0) | |
7 | 3707 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3708 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3709 && n_extra == 0) | |
7 | 3710 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3711 line_attr = hl_attr(diff_hlf); |
3712 } | |
3713 #endif | |
3714 | |
3715 /* Decide which of the highlight attributes to use. */ | |
3716 attr_pri = TRUE; | |
3717 if (area_attr != 0) | |
3718 char_attr = area_attr; | |
3719 else if (search_attr != 0) | |
3720 char_attr = search_attr; | |
3721 #ifdef LINE_ATTR | |
3722 /* Use line_attr when not in the Visual or 'incsearch' area | |
3723 * (area_attr may be 0 when "noinvcur" is set). */ | |
3724 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3725 || vcol < fromcol || vcol_prev < fromcol_prev |
3726 || vcol >= tocol)) | |
674 | 3727 char_attr = line_attr; |
3728 #endif | |
3729 else | |
3730 { | |
3731 attr_pri = FALSE; | |
3732 #ifdef FEAT_SYN_HL | |
3733 if (has_syntax) | |
3734 char_attr = syntax_attr; | |
3735 else | |
3736 #endif | |
3737 char_attr = 0; | |
3738 } | |
7 | 3739 } |
3740 | |
3741 /* | |
3742 * Get the next character to put on the screen. | |
3743 */ | |
3744 /* | |
1340 | 3745 * The "p_extra" points to the extra stuff that is inserted to |
3746 * represent special characters (non-printable stuff) and other | |
3747 * things. When all characters are the same, c_extra is used. | |
3748 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3749 * "p_extra[n_extra]". | |
7 | 3750 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3751 */ | |
3752 if (n_extra > 0) | |
3753 { | |
3754 if (c_extra != NUL) | |
3755 { | |
3756 c = c_extra; | |
3757 #ifdef FEAT_MBYTE | |
3758 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3759 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3760 { | |
3761 mb_utf8 = TRUE; | |
714 | 3762 u8cc[0] = 0; |
819 | 3763 c = 0xc0; |
7 | 3764 } |
3765 else | |
3766 mb_utf8 = FALSE; | |
3767 #endif | |
3768 } | |
3769 else | |
3770 { | |
3771 c = *p_extra; | |
3772 #ifdef FEAT_MBYTE | |
3773 if (has_mbyte) | |
3774 { | |
3775 mb_c = c; | |
3776 if (enc_utf8) | |
3777 { | |
3778 /* If the UTF-8 character is more than one byte: | |
3779 * Decode it into "mb_c". */ | |
474 | 3780 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3781 mb_utf8 = FALSE; |
3782 if (mb_l > n_extra) | |
3783 mb_l = 1; | |
3784 else if (mb_l > 1) | |
3785 { | |
714 | 3786 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3787 mb_utf8 = TRUE; |
819 | 3788 c = 0xc0; |
7 | 3789 } |
3790 } | |
3791 else | |
3792 { | |
3793 /* if this is a DBCS character, put it in "mb_c" */ | |
3794 mb_l = MB_BYTE2LEN(c); | |
3795 if (mb_l >= n_extra) | |
3796 mb_l = 1; | |
3797 else if (mb_l > 1) | |
3798 mb_c = (c << 8) + p_extra[1]; | |
3799 } | |
504 | 3800 if (mb_l == 0) /* at the NUL at end-of-line */ |
3801 mb_l = 1; | |
3802 | |
7 | 3803 /* If a double-width char doesn't fit display a '>' in the |
3804 * last column. */ | |
504 | 3805 if (( |
7 | 3806 # ifdef FEAT_RIGHTLEFT |
3807 wp->w_p_rl ? (col <= 0) : | |
3808 # endif | |
504 | 3809 (col >= W_WIDTH(wp) - 1)) |
7 | 3810 && (*mb_char2cells)(mb_c) == 2) |
3811 { | |
3812 c = '>'; | |
3813 mb_c = c; | |
3814 mb_l = 1; | |
3815 mb_utf8 = FALSE; | |
3816 multi_attr = hl_attr(HLF_AT); | |
3817 /* put the pointer back to output the double-width | |
3818 * character at the start of the next line. */ | |
3819 ++n_extra; | |
3820 --p_extra; | |
3821 } | |
3822 else | |
3823 { | |
3824 n_extra -= mb_l - 1; | |
3825 p_extra += mb_l - 1; | |
3826 } | |
3827 } | |
3828 #endif | |
3829 ++p_extra; | |
3830 } | |
3831 --n_extra; | |
3832 } | |
3833 else | |
3834 { | |
3835 /* | |
3836 * Get a character from the line itself. | |
3837 */ | |
3838 c = *ptr; | |
3839 #ifdef FEAT_MBYTE | |
3840 if (has_mbyte) | |
3841 { | |
3842 mb_c = c; | |
3843 if (enc_utf8) | |
3844 { | |
3845 /* If the UTF-8 character is more than one byte: Decode it | |
3846 * into "mb_c". */ | |
474 | 3847 mb_l = (*mb_ptr2len)(ptr); |
7 | 3848 mb_utf8 = FALSE; |
3849 if (mb_l > 1) | |
3850 { | |
714 | 3851 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3852 /* Overlong encoded ASCII or ASCII with composing char |
3853 * is displayed normally, except a NUL. */ | |
3854 if (mb_c < 0x80) | |
3855 c = mb_c; | |
3856 mb_utf8 = TRUE; | |
507 | 3857 |
3858 /* At start of the line we can have a composing char. | |
3859 * Draw it as a space with a composing char. */ | |
3860 if (utf_iscomposing(mb_c)) | |
3861 { | |
1326 | 3862 int i; |
3863 | |
714 | 3864 for (i = Screen_mco - 1; i > 0; --i) |
3865 u8cc[i] = u8cc[i - 1]; | |
3866 u8cc[0] = mb_c; | |
507 | 3867 mb_c = ' '; |
3868 } | |
7 | 3869 } |
3870 | |
3871 if ((mb_l == 1 && c >= 0x80) | |
3872 || (mb_l >= 1 && mb_c == 0) | |
3873 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3874 # ifdef UNICODE16 |
3875 || mb_c >= 0x10000 | |
3876 # endif | |
3877 ))) | |
7 | 3878 { |
3879 /* | |
3880 * Illegal UTF-8 byte: display as <xx>. | |
3881 * Non-BMP character : display as ? or fullwidth ?. | |
3882 */ | |
1401 | 3883 # ifdef UNICODE16 |
7 | 3884 if (mb_c < 0x10000) |
1401 | 3885 # endif |
7 | 3886 { |
3887 transchar_hex(extra, mb_c); | |
714 | 3888 # ifdef FEAT_RIGHTLEFT |
7 | 3889 if (wp->w_p_rl) /* reverse */ |
3890 rl_mirror(extra); | |
714 | 3891 # endif |
7 | 3892 } |
1401 | 3893 # ifdef UNICODE16 |
7 | 3894 else if (utf_char2cells(mb_c) != 2) |
3895 STRCPY(extra, "?"); | |
3896 else | |
3897 /* 0xff1f in UTF-8: full-width '?' */ | |
3898 STRCPY(extra, "\357\274\237"); | |
1401 | 3899 # endif |
7 | 3900 |
3901 p_extra = extra; | |
3902 c = *p_extra; | |
3903 mb_c = mb_ptr2char_adv(&p_extra); | |
3904 mb_utf8 = (c >= 0x80); | |
3905 n_extra = (int)STRLEN(p_extra); | |
3906 c_extra = NUL; | |
3907 if (area_attr == 0 && search_attr == 0) | |
3908 { | |
3909 n_attr = n_extra + 1; | |
3910 extra_attr = hl_attr(HLF_8); | |
3911 saved_attr2 = char_attr; /* save current attr */ | |
3912 } | |
3913 } | |
3914 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3915 mb_l = 1; | |
3916 #ifdef FEAT_ARABIC | |
3917 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3918 { | |
3919 /* Do Arabic shaping. */ | |
714 | 3920 int pc, pc1, nc; |
3921 int pcc[MAX_MCO]; | |
7 | 3922 |
3923 /* The idea of what is the previous and next | |
3924 * character depends on 'rightleft'. */ | |
3925 if (wp->w_p_rl) | |
3926 { | |
3927 pc = prev_c; | |
3928 pc1 = prev_c1; | |
3929 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3930 prev_c1 = u8cc[0]; |
7 | 3931 } |
3932 else | |
3933 { | |
714 | 3934 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3935 nc = prev_c; |
714 | 3936 pc1 = pcc[0]; |
7 | 3937 } |
3938 prev_c = mb_c; | |
3939 | |
714 | 3940 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3941 } |
3942 else | |
3943 prev_c = mb_c; | |
3944 #endif | |
3945 } | |
3946 else /* enc_dbcs */ | |
3947 { | |
3948 mb_l = MB_BYTE2LEN(c); | |
3949 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3950 mb_l = 1; | |
3951 else if (mb_l > 1) | |
3952 { | |
3953 /* We assume a second byte below 32 is illegal. | |
3954 * Hopefully this is OK for all double-byte encodings! | |
3955 */ | |
3956 if (ptr[1] >= 32) | |
3957 mb_c = (c << 8) + ptr[1]; | |
3958 else | |
3959 { | |
3960 if (ptr[1] == NUL) | |
3961 { | |
3962 /* head byte at end of line */ | |
3963 mb_l = 1; | |
3964 transchar_nonprint(extra, c); | |
3965 } | |
3966 else | |
3967 { | |
3968 /* illegal tail byte */ | |
3969 mb_l = 2; | |
3970 STRCPY(extra, "XX"); | |
3971 } | |
3972 p_extra = extra; | |
3973 n_extra = (int)STRLEN(extra) - 1; | |
3974 c_extra = NUL; | |
3975 c = *p_extra++; | |
3976 if (area_attr == 0 && search_attr == 0) | |
3977 { | |
3978 n_attr = n_extra + 1; | |
3979 extra_attr = hl_attr(HLF_8); | |
3980 saved_attr2 = char_attr; /* save current attr */ | |
3981 } | |
3982 mb_c = c; | |
3983 } | |
3984 } | |
3985 } | |
3986 /* If a double-width char doesn't fit display a '>' in the | |
3987 * last column; the character is displayed at the start of the | |
3988 * next line. */ | |
3989 if (( | |
3990 # ifdef FEAT_RIGHTLEFT | |
3991 wp->w_p_rl ? (col <= 0) : | |
3992 # endif | |
3993 (col >= W_WIDTH(wp) - 1)) | |
3994 && (*mb_char2cells)(mb_c) == 2) | |
3995 { | |
3996 c = '>'; | |
3997 mb_c = c; | |
3998 mb_utf8 = FALSE; | |
3999 mb_l = 1; | |
4000 multi_attr = hl_attr(HLF_AT); | |
4001 /* Put pointer back so that the character will be | |
4002 * displayed at the start of the next line. */ | |
4003 --ptr; | |
4004 } | |
4005 else if (*ptr != NUL) | |
4006 ptr += mb_l - 1; | |
4007 | |
4008 /* 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
|
4009 * 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
|
4010 * charactes. */ |
6d6378ba18cb
Fix: An unprintable multi-byte character at the start of the screen line
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
4011 if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
7 | 4012 { |
4013 n_extra = 1; | |
1340 | 4014 c_extra = '<'; |
7 | 4015 c = ' '; |
4016 if (area_attr == 0 && search_attr == 0) | |
4017 { | |
4018 n_attr = n_extra + 1; | |
4019 extra_attr = hl_attr(HLF_AT); | |
4020 saved_attr2 = char_attr; /* save current attr */ | |
4021 } | |
4022 mb_c = c; | |
4023 mb_utf8 = FALSE; | |
4024 mb_l = 1; | |
4025 } | |
4026 | |
4027 } | |
4028 #endif | |
4029 ++ptr; | |
4030 | |
12 | 4031 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 4032 if (wp->w_p_list && (c == 160 |
4033 #ifdef FEAT_MBYTE | |
4034 || (mb_utf8 && mb_c == 160) | |
4035 #endif | |
4036 ) && lcs_nbsp) | |
12 | 4037 { |
4038 c = lcs_nbsp; | |
4039 if (area_attr == 0 && search_attr == 0) | |
4040 { | |
4041 n_attr = 1; | |
4042 extra_attr = hl_attr(HLF_8); | |
4043 saved_attr2 = char_attr; /* save current attr */ | |
4044 } | |
4045 #ifdef FEAT_MBYTE | |
4046 mb_c = c; | |
4047 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4048 { | |
4049 mb_utf8 = TRUE; | |
714 | 4050 u8cc[0] = 0; |
819 | 4051 c = 0xc0; |
12 | 4052 } |
4053 else | |
4054 mb_utf8 = FALSE; | |
4055 #endif | |
4056 } | |
4057 | |
7 | 4058 if (extra_check) |
4059 { | |
743 | 4060 #ifdef FEAT_SPELL |
221 | 4061 int can_spell = TRUE; |
743 | 4062 #endif |
4063 | |
4064 #ifdef FEAT_SYN_HL | |
7 | 4065 /* Get syntax attribute, unless still at the start of the line |
4066 * (double-wide char that doesn't fit). */ | |
221 | 4067 v = (long)(ptr - line); |
4068 if (has_syntax && v > 0) | |
7 | 4069 { |
4070 /* Get the syntax attribute for the character. If there | |
4071 * is an error, disable syntax highlighting. */ | |
4072 save_did_emsg = did_emsg; | |
4073 did_emsg = FALSE; | |
4074 | |
221 | 4075 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 4076 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4077 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4078 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4079 NULL, FALSE); |
7 | 4080 |
4081 if (did_emsg) | |
482 | 4082 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4083 wp->w_s->b_syn_error = TRUE; |
482 | 4084 has_syntax = FALSE; |
4085 } | |
7 | 4086 else |
4087 did_emsg = save_did_emsg; | |
4088 | |
4089 /* Need to get the line again, a multi-line regexp may | |
4090 * have made it invalid. */ | |
4091 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4092 ptr = line + v; | |
4093 | |
674 | 4094 if (!attr_pri) |
7 | 4095 char_attr = syntax_attr; |
301 | 4096 else |
303 | 4097 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
|
4098 # 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
|
4099 /* 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
|
4100 * 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
|
4101 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
|
4102 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
|
4103 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
|
4104 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
|
4105 # endif |
7 | 4106 } |
743 | 4107 #endif |
4108 | |
4109 #ifdef FEAT_SPELL | |
301 | 4110 /* Check spelling (unless at the end of the line). |
319 | 4111 * Only do this when there is no syntax highlighting, the |
4112 * @Spell cluster is not used or the current syntax item | |
4113 * contains the @Spell cluster. */ | |
348 | 4114 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4115 { |
230 | 4116 spell_attr = 0; |
743 | 4117 # ifdef FEAT_SYN_HL |
674 | 4118 if (!attr_pri) |
230 | 4119 char_attr = syntax_attr; |
743 | 4120 # endif |
4121 if (c != 0 && ( | |
4122 # ifdef FEAT_SYN_HL | |
4123 !has_syntax || | |
4124 # endif | |
4125 can_spell)) | |
221 | 4126 { |
348 | 4127 char_u *prev_ptr, *p; |
4128 int len; | |
534 | 4129 hlf_T spell_hlf = HLF_COUNT; |
221 | 4130 # ifdef FEAT_MBYTE |
336 | 4131 if (has_mbyte) |
4132 { | |
4133 prev_ptr = ptr - mb_l; | |
4134 v -= mb_l - 1; | |
4135 } | |
4136 else | |
221 | 4137 # endif |
336 | 4138 prev_ptr = ptr - 1; |
348 | 4139 |
4140 /* Use nextline[] if possible, it has the start of the | |
4141 * next line concatenated. */ | |
4142 if ((prev_ptr - line) - nextlinecol >= 0) | |
4143 p = nextline + (prev_ptr - line) - nextlinecol; | |
4144 else | |
4145 p = prev_ptr; | |
835 | 4146 cap_col -= (int)(prev_ptr - line); |
625 | 4147 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4148 nochange); | |
348 | 4149 word_end = v + len; |
301 | 4150 |
4151 /* In Insert mode only highlight a word that | |
4152 * doesn't touch the cursor. */ | |
534 | 4153 if (spell_hlf != HLF_COUNT |
301 | 4154 && (State & INSERT) != 0 |
4155 && wp->w_cursor.lnum == lnum | |
4156 && wp->w_cursor.col >= | |
4157 (colnr_T)(prev_ptr - line) | |
4158 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4159 { |
534 | 4160 spell_hlf = HLF_COUNT; |
301 | 4161 spell_redraw_lnum = lnum; |
221 | 4162 } |
348 | 4163 |
534 | 4164 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4165 && (p - nextline) + len > nextline_idx) |
4166 { | |
4167 /* Remember that the good word continues at the | |
4168 * start of the next line. */ | |
4169 checked_lnum = lnum + 1; | |
835 | 4170 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4171 } |
386 | 4172 |
534 | 4173 /* Turn index into actual attributes. */ |
4174 if (spell_hlf != HLF_COUNT) | |
4175 spell_attr = highlight_attr[spell_hlf]; | |
4176 | |
386 | 4177 if (cap_col > 0) |
4178 { | |
4179 if (p != prev_ptr | |
4180 && (p - nextline) + cap_col >= nextline_idx) | |
4181 { | |
4182 /* Remember that the word in the next line | |
4183 * must start with a capital. */ | |
4184 capcol_lnum = lnum + 1; | |
835 | 4185 cap_col = (int)((p - nextline) + cap_col |
4186 - nextline_idx); | |
386 | 4187 } |
4188 else | |
4189 /* Compute the actual column. */ | |
835 | 4190 cap_col += (int)(prev_ptr - line); |
386 | 4191 } |
221 | 4192 } |
4193 } | |
4194 if (spell_attr != 0) | |
348 | 4195 { |
674 | 4196 if (!attr_pri) |
348 | 4197 char_attr = hl_combine_attr(char_attr, spell_attr); |
4198 else | |
4199 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4200 } | |
7 | 4201 #endif |
4202 #ifdef FEAT_LINEBREAK | |
4203 /* | |
221 | 4204 * Found last space before word: check for line break. |
7 | 4205 */ |
4206 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4207 && !wp->w_p_list) |
7 | 4208 { |
4209 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4210 # ifdef FEAT_MBYTE | |
4211 has_mbyte ? mb_l : | |
4212 # endif | |
4213 1), (colnr_T)vcol, NULL) - 1; | |
4214 c_extra = ' '; | |
4215 if (vim_iswhite(c)) | |
4216 c = ' '; | |
4217 } | |
4218 #endif | |
4219 | |
4220 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4221 { | |
4222 c = lcs_trail; | |
674 | 4223 if (!attr_pri) |
7 | 4224 { |
4225 n_attr = 1; | |
4226 extra_attr = hl_attr(HLF_8); | |
4227 saved_attr2 = char_attr; /* save current attr */ | |
4228 } | |
4229 #ifdef FEAT_MBYTE | |
4230 mb_c = c; | |
4231 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4232 { | |
4233 mb_utf8 = TRUE; | |
714 | 4234 u8cc[0] = 0; |
819 | 4235 c = 0xc0; |
7 | 4236 } |
4237 else | |
4238 mb_utf8 = FALSE; | |
4239 #endif | |
4240 } | |
4241 } | |
4242 | |
4243 /* | |
4244 * Handling of non-printable characters. | |
4245 */ | |
819 | 4246 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4247 { |
4248 /* | |
4249 * when getting a character from the file, we may have to | |
4250 * turn it into something else on the way to putting it | |
4251 * into "ScreenLines". | |
4252 */ | |
4253 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4254 { | |
4255 /* tab amount depends on current column */ | |
4256 n_extra = (int)wp->w_buffer->b_p_ts | |
3004 | 4257 - VCOL_HLC % (int)wp->w_buffer->b_p_ts - 1; |
7 | 4258 #ifdef FEAT_MBYTE |
4259 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4260 #endif | |
4261 if (wp->w_p_list) | |
4262 { | |
4263 c = lcs_tab1; | |
4264 c_extra = lcs_tab2; | |
4265 n_attr = n_extra + 1; | |
4266 extra_attr = hl_attr(HLF_8); | |
4267 saved_attr2 = char_attr; /* save current attr */ | |
4268 #ifdef FEAT_MBYTE | |
4269 mb_c = c; | |
4270 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4271 { | |
4272 mb_utf8 = TRUE; | |
714 | 4273 u8cc[0] = 0; |
819 | 4274 c = 0xc0; |
7 | 4275 } |
4276 #endif | |
4277 } | |
4278 else | |
4279 { | |
4280 c_extra = ' '; | |
4281 c = ' '; | |
4282 } | |
4283 } | |
36 | 4284 else if (c == NUL |
4285 && ((wp->w_p_list && lcs_eol > 0) | |
4286 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4287 && tocol > vcol | |
39 | 4288 #ifdef FEAT_VISUAL |
36 | 4289 && VIsual_mode != Ctrl_V |
39 | 4290 #endif |
36 | 4291 && ( |
4292 # ifdef FEAT_RIGHTLEFT | |
4293 wp->w_p_rl ? (col >= 0) : | |
4294 # endif | |
4295 (col < W_WIDTH(wp))) | |
4296 && !(noinvcur | |
1850 | 4297 && lnum == wp->w_cursor.lnum |
36 | 4298 && (colnr_T)vcol == wp->w_virtcol))) |
4299 && lcs_eol_one >= 0) | |
7 | 4300 { |
36 | 4301 /* Display a '$' after the line or highlight an extra |
4302 * character if the line break is included. */ | |
7 | 4303 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4304 /* For a diff line the highlighting continues after the | |
4305 * "$". */ | |
4306 if ( | |
4307 # ifdef FEAT_DIFF | |
534 | 4308 diff_hlf == (hlf_T)0 |
7 | 4309 # ifdef LINE_ATTR |
4310 && | |
4311 # endif | |
4312 # endif | |
4313 # ifdef LINE_ATTR | |
4314 line_attr == 0 | |
4315 # endif | |
4316 ) | |
4317 #endif | |
4318 { | |
4319 #ifdef FEAT_VIRTUALEDIT | |
4320 /* In virtualedit, visual selections may extend | |
4321 * beyond end of line. */ | |
4322 if (area_highlighting && virtual_active() | |
4323 && tocol != MAXCOL && vcol < tocol) | |
4324 n_extra = 0; | |
4325 else | |
4326 #endif | |
4327 { | |
4328 p_extra = at_end_str; | |
4329 n_extra = 1; | |
4330 c_extra = NUL; | |
4331 } | |
4332 } | |
36 | 4333 if (wp->w_p_list) |
4334 c = lcs_eol; | |
4335 else | |
4336 c = ' '; | |
7 | 4337 lcs_eol_one = -1; |
4338 --ptr; /* put it back at the NUL */ | |
674 | 4339 if (!attr_pri) |
7 | 4340 { |
4341 extra_attr = hl_attr(HLF_AT); | |
4342 n_attr = 1; | |
4343 } | |
4344 #ifdef FEAT_MBYTE | |
4345 mb_c = c; | |
4346 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4347 { | |
4348 mb_utf8 = TRUE; | |
714 | 4349 u8cc[0] = 0; |
819 | 4350 c = 0xc0; |
7 | 4351 } |
4352 else | |
4353 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4354 #endif | |
4355 } | |
4356 else if (c != NUL) | |
4357 { | |
4358 p_extra = transchar(c); | |
4359 #ifdef FEAT_RIGHTLEFT | |
4360 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4361 rl_mirror(p_extra); /* reverse "<12>" */ | |
4362 #endif | |
4363 n_extra = byte2cells(c) - 1; | |
4364 c_extra = NUL; | |
4365 c = *p_extra++; | |
674 | 4366 if (!attr_pri) |
7 | 4367 { |
4368 n_attr = n_extra + 1; | |
4369 extra_attr = hl_attr(HLF_8); | |
4370 saved_attr2 = char_attr; /* save current attr */ | |
4371 } | |
4372 #ifdef FEAT_MBYTE | |
4373 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4374 #endif | |
4375 } | |
4376 #ifdef FEAT_VIRTUALEDIT | |
4377 else if (VIsual_active | |
4378 && (VIsual_mode == Ctrl_V | |
4379 || VIsual_mode == 'v') | |
4380 && virtual_active() | |
4381 && tocol != MAXCOL | |
4382 && vcol < tocol | |
4383 && ( | |
4384 # ifdef FEAT_RIGHTLEFT | |
4385 wp->w_p_rl ? (col >= 0) : | |
4386 # endif | |
4387 (col < W_WIDTH(wp)))) | |
4388 { | |
4389 c = ' '; | |
4390 --ptr; /* put it back at the NUL */ | |
4391 } | |
4392 #endif | |
910 | 4393 #if defined(LINE_ATTR) |
7 | 4394 else if (( |
4395 # ifdef FEAT_DIFF | |
910 | 4396 diff_hlf != (hlf_T)0 || |
7 | 4397 # endif |
4398 line_attr != 0 | |
4399 ) && ( | |
4400 # ifdef FEAT_RIGHTLEFT | |
4401 wp->w_p_rl ? (col >= 0) : | |
4402 # endif | |
2553
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4403 (col |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4404 # ifdef FEAT_CONCEAL |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4405 - boguscols |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4406 # endif |
37d3f90f5203
Conceal feature caused the 'cursorline' highlighting to stop early.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4407 < W_WIDTH(wp)))) |
7 | 4408 { |
4409 /* Highlight until the right side of the window */ | |
4410 c = ' '; | |
4411 --ptr; /* put it back at the NUL */ | |
867 | 4412 |
4413 /* Remember we do the char for line highlighting. */ | |
4414 ++did_line_attr; | |
4415 | |
4416 /* don't do search HL for the rest of the line */ | |
4417 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4418 char_attr = line_attr; | |
7 | 4419 # ifdef FEAT_DIFF |
4420 if (diff_hlf == HLF_TXD) | |
4421 { | |
4422 diff_hlf = HLF_CHD; | |
4423 if (attr == 0 || char_attr != attr) | |
4424 char_attr = hl_attr(diff_hlf); | |
4425 } | |
4426 # endif | |
4427 } | |
4428 #endif | |
4429 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4430 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4431 #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
|
4432 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
|
4433 && (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
|
4434 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
|
4435 && (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
|
4436 && !(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
|
4437 && 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
|
4438 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4439 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
|
4440 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
|
4441 && (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
|
4442 && 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
|
4443 { |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4444 /* 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
|
4445 * character. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4446 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4447 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4448 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4449 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4450 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4451 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4452 |
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
|
4453 prev_syntax_id = syntax_seqnr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4454 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4455 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4456 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4457 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4458 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
|
4459 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4460 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4461 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4462 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4463 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4464 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4465 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4466 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4467 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4468 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4469 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4470 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4471 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4472 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4473 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4474 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4475 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4476 else if (n_skip == 0) |
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 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4479 n_skip = 1; |
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 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4482 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4483 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4484 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4485 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4486 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4487 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4488 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4489 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4490 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
|
4491 # endif |
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 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4494 { |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2364
diff
changeset
|
4495 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
|
4496 is_concealing = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4497 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4498 #endif /* FEAT_CONCEAL */ |
7 | 4499 } |
4500 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4501 #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
|
4502 /* 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
|
4503 * 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
|
4504 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
|
4505 && 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
|
4506 && 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
|
4507 && (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
|
4508 { |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4509 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
|
4510 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
|
4511 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
|
4512 } |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4513 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
4514 |
7 | 4515 /* Don't override visual selection highlighting. */ |
4516 if (n_attr > 0 | |
4517 && draw_state == WL_LINE | |
674 | 4518 && !attr_pri) |
7 | 4519 char_attr = extra_attr; |
4520 | |
42 | 4521 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4522 /* XIM don't send preedit_start and preedit_end, but they send |
4523 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4524 * im_is_preediting() here. */ | |
4525 if (xic != NULL | |
1850 | 4526 && lnum == wp->w_cursor.lnum |
7 | 4527 && (State & INSERT) |
4528 && !p_imdisable | |
4529 && im_is_preediting() | |
4530 && draw_state == WL_LINE) | |
4531 { | |
4532 colnr_T tcol; | |
4533 | |
4534 if (preedit_end_col == MAXCOL) | |
1850 | 4535 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4536 else |
4537 tcol = preedit_end_col; | |
4538 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4539 { | |
4540 if (feedback_old_attr < 0) | |
4541 { | |
4542 feedback_col = 0; | |
4543 feedback_old_attr = char_attr; | |
4544 } | |
4545 char_attr = im_get_feedback_attr(feedback_col); | |
4546 if (char_attr < 0) | |
4547 char_attr = feedback_old_attr; | |
4548 feedback_col++; | |
4549 } | |
4550 else if (feedback_old_attr >= 0) | |
4551 { | |
4552 char_attr = feedback_old_attr; | |
4553 feedback_old_attr = -1; | |
4554 feedback_col = 0; | |
4555 } | |
4556 } | |
4557 #endif | |
4558 /* | |
4559 * Handle the case where we are in column 0 but not on the first | |
4560 * character of the line and the user wants us to show us a | |
4561 * special character (via 'listchars' option "precedes:<char>". | |
4562 */ | |
4563 if (lcs_prec_todo != NUL | |
4564 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4565 #ifdef FEAT_DIFF | |
4566 && filler_todo <= 0 | |
4567 #endif | |
4568 && draw_state > WL_NR | |
4569 && c != NUL) | |
4570 { | |
4571 c = lcs_prec; | |
4572 lcs_prec_todo = NUL; | |
4573 #ifdef FEAT_MBYTE | |
4574 mb_c = c; | |
4575 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4576 { | |
4577 mb_utf8 = TRUE; | |
714 | 4578 u8cc[0] = 0; |
819 | 4579 c = 0xc0; |
7 | 4580 } |
4581 else | |
4582 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4583 #endif | |
674 | 4584 if (!attr_pri) |
7 | 4585 { |
4586 saved_attr3 = char_attr; /* save current attr */ | |
4587 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4588 n_attr3 = 1; | |
4589 } | |
4590 } | |
4591 | |
4592 /* | |
867 | 4593 * At end of the text line or just after the last character. |
7 | 4594 */ |
867 | 4595 if (c == NUL |
910 | 4596 #if defined(LINE_ATTR) |
867 | 4597 || did_line_attr == 1 |
4598 #endif | |
4599 ) | |
4600 { | |
4601 #ifdef FEAT_SEARCH_EXTRA | |
4602 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4603 |
4604 /* we're not really at that column when skipping some text */ | |
1439 | 4605 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4606 ++prevcol; |
867 | 4607 #endif |
4608 | |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4609 /* Invert at least one char, used for Visual and empty line or |
7 | 4610 * highlight match at end of line. If it's beyond the last |
4611 * char on the screen, just overwrite that one (tricky!) Not | |
4612 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4613 #ifdef FEAT_SEARCH_EXTRA |
4614 prevcol_hl_flag = FALSE; | |
4615 if (prevcol == (long)search_hl.startcol) | |
4616 prevcol_hl_flag = TRUE; | |
4617 else | |
4618 { | |
4619 cur = wp->w_match_head; | |
4620 while (cur != NULL) | |
4621 { | |
4622 if (prevcol == (long)cur->hl.startcol) | |
4623 { | |
4624 prevcol_hl_flag = TRUE; | |
4625 break; | |
4626 } | |
4627 cur = cur->next; | |
4628 } | |
4629 } | |
4630 #endif | |
7 | 4631 if (lcs_eol == lcs_eol_one |
1850 | 4632 && ((area_attr != 0 && vcol == fromcol |
4633 #ifdef FEAT_VISUAL | |
4634 && (VIsual_mode != Ctrl_V | |
4635 || lnum == VIsual.lnum | |
4636 || lnum == curwin->w_cursor.lnum) | |
4637 #endif | |
4638 && c == NUL) | |
7 | 4639 #ifdef FEAT_SEARCH_EXTRA |
4640 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4641 || (prevcol_hl_flag == TRUE |
910 | 4642 # if defined(LINE_ATTR) |
867 | 4643 && did_line_attr <= 1 |
4644 # endif | |
4645 ) | |
7 | 4646 #endif |
4647 )) | |
4648 { | |
4649 int n = 0; | |
4650 | |
4651 #ifdef FEAT_RIGHTLEFT | |
4652 if (wp->w_p_rl) | |
4653 { | |
4654 if (col < 0) | |
4655 n = 1; | |
4656 } | |
4657 else | |
4658 #endif | |
4659 { | |
4660 if (col >= W_WIDTH(wp)) | |
4661 n = -1; | |
4662 } | |
4663 if (n != 0) | |
4664 { | |
4665 /* At the window boundary, highlight the last character | |
4666 * instead (better than nothing). */ | |
4667 off += n; | |
4668 col += n; | |
4669 } | |
4670 else | |
4671 { | |
4672 /* Add a blank character to highlight. */ | |
4673 ScreenLines[off] = ' '; | |
4674 #ifdef FEAT_MBYTE | |
4675 if (enc_utf8) | |
4676 ScreenLinesUC[off] = 0; | |
4677 #endif | |
4678 } | |
4679 #ifdef FEAT_SEARCH_EXTRA | |
4680 if (area_attr == 0) | |
4681 { | |
1326 | 4682 /* Use attributes from match with highest priority among |
4683 * 'search_hl' and the match list. */ | |
4684 char_attr = search_hl.attr; | |
4685 cur = wp->w_match_head; | |
4686 shl_flag = FALSE; | |
4687 while (cur != NULL || shl_flag == FALSE) | |
699 | 4688 { |
1326 | 4689 if (shl_flag == FALSE |
4690 && ((cur != NULL | |
4691 && cur->priority > SEARCH_HL_PRIORITY) | |
4692 || cur == NULL)) | |
699 | 4693 { |
1326 | 4694 shl = &search_hl; |
4695 shl_flag = TRUE; | |
699 | 4696 } |
1326 | 4697 else |
4698 shl = &cur->hl; | |
4699 if ((ptr - line) - 1 == (long)shl->startcol) | |
4700 char_attr = shl->attr; | |
4701 if (shl != &search_hl && cur != NULL) | |
4702 cur = cur->next; | |
699 | 4703 } |
7 | 4704 } |
4705 #endif | |
4706 ScreenAttrs[off] = char_attr; | |
4707 #ifdef FEAT_RIGHTLEFT | |
4708 if (wp->w_p_rl) | |
1437 | 4709 { |
7 | 4710 --col; |
1437 | 4711 --off; |
4712 } | |
7 | 4713 else |
4714 #endif | |
1437 | 4715 { |
7 | 4716 ++col; |
1437 | 4717 ++off; |
4718 } | |
743 | 4719 ++vcol; |
1437 | 4720 #ifdef FEAT_SYN_HL |
4721 eol_hl_off = 1; | |
4722 #endif | |
743 | 4723 } |
867 | 4724 } |
4725 | |
4726 /* | |
4727 * At end of the text line. | |
4728 */ | |
4729 if (c == NUL) | |
4730 { | |
743 | 4731 #ifdef FEAT_SYN_HL |
1850 | 4732 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4733 && lnum == wp->w_cursor.lnum) | |
1437 | 4734 { |
4735 /* highlight last char after line */ | |
4736 --col; | |
4737 --off; | |
4738 --vcol; | |
4739 } | |
4740 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4741 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4742 if (wp->w_p_wrap) |
4743 v = wp->w_skipcol; | |
4744 else | |
4745 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4746 |
820 | 4747 /* check if line ends before left margin */ |
4748 if (vcol < v + col - win_col_off(wp)) | |
4749 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
|
4750 #ifdef FEAT_CONCEAL |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4751 /* 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
|
4752 * edge for 'cursorcolumn'. */ |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4753 col -= boguscols; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4754 boguscols = 0; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4755 #endif |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4756 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4757 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4758 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
|
4759 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4760 if (((wp->w_p_cuc |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4761 && (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
|
4762 && (int)wp->w_virtcol < |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4763 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
|
4764 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4765 || draw_color_col) |
743 | 4766 # ifdef FEAT_RIGHTLEFT |
4767 && !wp->w_p_rl | |
4768 # endif | |
4769 ) | |
4770 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4771 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4772 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4773 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4774 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4775 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4776 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4777 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4778 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
|
4779 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4780 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4781 |
743 | 4782 while (col < W_WIDTH(wp)) |
4783 { | |
4784 ScreenLines[off] = ' '; | |
4785 #ifdef FEAT_MBYTE | |
4786 if (enc_utf8) | |
4787 ScreenLinesUC[off] = 0; | |
4788 #endif | |
4789 ++col; | |
2356
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4790 if (draw_color_col) |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4791 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
|
4792 &color_cols); |
eb1f2554cac5
Fix 'colorcolumn' adjecent columns not highlighted after end of line.
Bram Moolenaar <bram@vim.org>
parents:
2349
diff
changeset
|
4793 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4794 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
|
4795 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
|
4796 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
|
4797 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4798 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4799 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4800 |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4801 if (VCOL_HLC >= rightmost_vcol) |
743 | 4802 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4803 |
743 | 4804 ++vcol; |
4805 } | |
4806 } | |
4807 #endif | |
7 | 4808 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4809 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
|
4810 (int)W_WIDTH(wp), wp->w_p_rl); |
7 | 4811 row++; |
4812 | |
4813 /* | |
4814 * Update w_cline_height and w_cline_folded if the cursor line was | |
4815 * updated (saves a call to plines() later). | |
4816 */ | |
4817 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4818 { | |
4819 curwin->w_cline_row = startrow; | |
4820 curwin->w_cline_height = row - startrow; | |
4821 #ifdef FEAT_FOLDING | |
4822 curwin->w_cline_folded = FALSE; | |
4823 #endif | |
4824 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4825 } | |
4826 | |
4827 break; | |
4828 } | |
4829 | |
4830 /* line continues beyond line end */ | |
4831 if (lcs_ext | |
4832 && !wp->w_p_wrap | |
4833 #ifdef FEAT_DIFF | |
4834 && filler_todo <= 0 | |
4835 #endif | |
4836 && ( | |
4837 #ifdef FEAT_RIGHTLEFT | |
4838 wp->w_p_rl ? col == 0 : | |
4839 #endif | |
4840 col == W_WIDTH(wp) - 1) | |
4841 && (*ptr != NUL | |
1555 | 4842 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4843 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4844 { | |
4845 c = lcs_ext; | |
4846 char_attr = hl_attr(HLF_AT); | |
4847 #ifdef FEAT_MBYTE | |
4848 mb_c = c; | |
4849 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4850 { | |
4851 mb_utf8 = TRUE; | |
714 | 4852 u8cc[0] = 0; |
819 | 4853 c = 0xc0; |
7 | 4854 } |
4855 else | |
4856 mb_utf8 = FALSE; | |
4857 #endif | |
4858 } | |
4859 | |
743 | 4860 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4861 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4862 if (draw_color_col) |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4863 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
|
4864 |
743 | 4865 /* 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
|
4866 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4867 * 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
|
4868 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4869 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4870 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
|
4871 { |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4872 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
|
4873 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4874 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4875 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4876 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
|
4877 } |
2346
b38c324bdc36
Fix: 'colorcolumn' interfered with concealed text.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
4878 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
|
4879 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4880 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4881 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
|
4882 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4883 } |
743 | 4884 #endif |
4885 | |
7 | 4886 /* |
4887 * Store character to be displayed. | |
4888 * Skip characters that are left of the screen for 'nowrap'. | |
4889 */ | |
4890 vcol_prev = vcol; | |
4891 if (draw_state < WL_LINE || n_skip <= 0) | |
4892 { | |
4893 /* | |
4894 * Store the character. | |
4895 */ | |
4896 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4897 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4898 { | |
4899 /* A double-wide character is: put first halve in left cell. */ | |
4900 --off; | |
4901 --col; | |
4902 } | |
4903 #endif | |
4904 ScreenLines[off] = c; | |
4905 #ifdef FEAT_MBYTE | |
4906 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4907 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4908 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4909 ScreenLines[off] = 0x8e; |
7 | 4910 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4911 } |
7 | 4912 else if (enc_utf8) |
4913 { | |
4914 if (mb_utf8) | |
4915 { | |
1326 | 4916 int i; |
4917 | |
7 | 4918 ScreenLinesUC[off] = mb_c; |
819 | 4919 if ((c & 0xff) == 0) |
4920 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4921 for (i = 0; i < Screen_mco; ++i) |
4922 { | |
4923 ScreenLinesC[i][off] = u8cc[i]; | |
4924 if (u8cc[i] == 0) | |
4925 break; | |
4926 } | |
7 | 4927 } |
4928 else | |
4929 ScreenLinesUC[off] = 0; | |
4930 } | |
4931 if (multi_attr) | |
4932 { | |
4933 ScreenAttrs[off] = multi_attr; | |
4934 multi_attr = 0; | |
4935 } | |
4936 else | |
4937 #endif | |
4938 ScreenAttrs[off] = char_attr; | |
4939 | |
4940 #ifdef FEAT_MBYTE | |
4941 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4942 { | |
4943 /* Need to fill two screen columns. */ | |
4944 ++off; | |
4945 ++col; | |
4946 if (enc_utf8) | |
4947 /* UTF-8: Put a 0 in the second screen char. */ | |
4948 ScreenLines[off] = 0; | |
4949 else | |
4950 /* DBCS: Put second byte in the second screen char. */ | |
4951 ScreenLines[off] = mb_c & 0xff; | |
4952 ++vcol; | |
4953 /* When "tocol" is halfway a character, set it to the end of | |
4954 * the character, otherwise highlighting won't stop. */ | |
4955 if (tocol == vcol) | |
4956 ++tocol; | |
4957 #ifdef FEAT_RIGHTLEFT | |
4958 if (wp->w_p_rl) | |
4959 { | |
4960 /* now it's time to backup one cell */ | |
4961 --off; | |
4962 --col; | |
4963 } | |
4964 #endif | |
4965 } | |
4966 #endif | |
4967 #ifdef FEAT_RIGHTLEFT | |
4968 if (wp->w_p_rl) | |
4969 { | |
4970 --off; | |
4971 --col; | |
4972 } | |
4973 else | |
4974 #endif | |
4975 { | |
4976 ++off; | |
4977 ++col; | |
4978 } | |
4979 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4980 #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
|
4981 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
|
4982 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4983 --n_skip; |
2332
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4984 ++vcol_off; |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4985 if (n_extra > 0) |
b13079093ae1
Make 'cursorcolumn' work together with the conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
4986 vcol_off += n_extra; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4987 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4988 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4989 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4990 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4991 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4992 * 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
|
4993 * 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
|
4994 * 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
|
4995 * 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
|
4996 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4997 * 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
|
4998 * 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
|
4999 * 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
|
5000 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5001 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5002 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5003 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5004 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5005 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5006 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5007 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5008 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5009 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5010 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5011 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5012 # endif |
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 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5015 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5016 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5017 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5018 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5019 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5020 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5021 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5022 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5023 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
|
5024 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5025 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5026 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5027 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5028 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5029 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5030 --col; |
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 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5033 # endif |
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 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5036 ++col; |
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 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5039 # endif |
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 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 if (wp->w_p_rl) |
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 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5045 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5046 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5047 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5048 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5049 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5050 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5051 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5052 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5053 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5054 else |
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 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5057 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5058 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5059 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5060 n_attr = 0; |
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 |
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 #endif /* FEAT_CONCEAL */ |
7 | 5066 else |
5067 --n_skip; | |
5068 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5069 /* 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
|
5070 * column. */ |
1849 | 5071 if (draw_state > WL_NR |
7 | 5072 #ifdef FEAT_DIFF |
5073 && filler_todo <= 0 | |
5074 #endif | |
5075 ) | |
5076 ++vcol; | |
5077 | |
743 | 5078 #ifdef FEAT_SYN_HL |
5079 if (vcol_save_attr >= 0) | |
5080 char_attr = vcol_save_attr; | |
5081 #endif | |
5082 | |
7 | 5083 /* restore attributes after "predeces" in 'listchars' */ |
5084 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5085 char_attr = saved_attr3; | |
5086 | |
5087 /* restore attributes after last 'listchars' or 'number' char */ | |
5088 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5089 char_attr = saved_attr2; | |
5090 | |
5091 /* | |
5092 * At end of screen line and there is more to come: Display the line | |
1378 | 5093 * so far. If there is no more to display it is caught above. |
7 | 5094 */ |
5095 if (( | |
5096 #ifdef FEAT_RIGHTLEFT | |
5097 wp->w_p_rl ? (col < 0) : | |
5098 #endif | |
5099 (col >= W_WIDTH(wp))) | |
5100 && (*ptr != NUL | |
5101 #ifdef FEAT_DIFF | |
5102 || filler_todo > 0 | |
5103 #endif | |
2724 | 5104 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
7 | 5105 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
5106 ) | |
5107 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5108 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5109 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
|
5110 (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
|
5111 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5112 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5113 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
|
5114 (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
|
5115 #endif |
7 | 5116 ++row; |
5117 ++screen_row; | |
5118 | |
5119 /* When not wrapping and finished diff lines, or when displayed | |
5120 * '$' and highlighting until last column, break here. */ | |
5121 if ((!wp->w_p_wrap | |
5122 #ifdef FEAT_DIFF | |
5123 && filler_todo <= 0 | |
5124 #endif | |
5125 ) || lcs_eol_one == -1) | |
5126 break; | |
5127 | |
5128 /* When the window is too narrow draw all "@" lines. */ | |
5129 if (draw_state != WL_LINE | |
5130 #ifdef FEAT_DIFF | |
5131 && filler_todo <= 0 | |
5132 #endif | |
5133 ) | |
5134 { | |
5135 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5136 #ifdef FEAT_VERTSPLIT | |
5137 draw_vsep_win(wp, row); | |
5138 #endif | |
5139 row = endrow; | |
5140 } | |
5141 | |
5142 /* When line got too long for screen break here. */ | |
5143 if (row == endrow) | |
5144 { | |
5145 ++row; | |
5146 break; | |
5147 } | |
5148 | |
5149 if (screen_cur_row == screen_row - 1 | |
5150 #ifdef FEAT_DIFF | |
5151 && filler_todo <= 0 | |
5152 #endif | |
5153 && W_WIDTH(wp) == Columns) | |
5154 { | |
5155 /* Remember that the line wraps, used for modeless copy. */ | |
5156 LineWraps[screen_row - 1] = TRUE; | |
5157 | |
5158 /* | |
5159 * Special trick to make copy/paste of wrapped lines work with | |
5160 * xterm/screen: write an extra character beyond the end of | |
5161 * the line. This will work with all terminal types | |
5162 * (regardless of the xn,am settings). | |
5163 * Only do this on a fast tty. | |
5164 * Only do this if the cursor is on the current line | |
5165 * (something has been written in it). | |
5166 * Don't do this for the GUI. | |
5167 * Don't do this for double-width characters. | |
5168 * Don't do this for a window not at the right screen border. | |
5169 */ | |
5170 if (p_tf | |
5171 #ifdef FEAT_GUI | |
5172 && !gui.in_use | |
5173 #endif | |
5174 #ifdef FEAT_MBYTE | |
5175 && !(has_mbyte | |
1378 | 5176 && ((*mb_off2cells)(LineOffset[screen_row], |
5177 LineOffset[screen_row] + screen_Columns) | |
5178 == 2 | |
7 | 5179 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5180 + (int)Columns - 2, |
5181 LineOffset[screen_row] + screen_Columns) | |
5182 == 2)) | |
7 | 5183 #endif |
5184 ) | |
5185 { | |
5186 /* First make sure we are at the end of the screen line, | |
5187 * then output the same character again to let the | |
5188 * terminal know about the wrap. If the terminal doesn't | |
5189 * auto-wrap, we overwrite the character. */ | |
5190 if (screen_cur_col != W_WIDTH(wp)) | |
5191 screen_char(LineOffset[screen_row - 1] | |
5192 + (unsigned)Columns - 1, | |
5193 screen_row - 1, (int)(Columns - 1)); | |
5194 | |
5195 #ifdef FEAT_MBYTE | |
5196 /* When there is a multi-byte character, just output a | |
5197 * space to keep it simple. */ | |
148 | 5198 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5199 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5200 out_char(' '); |
5201 else | |
5202 #endif | |
5203 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5204 + (Columns - 1)]); | |
5205 /* force a redraw of the first char on the next line */ | |
5206 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5207 screen_start(); /* don't know where cursor is now */ | |
5208 } | |
5209 } | |
5210 | |
5211 col = 0; | |
5212 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5213 #ifdef FEAT_RIGHTLEFT | |
5214 if (wp->w_p_rl) | |
5215 { | |
5216 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5217 off += col; | |
5218 } | |
5219 #endif | |
5220 | |
5221 /* reset the drawing state for the start of a wrapped line */ | |
5222 draw_state = WL_START; | |
5223 saved_n_extra = n_extra; | |
5224 saved_p_extra = p_extra; | |
5225 saved_c_extra = c_extra; | |
5226 saved_char_attr = char_attr; | |
5227 n_extra = 0; | |
5228 lcs_prec_todo = lcs_prec; | |
5229 #ifdef FEAT_LINEBREAK | |
5230 # ifdef FEAT_DIFF | |
5231 if (filler_todo <= 0) | |
5232 # endif | |
5233 need_showbreak = TRUE; | |
5234 #endif | |
5235 #ifdef FEAT_DIFF | |
5236 --filler_todo; | |
5237 /* When the filler lines are actually below the last line of the | |
5238 * file, don't draw the line itself, break here. */ | |
5239 if (filler_todo == 0 && wp->w_botfill) | |
5240 break; | |
5241 #endif | |
5242 } | |
5243 | |
5244 } /* for every character in the line */ | |
5245 | |
743 | 5246 #ifdef FEAT_SPELL |
386 | 5247 /* After an empty line check first word for capital. */ |
5248 if (*skipwhite(line) == NUL) | |
5249 { | |
5250 capcol_lnum = lnum + 1; | |
5251 cap_col = 0; | |
5252 } | |
5253 #endif | |
5254 | |
7 | 5255 return row; |
5256 } | |
5257 | |
714 | 5258 #ifdef FEAT_MBYTE |
5259 static int comp_char_differs __ARGS((int, int)); | |
5260 | |
5261 /* | |
5262 * 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
|
5263 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5264 */ |
5265 static int | |
5266 comp_char_differs(off_from, off_to) | |
5267 int off_from; | |
5268 int off_to; | |
5269 { | |
5270 int i; | |
5271 | |
5272 for (i = 0; i < Screen_mco; ++i) | |
5273 { | |
5274 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5275 return TRUE; | |
5276 if (ScreenLinesC[i][off_from] == 0) | |
5277 break; | |
5278 } | |
5279 return FALSE; | |
5280 } | |
5281 #endif | |
5282 | |
7 | 5283 /* |
5284 * Check whether the given character needs redrawing: | |
5285 * - the (first byte of the) character is different | |
5286 * - the attributes are different | |
5287 * - the character is multi-byte and the next byte is different | |
1616 | 5288 * - the character is two cells wide and the second cell differs. |
7 | 5289 */ |
5290 static int | |
5291 char_needs_redraw(off_from, off_to, cols) | |
5292 int off_from; | |
5293 int off_to; | |
5294 int cols; | |
5295 { | |
5296 if (cols > 0 | |
5297 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5298 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5299 | |
5300 #ifdef FEAT_MBYTE | |
5301 || (enc_dbcs != 0 | |
5302 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5303 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5304 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5305 : (cols > 1 && ScreenLines[off_from + 1] | |
5306 != ScreenLines[off_to + 1]))) | |
5307 || (enc_utf8 | |
5308 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5309 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5310 && comp_char_differs(off_from, off_to)) |
5311 || (cols > 1 && ScreenLines[off_from + 1] | |
5312 != ScreenLines[off_to + 1]))) | |
7 | 5313 #endif |
5314 )) | |
5315 return TRUE; | |
5316 return FALSE; | |
5317 } | |
5318 | |
5319 /* | |
5320 * Move one "cooked" screen line to the screen, but only the characters that | |
5321 * have actually changed. Handle insert/delete character. | |
5322 * "coloff" gives the first column on the screen for this line. | |
5323 * "endcol" gives the columns where valid characters are. | |
5324 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5325 * needs to be cleared, negative otherwise. | |
5326 * "rlflag" is TRUE in a rightleft window: | |
5327 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5328 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5329 */ | |
5330 static void | |
5331 screen_line(row, coloff, endcol, clear_width | |
5332 #ifdef FEAT_RIGHTLEFT | |
5333 , rlflag | |
5334 #endif | |
5335 ) | |
5336 int row; | |
5337 int coloff; | |
5338 int endcol; | |
5339 int clear_width; | |
5340 #ifdef FEAT_RIGHTLEFT | |
5341 int rlflag; | |
5342 #endif | |
5343 { | |
5344 unsigned off_from; | |
5345 unsigned off_to; | |
1378 | 5346 #ifdef FEAT_MBYTE |
5347 unsigned max_off_from; | |
5348 unsigned max_off_to; | |
5349 #endif | |
7 | 5350 int col = 0; |
5351 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5352 int hl; | |
5353 #endif | |
5354 int force = FALSE; /* force update rest of the line */ | |
5355 int redraw_this /* bool: does character need redraw? */ | |
5356 #ifdef FEAT_GUI | |
5357 = TRUE /* For GUI when while-loop empty */ | |
5358 #endif | |
5359 ; | |
5360 int redraw_next; /* redraw_this for next character */ | |
5361 #ifdef FEAT_MBYTE | |
5362 int clear_next = FALSE; | |
5363 int char_cells; /* 1: normal char */ | |
5364 /* 2: occupies two display cells */ | |
5365 # define CHAR_CELLS char_cells | |
5366 #else | |
5367 # define CHAR_CELLS 1 | |
5368 #endif | |
5369 | |
5370 # ifdef FEAT_CLIPBOARD | |
5371 clip_may_clear_selection(row, row); | |
5372 # endif | |
5373 | |
5374 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5375 off_to = LineOffset[row] + coloff; | |
1378 | 5376 #ifdef FEAT_MBYTE |
5377 max_off_from = off_from + screen_Columns; | |
5378 max_off_to = LineOffset[row] + screen_Columns; | |
5379 #endif | |
7 | 5380 |
5381 #ifdef FEAT_RIGHTLEFT | |
5382 if (rlflag) | |
5383 { | |
5384 /* Clear rest first, because it's left of the text. */ | |
5385 if (clear_width > 0) | |
5386 { | |
5387 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5388 && ScreenAttrs[off_to] == 0 | |
5389 # ifdef FEAT_MBYTE | |
5390 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5391 # endif | |
5392 ) | |
5393 { | |
5394 ++off_to; | |
5395 ++col; | |
5396 } | |
5397 if (col <= endcol) | |
5398 screen_fill(row, row + 1, col + coloff, | |
5399 endcol + coloff + 1, ' ', ' ', 0); | |
5400 } | |
5401 col = endcol + 1; | |
5402 off_to = LineOffset[row] + col + coloff; | |
5403 off_from += col; | |
5404 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5405 } | |
5406 #endif /* FEAT_RIGHTLEFT */ | |
5407 | |
5408 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5409 | |
5410 while (col < endcol) | |
5411 { | |
5412 #ifdef FEAT_MBYTE | |
5413 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5414 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5415 else |
5416 char_cells = 1; | |
5417 #endif | |
5418 | |
5419 redraw_this = redraw_next; | |
5420 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5421 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5422 | |
5423 #ifdef FEAT_GUI | |
5424 /* If the next character was bold, then redraw the current character to | |
5425 * remove any pixels that might have spilt over into us. This only | |
5426 * happens in the GUI. | |
5427 */ | |
5428 if (redraw_next && gui.in_use) | |
5429 { | |
5430 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5431 if (hl > HL_ALL) |
5432 hl = syn_attr2attr(hl); | |
5433 if (hl & HL_BOLD) | |
7 | 5434 redraw_this = TRUE; |
5435 } | |
5436 #endif | |
5437 | |
5438 if (redraw_this) | |
5439 { | |
5440 /* | |
5441 * Special handling when 'xs' termcap flag set (hpterm): | |
5442 * Attributes for characters are stored at the position where the | |
5443 * cursor is when writing the highlighting code. The | |
5444 * start-highlighting code must be written with the cursor on the | |
5445 * first highlighted character. The stop-highlighting code must | |
5446 * be written with the cursor just after the last highlighted | |
5447 * character. | |
5448 * Overwriting a character doesn't remove it's highlighting. Need | |
5449 * to clear the rest of the line, and force redrawing it | |
5450 * completely. | |
5451 */ | |
5452 if ( p_wiv | |
5453 && !force | |
5454 #ifdef FEAT_GUI | |
5455 && !gui.in_use | |
5456 #endif | |
5457 && ScreenAttrs[off_to] != 0 | |
5458 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5459 { | |
5460 /* | |
5461 * Need to remove highlighting attributes here. | |
5462 */ | |
5463 windgoto(row, col + coloff); | |
5464 out_str(T_CE); /* clear rest of this screen line */ | |
5465 screen_start(); /* don't know where cursor is now */ | |
5466 force = TRUE; /* force redraw of rest of the line */ | |
5467 redraw_next = TRUE; /* or else next char would miss out */ | |
5468 | |
5469 /* | |
5470 * If the previous character was highlighted, need to stop | |
5471 * highlighting at this character. | |
5472 */ | |
5473 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5474 { | |
5475 screen_attr = ScreenAttrs[off_to - 1]; | |
5476 term_windgoto(row, col + coloff); | |
5477 screen_stop_highlight(); | |
5478 } | |
5479 else | |
5480 screen_attr = 0; /* highlighting has stopped */ | |
5481 } | |
5482 #ifdef FEAT_MBYTE | |
5483 if (enc_dbcs != 0) | |
5484 { | |
5485 /* Check if overwriting a double-byte with a single-byte or | |
5486 * the other way around requires another character to be | |
5487 * redrawn. For UTF-8 this isn't needed, because comparing | |
5488 * ScreenLinesUC[] is sufficient. */ | |
5489 if (char_cells == 1 | |
5490 && col + 1 < endcol | |
1378 | 5491 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5492 { |
5493 /* Writing a single-cell character over a double-cell | |
5494 * character: need to redraw the next cell. */ | |
5495 ScreenLines[off_to + 1] = 0; | |
5496 redraw_next = TRUE; | |
5497 } | |
5498 else if (char_cells == 2 | |
5499 && col + 2 < endcol | |
1378 | 5500 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5501 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5502 { |
5503 /* Writing the second half of a double-cell character over | |
5504 * a double-cell character: need to redraw the second | |
5505 * cell. */ | |
5506 ScreenLines[off_to + 2] = 0; | |
5507 redraw_next = TRUE; | |
5508 } | |
5509 | |
5510 if (enc_dbcs == DBCS_JPNU) | |
5511 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5512 } | |
5513 /* When writing a single-width character over a double-width | |
5514 * character and at the end of the redrawn text, need to clear out | |
5515 * the right halve of the old character. | |
5516 * Also required when writing the right halve of a double-width | |
5517 * char over the left halve of an existing one. */ | |
5518 if (has_mbyte && col + char_cells == endcol | |
5519 && ((char_cells == 1 | |
1378 | 5520 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5521 || (char_cells == 2 |
1378 | 5522 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5523 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5524 clear_next = TRUE; |
5525 #endif | |
5526 | |
5527 ScreenLines[off_to] = ScreenLines[off_from]; | |
5528 #ifdef FEAT_MBYTE | |
5529 if (enc_utf8) | |
5530 { | |
5531 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5532 if (ScreenLinesUC[off_from] != 0) | |
5533 { | |
714 | 5534 int i; |
5535 | |
5536 for (i = 0; i < Screen_mco; ++i) | |
5537 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5538 } |
5539 } | |
5540 if (char_cells == 2) | |
5541 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5542 #endif | |
5543 | |
5544 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5545 /* The bold trick makes a single column of pixels appear in the |
5546 * next character. When a bold character is removed, the next | |
7 | 5547 * character should be redrawn too. This happens for our own GUI |
5548 * and for some xterms. */ | |
5549 if ( | |
5550 # ifdef FEAT_GUI | |
5551 gui.in_use | |
5552 # endif | |
5553 # if defined(FEAT_GUI) && defined(UNIX) | |
5554 || | |
5555 # endif | |
5556 # ifdef UNIX | |
5557 term_is_xterm | |
5558 # endif | |
5559 ) | |
5560 { | |
5561 hl = ScreenAttrs[off_to]; | |
743 | 5562 if (hl > HL_ALL) |
5563 hl = syn_attr2attr(hl); | |
5564 if (hl & HL_BOLD) | |
7 | 5565 redraw_next = TRUE; |
5566 } | |
5567 #endif | |
5568 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5569 #ifdef FEAT_MBYTE | |
819 | 5570 /* For simplicity set the attributes of second half of a |
5571 * double-wide character equal to the first half. */ | |
5572 if (char_cells == 2) | |
5573 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5574 | |
7 | 5575 if (enc_dbcs != 0 && char_cells == 2) |
5576 screen_char_2(off_to, row, col + coloff); | |
5577 else | |
5578 #endif | |
5579 screen_char(off_to, row, col + coloff); | |
5580 } | |
5581 else if ( p_wiv | |
5582 #ifdef FEAT_GUI | |
5583 && !gui.in_use | |
5584 #endif | |
5585 && col + coloff > 0) | |
5586 { | |
5587 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5588 { | |
5589 /* | |
5590 * Don't output stop-highlight when moving the cursor, it will | |
5591 * stop the highlighting when it should continue. | |
5592 */ | |
5593 screen_attr = 0; | |
5594 } | |
5595 else if (screen_attr != 0) | |
5596 screen_stop_highlight(); | |
5597 } | |
5598 | |
5599 off_to += CHAR_CELLS; | |
5600 off_from += CHAR_CELLS; | |
5601 col += CHAR_CELLS; | |
5602 } | |
5603 | |
5604 #ifdef FEAT_MBYTE | |
5605 if (clear_next) | |
5606 { | |
5607 /* Clear the second half of a double-wide character of which the left | |
5608 * half was overwritten with a single-wide character. */ | |
5609 ScreenLines[off_to] = ' '; | |
5610 if (enc_utf8) | |
5611 ScreenLinesUC[off_to] = 0; | |
5612 screen_char(off_to, row, col + coloff); | |
5613 } | |
5614 #endif | |
5615 | |
5616 if (clear_width > 0 | |
5617 #ifdef FEAT_RIGHTLEFT | |
5618 && !rlflag | |
5619 #endif | |
5620 ) | |
5621 { | |
5622 #ifdef FEAT_GUI | |
5623 int startCol = col; | |
5624 #endif | |
5625 | |
5626 /* blank out the rest of the line */ | |
5627 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5628 && ScreenAttrs[off_to] == 0 | |
5629 #ifdef FEAT_MBYTE | |
5630 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5631 #endif | |
5632 ) | |
5633 { | |
5634 ++off_to; | |
5635 ++col; | |
5636 } | |
5637 if (col < clear_width) | |
5638 { | |
5639 #ifdef FEAT_GUI | |
5640 /* | |
5641 * In the GUI, clearing the rest of the line may leave pixels | |
5642 * behind if the first character cleared was bold. Some bold | |
5643 * fonts spill over the left. In this case we redraw the previous | |
5644 * character too. If we didn't skip any blanks above, then we | |
5645 * only redraw if the character wasn't already redrawn anyway. | |
5646 */ | |
996 | 5647 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5648 { |
5649 hl = ScreenAttrs[off_to]; | |
5650 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5651 { |
5652 int prev_cells = 1; | |
5653 # ifdef FEAT_MBYTE | |
5654 if (enc_utf8) | |
5655 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5656 * that its width is 2. */ | |
5657 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5658 else if (enc_dbcs != 0) | |
5659 { | |
5660 /* find previous character by counting from first | |
5661 * column and get its width. */ | |
5662 unsigned off = LineOffset[row]; | |
1378 | 5663 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5664 |
5665 while (off < off_to) | |
5666 { | |
1378 | 5667 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5668 off += prev_cells; |
5669 } | |
5670 } | |
5671 | |
5672 if (enc_dbcs != 0 && prev_cells > 1) | |
5673 screen_char_2(off_to - prev_cells, row, | |
5674 col + coloff - prev_cells); | |
5675 else | |
5676 # endif | |
5677 screen_char(off_to - prev_cells, row, | |
5678 col + coloff - prev_cells); | |
5679 } | |
7 | 5680 } |
5681 #endif | |
5682 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5683 ' ', ' ', 0); | |
5684 #ifdef FEAT_VERTSPLIT | |
5685 off_to += clear_width - col; | |
5686 col = clear_width; | |
5687 #endif | |
5688 } | |
5689 } | |
5690 | |
5691 if (clear_width > 0) | |
5692 { | |
5693 #ifdef FEAT_VERTSPLIT | |
5694 /* For a window that's left of another, draw the separator char. */ | |
5695 if (col + coloff < Columns) | |
5696 { | |
5697 int c; | |
5698 | |
5699 c = fillchar_vsep(&hl); | |
5700 if (ScreenLines[off_to] != c | |
5701 # ifdef FEAT_MBYTE | |
714 | 5702 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5703 != (c >= 0x80 ? c : 0)) | |
7 | 5704 # endif |
5705 || ScreenAttrs[off_to] != hl) | |
5706 { | |
5707 ScreenLines[off_to] = c; | |
5708 ScreenAttrs[off_to] = hl; | |
5709 # ifdef FEAT_MBYTE | |
5710 if (enc_utf8) | |
5711 { | |
5712 if (c >= 0x80) | |
5713 { | |
5714 ScreenLinesUC[off_to] = c; | |
714 | 5715 ScreenLinesC[0][off_to] = 0; |
7 | 5716 } |
5717 else | |
5718 ScreenLinesUC[off_to] = 0; | |
5719 } | |
5720 # endif | |
5721 screen_char(off_to, row, col + coloff); | |
5722 } | |
5723 } | |
5724 else | |
5725 #endif | |
5726 LineWraps[row] = FALSE; | |
5727 } | |
5728 } | |
5729 | |
474 | 5730 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5731 /* |
474 | 5732 * Mirror text "str" for right-left displaying. |
5733 * Only works for single-byte characters (e.g., numbers). | |
7 | 5734 */ |
474 | 5735 void |
7 | 5736 rl_mirror(str) |
5737 char_u *str; | |
5738 { | |
5739 char_u *p1, *p2; | |
5740 int t; | |
5741 | |
5742 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5743 { | |
5744 t = *p1; | |
5745 *p1 = *p2; | |
5746 *p2 = t; | |
5747 } | |
5748 } | |
5749 #endif | |
5750 | |
5751 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5752 /* | |
5753 * mark all status lines for redraw; used after first :cd | |
5754 */ | |
5755 void | |
5756 status_redraw_all() | |
5757 { | |
5758 win_T *wp; | |
5759 | |
5760 for (wp = firstwin; wp; wp = wp->w_next) | |
5761 if (wp->w_status_height) | |
5762 { | |
5763 wp->w_redr_status = TRUE; | |
5764 redraw_later(VALID); | |
5765 } | |
5766 } | |
5767 | |
5768 /* | |
5769 * mark all status lines of the current buffer for redraw | |
5770 */ | |
5771 void | |
5772 status_redraw_curbuf() | |
5773 { | |
5774 win_T *wp; | |
5775 | |
5776 for (wp = firstwin; wp; wp = wp->w_next) | |
5777 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5778 { | |
5779 wp->w_redr_status = TRUE; | |
5780 redraw_later(VALID); | |
5781 } | |
5782 } | |
5783 | |
5784 /* | |
5785 * Redraw all status lines that need to be redrawn. | |
5786 */ | |
5787 void | |
5788 redraw_statuslines() | |
5789 { | |
5790 win_T *wp; | |
5791 | |
5792 for (wp = firstwin; wp; wp = wp->w_next) | |
5793 if (wp->w_redr_status) | |
5794 win_redr_status(wp); | |
673 | 5795 if (redraw_tabline) |
677 | 5796 draw_tabline(); |
7 | 5797 } |
5798 #endif | |
5799 | |
5800 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5801 /* | |
5802 * Redraw all status lines at the bottom of frame "frp". | |
5803 */ | |
5804 void | |
5805 win_redraw_last_status(frp) | |
5806 frame_T *frp; | |
5807 { | |
5808 if (frp->fr_layout == FR_LEAF) | |
5809 frp->fr_win->w_redr_status = TRUE; | |
5810 else if (frp->fr_layout == FR_ROW) | |
5811 { | |
5812 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5813 win_redraw_last_status(frp); | |
5814 } | |
5815 else /* frp->fr_layout == FR_COL */ | |
5816 { | |
5817 frp = frp->fr_child; | |
5818 while (frp->fr_next != NULL) | |
5819 frp = frp->fr_next; | |
5820 win_redraw_last_status(frp); | |
5821 } | |
5822 } | |
5823 #endif | |
5824 | |
5825 #ifdef FEAT_VERTSPLIT | |
5826 /* | |
5827 * Draw the verticap separator right of window "wp" starting with line "row". | |
5828 */ | |
5829 static void | |
5830 draw_vsep_win(wp, row) | |
5831 win_T *wp; | |
5832 int row; | |
5833 { | |
5834 int hl; | |
5835 int c; | |
5836 | |
5837 if (wp->w_vsep_width) | |
5838 { | |
5839 /* draw the vertical separator right of this window */ | |
5840 c = fillchar_vsep(&hl); | |
5841 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5842 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5843 c, ' ', hl); | |
5844 } | |
5845 } | |
5846 #endif | |
5847 | |
5848 #ifdef FEAT_WILDMENU | |
5849 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5850 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5851 |
5852 /* | |
1378 | 5853 * Get the length of an item as it will be shown in the status line. |
7 | 5854 */ |
5855 static int | |
5856 status_match_len(xp, s) | |
5857 expand_T *xp; | |
5858 char_u *s; | |
5859 { | |
5860 int len = 0; | |
5861 | |
5862 #ifdef FEAT_MENU | |
5863 int emenu = (xp->xp_context == EXPAND_MENUS | |
5864 || xp->xp_context == EXPAND_MENUNAMES); | |
5865 | |
5866 /* Check for menu separators - replace with '|'. */ | |
5867 if (emenu && menu_is_separator(s)) | |
5868 return 1; | |
5869 #endif | |
5870 | |
5871 while (*s != NUL) | |
5872 { | |
1685 | 5873 s += skip_status_match_char(xp, s); |
42 | 5874 len += ptr2cells(s); |
39 | 5875 mb_ptr_adv(s); |
7 | 5876 } |
5877 | |
5878 return len; | |
5879 } | |
5880 | |
5881 /* | |
1685 | 5882 * Return the number of characters that should be skipped in a status match. |
277 | 5883 * These are backslashes used for escaping. Do show backslashes in help tags. |
5884 */ | |
5885 static int | |
5886 skip_status_match_char(xp, s) | |
5887 expand_T *xp; | |
5888 char_u *s; | |
5889 { | |
1685 | 5890 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5891 #ifdef FEAT_MENU |
5892 || ((xp->xp_context == EXPAND_MENUS | |
5893 || xp->xp_context == EXPAND_MENUNAMES) | |
5894 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5895 #endif | |
1685 | 5896 ) |
5897 { | |
5898 #ifndef BACKSLASH_IN_FILENAME | |
5899 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5900 return 2; | |
5901 #endif | |
5902 return 1; | |
5903 } | |
5904 return 0; | |
277 | 5905 } |
5906 | |
5907 /* | |
7 | 5908 * Show wildchar matches in the status line. |
5909 * Show at least the "match" item. | |
5910 * We start at item 'first_match' in the list and show all matches that fit. | |
5911 * | |
5912 * If inversion is possible we use it. Else '=' characters are used. | |
5913 */ | |
5914 void | |
5915 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5916 expand_T *xp; | |
5917 int num_matches; | |
5918 char_u **matches; /* list of matches */ | |
5919 int match; | |
5920 int showtail; | |
5921 { | |
5922 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5923 int row; | |
5924 char_u *buf; | |
5925 int len; | |
1378 | 5926 int clen; /* length in screen cells */ |
7 | 5927 int fillchar; |
5928 int attr; | |
5929 int i; | |
5930 int highlight = TRUE; | |
5931 char_u *selstart = NULL; | |
5932 int selstart_col = 0; | |
5933 char_u *selend = NULL; | |
5934 static int first_match = 0; | |
5935 int add_left = FALSE; | |
5936 char_u *s; | |
5937 #ifdef FEAT_MENU | |
5938 int emenu; | |
5939 #endif | |
5940 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5941 int l; | |
5942 #endif | |
5943 | |
5944 if (matches == NULL) /* interrupted completion? */ | |
5945 return; | |
5946 | |
39 | 5947 #ifdef FEAT_MBYTE |
5948 if (has_mbyte) | |
5949 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5950 else | |
5951 #endif | |
5952 buf = alloc((unsigned)Columns + 1); | |
7 | 5953 if (buf == NULL) |
5954 return; | |
5955 | |
5956 if (match == -1) /* don't show match but original text */ | |
5957 { | |
5958 match = 0; | |
5959 highlight = FALSE; | |
5960 } | |
5961 /* count 1 for the ending ">" */ | |
5962 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5963 if (match == 0) | |
5964 first_match = 0; | |
5965 else if (match < first_match) | |
5966 { | |
5967 /* jumping left, as far as we can go */ | |
5968 first_match = match; | |
5969 add_left = TRUE; | |
5970 } | |
5971 else | |
5972 { | |
5973 /* check if match fits on the screen */ | |
5974 for (i = first_match; i < match; ++i) | |
5975 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5976 if (first_match > 0) | |
5977 clen += 2; | |
5978 /* jumping right, put match at the left */ | |
5979 if ((long)clen > Columns) | |
5980 { | |
5981 first_match = match; | |
5982 /* if showing the last match, we can add some on the left */ | |
5983 clen = 2; | |
5984 for (i = match; i < num_matches; ++i) | |
5985 { | |
5986 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5987 if ((long)clen >= Columns) | |
5988 break; | |
5989 } | |
5990 if (i == num_matches) | |
5991 add_left = TRUE; | |
5992 } | |
5993 } | |
5994 if (add_left) | |
5995 while (first_match > 0) | |
5996 { | |
5997 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5998 if ((long)clen >= Columns) | |
5999 break; | |
6000 --first_match; | |
6001 } | |
6002 | |
6003 fillchar = fillchar_status(&attr, TRUE); | |
6004 | |
6005 if (first_match == 0) | |
6006 { | |
6007 *buf = NUL; | |
6008 len = 0; | |
6009 } | |
6010 else | |
6011 { | |
6012 STRCPY(buf, "< "); | |
6013 len = 2; | |
6014 } | |
6015 clen = len; | |
6016 | |
6017 i = first_match; | |
6018 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
6019 { | |
6020 if (i == match) | |
6021 { | |
6022 selstart = buf + len; | |
6023 selstart_col = clen; | |
6024 } | |
6025 | |
6026 s = L_MATCH(i); | |
6027 /* Check for menu separators - replace with '|' */ | |
6028 #ifdef FEAT_MENU | |
6029 emenu = (xp->xp_context == EXPAND_MENUS | |
6030 || xp->xp_context == EXPAND_MENUNAMES); | |
6031 if (emenu && menu_is_separator(s)) | |
6032 { | |
6033 STRCPY(buf + len, transchar('|')); | |
6034 l = (int)STRLEN(buf + len); | |
6035 len += l; | |
6036 clen += l; | |
6037 } | |
6038 else | |
6039 #endif | |
6040 for ( ; *s != NUL; ++s) | |
6041 { | |
1685 | 6042 s += skip_status_match_char(xp, s); |
7 | 6043 clen += ptr2cells(s); |
6044 #ifdef FEAT_MBYTE | |
474 | 6045 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 6046 { |
6047 STRNCPY(buf + len, s, l); | |
6048 s += l - 1; | |
6049 len += l; | |
6050 } | |
6051 else | |
6052 #endif | |
6053 { | |
6054 STRCPY(buf + len, transchar_byte(*s)); | |
6055 len += (int)STRLEN(buf + len); | |
6056 } | |
6057 } | |
6058 if (i == match) | |
6059 selend = buf + len; | |
6060 | |
6061 *(buf + len++) = ' '; | |
6062 *(buf + len++) = ' '; | |
6063 clen += 2; | |
6064 if (++i == num_matches) | |
6065 break; | |
6066 } | |
6067 | |
6068 if (i != num_matches) | |
6069 { | |
6070 *(buf + len++) = '>'; | |
6071 ++clen; | |
6072 } | |
6073 | |
6074 buf[len] = NUL; | |
6075 | |
6076 row = cmdline_row - 1; | |
6077 if (row >= 0) | |
6078 { | |
6079 if (wild_menu_showing == 0) | |
6080 { | |
6081 if (msg_scrolled > 0) | |
6082 { | |
6083 /* Put the wildmenu just above the command line. If there is | |
6084 * no room, scroll the screen one line up. */ | |
6085 if (cmdline_row == Rows - 1) | |
6086 { | |
6087 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6088 ++msg_scrolled; | |
6089 } | |
6090 else | |
6091 { | |
6092 ++cmdline_row; | |
6093 ++row; | |
6094 } | |
6095 wild_menu_showing = WM_SCROLLED; | |
6096 } | |
6097 else | |
6098 { | |
6099 /* Create status line if needed by setting 'laststatus' to 2. | |
6100 * Set 'winminheight' to zero to avoid that the window is | |
6101 * resized. */ | |
6102 if (lastwin->w_status_height == 0) | |
6103 { | |
6104 save_p_ls = p_ls; | |
6105 save_p_wmh = p_wmh; | |
6106 p_ls = 2; | |
6107 p_wmh = 0; | |
6108 last_status(FALSE); | |
6109 } | |
6110 wild_menu_showing = WM_SHOWN; | |
6111 } | |
6112 } | |
6113 | |
6114 screen_puts(buf, row, 0, attr); | |
6115 if (selstart != NULL && highlight) | |
6116 { | |
6117 *selend = NUL; | |
6118 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6119 } | |
6120 | |
6121 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6122 } | |
6123 | |
6124 #ifdef FEAT_VERTSPLIT | |
6125 win_redraw_last_status(topframe); | |
6126 #else | |
6127 lastwin->w_redr_status = TRUE; | |
6128 #endif | |
6129 vim_free(buf); | |
6130 } | |
6131 #endif | |
6132 | |
6133 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6134 /* | |
6135 * Redraw the status line of window wp. | |
6136 * | |
6137 * If inversion is possible we use it. Else '=' characters are used. | |
6138 */ | |
6139 void | |
6140 win_redr_status(wp) | |
6141 win_T *wp; | |
6142 { | |
6143 int row; | |
6144 char_u *p; | |
6145 int len; | |
6146 int fillchar; | |
6147 int attr; | |
6148 int this_ru_col; | |
1910 | 6149 static int busy = FALSE; |
6150 | |
6151 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6152 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6153 if (busy) | |
6154 return; | |
6155 busy = TRUE; | |
7 | 6156 |
6157 wp->w_redr_status = FALSE; | |
6158 if (wp->w_status_height == 0) | |
6159 { | |
6160 /* no status line, can only be last window */ | |
6161 redraw_cmdline = TRUE; | |
6162 } | |
540 | 6163 else if (!redrawing() |
6164 #ifdef FEAT_INS_EXPAND | |
6165 /* don't update status line when popup menu is visible and may be | |
6166 * drawn over it */ | |
6167 || pum_visible() | |
6168 #endif | |
6169 ) | |
7 | 6170 { |
6171 /* Don't redraw right now, do it later. */ | |
6172 wp->w_redr_status = TRUE; | |
6173 } | |
6174 #ifdef FEAT_STL_OPT | |
40 | 6175 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6176 { |
6177 /* redraw custom status line */ | |
1983 | 6178 redraw_custom_statusline(wp); |
7 | 6179 } |
6180 #endif | |
6181 else | |
6182 { | |
6183 fillchar = fillchar_status(&attr, wp == curwin); | |
6184 | |
685 | 6185 get_trans_bufname(wp->w_buffer); |
7 | 6186 p = NameBuff; |
6187 len = (int)STRLEN(p); | |
6188 | |
6189 if (wp->w_buffer->b_help | |
6190 #ifdef FEAT_QUICKFIX | |
6191 || wp->w_p_pvw | |
6192 #endif | |
6193 || bufIsChanged(wp->w_buffer) | |
6194 || wp->w_buffer->b_p_ro) | |
6195 *(p + len++) = ' '; | |
6196 if (wp->w_buffer->b_help) | |
6197 { | |
809 | 6198 STRCPY(p + len, _("[Help]")); |
7 | 6199 len += (int)STRLEN(p + len); |
6200 } | |
6201 #ifdef FEAT_QUICKFIX | |
6202 if (wp->w_p_pvw) | |
6203 { | |
6204 STRCPY(p + len, _("[Preview]")); | |
6205 len += (int)STRLEN(p + len); | |
6206 } | |
6207 #endif | |
6208 if (bufIsChanged(wp->w_buffer)) | |
6209 { | |
6210 STRCPY(p + len, "[+]"); | |
6211 len += 3; | |
6212 } | |
6213 if (wp->w_buffer->b_p_ro) | |
6214 { | |
6215 STRCPY(p + len, "[RO]"); | |
6216 len += 4; | |
6217 } | |
6218 | |
6219 #ifndef FEAT_VERTSPLIT | |
6220 this_ru_col = ru_col; | |
6221 if (this_ru_col < (Columns + 1) / 2) | |
6222 this_ru_col = (Columns + 1) / 2; | |
6223 #else | |
6224 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6225 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6226 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6227 if (this_ru_col <= 1) | |
6228 { | |
6229 p = (char_u *)"<"; /* No room for file name! */ | |
6230 len = 1; | |
6231 } | |
6232 else | |
6233 #endif | |
6234 #ifdef FEAT_MBYTE | |
6235 if (has_mbyte) | |
6236 { | |
6237 int clen = 0, i; | |
6238 | |
6239 /* Count total number of display cells. */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6240 clen = mb_string2cells(p, -1); |
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2332
diff
changeset
|
6241 |
7 | 6242 /* Find first character that will fit. |
6243 * Going from start to end is much faster for DBCS. */ | |
6244 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6245 i += (*mb_ptr2len)(p + i)) |
7 | 6246 clen -= (*mb_ptr2cells)(p + i); |
6247 len = clen; | |
6248 if (i > 0) | |
6249 { | |
6250 p = p + i - 1; | |
6251 *p = '<'; | |
6252 ++len; | |
6253 } | |
6254 | |
6255 } | |
6256 else | |
6257 #endif | |
6258 if (len > this_ru_col - 1) | |
6259 { | |
6260 p += len - (this_ru_col - 1); | |
6261 *p = '<'; | |
6262 len = this_ru_col - 1; | |
6263 } | |
6264 | |
6265 row = W_WINROW(wp) + wp->w_height; | |
6266 screen_puts(p, row, W_WINCOL(wp), attr); | |
6267 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6268 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6269 | |
6270 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6271 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6272 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6273 - 1 + W_WINCOL(wp)), attr); | |
6274 | |
6275 #ifdef FEAT_CMDL_INFO | |
6276 win_redr_ruler(wp, TRUE); | |
6277 #endif | |
6278 } | |
6279 | |
6280 #ifdef FEAT_VERTSPLIT | |
6281 /* | |
6282 * May need to draw the character below the vertical separator. | |
6283 */ | |
6284 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6285 { | |
6286 if (stl_connected(wp)) | |
6287 fillchar = fillchar_status(&attr, wp == curwin); | |
6288 else | |
6289 fillchar = fillchar_vsep(&attr); | |
6290 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6291 attr); | |
6292 } | |
6293 #endif | |
1910 | 6294 busy = FALSE; |
7 | 6295 } |
6296 | |
680 | 6297 #ifdef FEAT_STL_OPT |
6298 /* | |
6299 * Redraw the status line according to 'statusline' and take care of any | |
6300 * errors encountered. | |
6301 */ | |
6302 static void | |
1983 | 6303 redraw_custom_statusline(wp) |
680 | 6304 win_T *wp; |
6305 { | |
1983 | 6306 static int entered = FALSE; |
6307 int save_called_emsg = called_emsg; | |
6308 | |
6309 /* When called recursively return. This can happen when the statusline | |
6310 * contains an expression that triggers a redraw. */ | |
6311 if (entered) | |
6312 return; | |
6313 entered = TRUE; | |
680 | 6314 |
6315 called_emsg = FALSE; | |
6316 win_redr_custom(wp, FALSE); | |
6317 if (called_emsg) | |
1983 | 6318 { |
6319 /* When there is an error disable the statusline, otherwise the | |
6320 * display is messed up with errors and a redraw triggers the problem | |
6321 * again and again. */ | |
680 | 6322 set_string_option_direct((char_u *)"statusline", -1, |
6323 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6324 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6325 } |
680 | 6326 called_emsg |= save_called_emsg; |
1983 | 6327 entered = FALSE; |
680 | 6328 } |
6329 #endif | |
6330 | |
7 | 6331 # ifdef FEAT_VERTSPLIT |
6332 /* | |
6333 * Return TRUE if the status line of window "wp" is connected to the status | |
6334 * line of the window right of it. If not, then it's a vertical separator. | |
6335 * Only call if (wp->w_vsep_width != 0). | |
6336 */ | |
6337 int | |
6338 stl_connected(wp) | |
6339 win_T *wp; | |
6340 { | |
6341 frame_T *fr; | |
6342 | |
6343 fr = wp->w_frame; | |
6344 while (fr->fr_parent != NULL) | |
6345 { | |
6346 if (fr->fr_parent->fr_layout == FR_COL) | |
6347 { | |
6348 if (fr->fr_next != NULL) | |
6349 break; | |
6350 } | |
6351 else | |
6352 { | |
6353 if (fr->fr_next != NULL) | |
6354 return TRUE; | |
6355 } | |
6356 fr = fr->fr_parent; | |
6357 } | |
6358 return FALSE; | |
6359 } | |
6360 # endif | |
6361 | |
6362 #endif /* FEAT_WINDOWS */ | |
6363 | |
6364 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6365 /* | |
6366 * Get the value to show for the language mappings, active 'keymap'. | |
6367 */ | |
6368 int | |
6369 get_keymap_str(wp, buf, len) | |
6370 win_T *wp; | |
6371 char_u *buf; /* buffer for the result */ | |
6372 int len; /* length of buffer */ | |
6373 { | |
6374 char_u *p; | |
6375 | |
6376 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6377 return FALSE; | |
6378 | |
6379 { | |
6380 #ifdef FEAT_EVAL | |
6381 buf_T *old_curbuf = curbuf; | |
6382 win_T *old_curwin = curwin; | |
6383 char_u *s; | |
6384 | |
6385 curbuf = wp->w_buffer; | |
6386 curwin = wp; | |
6387 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6388 ++emsg_skip; | |
714 | 6389 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6390 --emsg_skip; |
6391 curbuf = old_curbuf; | |
6392 curwin = old_curwin; | |
6393 if (p == NULL || *p == NUL) | |
6394 #endif | |
6395 { | |
6396 #ifdef FEAT_KEYMAP | |
6397 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6398 p = wp->w_buffer->b_p_keymap; | |
6399 else | |
6400 #endif | |
6401 p = (char_u *)"lang"; | |
6402 } | |
6403 if ((int)(STRLEN(p) + 3) < len) | |
6404 sprintf((char *)buf, "<%s>", p); | |
6405 else | |
6406 buf[0] = NUL; | |
6407 #ifdef FEAT_EVAL | |
6408 vim_free(s); | |
6409 #endif | |
6410 } | |
6411 return buf[0] != NUL; | |
6412 } | |
6413 #endif | |
6414 | |
6415 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6416 /* | |
677 | 6417 * Redraw the status line or ruler of window "wp". |
6418 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6419 */ |
6420 static void | |
574 | 6421 win_redr_custom(wp, draw_ruler) |
7 | 6422 win_T *wp; |
574 | 6423 int draw_ruler; /* TRUE or FALSE */ |
7 | 6424 { |
6425 int attr; | |
6426 int curattr; | |
6427 int row; | |
6428 int col = 0; | |
6429 int maxwidth; | |
6430 int width; | |
6431 int n; | |
6432 int len; | |
6433 int fillchar; | |
6434 char_u buf[MAXPATHL]; | |
1983 | 6435 char_u *stl; |
7 | 6436 char_u *p; |
681 | 6437 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6438 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6439 int use_sandbox = FALSE; |
2693 | 6440 win_T *ewp; |
6441 int p_crb_save; | |
7 | 6442 |
6443 /* setup environment for the task at hand */ | |
677 | 6444 if (wp == NULL) |
6445 { | |
6446 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6447 stl = p_tal; |
677 | 6448 row = 0; |
707 | 6449 fillchar = ' '; |
677 | 6450 attr = hl_attr(HLF_TPF); |
6451 maxwidth = Columns; | |
6452 # ifdef FEAT_EVAL | |
681 | 6453 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6454 # endif |
6455 } | |
40 | 6456 else |
677 | 6457 { |
6458 row = W_WINROW(wp) + wp->w_height; | |
6459 fillchar = fillchar_status(&attr, wp == curwin); | |
6460 maxwidth = W_WIDTH(wp); | |
6461 | |
6462 if (draw_ruler) | |
6463 { | |
1983 | 6464 stl = p_ruf; |
677 | 6465 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6466 if (*stl == '%') |
6467 { | |
6468 if (*++stl == '-') | |
6469 stl++; | |
6470 if (atoi((char *)stl)) | |
6471 while (VIM_ISDIGIT(*stl)) | |
6472 stl++; | |
6473 if (*stl++ != '(') | |
6474 stl = p_ruf; | |
677 | 6475 } |
7 | 6476 #ifdef FEAT_VERTSPLIT |
677 | 6477 col = ru_col - (Columns - W_WIDTH(wp)); |
6478 if (col < (W_WIDTH(wp) + 1) / 2) | |
6479 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6480 #else |
677 | 6481 col = ru_col; |
6482 if (col > (Columns + 1) / 2) | |
6483 col = (Columns + 1) / 2; | |
6484 #endif | |
6485 maxwidth = W_WIDTH(wp) - col; | |
7 | 6486 #ifdef FEAT_WINDOWS |
677 | 6487 if (!wp->w_status_height) |
6488 #endif | |
6489 { | |
6490 row = Rows - 1; | |
6491 --maxwidth; /* writing in last column may cause scrolling */ | |
6492 fillchar = ' '; | |
6493 attr = 0; | |
6494 } | |
6495 | |
6496 # ifdef FEAT_EVAL | |
681 | 6497 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6498 # endif |
6499 } | |
6500 else | |
6501 { | |
6502 if (*wp->w_p_stl != NUL) | |
1983 | 6503 stl = wp->w_p_stl; |
677 | 6504 else |
1983 | 6505 stl = p_stl; |
677 | 6506 # ifdef FEAT_EVAL |
681 | 6507 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6508 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6509 # endif |
6510 } | |
6511 | |
6512 #ifdef FEAT_VERTSPLIT | |
6513 col += W_WINCOL(wp); | |
6514 #endif | |
6515 } | |
6516 | |
7 | 6517 if (maxwidth <= 0) |
6518 return; | |
677 | 6519 |
2693 | 6520 /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
6521 * the cursor away and back. */ | |
6522 ewp = wp == NULL ? curwin : wp; | |
6523 p_crb_save = ewp->w_p_crb; | |
6524 ewp->w_p_crb = FALSE; | |
6525 | |
1983 | 6526 /* Make a copy, because the statusline may include a function call that |
6527 * might change the option value and free the memory. */ | |
6528 stl = vim_strsave(stl); | |
2693 | 6529 width = build_stl_str_hl(ewp, buf, sizeof(buf), |
1983 | 6530 stl, use_sandbox, |
681 | 6531 fillchar, maxwidth, hltab, tabtab); |
1983 | 6532 vim_free(stl); |
2693 | 6533 ewp->w_p_crb = p_crb_save; |
2661 | 6534 |
6535 /* Make all characters printable. */ | |
6536 p = transstr(buf); | |
6537 if (p != NULL) | |
6538 { | |
6539 vim_strncpy(buf, p, sizeof(buf) - 1); | |
6540 vim_free(p); | |
6541 } | |
6542 | |
6543 /* fill up with "fillchar" */ | |
835 | 6544 len = (int)STRLEN(buf); |
1883 | 6545 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6546 { |
6547 #ifdef FEAT_MBYTE | |
6548 len += (*mb_char2bytes)(fillchar, buf + len); | |
6549 #else | |
6550 buf[len++] = fillchar; | |
6551 #endif | |
6552 ++width; | |
6553 } | |
6554 buf[len] = NUL; | |
6555 | |
681 | 6556 /* |
6557 * Draw each snippet with the specified highlighting. | |
6558 */ | |
7 | 6559 curattr = attr; |
6560 p = buf; | |
681 | 6561 for (n = 0; hltab[n].start != NULL; n++) |
6562 { | |
6563 len = (int)(hltab[n].start - p); | |
7 | 6564 screen_puts_len(p, len, row, col, curattr); |
6565 col += vim_strnsize(p, len); | |
681 | 6566 p = hltab[n].start; |
6567 | |
6568 if (hltab[n].userhl == 0) | |
7 | 6569 curattr = attr; |
681 | 6570 else if (hltab[n].userhl < 0) |
6571 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6572 #ifdef FEAT_WINDOWS |
680 | 6573 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6574 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6575 #endif |
6576 else | |
681 | 6577 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6578 } |
6579 screen_puts(p, row, col, curattr); | |
681 | 6580 |
6581 if (wp == NULL) | |
6582 { | |
6583 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6584 col = 0; | |
6585 len = 0; | |
6586 p = buf; | |
6587 fillchar = 0; | |
6588 for (n = 0; tabtab[n].start != NULL; n++) | |
6589 { | |
6590 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6591 while (col < len) | |
6592 TabPageIdxs[col++] = fillchar; | |
6593 p = tabtab[n].start; | |
6594 fillchar = tabtab[n].userhl; | |
6595 } | |
6596 while (col < Columns) | |
6597 TabPageIdxs[col++] = fillchar; | |
6598 } | |
7 | 6599 } |
6600 | |
6601 #endif /* FEAT_STL_OPT */ | |
6602 | |
6603 /* | |
6604 * Output a single character directly to the screen and update ScreenLines. | |
6605 */ | |
6606 void | |
6607 screen_putchar(c, row, col, attr) | |
6608 int c; | |
6609 int row, col; | |
6610 int attr; | |
6611 { | |
6612 #ifdef FEAT_MBYTE | |
6613 char_u buf[MB_MAXBYTES + 1]; | |
6614 | |
6615 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6616 #else | |
6617 char_u buf[2]; | |
6618 | |
6619 buf[0] = c; | |
6620 buf[1] = NUL; | |
6621 #endif | |
6622 screen_puts(buf, row, col, attr); | |
6623 } | |
6624 | |
6625 /* | |
6626 * Get a single character directly from ScreenLines into "bytes[]". | |
6627 * Also return its attribute in *attrp; | |
6628 */ | |
6629 void | |
6630 screen_getbytes(row, col, bytes, attrp) | |
6631 int row, col; | |
6632 char_u *bytes; | |
6633 int *attrp; | |
6634 { | |
6635 unsigned off; | |
6636 | |
6637 /* safety check */ | |
6638 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6639 { | |
6640 off = LineOffset[row] + col; | |
6641 *attrp = ScreenAttrs[off]; | |
6642 bytes[0] = ScreenLines[off]; | |
6643 bytes[1] = NUL; | |
6644 | |
6645 #ifdef FEAT_MBYTE | |
6646 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6647 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6648 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6649 { | |
6650 bytes[0] = ScreenLines[off]; | |
6651 bytes[1] = ScreenLines2[off]; | |
6652 bytes[2] = NUL; | |
6653 } | |
6654 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6655 { | |
6656 bytes[1] = ScreenLines[off + 1]; | |
6657 bytes[2] = NUL; | |
6658 } | |
6659 #endif | |
6660 } | |
6661 } | |
6662 | |
714 | 6663 #ifdef FEAT_MBYTE |
6664 static int screen_comp_differs __ARGS((int, int*)); | |
6665 | |
6666 /* | |
6667 * Return TRUE if composing characters for screen posn "off" differs from | |
6668 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6669 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6670 */ |
6671 static int | |
6672 screen_comp_differs(off, u8cc) | |
6673 int off; | |
6674 int *u8cc; | |
6675 { | |
6676 int i; | |
6677 | |
6678 for (i = 0; i < Screen_mco; ++i) | |
6679 { | |
6680 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6681 return TRUE; | |
6682 if (u8cc[i] == 0) | |
6683 break; | |
6684 } | |
6685 return FALSE; | |
6686 } | |
6687 #endif | |
6688 | |
7 | 6689 /* |
6690 * Put string '*text' on the screen at position 'row' and 'col', with | |
6691 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6692 * Note: only outputs within one row, message is truncated at screen boundary! | |
6693 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6694 */ | |
6695 void | |
6696 screen_puts(text, row, col, attr) | |
6697 char_u *text; | |
6698 int row; | |
6699 int col; | |
6700 int attr; | |
6701 { | |
6702 screen_puts_len(text, -1, row, col, attr); | |
6703 } | |
6704 | |
6705 /* | |
6706 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6707 * a NUL. | |
6708 */ | |
6709 void | |
6710 screen_puts_len(text, len, row, col, attr) | |
6711 char_u *text; | |
6712 int len; | |
6713 int row; | |
6714 int col; | |
6715 int attr; | |
6716 { | |
6717 unsigned off; | |
6718 char_u *ptr = text; | |
6719 int c; | |
6720 #ifdef FEAT_MBYTE | |
1378 | 6721 unsigned max_off; |
7 | 6722 int mbyte_blen = 1; |
6723 int mbyte_cells = 1; | |
6724 int u8c = 0; | |
714 | 6725 int u8cc[MAX_MCO]; |
7 | 6726 int clear_next_cell = FALSE; |
6727 # ifdef FEAT_ARABIC | |
6728 int prev_c = 0; /* previous Arabic character */ | |
714 | 6729 int pc, nc, nc1; |
6730 int pcc[MAX_MCO]; | |
7 | 6731 # endif |
6732 #endif | |
1843 | 6733 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6734 int force_redraw_this; | |
6735 int force_redraw_next = FALSE; | |
6736 #endif | |
6737 int need_redraw; | |
7 | 6738 |
6739 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6740 return; | |
1843 | 6741 off = LineOffset[row] + col; |
7 | 6742 |
1668 | 6743 #ifdef FEAT_MBYTE |
6744 /* When drawing over the right halve of a double-wide char clear out the | |
6745 * left halve. Only needed in a terminal. */ | |
1685 | 6746 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6747 # ifdef FEAT_GUI |
6748 && !gui.in_use | |
6749 # endif | |
6750 && mb_fix_col(col, row) != col) | |
1843 | 6751 { |
6752 ScreenLines[off - 1] = ' '; | |
6753 ScreenAttrs[off - 1] = 0; | |
6754 if (enc_utf8) | |
6755 { | |
6756 ScreenLinesUC[off - 1] = 0; | |
6757 ScreenLinesC[0][off - 1] = 0; | |
6758 } | |
6759 /* redraw the previous cell, make it empty */ | |
6760 screen_char(off - 1, row, col - 1); | |
6761 /* force the cell at "col" to be redrawn */ | |
6762 force_redraw_next = TRUE; | |
6763 } | |
6764 #endif | |
6765 | |
1378 | 6766 #ifdef FEAT_MBYTE |
6767 max_off = LineOffset[row] + screen_Columns; | |
6768 #endif | |
1340 | 6769 while (col < screen_Columns |
6770 && (len < 0 || (int)(ptr - text) < len) | |
6771 && *ptr != NUL) | |
7 | 6772 { |
6773 c = *ptr; | |
6774 #ifdef FEAT_MBYTE | |
6775 /* check if this is the first byte of a multibyte */ | |
6776 if (has_mbyte) | |
6777 { | |
6778 if (enc_utf8 && len > 0) | |
474 | 6779 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6780 else |
474 | 6781 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6782 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6783 mbyte_cells = 1; | |
6784 else if (enc_dbcs != 0) | |
6785 mbyte_cells = mbyte_blen; | |
6786 else /* enc_utf8 */ | |
6787 { | |
6788 if (len >= 0) | |
714 | 6789 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6790 (int)((text + len) - ptr)); |
6791 else | |
714 | 6792 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6793 mbyte_cells = utf_char2cells(u8c); |
1401 | 6794 # ifdef UNICODE16 |
7 | 6795 /* Non-BMP character: display as ? or fullwidth ?. */ |
6796 if (u8c >= 0x10000) | |
6797 { | |
6798 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6799 if (attr == 0) | |
6800 attr = hl_attr(HLF_8); | |
6801 } | |
1401 | 6802 # endif |
7 | 6803 # ifdef FEAT_ARABIC |
6804 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6805 { | |
6806 /* Do Arabic shaping. */ | |
6807 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6808 { | |
6809 /* Past end of string to be displayed. */ | |
6810 nc = NUL; | |
6811 nc1 = NUL; | |
6812 } | |
6813 else | |
714 | 6814 { |
1994 | 6815 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6816 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6817 nc1 = pcc[0]; |
6818 } | |
7 | 6819 pc = prev_c; |
6820 prev_c = u8c; | |
714 | 6821 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6822 } |
6823 else | |
6824 prev_c = u8c; | |
6825 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6826 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6827 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6828 /* 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
|
6829 * 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
|
6830 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6831 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6832 } |
7 | 6833 } |
6834 } | |
6835 #endif | |
6836 | |
1843 | 6837 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6838 force_redraw_this = force_redraw_next; | |
6839 force_redraw_next = FALSE; | |
6840 #endif | |
6841 | |
6842 need_redraw = ScreenLines[off] != c | |
7 | 6843 #ifdef FEAT_MBYTE |
6844 || (mbyte_cells == 2 | |
6845 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6846 || (enc_dbcs == DBCS_JPNU | |
6847 && c == 0x8e | |
6848 && ScreenLines2[off] != ptr[1]) | |
6849 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6850 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6851 (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
|
6852 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6853 && screen_comp_differs(off, u8cc)))) |
7 | 6854 #endif |
6855 || ScreenAttrs[off] != attr | |
1843 | 6856 || exmode_active; |
6857 | |
6858 if (need_redraw | |
6859 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6860 || force_redraw_this | |
6861 #endif | |
7 | 6862 ) |
6863 { | |
6864 #if defined(FEAT_GUI) || defined(UNIX) | |
6865 /* The bold trick makes a single row of pixels appear in the next | |
6866 * character. When a bold character is removed, the next | |
6867 * character should be redrawn too. This happens for our own GUI | |
1843 | 6868 * and for some xterms. */ |
6869 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6870 # ifdef FEAT_GUI |
6871 gui.in_use | |
6872 # endif | |
6873 # if defined(FEAT_GUI) && defined(UNIX) | |
6874 || | |
6875 # endif | |
6876 # ifdef UNIX | |
6877 term_is_xterm | |
6878 # endif | |
1843 | 6879 )) |
6880 { | |
6881 int n = ScreenAttrs[off]; | |
6882 | |
6883 if (n > HL_ALL) | |
6884 n = syn_attr2attr(n); | |
6885 if (n & HL_BOLD) | |
6886 force_redraw_next = TRUE; | |
7 | 6887 } |
6888 #endif | |
6889 #ifdef FEAT_MBYTE | |
6890 /* When at the end of the text and overwriting a two-cell | |
6891 * character with a one-cell character, need to clear the next | |
6892 * cell. Also when overwriting the left halve of a two-cell char | |
6893 * with the right halve of a two-cell char. Do this only once | |
6894 * (mb_off2cells() may return 2 on the right halve). */ | |
6895 if (clear_next_cell) | |
6896 clear_next_cell = FALSE; | |
6897 else if (has_mbyte | |
6898 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6899 : ptr + mbyte_blen >= text + len) | |
1378 | 6900 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6901 || (mbyte_cells == 2 |
1378 | 6902 && (*mb_off2cells)(off, max_off) == 1 |
6903 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6904 clear_next_cell = TRUE; |
6905 | |
6906 /* Make sure we never leave a second byte of a double-byte behind, | |
6907 * it confuses mb_off2cells(). */ | |
6908 if (enc_dbcs | |
1378 | 6909 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6910 || (mbyte_cells == 2 |
1378 | 6911 && (*mb_off2cells)(off, max_off) == 1 |
6912 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6913 ScreenLines[off + mbyte_blen] = 0; |
6914 #endif | |
6915 ScreenLines[off] = c; | |
6916 ScreenAttrs[off] = attr; | |
6917 #ifdef FEAT_MBYTE | |
6918 if (enc_utf8) | |
6919 { | |
714 | 6920 if (c < 0x80 && u8cc[0] == 0) |
7 | 6921 ScreenLinesUC[off] = 0; |
6922 else | |
6923 { | |
714 | 6924 int i; |
6925 | |
7 | 6926 ScreenLinesUC[off] = u8c; |
714 | 6927 for (i = 0; i < Screen_mco; ++i) |
6928 { | |
6929 ScreenLinesC[i][off] = u8cc[i]; | |
6930 if (u8cc[i] == 0) | |
6931 break; | |
6932 } | |
7 | 6933 } |
6934 if (mbyte_cells == 2) | |
6935 { | |
6936 ScreenLines[off + 1] = 0; | |
6937 ScreenAttrs[off + 1] = attr; | |
6938 } | |
6939 screen_char(off, row, col); | |
6940 } | |
6941 else if (mbyte_cells == 2) | |
6942 { | |
6943 ScreenLines[off + 1] = ptr[1]; | |
6944 ScreenAttrs[off + 1] = attr; | |
6945 screen_char_2(off, row, col); | |
6946 } | |
6947 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6948 { | |
6949 ScreenLines2[off] = ptr[1]; | |
6950 screen_char(off, row, col); | |
6951 } | |
6952 else | |
6953 #endif | |
6954 screen_char(off, row, col); | |
6955 } | |
6956 #ifdef FEAT_MBYTE | |
6957 if (has_mbyte) | |
6958 { | |
6959 off += mbyte_cells; | |
6960 col += mbyte_cells; | |
6961 ptr += mbyte_blen; | |
6962 if (clear_next_cell) | |
6963 ptr = (char_u *)" "; | |
6964 } | |
6965 else | |
6966 #endif | |
6967 { | |
6968 ++off; | |
6969 ++col; | |
6970 ++ptr; | |
6971 } | |
6972 } | |
1843 | 6973 |
6974 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6975 /* If we detected the next character needs to be redrawn, but the text | |
6976 * doesn't extend up to there, update the character here. */ | |
6977 if (force_redraw_next && col < screen_Columns) | |
6978 { | |
6979 # ifdef FEAT_MBYTE | |
6980 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6981 screen_char_2(off, row, col); | |
6982 else | |
6983 # endif | |
6984 screen_char(off, row, col); | |
6985 } | |
6986 #endif | |
7 | 6987 } |
6988 | |
6989 #ifdef FEAT_SEARCH_EXTRA | |
6990 /* | |
1326 | 6991 * Prepare for 'hlsearch' highlighting. |
7 | 6992 */ |
6993 static void | |
6994 start_search_hl() | |
6995 { | |
6996 if (p_hls && !no_hlsearch) | |
6997 { | |
6998 last_pat_prog(&search_hl.rm); | |
6999 search_hl.attr = hl_attr(HLF_L); | |
1521 | 7000 # ifdef FEAT_RELTIME |
7001 /* Set the time limit to 'redrawtime'. */ | |
7002 profile_setlimit(p_rdt, &search_hl.tm); | |
7003 # endif | |
7 | 7004 } |
7005 } | |
7006 | |
7007 /* | |
1326 | 7008 * Clean up for 'hlsearch' highlighting. |
7 | 7009 */ |
7010 static void | |
7011 end_search_hl() | |
7012 { | |
7013 if (search_hl.rm.regprog != NULL) | |
7014 { | |
7015 vim_free(search_hl.rm.regprog); | |
7016 search_hl.rm.regprog = NULL; | |
7017 } | |
7018 } | |
7019 | |
7020 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7021 * 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
|
7022 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7023 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7024 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7025 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7026 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7027 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7028 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7029 /* 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
|
7030 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7031 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7032 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7033 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7034 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7035 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7036 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7037 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7038 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
|
7039 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
|
7040 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7041 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7042 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7043 /* 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
|
7044 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
|
7045 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7046 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7047 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7048 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
|
7049 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7050 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
7051 /* 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
|
7052 } |
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 /* |
7 | 7055 * Advance to the match in window "wp" line "lnum" or past it. |
7056 */ | |
7057 static void | |
7058 prepare_search_hl(wp, lnum) | |
7059 win_T *wp; | |
7060 linenr_T lnum; | |
7061 { | |
1326 | 7062 matchitem_T *cur; /* points to the match list */ |
7063 match_T *shl; /* points to search_hl or a match */ | |
7064 int shl_flag; /* flag to indicate whether search_hl | |
7065 has been processed or not */ | |
7 | 7066 int n; |
7067 | |
7068 /* | |
7069 * When using a multi-line pattern, start searching at the top | |
7070 * of the window or just after a closed fold. | |
1326 | 7071 * Do this both for search_hl and the match list. |
7 | 7072 */ |
1326 | 7073 cur = wp->w_match_head; |
7074 shl_flag = FALSE; | |
7075 while (cur != NULL || shl_flag == FALSE) | |
7076 { | |
7077 if (shl_flag == FALSE) | |
7078 { | |
7079 shl = &search_hl; | |
7080 shl_flag = TRUE; | |
7081 } | |
7082 else | |
7083 shl = &cur->hl; | |
7 | 7084 if (shl->rm.regprog != NULL |
7085 && shl->lnum == 0 | |
7086 && re_multiline(shl->rm.regprog)) | |
7087 { | |
7088 if (shl->first_lnum == 0) | |
7089 { | |
7090 # ifdef FEAT_FOLDING | |
7091 for (shl->first_lnum = lnum; | |
7092 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7093 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7094 NULL, NULL, TRUE, NULL)) | |
7095 break; | |
7096 # else | |
7097 shl->first_lnum = wp->w_topline; | |
7098 # endif | |
7099 } | |
7100 n = 0; | |
7101 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7102 { | |
7103 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7104 if (shl->lnum != 0) | |
7105 { | |
7106 shl->first_lnum = shl->lnum | |
7107 + shl->rm.endpos[0].lnum | |
7108 - shl->rm.startpos[0].lnum; | |
7109 n = shl->rm.endpos[0].col; | |
7110 } | |
7111 else | |
7112 { | |
7113 ++shl->first_lnum; | |
7114 n = 0; | |
7115 } | |
7116 } | |
7117 } | |
1326 | 7118 if (shl != &search_hl && cur != NULL) |
7119 cur = cur->next; | |
7 | 7120 } |
7121 } | |
7122 | |
7123 /* | |
1326 | 7124 * Search for a next 'hlsearch' or match. |
7 | 7125 * Uses shl->buf. |
7126 * Sets shl->lnum and shl->rm contents. | |
7127 * Note: Assumes a previous match is always before "lnum", unless | |
7128 * shl->lnum is zero. | |
7129 * Careful: Any pointers for buffer lines will become invalid. | |
7130 */ | |
7131 static void | |
7132 next_search_hl(win, shl, lnum, mincol) | |
7133 win_T *win; | |
1326 | 7134 match_T *shl; /* points to search_hl or a match */ |
7 | 7135 linenr_T lnum; |
7136 colnr_T mincol; /* minimal column for a match */ | |
7137 { | |
7138 linenr_T l; | |
7139 colnr_T matchcol; | |
7140 long nmatched; | |
7141 | |
7142 if (shl->lnum != 0) | |
7143 { | |
7144 /* Check for three situations: | |
7145 * 1. If the "lnum" is below a previous match, start a new search. | |
7146 * 2. If the previous match includes "mincol", use it. | |
7147 * 3. Continue after the previous match. | |
7148 */ | |
7149 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7150 if (lnum > l) | |
7151 shl->lnum = 0; | |
7152 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7153 return; | |
7154 } | |
7155 | |
7156 /* | |
7157 * Repeat searching for a match until one is found that includes "mincol" | |
7158 * or none is found in this line. | |
7159 */ | |
7160 called_emsg = FALSE; | |
7161 for (;;) | |
7162 { | |
1521 | 7163 #ifdef FEAT_RELTIME |
7164 /* Stop searching after passing the time limit. */ | |
7165 if (profile_passed_limit(&(shl->tm))) | |
7166 { | |
7167 shl->lnum = 0; /* no match found in time */ | |
7168 break; | |
7169 } | |
7170 #endif | |
7 | 7171 /* Three situations: |
7172 * 1. No useful previous match: search from start of line. | |
7173 * 2. Not Vi compatible or empty match: continue at next character. | |
7174 * Break the loop if this is beyond the end of the line. | |
7175 * 3. Vi compatible searching: continue at end of previous match. | |
7176 */ | |
7177 if (shl->lnum == 0) | |
7178 matchcol = 0; | |
7179 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7180 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7181 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7182 { | |
688 | 7183 char_u *ml; |
685 | 7184 |
7185 matchcol = shl->rm.startpos[0].col; | |
688 | 7186 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7187 if (*ml == NUL) |
7188 { | |
7189 ++matchcol; | |
7 | 7190 shl->lnum = 0; |
7191 break; | |
7192 } | |
685 | 7193 #ifdef FEAT_MBYTE |
7194 if (has_mbyte) | |
7195 matchcol += mb_ptr2len(ml); | |
7196 else | |
7197 #endif | |
7198 ++matchcol; | |
7 | 7199 } |
7200 else | |
7201 matchcol = shl->rm.endpos[0].col; | |
7202 | |
7203 shl->lnum = lnum; | |
1521 | 7204 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7205 #ifdef FEAT_RELTIME | |
7206 &(shl->tm) | |
7207 #else | |
7208 NULL | |
7209 #endif | |
7210 ); | |
2359
496feb41b83f
Fix: When 'searchhl' causes a hang make CTRL-C disable 'shearchhl'.
Bram Moolenaar <bram@vim.org>
parents:
2356
diff
changeset
|
7211 if (called_emsg || got_int) |
7 | 7212 { |
7213 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7214 if (shl == &search_hl) |
7215 { | |
1326 | 7216 /* don't free regprog in the match list, it's a copy */ |
1112 | 7217 vim_free(shl->rm.regprog); |
7218 no_hlsearch = TRUE; | |
7219 } | |
7 | 7220 shl->rm.regprog = NULL; |
1112 | 7221 shl->lnum = 0; |
7222 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7223 break; |
7224 } | |
7225 if (nmatched == 0) | |
7226 { | |
7227 shl->lnum = 0; /* no match found */ | |
7228 break; | |
7229 } | |
7230 if (shl->rm.startpos[0].lnum > 0 | |
7231 || shl->rm.startpos[0].col >= mincol | |
7232 || nmatched > 1 | |
7233 || shl->rm.endpos[0].col > mincol) | |
7234 { | |
7235 shl->lnum += shl->rm.startpos[0].lnum; | |
7236 break; /* useful match found */ | |
7237 } | |
7238 } | |
7239 } | |
7240 #endif | |
7241 | |
7242 static void | |
7243 screen_start_highlight(attr) | |
7244 int attr; | |
7245 { | |
7246 attrentry_T *aep = NULL; | |
7247 | |
7248 screen_attr = attr; | |
7249 if (full_screen | |
7250 #ifdef WIN3264 | |
7251 && termcap_active | |
7252 #endif | |
7253 ) | |
7254 { | |
7255 #ifdef FEAT_GUI | |
7256 if (gui.in_use) | |
7257 { | |
7258 char buf[20]; | |
7259 | |
681 | 7260 /* The GUI handles this internally. */ |
7261 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7262 OUT_STR(buf); |
7263 } | |
7264 else | |
7265 #endif | |
7266 { | |
7267 if (attr > HL_ALL) /* special HL attr. */ | |
7268 { | |
7269 if (t_colors > 1) | |
7270 aep = syn_cterm_attr2entry(attr); | |
7271 else | |
7272 aep = syn_term_attr2entry(attr); | |
7273 if (aep == NULL) /* did ":syntax clear" */ | |
7274 attr = 0; | |
7275 else | |
7276 attr = aep->ae_attr; | |
7277 } | |
7278 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7279 out_str(T_MD); | |
681 | 7280 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7281 && cterm_normal_fg_bold) | |
7282 /* If the Normal FG color has BOLD attribute and the new HL | |
7283 * has a FG color defined, clear BOLD. */ | |
7284 out_str(T_ME); | |
7 | 7285 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7286 out_str(T_SO); | |
205 | 7287 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7288 /* underline or undercurl */ | |
7 | 7289 out_str(T_US); |
7290 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7291 out_str(T_CZH); | |
7292 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7293 out_str(T_MR); | |
7294 | |
7295 /* | |
7296 * Output the color or start string after bold etc., in case the | |
7297 * bold etc. override the color setting. | |
7298 */ | |
7299 if (aep != NULL) | |
7300 { | |
7301 if (t_colors > 1) | |
7302 { | |
7303 if (aep->ae_u.cterm.fg_color) | |
7304 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7305 if (aep->ae_u.cterm.bg_color) | |
7306 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7307 } | |
7308 else | |
7309 { | |
7310 if (aep->ae_u.term.start != NULL) | |
7311 out_str(aep->ae_u.term.start); | |
7312 } | |
7313 } | |
7314 } | |
7315 } | |
7316 } | |
7317 | |
7318 void | |
7319 screen_stop_highlight() | |
7320 { | |
7321 int do_ME = FALSE; /* output T_ME code */ | |
7322 | |
7323 if (screen_attr != 0 | |
7324 #ifdef WIN3264 | |
7325 && termcap_active | |
7326 #endif | |
7327 ) | |
7328 { | |
7329 #ifdef FEAT_GUI | |
7330 if (gui.in_use) | |
7331 { | |
7332 char buf[20]; | |
7333 | |
7334 /* use internal GUI code */ | |
7335 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7336 OUT_STR(buf); | |
7337 } | |
7338 else | |
7339 #endif | |
7340 { | |
7341 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7342 { | |
7343 attrentry_T *aep; | |
7344 | |
7345 if (t_colors > 1) | |
7346 { | |
7347 /* | |
7348 * Assume that t_me restores the original colors! | |
7349 */ | |
7350 aep = syn_cterm_attr2entry(screen_attr); | |
7351 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7352 || aep->ae_u.cterm.bg_color)) | |
7353 do_ME = TRUE; | |
7354 } | |
7355 else | |
7356 { | |
7357 aep = syn_term_attr2entry(screen_attr); | |
7358 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7359 { | |
7360 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7361 do_ME = TRUE; | |
7362 else | |
7363 out_str(aep->ae_u.term.stop); | |
7364 } | |
7365 } | |
7366 if (aep == NULL) /* did ":syntax clear" */ | |
7367 screen_attr = 0; | |
7368 else | |
7369 screen_attr = aep->ae_attr; | |
7370 } | |
7371 | |
7372 /* | |
7373 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7374 * same sequence several times. | |
7375 */ | |
7376 if (screen_attr & HL_STANDOUT) | |
7377 { | |
7378 if (STRCMP(T_SE, T_ME) == 0) | |
7379 do_ME = TRUE; | |
7380 else | |
7381 out_str(T_SE); | |
7382 } | |
205 | 7383 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7384 { |
7385 if (STRCMP(T_UE, T_ME) == 0) | |
7386 do_ME = TRUE; | |
7387 else | |
7388 out_str(T_UE); | |
7389 } | |
7390 if (screen_attr & HL_ITALIC) | |
7391 { | |
7392 if (STRCMP(T_CZR, T_ME) == 0) | |
7393 do_ME = TRUE; | |
7394 else | |
7395 out_str(T_CZR); | |
7396 } | |
7397 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7398 out_str(T_ME); | |
7399 | |
7400 if (t_colors > 1) | |
7401 { | |
7402 /* set Normal cterm colors */ | |
7403 if (cterm_normal_fg_color != 0) | |
7404 term_fg_color(cterm_normal_fg_color - 1); | |
7405 if (cterm_normal_bg_color != 0) | |
7406 term_bg_color(cterm_normal_bg_color - 1); | |
7407 if (cterm_normal_fg_bold) | |
7408 out_str(T_MD); | |
7409 } | |
7410 } | |
7411 } | |
7412 screen_attr = 0; | |
7413 } | |
7414 | |
7415 /* | |
7416 * Reset the colors for a cterm. Used when leaving Vim. | |
7417 * The machine specific code may override this again. | |
7418 */ | |
7419 void | |
7420 reset_cterm_colors() | |
7421 { | |
7422 if (t_colors > 1) | |
7423 { | |
7424 /* set Normal cterm colors */ | |
7425 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7426 { | |
7427 out_str(T_OP); | |
7428 screen_attr = -1; | |
7429 } | |
7430 if (cterm_normal_fg_bold) | |
7431 { | |
7432 out_str(T_ME); | |
7433 screen_attr = -1; | |
7434 } | |
7435 } | |
7436 } | |
7437 | |
7438 /* | |
7439 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7440 * using the attributes from ScreenAttrs["off"]. | |
7441 */ | |
7442 static void | |
7443 screen_char(off, row, col) | |
7444 unsigned off; | |
7445 int row; | |
7446 int col; | |
7447 { | |
7448 int attr; | |
7449 | |
7450 /* Check for illegal values, just in case (could happen just after | |
7451 * resizing). */ | |
7452 if (row >= screen_Rows || col >= screen_Columns) | |
7453 return; | |
7454 | |
7455 /* Outputting the last character on the screen may scrollup the screen. | |
7456 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7457 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7458 #ifdef FEAT_RIGHTLEFT | |
7459 /* account for first command-line character in rightleft mode */ | |
7460 && !cmdmsg_rl | |
7461 #endif | |
7462 ) | |
7463 { | |
7464 ScreenAttrs[off] = (sattr_T)-1; | |
7465 return; | |
7466 } | |
7467 | |
7468 /* | |
7469 * Stop highlighting first, so it's easier to move the cursor. | |
7470 */ | |
7471 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7472 if (screen_char_attr != 0) | |
7473 attr = screen_char_attr; | |
7474 else | |
7475 #endif | |
7476 attr = ScreenAttrs[off]; | |
7477 if (screen_attr != attr) | |
7478 screen_stop_highlight(); | |
7479 | |
7480 windgoto(row, col); | |
7481 | |
7482 if (screen_attr != attr) | |
7483 screen_start_highlight(attr); | |
7484 | |
7485 #ifdef FEAT_MBYTE | |
7486 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7487 { | |
7488 char_u buf[MB_MAXBYTES + 1]; | |
7489 | |
7490 /* Convert UTF-8 character to bytes and write it. */ | |
7491 | |
7492 buf[utfc_char2bytes(off, buf)] = NUL; | |
7493 | |
7494 out_str(buf); | |
7495 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7496 ++screen_cur_col; | |
7497 } | |
7498 else | |
7499 #endif | |
7500 { | |
7501 #ifdef FEAT_MBYTE | |
7502 out_flush_check(); | |
7503 #endif | |
7504 out_char(ScreenLines[off]); | |
7505 #ifdef FEAT_MBYTE | |
7506 /* double-byte character in single-width cell */ | |
7507 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7508 out_char(ScreenLines2[off]); | |
7509 #endif | |
7510 } | |
7511 | |
7512 screen_cur_col++; | |
7513 } | |
7514 | |
7515 #ifdef FEAT_MBYTE | |
7516 | |
7517 /* | |
7518 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7519 * on the screen at position 'row' and 'col'. | |
7520 * The attributes of the first byte is used for all. This is required to | |
7521 * output the two bytes of a double-byte character with nothing in between. | |
7522 */ | |
7523 static void | |
7524 screen_char_2(off, row, col) | |
7525 unsigned off; | |
7526 int row; | |
7527 int col; | |
7528 { | |
7529 /* Check for illegal values (could be wrong when screen was resized). */ | |
7530 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7531 return; | |
7532 | |
7533 /* Outputting the last character on the screen may scrollup the screen. | |
7534 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7535 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7536 { | |
7537 ScreenAttrs[off] = (sattr_T)-1; | |
7538 return; | |
7539 } | |
7540 | |
7541 /* Output the first byte normally (positions the cursor), then write the | |
7542 * second byte directly. */ | |
7543 screen_char(off, row, col); | |
7544 out_char(ScreenLines[off + 1]); | |
7545 ++screen_cur_col; | |
7546 } | |
7547 #endif | |
7548 | |
7549 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7550 /* | |
7551 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7552 * This uses the contents of ScreenLines[] and doesn't change it. | |
7553 */ | |
7554 void | |
7555 screen_draw_rectangle(row, col, height, width, invert) | |
7556 int row; | |
7557 int col; | |
7558 int height; | |
7559 int width; | |
7560 int invert; | |
7561 { | |
7562 int r, c; | |
7563 int off; | |
1378 | 7564 #ifdef FEAT_MBYTE |
7565 int max_off; | |
7566 #endif | |
7 | 7567 |
534 | 7568 /* Can't use ScreenLines unless initialized */ |
7569 if (ScreenLines == NULL) | |
7570 return; | |
7571 | |
7 | 7572 if (invert) |
7573 screen_char_attr = HL_INVERSE; | |
7574 for (r = row; r < row + height; ++r) | |
7575 { | |
7576 off = LineOffset[r]; | |
1378 | 7577 #ifdef FEAT_MBYTE |
7578 max_off = off + screen_Columns; | |
7579 #endif | |
7 | 7580 for (c = col; c < col + width; ++c) |
7581 { | |
7582 #ifdef FEAT_MBYTE | |
1378 | 7583 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7584 { |
7585 screen_char_2(off + c, r, c); | |
7586 ++c; | |
7587 } | |
7588 else | |
7589 #endif | |
7590 { | |
7591 screen_char(off + c, r, c); | |
7592 #ifdef FEAT_MBYTE | |
1378 | 7593 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7594 ++c; |
7595 #endif | |
7596 } | |
7597 } | |
7598 } | |
7599 screen_char_attr = 0; | |
7600 } | |
7601 #endif | |
7602 | |
7603 #ifdef FEAT_VERTSPLIT | |
7604 /* | |
7605 * Redraw the characters for a vertically split window. | |
7606 */ | |
7607 static void | |
7608 redraw_block(row, end, wp) | |
7609 int row; | |
7610 int end; | |
7611 win_T *wp; | |
7612 { | |
7613 int col; | |
7614 int width; | |
7615 | |
7616 # ifdef FEAT_CLIPBOARD | |
7617 clip_may_clear_selection(row, end - 1); | |
7618 # endif | |
7619 | |
7620 if (wp == NULL) | |
7621 { | |
7622 col = 0; | |
7623 width = Columns; | |
7624 } | |
7625 else | |
7626 { | |
7627 col = wp->w_wincol; | |
7628 width = wp->w_width; | |
7629 } | |
7630 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7631 } | |
7632 #endif | |
7633 | |
7634 /* | |
7635 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7636 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7637 * Use attributes 'attr'. | |
7638 */ | |
7639 void | |
7640 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7641 int start_row, end_row; | |
7642 int start_col, end_col; | |
7643 int c1, c2; | |
7644 int attr; | |
7645 { | |
7646 int row; | |
7647 int col; | |
7648 int off; | |
7649 int end_off; | |
7650 int did_delete; | |
7651 int c; | |
7652 int norm_term; | |
7653 #if defined(FEAT_GUI) || defined(UNIX) | |
7654 int force_next = FALSE; | |
7655 #endif | |
7656 | |
7657 if (end_row > screen_Rows) /* safety check */ | |
7658 end_row = screen_Rows; | |
7659 if (end_col > screen_Columns) /* safety check */ | |
7660 end_col = screen_Columns; | |
7661 if (ScreenLines == NULL | |
7662 || start_row >= end_row | |
7663 || start_col >= end_col) /* nothing to do */ | |
7664 return; | |
7665 | |
7666 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7667 norm_term = ( | |
7668 #ifdef FEAT_GUI | |
7669 !gui.in_use && | |
7670 #endif | |
7671 t_colors <= 1); | |
7672 for (row = start_row; row < end_row; ++row) | |
7673 { | |
1668 | 7674 #ifdef FEAT_MBYTE |
7675 if (has_mbyte | |
7676 # ifdef FEAT_GUI | |
7677 && !gui.in_use | |
7678 # endif | |
7679 ) | |
7680 { | |
7681 /* When drawing over the right halve of a double-wide char clear | |
7682 * out the left halve. When drawing over the left halve of a | |
7683 * double wide-char clear out the right halve. Only needed in a | |
7684 * terminal. */ | |
1685 | 7685 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7686 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7687 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7688 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7689 } |
7690 #endif | |
7 | 7691 /* |
7692 * Try to use delete-line termcap code, when no attributes or in a | |
7693 * "normal" terminal, where a bold/italic space is just a | |
7694 * space. | |
7695 */ | |
7696 did_delete = FALSE; | |
7697 if (c2 == ' ' | |
7698 && end_col == Columns | |
7699 && can_clear(T_CE) | |
7700 && (attr == 0 | |
7701 || (norm_term | |
7702 && attr <= HL_ALL | |
7703 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7704 { | |
7705 /* | |
7706 * check if we really need to clear something | |
7707 */ | |
7708 col = start_col; | |
7709 if (c1 != ' ') /* don't clear first char */ | |
7710 ++col; | |
7711 | |
7712 off = LineOffset[row] + col; | |
7713 end_off = LineOffset[row] + end_col; | |
7714 | |
7715 /* skip blanks (used often, keep it fast!) */ | |
7716 #ifdef FEAT_MBYTE | |
7717 if (enc_utf8) | |
7718 while (off < end_off && ScreenLines[off] == ' ' | |
7719 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7720 ++off; | |
7721 else | |
7722 #endif | |
7723 while (off < end_off && ScreenLines[off] == ' ' | |
7724 && ScreenAttrs[off] == 0) | |
7725 ++off; | |
7726 if (off < end_off) /* something to be cleared */ | |
7727 { | |
7728 col = off - LineOffset[row]; | |
7729 screen_stop_highlight(); | |
7730 term_windgoto(row, col);/* clear rest of this screen line */ | |
7731 out_str(T_CE); | |
7732 screen_start(); /* don't know where cursor is now */ | |
7733 col = end_col - col; | |
7734 while (col--) /* clear chars in ScreenLines */ | |
7735 { | |
7736 ScreenLines[off] = ' '; | |
7737 #ifdef FEAT_MBYTE | |
7738 if (enc_utf8) | |
7739 ScreenLinesUC[off] = 0; | |
7740 #endif | |
7741 ScreenAttrs[off] = 0; | |
7742 ++off; | |
7743 } | |
7744 } | |
7745 did_delete = TRUE; /* the chars are cleared now */ | |
7746 } | |
7747 | |
7748 off = LineOffset[row] + start_col; | |
7749 c = c1; | |
7750 for (col = start_col; col < end_col; ++col) | |
7751 { | |
7752 if (ScreenLines[off] != c | |
7753 #ifdef FEAT_MBYTE | |
714 | 7754 || (enc_utf8 && (int)ScreenLinesUC[off] |
7755 != (c >= 0x80 ? c : 0)) | |
7 | 7756 #endif |
7757 || ScreenAttrs[off] != attr | |
7758 #if defined(FEAT_GUI) || defined(UNIX) | |
7759 || force_next | |
7760 #endif | |
7761 ) | |
7762 { | |
7763 #if defined(FEAT_GUI) || defined(UNIX) | |
7764 /* The bold trick may make a single row of pixels appear in | |
7765 * the next character. When a bold character is removed, the | |
7766 * next character should be redrawn too. This happens for our | |
7767 * own GUI and for some xterms. */ | |
7768 if ( | |
7769 # ifdef FEAT_GUI | |
7770 gui.in_use | |
7771 # endif | |
7772 # if defined(FEAT_GUI) && defined(UNIX) | |
7773 || | |
7774 # endif | |
7775 # ifdef UNIX | |
7776 term_is_xterm | |
7777 # endif | |
7778 ) | |
7779 { | |
7780 if (ScreenLines[off] != ' ' | |
7781 && (ScreenAttrs[off] > HL_ALL | |
7782 || ScreenAttrs[off] & HL_BOLD)) | |
7783 force_next = TRUE; | |
7784 else | |
7785 force_next = FALSE; | |
7786 } | |
7787 #endif | |
7788 ScreenLines[off] = c; | |
7789 #ifdef FEAT_MBYTE | |
7790 if (enc_utf8) | |
7791 { | |
7792 if (c >= 0x80) | |
7793 { | |
7794 ScreenLinesUC[off] = c; | |
714 | 7795 ScreenLinesC[0][off] = 0; |
7 | 7796 } |
7797 else | |
7798 ScreenLinesUC[off] = 0; | |
7799 } | |
7800 #endif | |
7801 ScreenAttrs[off] = attr; | |
7802 if (!did_delete || c != ' ') | |
7803 screen_char(off, row, col); | |
7804 } | |
7805 ++off; | |
7806 if (col == start_col) | |
7807 { | |
7808 if (did_delete) | |
7809 break; | |
7810 c = c2; | |
7811 } | |
7812 } | |
7813 if (end_col == Columns) | |
7814 LineWraps[row] = FALSE; | |
7815 if (row == Rows - 1) /* overwritten the command line */ | |
7816 { | |
7817 redraw_cmdline = TRUE; | |
7818 if (c1 == ' ' && c2 == ' ') | |
7819 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7820 if (start_col == 0) |
7821 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7822 } |
7823 } | |
7824 } | |
7825 | |
7826 /* | |
7827 * Check if there should be a delay. Used before clearing or redrawing the | |
7828 * screen or the command line. | |
7829 */ | |
7830 void | |
7831 check_for_delay(check_msg_scroll) | |
7832 int check_msg_scroll; | |
7833 { | |
7834 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7835 && !did_wait_return | |
7836 && emsg_silent == 0) | |
7837 { | |
7838 out_flush(); | |
7839 ui_delay(1000L, TRUE); | |
7840 emsg_on_display = FALSE; | |
7841 if (check_msg_scroll) | |
7842 msg_scroll = FALSE; | |
7843 } | |
7844 } | |
7845 | |
7846 /* | |
7847 * screen_valid - allocate screen buffers if size changed | |
7848 * If "clear" is TRUE: clear screen if it has been resized. | |
7849 * Returns TRUE if there is a valid screen to write to. | |
7850 * Returns FALSE when starting up and screen not initialized yet. | |
7851 */ | |
7852 int | |
7853 screen_valid(clear) | |
7854 int clear; | |
7855 { | |
7856 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7857 return (ScreenLines != NULL); | |
7858 } | |
7859 | |
7860 /* | |
7861 * Resize the shell to Rows and Columns. | |
7862 * Allocate ScreenLines[] and associated items. | |
7863 * | |
7864 * There may be some time between setting Rows and Columns and (re)allocating | |
7865 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7866 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7867 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7868 * final size of the shell is needed. | |
7869 */ | |
7870 void | |
7871 screenalloc(clear) | |
7872 int clear; | |
7873 { | |
7874 int new_row, old_row; | |
7875 #ifdef FEAT_GUI | |
7876 int old_Rows; | |
7877 #endif | |
7878 win_T *wp; | |
7879 int outofmem = FALSE; | |
7880 int len; | |
7881 schar_T *new_ScreenLines; | |
7882 #ifdef FEAT_MBYTE | |
7883 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7884 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7885 schar_T *new_ScreenLines2 = NULL; |
714 | 7886 int i; |
7 | 7887 #endif |
7888 sattr_T *new_ScreenAttrs; | |
7889 unsigned *new_LineOffset; | |
7890 char_u *new_LineWraps; | |
671 | 7891 #ifdef FEAT_WINDOWS |
681 | 7892 short *new_TabPageIdxs; |
671 | 7893 tabpage_T *tp; |
7894 #endif | |
7 | 7895 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7896 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7897 #ifdef FEAT_AUTOCMD |
7898 int retry_count = 0; | |
7899 | |
7900 retry: | |
7901 #endif | |
7 | 7902 /* |
7903 * Allocation of the screen buffers is done only when the size changes and | |
7904 * when Rows and Columns have been set and we have started doing full | |
7905 * screen stuff. | |
7906 */ | |
7907 if ((ScreenLines != NULL | |
7908 && Rows == screen_Rows | |
7909 && Columns == screen_Columns | |
7910 #ifdef FEAT_MBYTE | |
7911 && enc_utf8 == (ScreenLinesUC != NULL) | |
7912 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7913 && p_mco == Screen_mco |
7 | 7914 #endif |
7915 ) | |
7916 || Rows == 0 | |
7917 || Columns == 0 | |
7918 || (!full_screen && ScreenLines == NULL)) | |
7919 return; | |
7920 | |
7921 /* | |
7922 * It's possible that we produce an out-of-memory message below, which | |
7923 * will cause this function to be called again. To break the loop, just | |
7924 * return here. | |
7925 */ | |
7926 if (entered) | |
7927 return; | |
7928 entered = TRUE; | |
7929 | |
911 | 7930 /* |
7931 * Note that the window sizes are updated before reallocating the arrays, | |
7932 * thus we must not redraw here! | |
7933 */ | |
7934 ++RedrawingDisabled; | |
7935 | |
7 | 7936 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7937 | |
7938 comp_col(); /* recompute columns for shown command and ruler */ | |
7939 | |
7940 /* | |
7941 * We're changing the size of the screen. | |
7942 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7943 * - Move lines from the old arrays into the new arrays, clear extra | |
7944 * lines (unless the screen is going to be cleared). | |
7945 * - Free the old arrays. | |
7946 * | |
7947 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7948 * Continuing with the old ScreenLines may result in a crash, because the | |
7949 * size is wrong. | |
7950 */ | |
671 | 7951 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7952 win_free_lsize(wp); |
1946 | 7953 #ifdef FEAT_AUTOCMD |
7954 if (aucmd_win != NULL) | |
7955 win_free_lsize(aucmd_win); | |
7956 #endif | |
7 | 7957 |
7958 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7959 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7960 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7961 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7962 if (enc_utf8) |
7963 { | |
7964 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7965 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7966 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7967 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7968 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7969 } | |
7970 if (enc_dbcs == DBCS_JPNU) | |
7971 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7972 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7973 #endif | |
7974 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7975 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7976 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7977 Rows * sizeof(unsigned)), FALSE); | |
7978 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7979 #ifdef FEAT_WINDOWS |
681 | 7980 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7981 #endif |
7 | 7982 |
677 | 7983 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7984 { |
7985 if (win_alloc_lines(wp) == FAIL) | |
7986 { | |
7987 outofmem = TRUE; | |
7988 #ifdef FEAT_WINDOWS | |
1819 | 7989 goto give_up; |
7990 #endif | |
7991 } | |
7992 } | |
1906 | 7993 #ifdef FEAT_AUTOCMD |
1946 | 7994 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7995 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7996 outofmem = TRUE; |
7997 #endif | |
1819 | 7998 #ifdef FEAT_WINDOWS |
7999 give_up: | |
8000 #endif | |
7 | 8001 |
714 | 8002 #ifdef FEAT_MBYTE |
8003 for (i = 0; i < p_mco; ++i) | |
8004 if (new_ScreenLinesC[i] == NULL) | |
8005 break; | |
8006 #endif | |
7 | 8007 if (new_ScreenLines == NULL |
8008 #ifdef FEAT_MBYTE | |
714 | 8009 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 8010 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
8011 #endif | |
8012 || new_ScreenAttrs == NULL | |
8013 || new_LineOffset == NULL | |
8014 || new_LineWraps == NULL | |
671 | 8015 #ifdef FEAT_WINDOWS |
8016 || new_TabPageIdxs == NULL | |
8017 #endif | |
7 | 8018 || outofmem) |
8019 { | |
944 | 8020 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 8021 { |
8022 /* guess the size */ | |
8023 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
8024 | |
8025 /* Remember we did this to avoid getting outofmem messages over | |
8026 * and over again. */ | |
944 | 8027 done_outofmem_msg = TRUE; |
534 | 8028 } |
7 | 8029 vim_free(new_ScreenLines); |
8030 new_ScreenLines = NULL; | |
8031 #ifdef FEAT_MBYTE | |
8032 vim_free(new_ScreenLinesUC); | |
8033 new_ScreenLinesUC = NULL; | |
714 | 8034 for (i = 0; i < p_mco; ++i) |
8035 { | |
8036 vim_free(new_ScreenLinesC[i]); | |
8037 new_ScreenLinesC[i] = NULL; | |
8038 } | |
7 | 8039 vim_free(new_ScreenLines2); |
8040 new_ScreenLines2 = NULL; | |
8041 #endif | |
8042 vim_free(new_ScreenAttrs); | |
8043 new_ScreenAttrs = NULL; | |
8044 vim_free(new_LineOffset); | |
8045 new_LineOffset = NULL; | |
8046 vim_free(new_LineWraps); | |
8047 new_LineWraps = NULL; | |
671 | 8048 #ifdef FEAT_WINDOWS |
8049 vim_free(new_TabPageIdxs); | |
8050 new_TabPageIdxs = NULL; | |
8051 #endif | |
7 | 8052 } |
8053 else | |
8054 { | |
944 | 8055 done_outofmem_msg = FALSE; |
534 | 8056 |
7 | 8057 for (new_row = 0; new_row < Rows; ++new_row) |
8058 { | |
8059 new_LineOffset[new_row] = new_row * Columns; | |
8060 new_LineWraps[new_row] = FALSE; | |
8061 | |
8062 /* | |
8063 * If the screen is not going to be cleared, copy as much as | |
8064 * possible from the old screen to the new one and clear the rest | |
8065 * (used when resizing the window at the "--more--" prompt or when | |
8066 * executing an external command, for the GUI). | |
8067 */ | |
8068 if (!clear) | |
8069 { | |
8070 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
8071 ' ', (size_t)Columns * sizeof(schar_T)); | |
8072 #ifdef FEAT_MBYTE | |
8073 if (enc_utf8) | |
8074 { | |
8075 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
8076 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 8077 for (i = 0; i < p_mco; ++i) |
8078 (void)vim_memset(new_ScreenLinesC[i] | |
8079 + new_row * Columns, | |
7 | 8080 0, (size_t)Columns * sizeof(u8char_T)); |
8081 } | |
8082 if (enc_dbcs == DBCS_JPNU) | |
8083 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8084 0, (size_t)Columns * sizeof(schar_T)); | |
8085 #endif | |
8086 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8087 0, (size_t)Columns * sizeof(sattr_T)); | |
8088 old_row = new_row + (screen_Rows - Rows); | |
534 | 8089 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8090 { |
8091 if (screen_Columns < Columns) | |
8092 len = screen_Columns; | |
8093 else | |
8094 len = Columns; | |
26 | 8095 #ifdef FEAT_MBYTE |
571 | 8096 /* When switching to utf-8 don't copy characters, they |
714 | 8097 * may be invalid now. Also when p_mco changes. */ |
8098 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8099 && p_mco == Screen_mco) | |
26 | 8100 #endif |
8101 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8102 ScreenLines + LineOffset[old_row], | |
8103 (size_t)len * sizeof(schar_T)); | |
7 | 8104 #ifdef FEAT_MBYTE |
714 | 8105 if (enc_utf8 && ScreenLinesUC != NULL |
8106 && p_mco == Screen_mco) | |
7 | 8107 { |
8108 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8109 ScreenLinesUC + LineOffset[old_row], | |
8110 (size_t)len * sizeof(u8char_T)); | |
714 | 8111 for (i = 0; i < p_mco; ++i) |
8112 mch_memmove(new_ScreenLinesC[i] | |
8113 + new_LineOffset[new_row], | |
8114 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8115 (size_t)len * sizeof(u8char_T)); |
8116 } | |
8117 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8118 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8119 ScreenLines2 + LineOffset[old_row], | |
8120 (size_t)len * sizeof(schar_T)); | |
8121 #endif | |
8122 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8123 ScreenAttrs + LineOffset[old_row], | |
8124 (size_t)len * sizeof(sattr_T)); | |
8125 } | |
8126 } | |
8127 } | |
8128 /* Use the last line of the screen for the current line. */ | |
8129 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8130 } | |
8131 | |
356 | 8132 free_screenlines(); |
8133 | |
7 | 8134 ScreenLines = new_ScreenLines; |
8135 #ifdef FEAT_MBYTE | |
8136 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8137 for (i = 0; i < p_mco; ++i) |
8138 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8139 Screen_mco = p_mco; | |
7 | 8140 ScreenLines2 = new_ScreenLines2; |
8141 #endif | |
8142 ScreenAttrs = new_ScreenAttrs; | |
8143 LineOffset = new_LineOffset; | |
8144 LineWraps = new_LineWraps; | |
671 | 8145 #ifdef FEAT_WINDOWS |
8146 TabPageIdxs = new_TabPageIdxs; | |
8147 #endif | |
7 | 8148 |
8149 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8150 * size of ScreenLines[]. Set them before calling anything. */ | |
8151 #ifdef FEAT_GUI | |
8152 old_Rows = screen_Rows; | |
8153 #endif | |
8154 screen_Rows = Rows; | |
8155 screen_Columns = Columns; | |
8156 | |
8157 must_redraw = CLEAR; /* need to clear the screen later */ | |
8158 if (clear) | |
8159 screenclear2(); | |
8160 | |
8161 #ifdef FEAT_GUI | |
8162 else if (gui.in_use | |
8163 && !gui.starting | |
8164 && ScreenLines != NULL | |
8165 && old_Rows != Rows) | |
8166 { | |
8167 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8168 /* | |
8169 * Adjust the position of the cursor, for when executing an external | |
8170 * command. | |
8171 */ | |
8172 if (msg_row >= Rows) /* Rows got smaller */ | |
8173 msg_row = Rows - 1; /* put cursor at last row */ | |
8174 else if (Rows > old_Rows) /* Rows got bigger */ | |
8175 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8176 if (msg_col >= Columns) /* Columns got smaller */ | |
8177 msg_col = Columns - 1; /* put cursor at last column */ | |
8178 } | |
8179 #endif | |
8180 | |
8181 entered = FALSE; | |
911 | 8182 --RedrawingDisabled; |
766 | 8183 |
8184 #ifdef FEAT_AUTOCMD | |
1824 | 8185 /* |
8186 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8187 * in case applying autocommands always changes Rows or Columns. | |
8188 */ | |
8189 if (starting == 0 && ++retry_count <= 3) | |
8190 { | |
766 | 8191 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8192 /* In rare cases, autocommands may have altered Rows or Columns, |
8193 * jump back to check if we need to allocate the screen again. */ | |
8194 goto retry; | |
8195 } | |
766 | 8196 #endif |
7 | 8197 } |
8198 | |
8199 void | |
356 | 8200 free_screenlines() |
8201 { | |
8202 #ifdef FEAT_MBYTE | |
714 | 8203 int i; |
8204 | |
356 | 8205 vim_free(ScreenLinesUC); |
714 | 8206 for (i = 0; i < Screen_mco; ++i) |
8207 vim_free(ScreenLinesC[i]); | |
356 | 8208 vim_free(ScreenLines2); |
8209 #endif | |
714 | 8210 vim_free(ScreenLines); |
356 | 8211 vim_free(ScreenAttrs); |
8212 vim_free(LineOffset); | |
8213 vim_free(LineWraps); | |
671 | 8214 #ifdef FEAT_WINDOWS |
8215 vim_free(TabPageIdxs); | |
8216 #endif | |
356 | 8217 } |
8218 | |
8219 void | |
7 | 8220 screenclear() |
8221 { | |
8222 check_for_delay(FALSE); | |
8223 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8224 screenclear2(); /* clear the screen */ | |
8225 } | |
8226 | |
8227 static void | |
8228 screenclear2() | |
8229 { | |
8230 int i; | |
8231 | |
8232 if (starting == NO_SCREEN || ScreenLines == NULL | |
8233 #ifdef FEAT_GUI | |
8234 || (gui.in_use && gui.starting) | |
8235 #endif | |
8236 ) | |
8237 return; | |
8238 | |
8239 #ifdef FEAT_GUI | |
8240 if (!gui.in_use) | |
8241 #endif | |
8242 screen_attr = -1; /* force setting the Normal colors */ | |
8243 screen_stop_highlight(); /* don't want highlighting here */ | |
8244 | |
8245 #ifdef FEAT_CLIPBOARD | |
8246 /* disable selection without redrawing it */ | |
8247 clip_scroll_selection(9999); | |
8248 #endif | |
8249 | |
8250 /* blank out ScreenLines */ | |
8251 for (i = 0; i < Rows; ++i) | |
8252 { | |
8253 lineclear(LineOffset[i], (int)Columns); | |
8254 LineWraps[i] = FALSE; | |
8255 } | |
8256 | |
8257 if (can_clear(T_CL)) | |
8258 { | |
8259 out_str(T_CL); /* clear the display */ | |
8260 clear_cmdline = FALSE; | |
644 | 8261 mode_displayed = FALSE; |
7 | 8262 } |
8263 else | |
8264 { | |
8265 /* can't clear the screen, mark all chars with invalid attributes */ | |
8266 for (i = 0; i < Rows; ++i) | |
8267 lineinvalid(LineOffset[i], (int)Columns); | |
8268 clear_cmdline = TRUE; | |
8269 } | |
8270 | |
8271 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8272 | |
8273 win_rest_invalid(firstwin); | |
8274 redraw_cmdline = TRUE; | |
670 | 8275 #ifdef FEAT_WINDOWS |
673 | 8276 redraw_tabline = TRUE; |
670 | 8277 #endif |
7 | 8278 if (must_redraw == CLEAR) /* no need to clear again */ |
8279 must_redraw = NOT_VALID; | |
8280 compute_cmdrow(); | |
8281 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8282 msg_col = 0; | |
8283 screen_start(); /* don't know where cursor is now */ | |
8284 msg_scrolled = 0; /* can't scroll back */ | |
8285 msg_didany = FALSE; | |
8286 msg_didout = FALSE; | |
8287 } | |
8288 | |
8289 /* | |
8290 * Clear one line in ScreenLines. | |
8291 */ | |
8292 static void | |
8293 lineclear(off, width) | |
8294 unsigned off; | |
8295 int width; | |
8296 { | |
8297 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8298 #ifdef FEAT_MBYTE | |
8299 if (enc_utf8) | |
8300 (void)vim_memset(ScreenLinesUC + off, 0, | |
8301 (size_t)width * sizeof(u8char_T)); | |
8302 #endif | |
8303 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8304 } | |
8305 | |
8306 /* | |
8307 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8308 * invalid value. | |
8309 */ | |
8310 static void | |
8311 lineinvalid(off, width) | |
8312 unsigned off; | |
8313 int width; | |
8314 { | |
8315 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8316 } | |
8317 | |
8318 #ifdef FEAT_VERTSPLIT | |
8319 /* | |
8320 * Copy part of a Screenline for vertically split window "wp". | |
8321 */ | |
8322 static void | |
8323 linecopy(to, from, wp) | |
8324 int to; | |
8325 int from; | |
8326 win_T *wp; | |
8327 { | |
8328 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8329 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8330 | |
8331 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8332 wp->w_width * sizeof(schar_T)); | |
8333 # ifdef FEAT_MBYTE | |
8334 if (enc_utf8) | |
8335 { | |
714 | 8336 int i; |
8337 | |
7 | 8338 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8339 wp->w_width * sizeof(u8char_T)); | |
714 | 8340 for (i = 0; i < p_mco; ++i) |
8341 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8342 wp->w_width * sizeof(u8char_T)); | |
7 | 8343 } |
8344 if (enc_dbcs == DBCS_JPNU) | |
8345 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8346 wp->w_width * sizeof(schar_T)); | |
8347 # endif | |
8348 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8349 wp->w_width * sizeof(sattr_T)); | |
8350 } | |
8351 #endif | |
8352 | |
8353 /* | |
8354 * Return TRUE if clearing with term string "p" would work. | |
8355 * It can't work when the string is empty or it won't set the right background. | |
8356 */ | |
8357 int | |
8358 can_clear(p) | |
8359 char_u *p; | |
8360 { | |
8361 return (*p != NUL && (t_colors <= 1 | |
8362 #ifdef FEAT_GUI | |
8363 || gui.in_use | |
8364 #endif | |
8365 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8366 } | |
8367 | |
8368 /* | |
8369 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8370 * something directly to the screen (shell commands) or a terminal control | |
8371 * code. | |
8372 */ | |
8373 void | |
8374 screen_start() | |
8375 { | |
8376 screen_cur_row = screen_cur_col = 9999; | |
8377 } | |
8378 | |
8379 /* | |
8380 * Move the cursor to position "row","col" in the screen. | |
8381 * This tries to find the most efficient way to move, minimizing the number of | |
8382 * characters sent to the terminal. | |
8383 */ | |
8384 void | |
8385 windgoto(row, col) | |
8386 int row; | |
8387 int col; | |
8388 { | |
205 | 8389 sattr_T *p; |
7 | 8390 int i; |
8391 int plan; | |
8392 int cost; | |
8393 int wouldbe_col; | |
8394 int noinvcurs; | |
8395 char_u *bs; | |
8396 int goto_cost; | |
8397 int attr; | |
8398 | |
1213 | 8399 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8400 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8401 | |
8402 #define PLAN_LE 1 | |
8403 #define PLAN_CR 2 | |
8404 #define PLAN_NL 3 | |
8405 #define PLAN_WRITE 4 | |
8406 /* Can't use ScreenLines unless initialized */ | |
8407 if (ScreenLines == NULL) | |
8408 return; | |
8409 | |
8410 if (col != screen_cur_col || row != screen_cur_row) | |
8411 { | |
8412 /* Check for valid position. */ | |
8413 if (row < 0) /* window without text lines? */ | |
8414 row = 0; | |
8415 if (row >= screen_Rows) | |
8416 row = screen_Rows - 1; | |
8417 if (col >= screen_Columns) | |
8418 col = screen_Columns - 1; | |
8419 | |
8420 /* check if no cursor movement is allowed in highlight mode */ | |
8421 if (screen_attr && *T_MS == NUL) | |
8422 noinvcurs = HIGHL_COST; | |
8423 else | |
8424 noinvcurs = 0; | |
8425 goto_cost = GOTO_COST + noinvcurs; | |
8426 | |
8427 /* | |
8428 * Plan how to do the positioning: | |
8429 * 1. Use CR to move it to column 0, same row. | |
8430 * 2. Use T_LE to move it a few columns to the left. | |
8431 * 3. Use NL to move a few lines down, column 0. | |
8432 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8433 * | |
8434 * Don't do this if the cursor went beyond the last column, the cursor | |
8435 * position is unknown then (some terminals wrap, some don't ) | |
8436 * | |
1213 | 8437 * First check if the highlighting attributes allow us to write |
7 | 8438 * characters to move the cursor to the right. |
8439 */ | |
8440 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8441 { | |
8442 /* | |
8443 * If the cursor is in the same row, bigger col, we can use CR | |
8444 * or T_LE. | |
8445 */ | |
8446 bs = NULL; /* init for GCC */ | |
8447 attr = screen_attr; | |
8448 if (row == screen_cur_row && col < screen_cur_col) | |
8449 { | |
8450 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8451 if (*T_LE) | |
8452 bs = T_LE; /* "cursor left" */ | |
8453 else | |
8454 bs = T_BC; /* "backspace character (old) */ | |
8455 if (*bs) | |
8456 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8457 else | |
8458 cost = 999; | |
8459 if (col + 1 < cost) /* using CR is less characters */ | |
8460 { | |
8461 plan = PLAN_CR; | |
8462 wouldbe_col = 0; | |
8463 cost = 1; /* CR is just one character */ | |
8464 } | |
8465 else | |
8466 { | |
8467 plan = PLAN_LE; | |
8468 wouldbe_col = col; | |
8469 } | |
8470 if (noinvcurs) /* will stop highlighting */ | |
8471 { | |
8472 cost += noinvcurs; | |
8473 attr = 0; | |
8474 } | |
8475 } | |
8476 | |
8477 /* | |
8478 * If the cursor is above where we want to be, we can use CR LF. | |
8479 */ | |
8480 else if (row > screen_cur_row) | |
8481 { | |
8482 plan = PLAN_NL; | |
8483 wouldbe_col = 0; | |
8484 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8485 if (noinvcurs) /* will stop highlighting */ | |
8486 { | |
8487 cost += noinvcurs; | |
8488 attr = 0; | |
8489 } | |
8490 } | |
8491 | |
8492 /* | |
8493 * If the cursor is in the same row, smaller col, just use write. | |
8494 */ | |
8495 else | |
8496 { | |
8497 plan = PLAN_WRITE; | |
8498 wouldbe_col = screen_cur_col; | |
8499 cost = 0; | |
8500 } | |
8501 | |
8502 /* | |
8503 * Check if any characters that need to be written have the | |
8504 * correct attributes. Also avoid UTF-8 characters. | |
8505 */ | |
8506 i = col - wouldbe_col; | |
8507 if (i > 0) | |
8508 cost += i; | |
8509 if (cost < goto_cost && i > 0) | |
8510 { | |
8511 /* | |
8512 * Check if the attributes are correct without additionally | |
8513 * stopping highlighting. | |
8514 */ | |
8515 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8516 while (i && *p++ == attr) | |
8517 --i; | |
8518 if (i != 0) | |
8519 { | |
8520 /* | |
8521 * Try if it works when highlighting is stopped here. | |
8522 */ | |
8523 if (*--p == 0) | |
8524 { | |
8525 cost += noinvcurs; | |
8526 while (i && *p++ == 0) | |
8527 --i; | |
8528 } | |
8529 if (i != 0) | |
8530 cost = 999; /* different attributes, don't do it */ | |
8531 } | |
8532 #ifdef FEAT_MBYTE | |
8533 if (enc_utf8) | |
8534 { | |
8535 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8536 for (i = wouldbe_col; i < col; ++i) | |
8537 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8538 { | |
8539 cost = 999; | |
8540 break; | |
8541 } | |
8542 } | |
8543 #endif | |
8544 } | |
8545 | |
8546 /* | |
8547 * We can do it without term_windgoto()! | |
8548 */ | |
8549 if (cost < goto_cost) | |
8550 { | |
8551 if (plan == PLAN_LE) | |
8552 { | |
8553 if (noinvcurs) | |
8554 screen_stop_highlight(); | |
8555 while (screen_cur_col > col) | |
8556 { | |
8557 out_str(bs); | |
8558 --screen_cur_col; | |
8559 } | |
8560 } | |
8561 else if (plan == PLAN_CR) | |
8562 { | |
8563 if (noinvcurs) | |
8564 screen_stop_highlight(); | |
8565 out_char('\r'); | |
8566 screen_cur_col = 0; | |
8567 } | |
8568 else if (plan == PLAN_NL) | |
8569 { | |
8570 if (noinvcurs) | |
8571 screen_stop_highlight(); | |
8572 while (screen_cur_row < row) | |
8573 { | |
8574 out_char('\n'); | |
8575 ++screen_cur_row; | |
8576 } | |
8577 screen_cur_col = 0; | |
8578 } | |
8579 | |
8580 i = col - screen_cur_col; | |
8581 if (i > 0) | |
8582 { | |
8583 /* | |
8584 * Use cursor-right if it's one character only. Avoids | |
8585 * removing a line of pixels from the last bold char, when | |
8586 * using the bold trick in the GUI. | |
8587 */ | |
8588 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8589 { | |
8590 while (i-- > 0) | |
8591 out_char(*T_ND); | |
8592 } | |
8593 else | |
8594 { | |
8595 int off; | |
8596 | |
8597 off = LineOffset[row] + screen_cur_col; | |
8598 while (i-- > 0) | |
8599 { | |
8600 if (ScreenAttrs[off] != screen_attr) | |
8601 screen_stop_highlight(); | |
8602 #ifdef FEAT_MBYTE | |
8603 out_flush_check(); | |
8604 #endif | |
8605 out_char(ScreenLines[off]); | |
8606 #ifdef FEAT_MBYTE | |
8607 if (enc_dbcs == DBCS_JPNU | |
8608 && ScreenLines[off] == 0x8e) | |
8609 out_char(ScreenLines2[off]); | |
8610 #endif | |
8611 ++off; | |
8612 } | |
8613 } | |
8614 } | |
8615 } | |
8616 } | |
8617 else | |
8618 cost = 999; | |
8619 | |
8620 if (cost >= goto_cost) | |
8621 { | |
8622 if (noinvcurs) | |
8623 screen_stop_highlight(); | |
8624 if (row == screen_cur_row && (col > screen_cur_col) && | |
8625 *T_CRI != NUL) | |
8626 term_cursor_right(col - screen_cur_col); | |
8627 else | |
8628 term_windgoto(row, col); | |
8629 } | |
8630 screen_cur_row = row; | |
8631 screen_cur_col = col; | |
8632 } | |
8633 } | |
8634 | |
8635 /* | |
8636 * Set cursor to its position in the current window. | |
8637 */ | |
8638 void | |
8639 setcursor() | |
8640 { | |
8641 if (redrawing()) | |
8642 { | |
8643 validate_cursor(); | |
8644 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8645 W_WINCOL(curwin) + ( | |
8646 #ifdef FEAT_RIGHTLEFT | |
1545 | 8647 /* With 'rightleft' set and the cursor on a double-wide |
8648 * character, position it on the leftmost column. */ | |
7 | 8649 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8650 # ifdef FEAT_MBYTE | |
1545 | 8651 (has_mbyte |
8652 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8653 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8654 # endif |
8655 1)) : | |
8656 #endif | |
8657 curwin->w_wcol)); | |
8658 } | |
8659 } | |
8660 | |
8661 | |
8662 /* | |
8663 * insert 'line_count' lines at 'row' in window 'wp' | |
8664 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8665 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8666 * scrolling. | |
8667 * Returns FAIL if the lines are not inserted, OK for success. | |
8668 */ | |
8669 int | |
8670 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8671 win_T *wp; | |
8672 int row; | |
8673 int line_count; | |
8674 int invalid; | |
8675 int mayclear; | |
8676 { | |
8677 int did_delete; | |
8678 int nextrow; | |
8679 int lastrow; | |
8680 int retval; | |
8681 | |
8682 if (invalid) | |
8683 wp->w_lines_valid = 0; | |
8684 | |
8685 if (wp->w_height < 5) | |
8686 return FAIL; | |
8687 | |
8688 if (line_count > wp->w_height - row) | |
8689 line_count = wp->w_height - row; | |
8690 | |
8691 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8692 if (retval != MAYBE) | |
8693 return retval; | |
8694 | |
8695 /* | |
8696 * If there is a next window or a status line, we first try to delete the | |
8697 * lines at the bottom to avoid messing what is after the window. | |
8698 * If this fails and there are following windows, don't do anything to avoid | |
8699 * messing up those windows, better just redraw. | |
8700 */ | |
8701 did_delete = FALSE; | |
8702 #ifdef FEAT_WINDOWS | |
8703 if (wp->w_next != NULL || wp->w_status_height) | |
8704 { | |
8705 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8706 line_count, (int)Rows, FALSE, NULL) == OK) | |
8707 did_delete = TRUE; | |
8708 else if (wp->w_next) | |
8709 return FAIL; | |
8710 } | |
8711 #endif | |
8712 /* | |
8713 * if no lines deleted, blank the lines that will end up below the window | |
8714 */ | |
8715 if (!did_delete) | |
8716 { | |
8717 #ifdef FEAT_WINDOWS | |
8718 wp->w_redr_status = TRUE; | |
8719 #endif | |
8720 redraw_cmdline = TRUE; | |
8721 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8722 lastrow = nextrow + line_count; | |
8723 if (lastrow > Rows) | |
8724 lastrow = Rows; | |
8725 screen_fill(nextrow - line_count, lastrow - line_count, | |
8726 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8727 ' ', ' ', 0); | |
8728 } | |
8729 | |
8730 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8731 == FAIL) | |
8732 { | |
8733 /* deletion will have messed up other windows */ | |
8734 if (did_delete) | |
8735 { | |
8736 #ifdef FEAT_WINDOWS | |
8737 wp->w_redr_status = TRUE; | |
8738 #endif | |
8739 win_rest_invalid(W_NEXT(wp)); | |
8740 } | |
8741 return FAIL; | |
8742 } | |
8743 | |
8744 return OK; | |
8745 } | |
8746 | |
8747 /* | |
8748 * delete "line_count" window lines at "row" in window "wp" | |
8749 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8750 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8751 * scrolling | |
8752 * Return OK for success, FAIL if the lines are not deleted. | |
8753 */ | |
8754 int | |
8755 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8756 win_T *wp; | |
8757 int row; | |
8758 int line_count; | |
8759 int invalid; | |
8760 int mayclear; | |
8761 { | |
8762 int retval; | |
8763 | |
8764 if (invalid) | |
8765 wp->w_lines_valid = 0; | |
8766 | |
8767 if (line_count > wp->w_height - row) | |
8768 line_count = wp->w_height - row; | |
8769 | |
8770 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8771 if (retval != MAYBE) | |
8772 return retval; | |
8773 | |
8774 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8775 (int)Rows, FALSE, NULL) == FAIL) | |
8776 return FAIL; | |
8777 | |
8778 #ifdef FEAT_WINDOWS | |
8779 /* | |
8780 * If there are windows or status lines below, try to put them at the | |
8781 * correct place. If we can't do that, they have to be redrawn. | |
8782 */ | |
8783 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8784 { | |
8785 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8786 line_count, (int)Rows, NULL) == FAIL) | |
8787 { | |
8788 wp->w_redr_status = TRUE; | |
8789 win_rest_invalid(wp->w_next); | |
8790 } | |
8791 } | |
8792 /* | |
8793 * If this is the last window and there is no status line, redraw the | |
8794 * command line later. | |
8795 */ | |
8796 else | |
8797 #endif | |
8798 redraw_cmdline = TRUE; | |
8799 return OK; | |
8800 } | |
8801 | |
8802 /* | |
8803 * Common code for win_ins_lines() and win_del_lines(). | |
8804 * Returns OK or FAIL when the work has been done. | |
8805 * Returns MAYBE when not finished yet. | |
8806 */ | |
8807 static int | |
8808 win_do_lines(wp, row, line_count, mayclear, del) | |
8809 win_T *wp; | |
8810 int row; | |
8811 int line_count; | |
8812 int mayclear; | |
8813 int del; | |
8814 { | |
8815 int retval; | |
8816 | |
8817 if (!redrawing() || line_count <= 0) | |
8818 return FAIL; | |
8819 | |
8820 /* only a few lines left: redraw is faster */ | |
8821 if (mayclear && Rows - line_count < 5 | |
8822 #ifdef FEAT_VERTSPLIT | |
8823 && wp->w_width == Columns | |
8824 #endif | |
8825 ) | |
8826 { | |
8827 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8828 return FAIL; | |
8829 } | |
8830 | |
8831 /* | |
8832 * Delete all remaining lines | |
8833 */ | |
8834 if (row + line_count >= wp->w_height) | |
8835 { | |
8836 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8837 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8838 ' ', ' ', 0); | |
8839 return OK; | |
8840 } | |
8841 | |
8842 /* | |
8843 * when scrolling, the message on the command line should be cleared, | |
8844 * otherwise it will stay there forever. | |
8845 */ | |
8846 clear_cmdline = TRUE; | |
8847 | |
8848 /* | |
8849 * If the terminal can set a scroll region, use that. | |
8850 * Always do this in a vertically split window. This will redraw from | |
8851 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8852 * win_line(). | |
8853 * Don't use a scroll region when we are going to redraw the text, writing | |
8854 * a character in the lower right corner of the scroll region causes a | |
8855 * scroll-up in the DJGPP version. | |
8856 */ | |
8857 if (scroll_region | |
8858 #ifdef FEAT_VERTSPLIT | |
8859 || W_WIDTH(wp) != Columns | |
8860 #endif | |
8861 ) | |
8862 { | |
8863 #ifdef FEAT_VERTSPLIT | |
8864 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8865 #endif | |
8866 scroll_region_set(wp, row); | |
8867 if (del) | |
8868 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8869 wp->w_height - row, FALSE, wp); | |
8870 else | |
8871 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8872 wp->w_height - row, wp); | |
8873 #ifdef FEAT_VERTSPLIT | |
8874 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8875 #endif | |
8876 scroll_region_reset(); | |
8877 return retval; | |
8878 } | |
8879 | |
8880 #ifdef FEAT_WINDOWS | |
8881 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8882 return FAIL; | |
8883 #endif | |
8884 | |
8885 return MAYBE; | |
8886 } | |
8887 | |
8888 /* | |
8889 * window 'wp' and everything after it is messed up, mark it for redraw | |
8890 */ | |
8891 static void | |
8892 win_rest_invalid(wp) | |
8893 win_T *wp; | |
8894 { | |
8895 #ifdef FEAT_WINDOWS | |
8896 while (wp != NULL) | |
8897 #else | |
8898 if (wp != NULL) | |
8899 #endif | |
8900 { | |
8901 redraw_win_later(wp, NOT_VALID); | |
8902 #ifdef FEAT_WINDOWS | |
8903 wp->w_redr_status = TRUE; | |
8904 wp = wp->w_next; | |
8905 #endif | |
8906 } | |
8907 redraw_cmdline = TRUE; | |
8908 } | |
8909 | |
8910 /* | |
8911 * The rest of the routines in this file perform screen manipulations. The | |
8912 * given operation is performed physically on the screen. The corresponding | |
8913 * change is also made to the internal screen image. In this way, the editor | |
8914 * anticipates the effect of editing changes on the appearance of the screen. | |
8915 * That way, when we call screenupdate a complete redraw isn't usually | |
8916 * necessary. Another advantage is that we can keep adding code to anticipate | |
8917 * screen changes, and in the meantime, everything still works. | |
8918 */ | |
8919 | |
8920 /* | |
8921 * types for inserting or deleting lines | |
8922 */ | |
8923 #define USE_T_CAL 1 | |
8924 #define USE_T_CDL 2 | |
8925 #define USE_T_AL 3 | |
8926 #define USE_T_CE 4 | |
8927 #define USE_T_DL 5 | |
8928 #define USE_T_SR 6 | |
8929 #define USE_NL 7 | |
8930 #define USE_T_CD 8 | |
8931 #define USE_REDRAW 9 | |
8932 | |
8933 /* | |
8934 * insert lines on the screen and update ScreenLines[] | |
8935 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8936 * When scrolling region used 'off' is the offset from the top for the region. | |
8937 * 'row' and 'end' are relative to the start of the region. | |
8938 * | |
8939 * return FAIL for failure, OK for success. | |
8940 */ | |
446 | 8941 int |
7 | 8942 screen_ins_lines(off, row, line_count, end, wp) |
8943 int off; | |
8944 int row; | |
8945 int line_count; | |
8946 int end; | |
8947 win_T *wp; /* NULL or window to use width from */ | |
8948 { | |
8949 int i; | |
8950 int j; | |
8951 unsigned temp; | |
8952 int cursor_row; | |
8953 int type; | |
8954 int result_empty; | |
8955 int can_ce = can_clear(T_CE); | |
8956 | |
8957 /* | |
8958 * FAIL if | |
8959 * - there is no valid screen | |
8960 * - the screen has to be redrawn completely | |
8961 * - the line count is less than one | |
8962 * - the line count is more than 'ttyscroll' | |
8963 */ | |
8964 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8965 return FAIL; | |
8966 | |
8967 /* | |
8968 * There are seven ways to insert lines: | |
8969 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8970 * characters from ScreenLines[]. | |
8971 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8972 * the insert is just empty lines | |
8973 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8974 * present or line_count > 1. It looks better if we do all the inserts | |
8975 * at once. | |
8976 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8977 * insert is just empty lines and T_CE is not present or line_count > | |
8978 * 1. | |
8979 * 4. Use T_AL (insert line) if it exists. | |
8980 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8981 * just empty lines. | |
8982 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8983 * just empty lines. | |
8984 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8985 * the 'da' flag is not set or we have clear line capability. | |
8986 * 8. redraw the characters from ScreenLines[]. | |
8987 * | |
8988 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8989 * the scrollbar for the window. It does have insert line, use that if it | |
8990 * exists. | |
8991 */ | |
8992 result_empty = (row + line_count >= end); | |
8993 #ifdef FEAT_VERTSPLIT | |
8994 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8995 type = USE_REDRAW; | |
8996 else | |
8997 #endif | |
8998 if (can_clear(T_CD) && result_empty) | |
8999 type = USE_T_CD; | |
9000 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
9001 type = USE_T_CAL; | |
9002 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
9003 type = USE_T_CDL; | |
9004 else if (*T_AL != NUL) | |
9005 type = USE_T_AL; | |
9006 else if (can_ce && result_empty) | |
9007 type = USE_T_CE; | |
9008 else if (*T_DL != NUL && result_empty) | |
9009 type = USE_T_DL; | |
9010 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
9011 type = USE_T_SR; | |
9012 else | |
9013 return FAIL; | |
9014 | |
9015 /* | |
9016 * For clearing the lines screen_del_lines() is used. This will also take | |
9017 * care of t_db if necessary. | |
9018 */ | |
9019 if (type == USE_T_CD || type == USE_T_CDL || | |
9020 type == USE_T_CE || type == USE_T_DL) | |
9021 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
9022 | |
9023 /* | |
9024 * If text is retained below the screen, first clear or delete as many | |
9025 * lines at the bottom of the window as are about to be inserted so that | |
9026 * the deleted lines won't later surface during a screen_del_lines. | |
9027 */ | |
9028 if (*T_DB) | |
9029 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
9030 | |
9031 #ifdef FEAT_CLIPBOARD | |
9032 /* Remove a modeless selection when inserting lines halfway the screen | |
9033 * or not the full width of the screen. */ | |
9034 if (off + row > 0 | |
9035 # ifdef FEAT_VERTSPLIT | |
9036 || (wp != NULL && wp->w_width != Columns) | |
9037 # endif | |
9038 ) | |
9039 clip_clear_selection(); | |
9040 else | |
9041 clip_scroll_selection(-line_count); | |
9042 #endif | |
9043 | |
9044 #ifdef FEAT_GUI | |
9045 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9046 * scrolling is actually carried out. */ | |
9047 gui_dont_update_cursor(); | |
9048 #endif | |
9049 | |
9050 if (*T_CCS != NUL) /* cursor relative to region */ | |
9051 cursor_row = row; | |
9052 else | |
9053 cursor_row = row + off; | |
9054 | |
9055 /* | |
9056 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
9057 * Clear the inserted lines in ScreenLines[]. | |
9058 */ | |
9059 row += off; | |
9060 end += off; | |
9061 for (i = 0; i < line_count; ++i) | |
9062 { | |
9063 #ifdef FEAT_VERTSPLIT | |
9064 if (wp != NULL && wp->w_width != Columns) | |
9065 { | |
9066 /* need to copy part of a line */ | |
9067 j = end - 1 - i; | |
9068 while ((j -= line_count) >= row) | |
9069 linecopy(j + line_count, j, wp); | |
9070 j += line_count; | |
9071 if (can_clear((char_u *)" ")) | |
9072 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9073 else | |
9074 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9075 LineWraps[j] = FALSE; | |
9076 } | |
9077 else | |
9078 #endif | |
9079 { | |
9080 j = end - 1 - i; | |
9081 temp = LineOffset[j]; | |
9082 while ((j -= line_count) >= row) | |
9083 { | |
9084 LineOffset[j + line_count] = LineOffset[j]; | |
9085 LineWraps[j + line_count] = LineWraps[j]; | |
9086 } | |
9087 LineOffset[j + line_count] = temp; | |
9088 LineWraps[j + line_count] = FALSE; | |
9089 if (can_clear((char_u *)" ")) | |
9090 lineclear(temp, (int)Columns); | |
9091 else | |
9092 lineinvalid(temp, (int)Columns); | |
9093 } | |
9094 } | |
9095 | |
9096 screen_stop_highlight(); | |
9097 windgoto(cursor_row, 0); | |
9098 | |
9099 #ifdef FEAT_VERTSPLIT | |
9100 /* redraw the characters */ | |
9101 if (type == USE_REDRAW) | |
9102 redraw_block(row, end, wp); | |
9103 else | |
9104 #endif | |
9105 if (type == USE_T_CAL) | |
9106 { | |
9107 term_append_lines(line_count); | |
9108 screen_start(); /* don't know where cursor is now */ | |
9109 } | |
9110 else | |
9111 { | |
9112 for (i = 0; i < line_count; i++) | |
9113 { | |
9114 if (type == USE_T_AL) | |
9115 { | |
9116 if (i && cursor_row != 0) | |
9117 windgoto(cursor_row, 0); | |
9118 out_str(T_AL); | |
9119 } | |
9120 else /* type == USE_T_SR */ | |
9121 out_str(T_SR); | |
9122 screen_start(); /* don't know where cursor is now */ | |
9123 } | |
9124 } | |
9125 | |
9126 /* | |
9127 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9128 * have been scrolled down into the region. | |
9129 */ | |
9130 if (type == USE_T_SR && *T_DA) | |
9131 { | |
9132 for (i = 0; i < line_count; ++i) | |
9133 { | |
9134 windgoto(off + i, 0); | |
9135 out_str(T_CE); | |
9136 screen_start(); /* don't know where cursor is now */ | |
9137 } | |
9138 } | |
9139 | |
9140 #ifdef FEAT_GUI | |
9141 gui_can_update_cursor(); | |
9142 if (gui.in_use) | |
9143 out_flush(); /* always flush after a scroll */ | |
9144 #endif | |
9145 return OK; | |
9146 } | |
9147 | |
9148 /* | |
9149 * delete lines on the screen and update ScreenLines[] | |
9150 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9151 * When scrolling region used 'off' is the offset from the top for the region. | |
9152 * 'row' and 'end' are relative to the start of the region. | |
9153 * | |
9154 * Return OK for success, FAIL if the lines are not deleted. | |
9155 */ | |
9156 int | |
9157 screen_del_lines(off, row, line_count, end, force, wp) | |
9158 int off; | |
9159 int row; | |
9160 int line_count; | |
9161 int end; | |
9162 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9163 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9164 { |
9165 int j; | |
9166 int i; | |
9167 unsigned temp; | |
9168 int cursor_row; | |
9169 int cursor_end; | |
9170 int result_empty; /* result is empty until end of region */ | |
9171 int can_delete; /* deleting line codes can be used */ | |
9172 int type; | |
9173 | |
9174 /* | |
9175 * FAIL if | |
9176 * - there is no valid screen | |
9177 * - the screen has to be redrawn completely | |
9178 * - the line count is less than one | |
9179 * - the line count is more than 'ttyscroll' | |
9180 */ | |
9181 if (!screen_valid(TRUE) || line_count <= 0 || | |
9182 (!force && line_count > p_ttyscroll)) | |
9183 return FAIL; | |
9184 | |
9185 /* | |
9186 * Check if the rest of the current region will become empty. | |
9187 */ | |
9188 result_empty = row + line_count >= end; | |
9189 | |
9190 /* | |
9191 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9192 * available. | |
9193 */ | |
9194 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9195 | |
9196 /* | |
9197 * There are six ways to delete lines: | |
9198 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9199 * characters from ScreenLines[]. | |
9200 * 1. Use T_CD if it exists and the result is empty. | |
9201 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9202 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9203 * none of the other ways work. | |
9204 * 4. Use T_CE (erase line) if the result is empty. | |
9205 * 5. Use T_DL (delete line) if it exists. | |
9206 * 6. redraw the characters from ScreenLines[]. | |
9207 */ | |
9208 #ifdef FEAT_VERTSPLIT | |
9209 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9210 type = USE_REDRAW; | |
9211 else | |
9212 #endif | |
9213 if (can_clear(T_CD) && result_empty) | |
9214 type = USE_T_CD; | |
9215 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9216 /* | |
9217 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9218 * its internal termcap... this works okay for tests which test *T_DB != | |
9219 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9220 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9221 * the trick... | |
9222 * Anyway, this hack will hopefully go away with the next OS release. | |
9223 * (Olaf Seibert) | |
9224 */ | |
9225 else if (row == 0 && T_DB == empty_option | |
9226 && (line_count == 1 || *T_CDL == NUL)) | |
9227 #else | |
9228 else if (row == 0 && ( | |
9229 #ifndef AMIGA | |
9230 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9231 * up, so use delete-line command */ | |
9232 line_count == 1 || | |
9233 #endif | |
9234 *T_CDL == NUL)) | |
9235 #endif | |
9236 type = USE_NL; | |
9237 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9238 type = USE_T_CDL; | |
9239 else if (can_clear(T_CE) && result_empty | |
9240 #ifdef FEAT_VERTSPLIT | |
9241 && (wp == NULL || wp->w_width == Columns) | |
9242 #endif | |
9243 ) | |
9244 type = USE_T_CE; | |
9245 else if (*T_DL != NUL && can_delete) | |
9246 type = USE_T_DL; | |
9247 else if (*T_CDL != NUL && can_delete) | |
9248 type = USE_T_CDL; | |
9249 else | |
9250 return FAIL; | |
9251 | |
9252 #ifdef FEAT_CLIPBOARD | |
9253 /* Remove a modeless selection when deleting lines halfway the screen or | |
9254 * not the full width of the screen. */ | |
9255 if (off + row > 0 | |
9256 # ifdef FEAT_VERTSPLIT | |
9257 || (wp != NULL && wp->w_width != Columns) | |
9258 # endif | |
9259 ) | |
9260 clip_clear_selection(); | |
9261 else | |
9262 clip_scroll_selection(line_count); | |
9263 #endif | |
9264 | |
9265 #ifdef FEAT_GUI | |
9266 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9267 * scrolling is actually carried out. */ | |
9268 gui_dont_update_cursor(); | |
9269 #endif | |
9270 | |
9271 if (*T_CCS != NUL) /* cursor relative to region */ | |
9272 { | |
9273 cursor_row = row; | |
9274 cursor_end = end; | |
9275 } | |
9276 else | |
9277 { | |
9278 cursor_row = row + off; | |
9279 cursor_end = end + off; | |
9280 } | |
9281 | |
9282 /* | |
9283 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9284 * Clear the inserted lines in ScreenLines[]. | |
9285 */ | |
9286 row += off; | |
9287 end += off; | |
9288 for (i = 0; i < line_count; ++i) | |
9289 { | |
9290 #ifdef FEAT_VERTSPLIT | |
9291 if (wp != NULL && wp->w_width != Columns) | |
9292 { | |
9293 /* need to copy part of a line */ | |
9294 j = row + i; | |
9295 while ((j += line_count) <= end - 1) | |
9296 linecopy(j - line_count, j, wp); | |
9297 j -= line_count; | |
9298 if (can_clear((char_u *)" ")) | |
9299 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9300 else | |
9301 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9302 LineWraps[j] = FALSE; | |
9303 } | |
9304 else | |
9305 #endif | |
9306 { | |
9307 /* whole width, moving the line pointers is faster */ | |
9308 j = row + i; | |
9309 temp = LineOffset[j]; | |
9310 while ((j += line_count) <= end - 1) | |
9311 { | |
9312 LineOffset[j - line_count] = LineOffset[j]; | |
9313 LineWraps[j - line_count] = LineWraps[j]; | |
9314 } | |
9315 LineOffset[j - line_count] = temp; | |
9316 LineWraps[j - line_count] = FALSE; | |
9317 if (can_clear((char_u *)" ")) | |
9318 lineclear(temp, (int)Columns); | |
9319 else | |
9320 lineinvalid(temp, (int)Columns); | |
9321 } | |
9322 } | |
9323 | |
9324 screen_stop_highlight(); | |
9325 | |
9326 #ifdef FEAT_VERTSPLIT | |
9327 /* redraw the characters */ | |
9328 if (type == USE_REDRAW) | |
9329 redraw_block(row, end, wp); | |
9330 else | |
9331 #endif | |
9332 if (type == USE_T_CD) /* delete the lines */ | |
9333 { | |
9334 windgoto(cursor_row, 0); | |
9335 out_str(T_CD); | |
9336 screen_start(); /* don't know where cursor is now */ | |
9337 } | |
9338 else if (type == USE_T_CDL) | |
9339 { | |
9340 windgoto(cursor_row, 0); | |
9341 term_delete_lines(line_count); | |
9342 screen_start(); /* don't know where cursor is now */ | |
9343 } | |
9344 /* | |
9345 * Deleting lines at top of the screen or scroll region: Just scroll | |
9346 * the whole screen (scroll region) up by outputting newlines on the | |
9347 * last line. | |
9348 */ | |
9349 else if (type == USE_NL) | |
9350 { | |
9351 windgoto(cursor_end - 1, 0); | |
9352 for (i = line_count; --i >= 0; ) | |
9353 out_char('\n'); /* cursor will remain on same line */ | |
9354 } | |
9355 else | |
9356 { | |
9357 for (i = line_count; --i >= 0; ) | |
9358 { | |
9359 if (type == USE_T_DL) | |
9360 { | |
9361 windgoto(cursor_row, 0); | |
9362 out_str(T_DL); /* delete a line */ | |
9363 } | |
9364 else /* type == USE_T_CE */ | |
9365 { | |
9366 windgoto(cursor_row + i, 0); | |
9367 out_str(T_CE); /* erase a line */ | |
9368 } | |
9369 screen_start(); /* don't know where cursor is now */ | |
9370 } | |
9371 } | |
9372 | |
9373 /* | |
9374 * If the 'db' flag is set, we need to clear the lines that have been | |
9375 * scrolled up at the bottom of the region. | |
9376 */ | |
9377 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9378 { | |
9379 for (i = line_count; i > 0; --i) | |
9380 { | |
9381 windgoto(cursor_end - i, 0); | |
9382 out_str(T_CE); /* erase a line */ | |
9383 screen_start(); /* don't know where cursor is now */ | |
9384 } | |
9385 } | |
9386 | |
9387 #ifdef FEAT_GUI | |
9388 gui_can_update_cursor(); | |
9389 if (gui.in_use) | |
9390 out_flush(); /* always flush after a scroll */ | |
9391 #endif | |
9392 | |
9393 return OK; | |
9394 } | |
9395 | |
9396 /* | |
9397 * show the current mode and ruler | |
9398 * | |
9399 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9400 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9401 * cleared only if a mode is shown. | |
9402 * Return the length of the message (0 if no message). | |
9403 */ | |
9404 int | |
9405 showmode() | |
9406 { | |
9407 int need_clear; | |
9408 int length = 0; | |
9409 int do_mode; | |
9410 int attr; | |
9411 int nwr_save; | |
9412 #ifdef FEAT_INS_EXPAND | |
9413 int sub_attr; | |
9414 #endif | |
9415 | |
642 | 9416 do_mode = ((p_smd && msg_silent == 0) |
9417 && ((State & INSERT) | |
9418 || restart_edit | |
7 | 9419 #ifdef FEAT_VISUAL |
9420 || VIsual_active | |
9421 #endif | |
9422 )); | |
9423 if (do_mode || Recording) | |
9424 { | |
9425 /* | |
9426 * Don't show mode right now, when not redrawing or inside a mapping. | |
9427 * Call char_avail() only when we are going to show something, because | |
9428 * it takes a bit of time. | |
9429 */ | |
9430 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9431 { | |
9432 redraw_cmdline = TRUE; /* show mode later */ | |
9433 return 0; | |
9434 } | |
9435 | |
9436 nwr_save = need_wait_return; | |
9437 | |
9438 /* wait a bit before overwriting an important message */ | |
9439 check_for_delay(FALSE); | |
9440 | |
9441 /* if the cmdline is more than one line high, erase top lines */ | |
9442 need_clear = clear_cmdline; | |
9443 if (clear_cmdline && cmdline_row < Rows - 1) | |
9444 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9445 | |
9446 /* Position on the last line in the window, column 0 */ | |
9447 msg_pos_mode(); | |
9448 cursor_off(); | |
9449 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9450 if (do_mode) | |
9451 { | |
9452 MSG_PUTS_ATTR("--", attr); | |
9453 #if defined(FEAT_XIM) | |
2520 | 9454 if ( |
9455 # ifdef FEAT_GUI_GTK | |
9456 preedit_get_status() | |
1668 | 9457 # else |
9458 im_get_status() | |
2520 | 9459 # endif |
1668 | 9460 ) |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9461 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9462 MSG_PUTS_ATTR(" IM", attr); |
9463 # else | |
9464 MSG_PUTS_ATTR(" XIM", attr); | |
9465 # endif | |
9466 #endif | |
9467 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9468 if (gui.in_use) | |
9469 { | |
9470 if (hangul_input_state_get()) | |
236 | 9471 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9472 } |
9473 #endif | |
9474 #ifdef FEAT_INS_EXPAND | |
9475 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9476 { | |
9477 /* These messages can get long, avoid a wrap in a narrow | |
9478 * window. Prefer showing edit_submode_extra. */ | |
9479 length = (Rows - msg_row) * Columns - 3; | |
9480 if (edit_submode_extra != NULL) | |
9481 length -= vim_strsize(edit_submode_extra); | |
9482 if (length > 0) | |
9483 { | |
9484 if (edit_submode_pre != NULL) | |
9485 length -= vim_strsize(edit_submode_pre); | |
9486 if (length - vim_strsize(edit_submode) > 0) | |
9487 { | |
9488 if (edit_submode_pre != NULL) | |
9489 msg_puts_attr(edit_submode_pre, attr); | |
9490 msg_puts_attr(edit_submode, attr); | |
9491 } | |
9492 if (edit_submode_extra != NULL) | |
9493 { | |
9494 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9495 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9496 sub_attr = hl_attr(edit_submode_highl); | |
9497 else | |
9498 sub_attr = attr; | |
9499 msg_puts_attr(edit_submode_extra, sub_attr); | |
9500 } | |
9501 } | |
9502 length = 0; | |
9503 } | |
9504 else | |
9505 #endif | |
9506 { | |
9507 #ifdef FEAT_VREPLACE | |
9508 if (State & VREPLACE_FLAG) | |
9509 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9510 else | |
9511 #endif | |
9512 if (State & REPLACE_FLAG) | |
9513 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9514 else if (State & INSERT) | |
9515 { | |
9516 #ifdef FEAT_RIGHTLEFT | |
9517 if (p_ri) | |
9518 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9519 #endif | |
9520 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9521 } | |
9522 else if (restart_edit == 'I') | |
9523 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9524 else if (restart_edit == 'R') | |
9525 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9526 else if (restart_edit == 'V') | |
9527 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9528 #ifdef FEAT_RIGHTLEFT | |
9529 if (p_hkmap) | |
9530 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9531 # ifdef FEAT_FKMAP | |
9532 if (p_fkmap) | |
9533 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9534 # endif | |
9535 #endif | |
9536 #ifdef FEAT_KEYMAP | |
9537 if (State & LANGMAP) | |
9538 { | |
9539 # ifdef FEAT_ARABIC | |
9540 if (curwin->w_p_arab) | |
9541 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9542 else | |
9543 # endif | |
9544 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9545 } | |
9546 #endif | |
9547 if ((State & INSERT) && p_paste) | |
9548 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9549 | |
9550 #ifdef FEAT_VISUAL | |
9551 if (VIsual_active) | |
9552 { | |
9553 char *p; | |
9554 | |
9555 /* Don't concatenate separate words to avoid translation | |
9556 * problems. */ | |
9557 switch ((VIsual_select ? 4 : 0) | |
9558 + (VIsual_mode == Ctrl_V) * 2 | |
9559 + (VIsual_mode == 'V')) | |
9560 { | |
9561 case 0: p = N_(" VISUAL"); break; | |
9562 case 1: p = N_(" VISUAL LINE"); break; | |
9563 case 2: p = N_(" VISUAL BLOCK"); break; | |
9564 case 4: p = N_(" SELECT"); break; | |
9565 case 5: p = N_(" SELECT LINE"); break; | |
9566 default: p = N_(" SELECT BLOCK"); break; | |
9567 } | |
9568 MSG_PUTS_ATTR(_(p), attr); | |
9569 } | |
9570 #endif | |
9571 MSG_PUTS_ATTR(" --", attr); | |
9572 } | |
644 | 9573 |
7 | 9574 need_clear = TRUE; |
9575 } | |
9576 if (Recording | |
9577 #ifdef FEAT_INS_EXPAND | |
9578 && edit_submode == NULL /* otherwise it gets too long */ | |
9579 #endif | |
9580 ) | |
9581 { | |
9582 MSG_PUTS_ATTR(_("recording"), attr); | |
9583 need_clear = TRUE; | |
9584 } | |
644 | 9585 |
9586 mode_displayed = TRUE; | |
7 | 9587 if (need_clear || clear_cmdline) |
9588 msg_clr_eos(); | |
9589 msg_didout = FALSE; /* overwrite this message */ | |
9590 length = msg_col; | |
9591 msg_col = 0; | |
9592 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9593 } | |
9594 else if (clear_cmdline && msg_silent == 0) | |
9595 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9596 msg_clr_cmdline(); | |
9597 | |
9598 #ifdef FEAT_CMDL_INFO | |
9599 # ifdef FEAT_VISUAL | |
9600 /* In Visual mode the size of the selected area must be redrawn. */ | |
9601 if (VIsual_active) | |
9602 clear_showcmd(); | |
9603 # endif | |
9604 | |
9605 /* If the last window has no status line, the ruler is after the mode | |
9606 * message and must be redrawn */ | |
9607 if (redrawing() | |
9608 # ifdef FEAT_WINDOWS | |
9609 && lastwin->w_status_height == 0 | |
9610 # endif | |
9611 ) | |
9612 win_redr_ruler(lastwin, TRUE); | |
9613 #endif | |
9614 redraw_cmdline = FALSE; | |
9615 clear_cmdline = FALSE; | |
9616 | |
9617 return length; | |
9618 } | |
9619 | |
9620 /* | |
9621 * Position for a mode message. | |
9622 */ | |
9623 static void | |
9624 msg_pos_mode() | |
9625 { | |
9626 msg_col = 0; | |
9627 msg_row = Rows - 1; | |
9628 } | |
9629 | |
9630 /* | |
9631 * Delete mode message. Used when ESC is typed which is expected to end | |
9632 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9633 * Caller should check "mode_displayed". |
7 | 9634 */ |
9635 void | |
9636 unshowmode(force) | |
9637 int force; | |
9638 { | |
9639 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9640 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9641 */ |
9642 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9643 redraw_cmdline = TRUE; /* delete mode later */ | |
9644 else | |
9645 { | |
9646 msg_pos_mode(); | |
9647 if (Recording) | |
9648 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9649 msg_clr_eos(); | |
9650 } | |
9651 } | |
9652 | |
667 | 9653 #if defined(FEAT_WINDOWS) |
9654 /* | |
9655 * Draw the tab pages line at the top of the Vim window. | |
9656 */ | |
9657 static void | |
677 | 9658 draw_tabline() |
667 | 9659 { |
9660 int tabcount = 0; | |
9661 tabpage_T *tp; | |
9662 int tabwidth; | |
9663 int col = 0; | |
673 | 9664 int scol = 0; |
667 | 9665 int attr; |
9666 win_T *wp; | |
671 | 9667 win_T *cwp; |
9668 int wincount; | |
9669 int modified; | |
667 | 9670 int c; |
9671 int len; | |
9672 int attr_sel = hl_attr(HLF_TPS); | |
9673 int attr_nosel = hl_attr(HLF_TP); | |
9674 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9675 char_u *p; |
677 | 9676 int room; |
9677 int use_sep_chars = (t_colors < 8 | |
9678 #ifdef FEAT_GUI | |
9679 && !gui.in_use | |
9680 #endif | |
9681 ); | |
673 | 9682 |
9683 redraw_tabline = FALSE; | |
667 | 9684 |
685 | 9685 #ifdef FEAT_GUI_TABLINE |
798 | 9686 /* Take care of a GUI tabline. */ |
685 | 9687 if (gui_use_tabline()) |
9688 { | |
9689 gui_update_tabline(); | |
9690 return; | |
9691 } | |
9692 #endif | |
9693 | |
9694 if (tabline_height() < 1) | |
667 | 9695 return; |
9696 | |
677 | 9697 #if defined(FEAT_STL_OPT) |
681 | 9698 |
9699 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9700 for (scol = 0; scol < Columns; ++scol) | |
9701 TabPageIdxs[scol] = 0; | |
9702 | |
677 | 9703 /* Use the 'tabline' option if it's set. */ |
9704 if (*p_tal != NUL) | |
9705 { | |
680 | 9706 int save_called_emsg = called_emsg; |
9707 | |
9708 /* Check for an error. If there is one we would loop in redrawing the | |
9709 * screen. Avoid that by making 'tabline' empty. */ | |
9710 called_emsg = FALSE; | |
677 | 9711 win_redr_custom(NULL, FALSE); |
680 | 9712 if (called_emsg) |
9713 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9714 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9715 called_emsg |= save_called_emsg; |
9716 } | |
9717 else | |
9718 #endif | |
9719 { | |
9720 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9721 ++tabcount; | |
9722 | |
9723 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9724 if (tabwidth < 6) | |
9725 tabwidth = 6; | |
9726 | |
9727 attr = attr_nosel; | |
9728 tabcount = 0; | |
681 | 9729 scol = 0; |
699 | 9730 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9731 tp = tp->tp_next) | |
680 | 9732 { |
9733 scol = col; | |
9734 | |
9735 if (tp->tp_topframe == topframe) | |
9736 attr = attr_sel; | |
9737 if (use_sep_chars && col > 0) | |
9738 screen_putchar('|', 0, col++, attr); | |
9739 | |
9740 if (tp->tp_topframe != topframe) | |
9741 attr = attr_nosel; | |
9742 | |
9743 screen_putchar(' ', 0, col++, attr); | |
9744 | |
9745 if (tp == curtab) | |
9746 { | |
9747 cwp = curwin; | |
9748 wp = firstwin; | |
9749 } | |
9750 else | |
9751 { | |
9752 cwp = tp->tp_curwin; | |
9753 wp = tp->tp_firstwin; | |
9754 } | |
9755 | |
9756 modified = FALSE; | |
9757 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9758 if (bufIsChanged(wp->w_buffer)) | |
9759 modified = TRUE; | |
9760 if (modified || wincount > 1) | |
9761 { | |
9762 if (wincount > 1) | |
9763 { | |
9764 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9765 len = (int)STRLEN(NameBuff); |
699 | 9766 if (col + len >= Columns - 3) |
9767 break; | |
680 | 9768 screen_puts_len(NameBuff, len, 0, col, |
677 | 9769 #if defined(FEAT_SYN_HL) |
680 | 9770 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9771 #else |
680 | 9772 attr |
9773 #endif | |
9774 ); | |
9775 col += len; | |
9776 } | |
9777 if (modified) | |
9778 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9779 screen_putchar(' ', 0, col++, attr); | |
9780 } | |
9781 | |
9782 room = scol - col + tabwidth - 1; | |
9783 if (room > 0) | |
9784 { | |
685 | 9785 /* Get buffer name in NameBuff[] */ |
9786 get_trans_bufname(cwp->w_buffer); | |
819 | 9787 shorten_dir(NameBuff); |
680 | 9788 len = vim_strsize(NameBuff); |
9789 p = NameBuff; | |
677 | 9790 #ifdef FEAT_MBYTE |
680 | 9791 if (has_mbyte) |
9792 while (len > room) | |
9793 { | |
9794 len -= ptr2cells(p); | |
9795 mb_ptr_adv(p); | |
9796 } | |
9797 else | |
9798 #endif | |
9799 if (len > room) | |
677 | 9800 { |
680 | 9801 p += len - room; |
9802 len = room; | |
677 | 9803 } |
699 | 9804 if (len > Columns - col - 1) |
9805 len = Columns - col - 1; | |
680 | 9806 |
835 | 9807 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9808 col += len; |
9809 } | |
9810 screen_putchar(' ', 0, col++, attr); | |
9811 | |
9812 /* Store the tab page number in TabPageIdxs[], so that | |
9813 * jump_to_mouse() knows where each one is. */ | |
9814 ++tabcount; | |
9815 while (scol < col) | |
9816 TabPageIdxs[scol++] = tabcount; | |
9817 } | |
9818 | |
9819 if (use_sep_chars) | |
9820 c = '_'; | |
9821 else | |
9822 c = ' '; | |
9823 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9824 |
9825 /* Put an "X" for closing the current tab if there are several. */ | |
9826 if (first_tabpage->tp_next != NULL) | |
9827 { | |
9828 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9829 TabPageIdxs[Columns - 1] = -999; | |
9830 } | |
9831 } | |
834 | 9832 |
9833 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9834 * set. */ | |
9835 redraw_tabline = FALSE; | |
667 | 9836 } |
685 | 9837 |
9838 /* | |
9839 * Get buffer name for "buf" into NameBuff[]. | |
9840 * Takes care of special buffer names and translates special characters. | |
9841 */ | |
9842 void | |
9843 get_trans_bufname(buf) | |
9844 buf_T *buf; | |
9845 { | |
9846 if (buf_spname(buf) != NULL) | |
9847 STRCPY(NameBuff, buf_spname(buf)); | |
9848 else | |
9849 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9850 trans_characters(NameBuff, MAXPATHL); | |
9851 } | |
667 | 9852 #endif |
9853 | |
7 | 9854 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9855 /* | |
9856 * Get the character to use in a status line. Get its attributes in "*attr". | |
9857 */ | |
9858 static int | |
9859 fillchar_status(attr, is_curwin) | |
9860 int *attr; | |
9861 int is_curwin; | |
9862 { | |
9863 int fill; | |
9864 if (is_curwin) | |
9865 { | |
9866 *attr = hl_attr(HLF_S); | |
9867 fill = fill_stl; | |
9868 } | |
9869 else | |
9870 { | |
9871 *attr = hl_attr(HLF_SNC); | |
9872 fill = fill_stlnc; | |
9873 } | |
9874 /* Use fill when there is highlighting, and highlighting of current | |
9875 * window differs, or the fillchars differ, or this is not the | |
9876 * current window */ | |
9877 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9878 || !is_curwin || firstwin == lastwin) | |
9879 || (fill_stl != fill_stlnc))) | |
9880 return fill; | |
9881 if (is_curwin) | |
9882 return '^'; | |
9883 return '='; | |
9884 } | |
9885 #endif | |
9886 | |
9887 #ifdef FEAT_VERTSPLIT | |
9888 /* | |
9889 * Get the character to use in a separator between vertically split windows. | |
9890 * Get its attributes in "*attr". | |
9891 */ | |
9892 static int | |
9893 fillchar_vsep(attr) | |
9894 int *attr; | |
9895 { | |
9896 *attr = hl_attr(HLF_C); | |
9897 if (*attr == 0 && fill_vert == ' ') | |
9898 return '|'; | |
9899 else | |
9900 return fill_vert; | |
9901 } | |
9902 #endif | |
9903 | |
9904 /* | |
9905 * Return TRUE if redrawing should currently be done. | |
9906 */ | |
9907 int | |
9908 redrawing() | |
9909 { | |
9910 return (!RedrawingDisabled | |
9911 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9912 } | |
9913 | |
9914 /* | |
9915 * Return TRUE if printing messages should currently be done. | |
9916 */ | |
9917 int | |
9918 messaging() | |
9919 { | |
9920 return (!(p_lz && char_avail() && !KeyTyped)); | |
9921 } | |
9922 | |
9923 /* | |
9924 * Show current status info in ruler and various other places | |
9925 * If always is FALSE, only show ruler if position has changed. | |
9926 */ | |
9927 void | |
9928 showruler(always) | |
9929 int always; | |
9930 { | |
9931 if (!always && !redrawing()) | |
9932 return; | |
574 | 9933 #ifdef FEAT_INS_EXPAND |
9934 if (pum_visible()) | |
9935 { | |
639 | 9936 # ifdef FEAT_WINDOWS |
574 | 9937 /* Don't redraw right now, do it later. */ |
9938 curwin->w_redr_status = TRUE; | |
639 | 9939 # endif |
574 | 9940 return; |
9941 } | |
9942 #endif | |
7 | 9943 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9944 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9945 { |
1983 | 9946 redraw_custom_statusline(curwin); |
680 | 9947 } |
7 | 9948 else |
9949 #endif | |
9950 #ifdef FEAT_CMDL_INFO | |
9951 win_redr_ruler(curwin, always); | |
9952 #endif | |
9953 | |
9954 #ifdef FEAT_TITLE | |
9955 if (need_maketitle | |
9956 # ifdef FEAT_STL_OPT | |
9957 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9958 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9959 # endif | |
9960 ) | |
9961 maketitle(); | |
9962 #endif | |
1588 | 9963 #ifdef FEAT_WINDOWS |
9964 /* Redraw the tab pages line if needed. */ | |
9965 if (redraw_tabline) | |
9966 draw_tabline(); | |
9967 #endif | |
7 | 9968 } |
9969 | |
9970 #ifdef FEAT_CMDL_INFO | |
9971 static void | |
9972 win_redr_ruler(wp, always) | |
9973 win_T *wp; | |
9974 int always; | |
9975 { | |
1869 | 9976 #define RULER_BUF_LEN 70 |
9977 char_u buffer[RULER_BUF_LEN]; | |
7 | 9978 int row; |
9979 int fillchar; | |
9980 int attr; | |
9981 int empty_line = FALSE; | |
9982 colnr_T virtcol; | |
9983 int i; | |
1869 | 9984 size_t len; |
7 | 9985 int o; |
9986 #ifdef FEAT_VERTSPLIT | |
9987 int this_ru_col; | |
9988 int off = 0; | |
9989 int width = Columns; | |
9990 # define WITH_OFF(x) x | |
9991 # define WITH_WIDTH(x) x | |
9992 #else | |
9993 # define WITH_OFF(x) 0 | |
9994 # define WITH_WIDTH(x) Columns | |
9995 # define this_ru_col ru_col | |
9996 #endif | |
9997 | |
9998 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9999 if (!p_ru) | |
10000 return; | |
10001 | |
10002 /* | |
10003 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
10004 * after deleting lines, before cursor.lnum is corrected. | |
10005 */ | |
10006 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
10007 return; | |
10008 | |
10009 #ifdef FEAT_INS_EXPAND | |
10010 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
10011 * the (long) mode message. */ | |
10012 # ifdef FEAT_WINDOWS | |
10013 if (wp == lastwin && lastwin->w_status_height == 0) | |
10014 # endif | |
10015 if (edit_submode != NULL) | |
10016 return; | |
540 | 10017 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
10018 if (pum_visible()) | |
10019 return; | |
7 | 10020 #endif |
10021 | |
10022 #ifdef FEAT_STL_OPT | |
10023 if (*p_ruf) | |
10024 { | |
680 | 10025 int save_called_emsg = called_emsg; |
10026 | |
10027 called_emsg = FALSE; | |
7 | 10028 win_redr_custom(wp, TRUE); |
680 | 10029 if (called_emsg) |
10030 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 10031 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 10032 called_emsg |= save_called_emsg; |
7 | 10033 return; |
10034 } | |
10035 #endif | |
10036 | |
10037 /* | |
10038 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
10039 */ | |
10040 if (!(State & INSERT) | |
10041 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
10042 empty_line = TRUE; | |
10043 | |
10044 /* | |
10045 * Only draw the ruler when something changed. | |
10046 */ | |
10047 validate_virtcol_win(wp); | |
10048 if ( redraw_cmdline | |
10049 || always | |
10050 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
10051 || wp->w_cursor.col != wp->w_ru_cursor.col | |
10052 || wp->w_virtcol != wp->w_ru_virtcol | |
10053 #ifdef FEAT_VIRTUALEDIT | |
10054 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
10055 #endif | |
10056 || wp->w_topline != wp->w_ru_topline | |
10057 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
10058 #ifdef FEAT_DIFF | |
10059 || wp->w_topfill != wp->w_ru_topfill | |
10060 #endif | |
10061 || empty_line != wp->w_ru_empty) | |
10062 { | |
10063 cursor_off(); | |
10064 #ifdef FEAT_WINDOWS | |
10065 if (wp->w_status_height) | |
10066 { | |
10067 row = W_WINROW(wp) + wp->w_height; | |
10068 fillchar = fillchar_status(&attr, wp == curwin); | |
10069 # ifdef FEAT_VERTSPLIT | |
10070 off = W_WINCOL(wp); | |
10071 width = W_WIDTH(wp); | |
10072 # endif | |
10073 } | |
10074 else | |
10075 #endif | |
10076 { | |
10077 row = Rows - 1; | |
10078 fillchar = ' '; | |
10079 attr = 0; | |
10080 #ifdef FEAT_VERTSPLIT | |
10081 width = Columns; | |
10082 off = 0; | |
10083 #endif | |
10084 } | |
10085 | |
10086 /* In list mode virtcol needs to be recomputed */ | |
10087 virtcol = wp->w_virtcol; | |
10088 if (wp->w_p_list && lcs_tab1 == NUL) | |
10089 { | |
10090 wp->w_p_list = FALSE; | |
10091 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10092 wp->w_p_list = TRUE; | |
10093 } | |
10094 | |
10095 /* | |
10096 * Some sprintfs return the length, some return a pointer. | |
10097 * To avoid portability problems we use strlen() here. | |
10098 */ | |
1869 | 10099 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10100 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10101 ? 0L | |
10102 : (long)(wp->w_cursor.lnum)); | |
1869 | 10103 len = STRLEN(buffer); |
10104 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10105 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10106 (int)virtcol + 1); | |
10107 | |
10108 /* | |
10109 * Add a "50%" if there is room for it. | |
10110 * On the last line, don't print in the last column (scrolls the | |
10111 * screen up on some terminals). | |
10112 */ | |
10113 i = (int)STRLEN(buffer); | |
1869 | 10114 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10115 o = i + vim_strsize(buffer + i + 1); |
10116 #ifdef FEAT_WINDOWS | |
10117 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10118 #endif | |
10119 ++o; | |
10120 #ifdef FEAT_VERTSPLIT | |
10121 this_ru_col = ru_col - (Columns - width); | |
10122 if (this_ru_col < 0) | |
10123 this_ru_col = 0; | |
10124 #endif | |
10125 /* Never use more than half the window/screen width, leave the other | |
10126 * half for the filename. */ | |
10127 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10128 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10129 if (this_ru_col + o < WITH_WIDTH(width)) | |
10130 { | |
10131 while (this_ru_col + o < WITH_WIDTH(width)) | |
10132 { | |
10133 #ifdef FEAT_MBYTE | |
10134 if (has_mbyte) | |
10135 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10136 else | |
10137 #endif | |
10138 buffer[i++] = fillchar; | |
10139 ++o; | |
10140 } | |
1869 | 10141 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10142 } |
10143 /* Truncate at window boundary. */ | |
10144 #ifdef FEAT_MBYTE | |
10145 if (has_mbyte) | |
10146 { | |
10147 o = 0; | |
474 | 10148 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10149 { |
10150 o += (*mb_ptr2cells)(buffer + i); | |
10151 if (this_ru_col + o > WITH_WIDTH(width)) | |
10152 { | |
10153 buffer[i] = NUL; | |
10154 break; | |
10155 } | |
10156 } | |
10157 } | |
10158 else | |
10159 #endif | |
10160 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10161 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10162 | |
10163 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10164 i = redraw_cmdline; | |
10165 screen_fill(row, row + 1, | |
10166 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10167 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10168 fillchar, fillchar, attr); | |
10169 /* don't redraw the cmdline because of showing the ruler */ | |
10170 redraw_cmdline = i; | |
10171 wp->w_ru_cursor = wp->w_cursor; | |
10172 wp->w_ru_virtcol = wp->w_virtcol; | |
10173 wp->w_ru_empty = empty_line; | |
10174 wp->w_ru_topline = wp->w_topline; | |
10175 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10176 #ifdef FEAT_DIFF | |
10177 wp->w_ru_topfill = wp->w_topfill; | |
10178 #endif | |
10179 } | |
10180 } | |
10181 #endif | |
13 | 10182 |
10183 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10184 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10185 * 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
|
10186 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10187 * Otherwise it depends on 'numberwidth' and the line count. |
10188 */ | |
10189 int | |
10190 number_width(wp) | |
10191 win_T *wp; | |
10192 { | |
10193 int n; | |
10194 linenr_T lnum; | |
10195 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10196 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10197 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10198 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
|
10199 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10200 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10201 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10202 |
13 | 10203 if (lnum == wp->w_nrwidth_line_count) |
10204 return wp->w_nrwidth_width; | |
10205 wp->w_nrwidth_line_count = lnum; | |
10206 | |
10207 n = 0; | |
10208 do | |
10209 { | |
856 | 10210 lnum /= 10; |
10211 ++n; | |
13 | 10212 } while (lnum > 0); |
10213 | |
10214 /* 'numberwidth' gives the minimal width plus one */ | |
10215 if (n < wp->w_p_nuw - 1) | |
10216 n = wp->w_p_nuw - 1; | |
10217 | |
10218 wp->w_nrwidth_width = n; | |
10219 return n; | |
10220 } | |
10221 #endif |