cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
864 stars 84 forks source link

Option for local `indentconfig.yaml` or `paths:` in `latexindent.yaml` #516

Closed torik42 closed 3 months ago

torik42 commented 6 months ago

I would like to have an option to specify local indentconfig.yaml files, or even better, include the paths: functionality in all the yaml configuration files.

Please correct me, if this is already possible. I couldn’t find anything in the documentation and couldn’t make it work. I tried to use

# latexindent.yaml
paths:
- /absolute/path/to/config.yaml

in the local directory and call latexindent with -l switch. The indent.log shows

INFO:  YAML settings read: -l switch
       Multiple localSettings found, separated by commas:
       localSettings.yaml, latexindent.yaml, .localSettings.yaml, .latexindent.yaml
       Adding latexindent.yaml to YAML read paths
INFO:  YAML settings, reading from the following files:
       Reading USER settings from latexindent.yaml
       ---
       paths:
         - /absolute/path/to/config.yaml

INFO:  Backup procedure (-w flag active):

So the /absolute/path/to/config.yaml was never read.

The idea is to have several configuration files with different replacements/configurations (the focus is on replacements, I think) and then choose the correct one according to the project. If the paths: entry would be parsed for every configuration file, one could even nest configuration files. This would be useful to allow for fine-grained selection and still providing a preselection in a single file which just loads multiple paths.

cmhughes commented 6 months ago

Many thanks, this sounds reasonable and, I hope, fairly straight forward to implement.

cmhughes commented 6 months ago

For my reference, it'll be this loop that needs updating

https://github.com/cmhughes/latexindent.pl/blob/90523104cfa824d7642acae9d6f47664373d8694/LatexIndent/GetYamlSettings.pm#L373

Note that it'll need to be documented that paths can not be specified using the y switch.

torik42 commented 4 months ago

If anyone else is interested, as a workaround, I currently use

export LATEXINDENT_CONFIG=$(pwd)/indentconfig.yaml

to load a specific subset of additional rules with

# indentconfig.yaml
paths:
- path/to/default.yaml
- path/to/other-config-1.yaml
- path/to/other-config-2.yaml

It’s still not possible to nest them, but one can have multiple lists for different purposes.

cmhughes commented 3 months ago

This is implemented as of https://github.com/cmhughes/latexindent.pl/commit/1a629f2c9972bff270f459dee5104f188f0b6c61

It'll be part of the next release. Please leave this issue open until I've made the release, hopefully coming soon...

cmhughes commented 3 months ago

implemented and released at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.24

cmhughes commented 3 months ago

https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#paths-demonstration