Refactor: Add parsers.get_buf_lang

This commit is contained in:
Stephan Seitz 2020-07-10 21:47:50 +02:00 committed by Thomas Vigouroux
parent 1849f30bb5
commit a4e2692c7b
5 changed files with 18 additions and 11 deletions

View file

@ -257,14 +257,14 @@ end
function M.has_parser(lang)
local buf = api.nvim_get_current_buf()
local lang = lang or M.ft_to_lang(api.nvim_buf_get_option(buf, 'ft'))
local lang = M.get_buf_lang(buf) or lang
if not lang or #lang == 0 then return false end
return #api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) > 0
end
function M.get_parser(bufnr, lang)
local buf = bufnr or api.nvim_get_current_buf()
local lang = lang or M.ft_to_lang(api.nvim_buf_get_option(buf, 'ft'))
local lang = lang or M.get_buf_lang(buf)
if M.has_parser(lang) then
if not M[buf] then
@ -277,4 +277,12 @@ function M.get_parser(bufnr, lang)
end
end
-- get language of given buffer
-- @param optional buffer number or current buffer
-- @returns language string of buffer
function M.get_buf_lang(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
return M.ft_to_lang(api.nvim_buf_get_option(bufnr, "ft"))
end
return M