-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathmessage.c
4960 lines (4538 loc) · 112 KB
/
message.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* message.c: functions for displaying messages on the command line
*/
#define MESSAGE_FILE /* don't include prototype for smsg() */
#include "vim.h"
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
# include <math.h>
#endif
static int other_sourcing_name __ARGS((void));
static char_u *get_emsg_source __ARGS((void));
static char_u *get_emsg_lnum __ARGS((void));
static void add_msg_hist __ARGS((char_u *s, int len, int attr));
static void hit_return_msg __ARGS((void));
static void msg_home_replace_attr __ARGS((char_u *fname, int attr));
#ifdef FEAT_MBYTE
static char_u *screen_puts_mbyte __ARGS((char_u *s, int l, int attr));
#endif
static void msg_puts_attr_len __ARGS((char_u *str, int maxlen, int attr));
static void msg_puts_display __ARGS((char_u *str, int maxlen, int attr, int recurse));
static void msg_scroll_up __ARGS((void));
static void inc_msg_scrolled __ARGS((void));
static void store_sb_text __ARGS((char_u **sb_str, char_u *s, int attr, int *sb_col, int finish));
static void t_puts __ARGS((int *t_col, char_u *t_s, char_u *s, int attr));
static void msg_puts_printf __ARGS((char_u *str, int maxlen));
static int do_more_prompt __ARGS((int typed_char));
static void msg_screen_putchar __ARGS((int c, int attr));
static int msg_check_screen __ARGS((void));
static void redir_write __ARGS((char_u *s, int maxlen));
#ifdef FEAT_CON_DIALOG
static char_u *msg_show_console_dialog __ARGS((char_u *message, char_u *buttons, int dfltbutton));
static int confirm_msg_used = FALSE; /* displaying confirm_msg */
static char_u *confirm_msg = NULL; /* ":confirm" message */
static char_u *confirm_msg_tail; /* tail of confirm_msg */
#endif
struct msg_hist
{
struct msg_hist *next;
char_u *msg;
int attr;
};
static struct msg_hist *first_msg_hist = NULL;
static struct msg_hist *last_msg_hist = NULL;
static int msg_hist_len = 0;
static FILE *verbose_fd = NULL;
static int verbose_did_open = FALSE;
/*
* When writing messages to the screen, there are many different situations.
* A number of variables is used to remember the current state:
* msg_didany TRUE when messages were written since the last time the
* user reacted to a prompt.
* Reset: After hitting a key for the hit-return prompt,
* hitting <CR> for the command line or input().
* Set: When any message is written to the screen.
* msg_didout TRUE when something was written to the current line.
* Reset: When advancing to the next line, when the current
* text can be overwritten.
* Set: When any message is written to the screen.
* msg_nowait No extra delay for the last drawn message.
* Used in normal_cmd() before the mode message is drawn.
* emsg_on_display There was an error message recently. Indicates that there
* should be a delay before redrawing.
* msg_scroll The next message should not overwrite the current one.
* msg_scrolled How many lines the screen has been scrolled (because of
* messages). Used in update_screen() to scroll the screen
* back. Incremented each time the screen scrolls a line.
* msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr()
* writes something without scrolling should not make
* need_wait_return to be set. This is a hack to make ":ts"
* work without an extra prompt.
* lines_left Number of lines available for messages before the
* more-prompt is to be given. -1 when not set.
* need_wait_return TRUE when the hit-return prompt is needed.
* Reset: After giving the hit-return prompt, when the user
* has answered some other prompt.
* Set: When the ruler or typeahead display is overwritten,
* scrolling the screen for some message.
* keep_msg Message to be displayed after redrawing the screen, in
* main_loop().
* This is an allocated string or NULL when not used.
*/
/*
* msg(s) - displays the string 's' on the status line
* When terminal not initialized (yet) mch_errmsg(..) is used.
* return TRUE if wait_return not called
*/
int
msg(s)
char_u *s;
{
return msg_attr_keep(s, 0, FALSE);
}
#if defined(FEAT_EVAL) || defined(FEAT_X11) || defined(USE_XSMP) \
|| defined(FEAT_GUI_GTK) || defined(PROTO)
/*
* Like msg() but keep it silent when 'verbosefile' is set.
*/
int
verb_msg(s)
char_u *s;
{
int n;
verbose_enter();
n = msg_attr_keep(s, 0, FALSE);
verbose_leave();
return n;
}
#endif
int
msg_attr(s, attr)
char_u *s;
int attr;
{
return msg_attr_keep(s, attr, FALSE);
}
int
msg_attr_keep(s, attr, keep)
char_u *s;
int attr;
int keep; /* TRUE: set keep_msg if it doesn't scroll */
{
static int entered = 0;
int retval;
char_u *buf = NULL;
#ifdef FEAT_EVAL
if (attr == 0)
set_vim_var_string(VV_STATUSMSG, s, -1);
#endif
/*
* It is possible that displaying a messages causes a problem (e.g.,
* when redrawing the window), which causes another message, etc.. To
* break this loop, limit the recursiveness to 3 levels.
*/
if (entered >= 3)
return TRUE;
++entered;
/* Add message to history (unless it's a repeated kept message or a
* truncated message) */
if (s != keep_msg
|| (*s != '<'
&& last_msg_hist != NULL
&& last_msg_hist->msg != NULL
&& STRCMP(s, last_msg_hist->msg)))
add_msg_hist(s, -1, attr);
/* When displaying keep_msg, don't let msg_start() free it, caller must do
* that. */
if (s == keep_msg)
keep_msg = NULL;
/* Truncate the message if needed. */
msg_start();
buf = msg_strtrunc(s, FALSE);
if (buf != NULL)
s = buf;
msg_outtrans_attr(s, attr);
msg_clr_eos();
retval = msg_end();
if (keep && retval && vim_strsize(s) < (int)(Rows - cmdline_row - 1)
* Columns + sc_col)
set_keep_msg(s, 0);
vim_free(buf);
--entered;
return retval;
}
/*
* Truncate a string such that it can be printed without causing a scroll.
* Returns an allocated string or NULL when no truncating is done.
*/
char_u *
msg_strtrunc(s, force)
char_u *s;
int force; /* always truncate */
{
char_u *buf = NULL;
int len;
int room;
/* May truncate message to avoid a hit-return prompt */
if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL)
&& !exmode_active && msg_silent == 0) || force)
{
len = vim_strsize(s);
if (msg_scrolled != 0)
/* Use all the columns. */
room = (int)(Rows - msg_row) * Columns - 1;
else
/* Use up to 'showcmd' column. */
room = (int)(Rows - msg_row - 1) * Columns + sc_col - 1;
if (len > room && room > 0)
{
#ifdef FEAT_MBYTE
if (enc_utf8)
/* may have up to 18 bytes per cell (6 per char, up to two
* composing chars) */
len = (room + 2) * 18;
else if (enc_dbcs == DBCS_JPNU)
/* may have up to 2 bytes per cell for euc-jp */
len = (room + 2) * 2;
else
#endif
len = room + 2;
buf = alloc(len);
if (buf != NULL)
trunc_string(s, buf, room, len);
}
}
return buf;
}
/*
* Truncate a string "s" to "buf" with cell width "room".
* "s" and "buf" may be equal.
*/
void
trunc_string(s, buf, room, buflen)
char_u *s;
char_u *buf;
int room;
int buflen;
{
int half;
int len;
int e;
int i;
int n;
room -= 3;
half = room / 2;
len = 0;
/* First part: Start of the string. */
for (e = 0; len < half && e < buflen; ++e)
{
if (s[e] == NUL)
{
/* text fits without truncating! */
buf[e] = NUL;
return;
}
n = ptr2cells(s + e);
if (len + n >= half)
break;
len += n;
buf[e] = s[e];
#ifdef FEAT_MBYTE
if (has_mbyte)
for (n = (*mb_ptr2len)(s + e); --n > 0; )
{
if (++e == buflen)
break;
buf[e] = s[e];
}
#endif
}
/* Last part: End of the string. */
i = e;
#ifdef FEAT_MBYTE
if (enc_dbcs != 0)
{
/* For DBCS going backwards in a string is slow, but
* computing the cell width isn't too slow: go forward
* until the rest fits. */
n = vim_strsize(s + i);
while (len + n > room)
{
n -= ptr2cells(s + i);
i += (*mb_ptr2len)(s + i);
}
}
else if (enc_utf8)
{
/* For UTF-8 we can go backwards easily. */
half = i = (int)STRLEN(s);
for (;;)
{
do
half = half - (*mb_head_off)(s, s + half - 1) - 1;
while (utf_iscomposing(utf_ptr2char(s + half)) && half > 0);
n = ptr2cells(s + half);
if (len + n > room)
break;
len += n;
i = half;
}
}
else
#endif
{
for (i = (int)STRLEN(s); len + (n = ptr2cells(s + i - 1)) <= room; --i)
len += n;
}
/* Set the middle and copy the last part. */
if (e + 3 < buflen)
{
mch_memmove(buf + e, "...", (size_t)3);
len = (int)STRLEN(s + i) + 1;
if (len >= buflen - e - 3)
len = buflen - e - 3 - 1;
mch_memmove(buf + e + 3, s + i, len);
buf[e + 3 + len - 1] = NUL;
}
else
{
buf[e - 1] = NUL; /* make sure it is truncated */
}
}
/*
* Automatic prototype generation does not understand this function.
* Note: Caller of smgs() and smsg_attr() must check the resulting string is
* shorter than IOSIZE!!!
*/
#ifndef PROTO
# ifndef HAVE_STDARG_H
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg __ARGS((char_u *, long, long, long,
long, long, long, long, long, long, long));
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg_attr __ARGS((int, char_u *, long, long, long,
long, long, long, long, long, long, long));
int vim_snprintf __ARGS((char *, size_t, char *, long, long, long,
long, long, long, long, long, long, long));
/*
* smsg(str, arg, ...) is like using sprintf(buf, str, arg, ...) and then
* calling msg(buf).
* The buffer used is IObuff, the message is truncated at IOSIZE.
*/
/* VARARGS */
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg(s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
char_u *s;
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
{
return smsg_attr(0, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
}
/* VARARGS */
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg_attr(attr, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
int attr;
char_u *s;
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
{
vim_snprintf((char *)IObuff, IOSIZE, (char *)s,
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
return msg_attr(IObuff, attr);
}
# else /* HAVE_STDARG_H */
int vim_snprintf(char *str, size_t str_m, char *fmt, ...);
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg(char_u *s, ...)
{
va_list arglist;
va_start(arglist, s);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL);
va_end(arglist);
return msg(IObuff);
}
int
#ifdef __BORLANDC__
_RTLENTRYF
#endif
smsg_attr(int attr, char_u *s, ...)
{
va_list arglist;
va_start(arglist, s);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL);
va_end(arglist);
return msg_attr(IObuff, attr);
}
# endif /* HAVE_STDARG_H */
#endif
/*
* Remember the last sourcing name/lnum used in an error message, so that it
* isn't printed each time when it didn't change.
*/
static int last_sourcing_lnum = 0;
static char_u *last_sourcing_name = NULL;
/*
* Reset the last used sourcing name/lnum. Makes sure it is displayed again
* for the next error message;
*/
void
reset_last_sourcing()
{
vim_free(last_sourcing_name);
last_sourcing_name = NULL;
last_sourcing_lnum = 0;
}
/*
* Return TRUE if "sourcing_name" differs from "last_sourcing_name".
*/
static int
other_sourcing_name()
{
if (sourcing_name != NULL)
{
if (last_sourcing_name != NULL)
return STRCMP(sourcing_name, last_sourcing_name) != 0;
return TRUE;
}
return FALSE;
}
/*
* Get the message about the source, as used for an error message.
* Returns an allocated string with room for one more character.
* Returns NULL when no message is to be given.
*/
static char_u *
get_emsg_source()
{
char_u *Buf, *p;
if (sourcing_name != NULL && other_sourcing_name())
{
p = (char_u *)_("Error detected while processing %s:");
Buf = alloc((unsigned)(STRLEN(sourcing_name) + STRLEN(p)));
if (Buf != NULL)
sprintf((char *)Buf, (char *)p, sourcing_name);
return Buf;
}
return NULL;
}
/*
* Get the message about the source lnum, as used for an error message.
* Returns an allocated string with room for one more character.
* Returns NULL when no message is to be given.
*/
static char_u *
get_emsg_lnum()
{
char_u *Buf, *p;
/* lnum is 0 when executing a command from the command line
* argument, we don't want a line number then */
if (sourcing_name != NULL
&& (other_sourcing_name() || sourcing_lnum != last_sourcing_lnum)
&& sourcing_lnum != 0)
{
p = (char_u *)_("line %4ld:");
Buf = alloc((unsigned)(STRLEN(p) + 20));
if (Buf != NULL)
sprintf((char *)Buf, (char *)p, (long)sourcing_lnum);
return Buf;
}
return NULL;
}
/*
* Display name and line number for the source of an error.
* Remember the file name and line number, so that for the next error the info
* is only displayed if it changed.
*/
void
msg_source(attr)
int attr;
{
char_u *p;
++no_wait_return;
p = get_emsg_source();
if (p != NULL)
{
msg_attr(p, attr);
vim_free(p);
}
p = get_emsg_lnum();
if (p != NULL)
{
msg_attr(p, hl_attr(HLF_N));
vim_free(p);
last_sourcing_lnum = sourcing_lnum; /* only once for each line */
}
/* remember the last sourcing name printed, also when it's empty */
if (sourcing_name == NULL || other_sourcing_name())
{
vim_free(last_sourcing_name);
if (sourcing_name == NULL)
last_sourcing_name = NULL;
else
last_sourcing_name = vim_strsave(sourcing_name);
}
--no_wait_return;
}
/*
* Return TRUE if not giving error messages right now:
* If "emsg_off" is set: no error messages at the moment.
* If "msg" is in 'debug': do error message but without side effects.
* If "emsg_skip" is set: never do error messages.
*/
int
emsg_not_now()
{
if ((emsg_off > 0 && vim_strchr(p_debug, 'm') == NULL
&& vim_strchr(p_debug, 't') == NULL)
#ifdef FEAT_EVAL
|| emsg_skip > 0
#endif
)
return TRUE;
return FALSE;
}
/*
* emsg() - display an error message
*
* Rings the bell, if appropriate, and calls message() to do the real work
* When terminal not initialized (yet) mch_errmsg(..) is used.
*
* return TRUE if wait_return not called
*/
int
emsg(s)
char_u *s;
{
int attr;
char_u *p;
#ifdef FEAT_EVAL
int ignore = FALSE;
int severe;
#endif
/* Skip this if not giving error messages at the moment. */
if (emsg_not_now())
return TRUE;
called_emsg = TRUE;
ex_exitval = 1;
/*
* If "emsg_severe" is TRUE: When an error exception is to be thrown,
* prefer this message over previous messages for the same command.
*/
#ifdef FEAT_EVAL
severe = emsg_severe;
emsg_severe = FALSE;
#endif
if (!emsg_off || vim_strchr(p_debug, 't') != NULL)
{
#ifdef FEAT_EVAL
/*
* Cause a throw of an error exception if appropriate. Don't display
* the error message in this case. (If no matching catch clause will
* be found, the message will be displayed later on.) "ignore" is set
* when the message should be ignored completely (used for the
* interrupt message).
*/
if (cause_errthrow(s, severe, &ignore) == TRUE)
{
if (!ignore)
did_emsg = TRUE;
return TRUE;
}
/* set "v:errmsg", also when using ":silent! cmd" */
set_vim_var_string(VV_ERRMSG, s, -1);
#endif
/*
* When using ":silent! cmd" ignore error messages.
* But do write it to the redirection file.
*/
if (emsg_silent != 0)
{
msg_start();
p = get_emsg_source();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
p = get_emsg_lnum();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
redir_write(s, -1);
return TRUE;
}
/* Reset msg_silent, an error causes messages to be switched back on. */
msg_silent = 0;
cmd_silent = FALSE;
if (global_busy) /* break :global command */
++global_busy;
if (p_eb)
beep_flush(); /* also includes flush_buffers() */
else
flush_buffers(FALSE); /* flush internal buffers */
did_emsg = TRUE; /* flag for DoOneCmd() */
}
emsg_on_display = TRUE; /* remember there is an error message */
++msg_scroll; /* don't overwrite a previous message */
attr = hl_attr(HLF_E); /* set highlight mode for error messages */
if (msg_scrolled != 0)
need_wait_return = TRUE; /* needed in case emsg() is called after
* wait_return has reset need_wait_return
* and a redraw is expected because
* msg_scrolled is non-zero */
/*
* Display name and line number for the source of the error.
*/
msg_source(attr);
/*
* Display the error message itself.
*/
msg_nowait = FALSE; /* wait for this msg */
return msg_attr(s, attr);
}
/*
* Print an error message with one "%s" and one string argument.
*/
int
emsg2(s, a1)
char_u *s, *a1;
{
return emsg3(s, a1, NULL);
}
/* emsg3() and emsgn() are in misc2.c to avoid warnings for the prototypes. */
void
emsg_invreg(name)
int name;
{
EMSG2(_("E354: Invalid register name: '%s'"), transchar(name));
}
/*
* Like msg(), but truncate to a single line if p_shm contains 't', or when
* "force" is TRUE. This truncates in another way as for normal messages.
* Careful: The string may be changed by msg_may_trunc()!
* Returns a pointer to the printed message, if wait_return() not called.
*/
char_u *
msg_trunc_attr(s, force, attr)
char_u *s;
int force;
int attr;
{
int n;
/* Add message to history before truncating */
add_msg_hist(s, -1, attr);
s = msg_may_trunc(force, s);
msg_hist_off = TRUE;
n = msg_attr(s, attr);
msg_hist_off = FALSE;
if (n)
return s;
return NULL;
}
/*
* Check if message "s" should be truncated at the start (for filenames).
* Return a pointer to where the truncated message starts.
* Note: May change the message by replacing a character with '<'.
*/
char_u *
msg_may_trunc(force, s)
int force;
char_u *s;
{
int n;
int room;
room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
&& (n = (int)STRLEN(s) - room) > 0)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
int size = vim_strsize(s);
/* There may be room anyway when there are multibyte chars. */
if (size <= room)
return s;
for (n = 0; size >= room; )
{
size -= (*mb_ptr2cells)(s + n);
n += (*mb_ptr2len)(s + n);
}
--n;
}
#endif
s += n;
*s = '<';
}
return s;
}
static void
add_msg_hist(s, len, attr)
char_u *s;
int len; /* -1 for undetermined length */
int attr;
{
struct msg_hist *p;
if (msg_hist_off || msg_silent != 0)
return;
/* Don't let the message history get too big */
while (msg_hist_len > MAX_MSG_HIST_LEN)
(void)delete_first_msg();
/* allocate an entry and add the message at the end of the history */
p = (struct msg_hist *)alloc((int)sizeof(struct msg_hist));
if (p != NULL)
{
if (len < 0)
len = (int)STRLEN(s);
/* remove leading and trailing newlines */
while (len > 0 && *s == '\n')
{
++s;
--len;
}
while (len > 0 && s[len - 1] == '\n')
--len;
p->msg = vim_strnsave(s, len);
p->next = NULL;
p->attr = attr;
if (last_msg_hist != NULL)
last_msg_hist->next = p;
last_msg_hist = p;
if (first_msg_hist == NULL)
first_msg_hist = last_msg_hist;
++msg_hist_len;
}
}
/*
* Delete the first (oldest) message from the history.
* Returns FAIL if there are no messages.
*/
int
delete_first_msg()
{
struct msg_hist *p;
if (msg_hist_len <= 0)
return FAIL;
p = first_msg_hist;
first_msg_hist = p->next;
if (first_msg_hist == NULL)
last_msg_hist = NULL; /* history is empty */
vim_free(p->msg);
vim_free(p);
--msg_hist_len;
return OK;
}
/*
* ":messages" command.
*/
void
ex_messages(eap)
exarg_T *eap UNUSED;
{
struct msg_hist *p;
char_u *s;
msg_hist_off = TRUE;
s = mch_getenv((char_u *)"LANG");
if (s != NULL && *s != NUL)
msg_attr((char_u *)
_("Messages maintainer: Bram Moolenaar <Bram@vim.org>"),
hl_attr(HLF_T));
for (p = first_msg_hist; p != NULL && !got_int; p = p->next)
if (p->msg != NULL)
msg_attr(p->msg, p->attr);
msg_hist_off = FALSE;
}
#if defined(FEAT_CON_DIALOG) || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
/*
* Call this after prompting the user. This will avoid a hit-return message
* and a delay.
*/
void
msg_end_prompt()
{
need_wait_return = FALSE;
emsg_on_display = FALSE;
cmdline_row = msg_row;
msg_col = 0;
msg_clr_eos();
lines_left = -1;
}
#endif
/*
* wait for the user to hit a key (normally a return)
* if 'redraw' is TRUE, clear and redraw the screen
* if 'redraw' is FALSE, just redraw the screen
* if 'redraw' is -1, don't redraw at all
*/
void
wait_return(redraw)
int redraw;
{
int c;
int oldState;
int tmpState;
int had_got_int;
int save_Recording;
FILE *save_scriptout;
if (redraw == TRUE)
must_redraw = CLEAR;
/* If using ":silent cmd", don't wait for a return. Also don't set
* need_wait_return to do it later. */
if (msg_silent != 0)
return;
/*
* When inside vgetc(), we can't wait for a typed character at all.
* With the global command (and some others) we only need one return at
* the end. Adjust cmdline_row to avoid the next message overwriting the
* last one.
*/
if (vgetc_busy > 0)
return;
need_wait_return = TRUE;
if (no_wait_return)
{
if (!exmode_active)
cmdline_row = msg_row;
return;
}
redir_off = TRUE; /* don't redirect this message */
oldState = State;
if (quit_more)
{
c = CAR; /* just pretend CR was hit */
quit_more = FALSE;
got_int = FALSE;
}
else if (exmode_active)
{
MSG_PUTS(" "); /* make sure the cursor is on the right line */
c = CAR; /* no need for a return in ex mode */
got_int = FALSE;
}
else
{
/* Make sure the hit-return prompt is on screen when 'guioptions' was
* just changed. */
screenalloc(FALSE);
State = HITRETURN;
#ifdef FEAT_MOUSE
setmouse();
#endif
#ifdef USE_ON_FLY_SCROLL
dont_scroll = TRUE; /* disallow scrolling here */
#endif
/* Avoid the sequence that the user types ":" at the hit-return prompt
* to start an Ex command, but the file-changed dialog gets in the
* way. */
if (need_check_timestamps)
check_timestamps(FALSE);
hit_return_msg();
do
{
/* Remember "got_int", if it is set vgetc() probably returns a
* CTRL-C, but we need to loop then. */
had_got_int = got_int;
/* Don't do mappings here, we put the character back in the
* typeahead buffer. */
++no_mapping;
++allow_keys;
/* Temporarily disable Recording. If Recording is active, the
* character will be recorded later, since it will be added to the
* typebuf after the loop */
save_Recording = Recording;
save_scriptout = scriptout;
Recording = FALSE;
scriptout = NULL;
c = safe_vgetc();
if (had_got_int && !global_busy)
got_int = FALSE;
--no_mapping;
--allow_keys;
Recording = save_Recording;
scriptout = save_scriptout;
#ifdef FEAT_CLIPBOARD
/* Strange way to allow copying (yanking) a modeless selection at
* the hit-enter prompt. Use CTRL-Y, because the same is used in
* Cmdline-mode and it's harmless when there is no selection. */
if (c == Ctrl_Y && clip_star.state == SELECT_DONE)
{
clip_copy_modeless_selection(TRUE);
c = K_IGNORE;
}
#endif
/*
* Allow scrolling back in the messages.
* Also accept scroll-down commands when messages fill the screen,
* to avoid that typing one 'j' too many makes the messages
* disappear.
*/
if (p_more && !p_cp)
{
if (c == 'b' || c == 'k' || c == 'u' || c == 'g'
|| c == K_UP || c == K_PAGEUP)
{
if (msg_scrolled > Rows)