diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-03 22:51:45 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-09-06 17:19:07 -0700 |
commit | af946046b922dc5d5285a70a23d11916d8389a5d (patch) | |
tree | 090d68a1dd675b5ad6e99abc829be0daafe2a7d9 /runtime/lua/vim/shared.lua | |
parent | 638f2b6dee7439de303bea12dec80240617e8034 (diff) | |
download | rneovim-af946046b922dc5d5285a70a23d11916d8389a5d.tar.gz rneovim-af946046b922dc5d5285a70a23d11916d8389a5d.tar.bz2 rneovim-af946046b922dc5d5285a70a23d11916d8389a5d.zip |
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.
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 11 |
1 files changed, 11 insertions, 0 deletions
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, |