mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins and added vim-markdown
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
function! go#fillstruct#FillStruct() abort
|
||||
let l:cmd = ['fillstruct',
|
||||
\ '-file', bufname(''),
|
||||
\ '-offset', go#util#OffsetCursor()]
|
||||
\ '-offset', go#util#OffsetCursor(),
|
||||
\ '-line', line('.')]
|
||||
|
||||
" Read from stdin if modified.
|
||||
if &modified
|
||||
@ -23,27 +24,36 @@ function! go#fillstruct#FillStruct() abort
|
||||
return
|
||||
endtry
|
||||
|
||||
let l:code = split(l:json['code'], "\n")
|
||||
" Output is array:
|
||||
"[
|
||||
" {"start": 92, "end": 106, "code": "mail.Address{\n\tName: \"\",\n\tAddress: \"\",\n}"},
|
||||
" {...second struct...}
|
||||
" ]
|
||||
|
||||
let l:pos = getpos('.')
|
||||
|
||||
try
|
||||
" Add any code before/after the struct.
|
||||
exe l:json['start'] . 'go'
|
||||
let l:code[0] = getline('.')[:col('.')-1] . l:code[0]
|
||||
exe l:json['end'] . 'go'
|
||||
let l:code[len(l:code)-1] .= getline('.')[col('.'):]
|
||||
for l:struct in l:json
|
||||
let l:code = split(l:struct['code'], "\n")
|
||||
|
||||
" Indent every line except the first one; makes it look nice.
|
||||
let l:indent = repeat("\t", indent('.') / &ts)
|
||||
for i in range(1, len(l:code)-1)
|
||||
let l:code[l:i] = l:indent . l:code[i]
|
||||
" Add any code before/after the struct.
|
||||
exe l:struct['start'] . 'go'
|
||||
let l:code[0] = getline('.')[:col('.')-1] . l:code[0]
|
||||
exe l:struct['end'] . 'go'
|
||||
let l:code[len(l:code)-1] .= getline('.')[col('.'):]
|
||||
|
||||
" Indent every line except the first one; makes it look nice.
|
||||
let l:indent = repeat("\t", indent('.') / &tabstop)
|
||||
for l:i in range(1, len(l:code)-1)
|
||||
let l:code[l:i] = l:indent . l:code[l:i]
|
||||
endfor
|
||||
|
||||
" Out with the old ...
|
||||
exe 'normal! ' . l:struct['start'] . 'gov' . l:struct['end'] . 'gox'
|
||||
" ... in with the new.
|
||||
call setline('.', l:code[0])
|
||||
call append('.', l:code[1:])
|
||||
endfor
|
||||
|
||||
" Out with the old ...
|
||||
exe 'normal! ' . l:json['start'] . 'gov' . l:json['end'] . 'gox'
|
||||
" ... in with the new.
|
||||
call setline('.', l:code[0])
|
||||
call append('.', l:code[1:])
|
||||
finally
|
||||
call setpos('.', l:pos)
|
||||
endtry
|
||||
|
Reference in New Issue
Block a user