Macros | Enumerations | Functions | Variables
getchar.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/event/loop.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/ex_session.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/input.h"
#include "nvim/keycodes.h"
#include "nvim/lua/executor.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os/fileio.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/plines.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"


#define MINIMAL_SIZE   20
#define MAP_HASH(mode, c1)
#define RM_YES   0
#define RM_NONE   1
#define RM_SCRIPT   2
#define RM_ABBR   4
#define TYPELEN_INIT   (5 * (MAXMAPLEN + 3))
#define DUM_LEN   (MAXMAPLEN * 3 + 3)
#define MAPMODE(mode, modechars, chr, modeflags)


enum  map_result_T { map_result_fail, map_result_get, map_result_retry, map_result_nomatch }


void free_buff (buffheader_T *buf)
char_uget_recorded (void)
char_uget_inserted (void)
int stuff_empty (void)
int readbuf1_empty (void)
void typeahead_noflush (int c)
void flush_buffers (flush_buffers_T flush_typeahead)
void beep_flush (void)
 flush map and typeahead buffers and give a warning for an error More...
void ResetRedobuff (void)
void CancelRedo (void)
void saveRedobuff (save_redo_T *save_redo)
void restoreRedobuff (save_redo_T *save_redo)
void AppendToRedobuff (const char *s)
void AppendToRedobuffLit (const char *str, int len)
void AppendCharToRedobuff (int c)
void AppendNumberToRedobuff (long n)
void stuffReadbuff (const char *s)
void stuffRedoReadbuff (const char *s)
void stuffReadbuffLen (const char *s, long len)
void stuffReadbuffSpec (const char *s)
void stuffcharReadbuff (int c)
void stuffnumReadbuff (long n)
int start_redo (long count, bool old_redo)
int start_redo_ins (void)
void stop_redo_ins (void)
void init_default_mappings (void)
int ins_typebuf (char *str, int noremap, int offset, bool nottyped, bool silent)
int ins_char_typebuf (int c, int modifier)
bool typebuf_changed (int tb_change_cnt) FUNC_ATTR_PURE
int typebuf_typed (void)
int typebuf_maplen (void)
void del_typebuf (int len, int offset)
void ungetchars (int len)
void may_sync_undo (void)
void alloc_typebuf (void)
void free_typebuf (void)
void save_typebuf (void)
void save_typeahead (tasave_T *tp)
void restore_typeahead (tasave_T *tp)
void openscript (char_u *name, bool directly)
int using_script (void)
void before_blocking (void)
int merge_modifiers (int c_arg, int *modifiers)
 Merge "modifiers" into "c_arg". More...
int vgetc (void)
int safe_vgetc (void)
int plain_vgetc (void)
int vpeekc (void)
int vpeekc_any (void)
int char_avail (void)
void vungetc (int c)
void check_end_reg_executing (bool advance)
int inchar (char_u *buf, int maxlen, long wait_time)
int fix_input_buffer (char_u *buf, int len) FUNC_ATTR_NONNULL_ALL
void set_maparg_lhs_rhs (const char *const orig_lhs, const size_t orig_lhs_len, const char *const orig_rhs, const size_t orig_rhs_len, const LuaRef rhs_lua, const int cpo_flags, MapArguments *const mapargs)
int str_to_mapargs (const char_u *strargs, bool is_unmap, MapArguments *mapargs)
int buf_do_map (int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T *buf)
int do_map (int maptype, char_u *arg, int mode, bool is_abbrev)
int get_map_mode (char **cmdp, bool forceit)
void map_clear_mode (char_u *cmdp, char_u *arg, int forceit, int abbr)
void map_clear_int (buf_T *buf, int mode, bool local, bool abbr)
char * map_mode_to_chars (int mode) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET
bool map_to_exists (const char *const str, const char *const modechars, const bool abbr) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
int map_to_exists_mode (const char *const rhs, const int mode, const bool abbr)
char_uset_context_in_map_cmd (expand_T *xp, char_u *cmd, char_u *arg, bool forceit, bool isabbrev, bool isunmap, cmdidx_T cmdidx)
int ExpandMappings (regmatch_T *regmatch, int *num_file, char_u ***file)
bool check_abbr (int c, char_u *ptr, int col, int mincol)
char * vim_strsave_escape_ks (char *p)
void vim_unescape_ks (char_u *p)
int makemap (FILE *fd, buf_T *buf)
int put_escstr (FILE *fd, char_u *strstart, int what)
char_ucheck_map (char_u *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr, int *rhs_lua)
void add_map (char_u *map, int mode, bool nore)
mapblock_Tget_maphash (int index, buf_T *buf) FUNC_ATTR_PURE
char * getcmdkeycmd (int promptc, void *cookie, int indent, bool do_concat)
 Get command argument for <Cmd> key. More...
