Friday, May 29, 2009

Android development with Vim + Eclim

Let me repeat a millionth time that Vim is my favorite code editor. I however have been lured by Eclipse's glitter in the areas such as code completion, live debugging and graphic representation of various aspects of a project. But Eclipse code editor is only a bit better than Notepad, if compared to Vim. As a compromise I found the viPlugin. I used it for a while. It's not as rich as Vim, but good enough. (BTW, it is probably the first piece of software I ever paid for).

Due to Android, I did a comeback to Java couple months ago and again struggled while making the choice between Eclipse and Vim. I chose to do all the coding in Vim eventually.

Last week I learnt about Eclim. The project looks so mature, I wonder why I didn't hear about it earlier. It gets the best of both worlds. It provides a script that runs eclipse in headless mode and it has Vim plugins that provide the functionality like code-completion (among others) inside the Vim editor. (There are two other scenarios as well, but I use this one, check their docs for more info).

Here is a small guide on how to set this up for doing Android coding.

My setup: Fedora 10 x86_64 linux, vim-enhanced-7.2.148, Eclipse SDK 3.4.2, Eclim 1.4.7, using Sun's JDK 1.6.0 (although gnu jre is installed, I avoid it by using custom JAVA_HOME).

Install Eclipse. I download the tarball and untar it somewhere (mostly /opt).

mkdir ~/.vim/eclim

Download eclim from here.

One thing that annoyed me was lack of installation instructions. The project page has good overall documentation, but it doesn't mention that you need to compile and install it using ant. Thanks to this post, I figured that out.

As the post says, you need ant 1.7.1. Fedora 10 has the right version. Check what you have. I tried this incantation:

JAVA_HOME=/usr/java/default ant -Declipse.home=/opt/eclipse -Dplugins=ant,jdt

It failed complaining that ant didn't find org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp.

After some googling I found a list of jars that have this class. I downloaded the ant-nodeps-1.7.1.jar, then tried following command. It built and installed eclim successfully.

JAVA_HOME=/usr/java/default CLASSPATH=$CLASSPATH:./ant-nodeps-1.7.1.jar ant -Declipse.home=/opt/eclipse -Dplugins=ant,jdt

The installation deploys necessary vim scripts under ~/.vim and installs the plugins and some scripts to your eclipse installation.

Follow Android SDK directions on how to setup eclipse environment (installation of Android plugin, etc.) and how to create a sample project. If you have created a project using activitycreator (like me), then you can still create a new project in eclipse and choose the option of creating project from "existing source".

Now start the eclimd server (/opt/eclipse/eclimd for me). It starts listening on port 9091.

Navigate to your project directory (which has .project file) and start Vim. Execute ":ProjectSettings", if you don't get any error, but see a new buffer with folded lines, then you have a working setup.

To try code completion (probably the most important feature), write an incomplete pacakge name and hit "Ctrl x Ctrl u". You should see a drop-down list like this.



If you prefer to use Tab for this purpose install the supertab vim plugin and copy few lines to your .vimrc from the end of this post.

These instructions should work more-or-less for other Linux installations too. For Mac OSX, see the post I have linked twice above.

It looks like Eclim has a lot of features, I have yet to try most of them. But this clearly feels like a great addition to my toolbox.

Ads:
Eclipse Plug-ins (3rd Edition)
Eclipse IDE Pocket Guide
Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor: From personalizing Vim to productivity optimizations: Recipes to make life easier for experienced Vim users

Tuesday, May 19, 2009

Cutewit (preview)

This blog has been quiet lately despite all the things I have to share. The main culprit is Twitter. Everything there is to share, trickles away 140 characters a time and nothing is left for a long blog post.

Well, here is an update. I spent the last month applying all the ideas from the inkface library to the Android platform. During the exercise I have written an Android App - a Twitter client - Cutewit. Few hours ago I uploaded a preview version of the app, to Android market and SlideMe. Here are some screenshots:



All the GUI was developed in Inkscape as SVG images. The app lacks many features, but they will soon be coming in the 1.0 release.

If you have Android phone, give it a shot. Even if you don't have a phone (not unlike me) you can still try it in Android emulator that's part of the SDK. I myself plan to use it as a desktop app, running in the emulator window.

That's all for now... follow me on twitter (@jyro) if you are interested in updates.

Monday, May 04, 2009

Einstein's Dreams

Hardly ever (i.e. never) do I read a book in one sitting. I started this book last night and it's noon today when I read its last page.

I have always been intrigued by Einstein's theory of relativity and the non-intuitive nature of time it suggests. So when I read a summary of this book I suddenly jumped on it.

The author, Alan Lightman, has imagined time in various forms and has illustrated each of those forms as dreams that Einstein might have had in 1905.

Here are some excerpts from the book. If they intrigue you, then you should consider reading the book.

* For in this world, time has three dimensions, like space. Just as an object may move in three perpendicular directions, ... so an object may participate in three perpendicular futures. Each future moves in different direction of time. ...

* In this world, there are two times. There is mechanical time and there is body time.

* At some time in the past, scientists discovered that time flows more slowly the farther from the center of earth. The effect is

*Consider a world in which cause and effect are erratic. Sometimes the first precedes the second, sometimes the second the first.

* The world will end on 26 September 1907. Everyone knows it.

* In this world, the passage of time brings increasing order.

* There is a place where time stands still. Raindrops hang motionless in air.... As a traveler approaches this place from any direction, he moves more and more slowly. His heartbeats grow farther apart....

* Imagine a world in which there is no time. Only images.

* This is a world of changed plans, of sudden opportunities, of unexpected visions. For in this world, time flows not evenly but fitfully

* Why such a fixation on speed? Because in this world time passes mere slowly for people in motion. Thus everyone travels at high velocity, to gain time.

* In this world, time flows backward...

* Imagine a world in which people live just one day.

* In a world where time is a sense, like sight or like taste, a sequence of episodes may be quick or may be slow, dim or intense, salty or sweet, causal or without cause, orderly or random, depending on the prior history of the viewer.

* Suppose that time is not a quantity but a quality, like the luminescence of the night...

* In fact, this is a world without future. In this world, time is a line that terminates at the present, both in reality and in the mind.

* In this world, time is a visible dimension. Just as one may look off in the distance and see houses, trees, mountain peaks that are landmarks in space, so one may look out in another direction and see births, marriages, deaths that are signposts in time, stretching off dimly into the far future.

* In this world, time is a local phenomenon. Two clocks close together tick at nearly the same rate. But clocks separated by distance tick at different rates,...

* This is a world in which time is not fluid, parting to make way for events. Instead, time is a rigid, bonelike structure, extending infinitely ahead and behind, fossilizing the future as well as the past. Every action, every thought, every breath of wind, every flight of birds is completely determined, forever.... like a chess game in which every move is forced .... a world of fixed future.

* For time is like the light between two mirrors, Time bounces back and forth, producing an infinite number of images, of melodies, of thoughts. It is a world of countless copies.

* ... a world of shifting past ...

* ... Because this flock of nightingales is time. Time flutters and fidgets and hops with these birds. Trap one of these nightingales beneath a bell jar and time stops.
The author describes people's day-to-day lives in these alternate worlds and that part is very amusing. You can read some detailed excerpts here.

I came to know about this book while reading about Braid (the game), it was influenced partly by this book.