Fix #3787: only inhibit some hooks for org-src ops

Inhibiting all MAJOR-MODE-hook functions (to fix #3660) would mean
inhibiting some useful functionality, like indentation or syntax
highlighting modes. We only want to inhibit expensive hooks. Since Doom
adds these to MAJOR-MODE-local-vars-hook by convention, we can
selectively inhibit those instead.
This commit is contained in:
Henrik Lissner 2020-08-20 01:48:49 -04:00
parent 4841062db9
commit dddfd9a7b1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 10 additions and 8 deletions

View file

@ -366,12 +366,12 @@ config.el instead."
;; File+dir local variables are initialized after the major mode and its hooks ;; File+dir local variables are initialized after the major mode and its hooks
;; have run. If you want hook functions to be aware of these customizations, add ;; have run. If you want hook functions to be aware of these customizations, add
;; them to MODE-local-vars-hook instead. ;; them to MODE-local-vars-hook instead.
(defvar doom--inhibit-local-var-hooks nil) (defvar doom-inhibit-local-var-hooks nil)
(defun doom-run-local-var-hooks-h () (defun doom-run-local-var-hooks-h ()
"Run MODE-local-vars-hook after local variables are initialized." "Run MODE-local-vars-hook after local variables are initialized."
(unless doom--inhibit-local-var-hooks (unless doom-inhibit-local-var-hooks
(set (make-local-variable 'doom--inhibit-local-var-hooks) t) (set (make-local-variable 'doom-inhibit-local-var-hooks) t)
(run-hook-wrapped (intern-soft (format "%s-local-vars-hook" major-mode)) (run-hook-wrapped (intern-soft (format "%s-local-vars-hook" major-mode))
#'doom-try-run-hook))) #'doom-try-run-hook)))

View file

@ -226,11 +226,13 @@ This forces it to read the background before rendering."
(if (and (eq org-src-window-setup 'switch-invisibly) (if (and (eq org-src-window-setup 'switch-invisibly)
(functionp initialize)) (functionp initialize))
;; org-babel-do-in-edit-buffer is used to execute quick, one-off ;; org-babel-do-in-edit-buffer is used to execute quick, one-off
;; logic in the context of another major mode. Initializing this ;; logic in the context of another major mode, but initializing a
;; major mode can be terribly expensive (particular its mode ;; major mode with expensive hooks can be terribly expensive.
;; hooks), so we inhibit them. ;; Since Doom adds its most expensive hooks to
;; MAJOR-MODE-local-vars-hook, we can savely inhibit those.
(lambda () (lambda ()
(quiet! (delay-mode-hooks (funcall initialize)))) (let ((doom-inhibit-local-var-hooks t))
(funcall initialize)))
initialize) initialize)
args)) args))

View file

@ -247,7 +247,7 @@ called.")
(pyenv-mode +1) (pyenv-mode +1)
(when (executable-find "pyenv") (when (executable-find "pyenv")
(add-to-list 'exec-path (expand-file-name "shims" (or (getenv "PYENV_ROOT") "~/.pyenv")))) (add-to-list 'exec-path (expand-file-name "shims" (or (getenv "PYENV_ROOT") "~/.pyenv"))))
(add-hook 'python-mode-hook #'+python-pyenv-mode-set-auto-h) (add-hook 'python-mode-local-vars-hook #'+python-pyenv-mode-set-auto-h)
(add-hook 'doom-switch-buffer-hook #'+python-pyenv-mode-set-auto-h)) (add-hook 'doom-switch-buffer-hook #'+python-pyenv-mode-set-auto-h))