0

How can I execute a specific command automatically, when the cursor rests for a while?

During a correction phase of my project I very frequently run a grep on the word the cursor currently positioned on. I already found a great enhancement in Grep-o-Matic, which lets me execute a grep of the current word in my git repository. After re-assigning grep-o-matic-repository to F-12 I can execute the grep with one keystroke.

But maybe I could spare even this additional keystroke? I am thinking of a combination with something that wuould almost feel like the ispell-mode: When the cursor rests for, say, 500ms then the grep-o-matic-repository should be executed automatically.

As a final tweak the top 4 lines in the result windows should be removed, but that's a bonus I can probably attack later.

towi
  • 21,587
  • 28
  • 106
  • 187
  • 1
    Check out [idle timers](http://www.gnu.org/software/emacs/manual/html_node/elisp/Idle-Timers.html). – Dan Sep 07 '14 at 12:34
  • Whow, `run-with-idle-timer` is 90% what I want. Good. – towi Sep 07 '14 at 12:54
  • For modifying the grep results buffer, I found that I had to do the following: `(defun jpk/grep-mode-hook () (run-with-idle-timer 0.01 nil (lambda () (with-current-buffer "*grep*" (do-stuff))))) (add-hook 'grep-mode-hook 'jpk/grep-mode-hook)`. I needed the idle timer because the hook seems to run when the buffer is created, but it takes a while before the grep process starts filling it in. – jpkotta Sep 08 '14 at 01:37

0 Answers0