You've already forked dotfiles
feat: Replacement of the autopairs plugin using snippets, extension of
snippets (mainly python) and cleanup of keymappings for snippets.
This commit is contained in:
36
nvim/snippets/all.lua
Normal file
36
nvim/snippets/all.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
-- require('luasnip.session.snippet_collection').clear_snippets('all')
|
||||
|
||||
local ls = require('luasnip')
|
||||
local s = ls.snippet
|
||||
local sn = ls.snippet_node
|
||||
local i = ls.insert_node
|
||||
local t = ls.text_node
|
||||
local c = ls.choice_node
|
||||
local r = ls.restore_node
|
||||
|
||||
-- Replacement of autopairs
|
||||
local function pair(pair_begin, pair_end)
|
||||
-- Auto-pair using snippets
|
||||
return s({ trig = pair_begin, wordTrig = false }, {
|
||||
t({ pair_begin }),
|
||||
c(1, {
|
||||
r(1, "content", i(1)),
|
||||
sn(nil, { t({"", "\t"}), r(1, "content", i(1)), t({ "", "" }) }),
|
||||
}),
|
||||
t({ pair_end }),
|
||||
})
|
||||
end
|
||||
|
||||
ls.add_snippets('all', {
|
||||
pair('(', ')'),
|
||||
pair('{', '}'),
|
||||
pair('[', ']'),
|
||||
pair('<', '>'),
|
||||
pair("'", "'"),
|
||||
pair('"', '"'),
|
||||
pair('`', '`'),
|
||||
}, {
|
||||
type = 'autosnippets',
|
||||
key = 'all_auto',
|
||||
})
|
||||
-- end autopairs
|
||||
@@ -1,44 +1,36 @@
|
||||
local ls = require('luasnip')
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
local i = ls.insert_node
|
||||
local t = ls.text_node
|
||||
local l = require('luasnip.extras').lambda
|
||||
-- local l = require('luasnip.extras').lambda
|
||||
local fmt = require('luasnip.extras.fmt').fmt
|
||||
local ts_post = require('luasnip.extras.treesitter_postfix').treesitter_postfix
|
||||
-- local ts_post = require('luasnip.extras.treesitter_postfix').treesitter_postfix
|
||||
|
||||
return {
|
||||
ts_post({
|
||||
matchTSNode = {
|
||||
query = [[
|
||||
(function_definition
|
||||
parameters: (parameters) @params
|
||||
return_type: (type) @return
|
||||
) @prefix
|
||||
]],
|
||||
query_lang = "python",
|
||||
},
|
||||
trig = "docstring",
|
||||
}, fmt([[
|
||||
''' {}
|
||||
|
||||
Keyword arguments:
|
||||
{} () -
|
||||
|
||||
Return:
|
||||
{} - {}
|
||||
'''
|
||||
ls.add_snippets('python', {
|
||||
s('docstring single', {
|
||||
t("''' "), i(0, 'text'), t(" '''")
|
||||
}),
|
||||
s('def', fmt([[
|
||||
def {func}({args}) -> {ret}:
|
||||
''' {doc} '''
|
||||
{body}
|
||||
]], {
|
||||
i(1, 'Description'),
|
||||
l(l.LS_TSCAPTURE_PARAMS),
|
||||
l(l.LS_TSCAPTURE_RETURN),
|
||||
l(l.LS_TSDATA),
|
||||
func = i(1, 'fname'),
|
||||
args = i(2),
|
||||
ret = i(3, 'None'),
|
||||
doc = i(4, 'docstring'),
|
||||
body = i(5, 'pass'),
|
||||
}, {
|
||||
})),
|
||||
-- s(
|
||||
-- { trig = "thingy" },
|
||||
-- { t('Woot!') }
|
||||
-- ),
|
||||
-- s(
|
||||
-- { trig = 'thingy2' },
|
||||
-- { t('Woot2!') }
|
||||
-- )
|
||||
}
|
||||
s('ternary', {
|
||||
i(1, 'then'), t(' if '), i(2, 'condition'), t(' else '), i(3, 'else')
|
||||
}),
|
||||
s('tuple ternary', fmt([[
|
||||
({if_true}, {if_false})[{condition}]
|
||||
]], {
|
||||
if_true = i(1, 'if_true'),
|
||||
if_false = i(2, 'if_false'),
|
||||
condition = i(3, 'condition'),
|
||||
})),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user