diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /src/nvim/generators/gen_options.lua | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'src/nvim/generators/gen_options.lua')
-rw-r--r-- | src/nvim/generators/gen_options.lua | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index edb7dae159..26ade2745d 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -1,14 +1,6 @@ -if arg[1] == '--help' then - print('Usage: genoptions.lua src/nvim options_file') - os.exit(0) -end - -local nvimsrcdir = arg[1] -local options_file = arg[2] - -package.path = nvimsrcdir .. '/?.lua;' .. package.path +local options_file = arg[1] -local opt_fd = io.open(options_file, 'w') +local opt_fd = assert(io.open(options_file, 'w')) local w = function(s) if s:match('^ %.') then @@ -18,6 +10,7 @@ local w = function(s) end end +--- @module 'nvim.options' local options = require('options') local cstr = options.cstr @@ -42,11 +35,16 @@ local redraw_flags={ local list_flags={ comma='P_COMMA', onecomma='P_ONECOMMA', + commacolon='P_COMMA|P_COLON', + onecommacolon='P_ONECOMMA|P_COLON', flags='P_FLAGLIST', flagscomma='P_COMMA|P_FLAGLIST', } -local get_flags = function(o) +--- @param o vim.option_meta +--- @return string +local function get_flags(o) + --- @type string[] local ret = {type_flags[o.type]} local add_flag = function(f) ret[1] = ret[1] .. '|' .. f @@ -89,8 +87,10 @@ local get_flags = function(o) return ret[1] end -local get_cond -get_cond = function(c, base_string) +--- @param c string|string[] +--- @param base_string? string +--- @return string +local function get_cond(c, base_string) local cond_string = base_string or '#if ' if type(c) == 'table' then cond_string = cond_string .. get_cond(c[1], '') @@ -112,11 +112,11 @@ local value_dumpers = { string=cstr, boolean=function(v) return v and 'true' or 'false' end, number=function(v) return ('%iL'):format(v) end, - ['nil']=function(_) return '0L' end, + ['nil']=function(_) return '0' end, } local get_value = function(v) - return '(char *) ' .. value_dumpers[type(v)](v) + return '(void *) ' .. value_dumpers[type(v)](v) end local get_defaults = function(d,n) @@ -126,9 +126,12 @@ local get_defaults = function(d,n) return get_value(d) end +--- @type {[1]:string,[2]:string}[] local defines = {} -local dump_option = function(i, o) +--- @param i integer +--- @param o vim.option_meta +local function dump_option(i, o) w(' [' .. ('%u'):format(i - 1) .. ']={') w(' .fullname=' .. cstr(o.full_name)) if o.abbreviation then @@ -139,10 +142,14 @@ local dump_option = function(i, o) w(get_cond(o.enable_if)) end if o.varname then - w(' .var=(char_u *)&' .. o.varname) + w(' .var=&' .. o.varname) + -- Immutable options should directly point to the default value + elseif o.immutable then + w((' .var=&options[%u].def_val'):format(i - 1)) elseif #o.scope == 1 and o.scope[1] == 'window' then w(' .var=VAR_WIN') end + w(' .immutable=' .. (o.immutable and 'true' or 'false')) if #o.scope == 1 and o.scope[1] == 'global' then w(' .indir=PV_NONE') else @@ -162,6 +169,12 @@ local dump_option = function(i, o) table.insert(defines, { 'PV_' .. varname:sub(3):upper() , pv_name}) w(' .indir=' .. pv_name) end + if o.cb then + w(' .opt_did_set_cb=' .. o.cb) + end + if o.expand_cb then + w(' .opt_expand_cb=' .. o.expand_cb) + end if o.enable_if then w('#else') w(' .var=NULL') @@ -184,7 +197,19 @@ local dump_option = function(i, o) w(' },') end -w('static vimoption_T options[] = {') +w([[ +#include "nvim/ex_getln.h" +#include "nvim/insexpand.h" +#include "nvim/mapping.h" +#include "nvim/ops.h" +#include "nvim/option.h" +#include "nvim/optionstr.h" +#include "nvim/quickfix.h" +#include "nvim/runtime.h" +#include "nvim/tag.h" +#include "nvim/window.h" + +static vimoption_T options[] = {]]) for i, o in ipairs(options.options) do dump_option(i, o) end |