Open alixander opened 1 year ago
yes! good callout. thanks @alixander
@alixander this is actually tricker than it looks.
For .d2
files, it's pretty clear what to do, but there are also d2 regions in emacs mode, which it's less clear. I think we would want to autoformat all the d2 regions as well on save.
I think a few functions are probably required to support this :
Example:
@avelino yep. I'm aware of hooks you can configure on save with a hook. I think again, the tricky part here is region support. If that's not important for most people, I'm happy to implement a quick format command on the d2-mode. Personally, I tend to use d2 mostly in regions, which is why I've held back on implementing the simple solution.
Proposal here:
Are @avelino and @alixander ok with excluding region support?
Is regions like a markdown block? I do mostly edit just the d2 files standalone.
@alixander exactly. Regions are blocks.
As an example:
This is a graph
```d2 A --> B ``` Commentary here.
Another graph:
```d2 A --> B ```
Commentary here.
I mostly do graphs in regions, so for me ( personally ) unless there's region support it becomes a lot less useful. I didn't know people use standalone files frequently. Might make sense to support this for standalone files.
I'll see about getting a PR started this weekend.
Started work on a PR here: https://github.com/andorsk/d2-mode/pull/37
Latest D2 version exposes a command for autoformatting D2 scripts. Intended to be used like Go's, i.e. format on save
https://github.com/terrastruct/d2/pull/292