diff --git a/fnl/hotpot/loader/record/runtime.fnl b/fnl/hotpot/loader/record/runtime.fnl index 8e061216..e5ffd4c0 100644 --- a/fnl/hotpot/loader/record/runtime.fnl +++ b/fnl/hotpot/loader/record/runtime.fnl @@ -18,7 +18,12 @@ ;; Convert /a/b/c/nvim/ftplugin/x.fnl into ;; /a/b/c/nvim/ <- context, the last path section defines our namespace ;; ftplugin/x.fnl <- inside context - context-pattern (fmt "(%s/%s%%.%s)$" runtime-type modname-suffix ext) + context-pattern (fmt "(%s/%s%%.%s)$" + runtime-type + ;; escape regex pattern, e.g. plugin/x-y%.fnl -> plugin/x%-y%.fnl, + ;; this is identical to vim.pesc except we preserve any '.' in the pattern. + (string.gsub modname-suffix "[%(%)%%%+%-%*%?%[%]%^%$]" "%%%1") + ext) path-inside-context-dir (string.match src-path context-pattern) path-to-context-dir (string.sub src-path 1 (* -1 (+ (length path-inside-context-dir) 1))) ;; ftplugin/y.fnl -> lua/hotpot-runtime-ftplugin/y.lua diff --git a/lua/hotpot/loader/record/runtime.lua b/lua/hotpot/loader/record/runtime.lua index 6deea226..d763b879 100644 --- a/lua/hotpot/loader/record/runtime.lua +++ b/lua/hotpot/loader/record/runtime.lua @@ -27,7 +27,7 @@ local function new(modname_suffix, src_path, opts) true_modname = (modname_suffix .. _5_()) local runtime_mod_prefix = fmt("hotpot-runtime-%s", runtime_type) local modname = fmt("%s.%s", runtime_mod_prefix, modname_suffix) - local context_pattern = fmt("(%s/%s%%.%s)$", runtime_type, modname_suffix, ext) + local context_pattern = fmt("(%s/%s%%.%s)$", runtime_type, string.gsub(modname_suffix, "[%(%)%%%+%-%*%?%[%]%^%$]", "%%%1"), ext) local path_inside_context_dir = string.match(src_path0, context_pattern) local path_to_context_dir = string.sub(src_path0, 1, (-1 * (#path_inside_context_dir + 1))) local lua_code_path = string.gsub(string.gsub(path_inside_context_dir, ("^" .. vim.pesc(runtime_type)), join_path("lua", runtime_mod_prefix)), "fnl$", "lua") @@ -55,4 +55,4 @@ local function new(modname_suffix, src_path, opts) end return record end -return {new = new} \ No newline at end of file +return {new = new} diff --git a/test/test-nvim-runtime.fnl b/test/test-nvim-runtime.fnl index 2bcec43a..fc39204e 100644 --- a/test/test-nvim-runtime.fnl +++ b/test/test-nvim-runtime.fnl @@ -14,7 +14,7 @@ (values fnl-path lua-path))) (local (plugin-path-1 lua-path-1) (make-plugin :my_plugin_1)) -(local (plugin-path-2 lua-path-2) (make-plugin :nested/deeply/my_plugin_2)) +(local (plugin-path-2 lua-path-2) (make-plugin :nested/deeply/my-plugin-2)) (local (plugin-path-3 lua-path-3) (make-plugin :init)) (local (plugin-path-4 lua-path-4) (make-plugin :init/init.fnl)) (local lua-paths [lua-path-1 lua-path-2 lua-path-3 lua-path-4])