From 802f015f268380d40e364ca02642f5ada531b0eb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 22 Feb 2023 20:47:51 -0500 Subject: [PATCH] fix(file-templates): org-capture errors on new files If an org-capture template generates a new, blank file, Doom steps in to insert a yasnippet file-template into the buffer. If the file template has text fields, it leaves the new buffer in an "editing snippets" state (and insert mode) which causes errors downstream when org-capture tries to modify the buffer. The file-templates module employs some heuristics to prevent false positives like these, but packages (and org-capture) can get around this by simply generating and switching to the org buffer before modifying it. This commit no-ops file-template expansion in any org-capture session, which should resolve these issues. Fix: #6160 Fix: #6741 --- modules/editor/file-templates/config.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/editor/file-templates/config.el b/modules/editor/file-templates/config.el index 35c49bd44..0f9b8c5c6 100644 --- a/modules/editor/file-templates/config.el +++ b/modules/editor/file-templates/config.el @@ -138,13 +138,14 @@ information.") must be non-read-only, empty, and there must be a rule in `+file-templates-alist' that applies to it." (and (not +file-templates-inhibit) - buffer-file-name - (not buffer-read-only) - (bobp) (eobp) - (not (member (substring (buffer-name) 0 1) '("*" " "))) - (not (file-exists-p buffer-file-name)) - (not (buffer-modified-p)) - (null (buffer-base-buffer)) + buffer-file-name ; this buffer represents a file and + (not buffer-read-only) ; ...isn't read-only + (bobp) (eobp) ; ...is empty + (not (member (substring (buffer-name) 0 1) '("*" " "))) ; ...isn't a "special" buffer + (not (bound-and-true-p org-capture-current-plist)) ; ...isn't an org-capture buffer + (not (file-exists-p buffer-file-name)) ; ...is a new file + (not (buffer-modified-p)) ; ...hasn't been modified + (null (buffer-base-buffer)) ; ...isn't an indirect clone (when-let (rule (cl-find-if #'+file-template-p +file-templates-alist)) (apply #'+file-templates--expand rule))))