Wilfred / ag.el

An Emacs frontend to The Silver Searcher
http://agel.readthedocs.org/en/latest/
525 stars 61 forks source link

Help with figuring out how to wait for the ag process to finish #89

Closed kaushalmodi closed 9 years ago

kaushalmodi commented 9 years ago

Hi,

I want to run a function when the ag search has finished.

What is a good way to do it?

I have the below function:

(defun ag/jump-to-result-if-only-one-match ()
  (let (only-one-match temp)
    (when (member "--stats" ag-arguments)
      (with-current-buffer ag/last-search-buffer-name
        (save-excursion
          (setq temp (buffer-substring-no-properties (point-min) (point-max)))
          (goto-char (point-min))
          (setq only-one-match (re-search-forward "^1 matches\\s-*$" nil :noerror))
          ;; (message temp)
          ;; (message "match: %s" only-one-match)
          ))
      (when only-one-match
        (next-error)
        (kill-buffer ag/last-search-buffer-name)))))

I tried calling it after the below code in (defun* ag/search ..)

      (compilation-start
       command-string
       #'ag-mode
       `(lambda (mode-name) ,ag/last-search-buffer-name))

But it obviously didn't work.

How can I poll for a compilation-start initiated process status?

stardiviner commented 9 years ago

Maybe ag.el should have a hook for this?

Wilfred commented 9 years ago

Sorry for the delay on this. It's a good suggestion, I'll take a look at implementing it.

kaushalmodi commented 9 years ago

@Wilfred Thanks. I submitted this PR which the full code. The code in the first post in this issue was simplified.

@stardiviner Yes. That's what I had in my implementation (PR https://github.com/Wilfred/ag.el/pull/91). I wanted to wait till I figure out the solution for the above question. But I guess, adding this PR might help Wilfred, you or anyone else to help me more.