How to add indent after round bracket+newline when typing and reformatting?

Hey there,

it's been a while since I've worked on a formatter for R. See   In general, it's doing its job, except for one feature, which is to add an indent after a round bracket followed by a line break:

foo = function(){


In the example, all the "bla"s should be indented. What would be the correct function in to implement such a formatting logic?


2. Not sure if the same API after under the hood, but I'd also mimic the feature of other language integrations (kotlin, java) to indent on pressing enter after an opening round bracket.  paste(<enter> <-- should break line and indent. Is the done by the formatter as well, or this is a different API?

Thanks & best regards,


1 comment
Comment actions Permalink

I think (!) the code you should have a close look at is in


Specifically, pay attention to the end of this method which seems to handle this

if (settings.SMART_INDENT_ON_ENTER || forceIndent) {
caretOffset += 1;
caretOffset = CharArrayUtil.shiftForward(editor.getDocument().getCharsSequence(), caretOffset, " \t");
if (DocumentUtil.isAtLineEnd(caretOffset, document)) caretOffset = editor.getCaretModel().getOffset();
else {
caretOffset = editor.getCaretModel().getOffset();

final DoEnterAction action = new DoEnterAction(
file, editor, document, dataContext, caretOffset, !insertSpace, caretAdvanceRef.get(), project
for (EnterHandlerDelegate delegate : EnterHandlerDelegate.EP_NAME.getExtensionList()) {
if (delegate.postProcessEnter(file, editor, dataContext) == EnterHandlerDelegate.Result.Stop) {

if (settings.SMART_INDENT_ON_ENTER && action.isIndentAdjustmentNeeded()) {
FormatterBasedIndentAdjuster.scheduleIndentAdjustment(project, document, editor.getCaretModel().getOffset());

Please sign in to leave a comment.