Enable searching home, project root, and file's directory for latexmkrc file#582
Merged
Conversation
…ory for latexmkrc file This change enables searching home directory, project root, and then file's directory for a ".latexmkrc" file. It does this in reverse of the stated order, so that the "most local" out_dir configuration stands.
PMassicotte
requested changes
May 21, 2026
Comment on lines
597
to
609
| for _, chkdir in pairs(chkdirs) do | ||
| if vim.fn.glob(chkdir .. "/.latexmkrc") ~= "" then | ||
| local ltxmk = vim.fn.readfile(vim.fn.expand(chkdir .. "/.latexmkrc")) | ||
| for _, line in ipairs(ltxmk) do | ||
| if | ||
| line:match('out_dir%s*=%s*"(.*)"') | ||
| or line:match("out_dir%s*=%s*'(.*)'") | ||
| then | ||
| vim.b.rplugin_pdfdir = line:match('out_dir%s*=%s*"(.*)"') | ||
| or line:match("out_dir%s*=%s*'(.*)'") | ||
| end | ||
| end | ||
| end |
Collaborator
There was a problem hiding this comment.
Suggested change
| for _, chkdir in pairs(chkdirs) do | |
| if vim.fn.glob(chkdir .. "/.latexmkrc") ~= "" then | |
| local ltxmk = vim.fn.readfile(vim.fn.expand(chkdir .. "/.latexmkrc")) | |
| for _, line in ipairs(ltxmk) do | |
| if | |
| line:match('out_dir%s*=%s*"(.*)"') | |
| or line:match("out_dir%s*=%s*'(.*)'") | |
| then | |
| vim.b.rplugin_pdfdir = line:match('out_dir%s*=%s*"(.*)"') | |
| or line:match("out_dir%s*=%s*'(.*)'") | |
| end | |
| end | |
| end | |
| for _, chkdir in ipairs(chkdirs) do | |
| local rcfile = vim.fn.expand(chkdir .. "/.latexmkrc") | |
| if vim.fn.glob(rcfile) ~= "" then | |
| for _, line in ipairs(vim.fn.readfile(rcfile)) do | |
| vim.b.rplugin_pdfdir = line:match('out_dir%s*=%s*"(.*)"') | |
| or line:match("out_dir%s*=%s*'(.*)'") | |
| or vim.b.rplugin_pdfdir | |
| end | |
| end | |
| end |
Collaborator
There was a problem hiding this comment.
Thank you for your contribution.
Two small things:
- I would use
ipairs - Collapsed the inner
ifinto a single assignment (the orgvim.b.rplugin_pdfdirgat the end preserves the current value when no match is found)
Contributor
Author
There was a problem hiding this comment.
I agree, ipairs does exactly what I intended (Thank you!) and the collapsed if is much better. I had simply left the existing logic thinking to minimize changes, but your version is so much cleaner.
Changes done. Thanks for the feedback/suggestions.
Collaborator
|
Note: the CI style errors are expected. |
Refactor loop to use ipairs for better behavior. Simplify the assignment of vim.b.rplugin_pdfdir.
Collaborator
|
All good on my side :) |
Member
Thank you, @PMassicotte and @todmorrison! I'm no longer using LaTeX or Rnoweb to try the pull request carefully. Merging it now... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change enables searching home directory, cwd (typically the project root), and then file's directory for a ".latexmkrc" file. It does this in reverse of the stated order, so that the "most local" 'out_dir' configuration stands.