Code auto-format on Repl.it for C++, Go, ...

Code auto-format on Repl.it for C++, Go, ...

Written by Serhii Ostapchuk on Mar 9th, 2021 Views Report Post

Reposted from Original LiFl devblog

Repl.it is a very basic Cloud IDE / Code snippets service that has one significant advantage over other similar services - it's number languages supported. For frontend developers, it might be not as sophisticated/simple/performant. However, when I`m thinking about where to try out some new language - it comes to my mind first.

One of the issues with repl.it is their broken auto-format feature that works for Python, JS but doesn't work for some other languages. Luckily, we have a method to fix this up until the company does something about it.

While all your program output goes into Console tab (you are able to run commands in it though), you still have access to a separate tab Shell 1.png

So we can use it to set up our code formatter.

  1. We need to watch file changes
  2. We need to launch custom command when it happens That`s it!

For step 1 you can use whatever method/tool you want. When using free accounts better if that tool is simple and installs fast, as you`ll need to reinstall it on launch.

For example, you can use when-changed python package just by typing:

pip install when-changed

And then setting up your formatted commands like: For Go

when-changed . gofmt -w .

For C++

when-changed . clang-format -i *.*

With paid accounts and always on repls and higher CPU this should work even better.

Comments (0)