Skip to content

Commit

Permalink
Move from escape function to vim.pesc (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Tylor <alex@tylor.co.uk>
  • Loading branch information
b3nj5m1n and terrortylor authored Mar 28, 2021
1 parent 1c1668d commit 8026704
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions lua/nvim_comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ M.config = {
operator_mapping = "gc"
}

function M.escape(x)
return (x:gsub('%%', '%%%%')
:gsub('%^', '%%^')
:gsub('%$', '%%$')
:gsub('%(', '%%(')
:gsub('%)', '%%)')
:gsub('%.', '%%.')
:gsub('%[', '%%[')
:gsub('%]', '%%]')
:gsub('%*', '%%*')
:gsub('%+', '%%+')
:gsub('%-', '%%-')
:gsub('%?', '%%?'))
end

function M.get_comment_wrapper()
local cs = api.nvim_buf_get_option(0, 'commentstring')

Expand Down Expand Up @@ -77,10 +62,10 @@ end
function M.uncomment_line(l, left, right)
local line = l
if right ~= '' then
local esc_right = M.escape(right)
local esc_right = vim.pesc(right)
line = line:gsub(esc_right .. '$', '')
end
local esc_left = M.escape(left)
local esc_left = vim.pesc(left)
line = line:gsub(esc_left, '', 1)

return line
Expand Down Expand Up @@ -111,7 +96,7 @@ function M.comment_toggle(line_start, line_end)
if not lines then return end

-- check if any lines commented, capture indent
local esc_left = M.escape(left)
local esc_left = vim.pesc(left)
local commented_lines_counter = 0
local empty_counter = 0
local indent
Expand Down Expand Up @@ -177,4 +162,4 @@ function M.setup(user_opts)
end
end

return M
return M

0 comments on commit 8026704

Please sign in to comment.