> To make it easier in the future to deal with this problem, I > suggest to add a process specific flag > ``process-no-concurrent-filters''. When this flag is t for a > process, Emacs accepts output from this process inside a filter > but buffers it without calling the filter. The call to the filter > is delayed until a point where no filter for this process is > running. An error is signaled, if the buffered output exceeds a > certain size. I thought of just making a wrapper in Lisp instead, this saves the need to complicate the process C code with yet another flag; it's already tricky enough as it is. ;;; -*- lexical-binding: t -*- (defun make-buffered-filter (filter) (let ((filtering nil) (buffered nil) (process nil)) (lambda (proc str) (if process (unless (eq process proc) (error "Buffered filter used in different processes: %S, %S" proc process)) (setq process proc)) (push str buffered) (unless filtering (setq filtering t) (unwind-protect (while buffered (setq str (apply #'concat (nreverse buffered))) (setq buffered nil) (funcall filter proc str)) (setq filtering nil)))))) ;; Can be used like (set-process-filter my-process (make-buffered-filter #'my-filter-function))