VoidMain.net It's a website!

15Jan/11Off

Arduino IDE – Adding a little Emacs!

I've been using the Arduino IDE for a few weeks now and have to say that I like it's simplicity. However, I typically just use Emacs for text editing and only use Arduino for uploading to the board because I need my Control+ stuff. I'm not looking for everything...just the basics like Control+f for next character and Control+a for beginning of line. After hours of searching the Internet I figured I'd just hack it up a little and do it myself.

It's not pretty but it gets the job done and now I can use the Arduino IDE for editing and uploading!

FYI, I only tested this on my Mac...YMMV.

First, go here --> http://code.google.com/p/arduino/wiki/BuildingArduino. This will walk you through download the source code for the Arduino IDE. I won't hold your hand through that part...just read and follow the instructions.

Next, change directory to /app/src/processing/app/syntax

Then, open PdeTextAreaDefaults.java with your favorite text editor.

Now, look for the portion of the the function named PdeTextAreaDefaults() that looks like this:

inputHandler.addKeyBinding("MS+UP", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding("CS+UP", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding("MS+DOWN", InputHandler.SELECT_DOC_END);
inputHandler.addKeyBinding("CS+DOWN", InputHandler.SELECT_DOC_END);
inputHandler.addKeyBinding(mod + "+ENTER", InputHandler.REPEAT);
document = new SyntaxDocument();
editable = true;
electricScroll = 3;
cols = 80;
rows = 15;

This is roughly line #136 (As of Arduino IDE Version 0022)

Now, between these two lines:

inputHandler.addKeyBinding(mod + "+ENTER", InputHandler.REPEAT);
======RIGHT HERE======
document = new SyntaxDocument()

You will paste this code:

// Custom - A little bit of Emacs
inputHandler.addKeyBinding("C+f", InputHandler.NEXT_CHAR);
inputHandler.addKeyBinding("C+b", InputHandler.PREV_CHAR);
inputHandler.addKeyBinding("C+p", InputHandler.PREV_LINE);
inputHandler.addKeyBinding("C+n", InputHandler.NEXT_LINE);
inputHandler.addKeyBinding("C+a", InputHandler.HOME);
inputHandler.addKeyBinding("C+e", InputHandler.END);
inputHandler.addKeyBinding("C+k", InputHandler.SELECT_END);

Go back to this page --> http://code.google.com/p/arduino/wiki/BuildingArduino, build and run your fancy new Arduino IDE. If you are familiar with Emacs you should be able to figure most of the KeyBindings out. However, there is one caveat. I couldn't figure out how to cut text from the cursor to the end of the line (sometimes called a "yank"). So, as a workaround I just have Control+k selecting the text from the cursor to the end of the line. Then one could use copy or cut shortcuts from there.

I hope this helps someone else because I know it has helped me a ton. Thanks for reading.