I am trying to make a little function that aims to extract a method from a piece of php code. The function works fine. Is not optipized but "done is better than perfect" and the purpose here is not perfectio but just, ... keep expandtab settings right.
And here the incriminated code.
fun! ExtractMethod() range
let g:selection = s:get_visual_selection()
exec ":set paste"
exec ":normal! Gko\<esc>o\<esc>Spublic function xxxxxxx()\<esc>=="
exec ":normal! o\t{\<esc>"
exec ":normal! o" . g:selection . "\<esc>"
exec ":normal! o\t}\<esc>%k2w"
endfun
function! s:get_visual_selection()
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - 2]
let lines[0] = lines[0][col1 - 1:]
return join(lines, "\n")
endfunction
vnoremap <Leader>r :call ExtractMethod()<cr>