I'm working on modifying Haxe mode for Emacs. It is based on c-mode, Java language.
After this mode was created, the language introduced new construct, it is similar in style to Java annotations, except for one thing:
@:macro public function foo() { ... }
is an annotation too. I.e. the part "@:macro" is an annotation, but c-mode treats the annotation as if it had to be "@" symbol followed by letters (once it sees ":", it thinks it's the end of the annotation).
What is the rule it is using for parsing annotations and how would I modify it?
Below is something that I've tried to do, but it neither works, nor am I sure it's the right way to do it.
(defadvice c-forward-annotation
(around haxe-forward-annotation ())
"Overrides `c-forward-annotation' to be able to use @:\w+ syntax as well
as the Java original syntax."
(message "c-forward-annotation overloaded")
(and (looking-at "@")
(progn (forward-char) t)
(if (looking-at ":")
(progn
(forward-char)
(c-forward-type))
(c-forward-type))
(progn (c-forward-syntactic-ws) t)
(if (looking-at "(")
(c-go-list-forward)
t)))
The function seems to actually do the job properly, what doesn't work later is the c-beginning-of-statement-1
- but it's too complex to find out what is actually happening...
One more thing I've tried:
(c-lang-defconst c-symbol-start
haxe (concat "[" c-alpha "_@]:?"))
but didn't help either. Even some more info: if I C-c C-s on the line containing @:macro
I get cpp-macro
syntax, which is so ironically close, but not what I need.
More info: by overriding c-beginning-of-macro
I could make it believe it is not a cpp-macro
, however it is still not recognized as annotation. I've also overridden the place in c-forward-decl-or-cast-1
where it had a hardcoded regexp for testing for Java-style identifiers... still no go :(
Also changed in the (c-lang-defconst c-basic-matchers-after ...)
to the below, but still no go...
,@(when (c-major-mode-is 'java-mode)
`((eval . (list "\\<\\(@:?[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))