From ef6ee3d9afcb4c6b3e607a5ffcb1fb9c13234d9f Mon Sep 17 00:00:00 2001 From: Tod Morrison Date: Wed, 20 May 2026 18:39:44 -0600 Subject: [PATCH 1/2] Enable searching home directory, project root, and then file's directory 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. --- lua/r/rnw.lua | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lua/r/rnw.lua b/lua/r/rnw.lua index 04e31f96..822d1407 100644 --- a/lua/r/rnw.lua +++ b/lua/r/rnw.lua @@ -592,14 +592,20 @@ M.set_pdf_dir = function() vim.b.rplugin_pdfdir = "." -- Latexmk has an option to create the PDF in a directory other than '.' - if config.latexcmd and (vim.fn.glob("~/.latexmkrc") ~= "") == 1 then - local ltxmk = vim.fn.readfile(vim.fn.expand("~/.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*'(.*)'") + if config.latexcmd then + local chkdirs = { "~", ".", vim.fn.expand("%:p:h") } + 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 end end From c7df89901731606651eece9535ccdced830888f3 Mon Sep 17 00:00:00 2001 From: Tod Morrison Date: Thu, 21 May 2026 12:01:04 -0600 Subject: [PATCH 2/2] Refactor directory check and simplify PDF dir assignment Refactor loop to use ipairs for better behavior. Simplify the assignment of vim.b.rplugin_pdfdir. --- lua/r/rnw.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lua/r/rnw.lua b/lua/r/rnw.lua index 822d1407..c9c927a5 100644 --- a/lua/r/rnw.lua +++ b/lua/r/rnw.lua @@ -594,17 +594,13 @@ M.set_pdf_dir = function() -- Latexmk has an option to create the PDF in a directory other than '.' if config.latexcmd then local chkdirs = { "~", ".", vim.fn.expand("%:p:h") } - for _, chkdir in pairs(chkdirs) do + for _, chkdir in ipairs(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*"(.*)"') + vim.b.rplugin_pdfdir = 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 + or vim.b.rplugin_pdfdir end end end