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