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
This commit is contained in:
Henrik Lissner 2024-09-01 16:57:37 -04:00
parent 682f151176
commit 0d405329fe
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -41,10 +41,19 @@
(org-confirm-babel-evaluate nil) (org-confirm-babel-evaluate nil)
;; Say a little more ;; Say a little more
(doom-print-message-level 'info)) (doom-print-message-level 'info))
(if-let (files (org-babel-tangle-file target dest)) (cond ((not (file-exists-p target))
(always (print! (success "Done tangling %d file(s)!" (length files)))) (print! (warn "No org file at %s. Skipping...") (path target))
(print! (error "Failed to tangle any blocks from your config.")) nil)
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 () (defun +literate-tangle--sync ()
"Tangles `+literate-config-file' if it has changed." "Tangles `+literate-config-file' if it has changed."