From 259363fd4f21d796c3c6a35be6398aed3f493a73 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 3 Jan 2023 23:02:26 -0600 Subject: bleh --- lisp/+org.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'lisp/+org.el') diff --git a/lisp/+org.el b/lisp/+org.el index 70962d6..7698ec9 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -208,4 +208,60 @@ and POST-PROCESS are passed to `org-export-to-file'." ;; `org-verbatim' and `org-code' are apparently already things, so we skip them ;; here. +;;; 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'." + (let ((org-mode-hook nil)) + (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 " A/h" + :global t + (cond (+org-agenda-inhibit-hooks-mode + (advice-add 'org-agenda :around #'+org-agenda-inhibit-hooks) + (advice-add 'org-agenda-switch-to :after #'+org-agenda-switch-run-hooks)) + (:else + (advice-remove 'org-agenda #'+org-agenda-inhibit-hooks) + (advice-remove 'org-agenda-switch-to #'+org-agenda-switch-run-hooks)))) + +;;; Drawers +(defun +org-hide-drawers-except-point () + "Hide all drawers except for the one point is in." + ;; Most of this bit is taken from `org-fold--hide-drawers'. + (let ((pt (point)) + (begin (point-min)) + (end (point-max))) + (save-excursion + (goto-char begin) + (while (and (< (point) end) + (re-search-forward org-drawer-regexp end t)) + (if (org-fold-folded-p nil 'drawer) + (goto-char (org-fold-next-folding-state-change 'drawer nil end)) + (let* ((drawer (org-element-at-point)) + (type (org-element-type drawer)) + (el-begin (org-element-property :begin drawer)) + (el-end (org-element-property :end drawer))) + (when (memq type '(drawer property-drawer)) + (org-fold-hide-drawer-toggle + (if (< el-begin pt el-end) 'off 'on) + nil drawer) + (goto-char el-end)))))))) + + (provide '+org) -- cgit 1.4.1-21-gabe81