From 4899918773f87f4925718dbba1fb06e18889e758 Mon Sep 17 00:00:00 2001 From: Guilherme Thomazi Bonicontro Date: Sun, 10 May 2026 13:20:37 +0200 Subject: [PATCH 1/3] fix: ignore Emacs lockfiles when refreshing the note cache --- grove-core.el | 7 ++++++- tests/grove-review-test.el | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/grove-core.el b/grove-core.el index f29b71d..5c2a9ec 100644 --- a/grove-core.el +++ b/grove-core.el @@ -178,11 +178,16 @@ Returns (:title TITLE :tags TAGS :links LINKS :mtime MTIME)." :links (nreverse links) :mtime mtime))) +(defun grove--cacheable-note-p (file) + "Return non-nil when FILE should be included in the note cache." + (not (string-prefix-p ".#" (file-name-nondirectory file)))) + (defun grove--refresh-cache () "Refresh the vault cache by scanning `grove-directory'. Only re-parses files whose mtime has changed." (grove--ensure-directory) - (let ((files (directory-files-recursively grove-directory "\\.org\\'")) + (let ((files (seq-filter #'grove--cacheable-note-p + (directory-files-recursively grove-directory "\\.org\\'"))) (seen (make-hash-table :test #'equal))) ;; Update or add entries (dolist (file files) diff --git a/tests/grove-review-test.el b/tests/grove-review-test.el index d388225..d40d5b8 100644 --- a/tests/grove-review-test.el +++ b/tests/grove-review-test.el @@ -35,6 +35,24 @@ '("Project: Alpha"))) (delete-file file)))) +(ert-deftest grove-refresh-cache-ignores-emacs-lockfiles () + (let* ((grove-directory (make-temp-file "grove-vault" t)) + (note (expand-file-name "test-2.org" grove-directory)) + (lockfile (expand-file-name ".#test-2.org" grove-directory)) + (grove--cache (make-hash-table :test #'equal))) + (unwind-protect + (progn + (with-temp-file note + (insert "#+title: Real note\n")) + ;; Emacs lockfiles are symlinks whose names can still match the + ;; recursive .org scan; they should never be parsed as notes. + (make-symbolic-link note lockfile) + (delete-file note) + (grove--refresh-cache) + (should-not (gethash lockfile grove--cache)) + (should (= (hash-table-count grove--cache) 0))) + (delete-directory grove-directory t)))) + (ert-deftest grove-link-fontify-allows-colons-in-note-titles () (with-temp-buffer (insert "[[Project: Alpha]] [[https://example.com]]") From 33e3751203582e690a46712911816850c7f6058e Mon Sep 17 00:00:00 2001 From: Guilherme Date: Sun, 10 May 2026 13:28:19 +0200 Subject: [PATCH 2/3] chore: update test comment --- tests/grove-review-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/grove-review-test.el b/tests/grove-review-test.el index d40d5b8..e029f37 100644 --- a/tests/grove-review-test.el +++ b/tests/grove-review-test.el @@ -45,7 +45,7 @@ (with-temp-file note (insert "#+title: Real note\n")) ;; Emacs lockfiles are symlinks whose names can still match the - ;; recursive .org scan; they should never be parsed as notes. + ;; recursive .org scan, they should never be parsed as notes. (make-symbolic-link note lockfile) (delete-file note) (grove--refresh-cache) From eb71664dfd5d84b07d74aa177d85fe1034475048 Mon Sep 17 00:00:00 2001 From: Guilherme Thomazi Bonicontro Date: Sun, 10 May 2026 16:21:37 +0200 Subject: [PATCH 3/3] fix: ignore also autosaves and backups along with lockfiles --- grove-core.el | 7 ++++++- tests/grove-review-test.el | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/grove-core.el b/grove-core.el index 5c2a9ec..4e1fe35 100644 --- a/grove-core.el +++ b/grove-core.el @@ -180,7 +180,12 @@ Returns (:title TITLE :tags TAGS :links LINKS :mtime MTIME)." (defun grove--cacheable-note-p (file) "Return non-nil when FILE should be included in the note cache." - (not (string-prefix-p ".#" (file-name-nondirectory file)))) + (let ((name (file-name-nondirectory file))) + (and (string-suffix-p ".org" name) + (not (string-prefix-p ".#" name)) + (not (and (string-prefix-p "#" name) + (string-suffix-p "#" name))) + (not (string-suffix-p "~" name))))) (defun grove--refresh-cache () "Refresh the vault cache by scanning `grove-directory'. diff --git a/tests/grove-review-test.el b/tests/grove-review-test.el index e029f37..35da819 100644 --- a/tests/grove-review-test.el +++ b/tests/grove-review-test.el @@ -53,6 +53,28 @@ (should (= (hash-table-count grove--cache) 0))) (delete-directory grove-directory t)))) +(ert-deftest grove-refresh-cache-ignores-emacs-autosave-and-backup-files () + (let* ((grove-directory (make-temp-file "grove-vault" t)) + (autosave (expand-file-name "#draft.org#" grove-directory)) + (backup (expand-file-name "draft.org~" grove-directory)) + (note (expand-file-name "draft.org" grove-directory)) + (grove--cache (make-hash-table :test #'equal))) + (unwind-protect + (progn + (with-temp-file autosave + (insert "#+title: Autosave\n")) + (with-temp-file backup + (insert "#+title: Backup\n")) + (with-temp-file note + (insert "#+title: Real draft\n")) + (grove--refresh-cache) + (should-not (gethash autosave grove--cache)) + (should-not (gethash backup grove--cache)) + (should (= (hash-table-count grove--cache) 1)) + (should (equal (plist-get (gethash note grove--cache) :title) + "Real draft"))) + (delete-directory grove-directory t)))) + (ert-deftest grove-link-fontify-allows-colons-in-note-titles () (with-temp-buffer (insert "[[Project: Alpha]] [[https://example.com]]")