Subject: Re: bug#61350: Eglot over Tramp freezes with large project

From: João Távora <[email-masked]>
Date: Thu, 16 Mar 2023 15:58:58 +0000

João Távora <[email-masked]> writes:

> Jim Porter <[email-masked]> writes:
>    (setq answer-from-proc (catch 'done
>                             (process-put proc 'busy t)
>                             (process-send-string proc "OPEN THE POD BAY DOORS\n")
>                             (while (accept-process-output))))
>
> This is very simplified (and untested), but that's the gist.  

The gist it is, but also very broken.  As ever, vapourware sucks. This
is what that snippet should have been:

  ;;; hal.el --- asdasd                                -*- lexical-binding: t; -*-
  (defvar hal-proc nil)
  (defun hal-connect()
    (interactive)
    (when (processp hal-proc) (delete-process hal-proc))
    (setq hal-proc
          (make-process
           :name "halproc"
           :command (list (expand-file-name "hal" default-directory))
           :buffer (generate-new-buffer "*halbuf*")
           :filter (lambda (proc output)
                     (internal-default-process-filter proc output)
                     (when-let* ((buffer (process-buffer proc))
                                 (callback (and (buffer-live-p buffer)
                                                (process-get proc 'callback))))
                       (with-current-buffer buffer
                         (save-excursion
                           (goto-char (point-min))
                           (when (search-forward ", DAVE\n" nil t)
                             (unwind-protect (funcall callback
                                                      (buffer-substring
                                                       (point-min) (point)))
                               (process-put proc 'callback nil)
                               (delete-region (point-min)
                               (point)))))))))))
   
  (defun hal-command ()  "Synch command to HAL that doesn't block others."
    (interactive)
    (message
     (catch 'hal-done
       (process-put hal-proc 'callback
                    (lambda (result) (throw 'hal-done result)))
       (process-send-string hal-proc "OPEN THE POD BAY DOORS!\n")
       (while (accept-process-output hal-proc)))))

You can test this with this very complex C++ program
    
   #include <cstdlib>
   #include <iostream>
   #include <string>
   #include <array>
    
   int main() {
     std::string line;
     const char* retorts[] = {
       "I'M AFRAID I CAN'T DO THAT",
       "I'D RATHER NOT",
       "THINK OF THE CONSEQUENCES",
       "PLEASE STOP"
     };
     while (std::cin >> line)
       std::cout << retorts[std::rand()%4] << ", DAVE" << std::endl;
   }