Sonic-Pi send visual selection and integration, luasnip TAB jumps insert positions

This commit is contained in:
2024-10-30 20:40:56 +01:00
parent 9a0c3a4ca2
commit 67dafbaf6c
5 changed files with 26 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
-- load configurations files from lua/* -- load configurations files from lua/*
require('options') require('options')
require('functions')
require('plugins') require('plugins')
require('colorscheme') require('colorscheme')
require('lsp') require('lsp')

View File

@@ -33,6 +33,8 @@ cmp.setup({
-- Hint: if the completion menu is visible select next one -- Hint: if the completion menu is visible select next one
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.jumpable(1) then
luasnip.jump(1)
elseif has_words_before() then elseif has_words_before() then
cmp.complete() cmp.complete()
else else

15
lua/functions.lua Normal file
View File

@@ -0,0 +1,15 @@
-- custom defined functions
-- Return the currently, visually selected text range
function SL_get_visual_selection()
vim.cmd([[ execute "normal! \<ESC>" ]])
local s_start = vim.fn.getcharpos("'<")
local s_end = vim.fn.getcharpos("'>")
vim.cmd([[ execute "normal! gv" ]])
local current_buffer = vim.api.nvim_get_current_buf()
local r = vim.api.nvim_buf_get_text(current_buffer, s_start[2] - 1, s_start[3] - 1,
s_end[2] - 1, s_end[3], {})
-- print("region might be", current_buffer, s_start[2], s_start[3], s_end[2], s_end[3])
return table.concat(r, "\n")
end

View File

@@ -90,7 +90,7 @@ require('mason-lspconfig').setup_handlers({
on_attach = on_attach, on_attach = on_attach,
config = { config = {
on_init = function(client) on_init = function(client)
require('sonicpi').lsp_on_init(client, { server_dir = '/opt/sonic-pi/app/server' }) require('sonicpi').lsp_on_init(client, {})
end end
}, },
filetypes = { 'ruby', 'sonicpi' }, filetypes = { 'ruby', 'sonicpi' },

View File

@@ -447,13 +447,12 @@ require("lazy").setup({
end, end,
}, },
-- -- Live Coding: sonic-pi music programming -- Live Coding: sonic-pi music programming
{ {
'magicmonty/sonicpi.nvim', 'magicmonty/sonicpi.nvim',
-- broken if used here, setup called further below
config = function() config = function()
require('sonicpi').setup({ require('sonicpi').setup({
server_dir = '/opt/sonic-pi/app/server', -- server_dir = '/opt/sonic-pi/app/server',
lsp_diagnostics = true, lsp_diagnostics = true,
mappings = { mappings = {
{ 'n', '<leader>d', ':SonicPiStartDaemon<CR>', { desc = 'Sonic Pi: start daemon' } }, { 'n', '<leader>d', ':SonicPiStartDaemon<CR>', { desc = 'Sonic Pi: start daemon' } },
@@ -463,8 +462,11 @@ require("lazy").setup({
{ 'i', '<M-r>', require('sonicpi.remote').run_current_buffer, { desc = 'Sonic Pi: run' } }, { 'i', '<M-r>', require('sonicpi.remote').run_current_buffer, { desc = 'Sonic Pi: run' } },
{ 'n', '<leader>R', ':SonicPiSendBuffer<CR>', { desc = 'Sonic Pi: send buffer' } }, { 'n', '<leader>R', ':SonicPiSendBuffer<CR>', { desc = 'Sonic Pi: send buffer' } },
{ 'i', '<M-R>', ':SonicPiSendBuffer<CR>', { desc = 'Sonic Pi: send buffer' } }, { 'i', '<M-R>', ':SonicPiSendBuffer<CR>', { desc = 'Sonic Pi: send buffer' } },
-- // TODO.2024-10-29 implement sending of tree-sitter node { 'v', '<leader>s', require('sonicpi.remote').stop, { desc = 'Sonic Pi: stop' } },
{ 'n', '<C-H>', function() end, { desc = 'Sonic Pi: send current' } }, { 'v', '<leader>v',
function()
require('sonicpi.remote').run_code(SL_get_visual_selection())
end, { desc = 'Sonic Pi: send visual range' } }
}, },
single_file = true, single_file = true,
}) })