Formatting to explicit columns

Hi all,

I have a couple of formatting cases that I'm finding difficult to resolve with the IntelliJ formatter.

The first is a formatting convention where comments at the end of the line are lined up at a specific column, or pushed back if required:

(some-line)       ; A comment
(another-line)    ; Another comment, aligned to the first

(a-longer-line :a :b :c) ; A pushed-back comment


There doesn't seem to be any good way to express this. I tried to use spacing, but the problem is that I don't know until after the formatting how wide the line will be - it really needs to be resolved during the constraint resolution process. In the end I solved this by using a PostFormatProcessor and aligning the comments myself, but it's not ideal.

I would also like to align let bindings, but only up to a maximum width, like this:

(let [a        10
      some-var 20
      a-really-long-variable-name 30

      {:keys [binding-var another yet-another]} values]
  ...)

Here, I'd like the values in the let binding to be aligned. However, when the user users destructuring or maybe just a very long variable name, I'd like to cap the amount that items will be pushed back to say, 20 characters. I could do this with a PostFormatProcessor too, but it would get very messy, especially in the presence of line comments as detailed above.

Are there any tricks I can use to achieve this sort of thing?

Thanks,
Colin

Please sign in to leave a comment.