Skip to content

Instantly share code, notes, and snippets.

@oxyc
Created March 1, 2012 17:40
Show Gist options
  • Select an option

  • Save oxyc/1951604 to your computer and use it in GitHub Desktop.

Select an option

Save oxyc/1951604 to your computer and use it in GitHub Desktop.
function! DrupalImplementsComment ()
let filename = bufname("%")
let dot = stridx(filename, ".")
let module = strpart(filename, 0, dot)
let current_line = getline(".")
let hook_idx = matchend(current_line, "function " . module . "_")
if !empty(module) && hook_idx != -1
let hook_length = match(current_line, "(") - hook_idx
let hook_name = strpart(current_line, hook_idx, hook_length)
call DoxygenComment ("Implements hook_" . hook_name . "().")
else
call DoxygenComment ()
endif
endfunction
function! DoxygenComment (...)
set paste
let message = (a:0 > 0) ? a:1 : ''
exe "normal! O/**\<CR>"
\ . " * " . message . "\<CR>"
\ . " */\<Esc>"
if empty(message)
-1 | startinsert!
else
+1
endif
set nopaste
endfunction
noremap <leader>d :call DoxygenComment ()<CR>
noremap <leader>c :call DrupalImplementsComment ()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment