Subject: bug#62419: 28.2; Elisp let-bound buffer-local variable and kill-local-variable

From: Stefan Monnier <[email-masked]>
Date: Sun, 26 Mar 2023 10:34:05 -0400

> The "`newline` let-binds `auto-fill-mode`" seems like the source of the
> problem :-(

We could fix it with a patch like the one below (intended for `master`).

        Stefan

diff --git a/lisp/simple.el b/lisp/simple.el
index 3e50e888dad..6f0215bfb1d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -659,7 +659,7 @@ newline
          (beforepos (point))
          (last-command-event ?\n)
          ;; Don't auto-fill if we have a prefix argument.
-         (auto-fill-function (if arg nil auto-fill-function))
+         (inhibit-auto-fill (or inhibit-auto-fill arg))
          (arg (prefix-numeric-value arg))
          (procsym (make-symbol "newline-postproc")) ;(bug#46326)
          (postproc
@@ -9269,11 +9269,15 @@ default-indent-new-line
        ;; If we're not inside a comment, just try to indent.
        (t (indent-according-to-mode))))))
 
+(defvar inhibit-auto-fill nil
+  "Non-nil means to do as if `auto-fill-mode' was disabled.")
+
 (defun internal-auto-fill ()
   "The function called by `self-insert-command' to perform auto-filling."
-  (when (or (not comment-start)
-            (not comment-auto-fill-only-comments)
-            (nth 4 (syntax-ppss)))
+  (when (and (not inhibit-auto-fill)
+             (or (not comment-start)
+                 (not comment-auto-fill-only-comments)
+                 (nth 4 (syntax-ppss))))
     (funcall auto-fill-function)))
 
 (defvar normal-auto-fill-function #'do-auto-fill