Function: ghostel--events-filter

ghostel--events-filter is a natively compiled function defined in ghostel.el.

Signature

(ghostel--events-filter PIPE OUTPUT)

Documentation

Process native PTY events received from PIPE.

OUTPUT is a byte string containing one or more Lisp forms. Forms are evaluated in the ghostel buffer; incomplete trailing input is kept in ghostel--event-buf until more data arrives.

A bare numeric event is the native reaper's exit status marker; it closes PIPE so its sentinel can run the normal process-exit cleanup. Any event batch invalidates the buffer for redraw while the buffer is still live.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel.el
(defun ghostel--events-filter (pipe output)
  "Process native PTY events received from PIPE.
OUTPUT is a byte string containing one or more Lisp forms.  Forms
are evaluated in the ghostel buffer; incomplete trailing input is
kept in `ghostel--event-buf' until more data arrives.

A bare numeric event is the native reaper's exit status marker; it
closes PIPE so its sentinel can run the normal process-exit cleanup.
Any event batch invalidates the buffer for redraw while the buffer is
still live."
  (let* ((buffer (process-buffer pipe))
         (str (concat ghostel--event-buf output))
         (len (length str))
         (offset 0))
    (while (< offset len)
      (let* ((result (condition-case _ (read-from-string str offset)
                       (end-of-file (cons :incomplete len))))
             (event (car result))
             (next (cdr result)))
        (if (eq event :incomplete)
            (setq ghostel--event-buf (substring str offset)
                  offset len)
          (setq ghostel--event-buf nil)
          (cond
           ;; The reaper thread writes the child exit status as a bare number.
           ((numberp event)
            (delete-process pipe))
           ;; Other events are Lisp forms generated by native terminal callbacks.
           ((and (buffer-live-p buffer) event)
            (with-current-buffer buffer
              (condition-case err
                  (eval event t)
                (error
                 (message "ghostel: error handling event %S: %S"
                          event err))))))
          (setq offset next))))
    (when (buffer-live-p buffer)
      (with-current-buffer buffer
        (ghostel--invalidate)))))