Modifying Rustfmt

I often use multiple empty lines to separate different sections within the code I’m writing. It helps me manage a learning disability (LD). I use Sublime Text with the rstfmt package installed. When I save, it removes those extra lines. If I didn't have to deal with this LD, I'm sure removing those lines would be a good thing, but right now I really need to find a way to configure rstfmt to leave those lines where I put them. I looked through the rstfmt settings and didn't see anything that would address the problem. Can anyone shed some light on this problem?

What you're looking for is the blank_lines_upper_bound setting. Unfortunately, it is unstable and so you will have to use rustfmt from a nightly toolchain to get this feature.

1 Like

Would empty line comments (//) be a reasonable workaround? As a bonus, they also allow you to give titles to the different sections and write notes about them if needed.

Thanks for your reply. I followed the link for the blank_lines_upper_bound setting. I then created a rustfmt folder in my global .config folder and then created a rustfmt.toml file in that folder. Here's what that file looks like:

unstable_features = true
blank_lines_upper_bound = 7

I then closed and restarted Sublime Text. (My assumption is that by restarting Sublime, it will also restart rustfmt.) No luck, no change in the behavior we're talking about. I then tried copying the rustfmt.toml file directly into my project folder, saving it in the same folder where my cargo.toml resides. Still no joy. Obviously I'm not doing something right. Any suggestions?

(My assumption is that by restarting Sublime, it will also restart rustfmt .)

rustfmt is not a server — it is run anew every time you format a file.

Obviously I'm not doing something right. Any suggestions?

As I mentioned, you need to install and activate a nightly toolchain. Have you done that?

You may need to look into exactly how “Sublime Text with the rstfmt package” invokes rustfmt. For example, if it were using a bundled copy of rustfmt then changing the toolchain wouldn't help.

To troubleshoot further, I would suggest using rustfmt or cargo fmt directly, without an editor integration involved, and seeing whether the formatting works as you want in that case. This way you will also be able to see if there are any error messages.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.