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