Skip to content

Commit

Permalink
Initial go support
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Oct 27, 2013
1 parent 8c74eeb commit 149efad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
31 changes: 31 additions & 0 deletions autoload/sj/go.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function! sj#go#SplitStruct()
let [start, end] = sj#LocateBracesOnLine('{', '}', 'goString', 'goComment')
let args = sj#ParseJsonObjectBody(start + 1, end - 1)
call sj#ReplaceCols(start + 1, end - 1, "\n".join(args, ",\n").",\n")
endfunction

function! sj#go#JoinStruct()
let start_lineno = line('.')

if search('{$', 'Wc', line('.')) <= 0
return 0
endif

normal! %
let end_lineno = line('.')

if start_lineno == end_lineno
" we haven't moved, brackets not found
return 0
endif

let arguments = []
for line in getbufline('%', start_lineno + 1, end_lineno - 1)
let argument = substitute(line, ',$', '', '')
let argument = sj#Trim(argument)
call add(arguments, argument)
endfor

call sj#ReplaceMotion('va{', '{'.join(arguments, ', ').'}')
return 1
endfunction
1 change: 1 addition & 0 deletions examples/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StructType{1, "asdf", []int{1, 2, 3}}
7 changes: 7 additions & 0 deletions ftplugin/go/splitjoin.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let b:splitjoin_split_callbacks = [
\ 'sj#go#SplitStruct',
\ ]

let b:splitjoin_join_callbacks = [
\ 'sj#go#JoinStruct',
\ ]

0 comments on commit 149efad

Please sign in to comment.