#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"
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) |
Enumerations | |
enum | map_result_T { map_result_fail, map_result_get, map_result_retry, map_result_nomatch } |
Variables | |
FileDescriptor * | scriptin [NSCRIPT] = { NULL } |
Streams to read script from. More... | |
#define DUM_LEN (MAXMAPLEN * 3 + 3) |
#define MAP_HASH | ( | mode, | |
c1 | |||
) |
#define MAPMODE | ( | mode, | |
modechars, | |||
chr, | |||
modeflags | |||
) |
#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)) |
enum map_result_T |
Add a mapping. Unlike do_map this copies the {map} argument, so static or read-only strings can be used.
map | C-string containing the arguments of the map/abbrev command, i.e. everything except the initial :[X][nore]map . |
mode | Bitflags representing the mode in which to set the mapping. See get_map_mode. |
nore | If true, make a non-recursive mapping. |
void AppendCharToRedobuff | ( | int | c | ) |
Append a character to the redo buffer. Translates special keys, NUL, K_SPECIAL and multibyte characters.
void AppendNumberToRedobuff | ( | long | n | ) |
void AppendToRedobuff | ( | const char * | s | ) |
Append "s" to the redo buffer. K_SPECIAL should already have been escaped.
void AppendToRedobuffLit | ( | const char * | str, |
int | len | ||
) |
Append to Redo buffer literally, escaping special characters with CTRL-V. K_SPECIAL is escaped as well.
str | String to append |
len | Length of str or -1 for up to the NUL. |
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
.
maptype |
args | Fully 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 |
is_abbrev |
buf | Target Buffer |
int char_avail | ( | void | ) |
When peeking and not getting a character, reg_executing cannot be cleared yet, so set a flag to clear it later.
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.
exact | require exact match |
ign_mod | ignore preceding modifier |
abbr | do abbreviations |
mp_ptr | return: pointer to mapblock or NULL |
local_ptr | return: buffer-local mapping or NULL |
void del_typebuf | ( | int | len, |
int | offset | ||
) |
Set or remove a mapping or an abbreviation in the current buffer, OR display (matching) mappings/abbreviations.
maptype | 0 for |:map|, 1 for |:unmap|, 2 for |noremap|. |
arg | C-string containing the arguments of the map/abbrev command, i.e. everything except the initial :[X][nore]map .
|
mode | Bitflags representing the mode in which to set the mapping. See get_map_mode. |
is_abbrev | True if setting an abbreviation, false otherwise. |
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 | ) |
Return the contents of the redo buffer as a single string. K_SPECIAL in the returned string is escaped.
int get_map_mode | ( | char ** | cmdp, |
bool | forceit | ||
) |
mapblock_T* get_maphash | ( | int | index, |
buf_T * | buf | ||
) |
Retrieve the mapblock at the index either globally or for a certain buffer
index | The index in the maphash[] |
buf | The buffer to get the maphash from. NULL for global |
Return the contents of the record buffer as a single string and clear the record buffer. K_SPECIAL in the returned string is escaped.
Get command argument for <Cmd> key.
int inchar | ( | char_u * | buf, |
int | maxlen, | ||
long | wait_time | ||
) |
inchar() - get one character from
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.
wait_time | milliseconds |
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.
int makemap | ( | FILE * | fd, |
buf_T * | buf | ||
) |
Write map commands for the current mappings to an .exrc file. Return FAIL on error, OK otherwise.
buf | buffer for local mappings or NULL |
Clear all mappings in "mode".
buf,buffer | for local mappings |
mode | mode in which to delete |
local | true for buffer-local mappings |
abbr | true for abbreviations |
char* map_mode_to_chars | ( | int | mode | ) |
Return characters to represent the map mode in an allocated string
Check if a map exists that has given string in the rhs
Also checks mappings local to the current buffer.
[in] | str | String which mapping must have in the rhs. Termcap codes are recognized in this argument. |
[in] | modechars | Mode(s) in which mappings are checked. |
[in] | abbr | true if checking abbreviations in place of mappings. |
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] | rhs | String which mapping must have in the rhs. Termcap codes are recognized in this argument. |
[in] | mode | Mode(s) in which mappings are checked. |
[in] | abbr | true if checking abbreviations in place of mappings. |
int merge_modifiers | ( | int | c_arg, |
int * | modifiers | ||
) |
Merge "modifiers" into "c_arg".
Open a new script file for the ":source!" command.
directly | when true execute directly |
int plain_vgetc | ( | void | ) |
int put_escstr | ( | FILE * | fd, |
char_u * | strstart, | ||
int | what | ||
) |
int readbuf1_empty | ( | void | ) |
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 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, | ||
bool | forceit, | ||
bool | isabbrev, | ||
bool | isunmap, | ||
cmdidx_T | cmdidx | ||
) |
Work out what to complete when doing command line completion of mapping or abbreviation names.
forceit | true if '!' given |
isabbrev | true if abbreviation |
isunmap | true if unmap/unabbrev command |
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_lhs | Original mapping LHS, with characters to replace. |
[in] | orig_lhs_len | strlen of orig_lhs. |
[in] | orig_rhs | Original mapping RHS, with characters to replace. |
[in] | rhs_lua | Lua reference for Lua maps. |
[in] | orig_rhs_len | strlen of orig_rhs. |
[in] | cpo_flags | See param docs for replace_termcodes. |
[out] | mapargs | MapArguments struct holding the replaced strings. |
int start_redo | ( | long | count, |
bool | old_redo | ||
) |
int start_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.
[in] | strargs | String of map args, e.g. "<buffer> <expr><silent>". May contain leading or trailing whitespace. |
[in] | is_unmap | True, 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] | mapargs | MapArguments struct holding all extracted argument values. |
int stuff_empty | ( | void | ) |
void stuffcharReadbuff | ( | int | c | ) |
Append a character to the stuff buffer. Translates special keys, NUL, K_SPECIAL and multibyte characters.
void stuffnumReadbuff | ( | long | n | ) |
void stuffReadbuff | ( | const char * | s | ) |
Append string "s" to the stuff buffer. K_SPECIAL must already have been escaped.
void stuffReadbuffLen | ( | const char * | s, |
long | len | ||
) |
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.
void stuffRedoReadbuff | ( | const char * | s | ) |
Append string "s" to the redo stuff buffer.
void typeahead_noflush | ( | int | c | ) |
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_cnt | old value of typebuf.tb_change_cnt |
int typebuf_maplen | ( | void | ) |
int typebuf_typed | ( | void | ) |
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.
int using_script | ( | void | ) |
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".
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.
Remove escaping from K_SPECIAL characters. Reverse of vim_strsave_escape_ks(). Works in-place.
int vpeekc | ( | void | ) |
int vpeekc_any | ( | void | ) |
void vungetc | ( | int | c | ) |
FileDescriptor* scriptin[NSCRIPT] = { NULL } |
Streams to read script from.