Sugar hx Textmate
The sugar-hx TextMate bundle is available here.
Basic Features
- Syntax Highlighting Support
- Project Template
- Common tab triggers for code blocks
Advanced Features
All of the advanced features require a project folder, since they typically rely on integrating the compiler output for both the current class file, as well as the current hxml file. It's highly recommended that projects start from the project template available with this bundle.
HXML Build Specification
The bundle will default to using a build file called "build.hxml" if it exists. Pressing Cmd-B will build the current project.
A different hxml file can be respecified using Cmd-Shift-B. The bundle will search the current project folder for all hxml files, and will present a list for selection. The current alternate build file location is saved in .tmbuild in the project root. This can be altered by hand if necessary to point to a file external to the project, but this is not recommended.
The build command produces an html display of the compiler output. If there are errors, clicking on the error will take you directly to the error indicated by the compiler. Alternatively, pressing a number key will jump immediately to the corresponding error location.
Code Completion
Code completion is triggered using the standard Esc key. However, it only replaces the default TextMate completions when triggered after a potential field, with an additional period or paren: field. or field(.
If a code completion request occurs, then the current build file specified will be built with a --display compiler directive at the current cursor location. If the current build file contains multiple target directives (using the --next compiler command), the build file will be split into several sections based on the --next locations. By default, only the first section is used for autocompletion. However, it is possible to specify an alternate build section by using a special hxml comment switch "# @tm-autocomplete". Using this switch will not affect normal compilation.
For instance, consider the following build file:
# build file -main Foo -X foo --next -main Bar -X bar
Completions requested on this build file will be generated according to the first section, producing -X foo. If you use the tm-autocomplete switch:
# build file -main Foo -X foo --next -main Bar -X bar -D tm-autocomplete
Now completions will be performed on the second section.
Code completions triggered with Esc produce a small popup indicating if the field is a package, class, function, or property. If a function is selected, a snippet is automatically produced that allows for easy argument specification.
Import Helper
Imports can automatically be specified after an appropriate class name by pressing Cmd-I. This can be done in the following example:
class Demo { public static function main(): Void { var h = new Timer|(); } }
This code has not imported a Timer class, so
By pressing Cmd-I at the caret (|), a list pops up with possible classes, taken from the libraries and code paths indicated in the current build hxml. Selecting one of these classes will automatically insert an appropriate "import" command at the top of the file, without changing the current cursor position:
import haxe.Timer; class Demo { public static function main(): Void { var h = new Timer|(); } }
The import helper command can also be triggered after an import statement:
import Ti| class Demo { public static function main(): Void{} }
This will present a similar list of possible classes, and will complete the import directive appropriately:
import haxe.Timer; class Demo { public static function main(): Void{} }
There is also an unused import helper that will try and find imports that aren't used in the current file. This is triggered by Shift-Cmd-I.
AutoDoc Generation for Help
The command Shift-Cmd-H will create haxedoc generated documentation for the current project. This includes all external libraries and paths. The html content will be placed in a folder called ".haxedoc" located in the project directory root.
The command Cmd-H is a help command that will automatically open the corresponding autodoc generated html file for the class indicated under the cursor. This currently only works for classes, so other function names and keywords will throw an error.
It is also possible to open a class referenced in the code directly by the command Ctrl-Cmd-O. Be careful with this command, as it will open the base Haxe class files as well. Those should not be modified in normal circumstances.
Smart JavaDoc comment blocks
The tab trigger "doc" has special behavior. Tab triggering doc before a class declaration will automatically insert a class snippet, with all relevant javadoc style "@" fields populated. Tab triggering doc before a method will automatically insert a method snippet, with all relevant method fields, etc. Tab triggering elsewhere will insert private documentation snippets.
Currently, haxedoc does not support JavaDoc style fields inside comment blocks, so the default behavior for AutoDoc commands will likely change if support is not added.
JS, SWF, and HTML output embedding
Since JS and SWF cannot output to STDOUT, it is commonly necessary to open or embed them with additional commands. The TextMate bundle will embed JS and SWF output into the build results if the hxml comment switch "# @tm-preview" is included somewhere in the hxml.
In addition, it is possible to include arbitrary html in the output with the "# @tm-html" switch. Any additional text added on the same line after this switch will automatically get inserted into the build results. For instance:
# @tm-html <img src=http://haxe.org/img/haxe/logo_haxe.gif>
This command will add a haxe logo to the build result.
This html command can be useful to add additional divs and script locations for javascript specific externs. Such an addition can be done via the "script" tab completion command, which will produce:
# @tm-html <script type="text/javascript" src="|"></script>
likewise, the "div" tab completion command will produce:
# @tm-html <div id="|"></div>
Additional Notes
Keep in mind that the webkit browser included with textmate has its own debugging capabilities. It is possible to view a large amount of details via the built in html browser, which is accessible by pressing Control-Click on the build result page, and then inspecting an arbitrary element.