Skip to content

44. Editing in Codea

April 28, 2013

After a couple of months with Codea, this is what I’ve learned about editing.

Tips for the built in keyboard

The row of keys along the top is really useful. The little eye brings up the built in documentation, the key with +-x has a bunch of useful keys, and I use the double headed arrow selector button all the time.

A couple of things that aren’t obvious

  • if you swipe up or down on the double headed arrow key, you go up or down a line
  • you can indent or comment out multiple lines at once by selecting them before pressing the indent/comment key
  • you can put brackets or double quotes around existing text by selecting it before pressing the ( ) or ” ” key on the top row



I’ve found the tabs in the editor are useful for code that you want to keep separate, or code you are perhaps just playing with. So I often create a blank tab and put code in there that is not a class or anything.

Backing up code

I backup a couple of different ways. I keep a permanent copy of most versions of my code in Pages, but any text editor will do as well, eg Evernote. I would use an app that is backed up in the cloud, in case something happens to your iPad.

if you have multiple tabs, the best way to copy code is to go out to the main Codea screen, and hold down your project icon until you get a copy option. This copies all the code in all the tabs to the clipboard, so you can paste straight into your backup app. Then, when you want to bring it back into Codea, press down the Add New Project icon, until you get the option to paste into new project. This will restore all your tabs, just as they were.

Note – when you are importing code from other people (including me), always start by pressing the Add New Project icon in Codea, so the code will go neatly into the original tabs. If, Codea doesn’t give you the option of pasting into a new project, then you are out of luck and will have to create a new project and paste all the code into one big pile.

Copy and paste backup is a bit tedious, however, so I’m guessing most of us don’t do it often enough. Sometimes, you need a more temporary backup option, for when you hit small checkpoints, or you’re about to try something a little adventurous.

I wrote this code to fill the gap. It is a Codea project that you link to your project (the notes tell you how), and you add one line of code at the top of your project, containing a version number.

Every time you change the version number (and only when you change the number), the backup code will make a copy of your code, saved as an image in your Documents folder. There is an option to restore a backup if you need to. So this makes it easy to make incremental backups on the fly.

If you use this, check it works (ie restores properly) before leaning on it too heavily. There is no warranty!

Is a physical (Bluetooth) keyboard worth it?

Definitely, in my opinion, if you code a lot (and can afford it). It makes editing much easier, doesn’t take up most of the screen with a keyboard, and still gives you the row of special keys. I bought the one in the Apple store, and it’s great.

My only minor frustration is that I’ll take my iPad outside to do some editing, leaving the keyboard inside, and the iPad won’t bring up the onscreen keyboard because it can still “see” the Bluetooth keyboard and assumes I’m using that, so I can’t type until I disable Bluetooth.

But it’s still well worth it, for me.

Coding to music

I like to work to music, and I find it a bit irritating that Codea turns it off.

You can restart it by double pressing the main iPad button to bring up the row of currently running apps at the bottom of the screen, then swipe left to get the audio controls, and start the music again. It should work in Codea after that (until you restart Codea, of course).


From → Programming

  1. Saurabh permalink

    Thanks I was searching for a way to back up my codes

  2. Dwinner permalink

    You can also save projects as text files to dropbox through the assets folder on the home screen

  3. Scott permalink

    Having a bit of trouble running the Backup program.

    I created the Backup program in Codea and added it as a dependency to my test project.
    I added the following line in my test project setup(): b=Backup(“MyProject Ver 100”)
    The error says I am attempting to index a nil value (global: Backup)
    I suspect my proplem has to do with what I have in the parentheses. The notes instructed me to add a line like that into setup() and I literally did just that.

    If someone can get me back on track I would appreciate it very much.


  4. Scott permalink

    OK, forget the above posted question by me. I have that resolved. Call it “Pilot Error” I now have the Backup project created and all the tabs are in place. Big difference between pressing New Project and pressing and holding New Project.

    Now I just have to figure out where my backed up project goes when Backup runs. I’m doing all my programming on the iPad so the Documents folder may not be the destination.

    Thanks again for any help you can give.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: