fmt icon indicating copy to clipboard operation
fmt copied to clipboard

Quickscript

Open Metaxal opened this issue 2 years ago • 8 comments

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.

Metaxal avatar Jun 29 '22 08:06 Metaxal

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

sorawee avatar Jun 29 '22 12:06 sorawee

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.

Metaxal avatar Jun 29 '22 12:06 Metaxal

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.

sorawee avatar Jun 29 '22 12:06 sorawee

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

Metaxal avatar Jun 29 '22 13:06 Metaxal

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.

sorawee avatar Jun 29 '22 14:06 sorawee

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?

Metaxal avatar Jun 29 '22 15:06 Metaxal