View CocoaSugars
While Espresso’s language system can easily be extended using only XML (SugarBasics), sugars can also contain compiled Cocoa code. This gives you a rich API with extensive access to Espresso’s syntax metadata model. Currently, you can create the following Cocoa extensions:
- Custom “items”, used in the Itemizers. Together with the XML itemizer definitions, this allows you to create Navigator listings that work perfectly with a specific language.
- TextActions. Get access to a document’s text along with its syntax and itemizer metadata and create awesome transformations and functionality.
- FileActions. Create custom actions for local and remote file listings.
If you are not familiar or comfortable with Cocoa bundles yet, you may find the Intro to Cocoa Sugars and Espresso Cocoa API useful places to start. If you are interested in coding Espresso actions but disinclined to work in Objective-C, see Types of Custom Actions. Otherwise, the resources below should give you a place to start.
Headers
The Espresso API’s headers come with every build of Espresso, and are located in Espresso.app/Contents/Headers. The best way to learn about the possibilities is to look at these documented headers.
Example Sugar
Right now, the easiest way to dig in and learn more about the Cocoa Sugar API is to download the example. You need Apple’s Xcode Tools installed to compile.
1. Download the Example Cocoa Sugar.
2. Open Example Sugar.xcodeproj.
3. Open the project inspector and set the ESPRESSO_PATH variable to wherever Espresso is installed. (Do this by choosing Project > Edit Project Settings in Xcode, then going to the Build tab and finding the ESPRESSO_PATH setting all the way down the list).
4. Optionally change the sugar’s product name to something of your own.
5. Compile!
6. Install into ~/Library/Application Support/Espresso/Sugars
7. Relaunch Espresso to test
Example Sugar (Python flavor)
If for whatever reason you’re interested in coding in Python rather than Objective-C, it’s possible to code Sugars without ever touching Xcode. Here’s the steps:
- Download the PyExampleSugar (a direct port of the Cocoa Example Sugar above into Python)
- Open up Terminal, navigate to the PyExampleSugar directory and run
python setup.py py2app(see the setup.py file for how to create a development version you can edit without recompiling) - Move the newly created ExampleSugar.sugar out of the ./dist directory and into ~/Library/Application Support/Espresso/Sugars
- Relaunch Espresso to test
For more detailed information, see CocoaSugars in Python.