mirror of
https://github.com/dwinkler1/nvimConfig.git
synced 2026-08-22 17:43:13 -04:00
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:
parent
0ea9b249ed
commit
7f01be59d7
23 changed files with 952 additions and 490 deletions
|
|
@ -1,3 +1,5 @@
|
|||
local Config = require('config')
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Configuration
|
||||
|
|
@ -31,11 +33,15 @@ function M.split_and_open_terminal()
|
|||
vim.cmd("resize " .. math.floor(vim.fn.winheight(0) * 0.9))
|
||||
local term_buf = vim.api.nvim_win_get_buf(vim.api.nvim_get_current_win())
|
||||
M.opt_term = term_buf
|
||||
|
||||
|
||||
-- Set buffer-local variables for vim-slime
|
||||
local job_id = vim.b[term_buf].terminal_job_id
|
||||
if not job_id then
|
||||
vim.notify("Terminal job id not available", vim.log.levels.WARN)
|
||||
return term_buf
|
||||
end
|
||||
vim.b[term_buf].slime_config = { jobid = job_id }
|
||||
|
||||
|
||||
return M.opt_term
|
||||
end
|
||||
|
||||
|
|
@ -44,26 +50,45 @@ function M.open_in_terminal(cmd)
|
|||
local command = cmd or ""
|
||||
local current_window = vim.api.nvim_get_current_win()
|
||||
local code_buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
|
||||
if not vim.api.nvim_buf_is_valid(code_buf) then
|
||||
vim.notify("Code buffer is not valid", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
-- Open terminal and get buffer
|
||||
local term_buf = M.split_and_open_terminal()
|
||||
|
||||
|
||||
if not term_buf or not vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.notify("Failed to open terminal buffer", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
-- Send command if provided
|
||||
local job_id = vim.b[term_buf].terminal_job_id
|
||||
if command ~= "" then
|
||||
-- We can use standard slime sending if needed, or direct chan_send for initialization
|
||||
local job_id = vim.b[term_buf].terminal_job_id
|
||||
if job_id then
|
||||
vim.api.nvim_chan_send(job_id, command .. "\r")
|
||||
if not job_id then
|
||||
vim.notify("Terminal job not ready, cannot send command", vim.log.levels.WARN)
|
||||
else
|
||||
local ok, err = pcall(vim.api.nvim_chan_send, job_id, command .. "\r")
|
||||
if not ok then
|
||||
vim.notify("Failed to send command to terminal: " .. tostring(err), vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Configure slime for the ORIGINAL code buffer to point to this new terminal
|
||||
-- This makes "Send to Terminal" work immediately
|
||||
local slime_config = { jobid = vim.b[term_buf].terminal_job_id }
|
||||
|
||||
-- Fix: Set the variable on the captured code buffer, not the current (terminal) buffer
|
||||
vim.api.nvim_buf_set_var(code_buf, "slime_config", slime_config)
|
||||
|
||||
if job_id then
|
||||
local slime_config = { jobid = job_id }
|
||||
|
||||
-- Fix: Set the variable on the captured code buffer, not the current (terminal) buffer
|
||||
local ok, err = pcall(vim.api.nvim_buf_set_var, code_buf, "slime_config", slime_config)
|
||||
if not ok then
|
||||
vim.notify("Failed to set slime_config on code buffer: " .. tostring(err), vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
-- Switch back to code buffer
|
||||
vim.api.nvim_set_current_win(current_window)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue