diff options
author | Case Duckworth | 2022-05-12 22:38:01 -0500 |
---|---|---|
committer | Case Duckworth | 2022-05-12 22:38:01 -0500 |
commit | 97bbe5e3225def2e39a9d109620d62b1841ad5be (patch) | |
tree | 22b55a1b5070f9d3a40ff24e14501349bb0206e7 | |
parent | Modeline stuff! (diff) | |
download | emacs-97bbe5e3225def2e39a9d109620d62b1841ad5be.tar.gz emacs-97bbe5e3225def2e39a9d109620d62b1841ad5be.zip |
Inhibit org-mode-hook in org-agenda
-rw-r--r-- | init.el | 1 | ||||
-rw-r--r-- | lisp/+org.el | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/init.el b/init.el index 73f5685..c511871 100644 --- a/init.el +++ b/init.el | |||
@@ -571,6 +571,7 @@ | |||
571 | (setq load-path | 571 | (setq load-path |
572 | (cl-remove-if (lambda (path) (string-match-p "lisp/org\\'" path)) load-path)) | 572 | (cl-remove-if (lambda (path) (string-match-p "lisp/org\\'" path)) load-path)) |
573 | (:also-load +org) | 573 | (:also-load +org) |
574 | (with-eval-after-load '+org (+org-agenda-inhibit-hooks-mode +1)) | ||
574 | (:option org-adapt-indentation nil | 575 | (:option org-adapt-indentation nil |
575 | org-auto-align-tags t | 576 | org-auto-align-tags t |
576 | org-archive-mark-done t | 577 | org-archive-mark-done t |
diff --git a/lisp/+org.el b/lisp/+org.el index 6075b60..89ed483 100644 --- a/lisp/+org.el +++ b/lisp/+org.el | |||
@@ -650,5 +650,39 @@ and POST-PROCESS are passed to `org-export-to-file'." | |||
650 | (set-category-table +org-category-table) | 650 | (set-category-table +org-category-table) |
651 | (setq-local word-wrap-by-category t)) | 651 | (setq-local word-wrap-by-category t)) |
652 | 652 | ||
653 | |||
654 | ;;; Inhibit hooks on `org-agenda' | ||
655 | ;; It's really annoying when I call `org-agenda' and five hundred Ispell | ||
656 | ;; processes are created because I have `flyspell-mode' in the hook. This mode | ||
657 | ;; inhibits those hooks when entering the agenda, but runs them when opening the | ||
658 | ;; actual buffer. | ||
659 | |||
660 | (defun +org-agenda-inhibit-hooks (fn &rest r) | ||
661 | "Advice to inhibit hooks when entering `org-agenda'." | ||
662 | (dlet ((org-mode-hook nil)) ; I'm not sure if `dlet' is strictly needed | ||
663 | (apply fn r))) | ||
664 | |||
665 | (defvar-local +org-hook-has-run-p nil | ||
666 | "Whether `org-mode-hook' has run in the current buffer.") | ||
667 | |||
668 | (defun +org-agenda-switch-run-hooks (&rest _) | ||
669 | "Advice to run `org-mode-hook' when entering org-mode. | ||
670 | This should only fire when switching to a buffer from `org-agenda'." | ||
671 | (unless +org-hook-has-run-p | ||
672 | (run-hooks 'org-mode-hook) | ||
673 | (setq +org-hook-has-run-p t))) | ||
674 | |||
675 | (define-minor-mode +org-agenda-inhibit-hooks-mode | ||
676 | "Inhibit `org-mode-hook' when opening `org-agenda'." | ||
677 | :lighter "" | ||
678 | :global t | ||
679 | (if +org-agenda-inhibit-hooks-mode | ||
680 | (progn ; Enable | ||
681 | (advice-add 'org-agenda :around #'+org-agenda-inhibit-hooks) | ||
682 | (advice-add 'org-agenda-switch-to :after #'+org-agenda-switch-run-hooks)) | ||
683 | (progn ; Disable | ||
684 | (advice-remove 'org-agenda #'+org-agenda-inhibit-hooks) | ||
685 | (advice-remove 'org-agenda-switch-to #'+org-agenda-switch-run-hooks)))) | ||
686 | |||
653 | (provide '+org) | 687 | (provide '+org) |
654 | ;;; +org.el ends here | 688 | ;;; +org.el ends here |