Macros | Functions | Variables
getchar.c File Reference
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/getchar.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/func_attr.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/keymap.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.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/event/loop.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/fileio.h"
#include "nvim/api/private/handle.h"

Macros

#define MINIMAL_SIZE   20 /* minimal size for b_str */
 
#define MAP_HASH(mode, c1)
 
#define RM_YES   0 /* tb_noremap: remap */
 
#define RM_NONE   1 /* tb_noremap: don't remap */
 
#define RM_SCRIPT   2 /* tb_noremap: remap local script mappings */
 
#define RM_ABBR   4 /* tb_noremap: don't remap, do abbrev. */
 
#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)
 
int ins_typebuf (char_u *str, int noremap, int offset, int nottyped, bool silent)
 
void ins_char_typebuf (int c)
 
int 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, int 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)
 
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, int forceit)
 
void map_clear_mode (char_u *cmdp, char_u *arg, int forceit, int abbr)
 
void map_clear_int (buf_T *buf, int mode, int local, int 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, int forceit, int isabbrev, int isunmap, cmdidx_T cmdidx)
 
int ExpandMappings (regmatch_T *regmatch, int *num_file, char_u ***file)
 
int 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)
 
mapblock_Tget_maphash (int index, buf_T *buf) FUNC_ATTR_PURE
 
char_ugetcmdkeycmd (int promptc, void *cookie, int indent)
 Get command argument for <Cmd> key. More...
 

Variables

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

Macro Definition Documentation

#define DUM_LEN   MAXMAPLEN * 3 + 3
#define MAP_HASH (   mode,
  c1 
)
Value:
(((mode) & \
OP_PENDING + TERM_FOCUS)) ? (c1) : ((c1) ^ 0x80))
#define VISUAL
Definition: vim.h:50
#define NORMAL
Definition: vim.h:49
#define SELECTMODE
Definition: vim.h:72
#define TERM_FOCUS
Definition: vim.h:73
#define OP_PENDING
Definition: vim.h:51
#define MAPMODE (   mode,
  modechars,
  chr,
  modeflags 
)
Value:
do { \
if (strchr(modechars, chr) != NULL) { \
mode |= modeflags; \
} \
} while (0)
if(len)
Definition: encode.c:222
return NULL
Definition: eval.c:23643
#define MINIMAL_SIZE   20 /* minimal size for b_str */
#define RM_ABBR   4 /* tb_noremap: don't remap, do abbrev. */
#define RM_NONE   1 /* tb_noremap: don't remap */
#define RM_SCRIPT   2 /* tb_noremap: remap local script mappings */
#define RM_YES   0 /* tb_noremap: remap */
#define TYPELEN_INIT   (5 * (MAXMAPLEN + 3))

Function Documentation

void add_map ( char_u map,
int  mode 
)
void alloc_typebuf ( void  )
void AppendCharToRedobuff ( int  c)
void AppendNumberToRedobuff ( long  n)
void AppendToRedobuff ( const char *  s)
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.
void before_blocking ( void  )

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

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
void CancelRedo ( void  )
int char_avail ( void  )
int check_abbr ( int  c,
char_u ptr,
int  col,
int  mincol 
)
char_u* check_map ( char_u keys,
int  mode,
int  exact,
int  ign_mod,
int  abbr,
mapblock_T **  mp_ptr,
int *  local_ptr 
)
void del_typebuf ( int  len,
int  offset 
)
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.

1 map[!] " show all key mappings
2 map[!] {lhs} " show key mapping for {lhs}
3 map[!] {lhs} {rhs} " set key mapping for {lhs} to {rhs}
4 noremap[!] {lhs} {rhs} " same, but no remapping for {rhs}
5 unmap[!] {lhs} " remove key mapping for {lhs}
6 abbr " show all abbreviations
7 abbr {lhs} " show abbreviations for {lhs}
8 abbr {lhs} {rhs} " set abbreviation for {lhs} to {rhs}
9 noreabbr {lhs} {rhs} " same, but no remapping for {rhs}
10 unabbr {lhs} " remove abbreviation for {lhs}
11 
12 for :map mode is NORMAL + VISUAL + SELECTMODE + OP_PENDING
13 for :map! mode is INSERT + CMDLINE
14 for :cmap mode is CMDLINE
15 for :imap mode is INSERT
16 for :lmap mode is LANGMAP
17 for :nmap mode is NORMAL
18 for :vmap mode is VISUAL + SELECTMODE
19 for :xmap mode is VISUAL
20 for :smap mode is SELECTMODE
21 for :omap mode is OP_PENDING
22 for :tmap mode is TERM_FOCUS
23 
24 for :abbr mode is INSERT + CMDLINE
25 for :iabbr mode is INSERT
26 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
int ExpandMappings ( regmatch_T regmatch,
int *  num_file,
char_u ***  file 
)
int fix_input_buffer ( char_u buf,
int  len 
)
void flush_buffers ( flush_buffers_T  flush_typeahead)
void free_buff ( buffheader_T buf)
void free_typebuf ( void  )
char_u* get_inserted ( void  )
int get_map_mode ( char_u **  cmdp,
int  forceit 
)
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
char_u* get_recorded ( void  )
char_u* getcmdkeycmd ( int  promptc,
void *  cookie,
int  indent 
)

Get command argument for <Cmd> key.

int inchar ( char_u buf,
int  maxlen,
long  wait_time 
)
void ins_char_typebuf ( int  c)
int ins_typebuf ( char_u str,
int  noremap,
int  offset,
int  nottyped,
bool  silent 
)
int makemap ( FILE *  fd,
buf_T buf 
)
void map_clear_int ( buf_T buf,
int  mode,
int  local,
int  abbr 
)
void map_clear_mode ( char_u cmdp,
char_u arg,
int  forceit,
int  abbr 
)
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.
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.
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.
void may_sync_undo ( void  )
void openscript ( char_u name,
int  directly 
)
int plain_vgetc ( void  )
int put_escstr ( FILE *  fd,
char_u strstart,
int  what 
)
int readbuf1_empty ( void  )
void ResetRedobuff ( void  )
void restore_typeahead ( tasave_T tp)
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.

int safe_vgetc ( void  )
void save_typeahead ( tasave_T tp)
void save_typebuf ( void  )
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.

char_u* set_context_in_map_cmd ( expand_T xp,
char_u cmd,
char_u arg,
int  forceit,
int  isabbrev,
int  isunmap,
cmdidx_T  cmdidx 
)
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.
int start_redo ( long  count,
bool  old_redo 
)
int start_redo_ins ( void  )
void stop_redo_ins ( void  )
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.
int stuff_empty ( void  )
void stuffcharReadbuff ( int  c)
void stuffnumReadbuff ( long  n)
void stuffReadbuff ( const char *  s)
void stuffReadbuffLen ( const char *  s,
long  len 
)
void stuffReadbuffSpec ( const char *  s)
void stuffRedoReadbuff ( const char *  s)

Append string "s" to the redo stuff buffer.

Remarks
CSI and K_SPECIAL must already have been escaped.
void typeahead_noflush ( int  c)
int typebuf_changed ( int  tb_change_cnt)
int typebuf_maplen ( void  )
int typebuf_typed ( void  )
int using_script ( void  )
int vgetc ( void  )
char_u* vim_strsave_escape_csi ( char_u p)
void vim_unescape_csi ( char_u p)
int vpeekc ( void  )
int vpeekc_any ( void  )
void vungetc ( int  c)

Variable Documentation

FileDescriptor* scriptin[NSCRIPT] = { NULL }

Streams to read script from.