-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmakerc.vim
More file actions
71 lines (59 loc) · 1.78 KB
/
cmakerc.vim
File metadata and controls
71 lines (59 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
" For cdelledonne/vim-cmake
" let g:cmake_statusline = 1
" let g:cmake_root_markers = ['CMakeLists.txt']
" let g:cmake_generate_options=['-DCMAKE_EXPORT_COMPILE_COMMANDS=1', '-B', 'build']
" let g:cmake_build_dir_location='./build'
" augroup vim-cmake-group
" autocmd! User CMakeBuildSucceeded CMakeClose
" augroup END
" For ReverentEngineer/vim-cmake
let g:cmake_args='-DCMAKE_EXPORT_COMPILE_COMMANDS=1'
command! CMakeRun call s:CMakeRun()
command! CMakeRunAsync call s:CMakeRunAsync()
" Run target in a terminal buffer (interactive)
function! s:CMakeRun()
let l:target = s:FindCMakeTarget()
if empty(l:target)
echoerr "No add_executable() target found in CMakeLists.txt"
return
endif
let l:cmd = "./build/" . l:target
" Open terminal buffer and run
execute "terminal " . l:cmd
endfunction
" Run target async (logs output into :messages)
function! s:CMakeRunAsync()
let l:target = s:FindCMakeTarget()
if empty(l:target)
echoerr "No add_executable() target found in CMakeLists.txt"
return
endif
let l:cmd = ["./build/" . l:target]
call job_start(l:cmd, {})
endfunction
" Extract first add_executable() target
function! s:FindCMakeTarget()
let l:lines = readfile("CMakeLists.txt")
for l:line in l:lines
if l:line =~? 'add_executable'
let l:match = matchlist(l:line, 'add_executable\s*(\s*\([A-Za-z0-9_.-]\+\)')
if len(l:match) > 1
return l:match[1]
endif
elseif l:line =~? 'project'
let l:match = matchlist(l:line, 'project\s*(\s*\([A-Za-z0-9_.-]\+\)')
if len(l:match) > 1
return l:match[1]
endif
endif
endfor
return ''
endfunction
" Handle async job output
function! s:JobOutput(tag, data)
for l:line in a:data
if !empty(l:line)
echom a:tag . ': ' . l:line
endif
endfor
endfunction