From b54af0b2b851ee0b809f5e696f00939091361cb7 Mon Sep 17 00:00:00 2001 From: Vahagn Khachatryan Date: Thu, 30 Apr 2015 11:33:42 +0400 Subject: [PATCH] Update CF5-compile. --- .../{cf5-compiler.vim => cf5-compile.vim} | 130 ++++++++++++++---- 1 file changed, 103 insertions(+), 27 deletions(-) rename vim/plugin/{cf5-compiler.vim => cf5-compile.vim} (51%) diff --git a/vim/plugin/cf5-compiler.vim b/vim/plugin/cf5-compile.vim similarity index 51% rename from vim/plugin/cf5-compiler.vim rename to vim/plugin/cf5-compile.vim index f6c06b3..1c84d0a 100755 --- a/vim/plugin/cf5-compiler.vim +++ b/vim/plugin/cf5-compile.vim @@ -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 " -" 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 -" =0 - no output window opened. -" =1 - ouput window opened. +" Summary: Vim plugin to compile the edited files and run it. +" +" 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 :call CF5Compile(1) +" map :call CF5Compile(0) +" +" 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') finish endif 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. " -function! s:initDefaults() - let g:cf5output=0 - let g:argv="" - let g:pyflags="" - let g:cppflags="" - let g:wcppflags="/O2 /EHsc /DWIN32" - let g:lcppflags="-O2" - let g:ldflags="" - let g:wldflags="" - let g:ldlibpath="" -endfunction +let g:argv="" +let g:flags="" +let g:pyflags="" +let g:cppflags="" +let g:wcppflags="/O2 /EHsc /DWIN32" +let g:lcppflags="-O2" +let g:ldflags="" +let g:wldflags="" +let g:ldlibpath="" +" +" This is an experimental option. +" =0 - no output window opened. +" =1 - output window opened. +" +let g:cf5output=0 " " Microsoft Visual C++ @@ -119,6 +182,17 @@ function! s:InterpretPython(run) endif 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) if &filetype=="c" || &filetype=="cpp" if has("win32") || has("win64") @@ -133,6 +207,9 @@ function! s:Compile(run) if &filetype=="java" call s:CompileJava(a:run) endif + if &filetype=="matlab" + call s:InterpretMatlab(a:run) + endif endfunction " @@ -200,13 +277,12 @@ function! CF5Compile(run) return endif " - " First init global variables to let cf5-opt override it. - " - call s:initDefaults() - " " Set source specific compiler options. + " let-modeline.vim should be loaded for FirstModeLine. " - call FirstModeLine() + if exists('*FirstModeLine') + call FirstModeLine() + endif " " Clear output window "