[feat] nvim: highlight lua codesnippets
All checks were successful
/ check (push) Successful in 29s
/ build (docs) (push) Successful in 2s
/ build (nixosConfigurations.vm.config.system.build.toplevel) (push) Successful in 24s
/ build (nvim) (push) Successful in 16s

Adding a comment with the language will automatically highlight the
code:

```nix
luaCode = /*lua*/ ''
    function() return "look ma I'm highlighted!" end
'';
```

(May only work using treesitter)
This commit is contained in:
Jalil David Salamé Messina 2024-07-02 09:29:44 +02:00
parent 351e042a7c
commit dc130e4723
Signed by: jalil
GPG key ID: F016B9E770737A0B
4 changed files with 227 additions and 103 deletions

View file

@ -12,28 +12,38 @@ in {
group = "highlightOnYank";
event = "TextYankPost";
pattern = "*";
callback = mkRaw ''
function()
vim.highlight.on_yank {
higroup = (
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
),
timeout = 200,
}
end
'';
callback =
mkRaw
/*
lua
*/
''
function()
vim.highlight.on_yank {
higroup = (
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
),
timeout = 200,
}
end
'';
}
{
group = "restoreCursorPosition";
event = "BufReadPost";
pattern = "*";
callback = mkRaw ''
function()
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
vim.cmd [[execute "normal! g'\""]]
callback =
mkRaw
/*
lua
*/
''
function()
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
vim.cmd [[execute "normal! g'\""]]
end
end
end
'';
'';
}
{
group = "lspConfig";
@ -42,7 +52,11 @@ in {
callback = let
opts = "noremap = true, buffer = bufnr";
in
mkRaw ''
mkRaw
/*
lua
*/
''
function(opts)
local bufnr = opts.buf
local client = vim.lsp.get_client_by_id(opts.data.client_id)