mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(image): skip \usepackage in comments and body (#2325)
## Description
Here are some small and hopefully uncontroversial tweaks to package
extraction from LaTeX preambles:
* Don't consider anything in comments
* Make sure that the extracted names are actually the arguments of
`\usepackage` and not some other macro on the same line
* Stop looking for packages at `\begin{document}`, where the preamble
ends and the body of the document begins (you can't load packages after
this, so any `\usepackage` beyond this point is content, not code. Also
saves a huge amount of work in large documents.)
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
parent
5ef4c0b421
commit
90227af497
1 changed files with 4 additions and 1 deletions
|
|
@ -128,12 +128,15 @@ function M.get_packages(buf)
|
|||
return M._cache(buf, "packages", function()
|
||||
local ret = {} ---@type string[]
|
||||
for _, line in ipairs(vim.api.nvim_buf_get_lines(buf, 0, -1, false)) do
|
||||
line = line:match("(.-)%%") or line
|
||||
if line:find("\\usepackage", 1, true) then
|
||||
for _, p in ipairs(vim.split(line:match("{(.-)}") or "", ",%s*")) do
|
||||
for _, p in ipairs(vim.split(line:match("\\usepackage.-{(.-)}") or "", ",%s*")) do
|
||||
if not vim.tbl_contains(ret, p) then
|
||||
ret[#ret + 1] = p
|
||||
end
|
||||
end
|
||||
elseif line:find("\\begin{document}", 1, true) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return ret
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue