Guest User

Untitled

a guest
Jul 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. "ftplugins/php.vim
  2.  
  3. function! s:createSnippet(line)
  4. let l:signature = matchstr(a:line, '\v\s+[a-z0-9A-Z_]+\s*\(.*\)')
  5. let l:methodName = substitute(substitute(l:signature, '(.*$', '', 'g'), '\s', '', 'g')
  6. let l:paramList = []
  7. let l:params = substitute(l:signature, '\$[a-zA-Z0-9_]\+', '\=add(l:paramList, submatch(0))', 'g')
  8.  
  9. let l:templateParams = []
  10. for p in l:paramList
  11. let l:parameterPos = len(l:templateParams) + 1
  12. call add(l:templateParams, '${' . l:parameterPos . ':' . p . '}')
  13. endfor
  14.  
  15. if l:methodName !=# '__construct'
  16. let l:template = l:methodName . '(' . join(l:templateParams, ', ') . ')$0'
  17. else
  18. let l:template = '(' . join(l:templateParams, ', ') . ')$0'
  19. endif
  20.  
  21. execute "normal! a\<C-r>=UltiSnips#Anon('" . l:template . "')\<cr>"
  22. endfunction
  23.  
  24. function! s:fzfphpmethods()
  25. call fzf#run({
  26. \ 'source': "ag -a --php --vimgrep '(public)? +(function\|@method) (.+) *\\(.*\\)'",
  27. \ 'sink': function('s:createsnippet'),
  28. \ 'down': '30%'
  29. \})
  30. endfunction
  31.  
  32. command! -buffer PhpMethods call <sid>fzfPhpMethods()
  33. inoremap <buffer> <C-l> <esc>:PhpMethods<CR>
Add Comment
Please, Sign In to add comment