Macros | Functions | Variables
getchar.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.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/keymap.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/misc1.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"

Macros

#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)
 

Functions

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 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_u *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_u *str, int noremap, int offset, bool nottyped, bool silent)
 
void ins_char_typebuf (int c)
 
bool typebuf_changed (int tb_change_cnt)
 
int typebuf_typed (void)
 
int typebuf_maplen (void)
 
void del_typebuf (int len, int offset)
 
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 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)
 
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_u *orig_lhs, const size_t orig_lhs_len, const char_u *orig_rhs, const size_t orig_rhs_len, int cpo_flags, MapArguments *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_u **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_uvim_strsave_escape_csi (char_u *p)
 
void vim_unescape_csi (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)
 
void add_map (char_u *map, int mode, bool nore)
 
mapblock_Tget_maphash (int index, buf_T *buf) FUNC_ATTR_PURE
 
char_ugetcmdkeycmd (int promptc, void *cookie, int indent, bool do_concat)
 Get command argument for <Cmd> key. More...
 

Variables

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

Macro Definition Documentation

◆ DUM_LEN

#define DUM_LEN   MAXMAPLEN * 3 + 3

◆ MAP_HASH

#define MAP_HASH (   mode,
  c1 
)
Value:
(((mode) & \
OP_PENDING + TERM_FOCUS)) ? (c1) : ((c1) ^ 0x80))

◆ MAPMODE

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

◆ MINIMAL_SIZE

#define MINIMAL_SIZE   20

◆ RM_ABBR

#define RM_ABBR   4

◆ RM_NONE

#define RM_NONE   1

◆ RM_SCRIPT

#define RM_SCRIPT   2

◆ RM_YES

#define RM_YES   0

◆ TYPELEN_INIT

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

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.

Parameters
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)

◆ AppendNumberToRedobuff()

void AppendNumberToRedobuff ( long  n)

◆ AppendToRedobuff()

void AppendToRedobuff ( const char *  s)

◆ AppendToRedobuffLit()

void AppendToRedobuffLit ( const char_u str,
int  len 
)

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

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

◆ 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.

Parameters
maptype
See also
do_map
Parameters
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.
mode
See also
do_map
Parameters
is_abbrev
See also
do_map
Parameters
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_map()

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

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

Parameters
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 NORMAL + VISUAL + SELECTMODE + OP_PENDING
for :map! mode is INSERT + CMDLINE
for :cmap mode is CMDLINE
for :imap mode is INSERT
for :lmap mode is LANGMAP
for :nmap mode is NORMAL
for :vmap mode is VISUAL + SELECTMODE
for :xmap mode is VISUAL
for :smap mode is SELECTMODE
for :omap mode is OP_PENDING
for :tmap mode is TERM_FOCUS
for :abbr mode is INSERT + CMDLINE
for :iabbr mode is INSERT
for :cabbr mode is CMDLINE
Parameters
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.
Returns
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  )

◆ get_map_mode()

int get_map_mode ( char_u **  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

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

◆ get_recorded()

char_u* get_recorded ( void  )

◆ getcmdkeycmd()

char_u* 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 much 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.

Parameters
wait_timemilli seconds

◆ init_default_mappings()

void init_default_mappings ( void  )

◆ ins_char_typebuf()

void ins_char_typebuf ( int  c)

◆ ins_typebuf()

int ins_typebuf ( char_u 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.

Parameters
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".

Parameters
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_mode_to_chars()

char* map_mode_to_chars ( int  mode)

Return characters to represent the map mode in an allocated string

Returns
[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.

Parameters
[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.
Returns
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.

Parameters
[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.
Returns
true if there is at least one mapping with given parameters.

◆ may_sync_undo()

void may_sync_undo ( void  )

◆ openscript()

void openscript ( char_u name,
bool  directly 
)

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

Parameters
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.

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

◆ set_maparg_lhs_rhs()

void set_maparg_lhs_rhs ( const char_u orig_lhs,
const size_t  orig_lhs_len,
const char_u orig_rhs,
const size_t  orig_rhs_len,
int  cpo_flags,
MapArguments 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.

Parameters
[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]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.

Parameters
[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.
Returns
0 on success, 1 if invalid arguments are detected.

◆ stuff_empty()

int stuff_empty ( void  )

◆ stuffcharReadbuff()

void stuffcharReadbuff ( int  c)

◆ stuffnumReadbuff()

void stuffnumReadbuff ( long  n)

◆ stuffReadbuff()

void stuffReadbuff ( const char *  s)

◆ stuffReadbuffLen()

void stuffReadbuffLen ( const char *  s,
long  len 
)

◆ stuffReadbuffSpec()

void stuffReadbuffSpec ( const char *  s)

◆ stuffRedoReadbuff()

void stuffRedoReadbuff ( const char *  s)

Append string "s" to the redo stuff buffer.

Remarks
CSI and 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.

Parameters
tb_change_cntold value of typebuf.tb_change_cnt

◆ typebuf_maplen()

int typebuf_maplen ( void  )

◆ typebuf_typed()

int typebuf_typed ( void  )

◆ using_script()

int using_script ( void  )

◆ vgetc()

int vgetc ( void  )

◆ vim_strsave_escape_csi()

char_u* vim_strsave_escape_csi ( char_u p)

◆ vim_unescape_csi()

void vim_unescape_csi ( char_u p)

◆ vpeekc()

int vpeekc ( void  )

◆ vpeekc_any()

int vpeekc_any ( void  )

◆ vungetc()

void vungetc ( int  c)

Variable Documentation

◆ scriptin

FileDescriptor* scriptin[NSCRIPT] = { NULL }

Streams to read script from.

TERM_FOCUS
#define TERM_FOCUS
Definition: vim.h:72
OP_PENDING
#define OP_PENDING
Definition: vim.h:50
VISUAL
#define VISUAL
Definition: vim.h:49
NORMAL
#define NORMAL
Definition: vim.h:48
SELECTMODE
#define SELECTMODE
Definition: vim.h:71
NULL
return NULL
Definition: eval.c:10355