The function for doing this is called run-with-idle-timer
. From the help for that function:
(run-with-idle-timer SECS REPEAT FUNCTION &rest ARGS)
Perform an action the next time Emacs is idle for SECS seconds.
The action is to call FUNCTION with arguments ARGS.
See the full help with C-h f run-with-idle-timer
, and the relevant manual section is (elisp) Idle Timers.
For your issue, you probably want something like:
(run-with-idle-timer 3 t #'my-function)
Where my-function
is the name of the function called by C-c C-k
. By default, C-c C-k
isn't bound to anything, so I don't know what this does on your Emacs, it must be a custom configuration you have added.
Note that this will run my-function
once every time Emacs is idle for more than 3 seconds. You only want it to run when the buffer has been edited. You can accomplish this by writing a wrapper that only calls my-function
when buffer-edited-p
returns t
:
(defun my-idle-function ()
(if (buffer-edited-p) (my-function)))
And then something like this:
(run-with-idle-timer 3 t #'my-idle-function)