JetBrains / JetBrains/MPS-extensions

How to control plaintextgenerated indent?

Open
#307 7 comments 0 reactions 1 assignee Claimed by @eugenschindler View on GitHub
comp.plaintextgen
Dominant language
JetBrains MPS
Stars
88
Forks
60
Avg merge
1d 3h
Merged PRs (30d)
15

Description

# Scenario

```
Given I am generating an XML file
Which has an embedded python dialect (which is indentation-sensitive)
And I use the mps.core.xml language for xml
And I use the plaintextgen for describing the generated python
When I run it
Then surprisingly, I see the python code indented relative to the xml nesting
But I'd expect instead: to be able to teach the `TextgenText` to restart the indentation level from `0` (maybe even by default)
```

# How can I work around this?

Plaintextgen indentation comes from the mps textgen `indent buffer;` ([source](http://127.0.0.1:63320/node?ref=r%3A4752c29d-6163-4693-b1d7-3c8befc060cd%28com.dslfoundry.plaintextgen.textGen%29%2F5407518469085614939)). It relies on the [MPS TextArea](https://github.com/JetBrains/MPS/blob/master/core/textgen/source/jetbrains/mps/text/impl/TextAreaImpl.java#L30), which does not publish absolute manipulation of the indentation depth. So to fix this we'd need to work on private fields of `TextAreaImpl`. That's nasty. How can I get outta here?

Here are some screenshots of my example. To respect my NDA, I had to censor it. Sorry for that.

## The xml:

![98415f51-2f5d-4821-8d37-2cfa50efc2a5](https://user-images.githubusercontent.com/569215/87427843-ae408980-c5e1-11ea-9921-458a84e6564b.png)

## And this python:
![97fa9327-ad66-4fd9-b775-17bbf1514dca](https://user-images.githubusercontent.com/569215/87427958-e0ea8200-c5e1-11ea-97c5-2a6661f382a6.png)

## Generate into
Note that the xml indentation of `` is correct. Just the indentation of the CDATA and each other python line is wrong (marked with the pink arrows):
![cbcdb34a-c328-4890-997e-59db9394a229](https://user-images.githubusercontent.com/569215/87428271-64a46e80-c5e2-11ea-98d4-56f04e04eeef.png)

By the way: I'd be glad to support in fixing it once we have a useful plan…Until then, I'll move my python code into a stringbuilder and fill the xml CDATA with a property macro.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.