From 63507160ce1fe13cc0a74f0b64db47f67f1c065f Mon Sep 17 00:00:00 2001 From: tiyn Date: Sat, 14 Mar 2026 09:22:36 +0100 Subject: [PATCH] nvim: added lilypond support --- .config/nvim/after/ftplugin/lilypond.lua | 57 +++++++++++++++++++ .config/nvim/lua/plugins/nvim-cmp.lua | 4 +- .../nvim/lua/plugins/nvim-lilypond-suite.lua | 47 +++++++++++++++ .local/bin/etc/nvim/compiler | 1 + 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 .config/nvim/after/ftplugin/lilypond.lua create mode 100644 .config/nvim/lua/plugins/nvim-lilypond-suite.lua diff --git a/.config/nvim/after/ftplugin/lilypond.lua b/.config/nvim/after/ftplugin/lilypond.lua new file mode 100644 index 0000000..9f85188 --- /dev/null +++ b/.config/nvim/after/ftplugin/lilypond.lua @@ -0,0 +1,57 @@ +local wk = require("which-key") + +local fluidsynth_job = nil + +-- setup interactive midi player +wk.add({ + { mode = "n", "p", desc = "Lilypond: output" }, + { + mode = "n", + "pm", + function() + local midi = vim.fn.expand("%:r") .. ".midi" + + if fluidsynth_job then + vim.fn.jobstop(fluidsynth_job) + fluidsynth_job = nil + print("fluidsynth stopped") + return + end + + fluidsynth_job = vim.fn.jobstart({ "fluidsynth", "-i", midi }) + print("fluidsynth playing (Ctrl-C to stop)") + end, + desc = "Lilypond: output MIDI", + buffer = true, + }, + { + mode = "n", + "pp", + "Viewer", + desc = "Lilypond: open PDF", + buffer = true, + }, + { + mode = "n", + "", + function() + if fluidsynth_job then + vim.fn.jobstop(fluidsynth_job) + fluidsynth_job = nil + print("fluidsynth stopped") + else + vim.cmd("normal! ") + end + end, + desc = "Stop MIDI playback", + buffer = true, + }, +}) + +-- autostart +if vim.b.first_start_lilypond then + return +end +vim.b.first_start_lilypond = true + +vim.cmd.Viewer() diff --git a/.config/nvim/lua/plugins/nvim-cmp.lua b/.config/nvim/lua/plugins/nvim-cmp.lua index 866f918..e99c68e 100644 --- a/.config/nvim/lua/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/plugins/nvim-cmp.lua @@ -8,6 +8,7 @@ return { -- cmp sources 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', + 'uga-rosa/cmp-dictionary', 'lukas-reineke/cmp-under-comparator', -- luasnip { @@ -69,7 +70,8 @@ return { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, - { name = 'buffer' } + { name = 'buffer' }, + { name = 'dictionary' } }, formatting = { format = require("lspkind").cmp_format({ diff --git a/.config/nvim/lua/plugins/nvim-lilypond-suite.lua b/.config/nvim/lua/plugins/nvim-lilypond-suite.lua new file mode 100644 index 0000000..a3c6b74 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lilypond-suite.lua @@ -0,0 +1,47 @@ +return { + "martineausimon/nvim-lilypond-suite", + dependencies = "uga-rosa/cmp-dictionary", + config = function() + require("nvls").setup({ + lilypond = { + mappings = { + player = "", + compile = "", + open_pdf = "", + switch_buffers = "", + insert_version = "", + hyphenation = "", + hyphenation_change_lang = "", + insert_hyphen = "", + add_hyphen = "", + del_next_hyphen = "", + del_prev_hyphen = "", + }, + }, + player = { + options = { + fluidsynth_flags = { + "/usr/share/soundfonts/FluidR3_GM.sf2", + }, + }, + }, + }) + + local lily_dicts = { + "~/.local/share/nvim/lazy/nvim-lilypond-suite/lilywords/keywords", + "~/.local/share/nvim/lazy/nvim-lilypond-suite/lilywords/musicCommands", + "~/.local/share/nvim/lazy/nvim-lilypond-suite/lilywords/musicFunctions", + "~/.local/share/nvim/lazy/nvim-lilypond-suite/lilywords/articulations", + "~/.local/share/nvim/lazy/nvim-lilypond-suite/lilywords/dynamics", + } + + vim.api.nvim_create_autocmd("FileType", { + pattern = "lilypond", + callback = function() + require("cmp_dictionary").setup({ + paths = lily_dicts, + }) + end, + }) + end, +} diff --git a/.local/bin/etc/nvim/compiler b/.local/bin/etc/nvim/compiler index e70ca77..d85ad58 100755 --- a/.local/bin/etc/nvim/compiler +++ b/.local/bin/etc/nvim/compiler @@ -51,5 +51,6 @@ case "$file" in *\.tex) textype "$file" ;; *\.vpr) $vipercmd "$file" ;; *\.zsh) zsh "$file" ;; + *\.ly) lilypond "$file" ;; *) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; esac