blob: 04ac497704a4fab561efacc6561ace4a1c5d9a35 [file] [log] [blame]
Chatsiri Rattanac4b848b2012-10-13 16:09:44 +07001*SingleCompile.txt*
2
3File: SingleCompile.txt
4Version: 2.10.6
5Original Author and Current Maintainer: Hong Xu <dev@hong.me>
6Last Change: 15 May 2012
7Homepage: http://www.vim.org/scripts/script.php?script_id=3115
8GitHub repo: https://github.com/xuhdev/SingleCompile
9Description: Make it more convenient to compile or run a single source file.
10License:
11 Copyright (C) 2010-2012 Hong Xu
12
13 This file is part of SingleCompile.
14
15 SingleCompile is free software: you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 SingleCompile is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with SingleCompile. If not, see <http://www.gnu.org/licenses/>.
27
28CONTENTS~
29 *SingleCompile-contents*
30----------------------------------------------------------------------------
311. Overview |SingleCompile-overview|
322. Installation |SingleCompile-installation|
333. Commands |SingleCompile-commands|
344. Settings |SingleCompile-settings|
355. Key-mappings |SingleCompile-key-mapping|
366. Compiler template |SingleCompile-compiler-template|
377. Supporting plugins |SingleCompile-supporting-plugins|
388. Advanced |SingleCompile-advanced|
399. Credits |SingleCompile-credits|
4010. Todo |SingleCompile-todo|
41
42
43OVERVIEW~
44 *SingleCompile-overview*
45----------------------------------------------------------------------------
46This plugin is aimed at making it more convenient to compile or run a single
47source file without leaving vim.
48
49A short introduction is available here:
50http://hong-xu.github.com/blog/2012/03/07/use-singlecompile-to-compile-and-run-a-single-source-file-easily-in-vim/
51
52Consider this situation: you have just written a small c source file for a
53small test, but you have to write a Makefile to compile it or exit vim to
54compile it or compile it using "!gcc" without quickfix feature because vim's
55make command only use the "make" command? This plugin will help you out.
56
57Add these key-mappings to your vimrc:
58>
59 nmap <F9> :SCCompile<cr>
60 nmap <F10> :SCCompileRun<cr>
61<
62Note that the two lines here should not have any trailing space. If your file
63type is supported, then press F9 to compile your source file, and press F10 to
64compile and run your source file. If there is a compilation error, and the
65|quickfix| feature is enabled, then you could use |:cope| command to see the
66error list. You may also use ":SCChooseCompiler" command to choose a compiler
67if you have more than one kind of compiler available on you system.
68":SCViewResult" will show you the last run result.
69
70
71Features:
721. Compile or run the source file quickly using |quickfix| feature and
73 |compiler| feature of vim;
742. Compilers and interpreters auto detecting;
753. Fast switch between several installed compilers or interpreters;
764. Multi-language support;
775. Custom your own compiler/interpreter template;
786. View the result of last run command at any time(requires "tee" command);
797. Run the compiled program asynchronously and view the result at any time
80 (see |:SCCompileRunAsync|).
81
82
83Here is a list of built-in supported compilers or interpreter(For some
84compilers/interpreters, you need to set the environment varibles correctly to
85make them available for SingleCompile):
86
87Ada:
88 gnat (GNAT)
89
90bash:
91 bash (Bourne-Again Shell)
92
93C:
94 bcc (Borland C++ Builder), Windows only
95 cc (UNIX C Compiler), UNIX only
96 ch (SoftIntegration Ch)
97 clang (the Clang C and Objective-C compiler)
98 gcc (GNU C Compiler)
99 icc (Intel C++ Compiler)
100 lcc (Little C Compiler)
101 msvc (Microsoft Visual C++ (In PATH)), Windows only
102 msvc80 (Microsoft Visual C++ 2005), Windows only
103 msvc90 (Microsoft Visual C++ 2008), Windows only
104 msvc100 (Microsoft Visual C++ 2010), Windows only
105 open-watcom (Open Watcom C/C++32 Compiler)
106 open64 (Open64 C Compiler), UNIX only
107 pcc (Portable C Compiler)
108 sol-studio (Sun C Compiler(Sun Solaris Studio)), UNIX only
109 tcc (Tiny C Compiler)
110 tcc-run (Tiny C Compiler with "-run" Flag)
111
112C++:
113 bcc (Borland C++ Builder), Windows Only
114 ch (SoftIntegration Ch)
115 clang (the Clang C and Objective-C compiler)
116 g++ (GNU C++ Compiler)
117 icc (Intel C++ Compiler)
118 msvc (Microsoft Visual C++ (In PATH)), Windows only
119 msvc80 (Microsoft Visual C++ 2005), Windows only
120 msvc90 (Microsoft Visual C++ 2008), Windows only
121 msvc100 (Microsoft Visual C++ 2010), Windows only
122 open-watcom (Open Watcom C/C++32 Compiler)
123 open64 (Open64 C++ Compiler), UNIX only
124 sol-studio (Sun C++ Compiler(Sun Solaris Studio)), UNIX only
125
126C#:
127 msvcs(Microsoft Visual C#), Windows Only
128 mono (Mono C# compiler)
129
130cmake:
131 cmake (cmake)
132
133csh:
134 csh (C Shell)
135 tcsh (TENEX C Shell)
136
137D:
138 dmd (DMD Compiler)
139
140dos batch:
141 dosbatch (DOS Batch)
142
143erlang:
144 escript (Erlang Scripting Support)
145
146Fortran:
147 ftn95 (Silverfrost FTN95), Windows only
148 g77 (GNU Fortran 77 Compiler)
149 g95 (G95)
150 gfortran (GNU Fortran Compiler)
151 ifort (Intel Fortran Compiler)
152 open-watcom (Open Watcom Fortran 77/32 Compiler)
153 open64-f90 (Open64 Fortran 90 Compiler), UNIX only
154 open64-f95 (Open64 Fortran 95 Compiler), UNIX only
155 sol-studio-f77 (Sun Fortran 77 Compiler(Sun Solaris Studio)), UNIX only
156 sol-studio-f90 (Sun Fortran 90 Compiler(Sun Solaris Studio)), UNIX only
157 sol-studio-f95 (Sun Fortran 95 Compiler(Sun Solaris Studio)), UNIX only
158
159Haskell:
160 ghc (Glasgow Haskell Compiler)
161 runhaskell (runhaskell)
162
163html:
164 arora (Arora)
165 chrome (Google Chrome)
166 epiphany (Epiphany)
167 firefox (Mozilla Firefox)
168 ie (Microsoft Internet Explorer)
169 konqueror (Konqueror)
170 opera (Opera)
171
172IDL(Interactive Data Language):
173 idl (ITT Visual Information Solutions Interactive Data Language)
174 gdl (GNU Data Language incremental compiler)
175
176Java:
177 gcj (GNU Java Compiler)
178 sunjdk (Sun Java Development Kit)
179
180JavaScript:
181 gjs (Javascript Bindings for GNOME)
182 js (SpiderMonkey, a JavaScript engine written in C)
183 node.js (node.js)
184 rhino (Rhino, a JavaScript engine written in Java)
185
186ksh:
187 ksh (Korn Shell)
188
189LaTeX:
190 latex (LaTeX)
191 pdflatex (pdfLaTeX)
192
193LISP:
194 clisp (GNU CLISP)
195 ecl (Embeddable Common-Lisp)
196 gcl (GNU Common Lisp)
197
198lua:
199 lua (Lua Interpreter)
200
201Makefile:
202 gmake (GNU Make)
203 nmake (Microsoft Program Maintenance Utility)
204 mingw32-make (MinGW32 Make)
205
206Markdown:
207 markdown (text-to-HTML conversion tool)
208 rdiscount (Discount Markdown Processor for Ruby)
209
210Object-C:
211 clang (the Clang C and Objective-C compiler)
212 gcc (GNU Object-C Compiler)
213
214Pascal:
215 fpc (Free Pascal Compiler)
216 gpc (GNU Pascal Compiler)
217
218perl:
219 perl (Perl Interpreter)
220
221PHP:
222 php (PHP Command Line Interface 'CLI')
223
224python:
225 ironpython (IronPython)
226 jython (Jython)
227 pypy (PyPy)
228 python (Python Interpreter)
229 python3 (Python 3 Interpreter)
230
231R:
232 R (R)
233
234reStructuredText:
235 rst2html (reST to HTML)
236
237ruby:
238 ruby (Ruby Interpreter)
239
240sh:
241 ash (Almquist Shell)
242 bash (Bourne-Again Shell)
243 dash (Debian Almquist Shell)
244 ksh (Korn Shell)
245 sh (Bourne Shell)
246 zsh (Z Shell)
247
248tcl:
249 tclsh (Simple shell containing Tcl interpreter)
250
251tcsh:
252 tcsh (TENEX C Shell)
253
254vb script:
255 vb (VB Script Interpreter)
256
257xhtml:
258 arora (Arora)
259 chrome (Google Chrome)
260 chromium (Chromium)
261 epiphany (Epiphany)
262 firefox (Mozilla Firefox)
263 ie (Microsoft Internet Explorer)
264 konqueror (Konqueror)
265 opera (Opera)
266
267zsh:
268 zsh (Z Shell)
269
270You can add your compiler or interpreter support if the compiler or
271interpreter you want is not in the list. See details in the help file.
272
273There are some supporting code in this plugin for Marc Weber's
274vim-addon-actions:
275 http://github.com/MarcWeber/vim-addon-actions
276
277If you find any bug, please report it to xuhdev@gmail.com or submit it on
278the issue tracker:
279https://bitbucket.org/xuhdev/singlecompile/issues
280
281If you've written some templates for some compilers or interpreters which are
282not included as built-in template, and you think they are useful for other
283people, you could send me an email to inform me, and I'll put them in the
284built-in templates.
285
286
287Git repository on github.com: https://github.com/xuhdev/SingleCompile
288Mercurial repository on bitbucket.org: https://bitbucket.org/xuhdev/singlecompile
289
290Follow xuhdev on twitter if you are interested in my development:
291http://twitter.com/xuhdev
292
293
294INSTALLATION~
295 *SingleCompile-installation*
296----------------------------------------------------------------------------
297Download the SingleCompile.zip file and extract it to your vim runtime
298directory(~/.vim on linux and $VIM_INSTALLATION_FOLDER\vimfiles on windows),
299you'd better then use ":helptags" command to generate the help tag(for example
300use ":helptags ~/.vim/doc" on UNIX/Linux).
301
302
303COMMANDS~
304 *SingleCompile-commands*
305----------------------------------------------------------------------------
306
307 *:SCCompile*
308Command:
309 :SCCompile
310If you are editing a source file of a compiling language such as C, Java, this
311command will compile the file which you are editing now. If you are editing a
312source file of a interpreted language such as python language, this command
313will run the file which you are editing. See |SingleCompile-compiler-template|
314about the compilation command.
315
316You can add some arguments after the command. For example, you want to compile
317your c source file with "-g -o %<" flag instead of the "-o %<" flag defined in
318the language template(see |SingleCompile-compiler-template|) for just this
319time, just use the following command:
320>
321 :SCCompile -g -o %<
322<
323"%<" means the current file name without extension.
324Also see |:SCCompileAF|.
325
326 *:SingleCompile*
327Command:
328 :SingleCompile
329Same as |:SCCompile|, only for backward compatibility use. Not recommended to
330use any more.
331
332 *:SCCompileAF*
333Command:
334 :SCCompileAF
335This command is also used for compiling your source file, but it allows you to
336append some additional compilation or interpretion flags other than the flags
337already defined in the compiler and interpreter template. The "AF" is short
338for "Addtional Flags". For example, GCC compiler for C has already been
339defined some flags: "-o "%<"". But sometimes you also want to use "-O2" flag
340to optimize your code, then you can use the following commands to compile your
341file:
342>
343 :SCCompileAF -O2
344<
345:SCCompile can also be used with some arguments, but there are some
346differences. :SCCompileAF use your arguments as "additional" compilation
347flags, which means the flags defined in the original templates are also valid,
348while :SCCompile use you arguments as compilation flags only, which means the
349flags defined in the original templates are not used. For example, the
350templates of GCC defined "flags" as '-o "%<"', "%<" stands for the output file
351name. ":SCCompile -O2" will use "gcc -O2 some_file.c" to compile your source
352file, while ":SCCompileAF -O2" will use "gcc -o some_file -O2 some_file.c" to
353compile your source file.
354
355 *:SCCompileRun*
356Command:
357 :SCCompileRun
358If you are editing a source file of a compiling language such as C, Java, this
359command will compile the file which you are editing now and run the
360executable; if you are editing a source file of a interpreted language such as
361python, ruby, this command will run the source file you are editing. That
362means, there is nothing different between |:SCCompile| and |:SCCompileRun| for an
363interpreted language source file.
364
365You can also add some arguments after SCCompileRun command, the meaning of
366arguments is the same as SingleCompile command above. Here is an example:
367>
368 :SCCompileRun -g -o %<
369<
370
371When the program you've just compiled (or the script you've just written)
372runs, vim will hang up to wait for the program to terminate. If you do not
373want vim to hang up when running the program, use |:SCCompileRunAsync|
374instead. See |:SCCompileRunAsync| for further information.
375
376 *:SingleCompileRun*
377Command:
378 :SingleCompileRun
379Same as |:SCCompileRun|, only for backward compatibility use. Not recommended
380to use any more.
381
382 *:SCCompileRunAF*
383Command:
384 :SCCompileRunAF
385Same as |:SCCompileAF|, but also run the binary file after compilation. For
386example, the following command is going to compile your source file with an
387additional "-O2" flag and run the output binary file:
388>
389 :SCCompileRunAF -O2
390<
391
392 *:SCCompileRunAsync*
393Command:
394 :SCCompileRunAsync
395Same as |:SCCompileRun|, but compile the source and run asynchronously. That
396is to say, after the program starts to run, you are still able to edit the
397source file, because vim does not hang up waiting for the program to
398terminate. The result of the run could be viewed by |:SCViewResultAsync|
399command. This command might not be available on your vim, see
400|SingleCompile-asyncrunmode| for more information. This command is useful when
401the program takes a long time to run or you are developing a GUI program. Also
402see |:SCViewResultAsync|, |:SCTerminateAsync| and |:SCIsRunningAsync|.
403
404 *:SCCompileRunAsyncAF*
405Command:
406 :SCCompileRunAsyncAF
407Same as |:SCCompileRunAF|, but compile the source and run asynchronously. The
408result of the run could be viewed by |:SCViewResultAsync| command. This
409command is disabled by default, to enable it, see
410|SingleCompile-asyncrunmode|. Also see |:SCCompileRunAsync|.
411
412 *:SCChooseCompiler*
413Command:
414 :SCChooseCompiler
415Choose a compiler to use. This command will display a list of compilers for
416you to choose one. If you want to set a default compiler in your vimrc, please
417use the function SingleCompile#ChooseCompiler. See
418|SingleCompile-use-built-in-template|.
419
420 *:SCChooseInterpreter*
421Command:
422 :SCChooseInterpreter
423Same as |:SCChooseCompiler|.
424
425 *:SCIsRunningAsync*
426Command:
427 :SCIsRunningAsync
428Check whether the asynchronously run process is still running. Also see
429|:SCCompileRunAsync|.
430
431 *:SCTerminateAsync*
432Command:
433 :SCTerminateAsync
434Terminate the process which is running asynchronously if exists. Also see
435|:SCCompileRunAsync|.
436
437 *:SCViewResult*
438Command:
439 :SCViewResult
440View the result of the last run command. Only valid when "tee" command is
441available. "tee" is usually available on a UNIX system. If you are under
442Windows, install cygwin or visit the following link to download a "tee"
443command for Windows:
444http://gnuwin32.sourceforge.net/packages/coreutils.htm
445
446 *:SCViewResultAsync*
447Command:
448 :SCViewResultAsync
449Same as |:SCViewResult|, but the result displayed is the result of the process
450run by |:SCCompileRunAsync| or |:SCCompileRunAsyncAF|.
451
452
453SETTINGS~
454 *SingleCompile-settings*
455----------------------------------------------------------------------------
456
457 *SingleCompile-alwayscompile*
458If g:SingleCompile_alwayscompile is set to 0, when using |:SCCompileRun|
459command, SingleCompile may run the output of the compilation directly if the
460modification time of the source file is earlier than the output file. If you
461want to enable this feature, add the following line to your vimrc:
462>
463 let g:SingleCompile_alwayscompile = 0
464<
465The default value of g:SingleCompile_alwayscompile is 1.
466
467 *SingleCompile-asyncrunmode*
468This option specifies the asynchronous mode for |:SCCompileRunAsync| and
469|:SCCompileRunAsyncAF|. The default value is "auto", which means SingleCompile
470will automatically detect whether you are able to enable async run mode and
471select one mode for you. Use the following line, replace modename with the
472mode you want to change mode:
473>
474 let g:SingleCompile_asyncrunmode = 'modename'
475<
476
477Here is a list of available mode:
478
479auto This is the default value. SingleCompile automatically selects one
480 mode for you.
481>
482 let g:SingleCompile_asyncrunmode = 'auto'
483<
484
485none Disable asynchronous mode, which means |:SCCompileRunAsync| and
486 |:SCCompileRunAsyncAF| and related commands are disabled.
487>
488 let g:SingleCompile_asyncrunmode = 'none'
489<
490
491python Use python interface when running asynchronously. Required vim
492 compiled with python interface 2.6+. See |+python|.
493>
494 let g:SingleCompile_asyncrunmode = 'python'
495<
496
497
498 *SingleCompile-autowrite*
499If you don't want to save your file automatically when you use "SingleCompile"
500command or "SingleCompileRun" command, add the following line to your vimrc:
501>
502 let g:SingleCompile_autowrite = 0
503<
504NOTE: If you let g:SingleCompile_usequickfix=1, this option will take no
505effect, the running result will depend on the vim's option 'autowrite'. See
506'autowrite' for more information.
507
508 *SingleCompile-menumode*
509If you don't want the menus of SingleCompile to show, copy the following line
510to your vimrc:
511>
512 let g:SingleCompile_menumode = 0
513<
514If you want the menus of SingleCompile to show as a sub menu of Plugin, copy
515the following line to your vimrc:
516>
517 let g:SingleCompile_menumode = 1
518<
519If you want the menus of SingleCompile to show in the menu bar, copy the
520following line to your vimrc:
521>
522 let g:SingleCompile_menumode = 2
523<
524The default value is 1.
525
526 *SingleCompile-resultheight*
527g:SingleCompile_resultheight is the height of the result displaying window
528triggered by |:SCViewResult| command. To set the value, add the following line
529to your vimrc file:
530>
531 let g:SingleCompile_resultheight = a_number
532<
533Replace a_number to any number you want, such as "10", "4". The default value
534of g:SingleCompile_resultheight is 5.
535
536 *SingleCompile-showquickfixiferror*
537If |quickfix| is enabled and used, and you want the quickfix window to show
538automatically if there is a compilation error, then add the following line to
539your vimrc file:
540>
541 let g:SingleCompile_showquickfixiferror = 1
542<
543The default value of g:SingleCompile_showquickfixiferror is 0. Note that this
544option will be ignored if you are using interpreting languages on Windows,
545such as python, ruby.
546
547 *SingleCompile-showresultafterrun*
548If "tee" command is available on your system, copy the following line to your
549vimrc file will make vim show the result of the run automatically after you
550run the program:
551>
552 let g:SingleCompile_showresultafterrun = 1
553<
554This option is only valid for synchronous run. That is to say, asynchronous
555run is not affected by this option. The default value of
556g:SingleCompile_showresultafterrun is 0. Also see |:SCViewResult|.
557
558 *SingleCompile-usedialog*
559If you want SingleCompile to show message in a dialog, add the
560following line to your vimrc:
561>
562 let g:SingleCompile_usedialog = 1
563<
564This setting will take no effect if your vim is not compiled with
565'+dialog_con' and '+dialog_gui'.
566
567 *SingleCompile-usequickfix*
568If you don't want SingleCompile to use quickfix feature, add the following
569line to your vimrc:
570>
571 let g:SingleCompile_usequickfix = 0
572<
573
574
575KEY-MAPPING~
576 *SingleCompile-key-mapping*
577----------------------------------------------------------------------------
578I recommend you to copy the following two lines about key mapping to your
579vimrc:
580>
581 nmap <F9> :SingleCompile<cr>
582 nmap <F10> :SingleCompileRun<cr>
583<
584Then you can press F9 to compile, and F10 to compile and run.
585
586
587COMPILER-TEMPLATE~
588 *SingleCompile-compiler-template*
589----------------------------------------------------------------------------
590 *SingleCompile-use-built-in-template*
591 *SingleCompile#ChooseCompiler*
592To use a built-in compiler, add the following line to your vimrc file:
593>
594 call SingleCompile#ChooseCompiler('filetype', 'compiler')
595<
596"filetype" is the type of file which your compiler is for, such as "c",
597"python", and "compiler" is the short name of the compiler. "filetype" is a
598terminology of vim. See |filetype| if you don't know what is "filetype". For
599example:
600>
601 call SingleCompile#ChooseCompiler('c', 'icc')
602 call SingleCompile#ChooseCompiler('fortran', 'gfortran')
603<
604This will choose icc (short for Intel C++ Compiler) as your current C compiler
605and choose gfortran (GNU Fortran Compiler) as your current Fortran compiler.
606For the list of built-in supported compilers, see
607|SingleCompile-built-in-compilers|.
608
609If you don't choose a compiler by yourself, SingleCompile will automatically
610choose one for you according to the compiler's priority value (See
611|SingleCompile-priority|).
612
613You can also extend the compiler template if the compiler you want is not in
614the built-in supporting list. SingleCompile#ChooseCompiler could also be used
615to choose a user defined compiler. Check |SingleCompile-add-your-compiler| for
616more information.
617
618 *SingleCompile-add-your-compiler*
619 *SingleCompile#SetCompilerTemplate*
620To add a new compiler support by yourself, there are two ways:
6211. (Recommended) Add the following lines to your vimrc file:
622>
623 call SingleCompile#SetCompilerTemplate('filetype', 'compiler', 'compiler_name', 'command', 'flag', 'run_command')
624 call SingleCompile#SetOutfile('filetype', 'compiler', 'out_file')
625 call SingleCompile#ChooseCompiler('filetype', 'compiler')
626<
627Now Let's see the first line. "filetype" is the source file type, such as "c",
628"cpp", "python", etc. It is a terminology of vim. See |filetype| if you don't
629know what is "filetype". For compiling languages such as C, Java, Fortran,
630"compiler" is the short name for the compiler, such as "gcc", "icc"; "command"
631is the command of compiling, such as "gcc", "g++"; "flag" is the flags of
632compiling, such as "-O2"; "run_command" is the command of running, such as
633"./a.out". For interpreted languages such as Python, Ruby, "command" is the
634command of interpreting, such as "python"; "flag" is the flags of
635interpreting; and "run_command" MUST be set to be empty.
636
637For the second line, "filetype" and "compiler" has the same meanings with the
638first line. "out_file" is the output file of the compilation, such as
639"./a.out", "./a.exe", etc. This line could be omitted if you don't want
640SingleCompile to check whether compilation is needed. See
641|SingleCompile-alwayscompile| for more information.
642
643The first two lines are to set the template of your compiler, while the third
644line is to tell SingleCompile to use your compiler. If the second line is
645omitted, SingleCompile will detect the compilers available on your system
646automatically, and use the first detected one.
647
648Here are some examples modified from built-in compiler templates:
649>
650 " set the most common used run command
651 if has('win32') || has('win64') || has('os2')
652 let l:common_run_command = '$(FILE_TITLE)$'
653 let l:common_out_file = '$(FILE_TITLE)$.exe'
654 else
655 let l:common_run_command = './$(FILE_TITLE)$'
656 let l:common_out_file = '$(FILE_TITLE)$'
657 endif
658
659 " c
660 call SingleCompile#SetCompilerTemplate('c', 'gcc', 'GNU C Compiler',
661 \'gcc', '-o $(FILE_TITLE)$', l:common_run_command)
662 call SingleCompile#SetOutfile('c', 'gcc', l:common_out_file)
663 call SingleCompile#SetCompilerTemplate('c', 'icc',
664 \'Intel C++ Compiler', 'icc', '-o $(FILE_TITLE)$',
665 \l:common_run_command)
666 call SingleCompile#SetOutfile('c', 'icc', l:common_out_file)
667
668 call SingleCompile#ChooseCompiler('c', 'gcc')
669
670 " fortran
671 call SingleCompile#SetCompilerTemplate('fortran', 'g77',
672 \'GNU Fortran 77 Compiler', 'g77', '-o $(FILE_TITLE)$',
673 \l:common_run_command)
674 call SingleCompile#SetOutfile('fortran', 'g77', l:common_out_file)
675 call SingleCompile#SetCompilerTemplate('fortran', 'ifort',
676 \'Intel Fortran Compiler', 'ifort', '-o $(FILE_TITLE)$',
677 \l:common_run_command)
678 call SingleCompile#SetOutfile('fortran', 'ifort', l:common_out_file)
679
680 call SingleCompile#ChooseCompiler('fortran', 'g77')
681
682 " python
683 call SingleCompile#SetCompilerTemplate('python', 'python', 'CPython',
684 \'python', '', '')
685 call SingleCompile#SetCompilerTemplate('python', 'jython', 'Jython',
686 \'jython', '', '')
687
688 call SingleCompile#ChooseCompiler('python', 'jython')
689<
690
6912. (Deprecated, only kept for backward compatibility use)
692If you use this method to add a language template, many features of
693SingleCompile will be unavailable. For example, ":SCChooseCompiler" command
694will not be available. So I don't recommend you to use this method, and this
695method is kept ONLY for backward compatibility.
696
697Add the following lines to your vimrc file:
698>
699 call SingleCompile#SetTemplate('filetype', 'command', 'stringA')
700 call SingleCompile#SetTemplate('filetype', 'flags', 'stringB')
701 call SingleCompile#SetTemplate('filetype', 'run', 'stringC')
702<
703For compiling languages such as C, Java, stringA is the command of compiling,
704stringB is the flags of compiling, stringC is the command of running; For
705interpreted languages such as Python, Ruby, stringA is the command of
706interpreting, stringB is the flags of interpreting, stringC MUST be set to
707be empty.
708
709Here are some examples:
710>
711 " java
712 call SingleCompile#SetTemplate('java', 'command', 'javac')
713 call SingleCompile#SetTemplate('java', 'flags', '')
714 call SingleCompile#SetTemplate('java', 'run', 'java %<')
715
716 " python
717 call SingleCompile#SetTemplate('python', 'command', 'python')
718 call SingleCompile#SetTemplate('python', 'flags', '')
719 call SingleCompile#SetTemplate('python', 'run', '')
720
721 " latex
722 call SingleCompile#SetTemplate('tex', 'command', 'latex')
723 call SingleCompile#SetTemplate('tex', 'flags', '')
724 if has('unix')
725 call SingleCompile#SetTemplate('tex', 'run', 'xdvi %<.dvi')
726 elseif has('win32')
727 call SingleCompile#SetTemplate('tex', 'run', 'dviout %<.dvi')
728 endif
729<
730You can also use this method to modify the templates of a built-in supported
731language. For example, you can change 'dviout' to 'yap' in the example above
732to modify the built-in latex language template.
733
734Advanced: If you don't want to override the template if there is an existing
735one, but use the new template if there is no corresponding template existing,
736for example, you want to set the "command" of java language to javac if no
737command is set for java, but do nothing if the command of java is not set, use
738the following:
739>
740 call SingleCompile#SetTemplate('java', 'command', 'javac', 1)
741<
742In this way, if the command of java is already set, this sentence will do
743nothing. On the contrary, if the command of java is not set, it will set the
744compilation command of java to "javac".
745
746 *SingleCompile-built-in-compiler*
747The following compilers have built-in support in this plugin (For some
748compilers/interpreters, you need to set the environment varibles correctly to
749make them available for SingleCompile):
750
751Ada:
752 gnat (GNAT)
753
754bash:
755 bash (Bourne-Again Shell)
756
757C:
758 bcc (Borland C++ Builder), Windows only
759 cc (UNIX C Compiler), UNIX only
760 ch (SoftIntegration Ch)
761 clang (the Clang C and Objective-C compiler)
762 gcc (GNU C Compiler)
763 icc (Intel C++ Compiler)
764 lcc (Little C Compiler)
765 msvc (Microsoft Visual C++ (In PATH)), Windows only
766 msvc80 (Microsoft Visual C++ 2005), Windows only
767 msvc90 (Microsoft Visual C++ 2008), Windows only
768 msvc100 (Microsoft Visual C++ 2010), Windows only
769 open-watcom (Open Watcom C/C++32 Compiler)
770 open64 (Open64 C Compiler), UNIX only
771 pcc (Portable C Compiler)
772 sol-studio (Sun C Compiler(Sun Solaris Studio)), UNIX only
773 tcc (Tiny C Compiler)
774 tcc-run (Tiny C Compiler with "-run" Flag)
775
776C++:
777 bcc (Borland C++ Builder), Windows Only
778 ch (SoftIntegration Ch)
779 clang (the Clang C and Objective-C compiler)
780 g++ (GNU C++ Compiler)
781 icc (Intel C++ Compiler)
782 msvc (Microsoft Visual C++ (In PATH)), Windows only
783 msvc80 (Microsoft Visual C++ 2005), Windows only
784 msvc90 (Microsoft Visual C++ 2008), Windows only
785 msvc100 (Microsoft Visual C++ 2010), Windows only
786 open-watcom (Open Watcom C/C++32 Compiler)
787 open64 (Open64 C++ Compiler), UNIX only
788 sol-studio (Sun C++ Compiler(Sun Solaris Studio)), UNIX only
789
790C#:
791 msvcs(Microsoft Visual C#), Windows Only
792 mono (Mono C# compiler)
793
794cmake:
795 cmake (cmake)
796
797csh:
798 csh (C Shell)
799 tcsh (TENEX C Shell)
800
801D:
802 dmd (DMD Compiler)
803
804dos batch:
805 dosbatch (DOS Batch)
806
807erlang:
808 escript (Erlang Scripting Support)
809
810Fortran:
811 ftn95 (Silverfrost FTN95), Windows only
812 g77 (GNU Fortran 77 Compiler)
813 g95 (G95)
814 gfortran (GNU Fortran Compiler)
815 ifort (Intel Fortran Compiler)
816 open-watcom (Open Watcom Fortran 77/32 Compiler)
817 open64-f90 (Open64 Fortran 90 Compiler), UNIX only
818 open64-f95 (Open64 Fortran 95 Compiler), UNIX only
819 sol-studio-f77 (Sun Fortran 77 Compiler(Sun Solaris Studio)), UNIX only
820 sol-studio-f90 (Sun Fortran 90 Compiler(Sun Solaris Studio)), UNIX only
821 sol-studio-f95 (Sun Fortran 95 Compiler(Sun Solaris Studio)), UNIX only
822
823Haskell:
824 ghc (Glasgow Haskell Compiler)
825 runhaskell (runhaskell)
826
827html:
828 arora (Arora)
829 chrome (Google Chrome)
830 chromium (Chromium)
831 epiphany (Epiphany)
832 firefox (Mozilla Firefox)
833 ie (Microsoft Internet Explorer)
834 konqueror (Konqueror)
835 opera (Opera)
836
837IDL(Interactive Data Language):
838 idl (ITT Visual Information Solutions Interactive Data Language)
839 gdl (GNU Data Language incremental compiler)
840
841Java:
842 gcj (GNU Java Compiler)
843 sunjdk (Sun Java Development Kit)
844
845JavaScript:
846 gjs (Javascript Bindings for GNOME)
847 js (SpiderMonkey, a JavaScript engine written in C)
848 node.js (node.js)
849 rhino (Rhino, a JavaScript engine written in Java)
850
851ksh:
852 ksh (Korn Shell)
853
854LaTeX:
855 latex (LaTeX)
856 pdflatex (pdfLaTeX)
857
858LISP:
859 clisp (GNU CLISP)
860 ecl (Embeddable Common-Lisp)
861 gcl (GNU Common Lisp)
862
863lua:
864 lua (Lua Interpreter)
865
866Makefile:
867 gmake (GNU Make)
868 nmake (Microsoft Program Maintenance Utility)
869 mingw32-make (MinGW32 Make)
870
871Markdown:
872 markdown (text-to-HTML conversion tool)
873 rdiscount (Discount Markdown Processor for Ruby)
874
875Object-C:
876 clang (the Clang C and Objective-C compiler)
877 gcc (GNU Object-C Compiler)
878
879Pascal:
880 fpc (Free Pascal Compiler)
881 gpc (GNU Pascal Compiler)
882
883perl:
884 perl (Perl Interpreter)
885
886PHP:
887 php (PHP Command Line Interface 'CLI')
888
889python:
890 ironpython (IronPython)
891 jython (Jython)
892 pypy (PyPy)
893 python (Python Interpreter)
894 python3 (Python 3 Interpreter)
895
896R:
897 R (R)
898
899ruby:
900 ruby (Ruby Interpreter)
901
902sh:
903 ash (Almquist Shell)
904 bash (Bourne-Again Shell)
905 dash (Debian Almquist Shell)
906 ksh (Korn Shell)
907 sh (Bourne Shell)
908 zsh (Z Shell)
909
910tcl:
911 tclsh (Simple shell containing Tcl interpreter)
912
913tcsh:
914 tcsh (TENEX C Shell)
915
916vb script:
917 vb (VB Script Interpreter)
918
919xhtml:
920 arora (Arora)
921 chrome (Google Chrome)
922 epiphany (Epiphany)
923 firefox (Mozilla Firefox)
924 ie (Microsoft Internet Explorer)
925 konqueror (Konqueror)
926 opera (Opera)
927
928zsh:
929 zsh (Z Shell)
930
931
932See |SingleCompile-add-your-compiler| to add your compiler support.
933
934
935SUPPORTINGS~
936 *SingleCompile-supporting-plugins*
937----------------------------------------------------------------------------
938There are some supporting code in this plugin for Marc Weber's
939vim-addon-actions:
940 http://github.com/MarcWeber/vim-addon-actions
941
942
943ADVANCED~
944 *SingleCompile-advanced*
945----------------------------------------------------------------------------
946This chapter is for advanced users.
947
948 *SingleCompile-custom-compiler-detecting*
949SingleCompile allows you to custom compiler detecting function by yourself.
950
951In |SingleCompile-compiler-template|, the following function is introduced:
952>
953 call SingleCompile#SetCompilerTemplate('filetype', 'compiler',
954 \'compiler_name', 'command', 'flag', 'run_command')
955<
956
957However, in fact, the function SingleCompile#SetCompilerTemplate could have a
958seventh parameter. The seventh parameter is a |Funcref| which references to a
959compiler detecting function. The compiler detecting function will be called in
960the function SingleCompile#SetCompilerTemplate. The compiler detecting
961function must accept one parameter, which would be passed in the "command"
962parameter in SingleCompile#SetCompilerTemplate, and return a detected compiler
963command if detected, which will be used as the compiling command by
964SingleCompile, or returns 0 if the compiler is not detected. Thus, it is more
965powerful to detect some compilers. If the seventh parameter is omitted, the
966function will use a built-in default compiler detecting function instead. The
967default function would check whether the "command" is in PATH, ~/bin,
968/usr/local/bin, /usr/bin, /bin on UNIX and whether it is in PATH on other
969OSes, and returns the full path of the command if it is not in PATH. If the
970command is not detected, the default function would return 0.
971
972Here is a short example excerpted from built-in template(OpenWatcom detecting
973function):
974>
975 function! s:DetectWatcom(compiling_command)
976 let l:watcom_command =
977 \SingleCompile#DetectCompilerGenerally(a:compiling_command)
978 if l:watcom_command != 0
979 return l:watcom_command
980 endif
981
982 if $WATCOM != ''
983 return $WATCOM.'\binnt\'.a:compiling_command
984 endif
985 endfunction
986<
987SingleCompile#DetectCompilerGenerally is the default compiler detecting
988function introduced in the above paragraph. This function first uses a general
989way to detect the compiler. If the general way can not detect it, it check the
990environment varible "$WATCOM" to get the compiler's installation directory and
991get the full path of the compiling program.
992
993 *SingleCompile-predo-postdo*
994 *SingleCompile-predo*
995 *SingleCompile-postdo*
996 *SingleCompile#SetPredo*
997 *SingleCompile#SetPostdo*
998"Predo" and "Postdo" features allow you to initialize the compiler before
999compiling and clean up after compiling in you own way.
1000
1001"Predo" feature allows you to define a function, which would be called before
1002compiling by SingleCompile, all by yourself. In the same way, "Postdo" feature
1003allows you to define a function called by SingleCompile after compiling. Your
1004"Predo" or "Postdo" function should accept one parameter, which would be
1005passed in a dictionary containing compiling information, and return a new
1006compiling information modified in the function by you. SingleCompile will use
1007the new compiling information in its following work. The dictionary passed in
1008is like this: >
1009 {"command": "the-compiling-command", "args": "the-compiling-argument"}
1010>
1011Then modify the dictionary to meet your need and return the modified
1012dictionary. If you don't want to modify the dictionary, please return the
1013parameter passed in directly.
1014
1015The two functions below provide a way to set the "Predo" and "Postdo"
1016functions:
1017>
1018 call SingleCompile#SetPredo('filetype', 'compiler',
1019 \function('your_predo_function'))
1020 call SingleCompile#SetPostdo('filetype', 'compiler',
1021 \function('your_postdo_function'))
1022<
1023
1024Example: OpenWatcom's "Predo" and "Postdo" functions:
1025>
1026 " pre-do
1027 function! s:PredoWatcom(compiling_info)
1028 let s:old_path = $PATH
1029 let $PATH = $WATCOM.s:GetPathSeperator().'binnt'.s:GetEnvSeperator().
1030 \$WATCOM.s:GetPathSeperator().'binw'.s:GetEnvSeperator().
1031 \$PATH
1032 return a:compiling_info
1033 endfunction
1034
1035 " post-do
1036 function! s:PostdoWatcom(compiling_info) " watcom pre-do {{{2
1037 let $PATH = s:old_path
1038 return a:compiling_info
1039 endfunction
1040
1041 call SingleCompile#SetPredo('c', 'open-watcom', function('s:PredoWatcom'))
1042 call SingleCompile#SetPostdo('c', 'open-watcom', function('s:PostdoWatcom'))
1043<
1044As you see, the OpenWatcom "Predo" function first saves the current PATH
1045environment varible, then modifies $PATH to meet the OpenWatcom compiler needs.
1046It returns the original compiling info because it does not need to modify it.
1047The OpenWatcom "Postdo" function restores the original $PATH. After defining
1048the two functions, the example calls "SetPredo" and "SetPostdo" function to
1049set the functions as the "Predo" function and "Postdo" function for
1050corresponding language and compiler.
1051
1052
1053To make it less confusing, I better explain the calling order here. The
1054calling order is: first the compiler detecting function, then "Predo"
1055function, then compile, and the last is the "Postdo" function.
1056
1057 *SingleCompile-vim-compiler*
1058 *SingleCompile#SetVimCompiler*
1059SingleCompile can work with the compiler feature of vim(see |:compiler|). To
1060set the compiler file in the compiler direcotry for a compiler, use
1061SingleCompile#SetVimCompiler function. For example, for g77, the GNU Fortran
106277 compiler, use the following line to set the compiler file for g77:
1063>
1064 call SingleCompile#SetVimCompiler('fortran', 'g77', 'fortran_g77')
1065<
1066(This line is excerpted from the built-in templates.)
1067
1068Then if we are using g77 as our compiler, SingleCompile will first execute
1069":compiler fortran_g77" before compiling the source file. This will give us
1070the advantage that vim's quickfix will recognize the messages output by g77
1071and help us locate these errors quickly.
1072
1073 *SingleCompile-priority*
1074 *SingleCompile#SetPriority*
1075Since version 2.9, every compiler template could be assigned a priority value.
1076This value determines which compiler to use when seversal compilers has been
1077detected. Use the following line to set a compiler's priority:
1078>
1079 call SingleCompile#SetPriority('language_name', 'compiler_name', priority)
1080<
1081The parameter "priority" is an integer. The less the parameter "priority" is,
1082the higher priority the compiler has. For example, the following two lines set
1083two Fortran compilers' priorities (The two lines are excerpted from the
1084built-in template):
1085>
1086 call SingleCompile#SetPriority('fortran', 'gfortran', 70)
1087 call SingleCompile#SetPriority('fortran', 'ifort', 80)
1088<
1089After executing the two lines above, if ifort (which is Intel Fortran
1090Compiler) and gfortran (GNU fortran compiler) are both detected by
1091SingleCompile, and the user does not call |SingleCompile#ChooseCompiler| to
1092choose a compiler explicitly, SingleCompile will choose gfortran as the
1093current compiler.
1094
1095CREDITS~
1096 *SingleCompile-credits*
1097----------------------------------------------------------------------------
1098Marc Weber Integrated SingleCompile with vim-addon-actions, and some other
1099 improvements
1100Darek Fixed a directory switching bug
1101sky hi Provided DMD compiler for D language built-in template
1102Zhou Yichao Made several improvements and fixed several bugs.
1103
1104
1105TODO~
1106 *SingleCompile-todo*
1107----------------------------------------------------------------------------
1108Add asynchronous compilation support.
1109
1110Add matlab built-in template.
1111
1112If "tee" is used when we are executing ":make" command, currently we can't get
1113the exit code of the compiler. We need to fix this.
1114
1115When running compiled program, if "tee" is used for redirecting, things
1116written to stdout are not printed as if what happens when stdout is a tty.
1117This need to be fixed.
1118
1119Make it possible to store compiler template in config files, such as ini
1120files.
1121
1122Reduce startup time and shrink memory use.
1123
1124vim:ts=4:ft=help:tw=78:et