branch: externals/denote commit 307db010031d77197016b2b66b662a93d4069e99 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Make denote--prepare-note only error if an existing file is not empty This way we avoid cases where some other function saves the buffer before we get to operate on it. One such example is 'lsp-auto-touch-files', as noted by wuzhihao in issue 627: <https://github.com/protesilaos/denote/issues/627>. --- README.org | 2 +- denote.el | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index 3eedcc5d03..7855790fe7 100644 --- a/README.org +++ b/README.org @@ -6458,7 +6458,7 @@ Denote is meant to be a collective effort. Every bit of help matters. fingerknight, hpgisler, hyperfocus1337,johkneisl, jtpavlock, juh, leafarbelm, mentalisttraceur, mjkalyan, oatmealm, pRot0ta1p, rbenit68, relict007, sarcom-sar, sienic, skissue, sundar bp, - yetanotherfossman, zadca123 + wuzhihao, yetanotherfossman, zadca123 Special thanks to Peter Povinec who helped refine the file-naming scheme, which is the cornerstone of this project. diff --git a/denote.el b/denote.el index ac079777df..0d98430434 100644 --- a/denote.el +++ b/denote.el @@ -2917,8 +2917,11 @@ Arguments TITLE, KEYWORDS, DATE, ID, DIRECTORY, FILE-TYPE, TEMPLATE, and SIGNATURE should be valid for note creation." (let* ((path (denote-format-file-name directory id keywords title (denote--file-extension file-type) signature)) - (buffer (if (file-regular-p path) - (user-error "A file named `%s' already exists" path) + ;; NOTE 2025-08-02: Is it safe to assume that an + ;; existing+empty file is good for us to use? Otherwise, we + ;; should have a `y-or-n-p' prompt here. + (buffer (if (and (file-regular-p path) (not (denote--file-empty-p path))) + (user-error "A file named `%s' already exists and is not empty" path) (find-file path))) (header (denote--format-front-matter title date keywords id signature file-type))) (with-current-buffer buffer