Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
message.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/message.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/keymap.h"
#include "nvim/garray.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/normal.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/highlight.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
#include "nvim/mouse.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/api/private/helpers.h"

Data Structures

struct  msgchunk_S


#define DLG_BUTTON_SEP   '\n'
#define DLG_HOTKEY_CHAR   '&'
#define MULTILINE_BUFSIZE   8192
#define HAS_HOTKEY_LEN   30
#define HOTK_LEN   (has_mbyte ? MB_MAXBYTES : 1)


typedef struct msgchunk_S msgchunk_T




void msg_grid_set_pos (int row, bool scrolled)
bool msg_use_grid (void)
void msg_grid_validate (void)
int msg (char_u *s)
int verb_msg (char *s)
 Like msg() but keep it silent when 'verbosefile' is set. More...
int msg_attr (const char *s, const int attr) FUNC_ATTR_NONNULL_ARG(1)
void msg_multiline_attr (const char *s, int attr, bool check_int, bool *need_clear) FUNC_ATTR_NONNULL_ALL
 similar to msg_outtrans_attr, but support newlines and tabs. More...
bool msg_attr_keep (char_u *s, int attr, bool keep, bool multiline) FUNC_ATTR_NONNULL_ALL
char_umsg_strtrunc (char_u *s, int force)
void trunc_string (char_u *s, char_u *buf, int room_in, int buflen)
int smsg (char *s,...) FUNC_ATTR_PRINTF(1
int va_start (arglist, s)
 vim_vsnprintf ((char *) IObuff, IOSIZE, s, arglist)
 va_end (arglist)
return msg (IObuff)
int smsg_attr (int attr, char *s,...) FUNC_ATTR_PRINTF(2
return msg_attr ((const char *) IObuff, attr)
int smsg_attr_keep (int attr, char *s,...) FUNC_ATTR_PRINTF(2
return msg_attr_keep (IObuff, attr, true, false)
void reset_last_sourcing (void)
void msg_source (int attr)
int emsg_not_now (void)
bool emsg (const char_u *s)
void emsg_invreg (int name)
bool emsgf (const char *const fmt,...) FUNC_ATTR_PRINTF(1
 Print an error message with unknown number of arguments. More...
 va_start (ap, fmt)
 va_end (ap)
bool emsgf_multiline (const char *const fmt,...)
void iemsg (const char *s)
void iemsgf (const char *s,...)
void internal_error (char *where)
 Give an "Internal error" message. More...
void msg_schedule_emsgf (const char *const fmt,...) FUNC_ATTR_PRINTF(1
 vim_vsnprintf ((char *) IObuff, IOSIZE, fmt, ap)
 multiqueue_put (, msg_emsgf_event, 1, s)
char_umsg_trunc_attr (char_u *s, int force, int attr)
char_umsg_may_trunc (int force, char_u *s)
int delete_first_msg (void)
void ex_messages (void *const eap_p) FUNC_ATTR_NONNULL_ALL
 :messages command implementation More...
void msg_end_prompt (void)
void wait_return (int redraw)
void set_keep_msg (char_u *s, int attr)
void msg_ext_set_kind (const char *msg_kind)
void msg_start (void)
void msg_starthere (void)
void msg_putchar (int c)
void msg_putchar_attr (int c, int attr)
void msg_outnum (long n)
void msg_home_replace (char_u *fname)
void msg_home_replace_hl (char_u *fname)
int msg_outtrans (char_u *str)
int msg_outtrans_attr (const char_u *str, int attr)
int msg_outtrans_len (const char_u *str, int len)
char_umsg_outtrans_one (char_u *p, int attr)
int msg_outtrans_len_attr (const char_u *msgstr, int len, int attr)
void msg_make (char_u *arg)
int msg_outtrans_special (const char_u *strstart, bool from, int maxlen)
char * str2special_save (const char *const str, const bool replace_spaces, const bool replace_lt) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET
const char * str2special (const char **const sp, const bool replace_spaces, const bool replace_lt) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
void str2specialbuf (const char *sp, char *buf, size_t len) FUNC_ATTR_NONNULL_ALL
void msg_prt_line (char_u *s, int list)
void msg_puts (const char *s)
void msg_puts_title (const char *s)
void msg_puts_long_attr (char_u *longstr, int attr)
void msg_puts_long_len_attr (char_u *longstr, int len, int attr)
void msg_puts_attr (const char *const s, const int attr)
void msg_puts_attr_len (const char *const str, const ptrdiff_t len, int attr) FUNC_ATTR_NONNULL_ALL
void msg_printf_attr (const int attr, const char *const fmt,...) FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_PRINTF(2
 msg_puts_attr_len (msgbuf,(ptrdiff_t) len, attr)
bool message_filtered (char_u *msg)
int msg_scrollsize (void)
 including horizontal separator More...
bool msg_use_msgsep (void)
bool msg_do_throttle (void)
void msg_scroll_up (bool may_throttle)
 Scroll the screen up one line for displaying the next message line. More...
void msg_scroll_flush (void)
void msg_reset_scroll (void)
void may_clear_sb_text (void)
void sb_text_start_cmdline (void)
 Starting to edit the command line, do not clear messages now. More...
void sb_text_end_cmdline (void)
 Ending to edit the command line. Clear old lines but the last one later. More...
void clear_sb_text (int all)
void show_sb_text (void)
void msg_sb_eol (void)
int msg_use_printf (void)
void msg_moremsg (int full)
void repeat_message (void)
void msg_clr_eos (void)
void msg_clr_eos_force (void)
void msg_clr_cmdline (void)
int msg_end (void)
void msg_ext_ui_flush (void)
void msg_ext_flush_showmode (void)
void msg_ext_clear (bool force)
void msg_ext_clear_later (void)
void msg_ext_check_clear (void)
bool msg_ext_is_visible (void)
void msg_check (void)
int redirecting (void)
void verbose_enter (void)
void verbose_leave (void)
void verbose_enter_scroll (void)
void verbose_leave_scroll (void)
void verbose_stop (void)
int verbose_open (void)
void give_warning (char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
void give_warning2 (char_u *const message, char_u *const a1, bool hl)
void msg_advance (int col)
int do_dialog (int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd)
void display_confirm_msg (void)
int vim_dialog_yesno (int type, char_u *title, char_u *message, int dflt)
int vim_dialog_yesnocancel (int type, char_u *title, char_u *message, int dflt)
int vim_dialog_yesnoallcancel (int type, char_u *title, char_u *message, int dflt)


MessageHistoryEntryfirst_msg_hist = NULL
 First message. More...
MessageHistoryEntrylast_msg_hist = NULL
 Last message. More...
bool va_list ap
 ret = emsgfv(fmt, ap)
char * s = xstrdup((char *)IObuff)
const size_t len = vim_vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap)
 msg_scroll = true

Macro Definition Documentation

#define DLG_BUTTON_SEP   '\n'
#define DLG_HOTKEY_CHAR   '&'
#define HAS_HOTKEY_LEN   30
#define HOTK_LEN   (has_mbyte ? MB_MAXBYTES : 1)
#define MULTILINE_BUFSIZE   8192

Typedef Documentation

typedef struct msgchunk_S msgchunk_T

Enumeration Type Documentation

enum sb_clear_T

Function Documentation

void clear_sb_text ( int  all)

Clear any text remembered for scrolling back. When "all" is FALSE keep the last line. Called when redrawing the screen.

int delete_first_msg ( void  )
void display_confirm_msg ( void  )
int do_dialog ( int  type,
char_u title,
char_u message,
char_u buttons,
int  dfltbutton,
char_u textfield,
int  ex_cmd 
bool emsg ( const char_u s)

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.

true if wait_return not called
void emsg_invreg ( int  name)
int emsg_not_now ( void  )
bool emsgf ( const char *const  fmt,

Print an error message with unknown number of arguments.

bool emsgf_multiline ( const char *const  fmt,
void ex_messages ( void *const  eap_p)

:messages command implementation

void give_warning ( char_u message,
bool  hl 
void give_warning2 ( char_u *const  message,
char_u *const  a1,
bool  hl 
void iemsg ( const char *  s)

Same as emsg(...), but abort on error when ABORT_ON_INTERNAL_ERROR is defined. It is used for internal errors only, so that they can be detected when fuzzing vim.

void iemsgf ( const char *  s,

Same as emsgf(...) but abort on error when ABORT_ON_INTERNAL_ERROR is defined. It is used for internal errors only, so that they can be detected when fuzzing vim.

void internal_error ( char *  where)

Give an "Internal error" message.

void may_clear_sb_text ( void  )
bool message_filtered ( char_u msg)

Return true when ":filter pattern" was used and "msg" does not match "pattern".

int msg ( char_u s)
return msg ( IObuff  )
void msg_advance ( int  col)
int msg_attr ( const char *  s,
const int  attr 
return msg_attr ( (const char *)  IObuff,
bool msg_attr_keep ( char_u s,
int  attr,
bool  keep,
bool  multiline 
keepset keep_msg if it doesn't scroll
return msg_attr_keep ( IObuff  ,
attr  ,
true  ,
void msg_check ( void  )
void msg_clr_cmdline ( void  )
void msg_clr_eos ( void  )
void msg_clr_eos_force ( void  )
bool msg_do_throttle ( void  )
int msg_end ( void  )
void msg_end_prompt ( void  )
void msg_ext_check_clear ( void  )
void msg_ext_clear ( bool  force)
void msg_ext_clear_later ( void  )
void msg_ext_flush_showmode ( void  )
bool msg_ext_is_visible ( void  )
void msg_ext_set_kind ( const char *  msg_kind)
void msg_ext_ui_flush ( void  )
void msg_grid_set_pos ( int  row,
bool  scrolled 
void msg_grid_validate ( void  )
void msg_home_replace ( char_u fname)
void msg_home_replace_hl ( char_u fname)
void msg_make ( char_u arg)
char_u* msg_may_trunc ( int  force,
char_u s 
void msg_moremsg ( int  full)
void msg_multiline_attr ( const char *  s,
int  attr,
bool  check_int,
bool *  need_clear 

similar to msg_outtrans_attr, but support newlines and tabs.

void msg_outnum ( long  n)
int msg_outtrans ( char_u str)
int msg_outtrans_attr ( const char_u str,
int  attr 
int msg_outtrans_len ( const char_u str,
int  len 
int msg_outtrans_len_attr ( const char_u msgstr,
int  len,
int  attr 
char_u* msg_outtrans_one ( char_u p,
int  attr 
int msg_outtrans_special ( const char_u strstart,
bool  from,
int  maxlen 

Output the string 'str' up to a NUL character. Return the number of characters it takes on the screen.

If K_SPECIAL is encountered, then it is taken in conjunction with the following character and shown as <F1>, <S-Up> etc. Any other character which is not printable shown in <> form. If 'from' is TRUE (lhs of a mapping), a space is shown as <Space>. If a character is displayed in one of these special ways, is also highlighted (its highlight name is '8' in the p_hl variable). Otherwise characters are not highlighted. This function is used to show mappings, where we want to see how to type the character/string – webb

fromtrue for LHS of a mapping
maxlenscreen columns, 0 for unlimeted
void msg_printf_attr ( const int  attr,
const char *const  fmt,

Print a formatted message

Message printed is limited by IOSIZE. Must not be used from inside msg_puts_attr().

[in]attrHighlight attributes.
[in]fmtFormat string.
void msg_prt_line ( char_u s,
int  list 
void msg_putchar ( int  c)
void msg_putchar_attr ( int  c,
int  attr 
void msg_puts ( const char *  s)
void msg_puts_attr ( const char *const  s,
const int  attr 
void msg_puts_attr_len ( const char *const  str,
const ptrdiff_t  len,
int  attr 

Write a message with highlight attributes

[in]strNUL-terminated message string.
[in]lenLength of the string or -1.
[in]attrHighlight attribute.
msg_puts_attr_len ( msgbuf  ,
(ptrdiff_t)  len,
void msg_puts_long_attr ( char_u longstr,
int  attr 
void msg_puts_long_len_attr ( char_u longstr,
int  len,
int  attr 
void msg_puts_title ( const char *  s)
void msg_reset_scroll ( void  )
void msg_sb_eol ( void  )
void msg_schedule_emsgf ( const char *const  fmt,
void msg_scroll_flush ( void  )

Send throttled message output to UI clients

The way message.c uses the grid_xx family of functions is quite inefficient relative to the "gridline" UI protocol used by TUI and modern clients. For instance scrolling is done one line at a time. By throttling drawing on the message grid, we can coalesce scrolling to a single grid_scroll per screen update.

NB: The bookkeeping is quite messy, and rests on a bunch of poorly documented assumtions. For instance that the message area always grows while being throttled, messages are only being output on the last line etc.

Probably message scrollback storage should reimplented as a file_buffer, and message scrolling in TUI be reimplemented as a modal floating window. Then we get throttling "for free" using standard redraw_win_later code paths.

void msg_scroll_up ( bool  may_throttle)

Scroll the screen up one line for displaying the next message line.

int msg_scrollsize ( void  )

including horizontal separator

void msg_source ( int  attr)
void msg_start ( void  )
void msg_starthere ( void  )
char_u* msg_strtrunc ( char_u s,
int  force 
char_u* msg_trunc_attr ( char_u s,
int  force,
int  attr 
bool msg_use_grid ( void  )
bool msg_use_msgsep ( void  )
int msg_use_printf ( void  )
multiqueue_put ( main_loop.  events,
msg_emsgf_event  ,
int redirecting ( void  )
void repeat_message ( void  )
void reset_last_sourcing ( void  )
void sb_text_end_cmdline ( void  )

Ending to edit the command line. Clear old lines but the last one later.

void sb_text_start_cmdline ( void  )

Starting to edit the command line, do not clear messages now.

void set_keep_msg ( char_u s,
int  attr 
void show_sb_text ( void  )
int smsg ( char *  s,
int smsg_attr ( int  attr,
char *  s,
int smsg_attr_keep ( int  attr,
char *  s,
const char* str2special ( const char **const  sp,
const bool  replace_spaces,
const bool  replace_lt 

Convert character, replacing key with printable representation.

[in,out]spString to convert. Is advanced to the next key code.
[in]replace_spacesConvert spaces into <Space>, normally used for lhs, but not rhs.
[in]replace_ltConvert < into <lt>.
Converted key code, in a static buffer. Buffer is always one and the same, so save converted string somewhere before running str2special for the second time.
char* str2special_save ( const char *const  str,
const bool  replace_spaces,
const bool  replace_lt 

Convert string, replacing key codes with printables

Used for lhs or rhs of mappings.

[in]strString to convert.
[in]replace_spacesConvert spaces into <Space>, normally used fo lhs, but not rhs.
[in]replace_ltConvert < into <lt>.
[allocated] Converted string.
void str2specialbuf ( const char *  sp,
char *  buf,
size_t  len 

Convert string, replacing key codes with printables

[in]strString to convert.
[out]bufBuffer to save results to.
[in]lenBuffer length.
void trunc_string ( char_u s,
char_u buf,
int  room_in,
int  buflen 
va_end ( arglist  )
va_end ( ap  )
int va_start ( arglist  ,
Initial value:
va_list arglist
Definition: buffer_defs.h:292
int va_start ( ap  ,
Initial value:
va_list ap
bool va_list ap
Definition: message.c:744
int verb_msg ( char *  s)

Like msg() but keep it silent when 'verbosefile' is set.

void verbose_enter ( void  )
void verbose_enter_scroll ( void  )
void verbose_leave ( void  )
void verbose_leave_scroll ( void  )
int verbose_open ( void  )
void verbose_stop ( void  )
int vim_dialog_yesno ( int  type,
char_u title,
char_u message,
int  dflt 
int vim_dialog_yesnoallcancel ( int  type,
char_u title,
char_u message,
int  dflt 
int vim_dialog_yesnocancel ( int  type,
char_u title,
char_u message,
int  dflt 
vim_vsnprintf ( (char *)  IObuff,
s  ,
vim_vsnprintf ( (char *)  IObuff,
fmt  ,
void wait_return ( int  redraw)

wait for the user to hit a key (normally a return)

if 'redraw' is true, redraw the entire screen NOT_VALID if 'redraw' is false, do a normal redraw if 'redraw' is -1, don't redraw at all

Variable Documentation

void va_list ap
Initial value:
bool ret
Definition: message.c:749
MessageHistoryEntry* first_msg_hist = NULL

First message.

MessageHistoryEntry* last_msg_hist = NULL

Last message.

const size_t len = vim_vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap)
msg_scroll = true
return ret = emsgfv(fmt, ap)
char* s = xstrdup((char *)IObuff)