aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-26 11:13:20 +0800
committerGitHub <noreply@github.com>2023-08-26 11:13:20 +0800
commit1635c9e75e21e07c4331cf983e14a11c7e09b119 (patch)
tree2acd3792ff17e17b9caa5c7b90e63710ffcba103
parentb1cfb299df2ef412339f594173ed23c75c090c8a (diff)
downloadrneovim-1635c9e75e21e07c4331cf983e14a11c7e09b119.tar.gz
rneovim-1635c9e75e21e07c4331cf983e14a11c7e09b119.tar.bz2
rneovim-1635c9e75e21e07c4331cf983e14a11c7e09b119.zip
refactor: move some structs out of buffer_defs.h (#24878)
-rw-r--r--src/nvim/arglist.h2
-rw-r--r--src/nvim/arglist_defs.h22
-rw-r--r--src/nvim/buffer_defs.h95
-rw-r--r--src/nvim/getchar.c200
-rw-r--r--src/nvim/getchar.h26
-rw-r--r--src/nvim/getchar_defs.h66
-rw-r--r--src/nvim/globals.h10
-rw-r--r--src/nvim/mapping.c42
-rw-r--r--src/nvim/mapping.h59
-rw-r--r--src/nvim/mapping_defs.h29
-rw-r--r--src/nvim/plines.c2
-rw-r--r--src/nvim/vim.h8
12 files changed, 299 insertions, 262 deletions
diff --git a/src/nvim/arglist.h b/src/nvim/arglist.h
index cd34ca10c4..52894b73a0 100644
--- a/src/nvim/arglist.h
+++ b/src/nvim/arglist.h
@@ -1,8 +1,10 @@
#ifndef NVIM_ARGLIST_H
#define NVIM_ARGLIST_H
+#include "nvim/arglist_defs.h"
#include "nvim/eval/typval_defs.h"
#include "nvim/ex_cmds_defs.h"
+#include "nvim/types.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "arglist.h.generated.h"
diff --git a/src/nvim/arglist_defs.h b/src/nvim/arglist_defs.h
new file mode 100644
index 0000000000..28f2c3cf69
--- /dev/null
+++ b/src/nvim/arglist_defs.h
@@ -0,0 +1,22 @@
+#ifndef NVIM_ARGLIST_DEFS_H
+#define NVIM_ARGLIST_DEFS_H
+
+#include "nvim/garray.h"
+
+/// Argument list: Array of file names.
+/// Used for the global argument list and the argument lists local to a window.
+typedef struct arglist {
+ garray_T al_ga; ///< growarray with the array of file names
+ int al_refcount; ///< number of windows using this arglist
+ int id; ///< id of this arglist
+} alist_T;
+
+/// For each argument remember the file name as it was given, and the buffer
+/// number that contains the expanded file name (required for when ":cd" is
+/// used).
+typedef struct argentry {
+ char *ae_fname; ///< file name as specified
+ int ae_fnum; ///< buffer number with expanded file name
+} aentry_T;
+
+#endif // NVIM_ARGLIST_DEFS_H
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index c94dbfa7fb..2d83242275 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -7,8 +7,8 @@
typedef struct file_buffer buf_T; // Forward declaration
-// Reference to a buffer that stores the value of buf_free_count.
-// bufref_valid() only needs to check "buf" when the count differs.
+/// Reference to a buffer that stores the value of buf_free_count.
+/// bufref_valid() only needs to check "buf" when the count differs.
typedef struct {
buf_T *br_buf;
int br_fnum;
@@ -17,6 +17,7 @@ typedef struct {
#include "klib/kvec.h"
#include "nvim/api/private/defs.h"
+#include "nvim/arglist_defs.h"
#include "nvim/eval/typval_defs.h"
#include "nvim/extmark_defs.h"
#include "nvim/garray.h"
@@ -24,6 +25,7 @@ typedef struct {
#include "nvim/hashtab.h"
#include "nvim/highlight_defs.h"
#include "nvim/map.h"
+#include "nvim/mapping_defs.h"
#include "nvim/mark_defs.h"
#include "nvim/marktree.h"
#include "nvim/option_defs.h"
@@ -100,28 +102,6 @@ typedef struct taggy {
char *user_data; // used with tagfunc
} taggy_T;
-typedef struct buffblock buffblock_T;
-typedef struct buffheader buffheader_T;
-
-// structure used to store one block of the stuff/redo/recording buffers
-struct buffblock {
- buffblock_T *b_next; // pointer to next buffblock
- char b_str[1]; // contents (actually longer)
-};
-
-// header used for the stuff buffer and the redo buffer
-struct buffheader {
- buffblock_T bh_first; // first (dummy) block of list
- buffblock_T *bh_curr; // buffblock for appending
- size_t bh_index; // index for reading
- size_t bh_space; // space in bh_curr for appending
-};
-
-typedef struct {
- buffheader_T sr_redobuff;
- buffheader_T sr_old_redobuff;
-} save_redo_T;
-
// Structure that contains all options that are local to a window.
// Used twice in a window: for the current buffer and for all buffers.
// Also used in wininfo_T.
@@ -267,27 +247,7 @@ struct wininfo_S {
int wi_changelistidx; // copy of w_changelistidx
};
-// Argument list: Array of file names.
-// Used for the global argument list and the argument lists local to a window.
-//
-// TODO(neovim): move struct arglist to another header
-typedef struct arglist {
- garray_T al_ga; // growarray with the array of file names
- int al_refcount; // number of windows using this arglist
- int id; ///< id of this arglist
-} alist_T;
-
-// For each argument remember the file name as it was given, and the buffer
-// number that contains the expanded file name (required for when ":cd" is
-// used).
-//
-// TODO(Felipe): move aentry_T to another header
-typedef struct argentry {
- char *ae_fname; // file name as specified
- int ae_fnum; // buffer number with expanded file name
-} aentry_T;
-
-#define ALIST(win) (win)->w_alist
+#define ALIST(win) (win)->w_alist
#define GARGLIST ((aentry_T *)global_alist.al_ga.ga_data)
#define ARGLIST ((aentry_T *)ALIST(curwin)->al_ga.ga_data)
#define WARGLIST(wp) ((aentry_T *)ALIST(wp)->al_ga.ga_data)
@@ -296,51 +256,6 @@ typedef struct argentry {
#define ARGCOUNT (ALIST(curwin)->al_ga.ga_len)
#define WARGCOUNT(wp) (ALIST(wp)->al_ga.ga_len)
-// Used for the typeahead buffer: typebuf.
-typedef struct {
- uint8_t *tb_buf; // buffer for typed characters
- uint8_t *tb_noremap; // mapping flags for characters in tb_buf[]
- int tb_buflen; // size of tb_buf[]
- int tb_off; // current position in tb_buf[]
- int tb_len; // number of valid bytes in tb_buf[]
- int tb_maplen; // nr of mapped bytes in tb_buf[]
- int tb_silent; // nr of silently mapped bytes in tb_buf[]
- int tb_no_abbr_cnt; // nr of bytes without abbrev. in tb_buf[]
- int tb_change_cnt; // nr of time tb_buf was changed; never zero
-} typebuf_T;
-
-// Struct to hold the saved typeahead for save_typeahead().
-typedef struct {
- typebuf_T save_typebuf;
- bool typebuf_valid; // true when save_typebuf valid
- int old_char;
- int old_mod_mask;
- buffheader_T save_readbuf1;
- buffheader_T save_readbuf2;
- String save_inputbuf;
-} tasave_T;
-
-// Structure used for mappings and abbreviations.
-typedef struct mapblock mapblock_T;
-struct mapblock {
- mapblock_T *m_next; // next mapblock in list
- char *m_keys; // mapped from, lhs
- char *m_str; // mapped to, rhs
- char *m_orig_str; // rhs as entered by the user
- LuaRef m_luaref; // lua function reference as rhs
- int m_keylen; // strlen(m_keys)
- int m_mode; // valid mode
- int m_simplified; // m_keys was simplified, do no use this map
- // if keys are typed
- int m_noremap; // if non-zero no re-mapping for m_str
- char m_silent; // <silent> used, don't echo commands
- char m_nowait; // <nowait> used
- char m_expr; // <expr> used, m_str is an expression
- sctx_T m_script_ctx; // SCTX where map was defined
- char *m_desc; // description of mapping
- bool m_replace_keycodes; // replace keycodes in result of expression
-};
-
// values for b_syn_spell: what to do with toplevel text
#define SYNSPL_DEFAULT 0 // spell check if @Spell not defined
#define SYNSPL_TOP 1 // spell check toplevel text
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index d10e021f14..779ba0f90d 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -84,50 +84,56 @@ static buffheader_T redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
static buffheader_T old_redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
static buffheader_T recordbuff = { { NULL, { NUL } }, NULL, 0, 0 };
-// First read ahead buffer. Used for translated commands.
+/// First read ahead buffer. Used for translated commands.
static buffheader_T readbuf1 = { { NULL, { NUL } }, NULL, 0, 0 };
-// Second read ahead buffer. Used for redo.
+/// Second read ahead buffer. Used for redo.
static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 };
-static int typeahead_char = 0; // typeahead char that's not flushed
+static int typeahead_char = 0; ///< typeahead char that's not flushed
/// When block_redo is true the redo buffer will not be changed.
/// Used by edit() to repeat insertions.
static int block_redo = false;
-static int KeyNoremap = 0; // remapping flags
+static int KeyNoremap = 0; ///< remapping flags
-// Variables used by vgetorpeek() and flush_buffers()
-//
-// typebuf.tb_buf[] contains all characters that are not consumed yet.
-// typebuf.tb_buf[typebuf.tb_off] is the first valid character.
-// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char.
-// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL.
-// The head of the buffer may contain the result of mappings, abbreviations
-// and @a commands. The length of this part is typebuf.tb_maplen.
-// typebuf.tb_silent is the part where <silent> applies.
-// After the head are characters that come from the terminal.
-// typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that
-// should not be considered for abbreviations.
-// Some parts of typebuf.tb_buf may not be mapped. These parts are remembered
-// in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and
-// contains RM_NONE for the characters that are not to be remapped.
-// typebuf.tb_noremap[typebuf.tb_off] is the first valid flag.
-// (typebuf has been put in globals.h, because check_termcode() needs it).
-#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.
+/// Variables used by vgetorpeek() and flush_buffers()
+///
+/// typebuf.tb_buf[] contains all characters that are not consumed yet.
+/// typebuf.tb_buf[typebuf.tb_off] is the first valid character.
+/// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char.
+/// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL.
+/// The head of the buffer may contain the result of mappings, abbreviations
+/// and @a commands. The length of this part is typebuf.tb_maplen.
+/// typebuf.tb_silent is the part where <silent> applies.
+/// After the head are characters that come from the terminal.
+/// typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that
+/// should not be considered for abbreviations.
+/// Some parts of typebuf.tb_buf may not be mapped. These parts are remembered
+/// in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and
+/// contains RM_NONE for the characters that are not to be remapped.
+/// typebuf.tb_noremap[typebuf.tb_off] is the first valid flag.
+enum {
+ RM_YES = 0, ///< tb_noremap: remap
+ RM_NONE = 1, ///< tb_noremap: don't remap
+ RM_SCRIPT = 2, ///< tb_noremap: remap local script mappings
+ RM_ABBR = 4, ///< tb_noremap: don't remap, do abbrev.
+};
// typebuf.tb_buf has three parts: room in front (for result of mappings), the
// middle for typeahead and room for new characters (which needs to be 3 *
// MAXMAPLEN for the Amiga).
#define TYPELEN_INIT (5 * (MAXMAPLEN + 3))
-static uint8_t typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf
-static uint8_t noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap
+static uint8_t typebuf_init[TYPELEN_INIT]; ///< initial typebuf.tb_buf
+static uint8_t noremapbuf_init[TYPELEN_INIT]; ///< initial typebuf.tb_noremap
+
+static size_t last_recorded_len = 0; ///< number of last recorded chars
-static size_t last_recorded_len = 0; // number of last recorded chars
+enum {
+ KEYLEN_PART_KEY = -1, ///< keylen value for incomplete key-code
+ KEYLEN_PART_MAP = -2, ///< keylen value for incomplete mapping
+};
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "getchar.c.generated.h"
@@ -139,8 +145,8 @@ static const char e_cmd_mapping_must_end_with_cr[]
static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[]
= N_("E1136: <Cmd> mapping must end with <CR> before second <Cmd>");
-// Free and clear a buffer.
-void free_buff(buffheader_T *buf)
+/// Free and clear a buffer.
+static void free_buff(buffheader_T *buf)
{
buffblock_T *p, *np;
@@ -359,7 +365,7 @@ static int read_readbuf(buffheader_T *buf, int advance)
return c;
}
-// Prepare the read buffers for reading (if they contain something).
+/// Prepare the read buffers for reading (if they contain something).
static void start_stuff(void)
{
if (readbuf1.bh_first.b_next != NULL) {
@@ -387,15 +393,15 @@ int readbuf1_empty(void)
return (readbuf1.bh_first.b_next == NULL);
}
-// Set a typeahead character that won't be flushed.
+/// Set a typeahead character that won't be flushed.
void typeahead_noflush(int c)
{
typeahead_char = c;
}
-// Remove the contents of the stuff buffer and the mapped characters in the
-// typeahead buffer (used in case of an error). If "flush_typeahead" is true,
-// flush all typeahead characters (used when interrupted by a CTRL-C).
+/// Remove the contents of the stuff buffer and the mapped characters in the
+/// typeahead buffer (used in case of an error). If "flush_typeahead" is true,
+/// flush all typeahead characters (used when interrupted by a CTRL-C).
void flush_buffers(flush_buffers_T flush_typeahead)
{
init_typebuf();
@@ -439,8 +445,8 @@ void beep_flush(void)
}
}
-// The previous contents of the redo buffer is kept in old_redobuffer.
-// This is used for the CTRL-O <.> command in insert mode.
+/// The previous contents of the redo buffer is kept in old_redobuffer.
+/// This is used for the CTRL-O <.> command in insert mode.
void ResetRedobuff(void)
{
if (block_redo) {
@@ -452,8 +458,8 @@ void ResetRedobuff(void)
redobuff.bh_first.b_next = NULL;
}
-// Discard the contents of the redo buffer and restore the previous redo
-// buffer.
+/// Discard the contents of the redo buffer and restore the previous redo
+/// buffer.
void CancelRedo(void)
{
if (block_redo) {
@@ -740,23 +746,21 @@ static void copy_redo(bool old_redo)
}
}
-// Stuff the redo buffer into readbuf2.
-// Insert the redo count into the command.
-// If "old_redo" is true, the last but one command is repeated
-// instead of the last command (inserting text). This is used for
-// CTRL-O <.> in insert mode
-//
-// return FAIL for failure, OK otherwise
+/// Stuff the redo buffer into readbuf2.
+/// Insert the redo count into the command.
+/// If "old_redo" is true, the last but one command is repeated
+/// instead of the last command (inserting text). This is used for
+/// CTRL-O <.> in insert mode
+///
+/// @return FAIL for failure, OK otherwise
int start_redo(long count, bool old_redo)
{
- int c;
-
// init the pointers; return if nothing to redo
if (read_redo(true, old_redo) == FAIL) {
return FAIL;
}
- c = read_redo(false, old_redo);
+ int c = read_redo(false, old_redo);
// copy the buffer name, if present
if (c == '"') {
@@ -801,9 +805,10 @@ int start_redo(long count, bool old_redo)
return OK;
}
-// Repeat the last insert (R, o, O, a, A, i or I command) by stuffing
-// the redo buffer into readbuf2.
-// return FAIL for failure, OK otherwise
+/// Repeat the last insert (R, o, O, a, A, i or I command) by stuffing
+/// the redo buffer into readbuf2.
+///
+/// @return FAIL for failure, OK otherwise
int start_redo_ins(void)
{
int c;
@@ -834,9 +839,9 @@ void stop_redo_ins(void)
block_redo = false;
}
-// Initialize typebuf.tb_buf to point to typebuf_init.
-// alloc() cannot be used here: In out-of-memory situations it would
-// be impossible to type anything.
+/// Initialize typebuf.tb_buf to point to typebuf_init.
+/// alloc() cannot be used here: In out-of-memory situations it would
+/// be impossible to type anything.
static void init_typebuf(void)
{
if (typebuf.tb_buf != NULL) {
@@ -857,8 +862,7 @@ bool noremap_keys(void)
return KeyNoremap & (RM_NONE|RM_SCRIPT);
}
-/// Insert a string in position "offset" in the typeahead buffer (for "@r"
-/// and ":normal" command, vgetorpeek() and check_termcode())
+/// Insert a string in position "offset" in the typeahead buffer.
///
/// If "noremap" is REMAP_YES, new string can be mapped again.
/// If "noremap" is REMAP_NONE, new string cannot be mapped again.
@@ -1030,14 +1034,14 @@ int typebuf_typed(void)
return typebuf.tb_maplen == 0;
}
-// Return the number of characters that are mapped (or not typed).
+/// Get the number of characters that are mapped (or not typed).
int typebuf_maplen(void)
FUNC_ATTR_PURE
{
return typebuf.tb_maplen;
}
-// remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset]
+/// Remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset]
void del_typebuf(int len, int offset)
{
if (len == 0) {
@@ -1102,8 +1106,8 @@ void del_typebuf(int len, int offset)
}
}
-// Write typed characters to script file.
-// If recording is on put the character in the recordbuffer.
+/// Write typed characters to script file.
+/// If recording is on put the character in the recordbuffer.
static void gotchars(const uint8_t *chars, size_t len)
FUNC_ATTR_NONNULL_ALL
{
@@ -1169,12 +1173,12 @@ void ungetchars(int len)
last_recorded_len -= (size_t)len;
}
-// Sync undo. Called when typed characters are obtained from the typeahead
-// buffer, or when a menu is used.
-// Do not sync:
-// - In Insert mode, unless cursor key has been used.
-// - While reading a script file.
-// - When no_u_sync is non-zero.
+/// Sync undo. Called when typed characters are obtained from the typeahead
+/// buffer, or when a menu is used.
+/// Do not sync:
+/// - In Insert mode, unless cursor key has been used.
+/// - While reading a script file.
+/// - When no_u_sync is non-zero.
void may_sync_undo(void)
{
if ((!(State & (MODE_INSERT | MODE_CMDLINE)) || arrow_used)
@@ -1183,7 +1187,7 @@ void may_sync_undo(void)
}
}
-// Make "typebuf" empty and allocate new buffers.
+/// Make "typebuf" empty and allocate new buffers.
void alloc_typebuf(void)
{
typebuf.tb_buf = xmalloc(TYPELEN_INIT);
@@ -1199,7 +1203,7 @@ void alloc_typebuf(void)
}
}
-// Free the buffers of "typebuf".
+/// Free the buffers of "typebuf".
void free_typebuf(void)
{
if (typebuf.tb_buf == typebuf_init) {
@@ -1214,8 +1218,8 @@ void free_typebuf(void)
}
}
-// When doing ":so! file", the current typeahead needs to be saved, and
-// restored when "file" has been read completely.
+/// When doing ":so! file", the current typeahead needs to be saved, and
+/// restored when "file" has been read completely.
static typebuf_T saved_typebuf[NSCRIPT];
void save_typebuf(void)
@@ -1225,12 +1229,12 @@ void save_typebuf(void)
alloc_typebuf();
}
-static int old_char = -1; // character put back by vungetc()
-static int old_mod_mask; // mod_mask for ungotten character
-static int old_mouse_grid; // mouse_grid related to old_char
-static int old_mouse_row; // mouse_row related to old_char
-static int old_mouse_col; // mouse_col related to old_char
-static int old_KeyStuffed; // whether old_char was stuffed
+static int old_char = -1; ///< character put back by vungetc()
+static int old_mod_mask; ///< mod_mask for ungotten character
+static int old_mouse_grid; ///< mouse_grid related to old_char
+static int old_mouse_row; ///< mouse_row related to old_char
+static int old_mouse_col; ///< mouse_col related to old_char
+static int old_KeyStuffed; ///< whether old_char was stuffed
static bool can_get_old_char(void)
{
@@ -1239,7 +1243,7 @@ static bool can_get_old_char(void)
return old_char != -1 && (old_KeyStuffed || stuff_empty());
}
-// Save all three kinds of typeahead, so that the user must type at a prompt.
+/// Save all three kinds of typeahead, so that the user must type at a prompt.
void save_typeahead(tasave_T *tp)
{
tp->save_typebuf = typebuf;
@@ -1255,8 +1259,8 @@ void save_typeahead(tasave_T *tp)
readbuf2.bh_first.b_next = NULL;
}
-// Restore the typeahead to what it was before calling save_typeahead().
-// The allocated memory is freed, can only be called once!
+/// Restore the typeahead to what it was before calling save_typeahead().
+/// The allocated memory is freed, can only be called once!
void restore_typeahead(tasave_T *tp)
{
if (tp->typebuf_valid) {
@@ -1342,7 +1346,7 @@ void openscript(char *name, bool directly)
}
}
-// Close the currently active input script.
+/// Close the currently active input script.
static void closescript(void)
{
free_typebuf();
@@ -1635,8 +1639,8 @@ int vgetc(void)
return c;
}
-// Like vgetc(), but never return a NUL when called recursively, get a key
-// directly from the user (ignoring typeahead).
+/// Like vgetc(), but never return a NUL when called recursively, get a key
+/// directly from the user (ignoring typeahead).
int safe_vgetc(void)
{
int c;
@@ -1648,8 +1652,8 @@ int safe_vgetc(void)
return c;
}
-// Like safe_vgetc(), but loop to handle K_IGNORE.
-// Also ignore scrollbar events.
+/// Like safe_vgetc(), but loop to handle K_IGNORE.
+/// Also ignore scrollbar events.
int plain_vgetc(void)
{
int c;
@@ -1662,10 +1666,10 @@ int plain_vgetc(void)
return c;
}
-// Check if a character is available, such that vgetc() will not block.
-// If the next character is a special character or multi-byte, the returned
-// character is not valid!.
-// Returns NUL if no character is available.
+/// Check if a character is available, such that vgetc() will not block.
+/// If the next character is a special character or multi-byte, the returned
+/// character is not valid!.
+/// Returns NUL if no character is available.
int vpeekc(void)
{
if (can_get_old_char()) {
@@ -1674,9 +1678,9 @@ int vpeekc(void)
return vgetorpeek(false);
}
-// Check if any character is available, also half an escape sequence.
-// Trick: when no typeahead found, but there is something in the typeahead
-// buffer, it must be an ESC that is recognized as the start of a key code.
+/// Check if any character is available, also half an escape sequence.
+/// Trick: when no typeahead found, but there is something in the typeahead
+/// buffer, it must be an ESC that is recognized as the start of a key code.
int vpeekc_any(void)
{
int c;
@@ -1688,9 +1692,9 @@ int vpeekc_any(void)
return c;
}
-// Call vpeekc() without causing anything to be mapped.
-// Return true if a character is available, false otherwise.
-int char_avail(void)
+/// Call vpeekc() without causing anything to be mapped.
+/// @return true if a character is available, false otherwise.
+bool char_avail(void)
{
int retval;
@@ -2881,9 +2885,9 @@ int inchar(uint8_t *buf, int maxlen, long wait_time)
return fix_input_buffer(buf, len);
}
-// Fix typed characters for use by vgetc() and check_termcode().
-// "buf[]" must have room to triple the number of bytes!
-// Returns the new length.
+/// Fix typed characters for use by vgetc().
+/// "buf[]" must have room to triple the number of bytes!
+/// Returns the new length.
int fix_input_buffer(uint8_t *buf, int len)
FUNC_ATTR_NONNULL_ALL
{
diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h
index 6996b00c6e..55b5657dc8 100644
--- a/src/nvim/getchar.h
+++ b/src/nvim/getchar.h
@@ -1,29 +1,21 @@
#ifndef NVIM_GETCHAR_H
#define NVIM_GETCHAR_H
-#include "nvim/os/fileio.h"
-#include "nvim/vim.h"
+#include <stdbool.h>
+#include <stdint.h>
-/// Values for "noremap" argument of ins_typebuf()
-///
-/// Also used for map->m_noremap and menu->noremap[].
-enum RemapValues {
- REMAP_YES = 0, ///< Allow remapping.
- REMAP_NONE = -1, ///< No remapping.
- REMAP_SCRIPT = -2, ///< Remap script-local mappings only.
- REMAP_SKIP = -3, ///< No remapping for first char.
-};
+#include "nvim/eval/typval_defs.h"
+#include "nvim/getchar_defs.h"
+#include "nvim/os/fileio.h"
+#include "nvim/types.h"
-// Argument for flush_buffers().
+/// Argument for flush_buffers().
typedef enum {
FLUSH_MINIMAL,
- FLUSH_TYPEAHEAD, // flush current typebuf contents
- FLUSH_INPUT, // flush typebuf and inchar() input
+ FLUSH_TYPEAHEAD, ///< flush current typebuf contents
+ FLUSH_INPUT, ///< flush typebuf and inchar() input
} flush_buffers_T;
-#define KEYLEN_PART_KEY (-1) // keylen value for incomplete key-code
-#define KEYLEN_PART_MAP (-2) // keylen value for incomplete mapping
-
/// Maximum number of streams to read script from
enum { NSCRIPT = 15, };
diff --git a/src/nvim/getchar_defs.h b/src/nvim/getchar_defs.h
new file mode 100644
index 0000000000..0ec662441a
--- /dev/null
+++ b/src/nvim/getchar_defs.h
@@ -0,0 +1,66 @@
+#ifndef NVIM_GETCHAR_DEFS_H
+#define NVIM_GETCHAR_DEFS_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "nvim/api/private/defs.h"
+
+typedef struct buffblock buffblock_T;
+typedef struct buffheader buffheader_T;
+
+/// structure used to store one block of the stuff/redo/recording buffers
+struct buffblock {
+ buffblock_T *b_next; ///< pointer to next buffblock
+ char b_str[1]; ///< contents (actually longer)
+};
+
+/// header used for the stuff buffer and the redo buffer
+struct buffheader {
+ buffblock_T bh_first; ///< first (dummy) block of list
+ buffblock_T *bh_curr; ///< buffblock for appending
+ size_t bh_index; ///< index for reading
+ size_t bh_space; ///< space in bh_curr for appending
+};
+
+typedef struct {
+ buffheader_T sr_redobuff;
+ buffheader_T sr_old_redobuff;
+} save_redo_T;
+
+/// Used for the typeahead buffer: typebuf.
+typedef struct {
+ uint8_t *tb_buf; ///< buffer for typed characters
+ uint8_t *tb_noremap; ///< mapping flags for characters in tb_buf[]
+ int tb_buflen; ///< size of tb_buf[]
+ int tb_off; ///< current position in tb_buf[]
+ int tb_len; ///< number of valid bytes in tb_buf[]
+ int tb_maplen; ///< nr of mapped bytes in tb_buf[]
+ int tb_silent; ///< nr of silently mapped bytes in tb_buf[]
+ int tb_no_abbr_cnt; ///< nr of bytes without abbrev. in tb_buf[]
+ int tb_change_cnt; ///< nr of time tb_buf was changed; never zero
+} typebuf_T;
+
+/// Struct to hold the saved typeahead for save_typeahead().
+typedef struct {
+ typebuf_T save_typebuf;
+ bool typebuf_valid; ///< true when save_typebuf valid
+ int old_char;
+ int old_mod_mask;
+ buffheader_T save_readbuf1;
+ buffheader_T save_readbuf2;
+ String save_inputbuf;
+} tasave_T;
+
+/// Values for "noremap" argument of ins_typebuf()
+///
+/// Also used for map->m_noremap and menu->noremap[].
+enum RemapValues {
+ REMAP_YES = 0, ///< Allow remapping.
+ REMAP_NONE = -1, ///< No remapping.
+ REMAP_SCRIPT = -2, ///< Remap script-local mappings only.
+ REMAP_SKIP = -3, ///< No remapping for first char.
+};
+
+#endif // NVIM_GETCHAR_DEFS_H
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index a1156a0196..1a7a62174d 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -4,10 +4,12 @@
#include <inttypes.h>
#include <stdbool.h>
+#include "nvim/arglist_defs.h"
#include "nvim/ascii.h"
#include "nvim/event/loop.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_eval_defs.h"
+#include "nvim/getchar_defs.h"
#include "nvim/iconv.h"
#include "nvim/macros.h"
#include "nvim/mbyte.h"
@@ -809,14 +811,6 @@ enum {
WM_LIST = 3, ///< cmdline CTRL-D
};
-// Some file names are stored in pathdef.c, which is generated from the
-// Makefile to make their value depend on the Makefile.
-#ifdef HAVE_PATHDEF
-extern char *default_vim_dir;
-extern char *default_vimruntime_dir;
-extern char *default_lib_dir;
-#endif
-
// When a window has a local directory, the absolute path of the global
// current directory is stored here (in allocated memory). If the current
// directory is not a local directory, globaldir is NULL.
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index f2732184db..ab528f8865 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -61,6 +61,48 @@ static mapblock_T *(maphash[MAX_MAPHASH]) = { 0 };
(MODE_NORMAL | MODE_VISUAL | MODE_SELECT | \
MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80))
+/// All possible |:map-arguments| usable in a |:map| command.
+///
+/// The <special> argument has no effect on mappings and is excluded from this
+/// struct declaration. |:noremap| is included, since it behaves like a map
+/// argument when used in a mapping.
+///
+/// @see mapblock_T
+struct map_arguments {
+ bool buffer;
+ bool expr;
+ bool noremap;
+ bool nowait;
+ bool script;
+ bool silent;
+ bool unique;
+ bool replace_keycodes;
+
+ /// The {lhs} of the mapping.
+ ///
+ /// vim limits this to MAXMAPLEN characters, allowing us to use a static
+ /// buffer. Setting lhs_len to a value larger than MAXMAPLEN can signal
+ /// that {lhs} was too long and truncated.
+ char lhs[MAXMAPLEN + 1];
+ size_t lhs_len;
+
+ /// Unsimplifed {lhs} of the mapping. If no simplification has been done then alt_lhs_len is 0.
+ char alt_lhs[MAXMAPLEN + 1];
+ size_t alt_lhs_len;
+
+ char *rhs; /// The {rhs} of the mapping.
+ size_t rhs_len;
+ LuaRef rhs_lua; /// lua function as {rhs}
+ bool rhs_is_noop; /// True when the {rhs} should be <Nop>.
+
+ char *orig_rhs; /// The original text of the {rhs}.
+ size_t orig_rhs_len;
+ char *desc; /// map description
+};
+typedef struct map_arguments MapArguments;
+#define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, false, \
+ { 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL }
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mapping.c.generated.h"
#endif
diff --git a/src/nvim/mapping.h b/src/nvim/mapping.h
index ff6c30c4c9..405234dbd5 100644
--- a/src/nvim/mapping.h
+++ b/src/nvim/mapping.h
@@ -3,60 +3,23 @@
#include <stdbool.h>
#include <stddef.h>
+#include <stdint.h>
-#include "lauxlib.h"
#include "nvim/api/keysets.h"
-#include "nvim/buffer_defs.h"
+#include "nvim/api/private/defs.h"
+#include "nvim/eval/typval_defs.h"
#include "nvim/ex_cmds_defs.h"
+#include "nvim/mapping_defs.h"
+#include "nvim/option_defs.h"
+#include "nvim/regexp_defs.h"
#include "nvim/types.h"
-#include "nvim/vim.h"
-/// All possible |:map-arguments| usable in a |:map| command.
-///
-/// The <special> argument has no effect on mappings and is excluded from this
-/// struct declaration. |:noremap| is included, since it behaves like a map
-/// argument when used in a mapping.
-///
-/// @see mapblock_T
-struct map_arguments {
- bool buffer;
- bool expr;
- bool noremap;
- bool nowait;
- bool script;
- bool silent;
- bool unique;
- bool replace_keycodes;
-
- /// The {lhs} of the mapping.
- ///
- /// vim limits this to MAXMAPLEN characters, allowing us to use a static
- /// buffer. Setting lhs_len to a value larger than MAXMAPLEN can signal
- /// that {lhs} was too long and truncated.
- char lhs[MAXMAPLEN + 1];
- size_t lhs_len;
-
- /// Unsimplifed {lhs} of the mapping. If no simplification has been done then alt_lhs_len is 0.
- char alt_lhs[MAXMAPLEN + 1];
- size_t alt_lhs_len;
-
- char *rhs; /// The {rhs} of the mapping.
- size_t rhs_len;
- LuaRef rhs_lua; /// lua function as {rhs}
- bool rhs_is_noop; /// True when the {rhs} should be <Nop>.
-
- char *orig_rhs; /// The original text of the {rhs}.
- size_t orig_rhs_len;
- char *desc; /// map description
+/// Used for the first argument of do_map()
+enum {
+ MAPTYPE_MAP = 0,
+ MAPTYPE_UNMAP = 1,
+ MAPTYPE_NOREMAP = 2,
};
-typedef struct map_arguments MapArguments;
-#define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, false, \
- { 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL }
-
-// Used for the first argument of do_map()
-#define MAPTYPE_MAP 0
-#define MAPTYPE_UNMAP 1
-#define MAPTYPE_NOREMAP 2
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mapping.h.generated.h"
diff --git a/src/nvim/mapping_defs.h b/src/nvim/mapping_defs.h
new file mode 100644
index 0000000000..ff0633308b
--- /dev/null
+++ b/src/nvim/mapping_defs.h
@@ -0,0 +1,29 @@
+#ifndef NVIM_MAPPING_DEFS_H
+#define NVIM_MAPPING_DEFS_H
+
+#include <stdbool.h>
+
+#include "nvim/eval/typval_defs.h"
+#include "nvim/types.h"
+
+/// Structure used for mappings and abbreviations.
+typedef struct mapblock mapblock_T;
+struct mapblock {
+ mapblock_T *m_next; ///< next mapblock in list
+ char *m_keys; ///< mapped from, lhs
+ char *m_str; ///< mapped to, rhs
+ char *m_orig_str; ///< rhs as entered by the user
+ LuaRef m_luaref; ///< lua function reference as rhs
+ int m_keylen; ///< strlen(m_keys)
+ int m_mode; ///< valid mode
+ int m_simplified; ///< m_keys was simplified
+ int m_noremap; ///< if non-zero no re-mapping for m_str
+ char m_silent; ///< <silent> used, don't echo commands
+ char m_nowait; ///< <nowait> used
+ char m_expr; ///< <expr> used, m_str is an expression
+ sctx_T m_script_ctx; ///< SCTX where map was defined
+ char *m_desc; ///< description of mapping
+ bool m_replace_keycodes; ///< replace keycodes in result of expression
+};
+
+#endif // NVIM_MAPPING_DEFS_H
diff --git a/src/nvim/plines.c b/src/nvim/plines.c
index be6bcd22ae..c95f362518 100644
--- a/src/nvim/plines.c
+++ b/src/nvim/plines.c
@@ -726,7 +726,7 @@ void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right
/// Functions calculating vertical size of text when displayed inside a window.
/// Calls horizontal size functions defined above.
-/// Check if there may be filler inlines anywhere in window "wp".
+/// Check if there may be filler lines anywhere in window "wp".
bool win_may_fill(win_T *wp)
{
return (wp->w_p_diff && diffopt_filler()) || wp->w_buffer->b_virt_line_blocks;
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index 44e3e9d86a..fc1f15b285 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -13,6 +13,14 @@
#include "auto/config.h"
#define HAVE_PATHDEF
+// Some file names are stored in pathdef.c, which is generated from the
+// Makefile to make their value depend on the Makefile.
+#ifdef HAVE_PATHDEF
+extern char *default_vim_dir;
+extern char *default_vimruntime_dir;
+extern char *default_lib_dir;
+#endif
+
// Check if configure correctly managed to find sizeof(int). If this failed,
// it becomes zero. This is likely a problem of not being able to run the
// test program. Other items from configure may also be wrong then!