Perhaps you need to register a Process Filter to give you the callback time you need? See 37.9 Getting Process Output in the Elisp Manual (I see this in my copy for Emacs 22.3).
Here is an example of triggering a callback when you get the first output of a process and also save it in a "linked buffer". Copy it to the *scratch* and eval-region buffers, but be sure to separate it and show the *Messages* buffer so you can see what happens.
;; this is emacs lisp (and a comment line) (defvar my-callback-got-some-already nil) (defun my-callback () (message "callback ran at %s" (current-time-string))) (defun my-filter-waits-for-first-time-input (proc string) (unless my-callback-got-some-already (setq my-callback-got-some-already t) ;; do your one-time thing (my-callback)) ;; insert into the associated buffer as if no process filter was ;; registered (with-current-buffer (process-buffer proc) (let ((moving (= (point) (process-mark proc)))) (save-excursion ;; Insert the text, advancing the process marker. (goto-char (process-mark proc)) (insert string) (set-marker (process-mark proc) (point))) (if moving (goto-char (process-mark proc)))))) (defun async-callback-test-harness () (interactive) (let ((process-handle "async-callback-test") (associated-process-buffer "*async-callback-test*") (command "ls") (busy-loop-var "")) (setq my-callback-got-some-already nil) (message "start test %s" (current-time-string)) (start-process process-handle associated-process-buffer command) ;; Supposedly async but Emacs doesn't get the input until ;; "Emacs is waiting" so the following set-process-filter ;; can be registered in time. ;; To prove the point, make emacs busy loop to show that the ;; emacs doesn't drop its input and ;; the callback will get the unskipped input. (switch-to-buffer associated-process-buffer) (dotimes (k 2000) ; about two seconds on my machine (setq busy-loop-var (concat busy-loop-var "busy looping..."))) (message "done busy waiting %s" (current-time-string)) (set-process-filter (get-process process-handle) 'my-filter-waits-for-first-time-input) nil)) ;; run it! (async-callback-test-harness)
source share