From 6df2941c1b0d965afc40f8c50ce08e45e060d64c Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 2 Apr 2023 17:54:02 -0400 Subject: [PATCH] lisp/simple.el (inhibit-auto-fill): New var * lisp/simple.el (inhibit-auto-fill): New var. (internal-auto-fill): Obey it. (newline): Use it instead of binding `auto-fill-function`, so as to avoid messing up the state if something wants to enable/disable `auto-fill-mode` during the course of the let binding (bug#62419). --- etc/NEWS | 2 ++ lisp/simple.el | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 67e1a02d587..d20d9f65ac9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -319,6 +319,8 @@ hooks named after the feature name, like 'esh-mode-unload-hook'. * Lisp Changes in Emacs 30.1 +** New var 'inhibit-auto-fill' to temporarily prevent auto-fill. + ** Functions and variables to transpose sexps +++ diff --git a/lisp/simple.el b/lisp/simple.el index 1447c7e53ff..b621e1603bd 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -623,7 +623,7 @@ A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'." (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 @@ -8919,11 +8919,15 @@ unless optional argument SOFT is non-nil." ;; 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))) + (unless (or inhibit-auto-fill + (and comment-start + comment-auto-fill-only-comments + (not (nth 4 (syntax-ppss))))) (funcall auto-fill-function))) (defvar normal-auto-fill-function 'do-auto-fill -- 2.39.2