Inhibit org-mode-hook in org-agenda
This commit is contained in:
parent
134409aa67
commit
97bbe5e322
1
init.el
1
init.el
|
@ -571,6 +571,7 @@
|
||||||
(setq load-path
|
(setq load-path
|
||||||
(cl-remove-if (lambda (path) (string-match-p "lisp/org\\'" path)) load-path))
|
(cl-remove-if (lambda (path) (string-match-p "lisp/org\\'" path)) load-path))
|
||||||
(:also-load +org)
|
(:also-load +org)
|
||||||
|
(with-eval-after-load '+org (+org-agenda-inhibit-hooks-mode +1))
|
||||||
(:option org-adapt-indentation nil
|
(:option org-adapt-indentation nil
|
||||||
org-auto-align-tags t
|
org-auto-align-tags t
|
||||||
org-archive-mark-done t
|
org-archive-mark-done t
|
||||||
|
|
34
lisp/+org.el
34
lisp/+org.el
|
@ -650,5 +650,39 @@ and POST-PROCESS are passed to `org-export-to-file'."
|
||||||
(set-category-table +org-category-table)
|
(set-category-table +org-category-table)
|
||||||
(setq-local word-wrap-by-category t))
|
(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)
|
(provide '+org)
|
||||||
;;; +org.el ends here
|
;;; +org.el ends here
|
||||||
|
|
Loading…
Reference in New Issue