A development system for the Haxe programming language.
Battle-haxe adds code-completion and IDE-like features when editing Haxe code, provided by the
Haxe compiler’s “compiler services” feature in server mode.
See Installation section to get started.
The main quirk is that the system has to force automatic saving of the edited Haxe File. ( Big issue )
- Member completion (via company-mode), for example after “myObject.” or “override ”
- Type completion, for example after “new ” or “import ”
- If you auto-complete a class name, for example after “new ” completion, it will automatically import the class as well
- Jump to the definition of the current symbol with a key. Press another key to go back to where you were
- Find all references of the current symbol (choose between them using helm)
- Eldoc support
- Optionally expand method calls completions using yasnippet.
- Before a compiler services action is called, the document is always automatically saved without question. This is because the Haxe compiler doesn’t accept compiler services calls when using other (temporary) files, so for now I had Haxe process the real file path instead and had the document forcibly saved. This is not an issue for me at all (I spam SAVE in all programs anyway), but if it is for you, don’t use the package!
- You MUST have a file with .hxml extension in the root project folder. (https://haxe.org/manual/compiler-usage-hxml.html) You must have it for the compiler to know what to check and which libraries you depend on. This file however does not exist in frameworks that compile your project differently (For example Lime/OpenFL projects, see that section for a solution).
- This package doesn’t handle multiple simultaneous projects or running multiple Haxe completion servers yet.
If you want to switch to another project, run the
battle-haxe-start-server
command in the new project to restart the server there.
- With MELPA:
M-x install-package "battle-haxe"
- Without MELPA (manual installation):
- First install the following packages which are required as dependencies:
company
,helm
,async
,dash
,f
,s
, and optionally,yasnippet
.
- Git-clone this package and add it to your load path, for example:
;; Tell Emacs where your elisp library sits (add-to-list 'load-path "~/.emacs.d/lisp/battle-haxe")
- First install the following packages which are required as dependencies:
- If you have use-package, this is a template you can insert to your init file to load the package:
;; This isn't really a package, it just provides a `haxe-mode' to work with
(use-package haxe-mode
:mode ("\\.hx\\'" . haxe-mode)
:no-require t
:init
(require 'js)
(define-derived-mode haxe-mode js-mode "Haxe"
"Haxe syntax highlighting mode. This is simply using js-mode for now."))
(use-package battle-haxe
:hook (haxe-mode . battle-haxe-mode)
:bind (("S-<f4>" . #'pop-global-mark) ;To get back after visiting a definition
:map battle-haxe-mode-map
("<f4>" . #'battle-haxe-goto-definition)
("<f12>" . #'battle-haxe-helm-find-references))
:custom
(battle-haxe-yasnippet-completion-expansion t "Keep this if you want yasnippet to expand completions when it's available.")
(battle-haxe-immediate-completion nil "Toggle this if you want to immediately trigger completion when typing '.' and other relevant prefixes."))
- Customize this as you will.
- Ensure you have a correct “.hxml” file in project root.
- Open a “.hx” file and you should have completion available in company-mode.
The package uses the Haxe compiler directly and doesn’t use Lime’s “Project.xml” config file,
but here is a template “some-project.hxml” to get you started for this use case:
-cp src
-lib lime
-lib openfl
-js example.js
- This package is intended to support only the latest and greatest Haxe compiler version (currently
4.0.0-rc.3
). - There is no haxe-specific syntax highlighting/indentation mode included.
However the
js-mode
(that drives thehaxe-mode
) does a good job with most Haxe code that it’s less urgent to create a specialized mode. However, Using “js-mode” directly for Haxe documents would be confusing. That’s why I include theuse-package
block for defining ahaxe-mode
. It’s also useful for interacting with other packages - such asyasnippet
storing your snippets under a predictable “haxe-mode” folder.
I just found it funny that the language’s creator gave it the name “Haxe” but pronounces it as “Axe”.