Compare commits

...

2 Commits

Author SHA1 Message Date
b0cfb31645 Add func snippet for go 2024-05-24 23:09:47 +01:00
Kenneth Benzie (Benie)
aba1664d09 Cleanup unused arg in statusline implementation 2024-05-24 16:04:23 +01:00
2 changed files with 64 additions and 5 deletions

View File

@@ -75,7 +75,7 @@ local function special(group, name, title)
end end
-- Construct a statusline for generic buffer types. -- Construct a statusline for generic buffer types.
local function generic(group, name, show_lsp) local function generic(group, name)
-- Display current mode with dynamic highlights. -- Display current mode with dynamic highlights.
local line = '%#' .. group .. '# ' .. name .. ' ' local line = '%#' .. group .. '# ' .. name .. ' '
-- Display spell or paste if set with dusk highlights in a group to swallow -- Display spell or paste if set with dusk highlights in a group to swallow
@@ -131,11 +131,11 @@ function _G.statusline_active()
return special('StatusLineLight', 'Terminal', '%f') return special('StatusLineLight', 'Terminal', '%f')
elseif vim.o.previewwindow then elseif vim.o.previewwindow then
if mode == 'Normal' then mode = 'Preview' end if mode == 'Normal' then mode = 'Preview' end
return generic('StatusLineLight', mode, false) return generic('StatusLineLight', mode)
elseif vim.o.filetype == 'man' then elseif vim.o.filetype == 'man' then
return special('StatusLineDusk', 'Manual', '%f') return special('StatusLineDusk', 'Manual', '%f')
end end
return generic('StatusLineLight', mode, true) return generic('StatusLineLight', mode)
end end
function _G.statusline_inactive() function _G.statusline_inactive()
@@ -152,11 +152,11 @@ function _G.statusline_inactive()
elseif vim.o.buftype == 'terminal' then elseif vim.o.buftype == 'terminal' then
line = special('StatusLineDusk', 'Terminal', '%f') line = special('StatusLineDusk', 'Terminal', '%f')
elseif vim.o.previewwindow then elseif vim.o.previewwindow then
line = generic('StatusLineDusk', 'Preview', false) line = generic('StatusLineDusk', 'Preview')
elseif vim.o.filetype == 'man' then elseif vim.o.filetype == 'man' then
line = special('StatusLineDusk', 'Manual', '%f') line = special('StatusLineDusk', 'Manual', '%f')
else else
line = generic('StatusLineDusk', 'Idle', false) line = generic('StatusLineDusk', 'Idle')
end end
return line return line
end end

59
snippets/go.lua Normal file
View File

@@ -0,0 +1,59 @@
# Go LuaSnip Snippets
local luasnip = require('luasnip')
local snip = luasnip.snippet
local text = luasnip.text_node
local ins = luasnip.insert_node
local func = luasnip.function_node
local node = luasnip.snippet_node
local key = require("luasnip.nodes.key_indexer").new_key
local function short_name(name)
local short = string.lower(string.sub(name, 1, 1))
for i = 2, #name do
local char = string.sub(name, i, i)
if char == string.upper(char) then
short = short .. char
end
end
return string.lower(short)
end
local snippets = {
snip('func', {
text('func '),
node(1, {
func(function(args)
if string.len(args[1][1]) > 0 then
return '(' .. short_name(args[1][1]) .. ' *'
end
return ''
end, key('type')),
ins(1, '', { key = 'type' }),
func(function(args)
if string.len(args[1][1]) > 0 then
return ') '
end
return ''
end, key('type')),
}),
ins(2, 'name'),
text('('),
ins(3, ''),
text(') '),
ins(4, '', { key = 'return' }),
func(function(args)
if string.len(args[1][1]) > 0 then
return ' '
end
return ''
end, key('return')),
text({ '{', '\t' }),
ins(0, ''),
text({ '', '}' }),
}),
}
return snippets