Skip to content

Commit

Permalink
fix: enum_cyclic and enum_sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
monaqa committed Feb 16, 2022
1 parent 3390a2b commit 3b70b2a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lua/dial/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ function M.enum_sequence(tbl)
desc = {tbl.desc, "string", true},
ptn_format = {tbl.ptn_format, "string", true},
}
util.validate_list("enum_cyclic", tbl.strlist, "string", false)
local desc, strlist, ptn_format = tbl.desc, tbl.strlist, tbl.ptn_format

-- option 引数
if ptn_format == nil then
ptn_format = "\\C\\M\\<\\(%s\\)\\>"
ptn_format = [[\C\V\<\(%s\)\>]]
end
local vim_regex_ptn = ptn_format:format(table.concat(strlist, "\\|"))
local escapedlist = vim.tbl_map(
function (e)
return vim.fn.escape(e, [[/\]])
end,
strlist
)
local vim_regex_ptn = ptn_format:format(table.concat(escapedlist, [[\|]]))

if desc == nil then
desc = vim_regex_ptn
Expand All @@ -84,7 +91,7 @@ function M.enum_sequence(tbl)
n_ptnlst = #strlist
n = 1
for i, ptn in pairs(strlist) do
if text:find(ptn) ~= nil then
if text:find(ptn, 1, true) ~= nil then
n = i
end
end
Expand Down Expand Up @@ -114,9 +121,15 @@ function M.enum_cyclic(tbl)

-- option 引数
if ptn_format == nil then
ptn_format = "\\C\\M\\<\\(%s\\)\\>"
ptn_format = [[\C\V\<\(%s\)\>]]
end
local vim_regex_ptn = ptn_format:format(table.concat(strlist, "\\|"))
local escapedlist = vim.tbl_map(
function (e)
return vim.fn.escape(e, [[/\]])
end,
strlist
)
local vim_regex_ptn = ptn_format:format(table.concat(escapedlist, [[\|]]))

if desc == nil then
desc = vim_regex_ptn
Expand All @@ -128,7 +141,7 @@ function M.enum_cyclic(tbl)
n_ptnlst = #strlist
n = 1
for i, ptn in pairs(strlist) do
if text:find(ptn) ~= nil then
if text:find(ptn, 1, true) ~= nil then
n = i
end
end
Expand Down

0 comments on commit 3b70b2a

Please sign in to comment.