2009-06-29

Vim compiler plugin for FreeBASIC

I have uploaded a Vim compiler plugin for FreeBASIC.
You can download the fbc.vim at
http://www.vim.org/scripts/script.php?script_id=2691

For the following code:


the
:make
command produces an output as follows:


Traditonally, you can see the all error messages with
:cl

you can jump to next error with
:cn

and you can jump to the previous error message with
:cp


To install it, copy the script into your compiler folder. Assuming standart installations, it should be
C:\Program Files\Vim\vimfiles\compiler\
in Microsoft Windows, and
$HOME/.vim/compiler
in Linux operating systems.

In Vim, the compiler plugins are not automatically triggered unlike file type plugins. To set it whenever you need, use the command
1 :compiler fbc


To set it once and for all if a .bas file is edited, type the following into your VIMRC file:
1 autocmd BufNewFile,BufRead *.bas compiler fbc


If you need a syntax file for the upcoming FreeBASIC 0.21, you can download a syntax file at http://cubaxd.net/?en&p=syntaxfile.

2009-06-05

Delphi Pascal/Object Pascal editing in Vim

Here are a few Vim plugins for Pascal editing.

Compiler
fpc.vim : "Free Pascal Compiler" compiler plugin
It can already be bundled in your Vim. If it is not, you can download it. After opening a .pas file, type
:compiler fpc
Compiler plugins are not loaded automatically in Vim. You'll have to load them explicitly.

Syntax
Syntax file for Borlands Delphi/Kylix
Vim 7 is already bundled with Pascal syntax plugin. But Object Pascal is more than that. To colorize the keywords of Object Pascal, you can use this plugin which is derived from the original Pascal syntax plugin.

Note that although this plugin is a syntax file, if you look in the script, you will see that it also contains color codes. That is why you will not see the color scheme you selected if you have this plugin. To overcome this issue, you can delete the following lines from the delphi.vim :


261 hi pascalObject          ctermfg=white         guifg=white         gui=italic
262 hi pascalFunction        ctermfg=LightRed      guifg=Orange        gui=NONE
263 hi pascalStatement       ctermfg=Green         guifg=Green         gui=NONE
264 hi pascalNumber          ctermfg=LightBlue     guifg=LightBlue     gui=NONE
265 hi pascalByte            ctermfg=LightRed      guifg=LightRed      gui=bold
266 hi pascalString          ctermfg=LightBlue     guifg=LightBlue     gui=NONE
267 hi pascalMatrixDelimiter ctermfg=lightred      guifg=lightred      gui=NONE
268 hi pascalConditional     ctermfg=Green         guifg=Green         gui=NONE
269 hi pascalConstant        ctermfg=white         guifg=white         gui=NONE
270 hi pascalModifier        ctermfg=Green         guifg=Green         gui=NONE
271 hi pascalType            ctermfg=white         guifg=white         gui=NONE
272 hi pascalStructure       ctermfg=Green         guifg=Green         gui=NONE
273 hi pascalRepeat          ctermfg=Green         guifg=Green         gui=NONE
274 hi pascalOperator        ctermfg=Green         guifg=Green         gui=NONE
275 hi pascalAssignment      ctermfg=Magenta       guifg=Magenta       gui=NONE
276 hi pascalComment         ctermfg=LightBlue     guifg=#00A0A0       gui=italic
277 hi pascalLabel           ctermfg=Green         guifg=Green         gui=NONE
278 hi pascalDelimiter       ctermfg=Yellow        guifg=Yellow        gui=NONE
279 hi pascalComparator      ctermfg=Yellow        guifg=Yellow        gui=NONE

I should remind you that the colors are not bad though. Delete them if you want to use the color scheme selected; otherwise leave it as it is, it just works.
If you are curious, here is the screenshot of the colors provided by the syntax plugin:


