Fix #3660: inhibit expensive mode hooks in src blocks

Speeds up native indentation on RET or TAB in org src blocks.

Also, only reindent natively on RET if org-src-tab-acts-natively is
non-nil.
This commit is contained in:
Henrik Lissner 2020-07-31 15:41:34 -04:00
parent 8b81c4c72a
commit ff18b1329e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -211,10 +211,27 @@ This forces it to read the background before rendering."
(defadvice! +org-fix-newline-and-indent-in-src-blocks-a (&optional indent _arg _interactive) (defadvice! +org-fix-newline-and-indent-in-src-blocks-a (&optional indent _arg _interactive)
"Mimic `newline-and-indent' in src blocks w/ lang-appropriate indentation." "Mimic `newline-and-indent' in src blocks w/ lang-appropriate indentation."
:after #'org-return :after #'org-return
(when (and indent (org-in-src-block-p t)) (when (and indent
org-src-tab-acts-natively
(org-in-src-block-p t))
(org-babel-do-in-edit-buffer (org-babel-do-in-edit-buffer
(call-interactively #'indent-for-tab-command)))) (call-interactively #'indent-for-tab-command))))
(defadvice! +org-inhibit-mode-hooks-a (orig-fn datum name &optional initialize &rest args)
"Prevent potentially expensive mode hooks in `org-babel-do-in-edit-buffer' ops."
:around #'org-src--edit-element
(apply orig-fn datum name
(if (and (eq org-src-window-setup 'switch-invisibly)
(functionp initialize))
;; org-babel-do-in-edit-buffer is used to execute quick, one-off
;; logic in the context of another major mode. Initializing this
;; major mode can be terribly expensive (particular its mode
;; hooks), so we inhibit them.
(lambda ()
(quiet! (delay-mode-hooks (funcall initialize))))
initialize)
args))
;; Refresh inline images after executing src blocks (useful for plantuml or ;; Refresh inline images after executing src blocks (useful for plantuml or
;; ipython, where the result could be an image) ;; ipython, where the result could be an image)
(add-hook 'org-babel-after-execute-hook #'org-redisplay-inline-images) (add-hook 'org-babel-after-execute-hook #'org-redisplay-inline-images)