[comp.emacs] Is process P waiting for user input?

gaynor@topaz.rutgers.edu (Silver) (01/19/88)

Hi.

I am using GNU Emacs v18.49.8.

I am running a process asynchroniously with a filter.  This process
intermittently but relatively rapidly produces spurts of garbage
intermixed with the good stuff.  With the filter, I stuff the output
into a temporary buffer to await further processing.  When the process
stops producing output and is waiting for input from the user, I want
a function called to inspect the contents of the buffer and send the
process some input based upon that inspection.  Continuously.

I could achieve this fairly easily if I had a function:

  (defun process-waiting-for-user-input-p (process)
    "Return t if PROCESS is waiting for user input, nil otherwise."
    ...)

I thought I had this with waiting-for-user-input-p, but the docs
clearly indicate that the waiting is with respect to emacs:

  waiting-for-user-input-p:
  Returns non-NIL if emacs is waiting for input from the user.
  This is intended for use by asynchronous process output filters and sentinels.

What is meant by "This is intended for use..."?

I looked at the possible status changes that fire the sentinel, but no
go:

  process-status:
  Return the status of PROCESS: a symbol, one of these:
  run  -- for a process that is running.
  stop -- for a process stopped but continuable.
  exit -- for a process that has exited.
  signal -- for a process that has got a fatal signal.
  open -- for a network stream connection that is open.
  closed -- for a network stream connection that is closed.
  nil -- if arg is a process name and no such process exists.

This was a desperate hack I tried earlier:

  (defun the-filter (process output)
    "Foo."

    ;; increment number-of-filters-running and make a local copy of it

    ;; insert the output into the temporary buffer

    (accept-process-output)

    ;; if number-of-filters-running is the same as the local copy,
    ;; then no output was accepted by the accept-process-output, and
    ;; the buffer should be inspected

    ;; decrement number-of-filters-running

I discovered then that the new output is not going to be processed
until the current output (function?) is done.  So this was a lose.

If I had this function, the filter would then read:

  (defun the-filter (process output)
    "Foo."

    ;; insert output into the temporary buffer

    (if (process-waiting-for-user-input-p process)
      ;; inspect the buffer, send a string to process

Any help muchly appreciated,
[Ag]

LOOKING FOR ENTRY-LEVELISH C/LISP PROGRAMMING, SOFTWARE ENGINEERING
Andy Gaynor   201-545-0458   81 Hassart St, New Brunswick, NJ 08901
  gaynor@topaz.rutgers.edu   ...!rutgers!topaz.rutgers.edu!gaynor
                    "Tarzan no want computer."