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

Delay for running dtrt-indent #57

Open
orlandini opened this issue Apr 11, 2021 · 5 comments
Open

Delay for running dtrt-indent #57

orlandini opened this issue Apr 11, 2021 · 5 comments

Comments

@orlandini
Copy link

When using functions such as projectile-replace, every time I visit a buffer dtrt scans the file for detecting the indent. Is there a way to set a delay for this to happen?

I am often visiting 300+ files at a time, and it would be great if dtrt-indent didn't try to set the c-basic-offset unless I stayed in the buffer for half a second, for instance.

@rrthomas
Copy link
Collaborator

rrthomas commented Apr 11, 2021

There isn't a way. It sounds like this should be possible with some more generic feature, like, instead of adding dtrt-indent-mode to a hook, add a function that delays it? Also, it sounds to me like there might be other things you want to delay.

@orlandini
Copy link
Author

orlandini commented Apr 11, 2021

While I'm sure it'd be great to delay other things, I should say that dtrt-indent was certainly noticeable.

I don't have enough lisp knowledge to think of a way to deal with it, but should I find something I will comment here in case somebody is interested.

Should I close the issue then?

@rrthomas
Copy link
Collaborator

Feel free to keep it open!

@jscheid
Copy link
Owner

jscheid commented May 28, 2021

Not exactly what you asked for @orlandini but how about enabling it just before first indent? That seems even better to me than a delay. Something like this appears to work:

(require 'dtrt-indent)

(add-hook
 'pre-command-hook
 (lambda ()
   (when (and (not dtrt-indent-mode)
              (memq this-command
                    `(,indent-line-function
                      ,indent-region-function
                      ,(key-binding "\t")
                      indent-according-to-mode
                      indent-region
                      indent-sexp)))
     (dtrt-indent-mode 1))))

Could probably be optimized slightly, and there might be a few corner cases (functions not included in the list) but shouldn't be too hard to make work reliably.

@rrthomas I'm going to use this for a while, if it holds up perhaps this would be a nice feature. Something like dtrt-indent-lazy-flag. It could optionally be buffer-local which would let you set lazy mode depending on major mode, say.

@orlandini
Copy link
Author

@jscheid im looking forward to testing it! Thanks a lot.

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