mirror of
https://github.com/pnx/dotfiles
synced 2026-06-16 03:14:55 +02:00
nvim add c/cpp snippets
This commit is contained in:
parent
a011d86b24
commit
ce00d0e5c9
2 changed files with 46 additions and 0 deletions
23
nvim/snippets/c.lua
Normal file
23
nvim/snippets/c.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
local ls = require("luasnip")
|
||||||
|
local s = ls.snippet
|
||||||
|
local t = ls.text_node
|
||||||
|
local f = ls.function_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
|
||||||
|
-- Helper: convert current filename to uppercase header guard
|
||||||
|
local function header_guard(_, snip)
|
||||||
|
local name = snip.env.TM_FILENAME or "HEADER"
|
||||||
|
-- Replace dots and non-alphanumerics with underscores
|
||||||
|
name = name:gsub("%.", "_"):gsub("%W", "_"):upper()
|
||||||
|
return name .. "_"
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
s("guard", {
|
||||||
|
t("#ifndef "), f(header_guard, {}),
|
||||||
|
t({ "", "#define " }), f(header_guard, {}),
|
||||||
|
t({ "", "", "" }),
|
||||||
|
i(0),
|
||||||
|
t({ "", "", "#endif // " }), f(header_guard, {}),
|
||||||
|
}),
|
||||||
|
}
|
||||||
23
nvim/snippets/cpp.lua
Normal file
23
nvim/snippets/cpp.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
local ls = require("luasnip")
|
||||||
|
local s = ls.snippet
|
||||||
|
local t = ls.text_node
|
||||||
|
local f = ls.function_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
|
||||||
|
-- Helper: convert current filename to uppercase header guard
|
||||||
|
local function header_guard(_, snip)
|
||||||
|
local name = snip.env.TM_FILENAME or "HEADER"
|
||||||
|
-- Replace dots and non-alphanumerics with underscores
|
||||||
|
name = name:gsub("%.", "_"):gsub("%W", "_"):upper()
|
||||||
|
return name .. "_"
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
s("guard", {
|
||||||
|
t("#ifndef "), f(header_guard, {}),
|
||||||
|
t({ "", "#define " }), f(header_guard, {}),
|
||||||
|
t({ "", "", "" }),
|
||||||
|
i(0),
|
||||||
|
t({ "", "", "#endif // " }), f(header_guard, {}),
|
||||||
|
}),
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue