question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: better auto indent

See original GitHub issue

Would be really great if the autoIndent worked better, preferably according to standard style guides. (see https://google.github.io/styleguide/Rguide.xml and http://adv-r.had.co.nz/Style.html)

When a line ends with an open bracket of some sort ((, [, {) indentation kicks in according to whatever setting you have. This example already works as it should:

a <- b[
  c >= 3 &
  d == 2
]

However when a bracket is open, but there is something after it on the same line, indentation should be all the way to the opening bracket, not just the default number of spaces. For example:

bad way:

a <- b[c >= 3 &
  d == 2]

correct:

a <- b[c >= 3 &
       d == 2]

That is, when pressing enter after the & sign, indent should be 7 spaces instead of 2. Right now, when one presses enter after the & sign, no indent is applied at all.

Maybe one could implement the styler package to do it automatically (http://styler.r-lib.org) using the formatOnSave option in VsCode.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Fred-Wucommented, Sep 8, 2021

Just found an extension called “Indent To Bracket” that would do indent to open bracket.

3reactions
andycraigcommented, Oct 24, 2019

The version of the language server on GitHub supports customised styler formatting: https://github.com/REditorSupport/languageserver/blob/master/README.md#customizing-formatting-style

I think customised indenting should be supported via the styler package rather than directly in vscode-R, so I’m going to close this. All the indenting formats described in this issue look good to me, so if they’re not already implemented in styler please consider adding them there!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: better auto indent · Issue #62
Would be really great if the autoIndent worked better, preferably according to standard style guides.
Read more >
Improve auto-indent for folded lines - Feature requests
Currently, pressing Enter at the end of an indented line creates a new line at the same indentation level as the line just...
Read more >
Feature Request: Pretty format keyboard shortcut
My Observable team has auto-pretty formatting off by default, as there are some cases where we find the default pretty format has made...
Read more >
Introduce auto indent detection - Merge requests
Auto indent detection does what it says i.e., detects the indentation in a file. The code is directly ported from VSCode where this...
Read more >
Feature request re: Stan support in RStudio 1.2
Auto -indent for Stan files doesn't work the same way it does for R scripts. Expressions following for and if statements are only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found