Open Th3Whit3Wolf opened 4 years ago
For part one lets say you have a verbose directory structure that looks something like this.
.
├─ lua
│ ├─ init.lua
│ └─ plugins
│ ├─ init.lua
│ └─ snippets
│ ├─ init.lua
│ └─ lang # Language directory
│ ├─ c.lua # C snippets
│ └─ rust.lua # Rust snippets
└ init.vim
in lua/plugins/snippets/lang/rust.lua
you'd have something like this.
local U = require 'snippets.utils'
local snippets = {}
snippets = {
macro = U.match_indentation [[
macro_rules! ${1:name} {
($2) => {
$0
}
}
]],
type = [[type $1 = $2;]],
struct = U.match_indentation [[
struct $1 {
$0
}]],
enum = U.match_indentation [[
enum $1 {
$0
}]],
-- TODO(ashkan, 2020-08-19 05:33:54+0900) case change from TitleCase to snake_case for last element of ::
field = [[$1: $2,]],
-- field = [[${2=R.case_change.S[1]..}: $1,]];
impl = U.match_indentation [[
impl $1 {
$0
}
]],
hashmap = [[use std::collections::HashMap;]],
hashset = [[use std::collections::HashSet;]],
collections = [[use std::collections::$1;]],
match = U.match_indentation [[
match $1 {
$0
}]],
bcase = U.match_indentation [[
$1 => {
$0
}]],
case = U.match_indentation [[$1 => $0,]]
}
return snippets
in lua/plugins/snippets/init.lua
you'd have something like this.
local snippets = require 'snippets'
local U = require 'snippets.utils'
snippets.snippets = {
rust = require 'plugins/snippets/lang/rust',
_global = {
-- If you aren't inside of a comment, make the line a comment.
copyright = U.force_comment [[Copyright (C) Ashkan Kiani ${=os.date("%Y")}]]
}
}
Not sure how you could tie in lazy loading, maybe set an autocmd and wrap this in a function that checks for filetype.
I have a couple things I would like to do with snippets nvim