From eb690735784ba162e68d9fb9ab3704feae126e24 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 27 Feb 2020 21:47:32 -0500 Subject: [PATCH] Fix infinite redrawing/freezing with {centaur,awesome}-tabs Caused by over-zealous doom-switch-window-hook. For my own sanity (and if you're curious), I'll break it down here: 1. Doom has a `doom-switch-window-hook` hook. It triggers when window focus is changed. 2. We use `buffer-list-update-hook` to trigger `doom-switch-window-hook`. (That may sound weird, but this hook is reliably executed when window focus is changed -- there are safeguards to prevent this from triggering too often) 3. `buffer-list-update-hook` triggers whenever a buffer is created, but `doom-switch-window-hook` only triggers if the created buffer is in a new window. 4. The use of `with-temp-buffer` in `centaur-tabs-line-format` counts as "buffer creation" in a "new window". 5. `+vc-gutter-update-h` is in `doom-switch-window-hook`. This refreshes git-gutter, which initiates a redraw of Emacs. 6. When Emacs redraws, it recalculates its mode and header lines. which triggers `doom-switch-window-hook` once, which triggers `+vc-gutter-update-h`, which redraws the screen, then Emacs recalculates the header line, running `centaur-tabs-line-format`... Infinite loop ensues Hopefully fixes: - hlissner/doom-emacs#2436 - ema2159/centaur-tabs#18 - ema2159/centaur-tabs#88 --- core/core-ui.el | 9 ++++++--- modules/ui/vc-gutter/config.el | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/core-ui.el b/core/core-ui.el index 6592485ec..faf5309f9 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -89,7 +89,8 @@ size.") (unless (or doom-inhibit-switch-window-hooks (eq doom--last-window (selected-window)) (minibufferp)) - (let ((doom-inhibit-switch-window-hooks t)) + (let ((doom-inhibit-switch-window-hooks t) + (inhibit-redisplay t)) (run-hooks 'doom-switch-window-hook) (setq doom--last-window (selected-window)))))) @@ -107,7 +108,8 @@ size.") (eq (current-buffer) (get-buffer buffer-or-name)) (and (eq orig-fn #'switch-to-buffer) (car args))) (apply orig-fn buffer-or-name args) - (let ((doom-inhibit-switch-buffer-hooks t)) + (let ((doom-inhibit-switch-buffer-hooks t) + (inhibit-redisplay t)) (when-let (buffer (apply orig-fn buffer-or-name args)) (with-current-buffer (if (windowp buffer) (window-buffer buffer) @@ -119,7 +121,8 @@ size.") (let ((gc-cons-threshold most-positive-fixnum)) (if doom-inhibit-switch-buffer-hooks (apply orig-fn args) - (let ((doom-inhibit-switch-buffer-hooks t)) + (let ((doom-inhibit-switch-buffer-hooks t) + (inhibit-redisplay t)) (when-let (buffer (apply orig-fn args)) (with-current-buffer buffer (run-hooks 'doom-switch-buffer-hook)) diff --git a/modules/ui/vc-gutter/config.el b/modules/ui/vc-gutter/config.el index d310a82b8..075fb0005 100644 --- a/modules/ui/vc-gutter/config.el +++ b/modules/ui/vc-gutter/config.el @@ -71,7 +71,8 @@ is deferred until the file is saved. Respects `git-gutter:disabled-modes'." `doom-escape-hook' hooks." (when (and git-gutter-mode (not (memq this-command '(git-gutter:stage-hunk - git-gutter:revert-hunk)))) + git-gutter:revert-hunk))) + (not inhibit-redisplay)) (ignore (git-gutter))))) ;; update git-gutter when using magit commands (advice-add #'magit-stage-file :after #'+vc-gutter-update-h)