From c073ebf763d645bc1dd52a0deeb2cec58f31685d Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sat, 24 Feb 2024 16:08:58 -0700 Subject: [PATCH] Drop snippets except UTF-8. --- users/jrpotter/lang/cxx.nix | 10 +--- users/jrpotter/lang/lua.nix | 6 +- users/jrpotter/lang/python.nix | 8 +-- users/jrpotter/neovim/config/cxx/snippets.lua | 57 ------------------- .../config/{cxx/init.lua => lang/cxx.lua} | 0 .../config/{lua/init.lua => lang/lua.lua} | 0 .../{python/init.lua => lang/python.lua} | 0 users/jrpotter/neovim/config/lua/snippets.lua | 48 ---------------- .../neovim/config/python/snippets.lua | 54 ------------------ .../{utf8/snippets.lua => utils/utf8.lua} | 0 users/jrpotter/neovim/default.nix | 13 +---- 11 files changed, 6 insertions(+), 190 deletions(-) delete mode 100644 users/jrpotter/neovim/config/cxx/snippets.lua rename users/jrpotter/neovim/config/{cxx/init.lua => lang/cxx.lua} (100%) rename users/jrpotter/neovim/config/{lua/init.lua => lang/lua.lua} (100%) rename users/jrpotter/neovim/config/{python/init.lua => lang/python.lua} (100%) delete mode 100644 users/jrpotter/neovim/config/lua/snippets.lua delete mode 100644 users/jrpotter/neovim/config/python/snippets.lua rename users/jrpotter/neovim/config/{utf8/snippets.lua => utils/utf8.lua} (100%) diff --git a/users/jrpotter/lang/cxx.nix b/users/jrpotter/lang/cxx.nix index 0ec0ea0..8aa6505 100644 --- a/users/jrpotter/lang/cxx.nix +++ b/users/jrpotter/lang/cxx.nix @@ -15,23 +15,17 @@ in programs.neovim = { nvim-dap = '' - require('cxx.init').nvim_dap() + require('lang.cxx').nvim_dap() ''; nvim-lspconfig = '' - require('cxx.init').nvim_lspconfig() - + require('lang.cxx').nvim_lspconfig() vim.filetype.add({ pattern = { ['.*%.h'] = 'c', }, }) ''; - - nvim-snippets = '' - require('luasnip').add_snippets('c', require('cxx.snippets')) - require('luasnip').add_snippets('cpp', require('cxx.snippets')) - ''; }; xdg.configFile."nvim/after/ftplugin/c.lua".text = '' diff --git a/users/jrpotter/lang/lua.nix b/users/jrpotter/lang/lua.nix index fb25d87..114c9a8 100644 --- a/users/jrpotter/lang/lua.nix +++ b/users/jrpotter/lang/lua.nix @@ -6,11 +6,7 @@ programs.neovim = { nvim-lspconfig = '' - require('lua.init').nvim_lspconfig() - ''; - - nvim-snippets = '' - require('luasnip').add_snippets('lua', require('lua.snippets')) + require('lang.lua').nvim_lspconfig() ''; }; } diff --git a/users/jrpotter/lang/python.nix b/users/jrpotter/lang/python.nix index 211eede..2458577 100644 --- a/users/jrpotter/lang/python.nix +++ b/users/jrpotter/lang/python.nix @@ -13,15 +13,11 @@ programs.neovim = { nvim-dap = '' - require('python.init').nvim_dap() + require('lang.python').nvim_dap() ''; nvim-lspconfig = '' - require('python.init').nvim_lspconfig() - ''; - - nvim-snippets = '' - require('luasnip').add_snippets('python', require('python.snippets')) + require('lang.python').nvim_lspconfig() ''; }; diff --git a/users/jrpotter/neovim/config/cxx/snippets.lua b/users/jrpotter/neovim/config/cxx/snippets.lua deleted file mode 100644 index 80173de..0000000 --- a/users/jrpotter/neovim/config/cxx/snippets.lua +++ /dev/null @@ -1,57 +0,0 @@ -local fmt = require('luasnip.extras.fmt').fmt -local ls = require('luasnip') -local ki = require('luasnip.nodes.key_indexer') -local ul = require('utils.luasnip') - -local c = ls.choice_node -local d = ls.dynamic_node -local i = ls.insert_node -local k = ki.new_key -local r = ls.restore_node -local s = ls.snippet -local sn = ls.snippet_node -local t = ls.text_node - -return { - s( - { name = 'for', trig = 'for' }, - fmt([[ -for (<>; <>) { - <> -}]], - { - c(1, { - sn(nil, { - i(1, 'int'), - t(' '), - i(2, 'i'), - }), - sn(nil, { - i(1, 'char *'), - i(2, 'c'), - }), - }), - d(2, function(_, parent) - local index = ul.choice_index(parent.nodes[2]) - return sn( - nil, - r(1, string.format('for-%d', index), ({ - sn(nil, { - i(1, 'i < N'), - t('; '), - i(2, '++i'), - }), - sn(nil, { - i(1, 'c'), - t('; '), - i(2, '++c'), - }), - })[index]) - ) - end, { 1 }), - ul.visual_isn(3), - }, - { delimiters = '<>' } - ) - ), -} diff --git a/users/jrpotter/neovim/config/cxx/init.lua b/users/jrpotter/neovim/config/lang/cxx.lua similarity index 100% rename from users/jrpotter/neovim/config/cxx/init.lua rename to users/jrpotter/neovim/config/lang/cxx.lua diff --git a/users/jrpotter/neovim/config/lua/init.lua b/users/jrpotter/neovim/config/lang/lua.lua similarity index 100% rename from users/jrpotter/neovim/config/lua/init.lua rename to users/jrpotter/neovim/config/lang/lua.lua diff --git a/users/jrpotter/neovim/config/python/init.lua b/users/jrpotter/neovim/config/lang/python.lua similarity index 100% rename from users/jrpotter/neovim/config/python/init.lua rename to users/jrpotter/neovim/config/lang/python.lua diff --git a/users/jrpotter/neovim/config/lua/snippets.lua b/users/jrpotter/neovim/config/lua/snippets.lua deleted file mode 100644 index 4b99289..0000000 --- a/users/jrpotter/neovim/config/lua/snippets.lua +++ /dev/null @@ -1,48 +0,0 @@ -local fmt = require('luasnip.extras.fmt').fmt -local ls = require('luasnip') -local ul = require('utils.luasnip') - -local c = ls.choice_node -local i = ls.insert_node -local s = ls.snippet -local sn = ls.snippet_node -local t = ls.text_node - -return { - s( - { name = 'for', trig = 'for' }, - fmt([[ -for {} do - {} -end]], - { - c(1, { - sn(nil, { - i(1, 'i'), - t('='), - i(2, 'm'), - t(','), - i(3, 'n'), - }), - sn(nil, { - i(1, 'k'), - t(', '), - i(2, 'v'), - t(' in pairs('), - i(3, 'tbl'), - t(')'), - }), - sn(nil, { - i(1, 'i'), - t(', '), - i(2, 'v'), - t(' in ipairs('), - i(3, 'seq'), - t(')'), - }), - }), - ul.visual_isn(2), - } - ) - ), -} diff --git a/users/jrpotter/neovim/config/python/snippets.lua b/users/jrpotter/neovim/config/python/snippets.lua deleted file mode 100644 index 0050a76..0000000 --- a/users/jrpotter/neovim/config/python/snippets.lua +++ /dev/null @@ -1,54 +0,0 @@ -local fmt = require('luasnip.extras.fmt').fmt -local ls = require('luasnip') -local ul = require('utils.luasnip') - -local c = ls.choice_node -local d = ls.dynamic_node -local i = ls.insert_node -local r = ls.restore_node -local s = ls.snippet -local sn = ls.snippet_node -local t = ls.text_node - -return { - s( - { name = 'for', trig = 'for' }, - fmt([[ -for {} in {}: - {}]], - { - c(1, { - i(nil, 'i'), - i(nil, 'k'), - i(nil, 'v'), - { i(1, 'k'), t(', '), i(2, 'v') }, - }), - d(2, function(_, parent) - local index = ul.choice_index(parent.nodes[2]) - return sn( - nil, - r(1, string.format('for-%d', index), ({ - c(nil, { - { t('range('), i(1, 'n'), t(')') }, - i(nil, 'val'), - }), - c(nil, { - { i(1, 'dict'), t('.keys()') }, - i(nil, 'val'), - }), - c(nil, { - { i(1, 'dict'), t('.values()') }, - i(nil, 'val'), - }), - c(nil, { - { i(1, 'dict'), t('.items()') }, - i(nil, 'val'), - }), - })[index]) - ) - end, { 1 }), - ul.visual_isn(3), - } - ) - ), -} diff --git a/users/jrpotter/neovim/config/utf8/snippets.lua b/users/jrpotter/neovim/config/utils/utf8.lua similarity index 100% rename from users/jrpotter/neovim/config/utf8/snippets.lua rename to users/jrpotter/neovim/config/utils/utf8.lua diff --git a/users/jrpotter/neovim/default.nix b/users/jrpotter/neovim/default.nix index 7649994..81575e1 100644 --- a/users/jrpotter/neovim/default.nix +++ b/users/jrpotter/neovim/default.nix @@ -32,10 +32,9 @@ let plugin = pkgs.vimPlugins.luasnip; config = '' require('utils.luasnip').setup() - require('luasnip').add_snippets('all', require('utf8.snippets'), { + require('luasnip').add_snippets('all', require('utils.utf8'), { type = "autosnippets", }) - ${config.programs.neovim.nvim-snippets} ''; }; @@ -109,16 +108,6 @@ in Language-specific configurations for the `nvim-lspconfig` plugin. ''; }; - - nvim-snippets = lib.mkOption { - type = lib.types.lines; - example = '' - require('...').nvim_lspconfig() - ''; - description = lib.mdDoc '' - Language-specific configurations for the `luasnip` plugin. - ''; - }; }; config = {