-
Notifications
You must be signed in to change notification settings - Fork 31
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
Several improvements in file local variable usage #47
base: master
Are you sure you want to change the base?
Conversation
When file or directory local variables are used, they are set after the minor mode is setup. To fix this, use the hack-local-variables-hook to ensure that the setup is done after variables are set.
Apply dtrt-indent-hook-generic-mapping-list to derived modes as well. For example, if '(prog-mode tab-width) is added to to the list, 'tab-width' will be set to the current offset for any major mode derived from prog-mode.
Add dtrt-indent-force-offset, which when set will allow the indent to be set to a particular value. This value is used as if dtrt-indent guessed it as the offset value. This is intended to be used as a file-local or dir-local variable to set the offset value when dtrt-indent comes up with the wrong value or can't determine the value because only hard tabs are in use in the file. Any related values are still set (e.g. evil-shift-width). Logging of set value will show "[forced]" when this variable is used.
A file variable setting of indent-tabs-mode should override dtrt-indent's setting of this variable, but the code was only partially implemented. This commit finishes the implementation.
Great stuff. Is this now ready to be merged as far as you're concerned? |
I think so. If you are reluctant, I can give it another week of testing at my day job. I did make some minor changes during the week, and I'm not in any rush in any case. |
Another week would be great if that's OK by you. I'll also try your branch. |
OK to ping me in a week? Many thanks in any case! |
I just noticed that your branch isn't working for me, in what looks like a fairly basic case: I have c-basic-offset set to 2, I visit a file that dtrt-indent evaluates (correctly) as having an indent of 4, and c-basic-offset is not adjusted. There are no file-local or directory-local overrides in this case. Sorry, I don't have time to debug this right now, but thought you'd want to know. |
OK, I'll look into it. |
So far I'm not able to reproduce with a file with 3-space indent (no hard tabs), no .dir-locals.el, and me setting c-basic-offset to 8 in my init.el for cc-mode. It correctly detects offset of 3. What does dtrt-indent log in your case? |
Nothing is logged. If I run
However, it doesn't alter anything; maybe it thinks my setting is already 4 for some reason? With current head, I get the same output from dtrt-indent-diagnosis, and the following logged:
I should also note that my |
Very odd. I'll look at the code further when I get a chance. |
I don't see anything that would explain the different behaviours we are seeing. I would check that dtrt-indent-post-local-variable-setup runs for the buffer, maybe the hooks aren't working the way I thought for some reason. Also, what does your dtrt-indent setup look like? |
All my dtrt settings are customizations: '(dtrt-indent-global-mode t) Checking, I find that I tried disabling So to summarize, if I run |
That analysis seems correct. I ran dtrt-indent-mode from a prog-mode hook, which I guess has the right timing for the code in the PR. I'll revise it so it works correctly for that case, for manual invoke and for the global mode. Not sure how to do that yet, but I guess I'll learn something in the process. |
Great stuff, looking forward to it! |
The commits first to last: