mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
gen_ex_cmds: simplify writes to defsfile (#13096)
defsfile:write() is executed multiple times to append strings. Some of these can be combined into a format string, wrapped in [[]]. It is easier to read and insert strings via "%s". defsfile now has a trailing comma for "cmdnames" array but it does not break the build.
This commit is contained in:
@@ -24,8 +24,6 @@ local defsfile = io.open(defsfname, 'w')
|
|||||||
|
|
||||||
local defs = require('ex_cmds')
|
local defs = require('ex_cmds')
|
||||||
|
|
||||||
local first = true
|
|
||||||
|
|
||||||
local byte_a = string.byte('a')
|
local byte_a = string.byte('a')
|
||||||
local byte_z = string.byte('z')
|
local byte_z = string.byte('z')
|
||||||
local a_to_z = byte_z - byte_a + 1
|
local a_to_z = byte_z - byte_a + 1
|
||||||
@@ -42,7 +40,6 @@ static const uint16_t cmdidxs1[%u] = {
|
|||||||
local cmdidxs2_out = string.format([[
|
local cmdidxs2_out = string.format([[
|
||||||
static const char_u cmdidxs2[%u][%u] = {
|
static const char_u cmdidxs2[%u][%u] = {
|
||||||
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */
|
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */
|
||||||
|
|
||||||
]], a_to_z, a_to_z)
|
]], a_to_z, a_to_z)
|
||||||
|
|
||||||
enumfile:write([[
|
enumfile:write([[
|
||||||
@@ -50,10 +47,8 @@ typedef enum CMD_index {
|
|||||||
]])
|
]])
|
||||||
defsfile:write(string.format([[
|
defsfile:write(string.format([[
|
||||||
static const int command_count = %u;
|
static const int command_count = %u;
|
||||||
]], #defs))
|
|
||||||
defsfile:write(string.format([[
|
|
||||||
static CommandDefinition cmdnames[%u] = {
|
static CommandDefinition cmdnames[%u] = {
|
||||||
]], #defs))
|
]], #defs, #defs))
|
||||||
local cmds, cmdidxs1, cmdidxs2 = {}, {}, {}
|
local cmds, cmdidxs1, cmdidxs2 = {}, {}, {}
|
||||||
for _, cmd in ipairs(defs) do
|
for _, cmd in ipairs(defs) do
|
||||||
local enumname = cmd.enum or ('CMD_' .. cmd.command)
|
local enumname = cmd.enum or ('CMD_' .. cmd.command)
|
||||||
@@ -61,11 +56,6 @@ for _, cmd in ipairs(defs) do
|
|||||||
if byte_a <= byte_cmd and byte_cmd <= byte_z then
|
if byte_a <= byte_cmd and byte_cmd <= byte_z then
|
||||||
table.insert(cmds, cmd.command)
|
table.insert(cmds, cmd.command)
|
||||||
end
|
end
|
||||||
if first then
|
|
||||||
first = false
|
|
||||||
else
|
|
||||||
defsfile:write(',\n')
|
|
||||||
end
|
|
||||||
enumfile:write(' ' .. enumname .. ',\n')
|
enumfile:write(' ' .. enumname .. ',\n')
|
||||||
defsfile:write(string.format([[
|
defsfile:write(string.format([[
|
||||||
[%s] = {
|
[%s] = {
|
||||||
@@ -73,7 +63,8 @@ for _, cmd in ipairs(defs) do
|
|||||||
.cmd_func = (ex_func_T)&%s,
|
.cmd_func = (ex_func_T)&%s,
|
||||||
.cmd_argt = %uL,
|
.cmd_argt = %uL,
|
||||||
.cmd_addr_type = %i
|
.cmd_addr_type = %i
|
||||||
}]], enumname, cmd.command, cmd.func, cmd.flags, cmd.addr_type))
|
},
|
||||||
|
]], enumname, cmd.command, cmd.func, cmd.flags, cmd.addr_type))
|
||||||
end
|
end
|
||||||
for i = #cmds, 1, -1 do
|
for i = #cmds, 1, -1 do
|
||||||
local cmd = cmds[i]
|
local cmd = cmds[i]
|
||||||
@@ -104,15 +95,14 @@ for i = byte_a, byte_z do
|
|||||||
end
|
end
|
||||||
cmdidxs2_out = cmdidxs2_out .. ' },\n'
|
cmdidxs2_out = cmdidxs2_out .. ' },\n'
|
||||||
end
|
end
|
||||||
defsfile:write([[
|
|
||||||
|
|
||||||
};
|
|
||||||
]])
|
|
||||||
enumfile:write([[
|
enumfile:write([[
|
||||||
CMD_SIZE,
|
CMD_SIZE,
|
||||||
CMD_USER = -1,
|
CMD_USER = -1,
|
||||||
CMD_USER_BUF = -2
|
CMD_USER_BUF = -2
|
||||||
} cmdidx_T;
|
} cmdidx_T;
|
||||||
]])
|
]])
|
||||||
defsfile:write(cmdidxs1_out .. '};\n')
|
defsfile:write(string.format([[
|
||||||
defsfile:write(cmdidxs2_out .. '};\n')
|
};
|
||||||
|
%s};
|
||||||
|
%s};
|
||||||
|
]], cmdidxs1_out, cmdidxs2_out))
|
||||||
|
Reference in New Issue
Block a user