racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
453 stars 93 forks source link

@-Expressions should indent like regular S-expressions. #38

Closed LeifAndersen closed 8 years ago

LeifAndersen commented 8 years ago

At the moment, the indentation for @-Expressions in Racket is very unusual, and I would expect them to automatically indent similar to S-Expressions.

For example, if I have text on the same line, I would expect it to automatically indent like this:

@emph{Here is
      some text}

Or, if I don't put text on the first line, it should probably indent by some fixed number of spaces, such as:

@emph{
  Here is
  some text}

(For reference, it currently seems to put it at the end of the { like so:

@emph{
      Here is
      some text}

Which has the negative side effect of making the code go significantly more to the right than it needs to, and doesn't match how regular S-expressions indent, which is:

(emph
  "Here is"
  "some text")

)

I'm a little less clear on what a good idea is if the argument uses arguments in [] brackets, but I would expect the {} parts to follow the same rule. So I could do something like this:

@myfunc[#:arg1 val1
        #:arg2 val2]{
  Here is
  Some text}

How hard would it be to make DrRacket do this?

rfindler commented 8 years ago

DrRacket already has support for indenting @-exp languages, although it could be buggy. The rules we came up with when we built it was a kind of C-like thing, where you get N space of indentation on a line that is in text mode (i.e. inside {}), where N is the number of open {s you are inside. If you are in "racket" mode (i.e., inside []) then you should get normal Racket-style indentation. You can tell what mode you are in by the coloring that DrRacket does.

For your examples, this is the behavior I see in my DrRacket, which seems consistent with the intended rules. I do not see what you see for the third example.

#lang scribble/base

@emph{
 Here is
 some text}
#lang scribble/base

@emph{Here is
 some text}
#lang scribble/base

@myfunc[#:arg1 val1
        #:arg2 val2]{
 Here is
 Some text}
LeifAndersen commented 8 years ago

Odd. When I automatically indent the following file, I get this:

#lang scribble/lncs

@emph{
      foo
      bar}
LeifAndersen commented 8 years ago

AH!!! okay, when I switch the lang from scribble/lncs to scribble/base it works, odd that the #lang makes that much of a difference.

rfindler commented 8 years ago

The indentation strategy is based on the #lang line. Probably scribble/lncs needs to declare it uses the @ indenter, not the regular racket one.

Maybe open an issue there (or move this one?)

LeifAndersen commented 8 years ago

Ah, I see.

Well in that case there's a lot of languages that are missing, such as:

scribble/html at-exp etc.

Can you tell me where a #lang declares what indentation it is supposed to use?

Thanks.

rfindler commented 8 years ago

I guess these are the docs you want? http://docs.racket-lang.org/tools/adding-languages.html?q=indent#%28part.__lang-based_.Languages_in_.Dr.Racket%29

Thanks for looking into this!

LeifAndersen commented 8 years ago

Ah, yes, that does look like what I want. Thank you.

As a side note, it's kind of sad that the indentation can only be set in with the #lang line, and not with other things such as #reader. But oh well. That's a different issue entirely.

Thanks again.

LeifAndersen commented 8 years ago

Okay, I'm re-opening this issue because I've found another issue. It turns out that it DOES indent correctly, but only after you hit tab when there's already text there.

For example:

Type:

@list{

hit enter, and start typing, and the text should appear on the next line after the {. So you get something like this:

@list{
      foo}

Now if you hit tab on that new line, it will indent to the right place, but only because there is now text on it.

rfindler commented 8 years ago

Yeah, I've noticed that too. If would be great to get that fixed.

But this is still the wrong repo.

Here's the code: https://github.com/racket/gui/blob/master/gui-lib/scribble/private/indentation.rkt

LeifAndersen commented 8 years ago

Ah, fair point. I'll move this issue to that repo.

Thanks.

rfindler commented 8 years ago

Thanks!