From 3c332abf0f5f283e07c873ee67b417bf23a33c3a Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Wed, 25 Dec 2024 18:35:17 +0800 Subject: [PATCH] Update bindings + luasnip config --- lua/snippets/c-cpp.lua | 24 ++++++++++++++++++++++++ lua/snippets/common.lua | 27 +++++++++++++++++++++++++++ lua/snippets/init.lua | 4 ++++ lua/snippets/lua.lua | 19 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 lua/snippets/c-cpp.lua create mode 100644 lua/snippets/common.lua create mode 100644 lua/snippets/init.lua create mode 100644 lua/snippets/lua.lua diff --git a/lua/snippets/c-cpp.lua b/lua/snippets/c-cpp.lua new file mode 100644 index 0000000..21ac8bb --- /dev/null +++ b/lua/snippets/c-cpp.lua @@ -0,0 +1,24 @@ +print 'c-cpp init' +ls.add_snippets('c', { + s('fn', { + i(1, 'void'), + t ' ', + i(2, 'func_name'), + t '(', + i(3), + t ') ', + t '{ ', + i(4, '...'), + t ' }', + }), + s('test', { + t 'printf("', + i(1), + t '");', + }), +}) +ls.filetype_extend('cpp', { 'c' }) +-- Return false to invalidate cache entry for require() +-- This is so sourcing snippets/init.lua also "reloads" this file +-- https://stackoverflow.com/questions/72242451/sourcing-nvim-init-does-not-source-required-lua-files +return false diff --git a/lua/snippets/common.lua b/lua/snippets/common.lua new file mode 100644 index 0000000..92402e3 --- /dev/null +++ b/lua/snippets/common.lua @@ -0,0 +1,27 @@ +ls = require 'luasnip' +s = ls.snippet +sn = ls.snippet_node +isn = ls.indent_snippet_node +t = ls.text_node +i = ls.insert_node +f = ls.function_node +c = ls.choice_node +d = ls.dynamic_node +r = ls.restore_node +events = require 'luasnip.util.events' +ai = require 'luasnip.nodes.absolute_indexer' +extras = require 'luasnip.extras' +l = extras.lambda +rep = extras.rep +p = extras.partial +m = extras.match +n = extras.nonempty +dl = extras.dynamic_lambda +fmt = require('luasnip.extras.fmt').fmt +fmta = require('luasnip.extras.fmt').fmta +conds = require 'luasnip.extras.expand_conditions' +postfix = require('luasnip.extras.postfix').postfix +types = require 'luasnip.util.types' +parse = require('luasnip.util.parser').parse_snippet +ms = ls.multi_snippet +k = require('luasnip.nodes.key_indexer').new_key diff --git a/lua/snippets/init.lua b/lua/snippets/init.lua new file mode 100644 index 0000000..9b510ef --- /dev/null +++ b/lua/snippets/init.lua @@ -0,0 +1,4 @@ +print 'init.lua init' +require 'snippets.common' +require 'snippets.lua' +require 'snippets.c-cpp' diff --git a/lua/snippets/lua.lua b/lua/snippets/lua.lua new file mode 100644 index 0000000..eaf909a --- /dev/null +++ b/lua/snippets/lua.lua @@ -0,0 +1,19 @@ +ls.add_snippets('lua', { + s('func', { + t 'function() ', + i(1), + t ' end', + }), + + s('if', { + t 'if ', + i(1, 'true'), + t ' then ', + i(2), + t ' end', + }), +}) +-- Return false to invalidate cache entry for require() +-- This is so sourcing snippets/init.lua also "reloads" this file +-- https://stackoverflow.com/questions/72242451/sourcing-nvim-init-does-not-source-required-lua-files +return false