From e15b62f0b27ac2dd730fadbf83803f9a5f0af092 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 25 Oct 2025 16:40:09 -0500 Subject: 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. --- modules/org-config.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- cgit v1.2.3