summaryrefslogtreecommitdiffstats
path: root/src/message.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2004-06-13 20:20:40 +0000
committerBram Moolenaar <Bram@vim.org>2004-06-13 20:20:40 +0000
commit071d4279d6ab81b7187b48f3a0fc61e587b6db6c (patch)
tree221cbe3c40e043163c06f61c52a7ba2eb41e12ce /src/message.c
parentb4210b3bc14e2918f153a7307530fbe6eba659e1 (diff)
updated for version 7.0001v7.0001
Diffstat (limited to 'src/message.c')
-rw-r--r--src/message.c3165
1 files changed, 3165 insertions, 0 deletions
diff --git a/src/message.c b/src/message.c
new file mode 100644
index 0000000000..405ae6e03c
--- /dev/null
+++ b/src/message.c
@@ -0,0 +1,3165 @@
+/* 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"
+
+#ifdef HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+
+static void reset_last_sourcing __ARGS((void));
+static char_u *get_emsg_source __ARGS((int other));
+static char_u *get_emsg_lnum __ARGS((int other));
+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 t_puts __ARGS((int t_col, char_u *t_s, char_u *s, int attr));
+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 int msg_hist_off = FALSE; /* don't add messages to history */
+
+/*
+ * 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.
+ * 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);
+}
+
+ 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. */
+ buf = msg_strtrunc(s);
+ if (buf != NULL)
+ s = buf;
+
+ msg_start();
+ 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);
+ keep_msg_attr = 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)
+ char_u *s;
+{
+ 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)
+ {
+ len = vim_strsize(s);
+ room = (int)(Rows - cmdline_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) */
+ buf = alloc((room + 2) * 18);
+ else if (enc_dbcs == DBCS_JPNU)
+ /* may have up to 2 bytes per cell for euc-jp */
+ buf = alloc((room + 2) * 2);
+ else
+#endif
+ buf = alloc(room + 2);
+ if (buf != NULL)
+ trunc_string(s, buf, room);
+ }
+ }
+ return buf;
+}
+
+/*
+ * Truncate a string "s" to "buf" with cell width "room".
+ * "s" and "buf" may be equal.
+ */
+ void
+trunc_string(s, buf, room)
+ char_u *s;
+ char_u *buf;
+ int room;
+{
+ 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)
+ {
+ 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_check)(s + e); --n > 0; )
+ {
+ ++e;
+ 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_check)(s + i);
+ }
+ }
+ else if (enc_utf8)
+ {
+ /* For UTF-8 we can go backwards easily. */
+ i = (int)STRLEN(s);
+ for (;;)
+ {
+ half = i - (*mb_head_off)(s, s + i - 1) - 1;
+ 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. */
+ mch_memmove(buf + e, "...", (size_t)3);
+ mch_memmove(buf + e + 3, s + i, STRLEN(s + i) + 1);
+}
+
+/*
+ * 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));
+
+/* 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;
+{
+ sprintf((char *)IObuff, (char *)s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
+ return msg_attr(IObuff, attr);
+}
+
+# else /* HAVE_STDARG_H */
+
+ int
+#ifdef __BORLANDC__
+_RTLENTRYF
+#endif
+smsg(char_u *s, ...)
+{
+ va_list arglist;
+
+ va_start(arglist, s);
+# ifdef HAVE_VSNPRINTF
+ vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist);
+# else
+ vsprintf((char *)IObuff, (char *)s, arglist);
+# endif
+ 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);
+# ifdef HAVE_VSNPRINTF
+ vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist);
+# else
+ vsprintf((char *)IObuff, (char *)s, arglist);
+# endif
+ 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;
+ */
+ static void
+reset_last_sourcing()
+{
+ vim_free(last_sourcing_name);
+ last_sourcing_name = NULL;
+ last_sourcing_lnum = 0;
+}
+
+/*
+ * 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(other)
+ int other; /* TRUE when "sourcing_name" differs from last time */
+{
+ char_u *Buf, *p;
+
+ if (sourcing_name != NULL && other)
+ {
+ 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(other)
+ int other; /* TRUE when "sourcing_name" differs from last time */
+{
+ 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_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;
+}
+
+/*
+ * 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;
+ int other_sourcing_name;
+ char_u *p;
+#ifdef FEAT_EVAL
+ int ignore = FALSE;
+ int severe;
+#endif
+
+ called_emsg = TRUE;
+
+ /*
+ * 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" is set: no error messages at the moment.
+ * If 'debug' is set: do error message anyway, but without side effects.
+ * If "emsg_skip" is set: never do error messages.
+ */
+ if ((emsg_off > 0 && *p_debug == NUL)
+#ifdef FEAT_EVAL
+ || emsg_skip > 0
+#endif
+ )
+ return TRUE;
+
+ if (sourcing_name != NULL)
+ {
+ if (last_sourcing_name != NULL)
+ other_sourcing_name = STRCMP(sourcing_name, last_sourcing_name);
+ else
+ other_sourcing_name = TRUE;
+ }
+ else
+ other_sourcing_name = FALSE;
+
+ if (!emsg_off)
+ {
+#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 messsages.
+ * But do write it to the redirection file.
+ */
+ if (emsg_silent != 0)
+ {
+ msg_start();
+ p = get_emsg_source(other_sourcing_name);
+ if (p != NULL)
+ {
+ STRCAT(p, "\n");
+ redir_write(p, -1);
+ vim_free(p);
+ }
+ p = get_emsg_lnum(other_sourcing_name);
+ 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() */
+
+#ifdef VIMBUDDY
+ if (sourcing_name == NULL)
+ {
+ VimBuddyText(s, 2);
+ return TRUE;
+ }
+#endif
+ }
+
+ 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)
+ 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.
+ */
+ ++no_wait_return;
+ p = get_emsg_source(other_sourcing_name);
+ if (p != NULL)
+ {
+ msg_attr(p, attr);
+ vim_free(p);
+ }
+ p = get_emsg_lnum(other_sourcing_name);
+ if (p != NULL)
+ {
+ msg_attr(p, hl_attr(HLF_N));
+ vim_free(p);
+ last_sourcing_lnum = sourcing_lnum; /* only once for each line */
+ }
+ --no_wait_return;
+
+ /* 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);
+ }
+ msg_nowait = FALSE; /* wait for this msg */
+
+ /*
+ * Display the error message itself.
+ */
+ 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);
+}
+
+/*
+ * Print an error message with one or two "%s" and one or two string arguments.
+ */
+ int
+emsg3(s, a1, a2)
+ char_u *s, *a1, *a2;
+{
+ if ((emsg_off > 0 && *p_debug == NUL)
+#ifdef FEAT_EVAL
+ || emsg_skip > 0
+#endif
+ )
+ return TRUE; /* no error messages at the moment */
+
+ /* Check for NULL strings (just in case) */
+ if (a1 == NULL)
+ a1 = (char_u *)"[NULL]";
+ if (a2 == NULL)
+ a2 = (char_u *)"[NULL]";
+
+ /* Check for very long strings (can happen with ":help ^A<CR>"). */
+ if (STRLEN(s) + STRLEN(a1) + STRLEN(a2) >= (size_t)IOSIZE)
+ a1 = a2 = (char_u *)_("[string too long]");
+
+ sprintf((char *)IObuff, (char *)s, (char *)a1, (char *)a2);
+ return emsg(IObuff);
+}
+
+/*
+ * Print an error message with one "%ld" and one long int argument.
+ */
+ int
+emsgn(s, n)
+ char_u *s;
+ long n;
+{
+ if ((emsg_off > 0 && *p_debug == NUL)
+#ifdef FEAT_EVAL
+ || emsg_skip > 0
+#endif
+ )
+ return TRUE; /* no error messages at the moment */
+ sprintf((char *)IObuff, (char *)s, n);
+ return emsg(IObuff);
+}
+
+/*
+ * 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);
+
+ for (n = 0; size >= room; )
+ {
+ size -= (*mb_ptr2cells)(s + n);
+ n += (*mb_ptr2len_check)(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 > 20)
+ {
+ p = first_msg_hist;
+ first_msg_hist = p->next;
+ vim_free(p->msg);
+ vim_free(p);
+ --msg_hist_len;
+ }
+ /* 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;
+ }
+}
+
+/*
+ * ":messages" command.
+ */
+/*ARGSUSED*/
+ void
+ex_messages(eap)
+ exarg_T *eap;
+{
+ 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; p = p->next)
+ if (p->msg != NULL)
+ msg_attr(p->msg, p->attr);
+
+ msg_hist_off = FALSE;
+}
+
+#if defined(FEAT_CON_DIALOG) || defined(PROTO)
+static void msg_end_prompt __ARGS((void));
+
+/*
+ * Call this after prompting the user. This will avoid a hit-return message
+ * and a delay.
+ */
+ static void
+msg_end_prompt()
+{
+ need_wait_return = FALSE;
+ emsg_on_display = FALSE;
+ cmdline_row = msg_row;
+ msg_col = 0;
+ msg_clr_eos();
+}
+#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;
+#ifndef ORG_HITRETURN
+ int had_got_int;
+#endif
+
+ 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;
+
+/*
+ * 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.
+ * When inside vgetc(), we can't wait for a typed character at all.
+ */
+ if (vgetc_busy)
+ return;
+ if (no_wait_return)
+ {
+ need_wait_return = TRUE;
+ 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
+ hit_return_msg();
+
+#ifdef ORG_HITRETURN
+ do
+ {
+ c = safe_vgetc();
+ } while (vim_strchr((char_u *)"\r\n: ", c) == NULL);
+ if (c == ':') /* this can vi too (but not always!) */
+ stuffcharReadbuff(c);
+#else
+ 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;
+ c = safe_vgetc();
+ if (!global_busy)
+ got_int = FALSE;
+#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
+ } while ((had_got_int && c == Ctrl_C)
+ || c == K_IGNORE
+#ifdef FEAT_GUI
+ || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR
+#endif
+#ifdef FEAT_MOUSE
+ || c == K_LEFTDRAG || c == K_LEFTRELEASE
+ || c == K_MIDDLEDRAG || c == K_MIDDLERELEASE
+ || c == K_RIGHTDRAG || c == K_RIGHTRELEASE
+ || c == K_MOUSEDOWN || c == K_MOUSEUP
+ || (!mouse_has(MOUSE_RETURN)
+ && mouse_row < msg_row
+ && (c == K_LEFTMOUSE
+ || c == K_MIDDLEMOUSE
+ || c == K_RIGHTMOUSE
+ || c == K_X1MOUSE
+ || c == K_X2MOUSE))
+#endif
+ );
+ ui_breakcheck();
+#ifdef FEAT_MOUSE
+ /*
+ * Avoid that the mouse-up event causes visual mode to start.
+ */
+ if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE
+ || c == K_X1MOUSE || c == K_X2MOUSE)
+ (void)jump_to_mouse(MOUSE_SETPOS, NULL, 0);
+ else
+#endif
+ if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C)
+ {
+ stuffcharReadbuff(c);
+ do_redraw = TRUE; /* need a redraw even though there is
+ something in the stuff buffer */
+ }
+#endif
+ }
+ redir_off = FALSE;
+
+ /*
+ * If the user hits ':', '?' or '/' we get a command line from the next
+ * line.
+ */
+ if (c == ':' || c == '?' || c == '/')
+ {
+ if (!exmode_active)
+ cmdline_row = msg_row;
+ skip_redraw = TRUE; /* skip redraw once */
+ do_redraw = FALSE;
+ }
+
+ /*
+ * If the window size changed set_shellsize() will redraw the screen.
+ * Otherwise the screen is only redrawn if 'redraw' is set and no ':'
+ * typed.
+ */
+ tmpState = State;
+ State = oldState; /* restore State before set_shellsize */
+#ifdef FEAT_MOUSE
+ setmouse();
+#endif
+ msg_check();
+
+#if defined(UNIX) || defined(VMS)
+ /*
+ * When switching screens, we need to output an extra newline on exit.
+ */
+ if (swapping_screen() && !termcap_active)
+ newline_on_exit = TRUE;
+#endif
+
+ need_wait_return = FALSE;
+ did_wait_return = TRUE;
+ emsg_on_display = FALSE; /* can delete error message now */
+ lines_left = -1; /* reset lines_left at next msg_start() */
+ reset_last_sourcing();
+ if (keep_msg != NULL && vim_strsize(keep_msg) >=
+ (Rows - cmdline_row - 1) * Columns + sc_col)
+ {
+ vim_free(keep_msg);
+ keep_msg = NULL; /* don't redisplay message, it's too long */
+ }
+
+ if (tmpState == SETWSIZE) /* got resize event while in vgetc() */
+ {
+ starttermcap(); /* start termcap before redrawing */
+ shell_resized();
+ }
+ else if (!skip_redraw
+ && (redraw == TRUE || (msg_scrolled != 0 && redraw != -1)))
+ {
+ starttermcap(); /* start termcap before redrawing */
+ redraw_later(VALID);
+ }
+}
+
+/*
+ * Write the hit-return prompt.
+ */
+ static void
+hit_return_msg()
+{
+ if (msg_didout) /* start on a new line */
+ msg_putchar('\n');
+ if (got_int)
+ MSG_PUTS(_("Interrupt: "));
+
+#ifdef ORG_HITRETURN
+ MSG_PUTS_ATTR(_("Hit ENTER to continue"), hl_attr(HLF_R));
+#else
+ MSG_PUTS_ATTR(_("Hit ENTER or type command to continue"), hl_attr(HLF_R));
+#endif
+ if (!msg_use_printf())
+ msg_clr_eos();
+}
+
+/*
+ * Set "keep_msg" to "s". Free the old value and check for NULL pointer.
+ */
+ void
+set_keep_msg(s)
+ char_u *s;
+{
+ vim_free(keep_msg);
+ if (s != NULL && msg_silent == 0)
+ keep_msg = vim_strsave(s);
+ else
+ keep_msg = NULL;
+}
+
+/*
+ * Prepare for outputting characters in the command line.
+ */
+ void
+msg_start()
+{
+ int did_return = FALSE;
+
+ vim_free(keep_msg);
+ keep_msg = NULL; /* don't display old message now */
+ if (!msg_scroll && full_screen) /* overwrite last message */
+ {
+ msg_row = cmdline_row;
+ msg_col =
+#ifdef FEAT_RIGHTLEFT
+ cmdmsg_rl ? Columns - 1 :
+#endif
+ 0;
+ }
+ else if (msg_didout) /* start message on next line */
+ {
+ msg_putchar('\n');
+ did_return = TRUE;
+ if (exmode_active != EXMODE_NORMAL)
+ cmdline_row = msg_row;
+ }
+ if (!msg_didany || lines_left < 0)
+ msg_starthere();
+ if (msg_silent == 0)
+ {
+ msg_didout = FALSE; /* no output on current line yet */
+ cursor_off();
+ }
+
+ /* when redirecting, may need to start a new line. */
+ if (!did_return)
+ redir_write((char_u *)"\n", -1);
+}
+
+/*
+ * Note that the current msg position is where messages start.
+ */
+ void
+msg_starthere()
+{
+ lines_left = cmdline_row;
+ msg_didany = FALSE;
+}
+
+ void
+msg_putchar(c)
+ int c;
+{
+ msg_putchar_attr(c, 0);
+}
+
+ void
+msg_putchar_attr(c, attr)
+ int c;
+ int attr;
+{
+#ifdef FEAT_MBYTE
+ char_u buf[MB_MAXBYTES + 1];
+#else
+ char_u buf[4];
+#endif
+
+ if (IS_SPECIAL(c))
+ {
+ buf[0] = K_SPECIAL;
+ buf[1] = K_SECOND(c);
+ buf[2] = K_THIRD(c);
+ buf[3] = NUL;
+ }
+ else
+ {
+#ifdef FEAT_MBYTE
+ buf[(*mb_char2bytes)(c, buf)] = NUL;
+#else
+ buf[0] = c;
+ buf[1] = NUL;
+#endif
+ }
+ msg_puts_attr(buf, attr);
+}
+
+ void
+msg_outnum(n)
+ long n;
+{
+ char_u buf[20];
+
+ sprintf((char *)buf, "%ld", n);
+ msg_puts(buf);
+}
+
+ void
+msg_home_replace(fname)
+ char_u *fname;
+{
+ msg_home_replace_attr(fname, 0);
+}
+
+#if defined(FEAT_FIND_ID) || defined(PROTO)
+ void
+msg_home_replace_hl(fname)
+ char_u *fname;
+{
+ msg_home_replace_attr(fname, hl_attr(HLF_D));
+}
+#endif
+
+ static void
+msg_home_replace_attr(fname, attr)
+ char_u *fname;
+ int attr;
+{
+ char_u *name;
+
+ name = home_replace_save(NULL, fname);
+ if (name != NULL)
+ msg_outtrans_attr(name, attr);
+ vim_free(name);
+}
+
+/*
+ * Output 'len' characters in 'str' (including NULs) with translation
+ * if 'len' is -1, output upto a NUL character.
+ * Use attributes 'attr'.
+ * Return the number of characters it takes on the screen.
+ */
+ int
+msg_outtrans(str)
+ char_u *str;
+{
+ return msg_outtrans_attr(str, 0);
+}
+
+ int
+msg_outtrans_attr(str, attr)
+ char_u *str;
+ int attr;
+{
+ return msg_outtrans_len_attr(str, (int)STRLEN(str), attr);
+}
+
+ int
+msg_outtrans_len(str, len)
+ char_u *str;
+ int len;
+{
+ return msg_outtrans_len_attr(str, len, 0);
+}
+
+/*
+ * Output one character at "p". Return pointer to the next character.
+ * Handles multi-byte characters.
+ */
+ char_u *
+msg_outtrans_one(p, attr)
+ char_u *p;
+ int attr;
+{
+#ifdef FEAT_MBYTE
+ int l;
+
+ if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1)
+ {
+ msg_outtrans_len_attr(p, l, attr);
+ return p + l;
+ }
+#endif
+ msg_puts_attr(transchar_byte(*p), attr);
+ return p + 1;
+}
+
+ int
+msg_outtrans_len_attr(msgstr, len, attr)
+ char_u *msgstr;
+ int len;
+ int attr;
+{
+ int retval = 0;
+ char_u *str = msgstr;
+ char_u *plain_start = msgstr;
+ char_u *s;
+#ifdef FEAT_MBYTE
+ int mb_l;
+ int c;
+#endif
+
+ /* if MSG_HIST flag set, add message to history */
+ if (attr & MSG_HIST)
+ {
+ add_msg_hist(str, len, attr);
+ attr &= ~MSG_HIST;
+ }
+
+#ifdef FEAT_MBYTE
+ /* If the string starts with a composing character first draw a space on
+ * which the composing char can be drawn. */
+ if (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr)))
+ msg_puts_attr((char_u *)" ", attr);
+#endif
+
+ /*
+ * Go over the string. Special characters ar