]> git.rmz.io Git - dotfiles.git/blob - vim/ycm_extra_conf.py
weechat: open new buffer in first_gap
[dotfiles.git] / vim / ycm_extra_conf.py
1 import os
2 import shlex
3 import subprocess
4 import ycm_core
5
6 def FlagsForFile( filename, **kwargs ):
7 client_data = kwargs['client_data']
8 cwd = client_data['getcwd()']
9 # These are the compilation flags that will be used in case there's no
10 # compilation database set (by default, one is not set).
11 flags = [
12 '-Wall',
13 # '-Wextra',
14 # '-Wshadow',
15 # '-Werror',
16 # '-Wc++98-compat',
17 # '-Wno-long-long',
18 # '-Wno-variadic-macros',
19 # '-fexceptions',
20 # '-DNDEBUG',
21 '-std=c++11',
22 '-stdlib=libc++',
23 '-x', 'c++',
24 '-I', '.',
25 '-I', './include',
26 '-isystem', '/usr/include/c++/4.9.0',
27 '-isystem', '/usr/include/c++/4.9.0/x86_64-unknown-linux-gnu',
28 '-isystem', '/usr/include/c++/4.9.0/backward',
29 '-isystem', '/usr/lib/clang/3.4.1/include'
30 ]
31 flags += rospack()
32 relative_to = cwd
33 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
34 print flags
35
36 return {
37 'flags': final_flags,
38 'do_cache': True
39 }
40
41 # This function makes it easy to pull in additional flags from rospack
42 def rospack():
43 cmd = ['rospack', 'cflags-only-I']
44 try:
45 out = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE).stdout
46 except:
47 return []
48 line = out.readline()[:-1].split(" ")
49 includes = []
50 for include in line:
51 if include.startswith(os.path.expanduser('~')):
52 includes += ['-I', include]
53 else:
54 includes += ['-isystem', include]
55 return filter(lambda a: a != ' ', includes)
56
57
58 def DirectoryOfThisScript():
59 return os.path.dirname( os.path.abspath( __file__ ) )
60
61 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
62 if not working_directory:
63 return list( flags )
64 new_flags = []
65 make_next_absolute = False
66 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
67 for flag in flags:
68 new_flag = flag
69
70 if make_next_absolute:
71 make_next_absolute = False
72 if not flag.startswith( '/' ):
73 new_flag = os.path.join( working_directory, flag )
74
75 for path_flag in path_flags:
76 if flag == path_flag:
77 make_next_absolute = True
78 break
79
80 if flag.startswith( path_flag ):
81 path = flag[ len( path_flag ): ]
82 new_flag = path_flag + os.path.join( working_directory, path )
83 break
84
85 if new_flag:
86 new_flags.append( new_flag )
87 return new_flags
88