Because it came up yesterday and I already have the bad reputation to like Java, here it goes: A somewhat better Java Syntax than the included one:
Features: - Better colouring (due to the old syntax being outdated) - Goto Symbol popup working
Bugs: - Keep the closing parentheses and the opening brace ) { of a method declaration on the same line, otherwise the end pattern won't match - More to come soon ;)
Soryu
{ scopeName = 'source.java'; comment = ' Credits to Brian Lalor, who wrote the Java syntax included in TM. I might have adapted some of his syntax. Soryu Comments: • I excluded overridden anonymous Constructors from "declaration.function.method.java", so they won''t show up in the Goto Symbol popup to reduce clutter a little. '; fileTypes = ( 'java' ); foldingStartMarker = '/**|{\s*$'; foldingStopMarker = '**/|^\s*}'; patterns = ( { name = 'comment.line.double-slash.java'; begin = '//'; end = '$'; swallow = '\\s*\n'; }, { name = 'comment.documentation.java'; begin = '/**'; end = '*/'; patterns = ( { match = '*\s*(@)(param)\s*([a-z][a-zA-Z0-9_]+)\s*'; captures = { 1 = { name = 'keyword.other.documentation.control'; }; 2 = { name = 'keyword.other.documentation.params.java'; }; 3 = { name = 'keyword.other.documentation.value.java'; }; }; }, { match = '*\s*(@)([a-zA-Z0-9_-]+)\s*'; captures = { 1 = { name = 'keyword.embedded-docs.control.java'; }; 2 = { name = 'keyword.embedded-docs.params.java'; }; }; }, ); }, { name = 'comment.block.java'; begin = '/*'; end = '*/'; }, { name = 'meta.package.java'; match = '(package)\s+([^ ;]+?)\s*;'; captures = { 1 = { name = 'keyword.other.java'; }; 2 = { name = 'entity.name.package.java'; }; }; }, { name = 'meta.import.java'; match = '(import)\s+([^ ;]+?);'; captures = { 1 = { name = 'keyword.other.java'; }; 2 = { name = 'entity.name.class.java'; }; }; }, { name = 'declaration.class.java'; match = '\b(?<=class|interface|enum)\s+(\w+)'; captures = { 1 = { name = 'entity.name.class.java'; }; }; }, { name = 'other.inheritance.class.java'; comment = 'TODO: implements has multiple Parameters, Extends does not'; match = '\b(?<=extends|implements)\s+(\w+)'; captures = { 1 = { name = 'entity.name.class.java'; }; }; }, { name = 'declaration.function.method.java'; begin = '\b(?<!new)\s+(\w+)\s*('; end = ')\s*{'; captures = { 1 = { name = 'entity.name.function.java'; }; }; patterns = ( { include = '#keywords'; } ); }, { name = 'constant.numeric.java'; comment = 'stolen from c syntax without looking very much at it'; match = '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+.?[0-9]*)|(.[0-9]+))((e| E)(+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b'; }, { name = 'keyword.flow.java'; match = '\b(if|else|while|for|return|continue|break|switch|do|goto| case|try|catch|finally|throw)\b'; }, { name = 'keyword.other.simple-types.java'; match = '\b(int|char|float|long|double|boolean|byte|short)\b'; }, { name = 'keyword.operator.comparison.java'; match = '(==|!=|<=|>=|<>|<|>)'; }, { name = 'keyword.operator.increment-decrement.java'; match = '(--|++)'; }, { name = 'keyword.operator.arithmetic.java'; match = '(-|+|*|/|%)'; }, { name = 'keyword.operator.logical.java'; match = '(!|&&|||)'; }, { name = 'storage.modifier.java'; match = '\b(private|public|protected|static|transient|final| abstract|native|threadsafe|synchronized|volatile|strictfp)\b'; }, { name = 'storage.type.java'; match = '\b(class|interface|enum)\b'; }, { include = '#string-double-quoted'; }, { include = '#keywords'; }, ); repository = { keywords = { name = 'keyword.other.java'; match = '\b(new|abstract|assert|default|synchronized|private| protected|public|throws|enum|instanceof|transient|final|interface| static|void|null|class|finally|strictfp|volatile|const|native|import| package|extends|implements|this|super|true|false|if|else|while|for| return|continue|break|switch|do|goto|case|try|catch|finally|throw|int| char|float|long|double|boolean|byte|short)\b'; }; string-double-quoted = { name = 'string.quoted.double.java'; begin = '"'; end = '"'; patterns = ( { name = 'constant.character.escaped.java'; match = '\.'; } ); }; }; }
On Nov 2, 2005, at 5:32 PM, Soryu wrote:
foldingStartMarker = '/**|{\s*$'; foldingStopMarker = '**/|^\s*}';
Thanks, Soryu, this looks good. It's nice to see this syntax getting some love. :-)
The folding's giving me problems, however. I do my javadoc blocks like this: /** * comment here */
Note that the asterisks are indented one add'l space from the initial "/" at the beginning of the block. The problem is that TM shows the beginning folding marker, but never the 2nd. I've been tinkering with the foldingStopMarker, but even with foldingStopMarker = '^\s*( ?*+/|})'; it fails to work.
Is this a "feature" of TextMate? Is it interpreting the leading space as a different indent level than the opening "/**"?
On 08/11/2005, at 19.36, Brian Lalor wrote:
Is this a "feature" of TextMate? Is it interpreting the leading space as a different indent level than the opening "/**"?
It is, yes. In this case it would be better if TM used everything to the left of the match as the indent, but I'm afraid that there's a lot of folding patterns where that wouldn't work (e.g. matching { at the end of the line).
Come to think of it, it could probably be solved by doing: indent -= indent % tab_size.