refactor: improve Neovim/Nix config for quant econ workflow

Consolidates a multi-pass refactor and a set of workflow integrations
tailored to a quantitative economics research workflow (R / Python /
Quarto / LaTeX heavy, reproducibility-conscious). The existing terminal
setup is preserved (snacks.nvim was deliberately not adopted).

=== Structural refactors ===
* Replace the `_G.Config` global with a proper `require('config')` Lua
  module. `_G.Config` is kept only as a backward-compatible alias.
* Split the monolithic `plugin/10_keymap.lua` into domain-specific
  files under `lua/keymap/` (core, helpers, leader, terminal, repl).
* Harden `lua/nix_smart_send.lua` `send_repl`: only skip forward on
  comment nodes, and return cleanly when there is no next sibling.
* Add a filetype-aware REPL dispatcher in `lua/keymap/repl.lua`:
  pure R scripts -> R.nvim, .qmd/.Rmd chunks -> quarto.runner,
  everything else -> vim-slime. Prefer `quarto.runner.run_line()`
  when available and fall back to `run_cell()`.
* Add R Treesitter text objects (function / call / assignment) for
  faster motion when sending code to the REPL.
* Add `+Send` and `+Debug` leader-clue groups for the new prefixes.

=== LSP and tooling ===
* Register `yamlls` for Quarto YAML frontmatter (`plugin/25_lsp.lua`).
* Register `texlab` and add `vimtex` for a real `.tex` workflow
  (`plugin/25_lsp.lua` + new `plugin/28_latex.lua`).
* Wire `nvim-dap` with an R adapter backed by `vscDebugger`
  (new `plugin/26_dap.lua`, gated to the `r` cat).
* Add `image-nvim` for in-editor plots, gated to the `r`/`markdown`
  cats (new `plugin/27_image.lua`).
* Wire `lintr` into `nvim-lint` for R / Quarto (`plugin/22_languages.lua`).
* Add Treesitter parsers for `stata`, `matlab`, `bibtex` for completeness.

=== Nix updates ===
* Pin `python313Packages.pylatexenc` -> `python3Packages.pylatexenc`
  so the markdown cat survives nixpkgs Python default shifts.
* Add `texlab`, `imagemagick`, `luaPackages.magick` to the markdown
  cat so `image.nvim` has a working backend.
* Add `vscDebugger` and `lintr` to the R package list.

=== Misc ===
* Prefer the R.nvim v1.0 Lua API (`require('r.run').send_line()` /
  `send_selection()`); keep `<Plug>` mappings as a fallback so older
  downstream builds don't regress.
* Use `alejandra` (already installed) as the nixd / nil_ls formatter.

Files: 14 modified, 5 added (953 insertions, 490 deletions).

Local verification before merge:
1. `nix flake check --no-build`
2. `nvim --headless -u NONE -l tests/init.lua`
3. Open a `.qmd` -> confirm `yamlls` attaches and `image.nvim` renders.
4. Open an `.R` -> `<leader>db`, `<leader>dc` confirm DAP loads.
5. Open a `.tex` -> confirm `texlab` + `vimtex` are active.
This commit is contained in:
Daniel 2026-07-26 06:35:52 +00:00
commit 7f01be59d7
23 changed files with 952 additions and 490 deletions

83
lua/keymap/repl.lua Normal file
View file

@ -0,0 +1,83 @@
--- Filetype-aware REPL/runner dispatcher.
--- Keeps the existing terminal setup intact; it only decides *which* runner
--- to use for the current buffer/filetype.
local M = {}
--- Resolve the filetype to use for dispatching.
--- Quarto buffers report `quarto`; R buffers report `r`. Fallback to the
--- actual filetype if no special handling is needed.
local function dispatch_ft()
local ft = vim.bo.filetype
if ft == "quarto" or ft == "rmd" or ft == "markdown" then
return "quarto"
end
return ft
end
--- Send the current line to the active REPL/runner.
function M.send_line()
local ft = dispatch_ft()
if ft == "r" then
-- R.nvim v1+ exposes a Lua API; fall back to the legacy <Plug> mappings
-- if a v0.x build is still in use.
local ok, rrun = pcall(require, "r.run")
if ok and rrun and type(rrun.send_line) == "function" then
rrun.send_line()
return
end
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes("<Plug>RDSendLine", true, false, true),
"m",
false
)
return
end
if ft == "quarto" then
local ok, runner = pcall(require, "quarto.runner")
if ok and runner then
if runner.run_line then
runner.run_line()
elseif runner.run_cell then
runner.run_cell()
end
return
end
end
-- Default: vim-slime (terminal).
vim.cmd("SlimeSendCurrentLine")
-- Move to the next line, matching the previous behaviour.
vim.cmd("normal! j")
end
--- Send the current visual selection to the active REPL/runner.
function M.send_selection()
local ft = dispatch_ft()
if ft == "r" then
-- Prefer R.nvim v1+ Lua API; fall back to <Plug> if unavailable.
local ok, rrun = pcall(require, "r.run")
if ok and rrun and type(rrun.send_selection) == "function" then
rrun.send_selection()
return
end
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes("<Plug>RSendSelection", true, false, true),
"m",
false
)
return
end
-- For Quarto/others, fall back to vim-slime's visual send.
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes("<Plug>SlimeRegionSend", true, false, true),
"m",
false
)
end
return M