Dhall Format and long lines?

I’m currently writing a Dhall wrapper over KMonad configuration files, which is their own Lisp-ish format to configure itself.

KMonad, being a keyboard configuration app, uses what they call “blueprints” which essentially is a “picture” of your keyboard, but in plain text.

As an example, here’s the blueprint of my keyboard ( Kinesis Advantage 2):

(defsrc
  esc   f1   f2   f3   f4   f5   f6   f7   f8   f9   f10  f11   f12    prnt   slck  pause
  =     1    2    3    4    5    6    7    8    9    0    -
  tab   q    w    e    r    t    y    u    i    o    p    \
  caps  a    s    d    f    g    h    j    k    l    ;    '
  lsft  z    x    c    v    b    n    m    ,    .    /    rsft
        `    \    left rght           up   down
                  lmet home           end  del
             bspc lctl lctl           pgup ret  spc
                       lalt           pgdn
  )

So my first move in order to convert this to Dhall was to use Lists of Lists to specify the blueprint. But the issue is that Dhall Format will automatically convert

defsrc
  [ [esc, f1, f2, f3, ...]
  , [eq, n1, n2, n3, ...]
  ]

into

defsrc
  [ [esc
    , f1
    , f2
    , f3
    , ...
    ]
  , [eq
    , n1
    , n2
    , n3
    , ...
    ]
  ]

Which already defies the point of the blueprint, and makes it very confusing.

Perhaps there’s a way to make a workaround for this issue that I’m not seeing? Use records, define some functions in some kind of way?

I don’t know, any ideas on how to approach this?

Ideally, I would like to avoid telling users to “just disable Dhall Format” because it would be a huge disadvantage from my point of view.

Thanks

Hi Nick!

The current pretty-printer in dhall doesn’t try to preserve very much of the input formatting. It basically tries to fit things into 80 columns and if that doesn’t work, uses an alternative, multi-line layout.

I assume that the lists in your case don’t fit into 80 columns and are therefore laid out with one element per line.

The easiest thing to change would be to make the 80-column limit configurable. Maybe these blueprints would look better with, say, a 120-column limit. The prettyprinter library we use also has an Unbounded setting. You could combine this setting with line comments (--) to force a linebreak where desired.

To get the best results and ergonomics, you’d probably want a “Vonderhaar-syle” prettyprinter. There’s an existing feature request and discussion in https://github.com/dhall-lang/dhall-haskell/issues/1496.

Another solution I can think of is to provide some sort of annotation that can let the user disable the formatting logic for a sub-expression. I believe Rust provides something like this