Subject: bug#69809: 30.0.50; flymake: error in process sentinel

From: Eli Zaretskii <[email-masked]>
Date: Fri, 12 Jul 2024 09:27:26 +0300

> From: Eshel Yaron <[email-masked]>
> Cc: [email-masked],  Spencer Baugh <[email-masked]>,  Eli
>  Zaretskii <[email-masked]>,  [email-masked]
> Date: Thu, 11 Jul 2024 13:15:41 +0200
> 
> Eshel Yaron <[email-masked]> writes:
> 
> [...]
> 
> > This issue bothered me as well.  Here's a recipe for reproducing on
> > master, with emacs -Q:
> >
> > 1. (add-hook 'c-mode-hook 'flymake-mode)
> > 2. (add-hook 'c-mode-hook 'eglot-ensure)
> > 3. Find some C file
> >
> > This happens because Eglot _restarts_ flymake-mode while flymake-cc's
> > process is already running.  Here's a simple fix:
> >
> > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> > index a893a8d749a..c9e1bb7b52d 100644
> > --- a/lisp/progmodes/eglot.el
> > +++ b/lisp/progmodes/eglot.el
> > @@ -2040,7 +2040,7 @@ eglot--managed-mode
> >      (unless (eglot--stay-out-of-p 'imenu)
> >        (add-function :before-until (local 'imenu-create-index-function)
> >                      #'eglot-imenu))
> > -    (unless (eglot--stay-out-of-p 'flymake) (flymake-mode 1))
> > +    (unless (or (eglot--stay-out-of-p 'flymake) flymake-mode) (flymake-mode 1))
> >      (unless (eglot--stay-out-of-p 'eldoc)
> >        (add-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function
> >                  nil t)
> 
> I realized that the change above has the downside of no longer
> immediately initiating a Flymake analysis with Eglot in place.  To
> preserve that behavior, maybe something like the following is better:
> 
> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index a893a8d749a..6cd48917d47 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -2040,7 +2040,8 @@ eglot--managed-mode
>      (unless (eglot--stay-out-of-p 'imenu)
>        (add-function :before-until (local 'imenu-create-index-function)
>                      #'eglot-imenu))
> -    (unless (eglot--stay-out-of-p 'flymake) (flymake-mode 1))
> +    (unless (eglot--stay-out-of-p 'flymake)
> +      (if flymake-mode (flymake-start) (flymake-mode 1)))
>      (unless (eglot--stay-out-of-p 'eldoc)
>        (add-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function
>                  nil t)

Spencer, any comments?

>From where I stand, this is okay for the emacs-30 release branch,
unless you think it could break some legitimate workflow.