Also the author of this plugin provides some code to be put on your .vimrc and it is quite useful.
This is the code to be put on your .vimrc:
 1 " Pascal / Delphi
 2 if (1==1) "change to 1==0 to use original syntax
 3   au BufNewFile,BufRead *.pas,*.PAS set ft=delphi
 4 else
 5   au BufNewFile,BufRead *.pas,*.PAS set ft=pascal
 6 endif
 7 " Delphi project file
 8 au BufNewFile,BufRead *.dpr,*.DPR set ft=delphi
 9 " Delphi form file
10 au BufNewFile,BufRead *.dfm,*.DFM set ft=delphi
11 au BufNewFile,BufRead *.xfm,*.XFM set ft=delphi
12 " Delphi package file
13 au BufNewFile,BufRead *.dpk,*.DPK set ft=delphi
14 " Delphi .DOF file = INI file for MSDOS
15 au BufNewFile,BufRead *.dof,*.DOF set ft=dosini
16 au BufNewFile,BufRead *.kof,*.KOF set ft=dosini
17 au BufNewFile,BufRead *.dsk,*.DSK set ft=dosini
18 au BufNewFile,BufRead *.desk,*.DESK set ft=dosini
19 au BufNewFile,BufRead *.dti,*.DTI set ft=dosini
20 " Delphi .BPG = Makefile
21 au BufNewFile,BufRead *.bpg,*.BPG set ft=make|setlocal makeprg=make\ -f\ %

Color Schemes
Delphi color scheme

Turbo color scheme

Borland color scheme

2009-06-04

IronPython and C#, Hosting/Embedding, Part I

As IronPython improves, the way to embed it in other applications is changed too. It is constantly becoming easier and more general. When the C# 4.0 is released, it will be even more easier and useful.

I have written a simple hosting example for the current stable version. I have used IronPython 2.0.1, Visual Studio 2005 SP1, and .NET Framework 2.0 SP2. This example has not been tested with IronPython 2.6 Beta 1 nor IronPython 2.6 for .NET 4.0 Beta 1.

The example code can be seen as follows:

1  namespace IronPythonHostingExample
2  {
3      using System;
4      using IronPython.Hosting;
5      using Microsoft.Scripting.Hosting;
6
7      public class IronPythonStatementHostingExample
8      {
9          public static void ShowDemo()
10         {
11             ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
12             ScriptRuntime runtime = new ScriptRuntime(setup);
13             ScriptEngine engine = Python.GetEngine(runtime);
14             ScriptScope scope = engine.CreateScope();
15             ScriptSource source;
16             string sourceCode = string.Empty;
17             sourceCode += "def factorial(n):" + Environment.NewLine;
18             sourceCode += "    f = 1" + Environment.NewLine;
19             sourceCode += "    i = 1" + Environment.NewLine;
20             sourceCode += "    if (i > n):" + Environment.NewLine;
21             sourceCode += "        return -1" + Environment.NewLine;
22             sourceCode += "    while (i < n):" + Environment.NewLine;
23             sourceCode += "        f = f * i" + Environment.NewLine;
24             sourceCode += "        i = i + 1" + Environment.NewLine;
25             sourceCode += "    return f" + Environment.NewLine;
26             sourceCode += "def add_two_numbers(n1, n2):" + Environment.NewLine;
27             sourceCode += "    return n1+n2" + Environment.NewLine;
28             sourceCode += "for i in range(5):" + Environment.NewLine;
29             sourceCode += "    print i" + Environment.NewLine;
30             sourceCode += "print factorial(5)" + Environment.NewLine;
31             sourceCode += "print factorial(-4)" + Environment.NewLine;
32             sourceCode += "print add_two_numbers(1, 2)" + Environment.NewLine;
33             source = scope.Engine.CreateScriptSourceFromString(sourceCode, Microsoft.Scripting.SourceCodeKind.Statements);
34             source.Execute(scope);
35         }
36     }
37 }



To compile it as a project, you need the following DLLs to be added to your project:
The DLL files can be found in the directory
"C:\Program Files\IronPython 2.0.1".