brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 110 forks source link

Bad interaction between triple quote and indenter #1383

Closed sorawee closed 6 years ago

sorawee commented 6 years ago

Say I write

a = ```|

(where | indicates the cursor)

After I hit the enter key, I get

a = ```
    |

After I add more text and hit the enter key, I get

a = ```
    abc

    |

which suggests to users that Pyret wants them to write like this:

a = ```
    abc

    def
    ```

But this evaluates to

"abc\n\n    def"

which is not what users would want.

Even when a block of text is copied over from external sources, the indenter still formats it:

Text:

abc

def

Code:

a = ```
abc

def
```

After indenting all lines

a = ```
    abc

    def
    ```

Note that

a =
```
abc

doesn't help either because this formats to:

a = 
  ```
  abc

I think there are two ways to fix this:

  1. Disable the indenter inside triple quotes
  2. Make the triple quote aware of indentation, just like Python and Racket's @-syntax.
blerner commented 6 years ago

Ugh. We've discussed this at length. The consensus was, there simply is no good answer here. "Do what Python does to fix excess whitespace" was the best idea, but even that algorithm is sufficiently complicated that it's hard to predict what it does. You were the one who told us that that approach was a bad idea -- https://github.com/brownplt/pyret-lang/issues/639#issuecomment-181497359 ;-)

Since the primary use of TQS was doc: strings, and we don't do anything semantic with them right now anyway, this isn't a big problem. I'm closing this as a dupe, and "just another piece of the pain that is TQS." :-(