From af946046b922dc5d5285a70a23d11916d8389a5d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Sep 2019 22:51:45 +0200 Subject: test: Rename meth_pcall to pcall_err - Rename `meth_pcall`. - Make `pcall_err` raise an error if the function does not fail. - Add `vim.pesc()` to treat a string as literal where a Lua pattern is expected. --- runtime/lua/vim/shared.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'runtime/lua/vim/shared.lua') diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 75d4a6eee6..cd6f8a04d8 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -178,9 +178,20 @@ local function trim(s) return s:match('^%s*(.*%S)') or '' end +--- Escapes magic chars in a Lua pattern string. +--- +--@see https://github.com/rxi/lume +--@param s String to escape +--@returns %-escaped pattern string +local function pesc(s) + assert(type(s) == 'string') + return s:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', '%%%1') +end + local module = { deepcopy = deepcopy, gsplit = gsplit, + pesc = pesc, split = split, tbl_contains = tbl_contains, tbl_extend = tbl_extend, -- cgit