diff --git a/Makefile b/Makefile index e1024009a3..cbcc7f5eae 100644 --- a/Makefile +++ b/Makefile @@ -173,11 +173,7 @@ iwyu: build/.ran-cmake |src/nvim/event/stream.h\ |src/nvim/event/time.h\ |src/nvim/event/wstream.h\ - |src/nvim/ex_cmds.h\ - |src/nvim/ex_docmd.h\ |src/nvim/extmark.h\ - |src/nvim/file_search.h\ - |src/nvim/fileio.h\ |src/nvim/fold.h\ |src/nvim/garray.h\ |src/nvim/getchar.h\ @@ -186,14 +182,11 @@ iwyu: build/.ran-cmake |src/nvim/highlight.h\ |src/nvim/highlight_group.h\ |src/nvim/input.h\ - |src/nvim/insexpand.h\ |src/nvim/keycodes.h\ |src/nvim/log.h\ |src/nvim/lua/executor.h\ |src/nvim/main.h\ |src/nvim/mark.h\ - |src/nvim/mouse.h\ - |src/nvim/move.h\ |src/nvim/msgpack_rpc/channel.h\ |src/nvim/msgpack_rpc/channel_defs.h\ |src/nvim/msgpack_rpc/helpers.h\ @@ -207,10 +200,6 @@ iwyu: build/.ran-cmake |src/nvim/path.h\ |src/nvim/plines.h\ |src/nvim/popupmenu.h\ - |src/nvim/search.h\ - |src/nvim/spell.h\ - |src/nvim/syntax.h\ - |src/nvim/textobject.h\ |src/nvim/tui/input.h\ |src/nvim/ui.h\ |src/nvim/viml/parser/expressions.h\ diff --git a/src/clint.py b/src/clint.py index a45969af31..9b946998c9 100755 --- a/src/clint.py +++ b/src/clint.py @@ -931,11 +931,7 @@ def CheckIncludes(filename, lines, error): "src/nvim/event/stream.h", "src/nvim/event/time.h", "src/nvim/event/wstream.h", - "src/nvim/ex_cmds.h", - "src/nvim/ex_docmd.h", "src/nvim/extmark.h", - "src/nvim/file_search.h", - "src/nvim/fileio.h", "src/nvim/fold.h", "src/nvim/garray.h", "src/nvim/getchar.h", @@ -944,14 +940,11 @@ def CheckIncludes(filename, lines, error): "src/nvim/highlight.h", "src/nvim/highlight_group.h", "src/nvim/input.h", - "src/nvim/insexpand.h", "src/nvim/keycodes.h", "src/nvim/log.h", "src/nvim/lua/executor.h", "src/nvim/main.h", "src/nvim/mark.h", - "src/nvim/mouse.h", - "src/nvim/move.h", "src/nvim/msgpack_rpc/channel.h", "src/nvim/msgpack_rpc/channel_defs.h", "src/nvim/msgpack_rpc/helpers.h", @@ -965,10 +958,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/path.h", "src/nvim/plines.h", "src/nvim/popupmenu.h", - "src/nvim/search.h", - "src/nvim/spell.h", - "src/nvim/syntax.h", - "src/nvim/textobject.h", "src/nvim/tui/input.h", "src/nvim/ui.h", "src/nvim/viml/parser/expressions.h", diff --git a/src/nvim/autocmd.h b/src/nvim/autocmd.h index 259a56cf5c..8ff4d75ddf 100644 --- a/src/nvim/autocmd.h +++ b/src/nvim/autocmd.h @@ -27,18 +27,57 @@ EXTERN win_T *last_cursormoved_win INIT( = NULL); /// For CursorMoved event, only used when last_cursormoved_win == curwin EXTERN pos_T last_cursormoved INIT( = { 0, 0, 0 }); -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "autocmd.h.generated.h" -#endif +EXTERN bool autocmd_busy INIT( = false); ///< Is apply_autocmds() busy? +EXTERN int autocmd_no_enter INIT( = false); ///< *Enter autocmds disabled +EXTERN int autocmd_no_leave INIT( = false); ///< *Leave autocmds disabled +EXTERN bool did_filetype INIT( = false); ///< FileType event found +/// value for did_filetype when starting to execute autocommands +EXTERN bool keep_filetype INIT( = false); -#define AUGROUP_DEFAULT (-1) // default autocmd group -#define AUGROUP_ERROR (-2) // erroneous autocmd group -#define AUGROUP_ALL (-3) // all autocmd groups -#define AUGROUP_DELETED (-4) // all autocmd groups -// #define AUGROUP_NS -5 // TODO(tjdevries): Support namespaced based augroups +/// When deleting the current buffer, another one must be loaded. +/// If we know which one is preferred, au_new_curbuf is set to it. +EXTERN bufref_T au_new_curbuf INIT( = { NULL, 0, 0 }); -#define BUFLOCAL_PAT_LEN 25 +// When deleting a buffer/window and autocmd_busy is true, do not free the +// buffer/window. but link it in the list starting with +// au_pending_free_buf/ap_pending_free_win, using b_next/w_next. +// Free the buffer/window when autocmd_busy is being set to false. +EXTERN buf_T *au_pending_free_buf INIT( = NULL); +EXTERN win_T *au_pending_free_win INIT( = NULL); + +EXTERN char *autocmd_fname INIT( = NULL); ///< fname for on cmdline +EXTERN bool autocmd_fname_full INIT( = false); ///< autocmd_fname is full path +EXTERN int autocmd_bufnr INIT( = 0); ///< fnum for on cmdline +EXTERN char *autocmd_match INIT( = NULL); ///< name for on cmdline +EXTERN bool did_cursorhold INIT( = false); ///< set when CursorHold t'gerd + +typedef struct { + win_T *auc_win; ///< Window used in aucmd_prepbuf(). When not NULL the + ///< window has been allocated. + bool auc_win_used; ///< This auc_win is being used. +} aucmdwin_T; + +/// When executing autocommands for a buffer that is not in any window, a +/// special window is created to handle the side effects. When autocommands +/// nest we may need more than one. +EXTERN kvec_t(aucmdwin_T) aucmd_win_vec INIT( = KV_INITIAL_VALUE); +#define aucmd_win (aucmd_win_vec.items) +#define AUCMD_WIN_COUNT ((int)aucmd_win_vec.size) + +enum { + AUGROUP_DEFAULT = -1, ///< default autocmd group + AUGROUP_ERROR = -2, ///< erroneous autocmd group + AUGROUP_ALL = -3, ///< all autocmd groups + AUGROUP_DELETED = -4, ///< all autocmd groups + // AUGROUP_NS = -5, // TODO(tjdevries): Support namespaced based augroups +}; + +enum { BUFLOCAL_PAT_LEN = 25, }; /// Iterates over all the events for auto commands #define FOR_ALL_AUEVENTS(event) \ for (event_T event = (event_T)0; (int)event < (int)NUM_EVENTS; event = (event_T)((int)event + 1)) // NOLINT + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "autocmd.h.generated.h" +#endif diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a43ca3d78a..de36bf016f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14,6 +14,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii_defs.h" +#include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" #include "nvim/channel.h" diff --git a/src/nvim/eval.h b/src/nvim/eval.h index 1fc2891917..7306645cc3 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -4,17 +4,18 @@ #include #include -#include "nvim/buffer_defs.h" +#include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/channel.h" -#include "nvim/cmdexpand_defs.h" +#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" #include "nvim/event/time.h" #include "nvim/ex_cmds_defs.h" -#include "nvim/globals.h" #include "nvim/hashtab_defs.h" #include "nvim/macros_defs.h" +#include "nvim/mbyte_defs.h" // IWYU pragma: keep #include "nvim/os/fileio.h" #include "nvim/os/stdpaths_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep #define COPYID_INC 2 #define COPYID_MASK (~0x1) diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 8505c30fad..38be10dbaf 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -21,6 +21,7 @@ #include "nvim/eval/typval_encode.h" #include "nvim/garray.h" #include "nvim/gettext.h" +#include "nvim/globals.h" #include "nvim/hashtab.h" #include "nvim/macros_defs.h" #include "nvim/math.h" diff --git a/src/nvim/eval/typval_defs.h b/src/nvim/eval/typval_defs.h index c6bd11ccdb..a6a0282fad 100644 --- a/src/nvim/eval/typval_defs.h +++ b/src/nvim/eval/typval_defs.h @@ -13,8 +13,10 @@ typedef int64_t varnumber_T; typedef uint64_t uvarnumber_T; -/// Refcount for dict or list that should not be freed -enum { DO_NOT_FREE_CNT = (INT_MAX / 2), }; +enum { + /// Refcount for dict or list that should not be freed + DO_NOT_FREE_CNT = (INT_MAX / 2), +}; /// Additional values for tv_list_alloc() len argument enum ListLenSpecials { @@ -291,12 +293,9 @@ typedef struct { uint64_t channel_id; /// Only used when script_id is SID_API_CLIENT. } LastSet; -/// Maximum number of function arguments -enum { MAX_FUNC_ARGS = 20, }; -/// Short variable name length -enum { VAR_SHORT_LEN = 20, }; -/// Number of fixed variables used for arguments -enum { FIXVAR_CNT = 12, }; +enum { MAX_FUNC_ARGS = 20, }; ///< Maximum number of function arguments +enum { VAR_SHORT_LEN = 20, }; ///< Short variable name length +enum { FIXVAR_CNT = 12, }; ///< Number of fixed variables used for arguments /// Structure to hold info for a function that is currently being executed. typedef struct funccall_S funccall_T; diff --git a/src/nvim/ex_cmds.h b/src/nvim/ex_cmds.h index de13f03197..011d42c6d9 100644 --- a/src/nvim/ex_cmds.h +++ b/src/nvim/ex_cmds.h @@ -1,27 +1,28 @@ #pragma once -#include - #include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" // IWYU pragma: export -#include "nvim/os/time.h" +#include "nvim/os/time_defs.h" #include "nvim/pos_defs.h" // IWYU pragma: keep -// flags for do_ecmd() -#define ECMD_HIDE 0x01 // don't free the current buffer -#define ECMD_SET_HELP 0x02 // set b_help flag of (new) buffer before - // opening file -#define ECMD_OLDBUF 0x04 // use existing buffer if it exists -#define ECMD_FORCEIT 0x08 // ! used in Ex command -#define ECMD_ADDBUF 0x10 // don't edit, just add to buffer list -#define ECMD_ALTBUF 0x20 // like ECMD_ADDBUF and set the alternate file -#define ECMD_NOWINENTER 0x40 // do not trigger BufWinEnter +/// flags for do_ecmd() +enum { + ECMD_HIDE = 0x01, ///< don't free the current buffer + ECMD_SET_HELP = 0x02, ///< set b_help flag of (new) buffer before opening file + ECMD_OLDBUF = 0x04, ///< use existing buffer if it exists + ECMD_FORCEIT = 0x08, ///< ! used in Ex command + ECMD_ADDBUF = 0x10, ///< don't edit, just add to buffer list + ECMD_ALTBUF = 0x20, ///< like ECMD_ADDBUF and set the alternate file + ECMD_NOWINENTER = 0x40, ///< do not trigger BufWinEnter +}; -// for lnum argument in do_ecmd() -#define ECMD_LASTL 0 // use last position in loaded file -#define ECMD_LAST (-1) // use last position in all files -#define ECMD_ONE 1 // use first line +/// for lnum argument in do_ecmd() +enum { + ECMD_LASTL = 0, ///< use last position in loaded file + ECMD_LAST = -1, ///< use last position in all files + ECMD_ONE = 1, ///< use first line +}; /// Previous :substitute replacement string definition typedef struct { diff --git a/src/nvim/ex_docmd.h b/src/nvim/ex_docmd.h index 698153e8df..ce23b9f464 100644 --- a/src/nvim/ex_docmd.h +++ b/src/nvim/ex_docmd.h @@ -6,8 +6,8 @@ #include "nvim/cmdexpand_defs.h" // IWYU pragma: keep #include "nvim/ex_cmds_defs.h" // IWYU pragma: keep #include "nvim/getchar_defs.h" -#include "nvim/globals.h" #include "nvim/types_defs.h" // IWYU pragma: keep +#include "nvim/vim_defs.h" // IWYU pragma: keep /// flags for do_cmdline() enum { diff --git a/src/nvim/ex_eval_defs.h b/src/nvim/ex_eval_defs.h index c7231bb315..3f5e510a20 100644 --- a/src/nvim/ex_eval_defs.h +++ b/src/nvim/ex_eval_defs.h @@ -13,9 +13,11 @@ struct eslist_elem { eslist_T *next; ///< next element on the list }; -/// For conditional commands a stack is kept of nested conditionals. -/// When cs_idx < 0, there is no conditional command. -enum { CSTACK_LEN = 50, }; +enum { + /// For conditional commands a stack is kept of nested conditionals. + /// When cs_idx < 0, there is no conditional command. + CSTACK_LEN = 50, +}; typedef struct { int cs_flags[CSTACK_LEN]; ///< CSF_ flags diff --git a/src/nvim/file_search.h b/src/nvim/file_search.h index d4b5c5d352..a2d578a668 100644 --- a/src/nvim/file_search.h +++ b/src/nvim/file_search.h @@ -1,14 +1,14 @@ #pragma once -#include - -#include "nvim/globals.h" #include "nvim/types_defs.h" // IWYU pragma: keep +#include "nvim/vim_defs.h" // IWYU pragma: keep -// Flags for find_file_*() functions. -#define FINDFILE_FILE 0 // only files -#define FINDFILE_DIR 1 // only directories -#define FINDFILE_BOTH 2 // files and directories +/// Flags for find_file_*() functions. +enum { + FINDFILE_FILE = 0, ///< only files + FINDFILE_DIR = 1, ///< only directories + FINDFILE_BOTH = 2, ///< files and directories +}; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "file_search.h.generated.h" diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h index d1f6561507..32a5ec3002 100644 --- a/src/nvim/fileio.h +++ b/src/nvim/fileio.h @@ -8,44 +8,49 @@ #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" // IWYU pragma: keep #include "nvim/garray_defs.h" // IWYU pragma: keep -#include "nvim/globals.h" #include "nvim/os/fs_defs.h" // IWYU pragma: keep -#include "nvim/pos_defs.h" +#include "nvim/pos_defs.h" // IWYU pragma: keep -// Values for readfile() flags -#define READ_NEW 0x01 // read a file into a new buffer -#define READ_FILTER 0x02 // read filter output -#define READ_STDIN 0x04 // read from stdin -#define READ_BUFFER 0x08 // read from curbuf (converting stdin) -#define READ_DUMMY 0x10 // reading into a dummy buffer -#define READ_KEEP_UNDO 0x20 // keep undo info -#define READ_FIFO 0x40 // read from fifo or socket -#define READ_NOWINENTER 0x80 // do not trigger BufWinEnter -#define READ_NOFILE 0x100 // do not read a file, do trigger BufReadCmd +/// Values for readfile() flags +enum { + READ_NEW = 0x01, ///< read a file into a new buffer + READ_FILTER = 0x02, ///< read filter output + READ_STDIN = 0x04, ///< read from stdin + READ_BUFFER = 0x08, ///< read from curbuf (converting stdin) + READ_DUMMY = 0x10, ///< reading into a dummy buffer + READ_KEEP_UNDO = 0x20, ///< keep undo info + READ_FIFO = 0x40, ///< read from fifo or socket + READ_NOWINENTER = 0x80, ///< do not trigger BufWinEnter + READ_NOFILE = 0x100, ///< do not read a file, do trigger BufReadCmd +}; typedef varnumber_T (*CheckItem)(void *expr, const char *name); enum { - FIO_LATIN1 = 0x01, // convert Latin1 - FIO_UTF8 = 0x02, // convert UTF-8 - FIO_UCS2 = 0x04, // convert UCS-2 - FIO_UCS4 = 0x08, // convert UCS-4 - FIO_UTF16 = 0x10, // convert UTF-16 - FIO_ENDIAN_L = 0x80, // little endian - FIO_NOCONVERT = 0x2000, // skip encoding conversion - FIO_UCSBOM = 0x4000, // check for BOM at start of file - FIO_ALL = -1, // allow all formats + FIO_LATIN1 = 0x01, ///< convert Latin1 + FIO_UTF8 = 0x02, ///< convert UTF-8 + FIO_UCS2 = 0x04, ///< convert UCS-2 + FIO_UCS4 = 0x08, ///< convert UCS-4 + FIO_UTF16 = 0x10, ///< convert UTF-16 + FIO_ENDIAN_L = 0x80, ///< little endian + FIO_NOCONVERT = 0x2000, ///< skip encoding conversion + FIO_UCSBOM = 0x4000, ///< check for BOM at start of file + FIO_ALL = -1, ///< allow all formats }; -// When converting, a read() or write() may leave some bytes to be converted -// for the next call. The value is guessed... -#define CONV_RESTLEN 30 +enum { + /// When converting, a read() or write() may leave some bytes to be converted + /// for the next call. The value is guessed... + CONV_RESTLEN = 30, +}; -#define WRITEBUFSIZE 8192 // size of normal write buffer +enum { WRITEBUFSIZE = 8192, }; ///< size of normal write buffer -// We have to guess how much a sequence of bytes may expand when converting -// with iconv() to be able to allocate a buffer. -#define ICONV_MULT 8 +enum { + /// We have to guess how much a sequence of bytes may expand when converting + /// with iconv() to be able to allocate a buffer. + ICONV_MULT = 8, +}; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "fileio.h.generated.h" diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h index 177a021706..e1bc64bfee 100644 --- a/src/nvim/getchar.h +++ b/src/nvim/getchar.h @@ -15,8 +15,7 @@ typedef enum { FLUSH_INPUT, ///< flush typebuf and inchar() input } flush_buffers_T; -/// Maximum number of streams to read script from -enum { NSCRIPT = 15, }; +enum { NSCRIPT = 15, }; ///< Maximum number of streams to read script from /// Streams to read script from extern FileDescriptor *scriptin[NSCRIPT]; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 270ffe4fa0..1299aa12e5 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -103,34 +103,6 @@ EXTERN struct nvim_stats_s { EXTERN int Rows INIT( = DFLT_ROWS); // nr of rows in the screen EXTERN int Columns INIT( = DFLT_COLS); // nr of columns in the screen -// We use 64-bit file functions here, if available. E.g. ftello() returns -// off_t instead of long, which helps if long is 32 bit and off_t is 64 bit. -// We assume that when fseeko() is available then ftello() is too. -// Note that Windows has different function names. -#if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__MINGW32__) -typedef __int64 off_T; -# ifdef __MINGW32__ -# define vim_lseek lseek64 -# define vim_fseek fseeko64 -# define vim_ftell ftello64 -# else -# define vim_lseek _lseeki64 -# define vim_fseek _fseeki64 -# define vim_ftell _ftelli64 -# endif -#else -typedef off_t off_T; -# ifdef HAVE_FSEEKO -# define vim_lseek lseek -# define vim_ftell ftello -# define vim_fseek fseeko -# else -# define vim_lseek lseek -# define vim_ftell ftell -# define vim_fseek(a, b, c) fseek(a, (long)b, c) -# endif -#endif - // When vgetc() is called, it sets mod_mask to the set of modifiers that are // held down based on the MOD_MASK_* symbols that are read first. EXTERN int mod_mask INIT( = 0); // current key modifiers @@ -370,24 +342,7 @@ EXTERN bool did_check_timestamps INIT( = false); // did check timestamps // recently EXTERN int no_check_timestamps INIT( = 0); // Don't check timestamps -EXTERN bool autocmd_busy INIT( = false); // Is apply_autocmds() busy? -EXTERN int autocmd_no_enter INIT( = false); // *Enter autocmds disabled -EXTERN int autocmd_no_leave INIT( = false); // *Leave autocmds disabled EXTERN int modified_was_set; // did ":set modified" -EXTERN bool did_filetype INIT( = false); // FileType event found -// value for did_filetype when starting to execute autocommands -EXTERN bool keep_filetype INIT( = false); - -// When deleting the current buffer, another one must be loaded. -// If we know which one is preferred, au_new_curbuf is set to it. -EXTERN bufref_T au_new_curbuf INIT( = { NULL, 0, 0 }); - -// When deleting a buffer/window and autocmd_busy is true, do not free the -// buffer/window. but link it in the list starting with -// au_pending_free_buf/ap_pending_free_win, using b_next/w_next. -// Free the buffer/window when autocmd_busy is being set to false. -EXTERN buf_T *au_pending_free_buf INIT( = NULL); -EXTERN win_T *au_pending_free_win INIT( = NULL); // Mouse coordinates, set by handle_mouse_event() EXTERN int mouse_grid; @@ -426,19 +381,6 @@ EXTERN win_T *prevwin INIT( = NULL); // previous window EXTERN win_T *curwin; // currently active window -typedef struct { - win_T *auc_win; ///< Window used in aucmd_prepbuf(). When not NULL the - ///< window has been allocated. - bool auc_win_used; ///< This auc_win is being used. -} aucmdwin_T; - -/// When executing autocommands for a buffer that is not in any window, a -/// special window is created to handle the side effects. When autocommands -/// nest we may need more than one. -EXTERN kvec_t(aucmdwin_T) aucmd_win_vec INIT( = KV_INITIAL_VALUE); -#define aucmd_win (aucmd_win_vec.items) -#define AUCMD_WIN_COUNT ((int)aucmd_win_vec.size) - // The window layout is kept in a tree of frames. topframe points to the top // of the tree. EXTERN frame_T *topframe; // top of the window frame tree @@ -758,11 +700,6 @@ EXTERN char last_mode[MODE_MAX_LENGTH] INIT( = "n"); EXTERN char *last_cmdline INIT( = NULL); // last command line (for ":) EXTERN char *repeat_cmdline INIT( = NULL); // command line for "." EXTERN char *new_last_cmdline INIT( = NULL); // new value for last_cmdline -EXTERN char *autocmd_fname INIT( = NULL); // fname for on cmdline -EXTERN bool autocmd_fname_full INIT( = false); // autocmd_fname is full path -EXTERN int autocmd_bufnr INIT( = 0); // fnum for on cmdline -EXTERN char *autocmd_match INIT( = NULL); // name for on cmdline -EXTERN bool did_cursorhold INIT( = false); // set when CursorHold t'gerd EXTERN int postponed_split INIT( = 0); // for CTRL-W CTRL-] command EXTERN int postponed_split_flags INIT( = 0); // args for win_split() @@ -1051,39 +988,7 @@ EXTERN bool headless_mode INIT(= false); // uncrustify:on -/// Used to track the status of external functions. -/// Currently only used for iconv(). -typedef enum { - kUnknown, - kWorking, - kBroken, -} WorkingStatus; - -/// The scope of a working-directory command like `:cd`. -/// -/// Scopes are enumerated from lowest to highest. When adding a scope make sure -/// to update all functions using scopes as well, such as the implementation of -/// `getcwd()`. When using scopes as limits (e.g. in loops) don't use the scopes -/// directly, use `MIN_CD_SCOPE` and `MAX_CD_SCOPE` instead. -typedef enum { - kCdScopeInvalid = -1, - kCdScopeWindow, ///< Affects one window. - kCdScopeTabpage, ///< Affects one tab page. - kCdScopeGlobal, ///< Affects the entire Nvim instance. -} CdScope; - -#define MIN_CD_SCOPE kCdScopeWindow -#define MAX_CD_SCOPE kCdScopeGlobal - -/// What caused the current directory to change. -typedef enum { - kCdCauseOther = -1, - kCdCauseManual, ///< Using `:cd`, `:tcd`, `:lcd` or `chdir()`. - kCdCauseWindow, ///< Switching to another window. - kCdCauseAuto, ///< On 'autochdir'. -} CdCause; - -// Only filled for Win32. +/// Only filled for Win32. EXTERN char windowsVersion[20] INIT( = { 0 }); /// While executing a regexp and set to OPTION_MAGIC_ON or OPTION_MAGIC_OFF this diff --git a/src/nvim/hashtab_defs.h b/src/nvim/hashtab_defs.h index 089838fcae..8888eab972 100644 --- a/src/nvim/hashtab_defs.h +++ b/src/nvim/hashtab_defs.h @@ -34,11 +34,13 @@ typedef struct hashitem_S { char *hi_key; } hashitem_T; -/// Initial size for a hashtable. -/// Our items are relatively small and growing is expensive, thus start with 16. -/// Must be a power of 2. -/// This allows for storing 10 items (2/3 of 16) before a resize is needed. -enum { HT_INIT_SIZE = 16, }; +enum { + /// Initial size for a hashtable. + /// Our items are relatively small and growing is expensive, thus start with 16. + /// Must be a power of 2. + /// This allows for storing 10 items (2/3 of 16) before a resize is needed. + HT_INIT_SIZE = 16, +}; /// An array-based hashtable. /// diff --git a/src/nvim/insexpand.h b/src/nvim/insexpand.h index 121d5568ff..b880e64ea4 100644 --- a/src/nvim/insexpand.h +++ b/src/nvim/insexpand.h @@ -1,10 +1,9 @@ #pragma once -#include "nvim/macros_defs.h" #include "nvim/option_defs.h" // IWYU pragma: keep #include "nvim/pos_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep -#include "nvim/vim_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS # include "insexpand.h.generated.h" diff --git a/src/nvim/mapping_defs.h b/src/nvim/mapping_defs.h index 6691c5ac3b..4f0334c226 100644 --- a/src/nvim/mapping_defs.h +++ b/src/nvim/mapping_defs.h @@ -5,8 +5,7 @@ #include "nvim/eval/typval_defs.h" #include "nvim/types_defs.h" -/// Maximum length of key sequence to be mapped. -enum { MAXMAPLEN = 50, }; +enum { MAXMAPLEN = 50, }; ///< Maximum length of key sequence to be mapped. /// Structure used for mappings and abbreviations. typedef struct mapblock mapblock_T; diff --git a/src/nvim/mbyte_defs.h b/src/nvim/mbyte_defs.h index 2904047223..efb4f558a6 100644 --- a/src/nvim/mbyte_defs.h +++ b/src/nvim/mbyte_defs.h @@ -4,13 +4,14 @@ #include "nvim/iconv_defs.h" -/// Maximum number of bytes in a multi-byte character. It can be one 32-bit -/// character of up to 6 bytes, or one 16-bit character of up to three bytes -/// plus six following composing characters of three bytes each. -enum { MB_MAXBYTES = 21, }; - -/// max length of an unicode char -enum { MB_MAXCHAR = 6, }; +enum { + /// Maximum number of bytes in a multi-byte character. It can be one 32-bit + /// character of up to 6 bytes, or one 16-bit character of up to three bytes + /// plus six following composing characters of three bytes each. + MB_MAXBYTES = 21, + /// max length of an unicode char + MB_MAXCHAR = 6, +}; /// properties used in enc_canon_table[] (first three mutually exclusive) enum { diff --git a/src/nvim/message.h b/src/nvim/message.h index adbb40277b..904fb2d3ad 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -30,8 +30,7 @@ enum { VIM_DISCARDALL = 6, }; -/// special attribute addition: Put message in history -enum { MSG_HIST = 0x1000, }; +enum { MSG_HIST = 0x1000, }; ///< special attribute addition: Put message in history typedef struct { String text; diff --git a/src/nvim/mouse.h b/src/nvim/mouse.h index 928b3e360b..d787b8ff57 100644 --- a/src/nvim/mouse.h +++ b/src/nvim/mouse.h @@ -4,7 +4,7 @@ #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/normal_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep -#include "nvim/vim_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep /// jump_to_mouse() returns one of first five these values, possibly with /// some of the other five added. diff --git a/src/nvim/move.h b/src/nvim/move.h index ab8fb2b386..f48de6987b 100644 --- a/src/nvim/move.h +++ b/src/nvim/move.h @@ -1,11 +1,9 @@ #pragma once -#include - #include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep -#include "nvim/vim_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS # include "move.h.generated.h" diff --git a/src/nvim/normal_defs.h b/src/nvim/normal_defs.h index 060c1057f9..6ea6660a8b 100644 --- a/src/nvim/normal_defs.h +++ b/src/nvim/normal_defs.h @@ -70,6 +70,5 @@ enum { REPLACE_NL_NCHAR = -2, }; -/// columns needed by shown command -enum { SHOWCMD_COLS = 10, }; +enum { SHOWCMD_COLS = 10, }; ///< columns needed by shown command enum { SHOWCMD_BUFLEN = SHOWCMD_COLS + 1 + 30, }; diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index 12de55a227..db575e005a 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -113,3 +113,31 @@ && (defined(S_ISCHR) || defined(S_IFCHR)) # define OPEN_CHR_FILES #endif + +// We use 64-bit file functions here, if available. E.g. ftello() returns +// off_t instead of long, which helps if long is 32 bit and off_t is 64 bit. +// We assume that when fseeko() is available then ftello() is too. +// Note that Windows has different function names. +#if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__MINGW32__) +typedef __int64 off_T; +# ifdef __MINGW32__ +# define vim_lseek lseek64 +# define vim_fseek fseeko64 +# define vim_ftell ftello64 +# else +# define vim_lseek _lseeki64 +# define vim_fseek _fseeki64 +# define vim_ftell _ftelli64 +# endif +#else +typedef off_t off_T; +# ifdef HAVE_FSEEKO +# define vim_lseek lseek +# define vim_ftell ftello +# define vim_fseek fseeko +# else +# define vim_lseek lseek +# define vim_ftell ftell +# define vim_fseek(a, b, c) fseek(a, (long)b, c) +# endif +#endif diff --git a/src/nvim/pos_defs.h b/src/nvim/pos_defs.h index 98a1762a5c..a9816c6a66 100644 --- a/src/nvim/pos_defs.h +++ b/src/nvim/pos_defs.h @@ -12,19 +12,15 @@ typedef int colnr_T; /// Format used to print values which have colnr_T type #define PRIdCOLNR "d" -/// Maximal (invalid) line number -enum { MAXLNUM = 0x7fffffff, }; +enum { MAXLNUM = 0x7fffffff, }; ///< Maximal (invalid) line number -/// Maximal column number -/// MAXCOL used to be INT_MAX, but with 64 bit ints that results in running -/// out of memory when trying to allocate a very long line. -enum { MAXCOL = 0x7fffffff, }; +// MAXCOL used to be INT_MAX, but with 64 bit ints that results in running +// out of memory when trying to allocate a very long line. +enum { MAXCOL = 0x7fffffff, }; ///< Maximal column number -/// Minimum line number -enum { MINLNUM = 1, }; +enum { MINLNUM = 1, }; ///< Minimum line number -/// Minimum column number -enum { MINCOL = 1, }; +enum { MINCOL = 1, }; ///< Minimum column number /// position in file or buffer typedef struct { diff --git a/src/nvim/regexp_defs.h b/src/nvim/regexp_defs.h index 079f3b6929..31bc0e86e8 100644 --- a/src/nvim/regexp_defs.h +++ b/src/nvim/regexp_defs.h @@ -33,18 +33,22 @@ typedef enum { MAGIC_ALL = 4, ///< "\v" very magic } magic_T; -/// The number of sub-matches is limited to 10. -/// The first one (index 0) is the whole match, referenced with "\0". -/// The second one (index 1) is the first sub-match, referenced with "\1". -/// This goes up to the tenth (index 9), referenced with "\9". -enum { NSUBEXP = 10, }; - -/// In the NFA engine: how many braces are allowed. -/// TODO(RE): Use dynamic memory allocation instead of static, like here -enum { NFA_MAX_BRACES = 20, }; - -/// In the NFA engine: how many states are allowed. enum { + /// The number of sub-matches is limited to 10. + /// The first one (index 0) is the whole match, referenced with "\0". + /// The second one (index 1) is the first sub-match, referenced with "\1". + /// This goes up to the tenth (index 9), referenced with "\9". + NSUBEXP = 10, +}; + +enum { + /// In the NFA engine: how many braces are allowed. + /// TODO(RE): Use dynamic memory allocation instead of static, like here + NFA_MAX_BRACES = 20, +}; + +enum { + /// In the NFA engine: how many states are allowed. NFA_MAX_STATES = 100000, NFA_TOO_EXPENSIVE = -1, }; diff --git a/src/nvim/search.h b/src/nvim/search.h index 48ca555e7f..12553c8e74 100644 --- a/src/nvim/search.h +++ b/src/nvim/search.h @@ -3,61 +3,73 @@ #include #include -#include "nvim/buffer_defs.h" +#include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" #include "nvim/normal_defs.h" // IWYU pragma: keep #include "nvim/os/time_defs.h" #include "nvim/pos_defs.h" #include "nvim/regexp_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" -#include "nvim/vim_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep -// Values for the find_pattern_in_path() function args 'type' and 'action': -#define FIND_ANY 1 -#define FIND_DEFINE 2 -#define CHECK_PATH 3 +/// Values for the find_pattern_in_path() function args 'type' and 'action': +enum { + FIND_ANY = 1, + FIND_DEFINE = 2, + CHECK_PATH = 3, +}; -#define ACTION_SHOW 1 -#define ACTION_GOTO 2 -#define ACTION_SPLIT 3 -#define ACTION_SHOW_ALL 4 -#define ACTION_EXPAND 5 +enum { + ACTION_SHOW = 1, + ACTION_GOTO = 2, + ACTION_SPLIT = 3, + ACTION_SHOW_ALL = 4, + ACTION_EXPAND = 5, +}; -// Values for 'options' argument in do_search() and searchit() -#define SEARCH_REV 0x01 ///< go in reverse of previous dir. -#define SEARCH_ECHO 0x02 ///< echo the search command and handle options -#define SEARCH_MSG 0x0c ///< give messages (yes, it's not 0x04) -#define SEARCH_NFMSG 0x08 ///< give all messages except not found -#define SEARCH_OPT 0x10 ///< interpret optional flags -#define SEARCH_HIS 0x20 ///< put search pattern in history -#define SEARCH_END 0x40 ///< put cursor at end of match -#define SEARCH_NOOF 0x80 ///< don't add offset to position -#define SEARCH_START 0x100 ///< start search without col offset -#define SEARCH_MARK 0x200 ///< set previous context mark -#define SEARCH_KEEP 0x400 ///< keep previous search pattern -#define SEARCH_PEEK 0x800 ///< peek for typed char, cancel search -#define SEARCH_COL 0x1000 ///< start at specified column instead of zero +/// Values for "options" argument in do_search() and searchit() +enum { + SEARCH_REV = 0x01, ///< go in reverse of previous dir. + SEARCH_ECHO = 0x02, ///< echo the search command and handle options + SEARCH_MSG = 0x0c, ///< give messages (yes, it's not 0x04) + SEARCH_NFMSG = 0x08, ///< give all messages except not found + SEARCH_OPT = 0x10, ///< interpret optional flags + SEARCH_HIS = 0x20, ///< put search pattern in history + SEARCH_END = 0x40, ///< put cursor at end of match + SEARCH_NOOF = 0x80, ///< don't add offset to position + SEARCH_START = 0x100, ///< start search without col offset + SEARCH_MARK = 0x200, ///< set previous context mark + SEARCH_KEEP = 0x400, ///< keep previous search pattern + SEARCH_PEEK = 0x800, ///< peek for typed char, cancel search + SEARCH_COL = 0x1000, ///< start at specified column instead of zero +}; -// Values for flags argument for findmatchlimit() -#define FM_BACKWARD 0x01 // search backwards -#define FM_FORWARD 0x02 // search forwards -#define FM_BLOCKSTOP 0x04 // stop at start/end of block -#define FM_SKIPCOMM 0x08 // skip comments +/// Values for flags argument for findmatchlimit() +enum { + FM_BACKWARD = 0x01, ///< search backwards + FM_FORWARD = 0x02, ///< search forwards + FM_BLOCKSTOP = 0x04, ///< stop at start/end of block + FM_SKIPCOMM = 0x08, ///< skip comments +}; -// Values for sub_cmd and which_pat argument for search_regcomp() -// Also used for which_pat argument for searchit() -#define RE_SEARCH 0 // save/use pat in/from search_pattern -#define RE_SUBST 1 // save/use pat in/from subst_pattern -#define RE_BOTH 2 // save pat in both patterns -#define RE_LAST 2 // use last used pattern if "pat" is NULL +/// Values for sub_cmd and which_pat argument for search_regcomp() +/// Also used for which_pat argument for searchit() +enum { + RE_SEARCH = 0, ///< save/use pat in/from search_pattern + RE_SUBST = 1, ///< save/use pat in/from subst_pattern + RE_BOTH = 2, ///< save pat in both patterns + RE_LAST = 2, ///< use last used pattern if "pat" is NULL +}; // Values for searchcount() -#define SEARCH_STAT_DEF_TIMEOUT 40 -#define SEARCH_STAT_DEF_MAX_COUNT 99 -#define SEARCH_STAT_BUF_LEN 12 +enum { SEARCH_STAT_DEF_TIMEOUT = 40, }; +enum { SEARCH_STAT_DEF_MAX_COUNT = 99, }; +enum { SEARCH_STAT_BUF_LEN = 12, }; -/// Maximum number of characters that can be fuzzy matched -#define MAX_FUZZY_MATCHES 256 +enum { + /// Maximum number of characters that can be fuzzy matched + MAX_FUZZY_MATCHES = 256, +}; /// Structure containing offset definition for the last search pattern /// diff --git a/src/nvim/spell.h b/src/nvim/spell.h index f3977fdaf2..43ba00e901 100644 --- a/src/nvim/spell.h +++ b/src/nvim/spell.h @@ -1,11 +1,8 @@ #pragma once -#include - #include "nvim/ex_cmds_defs.h" // IWYU pragma: keep -#include "nvim/globals.h" #include "nvim/spell_defs.h" // IWYU pragma: export -#include "nvim/vim_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep /// First language that is loaded, start of the linked list of loaded languages. extern slang_T *first_lang; diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h index dfa399750f..6293bc314b 100644 --- a/src/nvim/spell_defs.h +++ b/src/nvim/spell_defs.h @@ -8,12 +8,13 @@ #include "nvim/hashtab_defs.h" #include "nvim/regexp_defs.h" -/// Assume max. word len is this many bytes. -/// Some places assume a word length fits in a byte, thus it can't be above 255. -enum { MAXWLEN = 254, }; +enum { + /// Assume max. word len is this many bytes. + /// Some places assume a word length fits in a byte, thus it can't be above 255. + MAXWLEN = 254, +}; -/// Number of regions supported. -enum { MAXREGIONS = 8, }; +enum { MAXREGIONS = 8, }; ///< Number of regions supported. /// Type used for indexes in the word tree need to be at least 4 bytes. If int /// is 8 bytes we could use something smaller, but what? diff --git a/src/nvim/syntax.h b/src/nvim/syntax.h index 4e9c7a27dc..b9065acf7d 100644 --- a/src/nvim/syntax.h +++ b/src/nvim/syntax.h @@ -1,33 +1,32 @@ #pragma once -#include - #include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/cmdexpand_defs.h" // IWYU pragma: keep #include "nvim/ex_cmds_defs.h" // IWYU pragma: keep -#include "nvim/globals.h" #include "nvim/macros_defs.h" #include "nvim/syntax_defs.h" // IWYU pragma: export -#define HL_CONTAINED 0x01 // not used on toplevel -#define HL_TRANSP 0x02 // has no highlighting -#define HL_ONELINE 0x04 // match within one line only -#define HL_HAS_EOL 0x08 // end pattern that matches with $ -#define HL_SYNC_HERE 0x10 // sync point after this item (syncing only) -#define HL_SYNC_THERE 0x20 // sync point at current line (syncing only) -#define HL_MATCH 0x40 // use match ID instead of item ID -#define HL_SKIPNL 0x80 // nextgroup can skip newlines -#define HL_SKIPWHITE 0x100 // nextgroup can skip white space -#define HL_SKIPEMPTY 0x200 // nextgroup can skip empty lines -#define HL_KEEPEND 0x400 // end match always kept -#define HL_EXCLUDENL 0x800 // exclude NL from match -#define HL_DISPLAY 0x1000 // only used for displaying, not syncing -#define HL_FOLD 0x2000 // define fold -#define HL_EXTEND 0x4000 // ignore a keepend -#define HL_MATCHCONT 0x8000 // match continued from previous line -#define HL_TRANS_CONT 0x10000 // transparent item without contains arg -#define HL_CONCEAL 0x20000 // can be concealed -#define HL_CONCEALENDS 0x40000 // can be concealed +enum { + HL_CONTAINED = 0x01, ///< not used on toplevel + HL_TRANSP = 0x02, ///< has no highlighting + HL_ONELINE = 0x04, ///< match within one line only + HL_HAS_EOL = 0x08, ///< end pattern that matches with $ + HL_SYNC_HERE = 0x10, ///< sync point after this item (syncing only) + HL_SYNC_THERE = 0x20, ///< sync point at current line (syncing only) + HL_MATCH = 0x40, ///< use match ID instead of item ID + HL_SKIPNL = 0x80, ///< nextgroup can skip newlines + HL_SKIPWHITE = 0x100, ///< nextgroup can skip white space + HL_SKIPEMPTY = 0x200, ///< nextgroup can skip empty lines + HL_KEEPEND = 0x400, ///< end match always kept + HL_EXCLUDENL = 0x800, ///< exclude NL from match + HL_DISPLAY = 0x1000, ///< only used for displaying, not syncing + HL_FOLD = 0x2000, ///< define fold + HL_EXTEND = 0x4000, ///< ignore a keepend + HL_MATCHCONT = 0x8000, ///< match continued from previous line + HL_TRANS_CONT = 0x10000, ///< transparent item without contains arg + HL_CONCEAL = 0x20000, ///< can be concealed + HL_CONCEALENDS = 0x40000, ///< can be concealed +}; #define SYN_GROUP_STATIC(s) syn_check_group(S_LEN(s)) diff --git a/src/nvim/textobject.h b/src/nvim/textobject.h index a540c7c98f..735a2fec3d 100644 --- a/src/nvim/textobject.h +++ b/src/nvim/textobject.h @@ -2,7 +2,7 @@ #include "nvim/normal_defs.h" // IWYU pragma: keep #include "nvim/pos_defs.h" // IWYU pragma: keep -#include "nvim/vim_defs.h" +#include "nvim/vim_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS # include "textobject.h.generated.h" diff --git a/src/nvim/undo_defs.h b/src/nvim/undo_defs.h index 0b78ea543f..09a9689f67 100644 --- a/src/nvim/undo_defs.h +++ b/src/nvim/undo_defs.h @@ -6,8 +6,7 @@ #include "nvim/mark_defs.h" #include "nvim/pos_defs.h" -/// Size in bytes of the hash used in the undo file. -enum { UNDO_HASH_SIZE = 32, }; +enum { UNDO_HASH_SIZE = 32, }; ///< Size in bytes of the hash used in the undo file. typedef struct u_header u_header_T; diff --git a/src/nvim/vim_defs.h b/src/nvim/vim_defs.h index faf79b1c79..155265ac42 100644 --- a/src/nvim/vim_defs.h +++ b/src/nvim/vim_defs.h @@ -15,11 +15,10 @@ # error Configure did not run properly. #endif -// bring lots of system header files -#include "nvim/os/os_defs.h" // IWYU pragma: keep - -/// length of a buffer to store a number in ASCII (64 bits binary + NUL) -enum { NUMBUFLEN = 65, }; +enum { + /// length of a buffer to store a number in ASCII (64 bits binary + NUL) + NUMBUFLEN = 65, +}; #define MAX_TYPENR 65535 @@ -32,6 +31,41 @@ typedef enum { BACKWARD_FILE = -3, } Direction; +/// Used to track the status of external functions. +/// Currently only used for iconv(). +typedef enum { + kUnknown, + kWorking, + kBroken, +} WorkingStatus; + +/// The scope of a working-directory command like `:cd`. +/// +/// Scopes are enumerated from lowest to highest. When adding a scope make sure +/// to update all functions using scopes as well, such as the implementation of +/// `getcwd()`. When using scopes as limits (e.g. in loops) don't use the scopes +/// directly, use `MIN_CD_SCOPE` and `MAX_CD_SCOPE` instead. +typedef enum { + kCdScopeInvalid = -1, + kCdScopeWindow, ///< Affects one window. + kCdScopeTabpage, ///< Affects one tab page. + kCdScopeGlobal, ///< Affects the entire Nvim instance. +} CdScope; + +#define MIN_CD_SCOPE kCdScopeWindow +#define MAX_CD_SCOPE kCdScopeGlobal + +/// What caused the current directory to change. +typedef enum { + kCdCauseOther = -1, + kCdCauseManual, ///< Using `:cd`, `:tcd`, `:lcd` or `chdir()`. + kCdCauseWindow, ///< Switching to another window. + kCdCauseAuto, ///< On 'autochdir'. +} CdCause; + +// bring lots of system header files +#include "nvim/os/os_defs.h" // IWYU pragma: keep + // return values for functions #if !(defined(OK) && (OK == 1)) // OK already defined to 1 in MacOS X curses, skip this diff --git a/src/nvim/window.h b/src/nvim/window.h index 3650fef46e..d70292508a 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -38,8 +38,10 @@ enum { STATUS_HEIGHT = 1, ///< height of a status line under a window }; -/// Lowest number used for window ID. Cannot have this many windows per tab. -enum { LOWEST_WIN_ID = 1000, }; +enum { + /// Lowest number used for window ID. Cannot have this many windows per tab. + LOWEST_WIN_ID = 1000, +}; /// Set to true if 'cmdheight' was explicitly set to 0. EXTERN bool p_ch_was_zero INIT( = false);