Skip to content

Instantly share code, notes, and snippets.

@scrooloose
Last active August 29, 2015 14:21
Show Gist options
  • Save scrooloose/a60ebc0d685c6f5535a2 to your computer and use it in GitHub Desktop.
Save scrooloose/a60ebc0d685c6f5535a2 to your computer and use it in GitHub Desktop.
"Put this file in ~/.vim/nerdtree_plugin
"
"There are definitely more efficient ways to check a file to see if it
"is a class/interface/etc but this is really just a proof of concept.
if exists("loaded_nerdtree_ft_flags_plugin")
finish
endif
let g:loaded_nerdtree_ft_flags_plugin = 1
let s:flagNamespace = "filetype"
function! NERDTreeFtFlagsListener(event)
let path = a:event.subject
if path.isDirectory
return
endif
if s:IsClass(path)
call path.flagSet.addFlag(s:flagNamespace, 'C')
elseif s:IsInterface(path)
call path.flagSet.addFlag(s:flagNamespace, 'I')
endif
endfunction
call g:NERDTreePathNotifier.AddListener("init", "NERDTreeFtFlagsListener")
call g:NERDTreePathNotifier.AddListener("refreshFlags", "NERDTreeFtFlagsListener")
function! s:IsClass(path)
call system('grep -q ''^[ \t]*class '' ' . a:path.str())
return v:shell_error == 0
endfunction
function! s:IsInterface(path)
call system('grep -q ''^[ \t]*interface'' ' . a:path.str())
return v:shell_error == 0
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment