Sublime Forum

Parentheses wrapping has (apparently) hard-coded indentation

#1

Using the Scala mode:

  val x = if (foo)
    42
  else
    24

If I wrap the if expression in its entirety in parentheses by selecting the block and pressing (, Sublime forces the result to be the following:

  val x = (if (foo)
      42
    else
      24)

Note that this does not happen if the base indentation is 0:

val x = if (foo)
  42
else
  24

// wraps to

val x = (if (foo)
  42
else
  24)

And similarly, if I increase the indentation level, the effect is magnified:

                val x = if (foo)
                  42
                else
                  24

// wraps to

                val x = (if (foo)
                                  42
                                else
                                  24)

There is nothing in the Scala mode which is generating these semantics. I know because I rewrote all of the Scala indentation rules a few months ago, specifically intending to fix this issue. I couldn’t.

The semantic appears to be something in Sublime itself. Is this a bug? If not, is it configurable?

0 Likes

Multi-Line Snippets Often Indented
Auto indentation not working correctly for an else block in python written using a snippet
#2

It happens in Plain Text mode too, even with auto_indent, smart_indent and indent_to_bracket off, so looks like something to do with the insert_snippet command… I don’t believe it is configurable

0 Likes

#3

Oh it never occurred to me that this was handled with insert_snippet. That makes sense then. What’s probably happening is the contents of the selection (which includes all whitespace, including current indentation) is being inserted after the ( character, but that insertion is itself subject to the current indentation level. This causes current indentation to be doubled in the selection.

Though that doesn’t explain why it happens with auto_indent disabled…

0 Likes