diff --git a/README.md b/README.md index 342500f..c5dc0ae 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ And this is done via the `snippet_engine` option in neogen's setup: - `snippet_engine` option will use provided engine to place the annotations: -Currently supported: `luasnip`. +Currently supported: `luasnip`, `snippy`. ```lua require('neogen').setup({ snippet_engine = "luasnip" }) diff --git a/doc/neogen.txt b/doc/neogen.txt index 08b1f07..c274c75 100644 --- a/doc/neogen.txt +++ b/doc/neogen.txt @@ -180,12 +180,14 @@ Feel free to submit a PR, I will be happy to help you ! We use semantic versioning ! (https://semver.org) Here is the current Neogen version: > - neogen.version = "2.6.0" + neogen.version = "2.7.0" < # Changelog~ Note: We will only document `major` and `minor` versions, not `patch` ones. +## 2.7.0~ + - Add support for `snippy` snippet engine ! (see |neogen-snippet-integration|) ## 2.6.0~ - Add support for placeholders in snippet insertion ! None: placeholders are automatically set when using a bundled snippet engine. @@ -235,6 +237,7 @@ To use a snippet engine, pass the option into neogen setup: < Some snippet engines come out of the box bundled with neogen: - `"luasnip"` (https://github.com/L3MON4D3/LuaSnip) +- `"snippy"` (https://github.com/dcampos/nvim-snippy) If you want to customize the placeholders, you can use `placeholders_text` option: > diff --git a/lua/neogen/snippet.lua b/lua/neogen/snippet.lua index 492213c..2ba6b65 100644 --- a/lua/neogen/snippet.lua +++ b/lua/neogen/snippet.lua @@ -11,6 +11,7 @@ local conf = require("neogen.config").get() --- < --- Some snippet engines come out of the box bundled with neogen: --- - `"luasnip"` (https://github.com/L3MON4D3/LuaSnip) +--- - `"snippy"` (https://github.com/dcampos/nvim-snippy) --- --- If you want to customize the placeholders, you can use `placeholders_text` option: --- > @@ -94,4 +95,20 @@ snippet.engines.luasnip = function(snip, pos) ) end +--- Expand snippet for snippy engine +---@param snip string the snippet to expand +---@param pos table a tuple of row, col +---@private +snippet.engines.snippy = function (snip, pos) + local ok, snippy = pcall(require, "snippy") + if not ok then + notify("Snippy not found, aborting...", vim.log.levels.ERROR) + return + end + local row, _ = unpack(pos) + vim.api.nvim_buf_set_lines(0, row, row, true, {''}) -- snippy will change `row` + vim.api.nvim_win_set_cursor(0, {row + 1, 0}) -- `snip` already has indent so we should ignore `col` + snippy.expand_snippet({body = snip}) +end + return snippet