Is there anyway to ensure a common indent for inte...
# announcements
s
Is there anyway to ensure a common indent for interpolated multi-line strings? Here’s an example:
Copy code
val inner = """
    - List Entry 1
    - List Entry 2
""".trimIndent()

val outer = """
Outer:
    $inner
""".trimIndent()

fun main() {
    println(outer)
}
What I get:
Copy code
Outer:
    - List Entry 1
- List Entry 2
What I want (expect):
Copy code
Outer:
    - List Entry 1
    - List Entry 2
c
You could add pipes to mark the start of indent in the first string, and then call
.trimMargin()
instead of
.trimIndent()
on the second, trimming to the pipes from the first https://pl.kotl.in/AIX3d_2C5
s
rough way of doing it perhaps
Copy code
val inner = """
    - List Entry 1
    - List Entry 2
""".trimIndent()

val outer = """
    |Outer:
    |${inner.prependIndent("    ")}
""".trimMargin()
s
Right maybe I should reword the question--is there anyway to make the interpolation apply the local indentation of where the interpolation occurs to each interpolated line. If you’ve ever used Xtend, that’s how its template expressions work. The issue with the first solution is that it requires each interpolated string to be correctly indented for any place it occurs.
c
There is a difference with that, where XTend is a template, and it does processing in combining values into template expressions. In Kotlin multiline strings, interpolation is literally just concatenating plain Strings together, there’s no template-like logic that could be done under-the-hood with them
1
s
Ah, that’s unfortunate. I thought maybe during bytecode generation there was some mechanism for doing that.