Semantic font-lock for Java in Emacs
I've
been working on Semantic font-lock for Java using CEDET Semantic
infrastructure which uses Wisent incremental parsing under the hood. Also it only highlights the visible text on the screen to keep the delays acceptable. So
far the results look promising.
Builtin font-lock uses jit-lock infrastructure. cc-mode provides the keywords and regexes for language specific highlighting. However, this lacks highlighting using any contextual information.
Noticeable features:
- Static variables and functions are highlighted differently.
- Constant variables are highlighted differently.
- Not only the declaration, but the usages are highlighted also.
- Package is highlighted correctly.
It uses following face definitions for highlighting.
(defvar semantic-format-face-alist `( (function . font-lock-function-name-face) (variable . font-lock-variable-name-face) (type . font-lock-type-face) ;; These are different between Emacsen. (include . ,'font-lock-constant-face) (package . , 'font-lock-constant-face) ;; Not a tag, but instead a feature of output (label . font-lock-string-face) (comment . font-lock-comment-face) (keyword . font-lock-keyword-face) (annotation . font-lock-builtin-face) (constant . bold) ;;(member . font-lock-member-face) (abstract . italic) (static . italic) (documentation . font-lock-doc-face) )
Code: Emacs customization (https://gitlab.com/atamariya/emacs/tree/dev)
You can follow the exact code here https://gitlab.com/atamariya/emacs/compare/v0.5...dev
Most relevant changes are in lisp/cedet/semantic/java.el . Other minor changes are for disabling jit-lock.
- Font lock setup : semantic-font-lock-mode()
- Fontify region function: semantic-fontify-region()
- Helper function: semantic-fontify-tag()
Here are some other differences. These are based on test cases derived from cc-mode test cases.
Here are some other differences. These are based on test cases derived from cc-mode test cases.
Built-in Font-lock | Custom Font-lock | |
1 |
- Syntax errors are ignored. - @interface is highlighted as a keyword. | - MyClass is not highlighted because of syntax error. - @interface is highlighted as an annotation. - Highlighting after correction. |
2 |
- Syntax errors are ignored. | - Highlighting after correction. |
3 | - Generics | - Generics |
Comments
Post a Comment