Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickscript #34

Open
Metaxal opened this issue Jun 29, 2022 · 8 comments
Open

Quickscript #34

Metaxal opened this issue Jun 29, 2022 · 8 comments
Assignees

Comments

@Metaxal
Copy link

Metaxal commented Jun 29, 2022

Here's a slightly improved quickscript:
https://gist.github.com/Metaxal/f45ea1a893a1bdedaadbeafd11144e3d

It formats either the selection, or the whole program if the selection is empty.

It should probably call DrRacket's indenter afterwards, but I couldn't find the API for it, which means I would need to dig the keybinding function string name, get the keymap, etc.

@sorawee
Copy link
Owner

sorawee commented Jun 29, 2022

I don't think it should call the Racket indenter, so the current state is exactly what I want. Thanks again!

@sorawee sorawee self-assigned this Jun 29, 2022
@Metaxal
Copy link
Author

Metaxal commented Jun 29, 2022

Note though that DrRacket has rules in Edit|Preferences|Editing|Indenting that are not taken into account by fmt, such as the extra regexps in particular. For example, if you fmt the quickscript linked above, it will move a lot of stuff way to the right, while DrRacket flushes it left due to the define-.* rule.

@sorawee
Copy link
Owner

sorawee commented Jun 29, 2022

I think the better fix is to make all def.* handled like define in fmt.

What I don't want to happen is DrRacket undoes correct indentation by fmt.

@Metaxal
Copy link
Author

Metaxal commented Jun 29, 2022

How about program-format accepting DrRacket-like rules and then in the quickscript obtaining DrRacket rules and passing them to program-format?

@sorawee
Copy link
Owner

sorawee commented Jun 29, 2022

The problem is that DrRacket rules provide a lot less information. Take define/contract as an example. I personally want it to be formatted like this:

(define/contract (f x) (-> integer? integer?)
  (+ x 1))

The indentation rule in DrRacket only says that whatever comes after the first line of define/contract should be indented like a body, but it doesn't say how to place (-> integer? integer?).

Both:

(define/contract (f x) (-> integer? integer?)
  (+ x 1))

and

(define/contract (f x) 
  (-> integer? integer?)
  (+ x 1))

are admissible formats consistent with the indentation rule in DrRacket. But fmt needs to know exactly which one you want.

@Metaxal
Copy link
Author

Metaxal commented Jun 29, 2022

Well, that's because it's an indenter, not a formatter as you well know. That doesn't mean that DrRacket's indentation rules should be entirely disregarded.

At least, is it possible to add the default indentation rules of DrRacket, even if we don't build a bridge between the two?

@jessealama
Copy link

jessealama commented Jun 5, 2023

Any traction on this? I use define/contract a lot, in this form:

(define/contract (foo bar)
  (-> integer? integer?)
  bar)

and am just now discovering that fmt turns this into

(define/contract (foo bar)
                 (-> integer? integer?)
                 bar)

@sorawee
Copy link
Owner

sorawee commented Jun 5, 2023

I added a basic support for define/contract in fa8fd5c. The full support will require more work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants