fix(nvim): simplify preview.nvim config

This commit is contained in:
Barrett Ruth 2026-03-05 22:36:35 -05:00
parent 1e3d0fa577
commit 5c4fb10596
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
4 changed files with 97 additions and 0 deletions

View file

@ -34,6 +34,16 @@
pkgs.selene
pkgs.lua-language-server
];
okular-wrapped = pkgs.symlinkJoin {
name = "okular";
paths = [ pkgs.kdePackages.okular ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/okular \
--prefix XDG_DATA_DIRS : "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}" \
--prefix XDG_DATA_DIRS : "${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}"
'';
};
in
{
default = pkgs.mkShell {
@ -51,6 +61,7 @@
pkgs.mermaid-cli
pkgs.zathura
pkgs.sioyek
okular-wrapped
];
};
}

38
spec/synctex_okular.lua Normal file
View file

@ -0,0 +1,38 @@
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.opt.runtimepath:append('.')
vim.opt.packpath = {}
vim.opt.loadplugins = false
require('preview.commands').setup()
vim.fn.serverstart('/tmp/nvim-preview.sock')
local synctex_pdf = {}
vim.api.nvim_create_autocmd('User', {
pattern = 'PreviewCompileSuccess',
callback = function(args)
synctex_pdf[args.data.bufnr] = args.data.output
end,
})
vim.g.preview = {
latex = {
open = { 'okular', '--unique' },
output = function(ctx)
return vim.fn.fnamemodify(ctx.file, ':h')
.. '/build/'
.. vim.fn.fnamemodify(ctx.file, ':t:r')
.. '.pdf'
end,
},
}
vim.keymap.set('n', '<leader>s', function()
local pdf = synctex_pdf[vim.api.nvim_get_current_buf()]
if pdf then
vim.fn.jobstart({
'okular', '--unique',
('%s#src:%d:%s'):format(pdf, vim.fn.line('.'), vim.fn.expand('%:p')),
})
end
end)

42
spec/synctex_sioyek.lua Normal file
View file

@ -0,0 +1,42 @@
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.opt.runtimepath:append('.')
vim.opt.packpath = {}
vim.opt.loadplugins = false
require('preview.commands').setup()
vim.fn.serverstart('/tmp/nvim-preview.sock')
local synctex_pdf = {}
vim.api.nvim_create_autocmd('User', {
pattern = 'PreviewCompileSuccess',
callback = function(args)
synctex_pdf[args.data.bufnr] = args.data.output
end,
})
vim.g.preview = {
latex = {
open = { 'sioyek', '--instance-name', 'preview' },
output = function(ctx)
return vim.fn.fnamemodify(ctx.file, ':h')
.. '/build/'
.. vim.fn.fnamemodify(ctx.file, ':t:r')
.. '.pdf'
end,
},
}
vim.keymap.set('n', '<leader>s', function()
local pdf = synctex_pdf[vim.api.nvim_get_current_buf()]
if pdf then
vim.fn.jobstart({
'sioyek',
'--instance-name', 'preview',
'--reuse-window',
'--forward-search-file', vim.fn.expand('%:p'),
'--forward-search-line', tostring(vim.fn.line('.')),
pdf,
})
end
end)

View file

@ -23,6 +23,12 @@ vim.g.preview = {
'nvim --server /tmp/nvim-preview.sock'
.. [[ --remote-expr "execute('b +%{line} %{input}')"]],
},
output = function(ctx)
return vim.fn.fnamemodify(ctx.file, ':h')
.. '/build/'
.. vim.fn.fnamemodify(ctx.file, ':t:r')
.. '.pdf'
end,
},
}