Skip to content

Instantly share code, notes, and snippets.

@cameronbracken
Created August 1, 2011 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronbracken/1119021 to your computer and use it in GitHub Desktop.
Save cameronbracken/1119021 to your computer and use it in GitHub Desktop.
TextMate syntax highlighting for R with roxygen
{ scopeName = 'source.r';
fileTypes = ( 'R', 'r', 's', 'S', 'Rprofile' );
foldingStartMarker = '^[^#]*(\([^\)]*$|\{\s*$)';
foldingStopMarker = '(^\s*\)|^\s*\})';
patterns = (
{ name = 'comment.line.number-sign.r';
match = "(#(?!').{1}).*$\n?";
captures = { 1 = { name = 'punctuation.definition.comment.r'; }; };
},
{ name = 'storage.type.r';
match = '\b(logical|numeric|character|complex|matrix|array|data\.frame|list|factor)(?=\s*\()';
},
{ name = 'keyword.control.r';
match = '\b(function|if|break|next|repeat|else|for|return|switch|while|in|invisible)\b';
},
{ name = 'constant.numeric.r';
match = '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(i|L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b';
},
{ name = 'constant.language.r';
match = '\b(T|F|TRUE|FALSE|NULL|NA|Inf|NaN)\b';
},
{ name = 'support.constant.misc.r';
match = '\b(pi|letters|LETTERS|month\.abb|month\.name)\b';
},
{ name = 'keyword.operator.arithmetic.r';
match = '(\-|\+|\*|\/|%\/%|%%|%\*%|%in%|%o%|%x%|\^)';
},
{ name = 'keyword.operator.assignment.r';
match = '(=|<-|<<-|->|->>)';
},
{ name = 'keyword.operator.comparison.r';
match = '(==|!=|<>|<|>|<=|>=)';
},
{ name = 'keyword.operator.logical.r';
match = '(!|&{1,2}|[|]{1,2})';
},
{ name = 'keyword.other.r';
match = '(\.\.\.|\$|@|:|\~)';
},
{ name = 'string.quoted.double.r';
begin = '"';
end = '"';
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.r'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.r'; }; };
patterns = (
{ name = 'constant.character.escape.r';
match = '\\.';
},
);
},
{ name = 'string.quoted.single.r';
begin = "'";
end = "'";
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.r'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.r'; }; };
patterns = (
{ name = 'constant.character.escape.r';
match = '\\.';
},
);
},
{ name = 'meta.function.r';
match = '([[:alpha:].][[:alnum:]._]*)\s*(<-)\s*(function)';
captures = {
1 = { name = 'entity.name.function.r'; };
2 = { name = 'keyword.operator.assignment.r'; };
3 = { name = 'keyword.control.r'; };
};
},
{ name = 'meta.method.declaration.r';
match = '(setMethod|setGeneric|setGroupGeneric|setClass)\s*\(\s*("|\x{27})([a-zA-Z._\[\$@][a-zA-Z0-9._\[]*?)\2';
captures = {
1 = { name = 'entity.name.tag.r'; };
3 = { name = 'entity.name.type.r'; };
};
},
{ match = '([[:alpha:].][[:alnum:]._]*)\s*\('; },
{ match = '([[:alpha:].][[:alnum:]._]*)\s*(=)(?=[^=])';
captures = {
1 = { name = 'variable.parameter.r'; };
2 = { name = 'keyword.operator.assignment.r'; };
};
},
{ name = 'invalid.illegal.variable.other.r';
match = '\b([\d_][[:alnum:]._]+)\b';
},
{ name = 'entity.name.type.namespace.r';
match = '\b([[:alnum:]_]+)(?=::)';
},
{ name = 'variable.other.r';
match = '\b([[:alnum:]._]+)\b';
},
{ name = 'meta.comment.roxygen';
contentName = 'source.r.embedded.roxygen';
begin = "#'";
end = '$';
beginCaptures = { 1 = { name = 'comment.block.documentation.roxygen'; }; };
endCaptures = { 1 = { name = 'comment.block.documentation.roxygen'; }; };
patterns = (
{ name = 'keyword.other.param.roxygen';
contentName = 'variable.other.param.roxygen';
begin = '\@param\s';
end = '\b\s';
},
{ name = 'keyword.other.roxygen';
begin = '\@\b';
end = '[[:space:]]';
},
{ name = 'comment.line.number-sign.r';
match = '(#).*$';
captures = { 1 = { name = 'punctuation.definition.comment.r'; }; };
},
{ include = 'text.tex.latex.rd'; },
);
},
);
}
@cameronbracken
Copy link
Author

This is just a quick hack, it doesn't yet work as well as I would like but it is better than nothing.

Must have the R bundle installed. Easiest way to install is to open the bundle editor ("Bundles" > "Bundle Editor" > "Show Bundle Editor") and copy this file over the R syntax file from the R bundle. Then "Reload Bundles" or restart TextMate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment