Merge branch 'master' of bitbucket.org:vishap/scripts
This commit is contained in:
@@ -1,37 +1,100 @@
|
|||||||
|
" Copyright (c) 2014 Vahagn Khachatryan
|
||||||
"
|
"
|
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
" of this software and associated documentation files (the "Software"), to deal
|
||||||
|
" in the Software without restriction, including without limitation the rights
|
||||||
|
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
" copies of the Software, and to permit persons to whom the Software is
|
||||||
|
" furnished to do so, subject to the following conditions:
|
||||||
|
"
|
||||||
|
" The above copyright notice and this permission notice shall be included in
|
||||||
|
" all copies or substantial portions of the Software.
|
||||||
|
"
|
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
" THE SOFTWARE.
|
||||||
|
"
|
||||||
|
" Name: cf5-compile.vim
|
||||||
|
" Version: 1.0.1
|
||||||
|
" Authors: Vahagn Khachatryan <vahagn DOT khachatryan AT gmail DOT com>
|
||||||
"
|
"
|
||||||
" Functions to compile and link a single c/cpp/java files.
|
" Licence: http://www.opensource.org/licenses/mit-license.php
|
||||||
|
" The MIT License
|
||||||
"
|
"
|
||||||
" let g:cf5output
|
" Summary: Vim plugin to compile the edited files and run it.
|
||||||
" =0 - no output window opened.
|
"
|
||||||
" =1 - ouput window opened.
|
" Description:
|
||||||
|
" Functions to compile/link and run a single c/cpp/java/..etc
|
||||||
|
" file based programs. It's irreplaceable for small tests or
|
||||||
|
" experiments.
|
||||||
|
"
|
||||||
|
" How To Use
|
||||||
|
" --------------
|
||||||
|
" Put this file into vim plugin directory. For linux users should
|
||||||
|
" be $HOME/.vim/plugin.
|
||||||
|
" In your .vimrc file add
|
||||||
|
"
|
||||||
|
" map <silent> <C-F5> :call CF5Compile(1)<CR>
|
||||||
|
" map <silent> <F5> :call CF5Compile(0)<CR>
|
||||||
|
"
|
||||||
|
" This will allow Ctrl-F5 to "compile and run" and F5 to only
|
||||||
|
" "compile" the file. Please, note that "filetype" is used to
|
||||||
|
" define the compiler/interpreter used.
|
||||||
|
"
|
||||||
|
" The value of the following variables are used while compiling
|
||||||
|
" a file:
|
||||||
|
" g:argv - command line arguments to pass to program.
|
||||||
|
" g:pyflags - flags to pass to python interpreter.
|
||||||
|
" g:cppflags - flags to pass to c++ compiler.
|
||||||
|
" g:wcppflags - flags to pass to (windows) compiler.
|
||||||
|
" g:lcppflags - flags to pass to (linux) compiler.
|
||||||
|
" g:ldflags - flags to pass to linker.
|
||||||
|
" g:ldlibpath - paths to add to PATH or LD_LIBRARY_PATH.
|
||||||
|
"
|
||||||
|
" I personally use this script with let-modeline.vim. The last
|
||||||
|
" allows to define some of compiler options right in the file. For
|
||||||
|
" example I have the following header in some of my cpp files:
|
||||||
|
" /*
|
||||||
|
" VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
|
||||||
|
" VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
|
||||||
|
" VIM: let g:cppflags=g:Iboost.g:Itbb
|
||||||
|
" VIM: let g:ldflags=g:Lboost.g:Ltbb.g:tbbmalloc.g:tbbmproxy
|
||||||
|
" VIM: let g:ldlibpath=g:Bboost.g:Btbb
|
||||||
|
" VIM: let g:argv=""
|
||||||
|
" */
|
||||||
|
"
|
||||||
|
" You might also consider using independence.vim or localvimrc.vim
|
||||||
|
" in order to configure the plugin for a particular directory.
|
||||||
|
"
|
||||||
|
" Enjoy.
|
||||||
"
|
"
|
||||||
if exists('g:loaded_cf5_compiler')
|
if exists('g:loaded_cf5_compiler')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_cf5_compiler = 1
|
let g:loaded_cf5_compiler = 1
|
||||||
|
|
||||||
"
|
|
||||||
" Make sure let-modeline.vim is loaded.
|
|
||||||
"
|
|
||||||
if !exists('*FirstModeLine')
|
|
||||||
runtime plugin/let-modeline.vim
|
|
||||||
endif
|
|
||||||
|
|
||||||
"
|
"
|
||||||
" Init global variables with default values.
|
" Init global variables with default values.
|
||||||
"
|
"
|
||||||
function! s:initDefaults()
|
let g:argv=""
|
||||||
let g:cf5output=0
|
let g:flags=""
|
||||||
let g:argv=""
|
let g:pyflags=""
|
||||||
let g:pyflags=""
|
let g:cppflags=""
|
||||||
let g:cppflags=""
|
let g:wcppflags="/O2 /EHsc /DWIN32"
|
||||||
let g:wcppflags="/O2 /EHsc /DWIN32"
|
let g:lcppflags="-O2"
|
||||||
let g:lcppflags="-O2"
|
let g:ldflags=""
|
||||||
let g:ldflags=""
|
let g:wldflags=""
|
||||||
let g:wldflags=""
|
let g:ldlibpath=""
|
||||||
let g:ldlibpath=""
|
"
|
||||||
endfunction
|
" This is an experimental option.
|
||||||
|
" =0 - no output window opened.
|
||||||
|
" =1 - output window opened.
|
||||||
|
"
|
||||||
|
let g:cf5output=0
|
||||||
|
|
||||||
"
|
"
|
||||||
" Microsoft Visual C++
|
" Microsoft Visual C++
|
||||||
@@ -119,6 +182,17 @@ function! s:InterpretPython(run)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:InterpretMatlab(run)
|
||||||
|
" Interpret it
|
||||||
|
let cmd = "octave " . g:flags . " " . expand("%") . ' ' . g:argv
|
||||||
|
echo cmd
|
||||||
|
let cout = system( cmd )
|
||||||
|
echo cout
|
||||||
|
if v:shell_error
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:Compile(run)
|
function! s:Compile(run)
|
||||||
if &filetype=="c" || &filetype=="cpp"
|
if &filetype=="c" || &filetype=="cpp"
|
||||||
if has("win32") || has("win64")
|
if has("win32") || has("win64")
|
||||||
@@ -133,6 +207,9 @@ function! s:Compile(run)
|
|||||||
if &filetype=="java"
|
if &filetype=="java"
|
||||||
call s:CompileJava(a:run)
|
call s:CompileJava(a:run)
|
||||||
endif
|
endif
|
||||||
|
if &filetype=="matlab"
|
||||||
|
call s:InterpretMatlab(a:run)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"
|
"
|
||||||
@@ -200,13 +277,12 @@ function! CF5Compile(run)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
"
|
"
|
||||||
" First init global variables to let cf5-opt override it.
|
|
||||||
"
|
|
||||||
call s:initDefaults()
|
|
||||||
"
|
|
||||||
" Set source specific compiler options.
|
" Set source specific compiler options.
|
||||||
|
" let-modeline.vim should be loaded for FirstModeLine.
|
||||||
"
|
"
|
||||||
call FirstModeLine()
|
if exists('*FirstModeLine')
|
||||||
|
call FirstModeLine()
|
||||||
|
endif
|
||||||
"
|
"
|
||||||
" Clear output window
|
" Clear output window
|
||||||
"
|
"
|
||||||
Reference in New Issue
Block a user