Giter Club home page Giter Club logo

Comments (7)

andorsk avatar andorsk commented on June 3, 2024

yes! good callout. thanks @alixander

from d2-mode.

andorsk avatar andorsk commented on June 3, 2024

@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 :

  1. format-buffer
  2. format-region
  3. format-file
  4. format-all-d2-regions ;; goes through all d2 codeblocks and formats them.

from d2-mode.

avelino avatar avelino commented on June 3, 2024

Example:

from d2-mode.

andorsk avatar andorsk commented on June 3, 2024

@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:

  1. Implement format support with caveat that region's won't be supported for now.
  2. Region formatting will be a roadmap item. I'm guessing it will be must more involved, as we'll have to write something to scan the file and format appropriately. Not sure what the right solution is there.

Are @avelino and @alixander ok with excluding region support?

from d2-mode.

alixander avatar alixander commented on June 3, 2024

Is regions like a markdown block? I do mostly edit just the d2 files standalone.

from d2-mode.

andorsk avatar andorsk commented on June 3, 2024

@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.

from d2-mode.

andorsk avatar andorsk commented on June 3, 2024

Started work on a PR here: #37

from d2-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.