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

Guess indentation for new files in a project #76

Open
vishesh opened this issue Sep 8, 2023 · 3 comments
Open

Guess indentation for new files in a project #76

vishesh opened this issue Sep 8, 2023 · 3 comments

Comments

@vishesh
Copy link
Contributor

vishesh commented Sep 8, 2023

Currently, if we create a new file, dtrt will fallback to global default for that language. However, we can potentially do better by looking if we are in project-mode or projectile-mode and then looking at other files in that project (or dtrt can just save the indent settings for projects whenever other files were opened). If we are not in a project, then we can fallback to global mode.

@rrthomas
Copy link
Collaborator

rrthomas commented Sep 9, 2023

Nice idea! Currently project defaults might be expressed in .dir-locals.el or .editorconfig; the effort involved particularly in the latter is so low I'm not sure there's much need for dtrt-indent to be cleverer. In particular, which file or files would it look at, and how long would that take?

@yudi-matsuzake
Copy link

In particular, which file or files would it look at, and how long would that take?

One reasonable approach could be to focus on the buffers opened within the project. When we have only one buffer open, the behavior should be the same of opening a random file outside a project.

For each project, we could keep the histogram, and whenever a new file is opened within the project, we update the histogram and the analysis.

@rrthomas
Copy link
Collaborator

One reasonable approach could be to focus on the buffers opened within the project. When we have only one buffer open, the behavior should be the same of opening a random file outside a project.

This sounds like it would make the operation of dtrt-indent at the project level non-deterministic, in the sense that its conclusion about the right settings for the project would depend on which buffers were open. I guess it should converge on the same answer as you open more and more files (so eventually it should get the same result), but this all sounds quite complicated. Simply having a correctly-set .editorconfig sounds easier.

I have to confess, this still sounds to me like something that's theoretically interesting, but I don't myself see much practical benefit.

Another idea: if someone fancies implementing it, it could be part of a project-management system like projectile, rather than part of dtrt-indent, or indeed a third-party package. I'm tempted to say that I think it's out of scope for dtrt-indent proper.

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

3 participants