2010-03-10

Running Vim from Lazarus IDE

I would like to edit my program both in Lazarus IDE and Vim. Lazarus IDE is good, but Vim is faster for hard core text processing. Thanks to both of them, this task is easy.

First step is to launch Lazarus IDE, and selecting "Configure external tools ..." from the "Tools" menu.




Next step is trivial, just adding a new entry by clicking "Add".


In the final step, type the following information into specified fields.

Title: Edit with Vim

Program File Name: C:\PortableApps\PortableApps\gVimPortable\gVimPortable.exe

Parameters: +$Row() "$EdFile()"

Working Directory: $Path()

+$Row() allows Vim to directly locate the cursor when the file is opened so that you can keep going on, very useful for large files.

"$EdFile()" is the full path to the file. Note that this will work even though you have a single file on Lazarus, not a project. (If you want that, there are options for that too.)

$Path() is the working directory of the file. It will be useful to locate that directory so that you can easily open more files from Vim.


After all, your final screen should look like this:




You can now open a file from Lazarus IDE in Vim as follows:




Note that you should have a file opened it must be saved to appear in Vim.

2009-12-27

Using CPython modules from IronPython

I have IronPython 2.6 and Python 2.6.4 installed on a Windows box.

IronPython's interpreter ipy.exe is not installed on a directory on path, just unzipped in an arbitrary folder.
Python 2.6.4 is installed in C:\Python26 directory.

You can import pure CPython modules from IronPython as follows:

C:\Users\dude\Documents\SharpDevelop Projects\Faman5>ipy
IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4927
Type "help", "copyright", "credits" or "license" for more information.
>>> # Try to import the os module.
>>> import os
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named os
>>> # OK, we are sure that the module is can not be imported.
>>> # Now we need to import the sys module to achive our goal.
>>> import sys
>>> # sys.path is the list of directories to look for when importing modules.
>>> sys.path
['.', '.', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5\\Lib', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5\\DLLs', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5']
>>> # Add the Cpython path to the sys.path as follows:
>>> sys.path.append("C:\Python26\Lib")
>>> sys.path
['.', '.', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5\\Lib', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5\\DLLs', 'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5', 'C:\\Python26\\Lib']
>>> # Now we are sure that 'C:\\Python26\\Lib' is added.
>>> # Let us try to import the os module again.
>>> import os
>>> os.getcwd()
'C:\\Users\\dude\\Documents\\SharpDevelop Projects\\Faman5'
>>> # Success!