Try to execute run-cpp if editing a C/C++ file
This commit is contained in:
parent
05c46303c8
commit
4b6d506d7b
47
.vimrc
47
.vimrc
|
@ -1301,8 +1301,10 @@ endfu
|
|||
fu! RunProgramInDirectory(starting_path, file_exe_name) abort
|
||||
|
||||
let l:search_path = a:starting_path
|
||||
let l:ext = tolower(expand('%:e'))
|
||||
let l:also_search_for_cpp_run_script = 0 " Covers the case of having a run-cpp file in a jai project.
|
||||
|
||||
if tolower(expand('%:e')) == "jai"
|
||||
if l:ext == "jai"
|
||||
" Check if we're editing inside a modules file and if so then get a
|
||||
" path that takes us outside of it. We'll use that path for finding an
|
||||
" exe or run script.
|
||||
|
@ -1326,6 +1328,8 @@ fu! RunProgramInDirectory(starting_path, file_exe_name) abort
|
|||
|
||||
let l:search_path = l:module_root_path
|
||||
endif
|
||||
elseif l:ext == "cpp" || l:ext == "c" || l:ext == "h" || l:ext == "inc"
|
||||
let l:also_search_for_cpp_run_script = 1
|
||||
endif
|
||||
|
||||
let l:search_path = fnamemodify(l:search_path, ':p') " Normalize the path just in case.
|
||||
|
@ -1338,35 +1342,36 @@ fu! RunProgramInDirectory(starting_path, file_exe_name) abort
|
|||
" If nothing is found after exhausting the search then we start over and
|
||||
" find the first exe with any name.
|
||||
|
||||
fu! TryRun(path) abort
|
||||
if filereadable(a:path)
|
||||
exec "AsyncRun! " . a:path
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfu
|
||||
|
||||
let l:current_path = l:search_path
|
||||
while 1
|
||||
" Run script has higher priority over an exe named after the current file.
|
||||
let l:search = l:current_path . 'run'
|
||||
if filereadable(l:search)
|
||||
exec "AsyncRun! " . l:search
|
||||
return 1
|
||||
" run script
|
||||
if l:also_search_for_cpp_run_script
|
||||
if TryRun(l:current_path . 'run-cpp') | return 1 | endif
|
||||
endif
|
||||
if TryRun(l:current_path . 'run') | return 1 | endif
|
||||
|
||||
" run_tree/run script
|
||||
if l:also_search_for_cpp_run_script
|
||||
if TryRun(l:current_path . 'run_tree/run-cpp') | return 1 | endif
|
||||
endif
|
||||
if TryRun(l:current_path . 'run_tree/run') | return 1 | endif
|
||||
|
||||
" filename exe
|
||||
let l:search = l:current_path . a:file_exe_name
|
||||
if filereadable(l:search)
|
||||
exec "AsyncRun! " . l:search
|
||||
return 1
|
||||
endif
|
||||
if TryRun(l:current_path . a:file_exe_name) | return 1 | endif
|
||||
|
||||
" bin/filename exe
|
||||
let l:search = l:current_path . 'bin/' . a:file_exe_name
|
||||
if filereadable(l:search)
|
||||
exec "AsyncRun! " . l:search
|
||||
return 1
|
||||
endif
|
||||
if TryRun(l:current_path. 'bin/' . a:file_exe_name) | return 1 | endif
|
||||
|
||||
" run_tree/filename exe
|
||||
let l:search = l:current_path . 'run_tree/' . a:file_exe_name
|
||||
if filereadable(l:search)
|
||||
exec "AsyncRun! " . l:search
|
||||
return 1
|
||||
endif
|
||||
if TryRun(l:current_path. 'run_tree/' . a:file_exe_name) | return 1 | endif
|
||||
|
||||
" Only go back a directory if the current path doesn't have a .git folder or we're not in a root drive path.
|
||||
if isdirectory(l:current_path . '.git') || IsRootDrive(l:current_path)
|
||||
|
|
Loading…
Reference in New Issue
Block a user