From 2e07b0c85f310df46873a7173bf9f48278698b76 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Wed, 1 Mar 2023 15:27:26 -0500 Subject: [PATCH] vim build and run updates --- vimrc | 62 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/vimrc b/vimrc index 9a0e678..79526ae 100644 --- a/vimrc +++ b/vimrc @@ -980,9 +980,9 @@ endfunction " Set the intial light/dark mode. if g:campo_light_dark_mode =~ 'light' - call ChangeLightDarkMode('light', 1) + call ChangeLightDarkMode('light', 1) else - call ChangeLightDarkMode('dark', 1) + call ChangeLightDarkMode('dark', 1) endif " Open the current color scheme for editing. @@ -1152,46 +1152,67 @@ function! StopRunTask() endfunction function! Build(optimized=0, silent=0) - let l:ext = tolower(expand('%:e')) - let l:parent_dir = expand('%:p:h') let l:async_cmd = "AsyncRun! " if a:silent let l:async_cmd .= "-post=call\\ HideAsyncResults() " endif + let l:is_jai = 0 let l:cmd = "" - if filereadable(l:parent_dir . "/build.jai") + + let l:ext = tolower(expand('%:e')) + let l:current_dir = expand('%:h') + let l:parent_dir = expand('%:p:h') + + " Check if this is a jai module with a build.jai one directory back. This + " only works when the file is directly inside the modules folder. + let l:jai_module_with_build = (tolower(l:current_dir) == "modules") && filereadable(l:current_dir . "/../build.jai") + + if (l:jai_module_with_build == 1) || filereadable(l:parent_dir . "/build.jai") " Jai build file let l:is_jai = 1 - let l:cmd = "jai " . l:parent_dir . "/build.jai " + let l:cmd = "jai " . l:parent_dir . "/" + + if l:jai_module_with_build == 1 + let l:cmd .= "../build.jai" + else + let l:cmd .= "build.jai" + endif + if a:optimized == 1 echo "Compiling release build.jai" - let l:cmd .= "-release " + let l:cmd .= " -release" else echo "Compiling debug build.jai" endif + elseif l:ext == "jai" let l:is_jai = 1 let l:cmd = "jai % " + if a:optimized == 1 echo "Compiling release " . expand('%:t') - let l:cmd .= "-release " + let l:cmd .= " -release" else echo "Compiling debug " . expand('%:t') endif + " If there's a local modules/ directory then we'll import it. if isdirectory(l:parent_dir . "/modules") - let l:cmd .= "-import_dir modules " + let l:cmd .= " -import_dir modules" endif + else let l:cmd .= './build* ' if a:optimized == 1 - let l:cmd .= '-o ' + let l:cmd .= ' -o' endif endif + if l:is_jai let l:cmd .= ' '.g:campo_jai_build_args endif + " I was originally passing -save=2 to AsyncRun! in order to save all " modified files (it just does a `silent! wall` call), but I want ctags to " be generated so we're handling the save ourselves. @@ -1199,18 +1220,29 @@ function! Build(optimized=0, silent=0) exec l:async_cmd . l:cmd endfunction -function! RunExe() - if tolower(expand('%:e')) == "jai" +function! RunProgram() + let l:ext = tolower(expand('%:e')) + if l:ext == "jai" if filereadable(expand('%:p:r') . '.exe') exec "AsyncRun! " . expand('%:p:r') . ".exe" else - let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null') + 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 len(l:files) > 0 exec "AsyncRun! " . l:files[0] else call PrintError("No exe found. Compile first?") endif endif + + elseif l:ext == "py" + exec "AsyncRun! python %" + else exec "AsyncRun! -post=call\\ StopRunTask() ./run %" endif @@ -1237,8 +1269,8 @@ nnoremap :call Build(0, 1) nnoremap bb :call Build(1) " Execute run script -nnoremap br :call RunExe() -nnoremap :call RunExe() +nnoremap br :call RunProgram() +nnoremap :call RunProgram() nnoremap bs :AsyncStop