Inhibit org-mode-hook in org-agenda

This commit is contained in:
Case Duckworth 2022-05-12 22:38:01 -05:00
parent 134409aa67
commit 97bbe5e322
2 changed files with 35 additions and 0 deletions

View File

@ -571,6 +571,7 @@
(setq load-path
(cl-remove-if (lambda (path) (string-match-p "lisp/org\\'" path)) load-path))
(:also-load +org)
(with-eval-after-load '+org (+org-agenda-inhibit-hooks-mode +1))
(:option org-adapt-indentation nil
org-auto-align-tags t
org-archive-mark-done t

View File

@ -650,5 +650,39 @@ and POST-PROCESS are passed to `org-export-to-file'."
(set-category-table +org-category-table)
(setq-local word-wrap-by-category t))
;;; Inhibit hooks on `org-agenda'
;; It's really annoying when I call `org-agenda' and five hundred Ispell
;; processes are created because I have `flyspell-mode' in the hook. This mode
;; inhibits those hooks when entering the agenda, but runs them when opening the
;; actual buffer.
(defun +org-agenda-inhibit-hooks (fn &rest r)
"Advice to inhibit hooks when entering `org-agenda'."
(dlet ((org-mode-hook nil)) ; I'm not sure if `dlet' is strictly needed
(apply fn r)))
(defvar-local +org-hook-has-run-p nil
"Whether `org-mode-hook' has run in the current buffer.")
(defun +org-agenda-switch-run-hooks (&rest _)
"Advice to run `org-mode-hook' when entering org-mode.
This should only fire when switching to a buffer from `org-agenda'."
(unless +org-hook-has-run-p
(run-hooks 'org-mode-hook)
(setq +org-hook-has-run-p t)))
(define-minor-mode +org-agenda-inhibit-hooks-mode
"Inhibit `org-mode-hook' when opening `org-agenda'."
:lighter ""
:global t
(if +org-agenda-inhibit-hooks-mode
(progn ; Enable
(advice-add 'org-agenda :around #'+org-agenda-inhibit-hooks)
(advice-add 'org-agenda-switch-to :after #'+org-agenda-switch-run-hooks))
(progn ; Disable
(advice-remove 'org-agenda #'+org-agenda-inhibit-hooks)
(advice-remove 'org-agenda-switch-to #'+org-agenda-switch-run-hooks))))
(provide '+org)
;;; +org.el ends here