Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion grove-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,21 @@ 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."
(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'.
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)
Expand Down
40 changes: 40 additions & 0 deletions tests/grove-review-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@
'("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-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]]")
Expand Down