dbuenzli / fmt

OCaml Format pretty-printer combinators
http://erratique.ch/software/fmt
ISC License
71 stars 26 forks source link

Add Fmt.{colon,dot,slash} #58

Closed thizanne closed 1 year ago

thizanne commented 1 year ago

I keep redefining colon myself, usually for a separator for printing out (key, value) maps. I think it's on a similar level of "commonly used punctuation" as comma and semi.

Then while I was at it I also added dot and slash. They may be less consensual but I felt like they made sense.

Note that my whitespace-cleanup hook cleaned a bit of stuff in CHANGES. I can remove that if deemed not desirable.

dbuenzli commented 1 year ago

I'm a bit cold feet about adding more like this.

There's quite a few contexts where these separators are used without a subsequent space (I'm not even sure I understand your use case for slash). For example these would do the wrong thing:

let pp_qualified_id = Fmt.(list ~sep:dot string)
let pp_lookup_path = Fmt.(list ~sep:colon string)
let pp_path = Fmt.(list ~sep:slash string)

Note that my whitespace-cleanup hook cleaned a bit of stuff in CHANGES. I can remove that if deemed not desirable.

No worries in this case but you should likely disable it on markdown files: two final spaces on a line is for hard line breaks.

thizanne commented 1 year ago

There's quite a few contexts where these separators are used without a subsequent space (I'm not even sure I understand your use case for slash).

Fair enough. FTR I don't have a usecase for slash right now, I just thought I might as well do a batch of separators but your point does stand, even for colon. I wish we could have names for these, maybe colon_sp and colon, but that would be awkward to add to the current API names, and I guess using any ":@ " isn't too much of a hassle either.

I agree with your point and won't argue any more. I'll let you close the PR if that's the decision.

Note that my whitespace-cleanup hook cleaned a bit of stuff in CHANGES. I can remove that if deemed not desirable.

No worries in this case but you should likely disable it on markdown files: two final spaces on a line is for hard line breaks.

Thanks, I keep forgetting about this :)

dbuenzli commented 1 year ago

I guess using any ":@ " isn't too much of a hassle either.

Or even a local let colon = Fmt.any ":@ ".

Let's keep it that way for now.

Thanks, I keep forgetting about this :)

The following is what I have in my .emacs but it's not entirely satisfactory, emacs is a notorious whitespace pooper, I'd like a smarter delete-trailing-whitespace in markdown mode.

(add-hook 'before-save-hook
          (lambda ()
            (cond
             ((eq major-mode 'markdown-mode)) ; some white may be significant
             (t (delete-trailing-whitespace)))))