More tweaks to the vimrc run function
This commit is contained in:
parent
c05131d38f
commit
7b031d3127
68
vimrc
68
vimrc
|
@ -1251,29 +1251,63 @@ function! Build(optimized=0, silent=0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! RunProgram()
|
function! RunProgram()
|
||||||
if filereadable("run")
|
let l:ran = 0
|
||||||
exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
|
let l:ext = tolower(expand('%:e'))
|
||||||
else
|
let l:path_to_use = ""
|
||||||
let l:ext = tolower(expand('%:e'))
|
|
||||||
if l:ext == "jai"
|
|
||||||
if filereadable(expand('%:p:r') . '.exe')
|
|
||||||
exec "AsyncRun! " . expand('%:p:r') . ".exe"
|
|
||||||
else
|
|
||||||
if tolower(expand('%:h')) == "modules"
|
|
||||||
" This is likely a jai module inside a project. Check for an " exe one directory back.
|
|
||||||
let l:files = systemlist('ls ' . expand('%:p:h') . '/../*.exe 2>/dev/null')
|
|
||||||
else
|
|
||||||
let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null')
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
if l:ext == "jai"
|
||||||
|
" Maybe the current file has an exe, i.e. wasn't compiled with a build script.
|
||||||
|
if filereadable(expand('%:p:r') . '.exe')
|
||||||
|
let l:ran = 1
|
||||||
|
exec "AsyncRun! " . expand('%:p:r') . ".exe"
|
||||||
|
elseif tolower(expand('%:h:t')) == "modules" || tolower(expand('%:h:h:t')) == "modules"
|
||||||
|
" This is likely a jai module inside a project. We will want to do the exe/run script checks in the parent project folder.
|
||||||
|
" The :h:h tests for a module inside a folder, e.g. modules/Basic/module.jai
|
||||||
|
echo "module"
|
||||||
|
if tolower(expand('%:h:t')) == "modules"
|
||||||
|
let l:path_to_use = "/.."
|
||||||
|
else
|
||||||
|
let l:path_to_use = "/../.."
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
elseif l:ext == "py"
|
||||||
|
let l:ran = 1
|
||||||
|
exec "AsyncRun! python %"
|
||||||
|
endif
|
||||||
|
|
||||||
|
if l:ran == 0
|
||||||
|
" First check the current file's directory (and one directory back)
|
||||||
|
" for a run script, falling back to the current working directory (and
|
||||||
|
" one directory back) of the editor.
|
||||||
|
if filereadable(expand('%:h') . '/run')
|
||||||
|
echo "file here"
|
||||||
|
exec "AsyncRun! " . expand('%:h') . "/run"
|
||||||
|
elseif filereadable(expand('%:h') . '/../run')
|
||||||
|
" Handles editing a file in a code/ or src/ and there's a run script one directory back.
|
||||||
|
echo "file one back"
|
||||||
|
exec "AsyncRun! " . expand('%:h') . "/../run"
|
||||||
|
elseif filereadable("run")
|
||||||
|
echo "cwd here"
|
||||||
|
exec "AsyncRun! ./run"
|
||||||
|
elseif filereadable("../run")
|
||||||
|
" Handles editing a file in a code/ or src/ and there's a run script one directory back.
|
||||||
|
echo "cwd one back"
|
||||||
|
exec "AsyncRun! ../run"
|
||||||
|
else
|
||||||
|
" Final attempt is to run any exe that's found nearby.
|
||||||
|
" We start with an exe relative to the open file's path.
|
||||||
|
let l:files = systemlist('ls '.expand('%:h').''.l:path_to_use.'/*.exe 2>/dev/null')
|
||||||
|
if len(l:files) > 0
|
||||||
|
exec "AsyncRun! " . l:files[0]
|
||||||
|
else
|
||||||
|
" Last attempt is any exe in the current working directory.
|
||||||
|
let l:files = systemlist('ls *.exe 2>/dev/null')
|
||||||
if len(l:files) > 0
|
if len(l:files) > 0
|
||||||
exec "AsyncRun! " . l:files[0]
|
exec "AsyncRun! " . l:files[0]
|
||||||
else
|
else
|
||||||
call PrintError("No exe found. Compile first?")
|
call PrintError("No exe or run script found!")
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
elseif l:ext == "py"
|
|
||||||
exec "AsyncRun! python %"
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
Loading…
Reference in New Issue
Block a user