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