Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check adjacent-files like vim-sleuth #43

Open
deviantfero opened this issue Jul 25, 2018 · 2 comments
Open

check adjacent-files like vim-sleuth #43

deviantfero opened this issue Jul 25, 2018 · 2 comments

Comments

@deviantfero
Copy link

deviantfero commented Jul 25, 2018

More often than not I find myself creating a new file, it would be useful that dtrt adjusts indentation settings based on a few files of the same type adjacent to it, or maybe in the parent directories, would this be possible with the existing code-base? if so, how?

thanks for such a nice plugin, btw

@rrthomas
Copy link
Collaborator

I think this would need some more work, but it's mainly a matter of selecting suitable files and then feeding them to dtrt to get the settings, then applying them to the new buffer; I don't know vim-sleuth, but presumably its algorithm could be copied.

As far as the code goes, the guts of dtrt-indent-try-set-offset would need to be extracted into a function that, given a buffer, returns the results of analyzing it. I'm also not sure whether it's easily possible to merge the results of analyzing two buffers.

So realistically this would require some work, but it'd be great to have!

An alternative solution is to write out the current settings to a .dir-locals.el file, or some other per-project mechanism. This might be better in that it would have more predictable results.

@deviantfero
Copy link
Author

deviantfero commented Jul 25, 2018

It would definitely be appreciated, the problem with per project mechanisms is that one usually manages many file-types in one project and one might have different indentation settings for them, sure you could specify them, but then dtrt wouldn't make much sense then, since it wouldn't need to actually analyze anything.

but it's rare when two files of the same file-type have different indentation, so that's why I suggested that, I guess it wouldn't have to scan all the buffers available, I imagine something like this:

.
..
new.js
old.js
older.js

If this is my folder layout, dtrt would first try with old.js, then if no information is found (empty lines, no indentation found etc.) it would go on to scan older.js, and if still no information is found, it would go one level up and search for .js files, you would be able to adjust this behavior by setting two flags max-depth and scan-other-files for turning this behavior on/off

Thanks for your thoughtful response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants