nvim: configure snippets, add license snippets
This commit is contained in:
parent
3fe567a463
commit
888a7e083f
@ -49,3 +49,12 @@ packer.use {
|
||||
vim.g.AutoPairsFlyMode = 0
|
||||
end
|
||||
}
|
||||
|
||||
packer.use {
|
||||
'https://github.com/L3MON4D3/LuaSnip',
|
||||
config = function()
|
||||
require("luasnip.loaders.from_lua").load(
|
||||
{ paths = vim.fn.stdpath('config') .. '/snippets'} )
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -81,3 +81,29 @@ vim.api.nvim_create_autocmd(
|
||||
callback = MY_set_colorcolumn
|
||||
}
|
||||
)
|
||||
|
||||
function MY_get_project_root()
|
||||
local path = vim.api.nvim_buf_get_name(0)
|
||||
local root_markers = {
|
||||
'.git', '.hg', '.svn', '.bzr', '_darcs',
|
||||
'.projectile', '.clang-format', '.luarc.json'
|
||||
}
|
||||
local sep = '/'
|
||||
|
||||
repeat
|
||||
path = path:gsub('/[^/]*$', '')
|
||||
for _, marker in ipairs(root_markers) do
|
||||
if io.open(path .. sep .. marker) then
|
||||
return path
|
||||
end
|
||||
end
|
||||
until path == ''
|
||||
end
|
||||
|
||||
function MY_shell_capture(command)
|
||||
local handle = io.popen(command)
|
||||
if not handle then return '' end
|
||||
local result = handle:read() or ''
|
||||
handle:close()
|
||||
return result
|
||||
end
|
||||
|
75
.config/nvim/snippets/cpp.lua
Normal file
75
.config/nvim/snippets/cpp.lua
Normal file
@ -0,0 +1,75 @@
|
||||
require('my/functions')
|
||||
|
||||
-- <https://github.com/L3MON4D3/LuaSnip/blob/69cb81cf7490666890545fef905d31a414edc15b/lua/luasnip/config.lua#L82-L104>
|
||||
local s = require("luasnip.nodes.snippet").S
|
||||
local f = require("luasnip.nodes.functionNode").F
|
||||
local i = require("luasnip.nodes.insertNode").I
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
|
||||
local agpl =
|
||||
[[/* This file is part of {project}.
|
||||
* Copyright © {year} {name} <{email}>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
{cursor}]]
|
||||
|
||||
local bsd0 =
|
||||
[[/* This file is part of {project}.
|
||||
* Copyright © {year} {name} <{email}>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
{cursor}]]
|
||||
|
||||
return {
|
||||
s(
|
||||
{
|
||||
trig = 'AGPL',
|
||||
name = 'AGPL-3.0-only',
|
||||
dscr = 'Inserts the GNU Affero General Public License, version 3'
|
||||
},
|
||||
fmt(agpl, {
|
||||
project = MY_get_project_root():gsub('.*/', ''),
|
||||
year = f(function() return os.date('%Y') end),
|
||||
name = MY_shell_capture('git config user.name'),
|
||||
email = MY_shell_capture('git config user.email'),
|
||||
cursor = i()
|
||||
})
|
||||
),
|
||||
s(
|
||||
{
|
||||
trig = '0BSD',
|
||||
name = '0BSD',
|
||||
dscr = 'Inserts the BSD Zero Clause License'
|
||||
},
|
||||
fmt(bsd0, {
|
||||
project = MY_get_project_root():gsub('.*/', ''),
|
||||
year = f(function() return os.date('%Y') end),
|
||||
name = MY_shell_capture('git config user.name'),
|
||||
email = MY_shell_capture('git config user.email'),
|
||||
cursor = i()
|
||||
})
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user