Last active
November 1, 2017 14:59
-
-
Save tyru/dd804f78add8c4e01fd02a13950d083a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [function! s:load_on() | |
| imap <expr> <Tab> neosnippet#expandable_or_jumpable() ? | |
| \ "\<Plug>(neosnippet_expand_or_jump)" : "\<Tab>" | |
| endfuncti] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "strings" | |
| "github.com/haya14busa/go-vimlparser" | |
| "github.com/haya14busa/go-vimlparser/ast" | |
| ) | |
| func main() { | |
| src := ` | |
| function! s:load_on() | |
| imap <expr> <Tab> neosnippet#expandable_or_jumpable() ? | |
| \ "\<Plug>(neosnippet_expand_or_jump)" : "\<Tab>" | |
| endfunction | |
| ` | |
| file, err := vimlparser.ParseFile(strings.NewReader(src), "src.vim", nil) | |
| if err != nil { | |
| panic(err) | |
| } | |
| // Inspect nodes and get above values from plugconf script | |
| ast.Inspect(file, func(node ast.Node) bool { | |
| // Cast to function node (return if it's not a function node) | |
| var fn *ast.Function | |
| if f, ok := node.(*ast.Function); !ok { | |
| return true | |
| } else { | |
| fn = f | |
| } | |
| body := extractBody(fn, src) | |
| fmt.Printf("[%s]\n", body) | |
| return true | |
| }) | |
| } | |
| func extractBody(fn *ast.Function, src string) string { | |
| pos := fn.Pos() | |
| // TODO: Handle line break | |
| endpos := fn.EndFunction.Pos() | |
| endfunc := fn.EndFunction.ExArg | |
| cmdlen := endfunc.Argpos.Offset - endfunc.Cmdpos.Offset | |
| endpos.Offset += cmdlen | |
| return src[pos.Offset:endpos.Offset] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment