1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- function! go#keyify#Keyify()
- let bin_path = go#path#CheckBinPath("keyify")
- let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
- if empty(bin_path) || !exists('*json_decode')
- return
- endif
-
- let command = printf("%s -json %s:#%s", go#util#Shellescape(bin_path),
- \ go#util#Shellescape(fname), go#util#OffsetCursor())
- let output = go#util#System(command)
- silent! let result = json_decode(output)
-
- if type(result) != type({})
- call go#util#EchoError(s:chomp(output))
- return
- endif
-
-
- execute "goto" result.start + 1
- let start = getpos('.')
- execute "goto" result.end
- let end = getpos('.')
- let vis_start = getpos("'<")
- let vis_end = getpos("'>")
-
- call setpos("'<", start)
- call setpos("'>", end)
- let select = 'gv'
-
- normal! gv
- if mode() !=# 'v'
- let select .= 'v'
- endif
- silent! execute "normal!" select."\"=result.replacement\<cr>p"
-
- normal! '<v'>=
- call setpos("'<", vis_start)
- call setpos("'>", vis_end)
- endfunction
- function! s:chomp(string)
- return substitute(a:string, '\n\+$', '', '')
- endfunction
|