SublimePerlTidy icon indicating copy to clipboard operation
SublimePerlTidy copied to clipboard

Recursively search for .perltidyrc file instead of having to specify locations for it

Open devosnw opened this issue 9 years ago • 5 comments

It would be great to have the option for the plugin to find the .perltidyrc file by simply recursively searching each parent directory for the file until it finds one. It should start in the same directory as the file that the command is initiated from and then move up the tree until a file is found.

For example, for a directory structure like this:

project/
|--.perltidyrc
|--folder/
|  |--subfolder/
|     |--file1.pl
|--file2.pl

When executing the plugin from file1.pl, the plugin would search in project/folder/subfolder/ and project/folder/ before finally finding the .perltidyrc file in the project/ folder and using that. Similarly, if executing for file2.pl, the plugin would start its search in the project/ folder and find it there immediately.

The plugin could also have a default search location in case the .perltidyrc file wasn't found anywhere in the parent directories. It could default to searching in paths like ~/.perltidyrc, etc.

I don't know a lot about how Sublime's plugin API works but it seems like you could get the current file's path from self.view and then simply do a search by calling dirname() on that path until you get to /.

devosnw avatar May 22 '15 17:05 devosnw

Hi devosnw,

this seems useful - may I ask what your motivation/use case exactly is?

Cheers vifo

vifo avatar Sep 06 '15 14:09 vifo

Main reason is because every perl project I work on in Sublime I also have to remember to add the location of that project's .perltidyrc file to the config file. If the plugin could just traverse up to the root of the project (where I keep almost all of the .perltidyrc files) it would automatically know to apply those rules without any additional configuration.

Secondarily, sometimes I work on random one-time-use perl scripts and it would still be nice to format them governed by a .perltidyrc file located in my home folder. That way I could always have sensible defaults to work with on any script that I work on.

devosnw avatar Sep 06 '15 20:09 devosnw

Hi devosnw,

thanks for your feedback and explanation. I'll look into how to implement this in an upcoming release.

BTW: Are you using Sublime Text's projects? Having a project (not a workspace) opened in ST will let PerlTidy look for a .perltidyrc in the project root directory also. This can be a substitute for what you're trying to achieve with the recursive search. The only downside is, that you'll have to actively create/open the ST project.

Cheers vifo

vifo avatar Sep 06 '15 21:09 vifo

@vifo thanks for looking into this. Also thanks for the pro tip, I didn't know Sublime would enable this feature when using a project. I generally just open multiple folders in my day-to-day workflow.

devosnw avatar Sep 08 '15 04:09 devosnw

This would be hugely helpful for me too

pjlsergeant avatar Sep 11 '20 02:09 pjlsergeant