Doom Emacs ~ Is there a package to space out text to make things easier to read?

I am looking for a Doom Emacs extension that will format text and nicely space it out.

For example:

let hello = 10
let world123 = 20

I wish for the extension to do something like this:

let hello    = 10
let world123 = 20

Another example is with the match statement(s).

match x
{
    10 => println!("the value is at 10"),
    10000 => println!("the value is at 10000"),
}

The extension does something like this:

match x
{
    10    => println!("the value is at 10"),
    10000 => println!("the value is at 10000"),
}

Things are just more lined up nicely. Would anyone know such extensions?

This is not really the right place to ask questions about Doom Emacs. I don't see anything in the rustfmt config options, though.

I generally agree, although I think most of us would find the question fine if the phrasing had simply said "Emacs".

This can solved generically by using M-x align-regexp, which is a language-agnostic feature built into Emacs, and it does not have a default keybinding in Doom. Your target string is the separator, so = or => in your specific examples. It also accepts the universal argument (C-u in Emacs and SPC u in Doom) to provide significantly more power/complexity.

As Cole pointed out indirectly, you will wind up sacrificing your ability to use rustfmt at all as it would undo this kind of formatting, so I know I personally would have a hard time making the choice in favor of this alignment style. There are two settings for structs and enums specifically, but not for general purpose alignment or match arms.

2 Likes

Can I configure rustfmt to space out text the way I want it to?

No, as you can see from the list of config options rustfmt does not support this kind of spacing, and will remove it if you add it manually.

What does rustfmt do exactly by the way, I am actually new to Doom Emacs so I am not too sure mate?

rustfmt is unrelated to Doom or Emacs. It's a tool that formats Rust source code to make it look nice -- determining where to break lines, positioning opening braces {, sorting imports, that sort of thing. Here's the official repository with more information:

You can configure Emacs to run rustfmt automatically, among other language integrations:

1 Like

On top of what Cole mentioned: part of the appeal of rustfmt and similar tools is that it allows a team to agree to certain stylistic choices, and then automate applying them to the code. It produces more consistently-formatted codebases and diminishes or eliminates the need for an entire class of peer feedback, leaving more time and attention for meaningful critique of business logic, algorithms, etc.

1 Like