diff options
author | John Shahid <jvshahid@gmail.com> | 2018-06-23 11:12:44 -0400 |
---|---|---|
committer | Noam Postavsky <npostavs@gmail.com> | 2018-07-10 08:13:39 -0400 |
commit | 35e0305dc2a57cea6fcb515db9e0b0f938daf53a (patch) | |
tree | e6e8253c530733a0a3743d94b9e8dcc2fb801fd4 /lisp/emacs-lisp | |
parent | 51bf4e4650fc11fc4ab3037f5738151f86d7fb47 (diff) | |
download | emacs-35e0305dc2a57cea6fcb515db9e0b0f938daf53a.tar.gz emacs-35e0305dc2a57cea6fcb515db9e0b0f938daf53a.tar.bz2 emacs-35e0305dc2a57cea6fcb515db9e0b0f938daf53a.zip |
Avoid turning on the global-minor-mode recursively
* 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)
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 21ca69324ed..443e03eb1a3 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -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) |