From 0d405329fed6a46b28a9d5d0adebba2ae97e6e56 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 1 Sep 2024 16:57:37 -0400 Subject: [PATCH] fix(literate): improve error handling while tangling Now emits more informative errors in the case that the user's config.org doesn't exist or contains no src blocks. Fix: #6717 --- modules/config/literate/autoload.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/config/literate/autoload.el b/modules/config/literate/autoload.el index 294809075..7e3930b65 100644 --- a/modules/config/literate/autoload.el +++ b/modules/config/literate/autoload.el @@ -41,10 +41,19 @@ (org-confirm-babel-evaluate nil) ;; Say a little more (doom-print-message-level 'info)) - (if-let (files (org-babel-tangle-file target dest)) - (always (print! (success "Done tangling %d file(s)!" (length files)))) - (print! (error "Failed to tangle any blocks from your config.")) - nil)))))) + (cond ((not (file-exists-p target)) + (print! (warn "No org file at %s. Skipping...") (path target)) + nil) + ((with-temp-buffer + (insert-file-contents target) + (let ((case-fold-search t)) + (not (re-search-forward "^ *#\\+begin_src e\\(?:macs-\\)?lisp" nil t)))) + (print! (warn "No src blocks to tangle in %s. Skipping...") (path target)) + nil) + ((if-let (files (org-babel-tangle-file target dest)) + (always (print! (success "Done tangling %d file(s)!" (length files)))) + (print! (error "Failed to tangle any blocks from your config.")) + nil)))))))) (defun +literate-tangle--sync () "Tangles `+literate-config-file' if it has changed."