vim build and run updates
This commit is contained in:
		
							parent
							
								
									d664ba882c
								
							
						
					
					
						commit
						2e07b0c85f
					
				
							
								
								
									
										56
									
								
								vimrc
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								vimrc
									
									
									
									
									
								
							| 
						 | 
					@ -1152,46 +1152,67 @@ function! StopRunTask()
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! Build(optimized=0, silent=0)
 | 
					function! Build(optimized=0, silent=0)
 | 
				
			||||||
    let l:ext = tolower(expand('%:e'))
 | 
					 | 
				
			||||||
    let l:parent_dir  = expand('%:p:h')
 | 
					 | 
				
			||||||
    let l:async_cmd = "AsyncRun! "
 | 
					    let l:async_cmd = "AsyncRun! "
 | 
				
			||||||
    if a:silent
 | 
					    if a:silent
 | 
				
			||||||
        let l:async_cmd .= "-post=call\\ HideAsyncResults() "
 | 
					        let l:async_cmd .= "-post=call\\ HideAsyncResults() "
 | 
				
			||||||
    endif
 | 
					    endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let l:is_jai = 0
 | 
					    let l:is_jai = 0
 | 
				
			||||||
    let l:cmd = ""
 | 
					    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
 | 
					         " Jai build file
 | 
				
			||||||
        let l:is_jai = 1
 | 
					        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
 | 
					        if a:optimized == 1
 | 
				
			||||||
            echo "Compiling release build.jai"
 | 
					            echo "Compiling release build.jai"
 | 
				
			||||||
            let l:cmd .= "-release "
 | 
					            let l:cmd .= " -release"
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            echo "Compiling debug build.jai"
 | 
					            echo "Compiling debug build.jai"
 | 
				
			||||||
        endif
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    elseif l:ext == "jai"
 | 
					    elseif l:ext == "jai"
 | 
				
			||||||
        let l:is_jai = 1
 | 
					        let l:is_jai = 1
 | 
				
			||||||
        let l:cmd = "jai % "
 | 
					        let l:cmd = "jai % "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if a:optimized == 1
 | 
					        if a:optimized == 1
 | 
				
			||||||
            echo "Compiling release " . expand('%:t')
 | 
					            echo "Compiling release " . expand('%:t')
 | 
				
			||||||
            let l:cmd .= "-release "
 | 
					            let l:cmd .= " -release"
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            echo "Compiling debug " . expand('%:t')
 | 
					            echo "Compiling debug " . expand('%:t')
 | 
				
			||||||
        endif
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        " If there's a local modules/ directory then we'll import it.
 | 
					        " If there's a local modules/ directory then we'll import it.
 | 
				
			||||||
        if isdirectory(l:parent_dir . "/modules")
 | 
					        if isdirectory(l:parent_dir . "/modules")
 | 
				
			||||||
            let l:cmd .= "-import_dir modules "
 | 
					            let l:cmd .= " -import_dir modules"
 | 
				
			||||||
        endif
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        let l:cmd .= './build* '
 | 
					        let l:cmd .= './build* '
 | 
				
			||||||
        if a:optimized == 1
 | 
					        if a:optimized == 1
 | 
				
			||||||
            let l:cmd .= '-o '
 | 
					            let l:cmd .= ' -o'
 | 
				
			||||||
        endif
 | 
					        endif
 | 
				
			||||||
    endif
 | 
					    endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if l:is_jai
 | 
					    if l:is_jai
 | 
				
			||||||
        let l:cmd .= ' '.g:campo_jai_build_args
 | 
					        let l:cmd .= ' '.g:campo_jai_build_args
 | 
				
			||||||
    endif
 | 
					    endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    " I was originally passing -save=2 to AsyncRun! in order to save all
 | 
					    " 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
 | 
					    " modified files (it just does a `silent! wall` call), but I want ctags to
 | 
				
			||||||
    " be generated so we're handling the save ourselves.
 | 
					    " 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
 | 
					    exec l:async_cmd . l:cmd
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! RunExe()
 | 
					function! RunProgram()
 | 
				
			||||||
    if tolower(expand('%:e')) == "jai"
 | 
					    let l:ext = tolower(expand('%:e'))
 | 
				
			||||||
 | 
					    if l:ext == "jai"
 | 
				
			||||||
        if filereadable(expand('%:p:r') . '.exe')
 | 
					        if filereadable(expand('%:p:r') . '.exe')
 | 
				
			||||||
            exec "AsyncRun! " . 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
 | 
					            else
 | 
				
			||||||
                let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null')
 | 
					                let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null')
 | 
				
			||||||
 | 
					            endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            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 found. Compile first?")
 | 
				
			||||||
            endif
 | 
					            endif
 | 
				
			||||||
        endif
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    elseif l:ext == "py"
 | 
				
			||||||
 | 
					        exec "AsyncRun! python %"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
 | 
					        exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
 | 
				
			||||||
    endif
 | 
					    endif
 | 
				
			||||||
| 
						 | 
					@ -1237,8 +1269,8 @@ nnoremap <silent><F8> :call Build(0, 1)<cr>
 | 
				
			||||||
nnoremap <leader>bb :call Build(1)<cr>
 | 
					nnoremap <leader>bb :call Build(1)<cr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" Execute run script
 | 
					" Execute run script
 | 
				
			||||||
nnoremap <silent><leader>br :call RunExe()<cr>
 | 
					nnoremap <silent><leader>br :call RunProgram()<cr>
 | 
				
			||||||
nnoremap <silent><F9> :call RunExe()<cr>
 | 
					nnoremap <silent><F9> :call RunProgram()<cr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
nnoremap <leader>bs :AsyncStop<cr>
 | 
					nnoremap <leader>bs :AsyncStop<cr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user