bool map_execute_lua (void)


FileDescriptorscriptin [NSCRIPT] = { NULL }
 Streams to read script from. More...

Macro Definition Documentation


#define DUM_LEN   (MAXMAPLEN * 3 + 3)


#define MAP_HASH (   mode,
(((mode) & \
MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80))


#define MAPMODE (   mode,
do { \
if (strchr(modechars, chr) != NULL) { \
mode |= modeflags; \
} \
} while (0)


#define MINIMAL_SIZE   20


#define RM_ABBR   4


#define RM_NONE   1


#define RM_SCRIPT   2


#define RM_YES   0


#define TYPELEN_INIT   (5 * (MAXMAPLEN + 3))

Enumeration Type Documentation

◆ map_result_T


Function Documentation

◆ add_map()

void add_map ( char_u map,
int  mode,
bool  nore 

Add a mapping. Unlike do_map this copies the {map} argument, so static or read-only strings can be used.

mapC-string containing the arguments of the map/abbrev command, i.e. everything except the initial :[X][nore]map.
modeBitflags representing the mode in which to set the mapping. See get_map_mode.
noreIf true, make a non-recursive mapping.

◆ alloc_typebuf()

void alloc_typebuf ( void  )

◆ AppendCharToRedobuff()

void AppendCharToRedobuff ( int  c)

Append a character to the redo buffer. Translates special keys, NUL, K_SPECIAL and multibyte characters.

◆ AppendNumberToRedobuff()

void AppendNumberToRedobuff ( long  n)

◆ AppendToRedobuff()

void AppendToRedobuff ( const char *  s)

Append "s" to the redo buffer. K_SPECIAL should already have been escaped.

◆ AppendToRedobuffLit()

void AppendToRedobuffLit ( const char *  str,
int  len 

Append to Redo buffer literally, escaping special characters with CTRL-V. K_SPECIAL is escaped as well.

strString to append
lenLength of str or -1 for up to the NUL.

◆ beep_flush()

void beep_flush ( void  )

flush map and typeahead buffers and give a warning for an error

◆ before_blocking()

void before_blocking ( void  )

This function is called just before doing a blocking wait. Thus after waiting 'updatetime' for a character to arrive.

◆ buf_do_map()

int buf_do_map ( int  maptype,
MapArguments args,
int  mode,
bool  is_abbrev,
buf_T buf 

Sets or removes a mapping or abbreviation in buffer buf.

See also
argsFully parsed and "preprocessed" arguments for the (un)map/abbrev command. Termcodes should have already been replaced; whitespace, < and > signs, etc. in {lhs} and {rhs} are assumed to be literal components of the mapping.
See also
See also
bufTarget Buffer

◆ CancelRedo()

void CancelRedo ( void  )

◆ char_avail()

int char_avail ( void  )

◆ check_abbr()

bool check_abbr ( int  c,
char_u ptr,
int  col,
int  mincol 

◆ check_end_reg_executing()

void check_end_reg_executing ( bool  advance)

When peeking and not getting a character, reg_executing cannot be cleared yet, so set a flag to clear it later.

◆ check_map()

char_u* check_map ( char_u keys,
int  mode,
int  exact,
int  ign_mod,
int  abbr,
mapblock_T **  mp_ptr,
int *  local_ptr,
int *  rhs_lua 

Check the string "keys" against the lhs of all mappings. Return pointer to rhs of mapping (mapblock->m_str). NULL when no mapping found.

exactrequire exact match
ign_modignore preceding modifier
abbrdo abbreviations
mp_ptrreturn: pointer to mapblock or NULL
local_ptrreturn: buffer-local mapping or NULL

◆ del_typebuf()

void del_typebuf ( int  len,
int  offset 

◆ do_map()

int do_map ( int  maptype,
char_u arg,
int  mode,
bool  is_abbrev 

Set or remove a mapping or an abbreviation in the current buffer, OR display (matching) mappings/abbreviations.

map[!] " show all key mappings
map[!] {lhs} " show key mapping for {lhs}
map[!] {lhs} {rhs} " set key mapping for {lhs} to {rhs}
noremap[!] {lhs} {rhs} " same, but no remapping for {rhs}
unmap[!] {lhs} " remove key mapping for {lhs}
abbr " show all abbreviations
abbr {lhs} " show abbreviations for {lhs}
abbr {lhs} {rhs} " set abbreviation for {lhs} to {rhs}
noreabbr {lhs} {rhs} " same, but no remapping for {rhs}
unabbr {lhs} " remove abbreviation for {lhs}
for :map! mode is MODE_INSERT | MODE_CMDLINE
for :cmap mode is MODE_CMDLINE
for :imap mode is MODE_INSERT
for :lmap mode is MODE_LANGMAP
for :nmap mode is MODE_NORMAL
for :vmap mode is MODE_VISUAL | MODE_SELECT
for :xmap mode is MODE_VISUAL
for :smap mode is MODE_SELECT
for :omap mode is MODE_OP_PENDING
for :tmap mode is MODE_TERMINAL
for :abbr mode is MODE_INSERT | MODE_CMDLINE
for :iabbr mode is MODE_INSERT
for :cabbr mode is MODE_CMDLINE
maptype0 for |:map|, 1 for |:unmap|, 2 for |noremap|.
argC-string containing the arguments of the map/abbrev command, i.e. everything except the initial :[X][nore]map.
  • Cannot be a read-only string; it will be modified.
modeBitflags representing the mode in which to set the mapping. See get_map_mode.
is_abbrevTrue if setting an abbreviation, false otherwise.
0 on success. On failure, will return one of the following:
  • 1 for invalid arguments
  • 2 for no match
  • 4 for out of mem (deprecated, WON'T HAPPEN)
  • 5 for entry not unique

◆ ExpandMappings()

int ExpandMappings ( regmatch_T regmatch,
int *  num_file,
char_u ***  file 

◆ fix_input_buffer()

int fix_input_buffer ( char_u buf,
int  len 

◆ flush_buffers()

void flush_buffers ( flush_buffers_T  flush_typeahead)

◆ free_buff()

void free_buff ( buffheader_T buf)

◆ free_typebuf()

void free_typebuf ( void  )

◆ get_inserted()

char_u* get_inserted ( void  )

Return the contents of the redo buffer as a single string. K_SPECIAL in the returned string is escaped.

◆ get_map_mode()

int get_map_mode ( char **  cmdp,
bool  forceit 

◆ get_maphash()

mapblock_T* get_maphash ( int  index,
buf_T buf 

Retrieve the mapblock at the index either globally or for a certain buffer

indexThe index in the maphash[]
bufThe buffer to get the maphash from. NULL for global

◆ get_recorded()

char_u* get_recorded ( void  )

Return the contents of the record buffer as a single string and clear the record buffer. K_SPECIAL in the returned string is escaped.

◆ getcmdkeycmd()

char* getcmdkeycmd ( int  promptc,
void cookie,
int  indent,
bool  do_concat 

Get command argument for <Cmd> key.

◆ inchar()

int inchar ( char_u buf,
int  maxlen,
long  wait_time 

inchar() - get one character from

  1. a scriptfile
  2. the keyboard

As many characters as we can get (up to 'maxlen') are put in "buf" and NUL terminated (buffer length must be 'maxlen' + 1). Minimum for "maxlen" is 3!!!!

"tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into it. When typebuf.tb_change_cnt changes (e.g., when a message is received from a remote client) "buf" can no longer be used. "tb_change_cnt" is 0 otherwise.

If we got an interrupt all input is read until none is available.

If wait_time == 0 there is no waiting for the char. If wait_time == n we wait for n msec for a character to arrive. If wait_time == -1 we wait forever for a character to arrive.

Return the number of obtained characters. Return -1 when end of input script reached.


◆ init_default_mappings()

void init_default_mappings ( void  )

◆ ins_char_typebuf()

int ins_char_typebuf ( int  c,
int  modifier 

Put character "c" back into the typeahead buffer. Can be used for a character obtained by vgetc() that needs to be put back. Uses cmd_silent, KeyTyped and KeyNoremap to restore the flags belonging to the char.

the length of what was inserted

◆ ins_typebuf()

int ins_typebuf ( char *  str,
int  noremap,
int  offset,
bool  nottyped,
bool  silent 

◆ makemap()

int makemap ( FILE *  fd,
buf_T buf 

Write map commands for the current mappings to an .exrc file. Return FAIL on error, OK otherwise.

bufbuffer for local mappings or NULL

◆ map_clear_int()

void map_clear_int ( buf_T buf,
int  mode,
bool  local,
bool  abbr 

Clear all mappings in "mode".

buf,bufferfor local mappings
modemode in which to delete
localtrue for buffer-local mappings
abbrtrue for abbreviations

◆ map_clear_mode()

void map_clear_mode ( char_u cmdp,
char_u arg,
int  forceit,
int  abbr 

◆ map_execute_lua()

bool map_execute_lua ( void  )

◆ map_mode_to_chars()

char* map_mode_to_chars ( int  mode)

Return characters to represent the map mode in an allocated string

[allocated] NUL-terminated string with characters.

◆ map_to_exists()

bool map_to_exists ( const char *const  str,
const char *const  modechars,
const bool  abbr 

Check if a map exists that has given string in the rhs

Also checks mappings local to the current buffer.

[in]strString which mapping must have in the rhs. Termcap codes are recognized in this argument.
[in]modecharsMode(s) in which mappings are checked.
[in]abbrtrue if checking abbreviations in place of mappings.
true if there is at least one mapping with given parameters.

◆ map_to_exists_mode()

int map_to_exists_mode ( const char *const  rhs,
const int  mode,
const bool  abbr 

Check if a map exists that has given string in the rhs

Also checks mappings local to the current buffer.

[in]rhsString which mapping must have in the rhs. Termcap codes are recognized in this argument.
[in]modeMode(s) in which mappings are checked.
[in]abbrtrue if checking abbreviations in place of mappings.
true if there is at least one mapping with given parameters.

◆ may_sync_undo()

void may_sync_undo ( void  )

◆ merge_modifiers()

int merge_modifiers ( int  c_arg,
int *  modifiers 

Merge "modifiers" into "c_arg".

◆ openscript()

void openscript ( char_u name,
bool  directly 

Open a new script file for the ":source!" command.

directlywhen true execute directly

◆ plain_vgetc()

int plain_vgetc ( void  )

◆ put_escstr()

int put_escstr ( FILE *  fd,
char_u strstart,
int  what 

◆ readbuf1_empty()

int readbuf1_empty ( void  )

◆ ResetRedobuff()

void ResetRedobuff ( void  )

◆ restore_typeahead()

void restore_typeahead ( tasave_T tp)

◆ restoreRedobuff()

void restoreRedobuff ( save_redo_T save_redo)

Restore redobuff and old_redobuff from save_redobuff and save_old_redobuff. Used after executing autocommands and user functions.

◆ safe_vgetc()

int safe_vgetc ( void  )

◆ save_typeahead()

void save_typeahead ( tasave_T tp)

◆ save_typebuf()

void save_typebuf ( void  )

◆ saveRedobuff()

void saveRedobuff ( save_redo_T save_redo)

Save redobuff and old_redobuff to save_redobuff and save_old_redobuff. Used before executing autocommands and user functions.

◆ set_context_in_map_cmd()

char_u* set_context_in_map_cmd ( expand_T xp,
char_u cmd,
char_u arg,
bool  forceit,
bool  isabbrev,
bool  isunmap,
cmdidx_T  cmdidx 

Work out what to complete when doing command line completion of mapping or abbreviation names.

forceittrue if '!' given
isabbrevtrue if abbreviation
isunmaptrue if unmap/unabbrev command

◆ set_maparg_lhs_rhs()

void set_maparg_lhs_rhs ( const char *const  orig_lhs,
const size_t  orig_lhs_len,
const char *const  orig_rhs,
const size_t  orig_rhs_len,
const LuaRef  rhs_lua,
const int  cpo_flags,
MapArguments *const  mapargs 

Replace termcodes in the given LHS and RHS and store the results into the lhs and rhs of the given MapArguments struct.

rhs and orig_rhs will both point to new allocated buffers. orig_rhs will hold a copy of the given orig_rhs.

The *_len variables will be set appropriately. If the length of the final lhs exceeds MAXMAPLEN, lhs_len will be set equal to the original larger length and lhs will be truncated.

If RHS is equal to "<Nop>", rhs will be the empty string, rhs_len will be zero, and rhs_is_noop will be set to true.

Any memory allocated by replace_termcodes is freed before this function returns.

[in]orig_lhsOriginal mapping LHS, with characters to replace.
[in]orig_lhs_lenstrlen of orig_lhs.
[in]orig_rhsOriginal mapping RHS, with characters to replace.
[in]rhs_luaLua reference for Lua maps.
[in]orig_rhs_lenstrlen of orig_rhs.
[in]cpo_flagsSee param docs for replace_termcodes.
[out]mapargsMapArguments struct holding the replaced strings.

◆ start_redo()

int start_redo ( long  count,
bool  old_redo 

◆ start_redo_ins()

int start_redo_ins ( void  )

◆ stop_redo_ins()

void stop_redo_ins ( void  )

◆ str_to_mapargs()

int str_to_mapargs ( const char_u strargs,
bool  is_unmap,
MapArguments mapargs 

Parse a string of |:map-arguments| into a MapArguments struct.

Termcodes, backslashes, CTRL-V's, etc. inside the extracted {lhs} and {rhs} are replaced by set_maparg_lhs_rhs.

rhs and orig_rhs in the returned mapargs will be set to null or a pointer to allocated memory and should be freed even on error.

[in]strargsString of map args, e.g. "<buffer> <expr><silent>". May contain leading or trailing whitespace.
[in]is_unmapTrue, if strargs should be parsed like an |:unmap| command. |:unmap| commands interpret all text to the right of the last map argument as the {lhs} of the mapping, i.e. a literal ' ' character is treated like a "<space>", rather than separating the {lhs} from the {rhs}.
[out]mapargsMapArguments struct holding all extracted argument values.
0 on success, 1 if invalid arguments are detected.

◆ stuff_empty()

int stuff_empty ( void  )

◆ stuffcharReadbuff()

void stuffcharReadbuff ( int  c)

Append a character to the stuff buffer. Translates special keys, NUL, K_SPECIAL and multibyte characters.

◆ stuffnumReadbuff()

void stuffnumReadbuff ( long  n)

◆ stuffReadbuff()

void stuffReadbuff ( const char *  s)

Append string "s" to the stuff buffer. K_SPECIAL must already have been escaped.

◆ stuffReadbuffLen()

void stuffReadbuffLen ( const char *  s,
long  len 

◆ stuffReadbuffSpec()

void stuffReadbuffSpec ( const char *  s)

Stuff "s" into the stuff buffer, leaving special key codes unmodified and escaping other K_SPECIAL bytes. Change CR, LF and ESC into a space.

◆ stuffRedoReadbuff()

void stuffRedoReadbuff ( const char *  s)

Append string "s" to the redo stuff buffer.

K_SPECIAL must already have been escaped.

◆ typeahead_noflush()

void typeahead_noflush ( int  c)

◆ typebuf_changed()

bool typebuf_changed ( int  tb_change_cnt)

Return TRUE if the typeahead buffer was changed (while waiting for a character to arrive). Happens when a message was received from a client or from feedkeys(). But check in a more generic way to avoid trouble: When "typebuf.tb_buf" changed it was reallocated and the old pointer can no longer be used. Or "typebuf.tb_off" may have been changed and we would overwrite characters that was just added.

tb_change_cntold value of typebuf.tb_change_cnt

◆ typebuf_maplen()

int typebuf_maplen ( void  )

◆ typebuf_typed()

int typebuf_typed ( void  )

◆ ungetchars()

void ungetchars ( int  len)

Undo the last gotchars() for "len" bytes. To be used when putting a typed character back into the typeahead buffer, thus gotchars() will be called again. Only affects recorded characters.

◆ using_script()

int using_script ( void  )

◆ vgetc()

int vgetc ( void  )

Get the next input character. Can return a special key or a multi-byte character. Can return NUL when called recursively, use safe_vgetc() if that's not wanted. This translates escaped K_SPECIAL bytes to a K_SPECIAL byte. Collects the bytes of a multibyte character into the whole character. Returns the modifiers in the global "mod_mask".

◆ vim_strsave_escape_ks()

char* vim_strsave_escape_ks ( char *  p)

Copy "p" to allocated memory, escaping K_SPECIAL so that the result can be put in the typeahead buffer.

◆ vim_unescape_ks()

void vim_unescape_ks ( char_u p)

Remove escaping from K_SPECIAL characters. Reverse of vim_strsave_escape_ks(). Works in-place.

◆ vpeekc()

int vpeekc ( void  )

◆ vpeekc_any()

int vpeekc_any ( void  )

◆ vungetc()

void vungetc ( int  c)

unget one character (can only be done once!) If the character was stuffed, vgetc() will get it next time it is called. Otherwise vgetc() will only get it when the stuff buffer is empty.

Variable Documentation

◆ scriptin

FileDescriptor* scriptin[NSCRIPT] = { NULL }

Streams to read script from.

Definition: vim.h:57
Definition: vim.h:58
Definition: vim.h:50
Definition: vim.h:49
Definition: vim.h:51
return NULL
Definition: eval.c:9968