cf5 elaborated. p4 shortcuts added

This commit is contained in:
Vahagn Khachatryan
2013-06-19 18:28:01 +05:00
parent b2d25de6ba
commit 96acfe3416
3 changed files with 119 additions and 27 deletions

View File

@@ -1,6 +1,10 @@
"
" {{{1
" Functions to compile and link a single c/cpp file.
"
" let g:cf5output
" =0 - no output window opened.
" =1 - ouput window opened.
"
"if exists("g:loaded_vahagn_compiler") | finish | endif
let g:loaded_vahagn_compiler = 1
@@ -12,12 +16,9 @@ if !exists('*FirstModeLine')
endif
"
" Windows
" Windows {{{1
"
let g:argv=""
let g:cppflags=""
let g:wcppflags="/O2 /EHsc /DWIN32"
function! s:CompileMSVC()
function! s:CompileMSVC() "{{{2
let exename=expand("%:p:r:s,$,.exe,")
let srcname=expand("%")
" compile it
@@ -36,7 +37,7 @@ function! s:CompileMSVC()
echo eout
endfunction
function! s:CompileJava()
function! s:CompileJava() "{{{2
" compile it
let cmd = "javac " . g:javaflags . " " . expand("%")
echo cmd
@@ -54,7 +55,7 @@ function! s:CompileJava()
echo eout
endfunction
function! s:CompileWindows()
function! s:CompileWindows() "{{{2
let ext=expand("%:e")
if ext=="java"
call s:CompileJava()
@@ -64,43 +65,109 @@ function! s:CompileWindows()
endif
endfunction
"
" Linux {{{1
"
" Linux
"
let g:lcppflags="-O2"
function! s:CompileGCC()
function! s:CompileGCC() "{{{2
let exename=expand("%:p:r:s,$,.exe,")
let srcname=expand("%")
" compile it
let ccline="g++ ".g:cppflags." ".g:lcppflags." ".srcname." -o".exename
echo ccline
call s:appendOutput(ccline)
let cout = system( ccline )
if v:shell_error
echo cout
call s:appendOutput(cout)
return
endif
echo cout
call s:appendOutput(cout)
" run it
let cmdline="LD_LIBRARY_PATH=".g:ldlibrarypath.":".$LD_LIBRARY_PATH." ".exename
echo cmdline
let cmdline="LD_LIBRARY_PATH=".g:ldlibpath.":".$LD_LIBRARY_PATH." ".exename." ".g:argv
call s:appendOutput(cmdline)
let eout = system( cmdline )
echo eout
call s:appendOutput(eout)
endfunction
function! s:CompileLinux()
function! s:CompileLinux() "{{{2
call s:CompileGCC()
endfunction
"
" Load compile instructions and call window or linux compiler.
" Output Window {{{1
"
" Create output window. {{{2
"
function! s:getOutputWindow()
if !exists("w:outputwin")
let w:outputwin=tempname().'_output'
endif
let obuff = w:outputwin
let winnr = bufwinnr('^'.obuff.'$')
if (winnr < 0)
execute "below 10new ".obuff
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
" setlocal nomodifiable
let winnr = bufwinnr('^'.obuff.'$')
endif
return winnr
endfunction
"
" Append text to output window. {{{2
"
function! s:appendOutput( text )
if exists("g:cf5output") && (g:cf5output==1)
let cwinnr = winnr()
let owinnr = s:getOutputWindow()
" setlocal modifiable
execute owinnr . 'wincmd w'
execute 'normal! Go'.a:text
" setlocal nomodifiable
execute cwinnr.'wincmd w'
else
echo a:text
endif
endfunction
"
" Clear text from output window. {{{2
"
function! s:clearOutputWindow()
if exists("g:cf5output") && (g:cf5output==1)
let cwinnr = winnr()
let owinnr = s:getOutputWindow()
" setlocal modifiable
execute owinnr . 'wincmd w'
execute 'normal ggdG'
" setlocal nomodifiable
execute cwinnr . 'wincmd w'
endif
endfunction
"
" Init global variables with default values. {{{1
"
function! s:initDefaults()
let g:cf5output=0
let g:argv=""
let g:cppflags=""
let g:wcppflags="/O2 /EHsc /DWIN32"
let g:lcppflags="-O2"
let g:ldlibpath=""
endfunction
"
" Load compile instructions and call window or linux compiler. {{{1
"
function! CF5Compile()
"
" First init global variables to let cf5-opt override it.
"
call s:initDefaults()
"
" Source compile-opt.vim if exists.
"
let copt=expand("%:p:h")."/compile-opt.vim"
if filereadable(copt)
source copt
verbose let l:copt=expand("%:p:h")."/cf5-opt.vim"
if filereadable(l:copt)
exec ":source ".l:copt
endif
"
" Set source specific compiler options.
@@ -110,6 +177,10 @@ function! CF5Compile()
" execute g:cf5script
"endif
"
" Clear output window
"
call s:clearOutputWindow()
"
" Compile.
"
if has("win32") || has("win64")
@@ -119,5 +190,3 @@ function! CF5Compile()
endif
endfunction