From 80598bac5a1ba3e0261f0aff38a3c2bcc0b35b09 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 7 Jan 2021 21:50:32 +0100 Subject: [PATCH] Prevent infinite recursion when displaying a warning. If the *Warnings* buffer has auto-fill enabled and we're about to print the warning, `display-warning' would loop back here through `newline' and `self-insert-command', causing infinite recursion. I haven't been able to reproduce this in a noninteractive unit test, unfortunately, but the issue happens in interactive mode whenever `yas--original-auto-fill-function' is nil and `auto-fill-mode' is enabled in the *Warnings* buffer. * yasnippet.el (yas--auto-fill): Disable `auto-fill-mode' in the *Warnings* buffer as well. --- yasnippet.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yasnippet.el b/yasnippet.el index 78ef38ac..544d8aa8 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3919,6 +3919,12 @@ field start. This hook does nothing if an undo is in progress." (when (local-variable-p 'auto-fill-function) (if af-cell (setcdr af-cell (cons buf (cdr af-cell))) (push (list auto-fill-function buf) fill-fun-values)))))) + ;; Prevent infinite recursion if printing the warning tries to + ;; auto-fill. + (let ((buffer (get-buffer "*Warnings*"))) + (when (buffer-live-p buffer) + (with-current-buffer buffer + (auto-fill-mode -1)))) (lwarn '(yasnippet auto-fill bug) :error "`yas--original-auto-fill-function' unexpectedly nil in %S! Disabling auto-fill. %S