
I’ll share with you guys how to hack your Coda Editor in order to expand the auto-complete feature to include your own functions, regardless if you are using an open framework or just building from scratch.
As you can see in figure 1 and figure 2, I have modified my Coda to work with CodeIgniter php Framework. Now I am able to auto-complete some of the functions (they are a lot) and even complete constructer and model templates by typing three keys.
Ok.. so lets get to work.
- First of all, create a copy of your Coda application, just in case we fuck up really bad. (quite improbable).
- Second, open up your Coda contents by right-clicking the application and selection “Show Package Content” then go to folder Contents->Resources and hold it right there - or - you can simply type (shift+command+g) and type “/Application/Coda.app/Contents/Resources”  Newer versions of coda come with the files in Modes/*.mode/Contents/Resources/ Where * is your language or script or whatever you want to modd.
- Once there you will find lots of interesting files, sort them by size, and you will see all the xml files. All of them but one are the auto-complete dictionaries (i know you are exited by now)!
- Open up any you like I modded the php cuz im using code-igniter. Its a very big file, personally i preferred to open up with good old textEdit so i don’t waste too much ram on it.
When you open it you will find a xml well formatted, what we want to do is to add a sibling to file so lets take a brief look at the structure:
<dict>
<key>Hint</key><string>mixed number</string>
<key>ID</key><string>abs</string>
<key>MoveCursor</key><string>1</string>
<key>PostString</key><string>()</string>
<key>String</key><string>abs</string>
</dict>Â
Â
It consist of 5 variables, with a definition key and a string for its value.
-
- Hint: the actually string to be typed for you
- ID: identifier for the auto-complete item (make it unique)
- MoveCursor: Character spaces you want the cursor to move inside the auto-completed string
- PostString: This characters will enclose your Hint
- String: the actuals tying you type upon which coda will filter
Here’s a Very Basic Example
<dict>
<key>Hint</key><string>session_id</string>
<key>ID</key><string>$this->session->userdata</string>
<key>MoveCursor</key><string>2</string>
<key>PostString</key><string>('');</string>
<key>String</key><string>$this->session->userdata</string>
</dict>Â
Â
- As you can see i named the ID with the same string as the “string” key to avoid duplications.
- I enclosed (used in poststring) the opening and closing tags along with semicolon
- Moved the cursor two characters to the right, this will cause the character to end up just after the quote. This is important because all the string in the Key hint will be selected by default to be replaced, in this case the string session_id will be selected for me to immediately start typing my desired id or variable and finally the hint that i want to get
Lets get to a bit more complex (not that much) example:
<dict><key>Hint</key><string>your@your-site.com</string>
<key>ID</key><string>$this->email->from</string>
<key>MoveCursor</key><string>2</string>
<key>PostString</key><string>('', 'Your Name');</string>
<key>String</key><string>$this->email->from</string>
</dict>
Lets place attention to the PostString KeyI included part of the functions content in the closing string for a reason, they will still be included within the autocomplete hint but since they are not part of the Hint key, they will not be autoselected when the hint is typed for me, so only the Hint string “your@your-site.com” hence i can start replacing this email right away without having to delete all the functions contentWell this is pretty much it, its quite straight forward. Just a hint
- You will have to restart Code every time you add new functions to the list, so be ready to add them as a batch.
- If Coda simply hangs up, or crashes, (happened zillions of times for the first time) it only means you typed in a malformed entry in the list
- review it or delete it and everything will be back to normal.
@CodeIgniter Community
I really started to use Codeigniter this same week I actually havent made my first app.I’ve done some work with the first classes from the user guide, but it would take a lot of time to include the complete framework all by my self and probably i’m taking the risk of not implementing the autocomplete functions the best it can.If you guys want to help me out i’m sure all the community can benefit from our efforts, drop me a msg and we can distribute the work.











October 29th, 2007 at 10:07 pm
Any news on how to do this with the latest version of Coda? There are no longer .xml files, .modes instead (I think).
October 29th, 2007 at 10:32 pm
mhh no idea, i switched to textmate,
ill download the new version of coda and play with its guts… and get back to you…
November 1st, 2007 at 7:43 pm
ok found em’
1) right click on your coda app and select “show package contents”
2) browse to: Modes/*.mode/Contents/Resources/ Where * is your language or script or whatever you want to modd.
3) Open up the CodaCompletion.plist with you favourite texteditor.
4) mod it, save it, restart coda, and have fun