aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-22 12:24:23 +0800
committerGitHub <noreply@github.com>2023-12-22 12:24:23 +0800
commit089b934352437ab310a6dd3b138c7ed9445a3d7b (patch)
tree51de0fb010d97d4bd82aa9674156aae8ab619cdd
parent6700127b30d55e6ddf70495e7b886464172d7ac6 (diff)
downloadrneovim-089b934352437ab310a6dd3b138c7ed9445a3d7b.tar.gz
rneovim-089b934352437ab310a6dd3b138c7ed9445a3d7b.tar.bz2
rneovim-089b934352437ab310a6dd3b138c7ed9445a3d7b.zip
refactor(options): generate BV_ and WV_ constants (#26705)
-rwxr-xr-xsrc/clint.py13
-rw-r--r--src/nvim/buffer_defs.h2
-rw-r--r--src/nvim/eval/userfunc.h2
-rw-r--r--src/nvim/fold.c1
-rw-r--r--src/nvim/generators/gen_options_enum.lua53
-rw-r--r--src/nvim/globals.h3
-rw-r--r--src/nvim/input.h2
-rw-r--r--src/nvim/lua/executor.h1
-rw-r--r--src/nvim/option_vars.h150
-rw-r--r--src/nvim/viml/parser/expressions.h2
10 files changed, 58 insertions, 171 deletions
diff --git a/src/clint.py b/src/clint.py
index 303c3df25d..663416553e 100755
--- a/src/clint.py
+++ b/src/clint.py
@@ -901,7 +901,6 @@ def CheckIncludes(filename, lines, error):
"src/nvim/api/private/validate.h",
"src/nvim/assert_defs.h",
"src/nvim/buffer.h",
- "src/nvim/buffer_defs.h",
"src/nvim/channel.h",
"src/nvim/charset.h",
"src/nvim/eval.h",
@@ -910,34 +909,22 @@ def CheckIncludes(filename, lines, error):
"src/nvim/eval/typval_defs.h",
"src/nvim/eval/userfunc.h",
"src/nvim/event/libuv_process.h",
- "src/nvim/event/loop.h",
"src/nvim/event/multiqueue.h",
- "src/nvim/event/process.h",
- "src/nvim/event/rstream.h",
- "src/nvim/event/signal.h",
- "src/nvim/event/socket.h",
- "src/nvim/event/stream.h",
- "src/nvim/event/time.h",
- "src/nvim/event/wstream.h",
"src/nvim/garray.h",
"src/nvim/globals.h",
"src/nvim/grid.h",
"src/nvim/highlight.h",
- "src/nvim/input.h",
"src/nvim/keycodes.h",
"src/nvim/lua/executor.h",
"src/nvim/main.h",
"src/nvim/mark.h",
"src/nvim/msgpack_rpc/channel_defs.h",
- "src/nvim/msgpack_rpc/helpers.h",
"src/nvim/msgpack_rpc/unpacker.h",
"src/nvim/option.h",
- "src/nvim/os/input.h",
"src/nvim/os/pty_conpty_win.h",
"src/nvim/os/pty_process_unix.h",
"src/nvim/os/pty_process_win.h",
"src/nvim/tui/input.h",
- "src/nvim/ui.h",
"src/nvim/viml/parser/expressions.h",
"src/nvim/viml/parser/parser.h",
]
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 3a6b5e2c6b..ca6e874c1f 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -18,7 +18,7 @@
#include "nvim/mark_defs.h"
#include "nvim/marktree_defs.h"
#include "nvim/memline_defs.h"
-#include "nvim/option_vars.h"
+#include "nvim/option_defs.h"
#include "nvim/os/fs_defs.h"
#include "nvim/pos_defs.h"
#include "nvim/regexp_defs.h"
diff --git a/src/nvim/eval/userfunc.h b/src/nvim/eval/userfunc.h
index 65a96a13c5..270ca7db4e 100644
--- a/src/nvim/eval/userfunc.h
+++ b/src/nvim/eval/userfunc.h
@@ -11,8 +11,6 @@
#include "nvim/pos_defs.h"
#include "nvim/types_defs.h" // IWYU pragma: keep
-struct funccal_entry;
-
// From user function to hashitem and back.
#define UF2HIKEY(fp) ((fp)->uf_name)
#define HIKEY2UF(p) ((ufunc_T *)((p) - offsetof(ufunc_T, uf_name)))
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index b595bb0f87..3b7662e62d 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -38,6 +38,7 @@
#include "nvim/message.h"
#include "nvim/move.h"
#include "nvim/ops.h"
+#include "nvim/option_defs.h"
#include "nvim/option_vars.h"
#include "nvim/os/input.h"
#include "nvim/plines.h"
diff --git a/src/nvim/generators/gen_options_enum.lua b/src/nvim/generators/gen_options_enum.lua
index c3fe9baae6..9a3953fcbc 100644
--- a/src/nvim/generators/gen_options_enum.lua
+++ b/src/nvim/generators/gen_options_enum.lua
@@ -1,5 +1,6 @@
-- Generates option index enum and map of option name to option index.
-- Handles option full name, short name and aliases.
+-- Also generates BV_ and WV_ enum constants.
local options_enum_file = arg[1]
local options_map_file = arg[2]
@@ -16,6 +17,9 @@ local function map_w(s)
options_map_fd:write(s .. '\n')
end
+enum_w('// IWYU pragma: private, include "nvim/option_defs.h"')
+enum_w('')
+
--- @param s string
--- @return string
local lowercase_to_titlecase = function(s)
@@ -24,6 +28,55 @@ end
--- @type vim.option_meta[]
local options = require('options').options
+
+-- Generate BV_ enum constants.
+enum_w('/// "indir" values for buffer-local options.')
+enum_w('/// These need to be defined globally, so that the BV_COUNT can be used with')
+enum_w('/// b_p_script_stx[].')
+enum_w('enum {')
+
+local bv_val = 0
+
+for _, o in ipairs(options) do
+ assert(#o.scope == 1 or #o.scope == 2)
+ assert(#o.scope == 1 or o.scope[1] == 'global')
+ local min_scope = o.scope[#o.scope]
+ if min_scope == 'buffer' then
+ local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
+ local bv_name = 'BV_' .. varname:sub(3):upper()
+ enum_w((' %s = %u,'):format(bv_name, bv_val))
+ bv_val = bv_val + 1
+ end
+end
+
+enum_w((' BV_COUNT = %u, ///< must be the last one'):format(bv_val))
+enum_w('};')
+enum_w('')
+
+-- Generate WV_ enum constants.
+enum_w('/// "indir" values for window-local options.')
+enum_w('/// These need to be defined globally, so that the WV_COUNT can be used in the')
+enum_w('/// window structure.')
+enum_w('enum {')
+
+local wv_val = 0
+
+for _, o in ipairs(options) do
+ assert(#o.scope == 1 or #o.scope == 2)
+ assert(#o.scope == 1 or o.scope[1] == 'global')
+ local min_scope = o.scope[#o.scope]
+ if min_scope == 'window' then
+ local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
+ local wv_name = 'WV_' .. varname:sub(3):upper()
+ enum_w((' %s = %u,'):format(wv_name, wv_val))
+ wv_val = wv_val + 1
+ end
+end
+
+enum_w((' WV_COUNT = %u, ///< must be the last one'):format(wv_val))
+enum_w('};')
+enum_w('')
+
--- @type { [string]: string }
local option_index = {}
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index e153b03bc1..3097853bea 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -11,10 +11,9 @@
#include "nvim/getchar_defs.h"
#include "nvim/iconv_defs.h"
#include "nvim/macros_defs.h"
-#include "nvim/mbyte.h"
#include "nvim/menu_defs.h"
#include "nvim/os/os_defs.h"
-#include "nvim/runtime.h"
+#include "nvim/runtime_defs.h"
#include "nvim/state_defs.h"
#include "nvim/syntax_defs.h"
#include "nvim/types_defs.h"
diff --git a/src/nvim/input.h b/src/nvim/input.h
index 3d948fa4ca..8741dafba4 100644
--- a/src/nvim/input.h
+++ b/src/nvim/input.h
@@ -1,6 +1,6 @@
#pragma once
-#include "nvim/event/multiqueue.h" // IWYU pragma: keep
+#include "nvim/event/defs.h" // IWYU pragma: keep
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "input.h.generated.h"
diff --git a/src/nvim/lua/executor.h b/src/nvim/lua/executor.h
index 0b4623cbd3..16fa5f8bc0 100644
--- a/src/nvim/lua/executor.h
+++ b/src/nvim/lua/executor.h
@@ -9,6 +9,7 @@
#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
#include "nvim/func_attr.h"
#include "nvim/macros_defs.h"
+#include "nvim/map_defs.h"
#include "nvim/types_defs.h"
#include "nvim/usercmd.h" // IWYU pragma: keep
diff --git a/src/nvim/option_vars.h b/src/nvim/option_vars.h
index cbdec2e0db..c3ab034c4c 100644
--- a/src/nvim/option_vars.h
+++ b/src/nvim/option_vars.h
@@ -779,156 +779,6 @@ EXTERN int p_wb; ///< 'writebackup'
EXTERN OptInt p_wd; ///< 'writedelay'
EXTERN int p_cdh; ///< 'cdhome'
-/// "indir" values for buffer-local options.
-/// These need to be defined globally, so that the BV_COUNT can be used with
-/// b_p_script_stx[].
-enum {
- BV_AI = 0,
- BV_AR,
- BV_BH,
- BV_BKC,
- BV_BT,
- BV_EFM,
- BV_GP,
- BV_MP,
- BV_BIN,
- BV_BL,
- BV_BOMB,
- BV_CHANNEL,
- BV_CI,
- BV_CIN,
- BV_CINK,
- BV_CINO,
- BV_CINW,
- BV_CINSD,
- BV_CM,
- BV_CMS,
- BV_COM,
- BV_CPT,
- BV_DICT,
- BV_TSR,
- BV_CSL,
- BV_CFU,
- BV_DEF,
- BV_INC,
- BV_EOF,
- BV_EOL,
- BV_FIXEOL,
- BV_EP,
- BV_ET,
- BV_FENC,
- BV_FP,
- BV_BEXPR,
- BV_FEX,
- BV_FF,
- BV_FLP,
- BV_FO,
- BV_FT,
- BV_IMI,
- BV_IMS,
- BV_INDE,
- BV_INDK,
- BV_INEX,
- BV_INF,
- BV_ISK,
- BV_KMAP,
- BV_KP,
- BV_LISP,
- BV_LOP,
- BV_LW,
- BV_MENC,
- BV_MA,
- BV_ML,
- BV_MOD,
- BV_MPS,
- BV_NF,
- BV_OFU,
- BV_PATH,
- BV_PI,
- BV_QE,
- BV_RO,
- BV_SCBK,
- BV_SI,
- BV_SMC,
- BV_SYN,
- BV_SPC,
- BV_SPF,
- BV_SPL,
- BV_SPO,
- BV_STS,
- BV_SUA,
- BV_SW,
- BV_SWF,
- BV_TFU,
- BV_TSRFU,
- BV_TAGS,
- BV_TC,
- BV_TS,
- BV_TW,
- BV_TX,
- BV_UDF,
- BV_UL,
- BV_WM,
- BV_VSTS,
- BV_VTS,
- BV_COUNT, // must be the last one
-};
-
-/// "indir" values for window-local options.
-/// These need to be defined globally, so that the WV_COUNT can be used in the
-/// window structure.
-enum {
- WV_LIST = 0,
- WV_ARAB,
- WV_COCU,
- WV_COLE,
- WV_CRBIND,
- WV_BRI,
- WV_BRIOPT,
- WV_DIFF,
- WV_FDC,
- WV_FEN,
- WV_FDI,
- WV_FDL,
- WV_FDM,
- WV_FML,
- WV_FDN,
- WV_FDE,
- WV_FDT,
- WV_FMR,
- WV_LBR,
- WV_NU,
- WV_RNU,
- WV_VE,
- WV_NUW,
- WV_PVW,
- WV_RL,
- WV_RLC,
- WV_SCBIND,
- WV_SCROLL,
- WV_SMS,
- WV_SISO,
- WV_SO,
- WV_SPELL,
- WV_CUC,
- WV_CUL,
- WV_CULOPT,
- WV_CC,
- WV_SBR,
- WV_STC,
- WV_STL,
- WV_WFH,
- WV_WFW,
- WV_WRAP,
- WV_SCL,
- WV_WINHL,
- WV_LCS,
- WV_FCS,
- WV_WINBL,
- WV_WBR,
- WV_COUNT, // must be the last one
-};
-
// Value for b_p_ul indicating the global value must be used.
#define NO_LOCAL_UNDOLEVEL (-123456)
diff --git a/src/nvim/viml/parser/expressions.h b/src/nvim/viml/parser/expressions.h
index 94287ea4e1..ff33b9ead1 100644
--- a/src/nvim/viml/parser/expressions.h
+++ b/src/nvim/viml/parser/expressions.h
@@ -8,8 +8,6 @@
#include "nvim/types_defs.h"
#include "nvim/viml/parser/parser.h"
-struct expr_ast_node;
-
// Defines whether to ignore case:
// == kCCStrategyUseOption
// ==# kCCStrategyMatchCase