Skip to content

Instantly share code, notes, and snippets.

@nico
Created February 6, 2011 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nico/813631 to your computer and use it in GitHub Desktop.
Save nico/813631 to your computer and use it in GitHub Desktop.
vimrc to use per-file settings with chrome and clang_complete
let g:cr_root = '/Users/thakis/src/chrome-git/src/'
let g:cr_builddb = '/Users/thakis/src/chrome-git/src/all-builddb.sqlite'
fu! g:clang_per_file_user_options(path)
if a:path =~ g:cr_root
let l:path = a:path[strlen(g:cr_root):]
let l:cmd = 'sqlite3 ' . g:cr_builddb .
\' ''' . 'select command from gcc_build_commands join filenames ' .
\ 'on filename_input_id = filenames.rowid where name = "' .
\ l:path .
\'"'''
let l:flags = system(l:cmd)
if l:flags == ''
echo 'Could not find flags for file '.l:path
" TODO: Ideally, cancel completion.
endif
return l:flags
else
return ''
endif
endfu
fu! g:cr_build()
let l:path = expand('%:p')
if l:path =~ g:cr_root
let l:path = l:path[strlen(g:cr_root):]
let l:cmd = 'sqlite3 ' . g:cr_builddb .
\' ''' . 'select cwd from gcc_build_commands join filenames ' .
\ 'on filename_input_id = filenames.rowid where name = "' .
\ l:path .
\'"'''
let l:cwd = system(l:cmd)
if l:cwd == ''
echo 'Could not find cwd for file '.l:path
return
endif
let l:dir = getcwd()
try
execute 'cd `=l:cwd`'
call g:ClangUpdateQuickFix()
finally
execute 'cd `=l:dir`'
endtry
endif
endfu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment