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 * message.c: functions for displaying messages on the command line
|
|
12 */
|
|
13
|
|
14 #define MESSAGE_FILE /* don't include prototype for smsg() */
|
|
15
|
|
16 #include "vim.h"
|
|
17
|
|
18 #ifdef HAVE_STDARG_H
|
|
19 # include <stdarg.h>
|
|
20 #endif
|
|
21
|
|
22 static void reset_last_sourcing __ARGS((void));
|
16
|
23 static int other_sourcing_name __ARGS((void));
|
|
24 static char_u *get_emsg_source __ARGS((void));
|
|
25 static char_u *get_emsg_lnum __ARGS((void));
|
7
|
26 static void add_msg_hist __ARGS((char_u *s, int len, int attr));
|
|
27 static void hit_return_msg __ARGS((void));
|
|
28 static void msg_home_replace_attr __ARGS((char_u *fname, int attr));
|
|
29 #ifdef FEAT_MBYTE
|
|
30 static char_u *screen_puts_mbyte __ARGS((char_u *s, int l, int attr));
|
|
31 #endif
|
|
32 static void msg_puts_attr_len __ARGS((char_u *str, int maxlen, int attr));
|
|
33 static void t_puts __ARGS((int t_col, char_u *t_s, char_u *s, int attr));
|
|
34 static void msg_screen_putchar __ARGS((int c, int attr));
|
|
35 static int msg_check_screen __ARGS((void));
|
|
36 static void redir_write __ARGS((char_u *s, int maxlen));
|
|
37 #ifdef FEAT_CON_DIALOG
|
|
38 static char_u *msg_show_console_dialog __ARGS((char_u *message, char_u *buttons, int dfltbutton));
|
|
39 static int confirm_msg_used = FALSE; /* displaying confirm_msg */
|
|
40 static char_u *confirm_msg = NULL; /* ":confirm" message */
|
|
41 static char_u *confirm_msg_tail; /* tail of confirm_msg */
|
|
42 #endif
|
|
43
|
|
44 struct msg_hist
|
|
45 {
|
|
46 struct msg_hist *next;
|
|
47 char_u *msg;
|
|
48 int attr;
|
|
49 };
|
|
50
|
|
51 static struct msg_hist *first_msg_hist = NULL;
|
|
52 static struct msg_hist *last_msg_hist = NULL;
|
|
53 static int msg_hist_len = 0;
|
|
54 static int msg_hist_off = FALSE; /* don't add messages to history */
|
|
55
|
|
56 /*
|
|
57 * When writing messages to the screen, there are many different situations.
|
|
58 * A number of variables is used to remember the current state:
|
|
59 * msg_didany TRUE when messages were written since the last time the
|
|
60 * user reacted to a prompt.
|
|
61 * Reset: After hitting a key for the hit-return prompt,
|
|
62 * hitting <CR> for the command line or input().
|
|
63 * Set: When any message is written to the screen.
|
|
64 * msg_didout TRUE when something was written to the current line.
|
|
65 * Reset: When advancing to the next line, when the current
|
|
66 * text can be overwritten.
|
|
67 * Set: When any message is written to the screen.
|
|
68 * msg_nowait No extra delay for the last drawn message.
|
|
69 * Used in normal_cmd() before the mode message is drawn.
|
|
70 * emsg_on_display There was an error message recently. Indicates that there
|
|
71 * should be a delay before redrawing.
|
|
72 * msg_scroll The next message should not overwrite the current one.
|
|
73 * msg_scrolled How many lines the screen has been scrolled (because of
|
|
74 * messages). Used in update_screen() to scroll the screen
|
|
75 * back. Incremented each time the screen scrolls a line.
|
|
76 * msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr()
|
|
77 * writes something without scrolling should not make
|
|
78 * need_wait_return to be set. This is a hack to make ":ts"
|
|
79 * work without an extra prompt.
|
|
80 * lines_left Number of lines available for messages before the
|
|
81 * more-prompt is to be given.
|
|
82 * need_wait_return TRUE when the hit-return prompt is needed.
|
|
83 * Reset: After giving the hit-return prompt, when the user
|
|
84 * has answered some other prompt.
|
|
85 * Set: When the ruler or typeahead display is overwritten,
|
|
86 * scrolling the screen for some message.
|
|
87 * keep_msg Message to be displayed after redrawing the screen, in
|
|
88 * main_loop().
|
|
89 * This is an allocated string or NULL when not used.
|
|
90 */
|
|
91
|
|
92 /*
|
|
93 * msg(s) - displays the string 's' on the status line
|
|
94 * When terminal not initialized (yet) mch_errmsg(..) is used.
|
|
95 * return TRUE if wait_return not called
|
|
96 */
|
|
97 int
|
|
98 msg(s)
|
|
99 char_u *s;
|
|
100 {
|
|
101 return msg_attr_keep(s, 0, FALSE);
|
|
102 }
|
|
103
|
|
104 int
|
|
105 msg_attr(s, attr)
|
|
106 char_u *s;
|
|
107 int attr;
|
|
108 {
|
|
109 return msg_attr_keep(s, attr, FALSE);
|
|
110 }
|
|
111
|
|
112 int
|
|
113 msg_attr_keep(s, attr, keep)
|
|
114 char_u *s;
|
|
115 int attr;
|
|
116 int keep; /* TRUE: set keep_msg if it doesn't scroll */
|
|
117 {
|
|
118 static int entered = 0;
|
|
119 int retval;
|
|
120 char_u *buf = NULL;
|
|
121
|
|
122 #ifdef FEAT_EVAL
|
|
123 if (attr == 0)
|
|
124 set_vim_var_string(VV_STATUSMSG, s, -1);
|
|
125 #endif
|
|
126
|
|
127 /*
|
|
128 * It is possible that displaying a messages causes a problem (e.g.,
|
|
129 * when redrawing the window), which causes another message, etc.. To
|
|
130 * break this loop, limit the recursiveness to 3 levels.
|
|
131 */
|
|
132 if (entered >= 3)
|
|
133 return TRUE;
|
|
134 ++entered;
|
|
135
|
|
136 /* Add message to history (unless it's a repeated kept message or a
|
|
137 * truncated message) */
|
|
138 if (s != keep_msg
|
|
139 || (*s != '<'
|
|
140 && last_msg_hist != NULL
|
|
141 && last_msg_hist->msg != NULL
|
|
142 && STRCMP(s, last_msg_hist->msg)))
|
|
143 add_msg_hist(s, -1, attr);
|
|
144
|
|
145 /* When displaying keep_msg, don't let msg_start() free it, caller must do
|
|
146 * that. */
|
|
147 if (s == keep_msg)
|
|
148 keep_msg = NULL;
|
|
149
|
|
150 /* Truncate the message if needed. */
|
|
151 buf = msg_strtrunc(s);
|
|
152 if (buf != NULL)
|
|
153 s = buf;
|
|
154
|
|
155 msg_start();
|
|
156 msg_outtrans_attr(s, attr);
|
|
157 msg_clr_eos();
|
|
158 retval = msg_end();
|
|
159
|
|
160 if (keep && retval && vim_strsize(s) < (int)(Rows - cmdline_row - 1)
|
|
161 * Columns + sc_col)
|
|
162 {
|
|
163 set_keep_msg(s);
|
|
164 keep_msg_attr = 0;
|
|
165 }
|
|
166
|
|
167 vim_free(buf);
|
|
168 --entered;
|
|
169 return retval;
|
|
170 }
|
|
171
|
|
172 /*
|
|
173 * Truncate a string such that it can be printed without causing a scroll.
|
|
174 * Returns an allocated string or NULL when no truncating is done.
|
|
175 */
|
|
176 char_u *
|
|
177 msg_strtrunc(s)
|
|
178 char_u *s;
|
|
179 {
|
|
180 char_u *buf = NULL;
|
|
181 int len;
|
|
182 int room;
|
|
183
|
|
184 /* May truncate message to avoid a hit-return prompt */
|
|
185 if (!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL)
|
|
186 && !exmode_active)
|
|
187 {
|
|
188 len = vim_strsize(s);
|
|
189 room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
|
|
190 if (len > room && room > 0)
|
|
191 {
|
|
192 #ifdef FEAT_MBYTE
|
|
193 if (enc_utf8)
|
|
194 /* may have up to 18 bytes per cell (6 per char, up to two
|
|
195 * composing chars) */
|
|
196 buf = alloc((room + 2) * 18);
|
|
197 else if (enc_dbcs == DBCS_JPNU)
|
|
198 /* may have up to 2 bytes per cell for euc-jp */
|
|
199 buf = alloc((room + 2) * 2);
|
|
200 else
|
|
201 #endif
|
|
202 buf = alloc(room + 2);
|
|
203 if (buf != NULL)
|
|
204 trunc_string(s, buf, room);
|
|
205 }
|
|
206 }
|
|
207 return buf;
|
|
208 }
|
|
209
|
|
210 /*
|
|
211 * Truncate a string "s" to "buf" with cell width "room".
|
|
212 * "s" and "buf" may be equal.
|
|
213 */
|
|
214 void
|
|
215 trunc_string(s, buf, room)
|
|
216 char_u *s;
|
|
217 char_u *buf;
|
|
218 int room;
|
|
219 {
|
|
220 int half;
|
|
221 int len;
|
|
222 int e;
|
|
223 int i;
|
|
224 int n;
|
|
225
|
|
226 room -= 3;
|
|
227 half = room / 2;
|
|
228 len = 0;
|
|
229
|
|
230 /* First part: Start of the string. */
|
|
231 for (e = 0; len < half; ++e)
|
|
232 {
|
|
233 if (s[e] == NUL)
|
|
234 {
|
|
235 /* text fits without truncating! */
|
|
236 buf[e] = NUL;
|
|
237 return;
|
|
238 }
|
|
239 n = ptr2cells(s + e);
|
|
240 if (len + n >= half)
|
|
241 break;
|
|
242 len += n;
|
|
243 buf[e] = s[e];
|
|
244 #ifdef FEAT_MBYTE
|
|
245 if (has_mbyte)
|
|
246 for (n = (*mb_ptr2len_check)(s + e); --n > 0; )
|
|
247 {
|
|
248 ++e;
|
|
249 buf[e] = s[e];
|
|
250 }
|
|
251 #endif
|
|
252 }
|
|
253
|
|
254 /* Last part: End of the string. */
|
|
255 i = e;
|
|
256 #ifdef FEAT_MBYTE
|
|
257 if (enc_dbcs != 0)
|
|
258 {
|
|
259 /* For DBCS going backwards in a string is slow, but
|
|
260 * computing the cell width isn't too slow: go forward
|
|
261 * until the rest fits. */
|
|
262 n = vim_strsize(s + i);
|
|
263 while (len + n > room)
|
|
264 {
|
|
265 n -= ptr2cells(s + i);
|
|
266 i += (*mb_ptr2len_check)(s + i);
|
|
267 }
|
|
268 }
|
|
269 else if (enc_utf8)
|
|
270 {
|
|
271 /* For UTF-8 we can go backwards easily. */
|
|
272 i = (int)STRLEN(s);
|
|
273 for (;;)
|
|
274 {
|
|
275 half = i - (*mb_head_off)(s, s + i - 1) - 1;
|
|
276 n = ptr2cells(s + half);
|
|
277 if (len + n > room)
|
|
278 break;
|
|
279 len += n;
|
|
280 i = half;
|
|
281 }
|
|
282 }
|
|
283 else
|
|
284 #endif
|
|
285 {
|
|
286 for (i = (int)STRLEN(s); len + (n = ptr2cells(s + i - 1)) <= room; --i)
|
|
287 len += n;
|
|
288 }
|
|
289
|
|
290 /* Set the middle and copy the last part. */
|
|
291 mch_memmove(buf + e, "...", (size_t)3);
|
|
292 mch_memmove(buf + e + 3, s + i, STRLEN(s + i) + 1);
|
|
293 }
|
|
294
|
|
295 /*
|
|
296 * Automatic prototype generation does not understand this function.
|
|
297 * Note: Caller of smgs() and smsg_attr() must check the resulting string is
|
|
298 * shorter than IOSIZE!!!
|
|
299 */
|
|
300 #ifndef PROTO
|
|
301 # ifndef HAVE_STDARG_H
|
|
302
|
|
303 int
|
|
304 #ifdef __BORLANDC__
|
|
305 _RTLENTRYF
|
|
306 #endif
|
|
307 smsg __ARGS((char_u *, long, long, long,
|
|
308 long, long, long, long, long, long, long));
|
|
309 int
|
|
310 #ifdef __BORLANDC__
|
|
311 _RTLENTRYF
|
|
312 #endif
|
|
313 smsg_attr __ARGS((int, char_u *, long, long, long,
|
|
314 long, long, long, long, long, long, long));
|
|
315
|
|
316 /* VARARGS */
|
|
317 int
|
|
318 #ifdef __BORLANDC__
|
|
319 _RTLENTRYF
|
|
320 #endif
|
|
321 smsg(s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
|
|
322 char_u *s;
|
|
323 long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
|
|
324 {
|
|
325 return smsg_attr(0, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
|
|
326 }
|
|
327
|
|
328 /* VARARGS */
|
|
329 int
|
|
330 #ifdef __BORLANDC__
|
|
331 _RTLENTRYF
|
|
332 #endif
|
|
333 smsg_attr(attr, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
|
|
334 int attr;
|
|
335 char_u *s;
|
|
336 long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
|
|
337 {
|
|
338 sprintf((char *)IObuff, (char *)s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
|
|
339 return msg_attr(IObuff, attr);
|
|
340 }
|
|
341
|
|
342 # else /* HAVE_STDARG_H */
|
|
343
|
|
344 int
|
|
345 #ifdef __BORLANDC__
|
|
346 _RTLENTRYF
|
|
347 #endif
|
|
348 smsg(char_u *s, ...)
|
|
349 {
|
|
350 va_list arglist;
|
|
351
|
|
352 va_start(arglist, s);
|
|
353 # ifdef HAVE_VSNPRINTF
|
|
354 vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist);
|
|
355 # else
|
|
356 vsprintf((char *)IObuff, (char *)s, arglist);
|
|
357 # endif
|
|
358 va_end(arglist);
|
|
359 return msg(IObuff);
|
|
360 }
|
|
361
|
|
362 int
|
|
363 #ifdef __BORLANDC__
|
|
364 _RTLENTRYF
|
|
365 #endif
|
|
366 smsg_attr(int attr, char_u *s, ...)
|
|
367 {
|
|
368 va_list arglist;
|
|
369
|
|
370 va_start(arglist, s);
|
|
371 # ifdef HAVE_VSNPRINTF
|
|
372 vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist);
|
|
373 # else
|
|
374 vsprintf((char *)IObuff, (char *)s, arglist);
|
|
375 # endif
|
|
376 va_end(arglist);
|
|
377 return msg_attr(IObuff, attr);
|
|
378 }
|
|
379
|
|
380 # endif /* HAVE_STDARG_H */
|
|
381 #endif
|
|
382
|
|
383 /*
|
|
384 * Remember the last sourcing name/lnum used in an error message, so that it
|
|
385 * isn't printed each time when it didn't change.
|
|
386 */
|
|
387 static int last_sourcing_lnum = 0;
|
|
388 static char_u *last_sourcing_name = NULL;
|
|
389
|
|
390 /*
|
|
391 * Reset the last used sourcing name/lnum. Makes sure it is displayed again
|
|
392 * for the next error message;
|
|
393 */
|
|
394 static void
|
|
395 reset_last_sourcing()
|
|
396 {
|
|
397 vim_free(last_sourcing_name);
|
|
398 last_sourcing_name = NULL;
|
|
399 last_sourcing_lnum = 0;
|
|
400 }
|
|
401
|
|
402 /*
|
16
|
403 * Return TRUE if "sourcing_name" differs from "last_sourcing_name".
|
|
404 */
|
|
405 static int
|
|
406 other_sourcing_name()
|
|
407 {
|
|
408 if (sourcing_name != NULL)
|
|
409 {
|
|
410 if (last_sourcing_name != NULL)
|
|
411 return STRCMP(sourcing_name, last_sourcing_name) != 0;
|
|
412 return TRUE;
|
|
413 }
|
|
414 return FALSE;
|
|
415 }
|
|
416
|
|
417 /*
|
7
|
418 * Get the message about the source, as used for an error message.
|
|
419 * Returns an allocated string with room for one more character.
|
|
420 * Returns NULL when no message is to be given.
|
|
421 */
|
|
422 static char_u *
|
16
|
423 get_emsg_source()
|
7
|
424 {
|
|
425 char_u *Buf, *p;
|
|
426
|
16
|
427 if (sourcing_name != NULL && other_sourcing_name())
|
7
|
428 {
|
|
429 p = (char_u *)_("Error detected while processing %s:");
|
|
430 Buf = alloc((unsigned)(STRLEN(sourcing_name) + STRLEN(p)));
|
|
431 if (Buf != NULL)
|
|
432 sprintf((char *)Buf, (char *)p, sourcing_name);
|
|
433 return Buf;
|
|
434 }
|
|
435 return NULL;
|
|
436 }
|
|
437
|
|
438 /*
|
|
439 * Get the message about the source lnum, as used for an error message.
|
|
440 * Returns an allocated string with room for one more character.
|
|
441 * Returns NULL when no message is to be given.
|
|
442 */
|
|
443 static char_u *
|
16
|
444 get_emsg_lnum()
|
7
|
445 {
|
|
446 char_u *Buf, *p;
|
|
447
|
|
448 /* lnum is 0 when executing a command from the command line
|
|
449 * argument, we don't want a line number then */
|
|
450 if (sourcing_name != NULL
|
16
|
451 && (other_sourcing_name() || sourcing_lnum != last_sourcing_lnum)
|
7
|
452 && sourcing_lnum != 0)
|
|
453 {
|
|
454 p = (char_u *)_("line %4ld:");
|
|
455 Buf = alloc((unsigned)(STRLEN(p) + 20));
|
|
456 if (Buf != NULL)
|
|
457 sprintf((char *)Buf, (char *)p, (long)sourcing_lnum);
|
|
458 return Buf;
|
|
459 }
|
|
460 return NULL;
|
|
461 }
|
|
462
|
|
463 /*
|
16
|
464 * Display name and line number for the source of an error.
|
|
465 * Remember the file name and line number, so that for the next error the info
|
|
466 * is only displayed if it changed.
|
|
467 */
|
|
468 void
|
|
469 msg_source(attr)
|
|
470 int attr;
|
|
471 {
|
|
472 char_u *p;
|
|
473
|
|
474 ++no_wait_return;
|
|
475 p = get_emsg_source();
|
|
476 if (p != NULL)
|
|
477 {
|
|
478 msg_attr(p, attr);
|
|
479 vim_free(p);
|
|
480 }
|
|
481 p = get_emsg_lnum();
|
|
482 if (p != NULL)
|
|
483 {
|
|
484 msg_attr(p, hl_attr(HLF_N));
|
|
485 vim_free(p);
|
|
486 last_sourcing_lnum = sourcing_lnum; /* only once for each line */
|
|
487 }
|
|
488
|
|
489 /* remember the last sourcing name printed, also when it's empty */
|
36
|
490 if (sourcing_name == NULL || other_sourcing_name())
|
16
|
491 {
|
|
492 vim_free(last_sourcing_name);
|
|
493 if (sourcing_name == NULL)
|
|
494 last_sourcing_name = NULL;
|
|
495 else
|
|
496 last_sourcing_name = vim_strsave(sourcing_name);
|
|
497 }
|
|
498 --no_wait_return;
|
|
499 }
|
|
500
|
|
501 /*
|
7
|
502 * emsg() - display an error message
|
|
503 *
|
|
504 * Rings the bell, if appropriate, and calls message() to do the real work
|
|
505 * When terminal not initialized (yet) mch_errmsg(..) is used.
|
|
506 *
|
|
507 * return TRUE if wait_return not called
|
|
508 */
|
|
509 int
|
|
510 emsg(s)
|
|
511 char_u *s;
|
|
512 {
|
|
513 int attr;
|
|
514 char_u *p;
|
|
515 #ifdef FEAT_EVAL
|
|
516 int ignore = FALSE;
|
|
517 int severe;
|
|
518 #endif
|
|
519
|
|
520 called_emsg = TRUE;
|
|
521
|
|
522 /*
|
|
523 * If "emsg_severe" is TRUE: When an error exception is to be thrown, prefer
|
|
524 * this message over previous messages for the same command.
|
|
525 */
|
|
526 #ifdef FEAT_EVAL
|
|
527 severe = emsg_severe;
|
|
528 emsg_severe = FALSE;
|
|
529 #endif
|
|
530
|
|
531 /*
|
|
532 * If "emsg_off" is set: no error messages at the moment.
|
|
533 * If 'debug' is set: do error message anyway, but without side effects.
|
|
534 * If "emsg_skip" is set: never do error messages.
|
|
535 */
|
|
536 if ((emsg_off > 0 && *p_debug == NUL)
|
|
537 #ifdef FEAT_EVAL
|
|
538 || emsg_skip > 0
|
|
539 #endif
|
|
540 )
|
|
541 return TRUE;
|
|
542
|
|
543 if (!emsg_off)
|
|
544 {
|
|
545 #ifdef FEAT_EVAL
|
|
546 /*
|
|
547 * Cause a throw of an error exception if appropriate. Don't display
|
|
548 * the error message in this case. (If no matching catch clause will
|
|
549 * be found, the message will be displayed later on.) "ignore" is set
|
|
550 * when the message should be ignored completely (used for the
|
|
551 * interrupt message).
|
|
552 */
|
|
553 if (cause_errthrow(s, severe, &ignore) == TRUE)
|
|
554 {
|
|
555 if (!ignore)
|
|
556 did_emsg = TRUE;
|
|
557 return TRUE;
|
|
558 }
|
|
559
|
|
560 /* set "v:errmsg", also when using ":silent! cmd" */
|
|
561 set_vim_var_string(VV_ERRMSG, s, -1);
|
|
562 #endif
|
|
563
|
|
564 /*
|
|
565 * When using ":silent! cmd" ignore error messsages.
|
|
566 * But do write it to the redirection file.
|
|
567 */
|
|
568 if (emsg_silent != 0)
|
|
569 {
|
|
570 msg_start();
|
16
|
571 p = get_emsg_source();
|
7
|
572 if (p != NULL)
|
|
573 {
|
|
574 STRCAT(p, "\n");
|
|
575 redir_write(p, -1);
|
|
576 vim_free(p);
|
|
577 }
|
16
|
578 p = get_emsg_lnum();
|
7
|
579 if (p != NULL)
|
|
580 {
|
|
581 STRCAT(p, "\n");
|
|
582 redir_write(p, -1);
|
|
583 vim_free(p);
|
|
584 }
|
|
585 redir_write(s, -1);
|
|
586 return TRUE;
|
|
587 }
|
|
588
|
|
589 /* Reset msg_silent, an error causes messages to be switched back on. */
|
|
590 msg_silent = 0;
|
|
591 cmd_silent = FALSE;
|
|
592
|
|
593 if (global_busy) /* break :global command */
|
|
594 ++global_busy;
|
|
595
|
|
596 if (p_eb)
|
|
597 beep_flush(); /* also includes flush_buffers() */
|
|
598 else
|
|
599 flush_buffers(FALSE); /* flush internal buffers */
|
|
600 did_emsg = TRUE; /* flag for DoOneCmd() */
|
|
601 }
|
|
602
|
|
603 emsg_on_display = TRUE; /* remember there is an error message */
|
|
604 ++msg_scroll; /* don't overwrite a previous message */
|
|
605 attr = hl_attr(HLF_E); /* set highlight mode for error messages */
|
|
606 if (msg_scrolled)
|
|
607 need_wait_return = TRUE; /* needed in case emsg() is called after
|
|
608 * wait_return has reset need_wait_return
|
|
609 * and a redraw is expected because
|
|
610 * msg_scrolled is non-zero */
|
|
611
|
|
612 /*
|
|
613 * Display name and line number for the source of the error.
|
|
614 */
|
16
|
615 msg_source(attr);
|
7
|
616
|
|
617 /*
|
|
618 * Display the error message itself.
|
|
619 */
|
16
|
620 msg_nowait = FALSE; /* wait for this msg */
|
7
|
621 return msg_attr(s, attr);
|
|
622 }
|
|
623
|
|
624 /*
|
|
625 * Print an error message with one "%s" and one string argument.
|
|
626 */
|
|
627 int
|
|
628 emsg2(s, a1)
|
|
629 char_u *s, *a1;
|
|
630 {
|
|
631 return emsg3(s, a1, NULL);
|
|
632 }
|
|
633
|
|
634 /*
|
|
635 * Print an error message with one or two "%s" and one or two string arguments.
|
|
636 */
|
|
637 int
|
|
638 emsg3(s, a1, a2)
|
|
639 char_u *s, *a1, *a2;
|
|
640 {
|
|
641 if ((emsg_off > 0 && *p_debug == NUL)
|
|
642 #ifdef FEAT_EVAL
|
|
643 || emsg_skip > 0
|
|
644 #endif
|
|
645 )
|
|
646 return TRUE; /* no error messages at the moment */
|
|
647
|
|
648 /* Check for NULL strings (just in case) */
|
|
649 if (a1 == NULL)
|
|
650 a1 = (char_u *)"[NULL]";
|
|
651 if (a2 == NULL)
|
|
652 a2 = (char_u *)"[NULL]";
|
|
653
|
|
654 /* Check for very long strings (can happen with ":help ^A<CR>"). */
|
|
655 if (STRLEN(s) + STRLEN(a1) + STRLEN(a2) >= (size_t)IOSIZE)
|
|
656 a1 = a2 = (char_u *)_("[string too long]");
|
|
657
|
|
658 sprintf((char *)IObuff, (char *)s, (char *)a1, (char *)a2);
|
|
659 return emsg(IObuff);
|
|
660 }
|
|
661
|
|
662 /*
|
|
663 * Print an error message with one "%ld" and one long int argument.
|
|
664 */
|
|
665 int
|
|
666 emsgn(s, n)
|
|
667 char_u *s;
|
|
668 long n;
|
|
669 {
|
|
670 if ((emsg_off > 0 && *p_debug == NUL)
|
|
671 #ifdef FEAT_EVAL
|
|
672 || emsg_skip > 0
|
|
673 #endif
|
|
674 )
|
|
675 return TRUE; /* no error messages at the moment */
|
|
676 sprintf((char *)IObuff, (char *)s, n);
|
|
677 return emsg(IObuff);
|
|
678 }
|
|
679
|
|
680 /*
|
|
681 * Like msg(), but truncate to a single line if p_shm contains 't', or when
|
|
682 * "force" is TRUE. This truncates in another way as for normal messages.
|
|
683 * Careful: The string may be changed by msg_may_trunc()!
|
|
684 * Returns a pointer to the printed message, if wait_return() not called.
|
|
685 */
|
|
686 char_u *
|
|
687 msg_trunc_attr(s, force, attr)
|
|
688 char_u *s;
|
|
689 int force;
|
|
690 int attr;
|
|
691 {
|
|
692 int n;
|
|
693
|
|
694 /* Add message to history before truncating */
|
|
695 add_msg_hist(s, -1, attr);
|
|
696
|
|
697 s = msg_may_trunc(force, s);
|
|
698
|
|
699 msg_hist_off = TRUE;
|
|
700 n = msg_attr(s, attr);
|
|
701 msg_hist_off = FALSE;
|
|
702
|
|
703 if (n)
|
|
704 return s;
|
|
705 return NULL;
|
|
706 }
|
|
707
|
|
708 /*
|
|
709 * Check if message "s" should be truncated at the start (for filenames).
|
|
710 * Return a pointer to where the truncated message starts.
|
|
711 * Note: May change the message by replacing a character with '<'.
|
|
712 */
|
|
713 char_u *
|
|
714 msg_may_trunc(force, s)
|
|
715 int force;
|
|
716 char_u *s;
|
|
717 {
|
|
718 int n;
|
|
719 int room;
|
|
720
|
|
721 room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
|
|
722 if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
|
|
723 && (n = (int)STRLEN(s) - room) > 0)
|
|
724 {
|
|
725 #ifdef FEAT_MBYTE
|
|
726 if (has_mbyte)
|
|
727 {
|
|
728 int size = vim_strsize(s);
|
|
729
|
|
730 for (n = 0; size >= room; )
|
|
731 {
|
|
732 size -= (*mb_ptr2cells)(s + n);
|
|
733 n += (*mb_ptr2len_check)(s + n);
|
|
734 }
|
|
735 --n;
|
|
736 }
|
|
737 #endif
|
|
738 s += n;
|
|
739 *s = '<';
|
|
740 }
|
|
741 return s;
|
|
742 }
|
|
743
|
|
744 static void
|
|
745 add_msg_hist(s, len, attr)
|
|
746 char_u *s;
|
|
747 int len; /* -1 for undetermined length */
|
|
748 int attr;
|
|
749 {
|
|
750 struct msg_hist *p;
|
|
751
|
|
752 if (msg_hist_off || msg_silent != 0)
|
|
753 return;
|
|
754
|
|
755 /* Don't let the message history get too big */
|
|
756 while (msg_hist_len > 20)
|
|
757 {
|
|
758 p = first_msg_hist;
|
|
759 first_msg_hist = p->next;
|
|
760 vim_free(p->msg);
|
|
761 vim_free(p);
|
|
762 --msg_hist_len;
|
|
763 }
|
|
764 /* allocate an entry and add the message at the end of the history */
|
|
765 p = (struct msg_hist *)alloc((int)sizeof(struct msg_hist));
|
|
766 if (p != NULL)
|
|
767 {
|
|
768 if (len < 0)
|
|
769 len = (int)STRLEN(s);
|
|
770 /* remove leading and trailing newlines */
|
|
771 while (len > 0 && *s == '\n')
|
|
772 {
|
|
773 ++s;
|
|
774 --len;
|
|
775 }
|
|
776 while (len > 0 && s[len - 1] == '\n')
|
|
777 --len;
|
|
778 p->msg = vim_strnsave(s, len);
|
|
779 p->next = NULL;
|
|
780 p->attr = attr;
|
|
781 if (last_msg_hist != NULL)
|
|
782 last_msg_hist->next = p;
|
|
783 last_msg_hist = p;
|
|
784 if (first_msg_hist == NULL)
|
|
785 first_msg_hist = last_msg_hist;
|
|
786 ++msg_hist_len;
|
|
787 }
|
|
788 }
|
|
789
|
|
790 /*
|
|
791 * ":messages" command.
|
|
792 */
|
|
793 /*ARGSUSED*/
|
|
794 void
|
|
795 ex_messages(eap)
|
|
796 exarg_T *eap;
|
|
797 {
|
|
798 struct msg_hist *p;
|
|
799 char_u *s;
|
|
800
|
|
801 msg_hist_off = TRUE;
|
|
802
|
|
803 s = mch_getenv((char_u *)"LANG");
|
|
804 if (s != NULL && *s != NUL)
|
|
805 msg_attr((char_u *)
|
|
806 _("Messages maintainer: Bram Moolenaar <Bram@vim.org>"),
|
|
807 hl_attr(HLF_T));
|
|
808
|
|
809 for (p = first_msg_hist; p != NULL; p = p->next)
|
|
810 if (p->msg != NULL)
|
|
811 msg_attr(p->msg, p->attr);
|
|
812
|
|
813 msg_hist_off = FALSE;
|
|
814 }
|
|
815
|
28
|
816 #if defined(FEAT_CON_DIALOG) || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
|
7
|
817 /*
|
|
818 * Call this after prompting the user. This will avoid a hit-return message
|
|
819 * and a delay.
|
|
820 */
|
28
|
821 void
|
7
|
822 msg_end_prompt()
|
|
823 {
|
|
824 need_wait_return = FALSE;
|
|
825 emsg_on_display = FALSE;
|
|
826 cmdline_row = msg_row;
|
|
827 msg_col = 0;
|
|
828 msg_clr_eos();
|
|
829 }
|
|
830 #endif
|
|
831
|
|
832 /*
|
|
833 * wait for the user to hit a key (normally a return)
|
|
834 * if 'redraw' is TRUE, clear and redraw the screen
|
|
835 * if 'redraw' is FALSE, just redraw the screen
|
|
836 * if 'redraw' is -1, don't redraw at all
|
|
837 */
|
|
838 void
|
|
839 wait_return(redraw)
|
|
840 int redraw;
|
|
841 {
|
|
842 int c;
|
|
843 int oldState;
|
|
844 int tmpState;
|
|
845 #ifndef ORG_HITRETURN
|
|
846 int had_got_int;
|
|
847 #endif
|
|
848
|
|
849 if (redraw == TRUE)
|
|
850 must_redraw = CLEAR;
|
|
851
|
|
852 /* If using ":silent cmd", don't wait for a return. Also don't set
|
|
853 * need_wait_return to do it later. */
|
|
854 if (msg_silent != 0)
|
|
855 return;
|
|
856
|
|
857 /*
|
|
858 * With the global command (and some others) we only need one return at the
|
|
859 * end. Adjust cmdline_row to avoid the next message overwriting the last one.
|
|
860 * When inside vgetc(), we can't wait for a typed character at all.
|
|
861 */
|
|
862 if (vgetc_busy)
|
|
863 return;
|
|
864 if (no_wait_return)
|
|
865 {
|
|
866 need_wait_return = TRUE;
|
|
867 if (!exmode_active)
|
|
868 cmdline_row = msg_row;
|
|
869 return;
|
|
870 }
|
|
871
|
|
872 redir_off = TRUE; /* don't redirect this message */
|
|
873 oldState = State;
|
|
874 if (quit_more)
|
|
875 {
|
|
876 c = CAR; /* just pretend CR was hit */
|
|
877 quit_more = FALSE;
|
|
878 got_int = FALSE;
|
|
879 }
|
|
880 else if (exmode_active)
|
|
881 {
|
|
882 MSG_PUTS(" "); /* make sure the cursor is on the right line */
|
|
883 c = CAR; /* no need for a return in ex mode */
|
|
884 got_int = FALSE;
|
|
885 }
|
|
886 else
|
|
887 {
|
|
888 /* Make sure the hit-return prompt is on screen when 'guioptions' was
|
|
889 * just changed. */
|
|
890 screenalloc(FALSE);
|
|
891
|
|
892 State = HITRETURN;
|
|
893 #ifdef FEAT_MOUSE
|
|
894 setmouse();
|
|
895 #endif
|
|
896 #ifdef USE_ON_FLY_SCROLL
|
|
897 dont_scroll = TRUE; /* disallow scrolling here */
|
|
898 #endif
|
|
899 hit_return_msg();
|
|
900
|
|
901 #ifdef ORG_HITRETURN
|
|
902 do
|
|
903 {
|
|
904 c = safe_vgetc();
|
|
905 } while (vim_strchr((char_u *)"\r\n: ", c) == NULL);
|
|
906 if (c == ':') /* this can vi too (but not always!) */
|
|
907 stuffcharReadbuff(c);
|
|
908 #else
|
|
909 do
|
|
910 {
|
|
911 /* Remember "got_int", if it is set vgetc() probably returns a
|
|
912 * CTRL-C, but we need to loop then. */
|
|
913 had_got_int = got_int;
|
|
914 c = safe_vgetc();
|
|
915 if (!global_busy)
|
|
916 got_int = FALSE;
|
|
917 #ifdef FEAT_CLIPBOARD
|
|
918 /* Strange way to allow copying (yanking) a modeless selection at
|
|
919 * the hit-enter prompt. Use CTRL-Y, because the same is used in
|
|
920 * Cmdline-mode and it's harmless when there is no selection. */
|
|
921 if (c == Ctrl_Y && clip_star.state == SELECT_DONE)
|
|
922 {
|
|
923 clip_copy_modeless_selection(TRUE);
|
|
924 c = K_IGNORE;
|
|
925 }
|
|
926 #endif
|
|
927 } while ((had_got_int && c == Ctrl_C)
|
|
928 || c == K_IGNORE
|
|
929 #ifdef FEAT_GUI
|
|
930 || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR
|
|
931 #endif
|
|
932 #ifdef FEAT_MOUSE
|
|
933 || c == K_LEFTDRAG || c == K_LEFTRELEASE
|
|
934 || c == K_MIDDLEDRAG || c == K_MIDDLERELEASE
|
|
935 || c == K_RIGHTDRAG || c == K_RIGHTRELEASE
|
|
936 || c == K_MOUSEDOWN || c == K_MOUSEUP
|
|
937 || (!mouse_has(MOUSE_RETURN)
|
|
938 && mouse_row < msg_row
|
|
939 && (c == K_LEFTMOUSE
|
|
940 || c == K_MIDDLEMOUSE
|
|
941 || c == K_RIGHTMOUSE
|
|
942 || c == K_X1MOUSE
|
|
943 || c == K_X2MOUSE))
|
|
944 #endif
|
|
945 );
|
|
946 ui_breakcheck();
|
|
947 #ifdef FEAT_MOUSE
|
|
948 /*
|
|
949 * Avoid that the mouse-up event causes visual mode to start.
|
|
950 */
|
|
951 if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE
|
|
952 || c == K_X1MOUSE || c == K_X2MOUSE)
|
|
953 (void)jump_to_mouse(MOUSE_SETPOS, NULL, 0);
|
|
954 else
|
|
955 #endif
|
|
956 if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C)
|
|
957 {
|
|
958 stuffcharReadbuff(c);
|
|
959 do_redraw = TRUE; /* need a redraw even though there is
|
|
960 something in the stuff buffer */
|
|
961 }
|
|
962 #endif
|
|
963 }
|
|
964 redir_off = FALSE;
|
|
965
|
|
966 /*
|
|
967 * If the user hits ':', '?' or '/' we get a command line from the next
|
|
968 * line.
|
|
969 */
|
|
970 if (c == ':' || c == '?' || c == '/')
|
|
971 {
|
|
972 if (!exmode_active)
|
|
973 cmdline_row = msg_row;
|
|
974 skip_redraw = TRUE; /* skip redraw once */
|
|
975 do_redraw = FALSE;
|
|
976 }
|
|
977
|
|
978 /*
|
|
979 * If the window size changed set_shellsize() will redraw the screen.
|
|
980 * Otherwise the screen is only redrawn if 'redraw' is set and no ':'
|
|
981 * typed.
|
|
982 */
|
|
983 tmpState = State;
|
|
984 State = oldState; /* restore State before set_shellsize */
|
|
985 #ifdef FEAT_MOUSE
|
|
986 setmouse();
|
|
987 #endif
|
|
988 msg_check();
|
|
989
|
|
990 #if defined(UNIX) || defined(VMS)
|
|
991 /*
|
|
992 * When switching screens, we need to output an extra newline on exit.
|
|
993 */
|
|
994 if (swapping_screen() && !termcap_active)
|
|
995 newline_on_exit = TRUE;
|
|
996 #endif
|
|
997
|
|
998 need_wait_return = FALSE;
|
|
999 did_wait_return = TRUE;
|
|
1000 emsg_on_display = FALSE; /* can delete error message now */
|
|
1001 lines_left = -1; /* reset lines_left at next msg_start() */
|
|
1002 reset_last_sourcing();
|
|
1003 if (keep_msg != NULL && vim_strsize(keep_msg) >=
|
|
1004 (Rows - cmdline_row - 1) * Columns + sc_col)
|
|
1005 {
|
|
1006 vim_free(keep_msg);
|
|
1007 keep_msg = NULL; /* don't redisplay message, it's too long */
|
|
1008 }
|
|
1009
|
|
1010 if (tmpState == SETWSIZE) /* got resize event while in vgetc() */
|
|
1011 {
|
|
1012 starttermcap(); /* start termcap before redrawing */
|
|
1013 shell_resized();
|
|
1014 }
|
|
1015 else if (!skip_redraw
|
|
1016 && (redraw == TRUE || (msg_scrolled != 0 && redraw != -1)))
|
|
1017 {
|
|
1018 starttermcap(); /* start termcap before redrawing */
|
|
1019 redraw_later(VALID);
|
|
1020 }
|
|
1021 }
|
|
1022
|
|
1023 /*
|
|
1024 * Write the hit-return prompt.
|
|
1025 */
|
|
1026 static void
|
|
1027 hit_return_msg()
|
|
1028 {
|
|
1029 if (msg_didout) /* start on a new line */
|
|
1030 msg_putchar('\n');
|
|
1031 if (got_int)
|
|
1032 MSG_PUTS(_("Interrupt: "));
|
|
1033
|
|
1034 #ifdef ORG_HITRETURN
|
|
1035 MSG_PUTS_ATTR(_("Hit ENTER to continue"), hl_attr(HLF_R));
|
|
1036 #else
|
|
1037 MSG_PUTS_ATTR(_("Hit ENTER or type command to continue"), hl_attr(HLF_R));
|
|
1038 #endif
|
|
1039 if (!msg_use_printf())
|
|
1040 msg_clr_eos();
|
|
1041 }
|
|
1042
|
|
1043 /*
|
|
1044 * Set "keep_msg" to "s". Free the old value and check for NULL pointer.
|
|
1045 */
|
|
1046 void
|
|
1047 set_keep_msg(s)
|
|
1048 char_u *s;
|
|
1049 {
|
|
1050 vim_free(keep_msg);
|
|
1051 if (s != NULL && msg_silent == 0)
|
|
1052 keep_msg = vim_strsave(s);
|
|
1053 else
|
|
1054 keep_msg = NULL;
|
|
1055 }
|
|
1056
|
|
1057 /*
|
|
1058 * Prepare for outputting characters in the command line.
|
|
1059 */
|
|
1060 void
|
|
1061 msg_start()
|
|
1062 {
|
|
1063 int did_return = FALSE;
|
|
1064
|
|
1065 vim_free(keep_msg);
|
|
1066 keep_msg = NULL; /* don't display old message now */
|
|
1067 if (!msg_scroll && full_screen) /* overwrite last message */
|
|
1068 {
|
|
1069 msg_row = cmdline_row;
|
|
1070 msg_col =
|
|
1071 #ifdef FEAT_RIGHTLEFT
|
|
1072 cmdmsg_rl ? Columns - 1 :
|
|
1073 #endif
|
|
1074 0;
|
|
1075 }
|
|
1076 else if (msg_didout) /* start message on next line */
|
|
1077 {
|
|
1078 msg_putchar('\n');
|
|
1079 did_return = TRUE;
|
|
1080 if (exmode_active != EXMODE_NORMAL)
|
|
1081 cmdline_row = msg_row;
|
|
1082 }
|
|
1083 if (!msg_didany || lines_left < 0)
|
|
1084 msg_starthere();
|
|
1085 if (msg_silent == 0)
|
|
1086 {
|
|
1087 msg_didout = FALSE; /* no output on current line yet */
|
|
1088 cursor_off();
|
|
1089 }
|
|
1090
|
|
1091 /* when redirecting, may need to start a new line. */
|
|
1092 if (!did_return)
|
|
1093 redir_write((char_u *)"\n", -1);
|
|
1094 }
|
|
1095
|
|
1096 /*
|
|
1097 * Note that the current msg position is where messages start.
|
|
1098 */
|
|
1099 void
|
|
1100 msg_starthere()
|
|
1101 {
|
|
1102 lines_left = cmdline_row;
|
|
1103 msg_didany = FALSE;
|
|
1104 }
|
|
1105
|
|
1106 void
|
|
1107 msg_putchar(c)
|
|
1108 int c;
|
|
1109 {
|
|
1110 msg_putchar_attr(c, 0);
|
|
1111 }
|
|
1112
|
|
1113 void
|
|
1114 msg_putchar_attr(c, attr)
|
|
1115 int c;
|
|
1116 int attr;
|
|
1117 {
|
|
1118 #ifdef FEAT_MBYTE
|
|
1119 char_u buf[MB_MAXBYTES + 1];
|
|
1120 #else
|
|
1121 char_u buf[4];
|
|
1122 #endif
|
|
1123
|
|
1124 if (IS_SPECIAL(c))
|
|
1125 {
|
|
1126 buf[0] = K_SPECIAL;
|
|
1127 buf[1] = K_SECOND(c);
|
|
1128 buf[2] = K_THIRD(c);
|
|
1129 buf[3] = NUL;
|
|
1130 }
|
|
1131 else
|
|
1132 {
|
|
1133 #ifdef FEAT_MBYTE
|
|
1134 buf[(*mb_char2bytes)(c, buf)] = NUL;
|
|
1135 #else
|
|
1136 buf[0] = c;
|
|
1137 buf[1] = NUL;
|
|
1138 #endif
|
|
1139 }
|
|
1140 msg_puts_attr(buf, attr);
|
|
1141 }
|
|
1142
|
|
1143 void
|
|
1144 msg_outnum(n)
|
|
1145 long n;
|
|
1146 {
|
|
1147 char_u buf[20];
|
|
1148
|
|
1149 sprintf((char *)buf, "%ld", n);
|
|
1150 msg_puts(buf);
|
|
1151 }
|
|
1152
|
|
1153 void
|
|
1154 msg_home_replace(fname)
|
|
1155 char_u *fname;
|
|
1156 {
|
|
1157 msg_home_replace_attr(fname, 0);
|
|
1158 }
|
|
1159
|
|
1160 #if defined(FEAT_FIND_ID) || defined(PROTO)
|
|
1161 void
|
|
1162 msg_home_replace_hl(fname)
|
|
1163 char_u *fname;
|
|
1164 {
|
|
1165 msg_home_replace_attr(fname, hl_attr(HLF_D));
|
|
1166 }
|
|
1167 #endif
|
|
1168
|
|
1169 static void
|
|
1170 msg_home_replace_attr(fname, attr)
|
|
1171 char_u *fname;
|
|
1172 int attr;
|
|
1173 {
|
|
1174 char_u *name;
|
|
1175
|
|
1176 name = home_replace_save(NULL, fname);
|
|
1177 if (name != NULL)
|
|
1178 msg_outtrans_attr(name, attr);
|
|
1179 vim_free(name);
|
|
1180 }
|
|
1181
|
|
1182 /*
|
|
1183 * Output 'len' characters in 'str' (including NULs) with translation
|
|
1184 * if 'len' is -1, output upto a NUL character.
|
|
1185 * Use attributes 'attr'.
|
|
1186 * Return the number of characters it takes on the screen.
|
|
1187 */
|
|
1188 int
|
|
1189 msg_outtrans(str)
|
|
1190 char_u *str;
|
|
1191 {
|
|
1192 return msg_outtrans_attr(str, 0);
|
|
1193 }
|
|
1194
|
|
1195 int
|
|
1196 msg_outtrans_attr(str, attr)
|
|
1197 char_u *str;
|
|
1198 int attr;
|
|
1199 {
|
|
1200 return msg_outtrans_len_attr(str, (int)STRLEN(str), attr);
|
|
1201 }
|
|
1202
|
|
1203 int
|
|
1204 msg_outtrans_len(str, len)
|
|
1205 char_u *str;
|
|
1206 int len;
|
|
1207 {
|
|
1208 return msg_outtrans_len_attr(str, len, 0);
|
|
1209 }
|
|
1210
|
|
1211 /*
|
|
1212 * Output one character at "p". Return pointer to the next character.
|
|
1213 * Handles multi-byte characters.
|
|
1214 */
|
|
1215 char_u *
|
|
1216 msg_outtrans_one(p, attr)
|
|
1217 char_u *p;
|
|
1218 int attr;
|
|
1219 {
|
|
1220 #ifdef FEAT_MBYTE
|
|
1221 int l;
|
|
1222
|
|
1223 if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1)
|
|
1224 {
|
|
1225 msg_outtrans_len_attr(p, l, attr);
|
|
1226 return p + l;
|
|
1227 }
|
|
1228 #endif
|
|
1229 msg_puts_attr(transchar_byte(*p), attr);
|
|
1230 return p + 1;
|
|
1231 }
|
|
1232
|
|
1233 int
|
|
1234 msg_outtrans_len_attr(msgstr, len, attr)
|
|
1235 char_u *msgstr;
|
|
1236 int len;
|
|
1237 int attr;
|
|
1238 {
|
|
1239 int retval = 0;
|
|
1240 char_u *str = msgstr;
|
|
1241 char_u *plain_start = msgstr;
|
|
1242 char_u *s;
|
|
1243 #ifdef FEAT_MBYTE
|
|
1244 int mb_l;
|
|
1245 int c;
|
|
1246 #endif
|
|
1247
|
|
1248 /* if MSG_HIST flag set, add message to history */
|
|
1249 if (attr & MSG_HIST)
|
|
1250 {
|
|
1251 add_msg_hist(str, len, attr);
|
|
1252 attr &= ~MSG_HIST;
|
|
1253 }
|
|
1254
|
|
1255 #ifdef FEAT_MBYTE
|
|
1256 /* If the string starts with a composing character first draw a space on
|
|
1257 * which the composing char can be drawn. */
|
|
1258 if (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr)))
|
|
1259 msg_puts_attr((char_u *)" ", attr);
|
|
1260 #endif
|
|
1261
|
|
1262 /*
|
|
1263 * Go over the string. Special characters are translated and printed.
|
|
1264 * Normal characters are printed several at a time.
|
|
1265 */
|
|
1266 while (--len >= 0)
|
|
1267 {
|
|
1268 #ifdef FEAT_MBYTE
|
|
1269 if (enc_utf8)
|
|
1270 /* Don't include composing chars after the end. */
|
|
1271 mb_l = utfc_ptr2len_check_len(str, len + 1);
|
|
1272 else if (has_mbyte)
|
|
1273 mb_l = (*mb_ptr2len_check)(str);
|
|
1274 else
|
|
1275 mb_l = 1;
|
|
1276 if (has_mbyte && mb_l > 1)
|
|
1277 {
|
|
1278 c = (*mb_ptr2char)(str);
|
|
1279 if (vim_isprintc(c))
|
|
1280 /* printable multi-byte char: count the cells. */
|
|
1281 retval += (*mb_ptr2cells)(str);
|
|
1282 else
|
|
1283 {
|
|
1284 /* unprintable multi-byte char: print the printable chars so
|
|
1285 * far and the translation of the unprintable char. */
|
|
1286 if (str > plain_start)
|
|
1287 msg_puts_attr_len(plain_start, (int)(str - plain_start),
|
|
1288 attr);
|
|
1289 plain_start = str + mb_l;
|
|
1290 msg_puts_attr(transchar(c), attr == 0 ? hl_attr(HLF_8) : attr);
|
|
1291 retval += char2cells(c);
|
|
1292 }
|
|
1293 len -= mb_l - 1;
|
|
1294 str += mb_l;
|
|
1295 }
|
|
1296 else
|
|
1297 #endif
|
|
1298 {
|
|
1299 s = transchar_byte(*str);
|
|
1300 if (s[1] != NUL)
|
|
1301 {
|
|
1302 /* unprintable char: print the printable chars so far and the
|
|
1303 * translation of the unprintable char. */
|
|
1304 if (str > plain_start)
|
|
1305 msg_puts_attr_len(plain_start, (int)(str - plain_start),
|
|
1306 attr);
|
|
1307 plain_start = str + 1;
|
|
1308 msg_puts_attr(s, attr == 0 ? hl_attr(HLF_8) : attr);
|
|
1309 }
|
|
1310 retval += ptr2cells(str);
|
|
1311 ++str;
|
|
1312 }
|
|
1313 }
|
|
1314
|
|
1315 if (str > plain_start)
|
|
1316 /* print the printable chars at the end */
|
|
1317 msg_puts_attr_len(plain_start, (int)(str - plain_start), attr);
|
|
1318
|
|
1319 return retval;
|
|
1320 }
|
|
1321
|
|
1322 #if defined(FEAT_QUICKFIX) || defined(PROTO)
|
|
1323 void
|
|
1324 msg_make(arg)
|
|
1325 char_u *arg;
|
|
1326 {
|
|
1327 int i;
|
|
1328 static char_u *str = (char_u *)"eeffoc", *rs = (char_u *)"Plon#dqg#vxjduB";
|
|
1329
|
|
1330 arg = skipwhite(arg);
|
|
1331 for (i = 5; *arg && i >= 0; --i)
|
|
1332 if (*arg++ != str[i])
|
|
1333 break;
|
|
1334 if (i < 0)
|
|
1335 {
|
|
1336 msg_putchar('\n');
|
|
1337 for (i = 0; rs[i]; ++i)
|
|
1338 msg_putchar(rs[i] - 3);
|
|
1339 }
|
|
1340 }
|
|
1341 #endif
|
|
1342
|
|
1343 /*
|
|
1344 * Output the string 'str' upto a NUL character.
|
|
1345 * Return the number of characters it takes on the screen.
|
|
1346 *
|
|
1347 * If K_SPECIAL is encountered, then it is taken in conjunction with the
|
|
1348 * following character and shown as <F1>, <S-Up> etc. Any other character
|
|
1349 * which is not printable shown in <> form.
|
|
1350 * If 'from' is TRUE (lhs of a mapping), a space is shown as <Space>.
|
|
1351 * If a character is displayed in one of these special ways, is also
|
|
1352 * highlighted (its highlight name is '8' in the p_hl variable).
|
|
1353 * Otherwise characters are not highlighted.
|
|
1354 * This function is used to show mappings, where we want to see how to type
|
|
1355 * the character/string -- webb
|
|
1356 */
|
|
1357 int
|
|
1358 msg_outtrans_special(strstart, from)
|
|
1359 char_u *strstart;
|
|
1360 int from; /* TRUE for lhs of a mapping */
|
|
1361 {
|
|
1362 char_u *str = strstart;
|
|
1363 int retval = 0;
|
|
1364 char_u *string;
|
|
1365 int attr;
|
|
1366 int len;
|
|
1367
|
|
1368 attr = hl_attr(HLF_8);
|
|
1369 while (*str != NUL)
|
|
1370 {
|
|
1371 /* Leading and trailing spaces need to be displayed in <> form. */
|
|
1372 if ((str == strstart || str[1] == NUL) && *str == ' ')
|
|
1373 {
|
|
1374 string = (char_u *)"<Space>";
|
|
1375 ++str;
|
|
1376 }
|
|
1377 else
|
|
1378 string = str2special(&str, from);
|
|
1379 len = vim_strsize(string);
|
|
1380 /* Highlight special keys */
|
|
1381 msg_puts_attr(string, len > 1
|
|
1382 #ifdef FEAT_MBYTE
|
|
1383 && (*mb_ptr2len_check)(string) <= 1
|
|
1384 #endif
|
|
1385 ? attr : 0);
|
|
1386 retval += len;
|
|
1387 }
|
|
1388 return retval;
|
|
1389 }
|
|
1390
|
|
1391 /*
|
|
1392 * Return the printable string for the key codes at "*sp".
|
|
1393 * Used for translating the lhs or rhs of a mapping to printable chars.
|
|
1394 * Advances "sp" to the next code.
|
|
1395 */
|
|
1396 char_u *
|
|
1397 str2special(sp, from)
|
|
1398 char_u **sp;
|
|
1399 int from; /* TRUE for lhs of mapping */
|
|
1400 {
|
|
1401 int c;
|
|
1402 static char_u buf[7];
|
|
1403 char_u *str = *sp;
|
|
1404 int modifiers = 0;
|
|
1405 int special = FALSE;
|
|
1406
|
|
1407 #ifdef FEAT_MBYTE
|
|
1408 if (has_mbyte)
|
|
1409 {
|
|
1410 char_u *p;
|
|
1411
|
|
1412 /* Try to un-escape a multi-byte character. Return the un-escaped
|
|
1413 * string if it is a multi-byte character. */
|
|
1414 p = mb_unescape(sp);
|
|
1415 if (p != NULL)
|
|
1416 return p;
|
|
1417 }
|
|
1418 #endif
|
|
1419
|
|
1420 c = *str;
|
|
1421 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
|
|
1422 {
|
|
1423 if (str[1] == KS_MODIFIER)
|
|
1424 {
|
|
1425 modifiers = str[2];
|
|
1426 str += 3;
|
|
1427 c = *str;
|
|
1428 }
|
|
1429 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
|
|
1430 {
|
|
1431 c = TO_SPECIAL(str[1], str[2]);
|
|
1432 str += 2;
|
|
1433 if (c == K_ZERO) /* display <Nul> as ^@ */
|
|
1434 c = NUL;
|
|
1435 }
|
|
1436 if (IS_SPECIAL(c) || modifiers) /* special key */
|
|
1437 special = TRUE;
|
|
1438 }
|
|
1439 *sp = str + 1;
|
|
1440
|
|
1441 #ifdef FEAT_MBYTE
|
|
1442 /* For multi-byte characters check for an illegal byte. */
|
|
1443 if (has_mbyte && MB_BYTE2LEN(*str) > (*mb_ptr2len_check)(str))
|
|
1444 {
|
|
1445 transchar_nonprint(buf, c);
|
|
1446 return buf;
|
|
1447 }
|
|
1448 #endif
|
|
1449
|
|
1450 /* Make unprintable characters in <> form, also <M-Space> and <Tab>.
|
|
1451 * Use <Space> only for lhs of a mapping. */
|
|
1452 if (special || char2cells(c) > 1 || (from && c == ' '))
|
|
1453 return get_special_key_name(c, modifiers);
|
|
1454 buf[0] = c;
|
|
1455 buf[1] = NUL;
|
|
1456 return buf;
|
|
1457 }
|
|
1458
|
|
1459 /*
|
|
1460 * Translate a key sequence into special key names.
|
|
1461 */
|
|
1462 void
|
|
1463 str2specialbuf(sp, buf, len)
|
|
1464 char_u *sp;
|
|
1465 char_u *buf;
|
|
1466 int len;
|
|
1467 {
|
|
1468 char_u *s;
|
|
1469
|
|
1470 *buf = NUL;
|
|
1471 while (*sp)
|
|
1472 {
|
|
1473 s = str2special(&sp, FALSE);
|
|
1474 if ((int)(STRLEN(s) + STRLEN(buf)) < len)
|
|
1475 STRCAT(buf, s);
|
|
1476 }
|
|
1477 }
|
|
1478
|
|
1479 /*
|
|
1480 * print line for :print or :list command
|
|
1481 */
|
|
1482 void
|
|
1483 msg_prt_line(s)
|
|
1484 char_u *s;
|
|
1485 {
|
|
1486 int c;
|
|
1487 int col = 0;
|
|
1488 int n_extra = 0;
|
|
1489 int c_extra = 0;
|
|
1490 char_u *p_extra = NULL; /* init to make SASC shut up */
|
|
1491 int n;
|
|
1492 int attr= 0;
|
|
1493 char_u *trail = NULL;
|
|
1494 #ifdef FEAT_MBYTE
|
|
1495 int l;
|
|
1496 char_u buf[MB_MAXBYTES + 1];
|
|
1497 #endif
|
|
1498
|
|
1499 /* find start of trailing whitespace */
|
|
1500 if (curwin->w_p_list && lcs_trail)
|
|
1501 {
|
|
1502 trail = s + STRLEN(s);
|
|
1503 while (trail > s && vim_iswhite(trail[-1]))
|
|
1504 --trail;
|
|
1505 }
|
|
1506
|
|
1507 /* output a space for an empty line, otherwise the line will be
|
|
1508 * overwritten */
|
|
1509 if (*s == NUL && !(curwin->w_p_list && lcs_eol != NUL))
|
|
1510 msg_putchar(' ');
|
|
1511
|
|
1512 for (;;)
|
|
1513 {
|
|
1514 if (n_extra)
|
|
1515 {
|
|
1516 --n_extra;
|
|
1517 if (c_extra)
|
|
1518 c = c_extra;
|
|
1519 else
|
|
1520 c = *p_extra++;
|
|
1521 }
|
|
1522 #ifdef FEAT_MBYTE
|
|
1523 else if (has_mbyte && (l = (*mb_ptr2len_check)(s)) > 1)
|
|
1524 {
|
|
1525 col += (*mb_ptr2cells)(s);
|
|
1526 mch_memmove(buf, s, (size_t)l);
|
|
1527 buf[l] = NUL;
|
|
1528 msg_puts_attr(buf, attr);
|
|
1529 s += l;
|
|
1530 continue;
|
|
1531 }
|
|
1532 #endif
|
|
1533 else
|
|
1534 {
|
|
1535 attr = 0;
|
|
1536 c = *s++;
|
|
1537 if (c == TAB && (!curwin->w_p_list || lcs_tab1))
|
|
1538 {
|
|
1539 /* tab amount depends on current column */
|
|
1540 n_extra = curbuf->b_p_ts - col % curbuf->b_p_ts - 1;
|
|
1541 if (!curwin->w_p_list)
|
|
1542 {
|
|
1543 c = ' ';
|
|
1544 c_extra = ' ';
|
|
1545 }
|
|
1546 else
|
|
1547 {
|
|
1548 c = lcs_tab1;
|
|
1549 c_extra = lcs_tab2;
|
|
1550 attr = hl_attr(HLF_8);
|
|
1551 }
|
|
1552 }
|
|
1553 else if (c == NUL && curwin->w_p_list && lcs_eol != NUL)
|
|
1554 {
|
|
1555 p_extra = (char_u *)"";
|
|
1556 c_extra = NUL;
|
|
1557 n_extra = 1;
|
|
1558 c = lcs_eol;
|
|
1559 attr = hl_attr(HLF_AT);
|
|
1560 --s;
|
|
1561 }
|
|
1562 else if (c != NUL && (n = byte2cells(c)) > 1)
|
|
1563 {
|
|
1564 n_extra = n - 1;
|
|
1565 p_extra = transchar_byte(c);
|
|
1566 c_extra = NUL;
|
|
1567 c = *p_extra++;
|
|
1568 }
|
|
1569 else if (c == ' ' && trail != NULL && s > trail)
|
|
1570 {
|
|
1571 c = lcs_trail;
|
|
1572 attr = hl_attr(HLF_8);
|
|
1573 }
|
|
1574 }
|
|
1575
|
|
1576 if (c == NUL)
|
|
1577 break;
|
|
1578
|
|
1579 msg_putchar_attr(c, attr);
|
|
1580 col++;
|
|
1581 }
|
|
1582 msg_clr_eos();
|
|
1583 }
|
|
1584
|
|
1585 #ifdef FEAT_MBYTE
|
|
1586 /*
|
|
1587 * Use screen_puts() to output one multi-byte character.
|
|
1588 * Return the pointer "s" advanced to the next character.
|
|
1589 */
|
|
1590 static char_u *
|
|
1591 screen_puts_mbyte(s, l, attr)
|
|
1592 char_u *s;
|
|
1593 int l;
|
|
1594 int attr;
|
|
1595 {
|
|
1596 int cw;
|
|
1597
|
|
1598 msg_didout = TRUE; /* remember that line is not empty */
|
|
1599 cw = (*mb_ptr2cells)(s);
|
|
1600 if (cw > 1 && (
|
|
1601 #ifdef FEAT_RIGHTLEFT
|
|
1602 cmdmsg_rl ? msg_col <= 1 :
|
|
1603 #endif
|
|
1604 msg_col == Columns - 1))
|
|
1605 {
|
|
1606 /* Doesn't fit, print a highlighted '>' to fill it up. */
|
|
1607 msg_screen_putchar('>', hl_attr(HLF_AT));
|
|
1608 return s;
|
|
1609 }
|
|
1610
|
|
1611 screen_puts_len(s, l, msg_row, msg_col, attr);
|
|
1612 #ifdef FEAT_RIGHTLEFT
|
|
1613 if (cmdmsg_rl)
|
|
1614 {
|
|
1615 msg_col -= cw;
|
|
1616 if (msg_col == 0)
|
|
1617 {
|
|
1618 msg_col = Columns;
|
|
1619 ++msg_row;
|
|
1620 }
|
|
1621 }
|
|
1622 else
|
|
1623 #endif
|
|
1624 {
|
|
1625 msg_col += cw;
|
|
1626 if (msg_col >= Columns)
|
|
1627 {
|
|
1628 msg_col = 0;
|
|
1629 ++msg_row;
|
|
1630 }
|
|
1631 }
|
|
1632 return s + l;
|
|
1633 }
|
|
1634 #endif
|
|
1635
|
|
1636 /*
|
|
1637 * Output a string to the screen at position msg_row, msg_col.
|
|
1638 * Update msg_row and msg_col for the next message.
|
|
1639 */
|
|
1640 void
|
|
1641 msg_puts(s)
|
|
1642 char_u *s;
|
|
1643 {
|
|
1644 msg_puts_attr(s, 0);
|
|
1645 }
|
|
1646
|
|
1647 void
|
|
1648 msg_puts_title(s)
|
|
1649 char_u *s;
|
|
1650 {
|
|
1651 msg_puts_attr(s, hl_attr(HLF_T));
|
|
1652 }
|
|
1653
|
|
1654 #if defined(FEAT_CSCOPE) || defined(PROTO)
|
|
1655 /*
|
|
1656 * if printing a string will exceed the screen width, print "..." in the
|
|
1657 * middle.
|
|
1658 */
|
|
1659 void
|
|
1660 msg_puts_long(longstr)
|
|
1661 char_u *longstr;
|
|
1662 {
|
|
1663 msg_puts_long_len_attr(longstr, (int)strlen((char *)longstr), 0);
|
|
1664 }
|
|
1665 #endif
|
|
1666
|
|
1667 /*
|
|
1668 * Show a message in such a way that it always fits in the line. Cut out a
|
|
1669 * part in the middle and replace it with "..." when necessary.
|
|
1670 * Does not handle multi-byte characters!
|
|
1671 */
|
|
1672 void
|
|
1673 msg_puts_long_attr(longstr, attr)
|
|
1674 char_u *longstr;
|
|
1675 int attr;
|
|
1676 {
|
|
1677 msg_puts_long_len_attr(longstr, (int)strlen((char *)longstr), attr);
|
|
1678 }
|
|
1679
|
|
1680 void
|
|
1681 msg_puts_long_len_attr(longstr, len, attr)
|
|
1682 char_u *longstr;
|
|
1683 int len;
|
|
1684 int attr;
|
|
1685 {
|
|
1686 int slen = len;
|
|
1687 int room;
|
|
1688
|
|
1689 room = Columns - msg_col;
|
|
1690 if (len > room && room >= 20)
|
|
1691 {
|
|
1692 slen = (room - 3) / 2;
|
|
1693 msg_outtrans_len_attr(longstr, slen, attr);
|
|
1694 msg_puts_attr((char_u *)"...", hl_attr(HLF_8));
|
|
1695 }
|
|
1696 msg_outtrans_len_attr(longstr + len - slen, slen, attr);
|
|
1697 }
|
|
1698
|
|
1699 /*
|
|
1700 * Basic function for writing a message with highlight attributes.
|
|
1701 */
|
|
1702 void
|
|
1703 msg_puts_attr(s, attr)
|
|
1704 char_u *s;
|
|
1705 int attr;
|
|
1706 {
|
|
1707 msg_puts_attr_len(s, -1, attr);
|
|
1708 }
|
|
1709
|
|
1710 /*
|
|
1711 * Like msg_puts_attr(), but with a maximum length "maxlen" (in bytes).
|
|
1712 * When "maxlen" is -1 there is no maximum length.
|
|
1713 * When "maxlen" is >= 0 the message is not put in the history.
|
|
1714 */
|
|
1715 static void
|
|
1716 msg_puts_attr_len(str, maxlen, attr)
|
|
1717 char_u *str;
|
|
1718 int maxlen;
|
|
1719 int attr;
|
|
1720 {
|
|
1721 int oldState;
|
|
1722 char_u *s = str;
|
|
1723 char_u *p;
|
|
1724 char_u buf[4];
|
|
1725 char_u *t_s = str; /* string from "t_s" to "s" is still todo */
|
|
1726 int t_col = 0; /* screen cells todo, 0 when "t_s" not used */
|
|
1727 #ifdef FEAT_MBYTE
|
|
1728 int l;
|
|
1729 int cw;
|
|
1730 #endif
|
|
1731 int c;
|
|
1732
|
|
1733 /*
|
|
1734 * If redirection is on, also write to the redirection file.
|
|
1735 */
|
|
1736 redir_write(s, maxlen);
|
|
1737
|
|
1738 /*
|
|
1739 * Don't print anything when using ":silent cmd".
|
|
1740 */
|
|
1741 if (msg_silent != 0)
|
|
1742 return;
|
|
1743
|
|
1744 /* if MSG_HIST flag set, add message to history */
|
|
1745 if ((attr & MSG_HIST) && maxlen < 0)
|
|
1746 {
|
|
1747 add_msg_hist(s, -1, attr);
|
|
1748 attr &= ~MSG_HIST;
|
|
1749 }
|
|
1750
|
|
1751 /*
|
|
1752 * When writing something to the screen after it has scrolled, requires a
|
|
1753 * wait-return prompt later. Needed when scrolling, resetting
|
|
1754 * need_wait_return after some prompt, and then outputting something
|
|
1755 * without scrolling
|
|
1756 */
|
|
1757 if (msg_scrolled && !msg_scrolled_ign)
|
|
1758 need_wait_return = TRUE;
|
|
1759 msg_didany = TRUE; /* remember that something was outputted */
|
|
1760
|
|
1761 /*
|
|
1762 * If there is no valid screen, use fprintf so we can see error messages.
|
|
1763 * If termcap is not active, we may be writing in an alternate console
|
|
1764 * window, cursor positioning may not work correctly (window size may be
|
|
1765 * different, e.g. for Win32 console) or we just don't know where the
|
|
1766 * cursor is.
|
|
1767 */
|
|
1768 if (msg_use_printf())
|
|
1769 {
|
|
1770 #ifdef WIN3264
|
|
1771 if (!(silent_mode && p_verbose == 0))
|
|
1772 mch_settmode(TMODE_COOK); /* handle '\r' and '\n' correctly */
|
|
1773 #endif
|
|
1774 while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen))
|
|
1775 {
|
|
1776 if (!(silent_mode && p_verbose == 0))
|
|
1777 {
|
|
1778 p = &buf[0];
|
|
1779 /* NL --> CR NL translation (for Unix, not for "--version") */
|
|
1780 /* NL --> CR translation (for Mac) */
|
|
1781 if (*s == '\n' && !info_message)
|
|
1782 *p++ = '\r';
|
|
1783 #if defined(USE_CR) && !defined(MACOS_X_UNIX)
|
|
1784 else
|
|
1785 #endif
|
|
1786 *p++ = *s;
|
|
1787 *p = '\0';
|
|
1788 if (info_message) /* informative message, not an error */
|
|
1789 mch_msg((char *)buf);
|
|
1790 else
|
|
1791 mch_errmsg((char *)buf);
|
|
1792 }
|
|
1793
|
|
1794 /* primitive way to compute the current column */
|
|
1795 #ifdef FEAT_RIGHTLEFT
|
|
1796 if (cmdmsg_rl)
|
|
1797 {
|
|
1798 if (*s == '\r' || *s == '\n')
|
|
1799 msg_col = Columns - 1;
|
|
1800 else
|
|
1801 --msg_col;
|
|
1802 }
|
|
1803 else
|
|
1804 #endif
|
|
1805 {
|
|
1806 if (*s == '\r' || *s == '\n')
|
|
1807 msg_col = 0;
|
|
1808 else
|
|
1809 ++msg_col;
|
|
1810 }
|
|
1811 ++s;
|
|
1812 }
|
|
1813 msg_didout = TRUE; /* assume that line is not empty */
|
|
1814
|
|
1815 #ifdef WIN3264
|
|
1816 if (!(silent_mode && p_verbose == 0))
|
|
1817 mch_settmode(TMODE_RAW);
|
|
1818 #endif
|
|
1819 return;
|
|
1820 }
|
|
1821
|
|
1822 did_wait_return = FALSE;
|
|
1823 while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen))
|
|
1824 {
|
|
1825 /*
|
|
1826 * The screen is scrolled up when:
|
|
1827 * - When outputting a newline in the last row
|
|
1828 * - when outputting a character in the last column of the last row
|
|
1829 * (some terminals scroll automatically, some don't. To avoid
|
|
1830 * problems we scroll ourselves)
|
|
1831 */
|
|
1832 if (msg_row >= Rows - 1
|
|
1833 && (*s == '\n'
|
|
1834 || (
|
|
1835 #ifdef FEAT_RIGHTLEFT
|
|
1836 cmdmsg_rl
|
|
1837 ? (
|
|
1838 msg_col <= 1
|
|
1839 || (*s == TAB && msg_col <= 7)
|
|
1840 # ifdef FEAT_MBYTE
|
|
1841 || (has_mbyte && (*mb_ptr2cells)(s) > 1 && msg_col <= 2)
|
|
1842 # endif
|
|
1843 )
|
|
1844 :
|
|
1845 #endif
|
|
1846 (msg_col + t_col >= Columns - 1
|
|
1847 || (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7))
|
|
1848 # ifdef FEAT_MBYTE
|
|
1849 || (has_mbyte && (*mb_ptr2cells)(s) > 1
|
|
1850 && msg_col + t_col >= Columns - 2)
|
|
1851 # endif
|
|
1852 ))))
|
|
1853 {
|
|
1854 if (t_col > 0)
|
|
1855 {
|
|
1856 /* output postponed text */
|
|
1857 t_puts(t_col, t_s, s, attr);
|
|
1858 t_col = 0;
|
|
1859 }
|
|
1860
|
|
1861 /* When no more prompt an no more room, truncate here */
|
|
1862 if (msg_no_more && lines_left == 0)
|
|
1863 break;
|
|
1864 #ifdef FEAT_GUI
|
|
1865 /* Remove the cursor before scrolling, ScreenLines[] is going to
|
|
1866 * become invalid. */
|
|
1867 if (gui.in_use)
|
|
1868 gui_undraw_cursor();
|
|
1869 #endif
|
|
1870 /* scrolling up always works */
|
|
1871 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL);
|
|
1872
|
|
1873 if (!can_clear((char_u *)" "))
|
|
1874 {
|
|
1875 /* Scrolling up doesn't result in the right background. Set
|
|
1876 * the background here. It's not efficient, but avoids that
|
|
1877 * we have to do it all over the code. */
|
|
1878 screen_fill((int)Rows - 1, (int)Rows, 0,
|
|
1879 (int)Columns, ' ', ' ', 0);
|
|
1880
|
|
1881 /* Also clear the last char of the last but one line if it was
|
|
1882 * not cleared before to avoid a scroll-up. */
|
|
1883 if (ScreenAttrs[LineOffset[Rows - 2] + Columns - 1]
|
|
1884 == (sattr_T)-1)
|
|
1885 screen_fill((int)Rows - 2, (int)Rows - 1,
|
|
1886 (int)Columns - 1, (int)Columns, ' ', ' ', 0);
|
|
1887 }
|
|
1888
|
|
1889 msg_row = Rows - 2;
|
|
1890 if (msg_col >= Columns) /* can happen after screen resize */
|
|
1891 msg_col = Columns - 1;
|
|
1892
|
|
1893 ++msg_scrolled;
|
|
1894 need_wait_return = TRUE; /* may need wait_return in main() */
|
|
1895 if (must_redraw < VALID)
|
|
1896 must_redraw = VALID;
|
|
1897 redraw_cmdline = TRUE;
|
|
1898 if (cmdline_row > 0 && !exmode_active)
|
|
1899 --cmdline_row;
|
|
1900
|
|
1901 /*
|
|
1902 * if screen is completely filled wait for a character
|
|
1903 */
|
|
1904 if (p_more && --lines_left == 0 && State != HITRETURN
|
|
1905 && !msg_no_more && !exmode_active)
|
|
1906 {
|
|
1907 oldState = State;
|
|
1908 State = ASKMORE;
|
|
1909 #ifdef FEAT_MOUSE
|
|
1910 setmouse();
|
|
1911 #endif
|
|
1912 msg_moremsg(FALSE);
|
|
1913 for (;;)
|
|
1914 {
|
|
1915 /*
|
|
1916 * Get a typed character directly from the user.
|
|
1917 */
|
|
1918 c = get_keystroke();
|
|
1919
|
|
1920 #if defined(FEAT_MENU) && defined(FEAT_GUI)
|
|
1921 if (c == K_MENU)
|
|
1922 {
|
|
1923 int idx = get_menu_index(current_menu, ASKMORE);
|
|
1924
|
|
1925 /* Used a menu. If it starts with CTRL-Y, it must
|
|
1926 * be a "Copy" for the clipboard. Otherwise
|
|
1927 * assume that we end */
|
|
1928 if (idx == MENU_INDEX_INVALID)
|
|
1929 continue;
|
|
1930 c = *current_menu->strings[idx];
|
|
1931 if (c != NUL && current_menu->strings[idx][1] != NUL)
|
|
1932 ins_typebuf(current_menu->strings[idx] + 1,
|
|
1933 current_menu->noremap[idx], 0, TRUE,
|
|
1934 current_menu->silent[idx]);
|
|
1935 }
|
|
1936 #endif
|
|
1937
|
|
1938 switch (c)
|
|
1939 {
|
|
1940 case BS:
|
|
1941 case 'k':
|
|
1942 case K_UP:
|
|
1943 if (!more_back_used)
|
|
1944 {
|
|
1945 msg_moremsg(TRUE);
|
|
1946 continue;
|
|
1947 }
|
|
1948 more_back = 1;
|
|
1949 lines_left = 1;
|
|
1950 break;
|
|
1951 case CAR: /* one extra line */
|
|
1952 case NL:
|
|
1953 case 'j':
|
|
1954 case K_DOWN:
|
|
1955 lines_left = 1;
|
|
1956 break;
|
|
1957 case ':': /* start new command line */
|
|
1958 #ifdef FEAT_CON_DIALOG
|
|
1959 if (!confirm_msg_used)
|
|
1960 #endif
|
|
1961 {
|
|
1962 /* Since got_int is set all typeahead will be
|
|
1963 * flushed, but we want to keep this ':', remember
|
|
1964 * that in a special way. */
|
|
1965 typeahead_noflush(':');
|
|
1966 cmdline_row = Rows - 1; /* put ':' on this line */
|
|
1967 skip_redraw = TRUE; /* skip redraw once */
|
|
1968 need_wait_return = FALSE; /* don't wait in main() */
|
|
1969 }
|
|
1970 /*FALLTHROUGH*/
|
|
1971 case 'q': /* quit */
|
|
1972 case Ctrl_C:
|
|
1973 case ESC:
|
|
1974 #ifdef FEAT_CON_DIALOG
|
|
1975 if (confirm_msg_used)
|
|
1976 {
|
|
1977 /* Jump to the choices of the dialog. */
|
|
1978 s = confirm_msg_tail;
|
|
1979 lines_left = Rows - 1;
|
|
1980 }
|
|
1981 else
|
|
1982 #endif
|
|
1983 {
|
|
1984 got_int = TRUE;
|
|
1985 quit_more = TRUE;
|
|
1986 }
|
|
1987 break;
|
|
1988 case 'u': /* Up half a page */
|
|
1989 case K_PAGEUP:
|
|
1990 if (!more_back_used)
|
|
1991 {
|
|
1992 msg_moremsg(TRUE);
|
|
1993 continue;
|
|
1994 }
|
|
1995 more_back = Rows / 2;
|
|
1996 /*FALLTHROUGH*/
|
|
1997 case 'd': /* Down half a page */
|
|
1998 lines_left = Rows / 2;
|
|
1999 break;
|
|
2000 case 'b': /* one page back */
|
|
2001 if (!more_back_used)
|
|
2002 {
|
|
2003 msg_moremsg(TRUE);
|
|
2004 continue;
|
|
2005 }
|
|
2006 more_back = Rows - 1;
|
|
2007 /*FALLTHROUGH*/
|
|
2008 case ' ': /* one extra page */
|
|
2009 case K_PAGEDOWN:
|
|
2010 case K_LEFTMOUSE:
|
|
2011 lines_left = Rows - 1;
|
|
2012 break;
|
|
2013
|
|
2014 #ifdef FEAT_CLIPBOARD
|
|
2015 case Ctrl_Y:
|
|
2016 /* Strange way to allow copying (yanking) a modeless
|
|
2017 * selection at the more prompt. Use CTRL-Y,
|
|
2018 * because the same is used in Cmdline-mode and at the
|
|
2019 * hit-enter prompt. However, scrolling one line up
|
|
2020 * might be expected... */
|
|
2021 if (clip_star.state == SELECT_DONE)
|
|
2022 clip_copy_modeless_selection(TRUE);
|
|
2023 continue;
|
|
2024 #endif
|
|
2025 default: /* no valid response */
|
|
2026 msg_moremsg(TRUE);
|
|
2027 continue;
|
|
2028 }
|
|
2029 break;
|
|
2030 }
|
|
2031
|
|
2032 /* clear the --more-- message */
|
|
2033 screen_fill((int)Rows - 1, (int)Rows,
|
|
2034 0, (int)Columns, ' ', ' ', 0);
|
|
2035 State = oldState;
|
|
2036 #ifdef FEAT_MOUSE
|
|
2037 setmouse();
|
|
2038 #endif
|
|
2039 if (quit_more)
|
|
2040 {
|
|
2041 msg_row = Rows - 1;
|
|
2042 msg_col = 0;
|
|
2043 return; /* the string is not displayed! */
|
|
2044 }
|
|
2045 #ifdef FEAT_RIGHTLEFT
|
|
2046 if (cmdmsg_rl)
|
|
2047 msg_col = Columns - 1;
|
|
2048 #endif
|
|
2049 }
|
|
2050 }
|
|
2051
|
|
2052 if (t_col > 0
|
|
2053 && (vim_strchr((char_u *)"\n\r\b\t", *s) != NULL
|
|
2054 || *s == BELL
|
|
2055 || msg_col + t_col >= Columns
|
|
2056 #ifdef FEAT_MBYTE
|
|
2057 || (has_mbyte && (*mb_ptr2cells)(s) > 1
|
|
2058 && msg_col + t_col >= Columns - 1)
|
|
2059 #endif
|
|
2060 ))
|
|
2061 {
|
|
2062 /* output any postponed text */
|
|
2063 t_puts(t_col, t_s, s, attr);
|
|
2064 t_col = 0;
|
|
2065 }
|
|
2066
|
|
2067 if (*s == '\n') /* go to next line */
|
|
2068 {
|
|
2069 msg_didout = FALSE; /* remember that line is empty */
|
|
2070 msg_col = 0;
|
|
2071 if (++msg_row >= Rows) /* safety check */
|
|
2072 msg_row = Rows - 1;
|
|
2073 }
|
|
2074 else if (*s == '\r') /* go to column 0 */
|
|
2075 {
|
|
2076 msg_col = 0;
|
|
2077 }
|
|
2078 else if (*s == '\b') /* go to previous char */
|
|
2079 {
|
|
2080 if (msg_col)
|
|
2081 --msg_col;
|
|
2082 }
|
|
2083 else if (*s == TAB) /* translate into spaces */
|
|
2084 {
|
|
2085 do
|
|
2086 msg_screen_putchar(' ', attr);
|
|
2087 while (msg_col & 7);
|
|
2088 }
|
|
2089 else if (*s == BELL) /* beep (from ":sh") */
|
|
2090 vim_beep();
|
|
2091 else
|
|
2092 {
|
|
2093 #ifdef FEAT_MBYTE
|
|
2094 if (has_mbyte)
|
|
2095 {
|
|
2096 cw = (*mb_ptr2cells)(s);
|
|
2097 if (enc_utf8 && maxlen >= 0)
|
|
2098 /* avoid including composing chars after the end */
|
|
2099 l = utfc_ptr2len_check_len(s, (int)((str + maxlen) - s));
|
|
2100 else
|
|
2101 l = (*mb_ptr2len_check)(s);
|
|
2102 }
|
|
2103 else
|
|
2104 {
|
|
2105 cw = 1;
|
|
2106 l = 1;
|
|
2107 }
|
|
2108 #endif
|
|
2109 /* When drawing from right to left or when a double-wide character
|
|
2110 * doesn't fit, draw a single character here. Otherwise collect
|
|
2111 * characters and draw them all at once later. */
|
|
2112 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
|
|
2113 if (
|
|
2114 # ifdef FEAT_RIGHTLEFT
|
|
2115 cmdmsg_rl
|
|
2116 # ifdef FEAT_MBYTE
|
|
2117 ||
|
|
2118 # endif
|
|
2119 # endif
|
|
2120 # ifdef FEAT_MBYTE
|
|
2121 (cw > 1 && msg_col + t_col >= Columns - 1)
|
|
2122 # endif
|
|
2123 )
|
|
2124 {
|
|
2125 # ifdef FEAT_MBYTE
|
|
2126 if (l > 1)
|
|
2127 s = screen_puts_mbyte(s, l, attr) - 1;
|
|
2128 else
|
|
2129 # endif
|
|
2130 msg_screen_putchar(*s, attr);
|
|
2131 }
|
|
2132 else
|
|
2133 #endif
|
|
2134 {
|
|
2135 /* postpone this character until later */
|
|
2136 if (t_col == 0)
|
|
2137 t_s = s;
|
|
2138 #ifdef FEAT_MBYTE
|
|
2139 t_col += cw;
|
|
2140 s += l - 1;
|
|
2141 #else
|
|
2142 ++t_col;
|
|
2143 #endif
|
|
2144 }
|
|
2145 }
|
|
2146 ++s;
|
|
2147 }
|
|
2148
|
|
2149 /* output any postponed text */
|
|
2150 if (t_col > 0)
|
|
2151 t_puts(t_col, t_s, s, attr);
|
|
2152
|
|
2153 msg_check();
|
|
2154 }
|
|
2155
|
|
2156 /*
|
|
2157 * Output any postponed text for msg_puts_attr_len().
|
|
2158 */
|
|
2159 static void
|
|
2160 t_puts(t_col, t_s, s, attr)
|
|
2161 int t_col;
|
|
2162 char_u *t_s;
|
|
2163 char_u *s;
|
|
2164 int attr;
|
|
2165 {
|
|
2166 /* output postponed text */
|
|
2167 msg_didout = TRUE; /* remember that line is not empty */
|
|
2168 screen_puts_len(t_s, (int)(s - t_s), msg_row, msg_col, attr);
|
|
2169 msg_col += t_col;
|
|
2170 #ifdef FEAT_MBYTE
|
|
2171 /* If the string starts with a composing character don't increment the
|
|
2172 * column position for it. */
|
|
2173 if (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s)))
|
|
2174 --msg_col;
|
|
2175 #endif
|
|
2176 if (msg_col >= Columns)
|
|
2177 {
|
|
2178 msg_col = 0;
|
|
2179 ++msg_row;
|
|
2180 }
|
|
2181 }
|
|
2182
|
|
2183
|
|
2184 /*
|
|
2185 * Returns TRUE when messages should be printed with mch_errmsg().
|
|
2186 * This is used when there is no valid screen, so we can see error messages.
|
|
2187 * If termcap is not active, we may be writing in an alternate console
|
|
2188 * window, cursor positioning may not work correctly (window size may be
|
|
2189 * different, e.g. for Win32 console) or we just don't know where the
|
|
2190 * cursor is.
|
|
2191 */
|
|
2192 int
|
|
2193 msg_use_printf()
|
|
2194 {
|
|
2195 return (!msg_check_screen()
|
|
2196 #if defined(WIN3264) && !defined(FEAT_GUI_MSWIN)
|
|
2197 || !termcap_active
|
|
2198 #endif
|
|
2199 || (swapping_screen() && !termcap_active)
|
|
2200 );
|
|
2201 }
|
|
2202
|
|
2203 #if defined(USE_MCH_ERRMSG) || defined(PROTO)
|
|
2204
|
|
2205 #ifdef mch_errmsg
|
|
2206 # undef mch_errmsg
|
|
2207 #endif
|
|
2208 #ifdef mch_msg
|
|
2209 # undef mch_msg
|
|
2210 #endif
|
|
2211
|
|
2212 /*
|
|
2213 * Give an error message. To be used when the screen hasn't been initialized
|
|
2214 * yet. When stderr can't be used, collect error messages until the GUI has
|
|
2215 * started and they can be displayed in a message box.
|
|
2216 */
|
|
2217 void
|
|
2218 mch_errmsg(str)
|
|
2219 char *str;
|
|
2220 {
|
|
2221 int len;
|
|
2222
|
|
2223 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
|
|
2224 /* On Unix use stderr if it's a tty.
|
|
2225 * When not going to start the GUI also use stderr.
|
|
2226 * On Mac, when started from Finder, stderr is the console. */
|
|
2227 if (
|
|
2228 # ifdef UNIX
|
|
2229 # ifdef MACOS_X_UNIX
|
|
2230 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0)
|
|
2231 # else
|
|
2232 isatty(2)
|
|
2233 # endif
|
|
2234 # ifdef FEAT_GUI
|
|
2235 ||
|
|
2236 # endif
|
|
2237 # endif
|
|
2238 # ifdef FEAT_GUI
|
|
2239 !(gui.in_use || gui.starting)
|
|
2240 # endif
|
|
2241 )
|
|
2242 {
|
|
2243 fprintf(stderr, "%s", str);
|
|
2244 return;
|
|
2245 }
|
|
2246 #endif
|
|
2247
|
|
2248 /* avoid a delay for a message that isn't there */
|
|
2249 emsg_on_display = FALSE;
|
|
2250
|
|
2251 len = (int)STRLEN(str) + 1;
|
|
2252 if (error_ga.ga_growsize == 0)
|
|
2253 {
|
|
2254 error_ga.ga_growsize = 80;
|
|
2255 error_ga.ga_itemsize = 1;
|
|
2256 }
|
|
2257 if (ga_grow(&error_ga, len) == OK)
|
|
2258 {
|
|
2259 mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len,
|
|
2260 (char_u *)str, len);
|
|
2261 #ifdef UNIX
|
|
2262 /* remove CR characters, they are displayed */
|
|
2263 {
|
|
2264 char_u *p;
|
|
2265
|
|
2266 p = (char_u *)error_ga.ga_data + error_ga.ga_len;
|
|
2267 for (;;)
|
|
2268 {
|
|
2269 p = vim_strchr(p, '\r');
|
|
2270 if (p == NULL)
|
|
2271 break;
|
|
2272 *p = ' ';
|
|
2273 }
|
|
2274 }
|
|
2275 #endif
|
|
2276 --len; /* don't count the NUL at the end */
|
|
2277 error_ga.ga_len += len;
|
|
2278 }
|
|
2279 }
|
|
2280
|
|
2281 /*
|
|
2282 * Give a message. To be used when the screen hasn't been initialized yet.
|
|
2283 * When there is no tty, collect messages until the GUI has started and they
|
|
2284 * can be displayed in a message box.
|
|
2285 */
|
|
2286 void
|
|
2287 mch_msg(str)
|
|
2288 char *str;
|
|
2289 {
|
|
2290 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
|
|
2291 /* On Unix use stdout if we have a tty. This allows "vim -h | more" and
|
|
2292 * uses mch_errmsg() when started from the desktop.
|
|
2293 * When not going to start the GUI also use stdout.
|
|
2294 * On Mac, when started from Finder, stderr is the console. */
|
|
2295 if (
|
|
2296 # ifdef UNIX
|
|
2297 # ifdef MACOS_X_UNIX
|
|
2298 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0)
|
|
2299 # else
|
|
2300 isatty(2)
|
|
2301 # endif
|
|
2302 # ifdef FEAT_GUI
|
|
2303 ||
|
|
2304 # endif
|
|
2305 # endif
|
|
2306 # ifdef FEAT_GUI
|
|
2307 !(gui.in_use || gui.starting)
|
|
2308 # endif
|
|
2309 )
|
|
2310 {
|
|
2311 printf("%s", str);
|
|
2312 return;
|
|
2313 }
|
|
2314 # endif
|
|
2315 mch_errmsg(str);
|
|
2316 }
|
|
2317 #endif /* USE_MCH_ERRMSG */
|
|
2318
|
|
2319 /*
|
|
2320 * Put a character on the screen at the current message position and advance
|
|
2321 * to the next position. Only for printable ASCII!
|
|
2322 */
|
|
2323 static void
|
|
2324 msg_screen_putchar(c, attr)
|
|
2325 int c;
|
|
2326 int attr;
|
|
2327 {
|
|
2328 msg_didout = TRUE; /* remember that line is not empty */
|
|
2329 screen_putchar(c, msg_row, msg_col, attr);
|
|
2330 #ifdef FEAT_RIGHTLEFT
|
|
2331 if (cmdmsg_rl)
|
|
2332 {
|
|
2333 if (--msg_col == 0)
|
|
2334 {
|
|
2335 msg_col = Columns;
|
|
2336 ++msg_row;
|
|
2337 }
|
|
2338 }
|
|
2339 else
|
|
2340 #endif
|
|
2341 {
|
|
2342 if (++msg_col >= Columns)
|
|
2343 {
|
|
2344 msg_col = 0;
|
|
2345 ++msg_row;
|
|
2346 }
|
|
2347 }
|
|
2348 }
|
|
2349
|
|
2350 void
|
|
2351 msg_moremsg(full)
|
|
2352 int full;
|
|
2353 {
|
|
2354 int attr;
|
|
2355
|
|
2356 attr = hl_attr(HLF_M);
|
|
2357 screen_puts((char_u *)_("-- More --"), (int)Rows - 1, 0, attr);
|
|
2358 if (full)
|
|
2359 screen_puts(more_back_used
|
|
2360 ? (char_u *)_(" (RET/BS: line, SPACE/b: page, d/u: half page, q: quit)")
|
|
2361 : (char_u *)_(" (RET: line, SPACE: page, d: half page, q: quit)"),
|
|
2362 (int)Rows - 1, 10, attr);
|
|
2363 }
|
|
2364
|
|
2365 /*
|
|
2366 * Repeat the message for the current mode: ASKMORE, EXTERNCMD, CONFIRM or
|
|
2367 * exmode_active.
|
|
2368 */
|
|
2369 void
|
|
2370 repeat_message()
|
|
2371 {
|
|
2372 if (State == ASKMORE)
|
|
2373 {
|
|
2374 msg_moremsg(TRUE); /* display --more-- message again */
|
|
2375 msg_row = Rows - 1;
|
|
2376 }
|
|
2377 #ifdef FEAT_CON_DIALOG
|
|
2378 else if (State == CONFIRM)
|
|
2379 {
|
|
2380 display_confirm_msg(); /* display ":confirm" message again */
|
|
2381 msg_row = Rows - 1;
|
|
2382 }
|
|
2383 #endif
|
|
2384 else if (State == EXTERNCMD)
|
|
2385 {
|
|
2386 windgoto(msg_row, msg_col); /* put cursor back */
|
|
2387 }
|
|
2388 else if (State == HITRETURN || State == SETWSIZE)
|
|
2389 {
|
|
2390 hit_return_msg();
|
|
2391 msg_row = Rows - 1;
|
|
2392 }
|
|
2393 }
|
|
2394
|
|
2395 /*
|
|
2396 * msg_check_screen - check if the screen is initialized.
|
|
2397 * Also check msg_row and msg_col, if they are too big it may cause a crash.
|
|
2398 * While starting the GUI the terminal codes will be set for the GUI, but the
|
|
2399 * output goes to the terminal. Don't use the terminal codes then.
|
|
2400 */
|
|
2401 static int
|
|
2402 msg_check_screen()
|
|
2403 {
|
|
2404 if (!full_screen || !screen_valid(FALSE))
|
|
2405 return FALSE;
|
|
2406
|
|
2407 if (msg_row >= Rows)
|
|
2408 msg_row = Rows - 1;
|
|
2409 if (msg_col >= Columns)
|
|
2410 msg_col = Columns - 1;
|
|
2411 return TRUE;
|
|
2412 }
|
|
2413
|
|
2414 /*
|
|
2415 * Clear from current message position to end of screen.
|
|
2416 * Skip this when ":silent" was used, no need to clear for redirection.
|
|
2417 */
|
|
2418 void
|
|
2419 msg_clr_eos()
|
|
2420 {
|
|
2421 if (msg_silent == 0)
|
|
2422 msg_clr_eos_force();
|
|
2423 }
|
|
2424
|
|
2425 /*
|
|
2426 * Clear from current message position to end of screen.
|
|
2427 * Note: msg_col is not updated, so we remember the end of the message
|
|
2428 * for msg_check().
|
|
2429 */
|
|
2430 void
|
|
2431 msg_clr_eos_force()
|
|
2432 {
|
|
2433 if (msg_use_printf())
|
|
2434 {
|
|
2435 if (full_screen) /* only when termcap codes are valid */
|
|
2436 {
|
|
2437 if (*T_CD)
|
|
2438 out_str(T_CD); /* clear to end of display */
|
|
2439 else if (*T_CE)
|
|
2440 out_str(T_CE); /* clear to end of line */
|
|
2441 }
|
|
2442 }
|
|
2443 else
|
|
2444 {
|
|
2445 #ifdef FEAT_RIGHTLEFT
|
|
2446 if (cmdmsg_rl)
|
|
2447 {
|
|
2448 screen_fill(msg_row, msg_row + 1, 0, msg_col + 1, ' ', ' ', 0);
|
|
2449 screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
|
|
2450 }
|
|
2451 else
|
|
2452 #endif
|
|
2453 {
|
|
2454 screen_fill(msg_row, msg_row + 1, msg_col, (int)Columns,
|
|
2455 ' ', ' ', 0);
|
|
2456 screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
|
|
2457 }
|
|
2458 }
|
|
2459 }
|
|
2460
|
|
2461 /*
|
|
2462 * Clear the command line.
|
|
2463 */
|
|
2464 void
|
|
2465 msg_clr_cmdline()
|
|
2466 {
|
|
2467 msg_row = cmdline_row;
|
|
2468 msg_col = 0;
|
|
2469 msg_clr_eos_force();
|
|
2470 }
|
|
2471
|
|
2472 /*
|
|
2473 * end putting a message on the screen
|
|
2474 * call wait_return if the message does not fit in the available space
|
|
2475 * return TRUE if wait_return not called.
|
|
2476 */
|
|
2477 int
|
|
2478 msg_end()
|
|
2479 {
|
|
2480 /*
|
|
2481 * if the string is larger than the window,
|
|
2482 * or the ruler option is set and we run into it,
|
|
2483 * we have to redraw the window.
|
|
2484 * Do not do this if we are abandoning the file or editing the command line.
|
|
2485 */
|
|
2486 if (!exiting && need_wait_return && !(State & CMDLINE))
|
|
2487 {
|
|
2488 wait_return(FALSE);
|
|
2489 return FALSE;
|
|
2490 }
|
|
2491 out_flush();
|
|
2492 return TRUE;
|
|
2493 }
|
|
2494
|
|
2495 /*
|
|
2496 * If the written message runs into the shown command or ruler, we have to
|
|
2497 * wait for hit-return and redraw the window later.
|
|
2498 */
|
|
2499 void
|
|
2500 msg_check()
|
|
2501 {
|
|
2502 if (msg_row == Rows - 1 && msg_col >= sc_col)
|
|
2503 {
|
|
2504 need_wait_return = TRUE;
|
|
2505 redraw_cmdline = TRUE;
|
|
2506 }
|
|
2507 }
|
|
2508
|
|
2509 /*
|
|
2510 * May write a string to the redirection file.
|
|
2511 * When "maxlen" is -1 write the whole string, otherwise up to "maxlen" bytes.
|
|
2512 */
|
|
2513 static void
|
|
2514 redir_write(str, maxlen)
|
|
2515 char_u *str;
|
|
2516 int maxlen;
|
|
2517 {
|
|
2518 char_u *s = str;
|
|
2519 static int cur_col = 0;
|
|
2520
|
|
2521 if ((redir_fd != NULL
|
|
2522 #ifdef FEAT_EVAL
|
|
2523 || redir_reg
|
|
2524 #endif
|
|
2525 ) && !redir_off)
|
|
2526 {
|
|
2527 /* If the string doesn't start with CR or NL, go to msg_col */
|
|
2528 if (*s != '\n' && *s != '\r')
|
|
2529 {
|
|
2530 while (cur_col < msg_col)
|
|
2531 {
|
|
2532 #ifdef FEAT_EVAL
|
|
2533 if (redir_reg)
|
|
2534 write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE);
|
|
2535 else if (redir_fd)
|
|
2536 #endif
|
|
2537 fputs(" ", redir_fd);
|
|
2538 ++cur_col;
|
|
2539 }
|
|
2540 }
|
|
2541
|
|
2542 #ifdef FEAT_EVAL
|
|
2543 if (redir_reg)
|
|
2544 write_reg_contents(redir_reg, s, maxlen, TRUE);
|
|
2545 #endif
|
|
2546
|
|
2547 /* Adjust the current column */
|
|
2548 while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen))
|
|
2549 {
|
|
2550 #ifdef FEAT_EVAL
|
|
2551 if (!redir_reg && redir_fd != NULL)
|
|
2552 #endif
|
|
2553 putc(*s, redir_fd);
|
|
2554 if (*s == '\r' || *s == '\n')
|
|
2555 cur_col = 0;
|
|
2556 else if (*s == '\t')
|
|
2557 cur_col += (8 - cur_col % 8);
|
|
2558 else
|
|
2559 ++cur_col;
|
|
2560 ++s;
|
|
2561 }
|
|
2562
|
|
2563 if (msg_silent != 0) /* should update msg_col */
|
|
2564 msg_col = cur_col;
|
|
2565 }
|
|
2566 }
|
|
2567
|
|
2568 /*
|
|
2569 * Give a warning message (for searching).
|
|
2570 * Use 'w' highlighting and may repeat the message after redrawing
|
|
2571 */
|
|
2572 void
|
|
2573 give_warning(message, hl)
|
|
2574 char_u *message;
|
|
2575 int hl;
|
|
2576 {
|
|
2577 /* Don't do this for ":silent". */
|
|
2578 if (msg_silent != 0)
|
|
2579 return;
|
|
2580
|
|
2581 /* Don't want a hit-enter prompt here. */
|
|
2582 ++no_wait_return;
|
8
|
2583
|
7
|
2584 #ifdef FEAT_EVAL
|
|
2585 set_vim_var_string(VV_WARNINGMSG, message, -1);
|
|
2586 #endif
|
|
2587 vim_free(keep_msg);
|
|
2588 keep_msg = NULL;
|
|
2589 if (hl)
|
|
2590 keep_msg_attr = hl_attr(HLF_W);
|
|
2591 else
|
|
2592 keep_msg_attr = 0;
|
|
2593 if (msg_attr(message, keep_msg_attr) && msg_scrolled == 0)
|
|
2594 set_keep_msg(message);
|
|
2595 msg_didout = FALSE; /* overwrite this message */
|
|
2596 msg_nowait = TRUE; /* don't wait for this message */
|
|
2597 msg_col = 0;
|
8
|
2598
|
7
|
2599 --no_wait_return;
|
|
2600 }
|
|
2601
|
|
2602 /*
|
|
2603 * Advance msg cursor to column "col".
|
|
2604 */
|
|
2605 void
|
|
2606 msg_advance(col)
|
|
2607 int col;
|
|
2608 {
|
|
2609 if (msg_silent != 0) /* nothing to advance to */
|
|
2610 {
|
|
2611 msg_col = col; /* for redirection, may fill it up later */
|
|
2612 return;
|
|
2613 }
|
|
2614 if (col >= Columns) /* not enough room */
|
|
2615 col = Columns - 1;
|
|
2616 while (msg_col < col)
|
|
2617 msg_putchar(' ');
|
|
2618 }
|
|
2619
|
|
2620 #if defined(FEAT_CON_DIALOG) || defined(PROTO)
|
|
2621 /*
|
|
2622 * Used for "confirm()" function, and the :confirm command prefix.
|
|
2623 * Versions which haven't got flexible dialogs yet, and console
|
|
2624 * versions, get this generic handler which uses the command line.
|
|
2625 *
|
|
2626 * type = one of:
|
|
2627 * VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC
|
|
2628 * title = title string (can be NULL for default)
|
|
2629 * (neither used in console dialogs at the moment)
|
|
2630 *
|
|
2631 * Format of the "buttons" string:
|
|
2632 * "Button1Name\nButton2Name\nButton3Name"
|
|
2633 * The first button should normally be the default/accept
|
|
2634 * The second button should be the 'Cancel' button
|
|
2635 * Other buttons- use your imagination!
|
|
2636 * A '&' in a button name becomes a shortcut, so each '&' should be before a
|
|
2637 * different letter.
|
|
2638 */
|
|
2639 /* ARGSUSED */
|
|
2640 int
|
|
2641 do_dialog(type, title, message, buttons, dfltbutton, textfield)
|
|
2642 int type;
|
|
2643 char_u *title;
|
|
2644 char_u *message;
|
|
2645 char_u *buttons;
|
|
2646 int dfltbutton;
|
|
2647 char_u *textfield; /* IObuff for inputdialog(), NULL otherwise */
|
|
2648 {
|
|
2649 int oldState;
|
|
2650 int retval = 0;
|
|
2651 char_u *hotkeys;
|
|
2652 int c;
|
|
2653 int i;
|
|
2654
|
|
2655 #ifndef NO_CONSOLE
|
|
2656 /* Don't output anything in silent mode ("ex -s") */
|
|
2657 if (silent_mode)
|
|
2658 return dfltbutton; /* return default option */
|
|
2659 #endif
|
|
2660
|
|
2661 #ifdef FEAT_GUI_DIALOG
|
|
2662 /* When GUI is running and 'c' not in 'guioptions', use the GUI dialog */
|
|
2663 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL)
|
|
2664 {
|
|
2665 c = gui_mch_dialog(type, title, message, buttons, dfltbutton,
|
|
2666 textfield);
|
|
2667 msg_end_prompt();
|
|
2668
|
|
2669 /* Flush output to avoid that further messages and redrawing is done
|
|
2670 * in the wrong order. */
|
|
2671 out_flush();
|
|
2672 gui_mch_update();
|
|
2673
|
|
2674 return c;
|
|
2675 }
|
|
2676 #endif
|
|
2677
|
|
2678 oldState = State;
|
|
2679 State = CONFIRM;
|
|
2680 #ifdef FEAT_MOUSE
|
|
2681 setmouse();
|
|
2682 #endif
|
|
2683
|
|
2684 /*
|
|
2685 * Since we wait for a keypress, don't make the
|
|
2686 * user press RETURN as well afterwards.
|
|
2687 */
|
|
2688 ++no_wait_return;
|
|
2689 hotkeys = msg_show_console_dialog(message, buttons, dfltbutton);
|
|
2690
|
|
2691 if (hotkeys != NULL)
|
|
2692 {
|
|
2693 for (;;)
|
|
2694 {
|
|
2695 /* Get a typed character directly from the user. */
|
|
2696 c = get_keystroke();
|
|
2697 switch (c)
|
|
2698 {
|
|
2699 case CAR: /* User accepts default option */
|
|
2700 case NL:
|
|
2701 retval = dfltbutton;
|
|
2702 break;
|
|
2703 case Ctrl_C: /* User aborts/cancels */
|
|
2704 case ESC:
|
|
2705 retval = 0;
|
|
2706 break;
|
|
2707 default: /* Could be a hotkey? */
|
|
2708 if (c < 0) /* special keys are ignored here */
|
|
2709 continue;
|
|
2710 /* Make the character lowercase, as chars in "hotkeys" are. */
|
|
2711 c = MB_TOLOWER(c);
|
|
2712 retval = 1;
|
|
2713 for (i = 0; hotkeys[i]; ++i)
|
|
2714 {
|
|
2715 #ifdef FEAT_MBYTE
|
|
2716 if (has_mbyte)
|
|
2717 {
|
|
2718 if ((*mb_ptr2char)(hotkeys + i) == c)
|
|
2719 break;
|
|
2720 i += (*mb_ptr2len_check)(hotkeys + i) - 1;
|
|
2721 }
|
|
2722 else
|
|
2723 #endif
|
|
2724 if (hotkeys[i] == c)
|
|
2725 break;
|
|
2726 ++retval;
|
|
2727 }
|
|
2728 if (hotkeys[i])
|
|
2729 break;
|
|
2730 /* No hotkey match, so keep waiting */
|
|
2731 continue;
|
|
2732 }
|
|
2733 break;
|
|
2734 }
|
|
2735
|
|
2736 vim_free(hotkeys);
|
|
2737 }
|
|
2738
|
|
2739 State = oldState;
|
|
2740 #ifdef FEAT_MOUSE
|
|
2741 setmouse();
|
|
2742 #endif
|
|
2743 --no_wait_return;
|
|
2744 msg_end_prompt();
|
|
2745
|
|
2746 return retval;
|
|
2747 }
|
|
2748
|
|
2749 static int copy_char __ARGS((char_u *from, char_u *to, int lowercase));
|
|
2750
|
|
2751 /*
|
|
2752 * Copy one character from "*from" to "*to", taking care of multi-byte
|
|
2753 * characters. Return the length of the character in bytes.
|
|
2754 */
|
|
2755 static int
|
|
2756 copy_char(from, to, lowercase)
|
|
2757 char_u *from;
|
|
2758 char_u *to;
|
|
2759 int lowercase; /* make character lower case */
|
|
2760 {
|
|
2761 #ifdef FEAT_MBYTE
|
|
2762 int len;
|
|
2763 int c;
|
|
2764
|
|
2765 if (has_mbyte)
|
|
2766 {
|
|
2767 if (lowercase)
|
|
2768 {
|
|
2769 c = MB_TOLOWER((*mb_ptr2char)(from));
|
|
2770 return (*mb_char2bytes)(c, to);
|
|
2771 }
|
|
2772 else
|
|
2773 {
|
|
2774 len = (*mb_ptr2len_check)(from);
|
|
2775 mch_memmove(to, from, (size_t)len);
|
|
2776 return len;
|
|
2777 }
|
|
2778 }
|
|
2779 else
|
|
2780 #endif
|
|
2781 {
|
|
2782 if (lowercase)
|
|
2783 *to = (char_u)TOLOWER_LOC(*from);
|
|
2784 else
|
|
2785 *to = *from;
|
|
2786 return 1;
|
|
2787 }
|
|
2788 }
|
|
2789
|
|
2790 /*
|
|
2791 * Format the dialog string, and display it at the bottom of
|
|
2792 * the screen. Return a string of hotkey chars (if defined) for
|
|
2793 * each 'button'. If a button has no hotkey defined, the first character of
|
|
2794 * the button is used.
|
|
2795 * The hotkeys can be multi-byte characters, but without combining chars.
|
|
2796 *
|
|
2797 * Returns an allocated string with hotkeys, or NULL for error.
|
|
2798 */
|
|
2799 static char_u *
|
|
2800 msg_show_console_dialog(message, buttons, dfltbutton)
|
|
2801 char_u *message;
|
|
2802 char_u *buttons;
|
|
2803 int dfltbutton;
|
|
2804 {
|
|
2805 int len = 0;
|
|
2806 #ifdef FEAT_MBYTE
|
|
2807 # define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1)
|
|
2808 #else
|
|
2809 # define HOTK_LEN 1
|
|
2810 #endif
|
|
2811 int lenhotkey = HOTK_LEN; /* count first button */
|
|
2812 char_u *hotk = NULL;
|
|
2813 char_u *msgp = NULL;
|
|
2814 char_u *hotkp = NULL;
|
|
2815 char_u *r;
|
|
2816 int copy;
|
|
2817 #define HAS_HOTKEY_LEN 30
|
|
2818 char_u has_hotkey[HAS_HOTKEY_LEN];
|
|
2819 int first_hotkey = FALSE; /* first char of button is hotkey */
|
|
2820 int idx;
|
|
2821
|
|
2822 has_hotkey[0] = FALSE;
|
|
2823
|
|
2824 /*
|
|
2825 * First loop: compute the size of memory to allocate.
|
|
2826 * Second loop: copy to the allocated memory.
|
|
2827 */
|
|
2828 for (copy = 0; copy <= 1; ++copy)
|
|
2829 {
|
|
2830 r = buttons;
|
|
2831 idx = 0;
|
|
2832 while (*r)
|
|
2833 {
|
|
2834 if (*r == DLG_BUTTON_SEP)
|
|
2835 {
|
|
2836 if (copy)
|
|
2837 {
|
|
2838 *msgp++ = ',';
|
|
2839 *msgp++ = ' '; /* '\n' -> ', ' */
|
|
2840
|
|
2841 /* advance to next hotkey and set default hotkey */
|
|
2842 #ifdef FEAT_MBYTE
|
|
2843 if (has_mbyte)
|
|
2844 hotkp += (*mb_ptr2len_check)(hotkp);
|
|
2845 else
|
|
2846 #endif
|
|
2847 ++hotkp;
|
|
2848 (void)copy_char(r + 1, hotkp, TRUE);
|
|
2849 if (dfltbutton)
|
|
2850 --dfltbutton;
|
|
2851
|
|
2852 /* If no hotkey is specified first char is used. */
|
|
2853 if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx])
|
|
2854 first_hotkey = TRUE;
|
|
2855 }
|
|
2856 else
|
|
2857 {
|
|
2858 len += 3; /* '\n' -> ', '; 'x' -> '(x)' */
|
|
2859 lenhotkey += HOTK_LEN; /* each button needs a hotkey */
|
|
2860 if (idx < HAS_HOTKEY_LEN - 1)
|
|
2861 has_hotkey[++idx] = FALSE;
|
|
2862 }
|
|
2863 }
|
|
2864 else if (*r == DLG_HOTKEY_CHAR || first_hotkey)
|
|
2865 {
|
|
2866 if (*r == DLG_HOTKEY_CHAR)
|
|
2867 ++r;
|
|
2868 first_hotkey = FALSE;
|
|
2869 if (copy)
|
|
2870 {
|
|
2871 if (*r == DLG_HOTKEY_CHAR) /* '&&a' -> '&a' */
|
|
2872 *msgp++ = *r;
|
|
2873 else
|
|
2874 {
|
|
2875 /* '&a' -> '[a]' */
|
|
2876 *msgp++ = (dfltbutton == 1) ? '[' : '(';
|
|
2877 msgp += copy_char(r, msgp, FALSE);
|
|
2878 *msgp++ = (dfltbutton == 1) ? ']' : ')';
|
|
2879
|
|
2880 /* redefine hotkey */
|
|
2881 (void)copy_char(r, hotkp, TRUE);
|
|
2882 }
|
|
2883 }
|
|
2884 else
|
|
2885 {
|
|
2886 ++len; /* '&a' -> '[a]' */
|
|
2887 if (idx < HAS_HOTKEY_LEN - 1)
|
|
2888 has_hotkey[idx] = TRUE;
|
|
2889 }
|
|
2890 }
|
|
2891 else
|
|
2892 {
|
|
2893 /* everything else copy literally */
|
|
2894 if (copy)
|
|
2895 msgp += copy_char(r, msgp, FALSE);
|
|
2896 }
|
|
2897
|
|
2898 /* advance to the next character */
|
39
|
2899 mb_ptr_adv(r);
|
7
|
2900 }
|
|
2901
|
|
2902 if (copy)
|
|
2903 {
|
|
2904 *msgp++ = ':';
|
|
2905 *msgp++ = ' ';
|
|
2906 *msgp = NUL;
|
39
|
2907 mb_ptr_adv(hotkp);
|
7
|
2908 *hotkp = NUL;
|
|
2909 }
|
|
2910 else
|
|
2911 {
|
|
2912 len += STRLEN(message)
|
|
2913 + 2 /* for the NL's */
|
|
2914 + STRLEN(buttons)
|
|
2915 + 3; /* for the ": " and NUL */
|
|
2916 lenhotkey++; /* for the NUL */
|
|
2917
|
|
2918 /* If no hotkey is specified first char is used. */
|
|
2919 if (!has_hotkey[0])
|
|
2920 {
|
|
2921 first_hotkey = TRUE;
|
|
2922 len += 2; /* "x" -> "[x]" */
|
|
2923 }
|
|
2924
|
|
2925 /*
|
|
2926 * Now allocate and load the strings
|
|
2927 */
|
|
2928 vim_free(confirm_msg);
|
|
2929 confirm_msg = alloc(len);
|
|
2930 if (confirm_msg == NULL)
|
|
2931 return NULL;
|
|
2932 *confirm_msg = NUL;
|
|
2933 hotk = alloc(lenhotkey);
|
|
2934 if (hotk == NULL)
|
|
2935 return NULL;
|
|
2936
|
|
2937 *confirm_msg = '\n';
|
|
2938 STRCPY(confirm_msg + 1, message);
|
|
2939
|
|
2940 msgp = confirm_msg + 1 + STRLEN(message);
|
|
2941 hotkp = hotk;
|
|
2942
|
|
2943 /* define first default hotkey */
|
|
2944 (void)copy_char(buttons, hotkp, TRUE);
|
|
2945
|
|
2946 /* Remember where the choices start, displaying starts here when
|
|
2947 * "hotkp" typed at the more prompt. */
|
|
2948 confirm_msg_tail = msgp;
|
|
2949 *msgp++ = '\n';
|
|
2950 }
|
|
2951 }
|
|
2952
|
|
2953 display_confirm_msg();
|
|
2954 return hotk;
|
|
2955 }
|
|
2956
|
|
2957 /*
|
|
2958 * Display the ":confirm" message. Also called when screen resized.
|
|
2959 */
|
|
2960 void
|
|
2961 display_confirm_msg()
|
|
2962 {
|
|
2963 /* avoid that 'q' at the more prompt truncates the message here */
|
|
2964 ++confirm_msg_used;
|
|
2965 if (confirm_msg != NULL)
|
|
2966 msg_puts_attr(confirm_msg, hl_attr(HLF_M));
|
|
2967 --confirm_msg_used;
|
|
2968 }
|
|
2969
|
|
2970 #endif /* FEAT_CON_DIALOG */
|
|
2971
|
|
2972 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
|
|
2973
|
|
2974 int
|
|
2975 vim_dialog_yesno(type, title, message, dflt)
|
|
2976 int type;
|
|
2977 char_u *title;
|
|
2978 char_u *message;
|
|
2979 int dflt;
|
|
2980 {
|
|
2981 if (do_dialog(type,
|
|
2982 title == NULL ? (char_u *)_("Question") : title,
|
|
2983 message,
|
|
2984 (char_u *)_("&Yes\n&No"), dflt, NULL) == 1)
|
|
2985 return VIM_YES;
|
|
2986 return VIM_NO;
|
|
2987 }
|
|
2988
|
|
2989 int
|
|
2990 vim_dialog_yesnocancel(type, title, message, dflt)
|
|
2991 int type;
|
|
2992 char_u *title;
|
|
2993 char_u *message;
|
|
2994 int dflt;
|
|
2995 {
|
|
2996 switch (do_dialog(type,
|
|
2997 title == NULL ? (char_u *)_("Question") : title,
|
|
2998 message,
|
|
2999 (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL))
|
|
3000 {
|
|
3001 case 1: return VIM_YES;
|
|
3002 case 2: return VIM_NO;
|
|
3003 }
|
|
3004 return VIM_CANCEL;
|
|
3005 }
|
|
3006
|
|
3007 int
|
|
3008 vim_dialog_yesnoallcancel(type, title, message, dflt)
|
|
3009 int type;
|
|
3010 char_u *title;
|
|
3011 char_u *message;
|
|
3012 int dflt;
|
|
3013 {
|
|
3014 switch (do_dialog(type,
|
|
3015 title == NULL ? (char_u *)"Question" : title,
|
|
3016 message,
|
|
3017 (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"),
|
|
3018 dflt, NULL))
|
|
3019 {
|
|
3020 case 1: return VIM_YES;
|
|
3021 case 2: return VIM_NO;
|
|
3022 case 3: return VIM_ALL;
|
|
3023 case 4: return VIM_DISCARDALL;
|
|
3024 }
|
|
3025 return VIM_CANCEL;
|
|
3026 }
|
|
3027
|
|
3028 #endif /* FEAT_GUI_DIALOG || FEAT_CON_DIALOG */
|
|
3029
|
|
3030 #if defined(FEAT_BROWSE) || defined(PROTO)
|
|
3031 /*
|
|
3032 * Generic browse function. Calls gui_mch_browse() when possible.
|
|
3033 * Later this may pop-up a non-GUI file selector (external command?).
|
|
3034 */
|
|
3035 char_u *
|
28
|
3036 do_browse(flags, title, dflt, ext, initdir, filter, buf)
|
|
3037 int flags; /* BROWSE_SAVE and BROWSE_DIR */
|
7
|
3038 char_u *title; /* title for the window */
|
|
3039 char_u *dflt; /* default file name (may include directory) */
|
|
3040 char_u *ext; /* extension added */
|
|
3041 char_u *initdir; /* initial directory, NULL for current dir or
|
|
3042 when using path from "dflt" */
|
|
3043 char_u *filter; /* file name filter */
|
|
3044 buf_T *buf; /* buffer to read/write for */
|
|
3045 {
|
|
3046 char_u *fname;
|
|
3047 static char_u *last_dir = NULL; /* last used directory */
|
|
3048 char_u *tofree = NULL;
|
|
3049 int save_browse = cmdmod.browse;
|
|
3050
|
|
3051 /* Must turn off browse to avoid that autocommands will get the
|
|
3052 * flag too! */
|
|
3053 cmdmod.browse = FALSE;
|
|
3054
|
28
|
3055 if (title == NULL || *title == NUL)
|
7
|
3056 {
|
28
|
3057 if (flags & BROWSE_DIR)
|
|
3058 title = (char_u *)_("Select Directory dialog");
|
|
3059 else if (flags & BROWSE_SAVE)
|
7
|
3060 title = (char_u *)_("Save File dialog");
|
|
3061 else
|
|
3062 title = (char_u *)_("Open File dialog");
|
|
3063 }
|
|
3064
|
|
3065 /* When no directory specified, use default file name, default dir, buffer
|
|
3066 * dir, last dir or current dir */
|
|
3067 if ((initdir == NULL || *initdir == NUL) && dflt != NULL && *dflt != NUL)
|
|
3068 {
|
|
3069 if (mch_isdir(dflt)) /* default file name is a directory */
|
|
3070 {
|
|
3071 initdir = dflt;
|
|
3072 dflt = NULL;
|
|
3073 }
|
|
3074 else if (gettail(dflt) != dflt) /* default file name includes a path */
|
|
3075 {
|
|
3076 tofree = vim_strsave(dflt);
|
|
3077 if (tofree != NULL)
|
|
3078 {
|
|
3079 initdir = tofree;
|
|
3080 *gettail(initdir) = NUL;
|
|
3081 dflt = gettail(dflt);
|
|
3082 }
|
|
3083 }
|
|
3084 }
|
|
3085
|
|
3086 if (initdir == NULL || *initdir == NUL)
|
|
3087 {
|
|
3088 /* When 'browsedir' is a directory, use it */
|
28
|
3089 if (STRCMP(p_bsdir, "last") != 0
|
|
3090 && STRCMP(p_bsdir, "buffer") != 0
|
|
3091 && STRCMP(p_bsdir, "current") != 0
|
|
3092 && mch_isdir(p_bsdir))
|
7
|
3093 initdir = p_bsdir;
|
|
3094 /* When saving or 'browsedir' is "buffer", use buffer fname */
|
28
|
3095 else if (((flags & BROWSE_SAVE) || *p_bsdir == 'b')
|
7
|
3096 && buf != NULL && buf->b_ffname != NULL)
|
|
3097 {
|
|
3098 if (dflt == NULL || *dflt == NUL)
|
|
3099 dflt = gettail(curbuf->b_ffname);
|
|
3100 tofree = vim_strsave(curbuf->b_ffname);
|
|
3101 if (tofree != NULL)
|
|
3102 {
|
|
3103 initdir = tofree;
|
|
3104 *gettail(initdir) = NUL;
|
|
3105 }
|
|
3106 }
|
|
3107 /* When 'browsedir' is "last", use dir from last browse */
|
|
3108 else if (*p_bsdir == 'l')
|
|
3109 initdir = last_dir;
|
|
3110 /* When 'browsedir is "current", use current directory. This is the
|
|
3111 * default already, leave initdir empty. */
|
|
3112 }
|
|
3113
|
|
3114 # ifdef FEAT_GUI
|
|
3115 if (gui.in_use) /* when this changes, also adjust f_has()! */
|
|
3116 {
|
|
3117 if (filter == NULL
|
|
3118 # ifdef FEAT_EVAL
|
|
3119 && (filter = get_var_value((char_u *)"b:browsefilter")) == NULL
|
|
3120 && (filter = get_var_value((char_u *)"g:browsefilter")) == NULL
|
|
3121 # endif
|
|
3122 )
|
|
3123 filter = BROWSE_FILTER_DEFAULT;
|
28
|
3124 if (flags & BROWSE_DIR)
|
|
3125 {
|
|
3126 # if defined(HAVE_GTK2) || defined(WIN3264)
|
|
3127 /* For systems that have a directory dialog. */
|
|
3128 fname = gui_mch_browsedir(title, initdir);
|
|
3129 # else
|
|
3130 /* Generic solution for selecting a directory: select a file and
|
|
3131 * remove the file name. */
|
|
3132 fname = gui_mch_browse(0, title, dflt, ext, initdir, (char_u *)"");
|
|
3133 # endif
|
|
3134 # if !defined(HAVE_GTK2)
|
|
3135 /* Win32 adds a dummy file name, others return an arbitrary file
|
|
3136 * name. GTK+ 2 returns only the directory, */
|
|
3137 if (fname != NULL && *fname != NUL && !mch_isdir(fname))
|
|
3138 {
|
|
3139 /* Remove the file name. */
|
39
|
3140 char_u *tail = gettail_sep(fname);
|
28
|
3141
|
|
3142 if (tail == fname)
|
|
3143 *tail++ = '.'; /* use current dir */
|
|
3144 *tail = NUL;
|
|
3145 }
|
|
3146 # endif
|
|
3147 }
|
|
3148 else
|
|
3149 fname = gui_mch_browse(flags & BROWSE_SAVE,
|
|
3150 title, dflt, ext, initdir, filter);
|
7
|
3151
|
|
3152 /* We hang around in the dialog for a while, the user might do some
|
|
3153 * things to our files. The Win32 dialog allows deleting or renaming
|
|
3154 * a file, check timestamps. */
|
|
3155 need_check_timestamps = TRUE;
|
|
3156 did_check_timestamps = FALSE;
|
|
3157 }
|
|
3158 else
|
|
3159 # endif
|
|
3160 {
|
|
3161 /* TODO: non-GUI file selector here */
|
|
3162 EMSG(_("E338: Sorry, no file browser in console mode"));
|
|
3163 fname = NULL;
|
|
3164 }
|
|
3165
|
|
3166 /* keep the directory for next time */
|
|
3167 if (fname != NULL)
|
|
3168 {
|
|
3169 vim_free(last_dir);
|
|
3170 last_dir = vim_strsave(fname);
|
28
|
3171 if (last_dir != NULL && !(flags & BROWSE_DIR))
|
7
|
3172 {
|
|
3173 *gettail(last_dir) = NUL;
|
|
3174 if (*last_dir == NUL)
|
|
3175 {
|
|
3176 /* filename only returned, must be in current dir */
|
|
3177 vim_free(last_dir);
|
|
3178 last_dir = alloc(MAXPATHL);
|
|
3179 if (last_dir != NULL)
|
|
3180 mch_dirname(last_dir, MAXPATHL);
|
|
3181 }
|
|
3182 }
|
|
3183 }
|
|
3184
|
|
3185 vim_free(tofree);
|
|
3186 cmdmod.browse = save_browse;
|
|
3187
|
|
3188 return fname;
|
|
3189 }
|
|
3190 #endif
|