Subject: Re: bug#47588: 28.0.50; C-M-x in emacs-lisp-mode: elisp--eval-defun: Symbol’s function definition is void: nil [3 times]

From: Stefan Monnier <[email-masked]>
Date: Sun, 18 Apr 2021 01:06:35 -0400

It took me a while to figure out that the

    Symbol’s function definition is void: nil

was coming from `load-read-function` being nil (which was due to it
being rebound to nil by the `debug` function).

I installed the patch below which seems to fix it.
It's all still pretty messy, sadly.

        Stefan

commit 5c07cd0f156217db268ccb9fa64566fb429c4257 (HEAD -> trunk, origin/master, origin/HEAD)
Author: Stefan Monnier <[email-masked]>
Date:   Sun Apr 18 01:03:43 2021 -0400

    * lisp/emacs-lisp/debug.el (debug): Fix (bug#47588)
    
    Don't bind `load-read-function` to nil but to its actual default value.
    Actually, I'm not sure it's worth the trouble rebinding this var, but
    if we do, then we should bind it to a valid value rather than to nil.
    
    * lisp/emacs-lisp/edebug.el (edebug--eval-defun): Re-install our advice
    if needed.

diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el
index b2d54c77feb..069c7a90ad0 100644
--- a/lisp/emacs-lisp/debug.el
+++ b/lisp/emacs-lisp/debug.el
@@ -213,7 +213,7 @@ debug
              last-input-event last-command-event last-nonmenu-event
              last-event-frame
              overriding-local-map
-         load-read-function
+       (load-read-function #'read)
              ;; If we are inside a minibuffer, allow nesting
              ;; so that we don't get an error from the `e' command.
              (enable-recursive-minibuffers
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index cbc40193125..b08ee3c4a17 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -459,6 +459,9 @@ edebug--eval-defun
 If acting on a `defun' for FUNCTION, and the function was instrumented,
 `Edebug: FUNCTION' is printed in the minibuffer.  If not instrumented,
 just FUNCTION is printed."
+  ;; Re-install our advice, in case `debug' re-bound `load-read-function' to
+  ;; its default value.
+  (add-function :around load-read-function #'edebug--read)
   (let* ((edebug-all-forms (not (eq (not edebug-it) (not edebug-all-defs))))
         (edebug-all-defs  edebug-all-forms))
     (funcall orig-fun nil)))