WGUNDERWOOD / tex-fmt

An extremely fast LaTeX formatter written in Rust
MIT License
195 stars 14 forks source link

[feat] Add support for a configuration file #39

Open VJMReichenbach opened 4 hours ago

VJMReichenbach commented 4 hours ago

I personally don't want my lines to wrapped and always adding --keep is a bit annoying (and I often forget it). It would be nice, if there was a configuration file for both system wide config (e.g. ~/.config/.tex-fmt.toml and/or ~/.tex-fmt.toml) and a project specific config (e.g. ~/my_folder/.tex-fmt.toml) where you configure the formatter instead of using cli flags. It would also make it possible for two people to use tex-fmt on the same project with the same settings, while using different editors, without any editor configuration.

For reference, I like the way StyLua does it.

WGUNDERWOOD commented 3 hours ago

Thanks for this suggestion! I would be interested in the possibility of adding support for a configuration file. However there are some issues/concerns to be addressed first.

VJMReichenbach commented 2 hours ago

My aim for tex-fmt is that configuration should remain relatively limited, for simplicity of use, consistency of output, and maintainability.

I really like your default configuration. I just don't want tex-fmt to wrap lines, so that is the only change I personally would make. The only thing I would use the config file for is setting options I can already change with cli flags. I guess that would even improve consistency of the output since you don't have to share your specific command you used to format. Instead you can only share the repository's config file.

Configuration files increase the complexity of distributing the software, as they would need to work on multiple operating systems.

Valid point. I still think at least local config files should be supported, since you only have to check the current directory. (I've never written rust code on e.g. Windows, so if there is a fundamental difference between using a relative path on Windows and e.g. Linux I understand your concern.)

I've never used it, but confy is a crate that handles all the operating system stuff for you. I just ran the example and it seems fairly easy to implement a global config that way. figment and config-rs also seem pretty nice, but more complicated. Figment appearantly is pretty easy to combine with clap.

Relying on configuration files can make the tool less portable, e.g. if you are working on another machine and don't have access to the config file.

If you can share your code, shouldn't you be able to share your config? I would just put an .tex-fmt.toml file in the root of my repo. That way, everybody who has access to the code, also has access to the config.

VJMReichenbach commented 2 hours ago

Maybe using directories to handle operating system specific paths in combination with figment for handling global and local configs is an option?

WGUNDERWOOD commented 55 minutes ago

Thanks for these thoughts, and for supplying some useful links! I agree with you that the config file should only contain arguments already available on the CLI. I'll take a closer look at the config file crates to decide which looks best.