summaryrefslogtreecommitdiff
path: root/modules/org-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-25 16:40:09 -0500
committerCraig Jennings <c@cjennings.net>2025-10-25 16:40:09 -0500
commite15b62f0b27ac2dd730fadbf83803f9a5f0af092 (patch)
treefe68336bbc854bd84a90443fab3e633500e6bf66 /modules/org-config.el
parentb130e65e9365588e8a37c5d2df364c83233533ac (diff)
feat:org-config: Add function to clear org-element cache
Introduce `cj/org-clear-element-cache` to clear the org-element cache for the current buffer or all buffers. This is useful for resolving parsing errors encountered during agenda generation, such as 'wrong-type-argument stringp nil'. The function can be triggered with a prefix argument to clear the cache for all org buffers, or without it to clear only the current buffer's cache.
Diffstat (limited to 'modules/org-config.el')
-rw-r--r--modules/org-config.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/org-config.el b/modules/org-config.el
index 8fe8ed6d..0249973f 100644
--- a/modules/org-config.el
+++ b/modules/org-config.el
@@ -248,5 +248,23 @@ with a file, the function will throw an error."
(message "Copied Org link to current file to clipboard: %s" link))
(user-error "Buffer isn't associated with a file, so no link sent to clipboard")))
+;; ----------------------- Org Element Cache Management ------------------------
+
+(defun cj/org-clear-element-cache ()
+ "Clear the org-element cache for the current buffer or all buffers.
+With prefix argument, clear cache for all org buffers. Otherwise, clear only
+the current buffer's cache. Useful when encountering parsing errors like
+'wrong-type-argument stringp nil' during agenda generation."
+ (interactive)
+ (if current-prefix-arg
+ (progn
+ (org-element-cache-reset 'all)
+ (message "Cleared org-element cache for all buffers"))
+ (if (derived-mode-p 'org-mode)
+ (progn
+ (org-element-cache-reset)
+ (message "Cleared org-element cache for current buffer"))
+ (user-error "Current buffer is not in org-mode"))))
+
(provide 'org-config)
;;; org-config.el ends here