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

Data Structures

struct  msgchunk_S


#define DLG_BUTTON_SEP   '\n'
#define DLG_HOTKEY_CHAR   '&'
#define MULTILINE_BUFSIZE   8192
#define LINE_BUFFER_SIZE   4096
#define HAS_HOTKEY_LEN   30


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 *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 (const char *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 (const char *s,...) FUNC_ATTR_PRINTF(1
int va_start (arglist, s)
 vim_vsnprintf ((char *) IObuff, IOSIZE, s, arglist)
 va_end (arglist)
return msg ((char *) IObuff)
int smsg_attr (int attr, const char *s,...) FUNC_ATTR_PRINTF(2
return msg_attr ((const char *) IObuff, attr)
int smsg_attr_keep (int attr, const char *s,...) FUNC_ATTR_PRINTF(2
return msg_attr_keep ((const char *) IObuff, attr, true, false)
void reset_last_sourcing (void)
void msg_source (int attr)
int emsg_not_now (void)
bool emsg (const char *s)
void emsg_invreg (int name)
bool semsg (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 semsg_multiline (const char *const fmt,...)
void iemsg (const char *s)
void siemsg (const char *s,...)
void internal_error (char *where)
 Give an "Internal error" message. More...
void msg_schedule_semsg (const char *const fmt,...) FUNC_ATTR_PRINTF(1
 vim_vsnprintf ((char *) IObuff, IOSIZE, fmt, ap)
 multiqueue_put (, msg_semsg_event, 1, s)
char * msg_trunc_attr (char *s, int force, int attr)
char_umsg_may_trunc (int force, char_u *s)
void clear_hl_msg (HlMessage *hl_msg)
void add_hl_msg_hist (HlMessage hl_msg)
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 *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_outtrans_long_attr (char_u *longstr, int attr)
void msg_outtrans_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 = semsgv(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 LINE_BUFFER_SIZE   4096


#define MULTILINE_BUFSIZE   8192

Typedef Documentation

◆ msgchunk_T

typedef struct msgchunk_S msgchunk_T

Enumeration Type Documentation

◆ sb_clear_T

enum sb_clear_T

Function Documentation

◆ add_hl_msg_hist()

void add_hl_msg_hist ( HlMessage  hl_msg)

◆ clear_hl_msg()

void clear_hl_msg ( HlMessage *  hl_msg)

◆ clear_sb_text()

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.

◆ delete_first_msg()

int delete_first_msg ( void  )

◆ display_confirm_msg()

void display_confirm_msg ( void  )

◆ do_dialog()

int do_dialog ( int  type,
char_u title,
char_u message,
char_u buttons,
int  dfltbutton,
char_u textfield,
int  ex_cmd 

Used for "confirm()" function, and the :confirm command prefix. Versions which haven't got flexible dialogs yet, and console versions, get this generic handler which uses the command line.

type = one of: VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC title = title string (can be NULL for default) (neither used in console dialogs at the moment)

Format of the "buttons" string: "Button1Name\nButton2Name\nButton3Name" The first button should normally be the default/accept The second button should be the 'Cancel' button Other buttons- use your imagination! A '&' in a button name becomes a shortcut, so each '&' should be before a different letter.

textfielIObuff for inputdialog(), NULL otherwise
ex_cmdwhen TRUE pressing : accepts default and starts Ex command

◆ emsg()

bool emsg ( const char *  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

◆ emsg_invreg()

void emsg_invreg ( int  name)

◆ emsg_not_now()

int emsg_not_now ( void  )

◆ ex_messages()

void ex_messages ( void *const  eap_p)

:messages command implementation

◆ give_warning()

void give_warning ( char_u message,
bool  hl 

◆ give_warning2()

void give_warning2 ( char_u *const  message,
char_u *const  a1,
bool  hl 

◆ iemsg()

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.

◆ internal_error()

void internal_error ( char *  where)

Give an "Internal error" message.

◆ may_clear_sb_text()

void may_clear_sb_text ( void  )

◆ message_filtered()

bool message_filtered ( char_u msg)

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

◆ msg() [1/2]

return msg ( (char *)  IObuff)

◆ msg() [2/2]

int msg ( char *  s)

◆ msg_advance()

void msg_advance ( int  col)

◆ msg_attr() [1/2]

return msg_attr ( (const char *)  IObuff,

◆ msg_attr() [2/2]

int msg_attr ( const char *  s,
const int  attr 

◆ msg_attr_keep() [1/2]

return msg_attr_keep ( (const char *)  IObuff,
attr  ,
true  ,

◆ msg_attr_keep() [2/2]

bool msg_attr_keep ( const char *  s,
int  attr,
bool  keep,
bool  multiline 
keepset keep_msg if it doesn't scroll

◆ msg_check()

void msg_check ( void  )

◆ msg_clr_cmdline()

void msg_clr_cmdline ( void  )

◆ msg_clr_eos()

void msg_clr_eos ( void  )

◆ msg_clr_eos_force()

void msg_clr_eos_force ( void  )

◆ msg_do_throttle()

bool msg_do_throttle ( void  )

◆ msg_end()

int msg_end ( void  )

◆ msg_end_prompt()

void msg_end_prompt ( void  )

◆ msg_ext_check_clear()

void msg_ext_check_clear ( void  )

◆ msg_ext_clear()

void msg_ext_clear ( bool  force)

◆ msg_ext_clear_later()

void msg_ext_clear_later ( void  )

◆ msg_ext_flush_showmode()

void msg_ext_flush_showmode ( void  )

◆ msg_ext_is_visible()

bool msg_ext_is_visible ( void  )

◆ msg_ext_set_kind()

void msg_ext_set_kind ( const char *  msg_kind)

◆ msg_ext_ui_flush()

void msg_ext_ui_flush ( void  )

◆ msg_grid_set_pos()

void msg_grid_set_pos ( int  row,
bool  scrolled 

◆ msg_grid_validate()

void msg_grid_validate ( void  )

◆ msg_home_replace()

void msg_home_replace ( char_u fname)

◆ msg_home_replace_hl()

void msg_home_replace_hl ( char_u fname)

◆ msg_make()

void msg_make ( char_u arg)

◆ msg_may_trunc()

char_u* msg_may_trunc ( int  force,
char_u s 

◆ msg_moremsg()

void msg_moremsg ( int  full)

◆ msg_multiline_attr()

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.

◆ msg_outnum()

void msg_outnum ( long  n)

◆ msg_outtrans()

int msg_outtrans ( char_u str)

◆ msg_outtrans_attr()

int msg_outtrans_attr ( const char_u str,
int  attr 

◆ msg_outtrans_len()

int msg_outtrans_len ( const char_u str,
int  len 

◆ msg_outtrans_len_attr()

int msg_outtrans_len_attr ( const char_u msgstr,
int  len,
int  attr 

◆ msg_outtrans_long_attr()

void msg_outtrans_long_attr ( char_u longstr,
int  attr 

◆ msg_outtrans_long_len_attr()

void msg_outtrans_long_len_attr ( char_u longstr,
int  len,
int  attr 

◆ msg_outtrans_one()

char_u* msg_outtrans_one ( char_u p,
int  attr 

◆ msg_outtrans_special()

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 unlimited

◆ msg_printf_attr()

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.

◆ msg_prt_line()

void msg_prt_line ( char_u s,
int  list 

◆ msg_putchar()

void msg_putchar ( int  c)

◆ msg_putchar_attr()

void msg_putchar_attr ( int  c,
int  attr 

◆ msg_puts()

void msg_puts ( const char *  s)

◆ msg_puts_attr()

void msg_puts_attr ( const char *const  s,
const int  attr 

◆ msg_puts_attr_len() [1/2]

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() [2/2]

msg_puts_attr_len ( msgbuf  ,
(ptrdiff_t)  len,

◆ msg_puts_title()

void msg_puts_title ( const char *  s)

◆ msg_reset_scroll()

void msg_reset_scroll ( void  )

◆ msg_sb_eol()

void msg_sb_eol ( void  )

◆ msg_schedule_semsg()

void msg_schedule_semsg ( const char *const  fmt,

◆ msg_scroll_flush()

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 assumptions. 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 be reimplemented 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_later code paths.

◆ msg_scroll_up()

void msg_scroll_up ( bool  may_throttle)

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

◆ msg_scrollsize()

int msg_scrollsize ( void  )

including horizontal separator

◆ msg_source()

void msg_source ( int  attr)

◆ msg_start()

void msg_start ( void  )

◆ msg_starthere()

void msg_starthere ( void  )

◆ msg_strtrunc()

char_u* msg_strtrunc ( char_u s,
int  force 

Truncate a string such that it can be printed without causing a scroll. Returns an allocated string or NULL when no truncating is done.

forcealways truncate

◆ msg_trunc_attr()

char* msg_trunc_attr ( char *  s,
int  force,
int  attr 

◆ msg_use_grid()

bool msg_use_grid ( void  )

◆ msg_use_msgsep()

bool msg_use_msgsep ( void  )

◆ msg_use_printf()

int msg_use_printf ( void  )

◆ multiqueue_put()

multiqueue_put ( main_loop.  events,
msg_semsg_event  ,

◆ redirecting()

int redirecting ( void  )

◆ repeat_message()

void repeat_message ( void  )

◆ reset_last_sourcing()

void reset_last_sourcing ( void  )

◆ sb_text_end_cmdline()

void sb_text_end_cmdline ( void  )

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

◆ sb_text_start_cmdline()

void sb_text_start_cmdline ( void  )

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

◆ semsg()

bool semsg ( const char *const  fmt,

Print an error message with unknown number of arguments.

◆ semsg_multiline()

bool semsg_multiline ( const char *const  fmt,

◆ set_keep_msg()

void set_keep_msg ( char *  s,
int  attr 

◆ show_sb_text()

void show_sb_text ( void  )

◆ siemsg()

void siemsg ( const char *  s,

Same as semsg(...) 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.

◆ smsg()

int smsg ( const char *  s,

◆ smsg_attr()

int smsg_attr ( int  attr,
const char *  s,

◆ smsg_attr_keep()

int smsg_attr_keep ( int  attr,
const char *  s,

◆ str2special()

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.

◆ str2special_save()

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.

◆ str2specialbuf()

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.

◆ trunc_string()

void trunc_string ( char_u s,
char_u buf,
int  room_in,
int  buflen 

◆ va_end() [1/2]

va_end ( ap  )

◆ va_end() [2/2]

va_end ( arglist  )

◆ va_start() [1/2]

int va_start ( ap  ,
Initial value:
va_list ap

◆ va_start() [2/2]

int va_start ( arglist  ,
Initial value:
va_list arglist

◆ verb_msg()

int verb_msg ( char *  s)

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

◆ verbose_enter()

void verbose_enter ( void  )

◆ verbose_enter_scroll()

void verbose_enter_scroll ( void  )

◆ verbose_leave()

void verbose_leave ( void  )

◆ verbose_leave_scroll()

void verbose_leave_scroll ( void  )

◆ verbose_open()

int verbose_open ( void  )

◆ verbose_stop()

void verbose_stop ( void  )

◆ vim_dialog_yesno()

int vim_dialog_yesno ( int  type,
char_u title,
char_u message,
int  dflt 

◆ vim_dialog_yesnoallcancel()

int vim_dialog_yesnoallcancel ( int  type,
char_u title,
char_u message,
int  dflt 

◆ vim_dialog_yesnocancel()

int vim_dialog_yesnocancel ( int  type,
char_u title,
char_u message,
int  dflt 

◆ vim_vsnprintf() [1/2]

vim_vsnprintf ( (char *)  IObuff,
fmt  ,

◆ vim_vsnprintf() [2/2]

vim_vsnprintf ( (char *)  IObuff,
s  ,

◆ wait_return()

void wait_return ( int  redraw)

Wait for the user to hit a key (normally Enter)

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

◆ ap

void va_list ap
Initial value:
bool ret

◆ first_msg_hist

MessageHistoryEntry* first_msg_hist = NULL

First message.

◆ last_msg_hist

MessageHistoryEntry* last_msg_hist = NULL

Last message.

◆ len

const size_t len = vim_vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap)

◆ msg_scroll

msg_scroll = true

◆ ret

return ret = semsgv(fmt, ap)

◆ s

char* s = xstrdup((char *)IObuff)
Definition: message.c:751
Definition: buffer_defs.h:295
bool va_list ap
Definition: message.c:746