Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per file compile flags and cwd #31

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for per-file user options through g:per_file_user_options.
  • Loading branch information
nico committed Feb 6, 2011
commit 507f893b4cf17a07fea6eccd293c6ddebd2381d0
23 changes: 22 additions & 1 deletion plugin/clang_complete.vim
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
" - g:clang_exec:
" Name or path of clang executable.
" Note: Use this if clang has a non-standard name, or isn't in the
" path.
" path. Not used if |g:clang_use_library| is set.
" Default: 'clang'
"
" - g:clang_user_options:
@@ -55,6 +55,21 @@
" Default: ''
" Example: '|| exit 0' (it will discard clang return value)
"
" - g:clang_per_file_user_options:
" Can be set to a function that is called with the name of the current
" buffer. This should return a list of additional flags for this file.
" Useful if compilation flags differ on a per-file or per-directory
" base. Works only if |g:clang_use_library| is set.
" Default: Not set.
" Example:
" fu! g:clang_per_file_user_options(path)
" if a:path =~ 'clang'
" return '-I/Users/thakis/src/llvm-rw/tools/clang/include'
" else
" return ''
" endif
" endfu
"
" - g:clang_use_library:
" Instead of calling the clang/clang++ tool use libclang directly. This
" should improve the performance, but is still experimental.
@@ -144,6 +159,12 @@ function! s:ClangCompleteInit()
let g:clang_user_options = ''
endif

if !exists('*g:clang_per_file_user_options')
function g:clang_per_file_user_options(path)
return ''
endfunction
endif

" Only use libclang if the user clearly show intent to do so for now
if !exists('g:clang_use_library')
let g:clang_use_library = (has('python') && exists('g:clang_library_path'))
10 changes: 6 additions & 4 deletions plugin/libclang.py
Original file line number Diff line number Diff line change
@@ -16,13 +16,15 @@ def getCurrentFile():
return (vim.current.buffer.name, file)

def getCurrentTranslationUnit(update = False):
userOptionsGlobal = vim.eval("g:clang_user_options").split(" ")
userOptionsLocal = vim.eval("b:clang_user_options").split(" ")
args = userOptionsGlobal + userOptionsLocal

currentFile = getCurrentFile()
fileName = vim.current.buffer.name

userOptionsGlobal = vim.eval("g:clang_user_options").split(" ")
userOptionsLocal = vim.eval("b:clang_user_options").split(" ")
userOptionsPerFile = vim.eval(
"g:clang_per_file_user_options('%s')" % fileName).split(" ")
args = userOptionsGlobal + userOptionsLocal + userOptionsPerFile

if fileName in translationUnits:
tu = translationUnits[fileName]
if update: