diff options
Diffstat (limited to 'lisp/+org.el')
-rw-r--r-- | lisp/+org.el | 56 |
1 files changed, 56 insertions, 0 deletions
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'." | |||
208 | ;; `org-verbatim' and `org-code' are apparently already things, so we skip them | 208 | ;; `org-verbatim' and `org-code' are apparently already things, so we skip them |
209 | ;; here. | 209 | ;; here. |
210 | 210 | ||
211 | ;;; Inhibit hooks on `org-agenda' | ||
212 | ;; It's really annoying when I call `org-agenda' and five hundred Ispell | ||
213 | ;; processes are created because I have `flyspell-mode' in the hook. This mode | ||
214 | ;; inhibits those hooks when entering the agenda, but runs them when opening the | ||
215 | ;; actual buffer. | ||
216 | |||
217 | (defun +org-agenda-inhibit-hooks (fn &rest r) | ||
218 | "Advice to inhibit hooks when entering `org-agenda'." | ||
219 | (let ((org-mode-hook nil)) | ||
220 | (apply fn r))) | ||
221 | |||
222 | (defvar-local +org-hook-has-run-p nil | ||
223 | "Whether `org-mode-hook' has run in the current buffer.") | ||
224 | |||
225 | (defun +org-agenda-switch-run-hooks (&rest _) | ||
226 | "Advice to run `org-mode-hook' when entering org-mode. | ||
227 | This should only fire when switching to a buffer from `org-agenda'." | ||
228 | (unless +org-hook-has-run-p | ||
229 | (run-hooks 'org-mode-hook) | ||
230 | (setq +org-hook-has-run-p t))) | ||
231 | |||
232 | (define-minor-mode +org-agenda-inhibit-hooks-mode | ||
233 | "Inhibit `org-mode-hook' when opening `org-agenda'." | ||
234 | :lighter " A/h" | ||
235 | :global t | ||
236 | (cond (+org-agenda-inhibit-hooks-mode | ||
237 | (advice-add 'org-agenda :around #'+org-agenda-inhibit-hooks) | ||
238 | (advice-add 'org-agenda-switch-to :after #'+org-agenda-switch-run-hooks)) | ||
239 | (:else | ||
240 | (advice-remove 'org-agenda #'+org-agenda-inhibit-hooks) | ||
241 | (advice-remove 'org-agenda-switch-to #'+org-agenda-switch-run-hooks)))) | ||
242 | |||
243 | ;;; Drawers | ||
244 | (defun +org-hide-drawers-except-point () | ||
245 | "Hide all drawers except for the one point is in." | ||
246 | ;; Most of this bit is taken from `org-fold--hide-drawers'. | ||
247 | (let ((pt (point)) | ||
248 | (begin (point-min)) | ||
249 | (end (point-max))) | ||
250 | (save-excursion | ||
251 | (goto-char begin) | ||
252 | (while (and (< (point) end) | ||
253 | (re-search-forward org-drawer-regexp end t)) | ||
254 | (if (org-fold-folded-p nil 'drawer) | ||
255 | (goto-char (org-fold-next-folding-state-change 'drawer nil end)) | ||
256 | (let* ((drawer (org-element-at-point)) | ||
257 | (type (org-element-type drawer)) | ||
258 | (el-begin (org-element-property :begin drawer)) | ||
259 | (el-end (org-element-property :end drawer))) | ||
260 | (when (memq type '(drawer property-drawer)) | ||
261 | (org-fold-hide-drawer-toggle | ||
262 | (if (< el-begin pt el-end) 'off 'on) | ||
263 | nil drawer) | ||
264 | (goto-char el-end)))))))) | ||
265 | |||
266 | |||
211 | (provide '+org) | 267 | (provide '+org) |