]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid turning on the global-minor-mode recursively
authorJohn Shahid <jvshahid@gmail.com>
Sat, 23 Jun 2018 15:12:44 +0000 (11:12 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Tue, 10 Jul 2018 12:13:39 +0000 (08:13 -0400)
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Clear
the buffer-list inside MODE-enable-in-buffers to avoid enabling the
mode recursively.  (Bug#31793)

lisp/emacs-lisp/easy-mmode.el

index 21ca69324edd39269e2dc5f74617c801a6af6a00..443e03eb1a38164ed6e6d415669ed2c21eb13f78 100644 (file)
@@ -457,22 +457,26 @@ See `%s' for more information on %s."
 
        ;; The function that calls TURN-ON in each buffer.
        (defun ,MODE-enable-in-buffers ()
-        (dolist (buf ,MODE-buffers)
-          (when (buffer-live-p buf)
-            (with-current-buffer buf
-               (unless ,MODE-set-explicitly
-                (unless (eq ,MODE-major-mode major-mode)
-                  (if ,mode
-                      (progn
-                        (,mode -1)
-                        (funcall #',turn-on))
-                    (funcall #',turn-on))))
-              (setq ,MODE-major-mode major-mode)))))
+         (let ((buffers ,MODE-buffers))
+           ;; Clear MODE-buffers to avoid scanning the same list of
+           ;; buffers in recursive calls to MODE-enable-in-buffers.
+           ;; Otherwise it could lead to infinite recursion.
+           (setq ,MODE-buffers nil)
+           (dolist (buf buffers)
+             (when (buffer-live-p buf)
+               (with-current-buffer buf
+                 (unless ,MODE-set-explicitly
+                   (unless (eq ,MODE-major-mode major-mode)
+                     (if ,mode
+                         (progn
+                           (,mode -1)
+                           (funcall #',turn-on))
+                       (funcall #',turn-on))))
+                 (setq ,MODE-major-mode major-mode))))))
        (put ',MODE-enable-in-buffers 'definition-name ',global-mode)
 
        (defun ,MODE-check-buffers ()
         (,MODE-enable-in-buffers)
-        (setq ,MODE-buffers nil)
         (remove-hook 'post-command-hook ',MODE-check-buffers))
        (put ',MODE-check-buffers 'definition-name ',global-mode)