From a34cc1a44de75eff4c6b43f983dc983eb283119d Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 8 Dec 2023 12:36:37 +0600 Subject: refactor(options): define `kOptIndexCount` Add a macro to indicate the option count so that we can iterate through the options[] table more clearly. This also removes the need for having an option with NULL fullname at the end of `options[]`. --- src/nvim/generators/gen_options.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 7c5fc08129..b7356a7bb1 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -44,8 +44,8 @@ local list_flags = { --- @param s string --- @return string -local title_case = function(s) - return s:sub(1, 1):upper() .. s:sub(2):lower() +local lowercase_to_titlecase = function(s) + return s:sub(1, 1):upper() .. s:sub(2) end --- @param o vim.option_meta @@ -229,7 +229,6 @@ static vimoption_T options[] = {]]) for i, o in ipairs(options.options) do dump_option(i, o) end -w(' [' .. ('%u'):format(#options.options) .. ']={.fullname=NULL}') w('};') w('') @@ -242,9 +241,13 @@ opt_fd = assert(io.open(options_enum_file, 'w')) w('typedef enum {') w(' kOptInvalid = -1,') + for i, o in ipairs(options.options) do - w((' kOpt%s = %u,'):format(title_case(o.full_name), i - 1)) + w((' kOpt%s = %u,'):format(lowercase_to_titlecase(o.full_name), i - 1)) end + +w(' // Option count, used when iterating through options') +w('#define kOptIndexCount ' .. tostring(#options.options)) w('} OptIndex;') opt_fd:close() -- cgit