grep ".*\.cpp" -R build/
SET(CMAKE_DEPENDS_CHECK_CXX "/home/..../brushcombo.cpp" "/home/.../build/CMakeFiles/kdots.dir/brushcombo.o" ... )
sub cmake_project_files { my $dir = shift; my @dependencies = File::Find::Rule->file() ->name("DependInfo.cmake") ->in($dir); my @accum = (); foreach my $filename(@dependencies) { open(FILE, $filename); my @data = <FILE>; push (@accum, src_files(\@data)); close(FILE); } return @accum; } sub src_files { my @result = (); foreach my $line(@{(shift)}) { if ($line =~ m/\s*\"(([a-zA-Z_\/]+)\/([a-zA-Z_]+\.(cpp|cc))).*/) { push(@result, $1); } } return @result; }
if !has('perl') echo "Error: perl not found" finish endif
function! s:cmake_project_window() vnew badd CMakeProject buffer CMakeProject " , , , VIM setlocal buftype=nofile ...
let s:cmake_project_bufname = bufname("%")
perl << EOF " Python Ruby use lib "$ENV{'HOME'}/.vim/plugin/cmake-project"; use cmakeproject; my $dir = VIM::Eval('g:cmake_project_build_dir'); my @result = cmakeproject::cmake_project_files($dir); VIM::DoCommand("let s:cmake_project_files = []"); foreach $filename(@result) { if (-e $filename) { VIM::DoCommand("call insert(s:cmake_project_files, \'$filename\')"); } } EOF
let s:cmake_project_file_tree = {} for fullpath in s:cmake_project_files let current_tree = s:cmake_project_file_tree let cmake_project_args = split(fullpath, '\/') let filename = remove(cmake_project_args, -1) for path in cmake_project_args if !has_key(current_tree, path) let current_tree[path] = {} " endif let current_tree = current_tree[path] endfor let current_tree[filename] = 1 endfor call s:cmake_project_print_bar(s:cmake_project_file_tree, 0)
function! s:cmake_project_print_bar(tree, level) for pair in items(a:tree) if type(pair[1]) == type({}) " let name = s:cmake_project_indent(a:level) . "-" . pair[0] call append(line('$'), name . "/") " "-<dir>/" let newlevel = a:level + 1 call s:cmake_project_print_bar(pair[1], newlevel) " . else " let name = s:cmake_project_indent(a:level) . pair[0] call append(line('$'), name) endif endfor endfunction
command -nargs=0 -bar CMakePro call s:cmake_project_window()
command -nargs=1 -bar CMake call s:cmake_project_cmake(<f-args>) function! s:cmake_project_cmake(srcdir) if !isdirectory(a:srcdir) echo "This directory not exists!" . a:srcdir return endif let s:cmake_project_dir = a:srcdir exec "cd" a:srcdir if !isdirectory(g:cmake_project_build_dir) call mkdir(g:cmake_project_build_dir) endif cd build exec "!cmake" "../" cd .. call s:cmake_project_window() endfunction
autocmd CursorMoved * call s:cmake_project_cursor_moved()
function! s:cmake_project_cursor_moved() if exists('s:cmake_project_bufname') && bufname('%') == s:cmake_project_bufname <code> endif endfunction
let cmake_project_filename = getline('.') let fullpath = s:cmake_project_var(cmake_project_filename) let highlight_pattern = substitute(fullpath, '[.]', '\\.', '') let highlight_pattern = substitute(highlight_pattern, '[/]', '\\/', '') exec "match" "ErrorMsg /" . highlight_pattern . "/"
let level = s:cmake_project_level(cmake_project_filename) let level -= 1 let finding_line = s:cmake_project_find_parent(level, line('.')) while level > -1 let path = s:cmake_project_var(getline(finding_line)) let fullpath = path . fullpath let level -= 1 let finding_line = s:cmake_project_find_parent(level, finding_line) endwhile let fullpath = "/" . fullpath "
if filereadable(fullpath) wincmd l exec 'e' fullpath setf cpp endif endif
Source: https://habr.com/ru/post/153873/
All Articles