- My favorite Textmate HTML actions (Wrap Selection in Tag, Insert Open/Close Tag with Current Word, Wrap Selection in Link, etc.)
- The ability to add your own actions, whether by using generic TEA actions with different snippets via XML or writing completely custom scripts in Python (making use of the helper functions that TEA provides)
- 100% Python, with source code freely available under the MIT license at the GitHub tea-for-espresso project for anyone interested in creating Python Sugar actions outside of TEA
- I’ve stuck some pretty extensive documentation for the Sugar and how you can customize/extend it over at the GitHub wiki for those who want to test out the waters
Caveats:
- There’s no good way to edit current TEA actions without delving into the Sugar and modifying the XML files.
A lot of the functionality that’s cool about this Sugar is actually already baked into Espresso; there’s just no easy interface to create your own snippets (or published method to insert and modify selected text in a snippet).
My hope is that Jan will add an interface to allow users to easily add and edit snippets of their own without editing XML, since ideally the TEA plugin should only be needed for actions that require more extensive internal logic than “wrap selected text in such and such a snippet when such and such a hotkey is invoked”.
If you’ve already downloaded TEA for Espresso beta 1 and are going to use Insert Tag From Word, please redownload. I stupidly was only allowing alphabetical characters in the word, which of course meant it was failing on H1, H2, etc.
Known bug: text snippets aren’t auto-completing themselves right. This was working when I initially tested it (if I remember correctly), but now closing tags are being populated with everything in the opening tag. As best I can tell there’s a bug in Espresso that’s preventing Textmate-style mirroring from working, but I will experiment and see if anything I’m doing in the TEA code is causing the problem.
I’ve updated TEA for Espresso to beta 2. Aside from some code shuffling, which won’t matter to anyone since no one is currently playing with the source that I know of, the only change is the addition of the Convert to Named Entities and Convert to Numeric Entities actions. Behavior is as follows:
* Select some text, and run the action to convert all non-ASCII characters into their HTML entity equivalents
* Invoke the action without a selection and it will run on the character immediately to the left of your cursor
* If you use Convert to Named Entities and you have a high-value Unicode character that doesn’t have a named equivalent, it will automatically be converted to a numeric entity instead
* Quotes, less than/greater than symbols, and other stuff that’s necessary for HTML tags should not be touched, so feel free to select text that has HTML scattered in it
Let me know if you run into any problems or would like to see any improvements!
This release was less interesting than I was hoping because most of the fixes and improvements I have planned for current actions are dependent on bug fixes or improvements in Espresso, but I wanted to release it anyway because some other folks were needing character entity conversion.
Glad to hear the Sugar is useful! If you’re trying to run the stuff from GitHub, you have to compile it first (since it’s a Cocoa plugin rather than a standard XML-based syntax Sugar). If you’d like to do this, once you’ve run your `git clone` command, `ls` to the newly created tea-for-espresso directory and run `python setup.py py2app`. The Sugar will show up in a new `dist` directory, and you can just drag it to your Sugars folder and relaunch Espresso. (That said, GitHub is currently identical to the version in the zip, so this shouldn’t change anything.)
For the errors, I’m not sure which action you’re using that’s failing (for the first error). For the second, it sounds like my error checking isn’t comprehensive enough for blank selections; I’ll take a look at that.
For the errors, I’m not sure which action you’re using that’s failing (for the first error). For the second, it sounds like my error checking isn’t comprehensive enough for blank selections; I’ll take a look at that.
The first error is when the document is empty, and you try any tab-completion snippet. It needs to have something in it, even a space works.
Another bug :D :
Error: <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'stringValue'
Appears when you open a brand new document with no language selected. Any text-snippet dies with this error. Assign a language and all fine afterwards.
Work was super boring, so I took a break and fixed these bugs. The bug fixes are currently only in GitHub (the beta 2 download will still have the bugs). rdougan, I’ll send you a new build via PM for you to test out if you’d like (can’t upload zip files to threads, but can to PMs; go figure).
Let me know if the bugs recur, you come across any other problems, have any feature requests, etc.!
Work was super boring, so I took a break and fixed these bugs. The bug fixes are currently only in GitHub (the beta 2 download will still have the bugs). rdougan, I’ll send you a new build via PM for you to test out if you’d like (can’t upload zip files to threads, but can to PMs; go figure).
Let me know if the bugs recur, you come across any other problems, have any feature requests, etc.!
Just tested this version out and the bugs seem to be gone- Nice one!
I’m currently working on a JavaScript snippets ‘bundle’ now. It would be cool if you could link up multiple action files and not just UserActions/UserCategories. Not sure how you’d do that though as I see you are currently using symlinks.
Update:
Another bug, if the text-trigger is not at the start of the line, or there is anything else on the line ’ div’ or ‘div o hai der’, where ‘div’ is the trigger.
Error: <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'stringValue'
Update #2:
If there is nothing in the file and a language IS set, the earlier bug appears again:
Error: <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'typeIdentifier'
Fine if the language isn’t set/something already in the file.
I have just finished porting the TextMate JavaScript snippets over to this, plus mine and edspencers ExtJS/JSDoc tmbundle. You can find it over on Github.
Do note, though, that there’s currently a bug in Espresso that’s causing mirrored snippets to not work quite right (you can see this with Wrap Selection In Tag, for instance).
I’ve bumped TEA for Espresso to beta 3. Beta 3 contains bug fixes for the errors that Robert found, and adds symlinks so that you can take advantage of the Javascript snippets that rdougan ported without needing to use your UserActions.xml file for them. To have TEA for Espresso automatically pick up on Robert’s Javascript actions do this:
cd ~/Library/Application\ Support/Espresso/TEA/ git clone git://github.com/rdougan/tea-for-espresso_javascript-extjs-jsdoc.git Javascript
Then rename the UserActions.xml in the Javascript folder to Actions.xml, and UserCategories.xml to Categories.xml. Relaunch Espresso and enjoy your Javascript snippets.
Just a note: my hope is that Jan will add an interface element that will blow TEA for Espresso’s text snippet support away (or at the very minimum add an easy way to create simple tab-completions via XML that’s less complicated than that necessitated by TEA for Espresso and doesn’t require a Sugar), so hopefully this symlink-driven solution will be short-lived. However, in the meantime if other folks have any collections of snippets that they think would be useful to include just give me a shout. Adding symlinks is easy.