Compare commits

...

6 Commits

Author SHA1 Message Date
57fadf54a6 test: add tests for link replacement optimization
Added integration tests for the roam link replacement functionality
to validate the performance optimization that limits the scope of
link replacement by searching specifically for "[[roam:" instead
of any org link bracket pattern. The tests ensure:

1. Special regex characters in buffer content don't break the
   search functionality when using search-forward
2. Only roam: links are processed, not other link types like
   file: or https:

These tests validate the optimization maintains correctness while
improving performance by avoiding unnecessary replacement attempts
on non-roam links.

Ref: fc8638759b
Ref: 89dfaef38b
2025-07-01 22:41:27 -07:00
54a6eeaf1d test: fix org-roam-demote-entire-buffer leaving git dirty
The test was modifying tests/roam-files/demoteable.org directly,
causing the file to be left in a modified state after test runs.
This left git in a dirty state and caused subsequent test failures
when the database expected the original file contents.

Changed the test to use a temporary copy of the file instead,
ensuring the original test data remains unmodified.
2025-07-01 21:35:16 -07:00
89dfaef38b Fix link replacement optimization
We are searching for a string literal for speed, so don’t treat it as a
regexp.

Fixes: fc8638759b ("feat: Limit link replacement scope")
Fixes: #2529
2025-07-01 00:28:11 -05:00
fc8638759b feat: Limit link replacement scope
Test for `roam:` link prefix to limit the number of times we need to
call `org-roam-link-replace-at-point`.
2025-06-29 19:44:00 -05:00
1958e035fc build: do not lock issues
Allow folks to revisit issues at any time if they want to restart the conversation.

See Discourse conversation: https://org-roam.discourse.group/t/org-roam-development-status-may-2025/3810/15

Amend: d099204129
2025-06-28 15:38:16 -07:00
1ea7e3077c fix: run org-roam-db-clear-file on file deletion via vc-delete-file 2025-06-26 14:54:27 -07:00
5 changed files with 85 additions and 39 deletions

View File

@ -71,12 +71,6 @@ jobs:
This pull request was automatically closed due to **6 months of inactivity** followed by 2 weeks notice.
**To reopen:**
- If still relevant, comment below or push new commits
- Or create a new PR with updated changes
If this PR is not reopened in 2 weeks, it will be locked.
# Timing (6 months + 2 weeks)
days-before-stale: 182 # ~6 months
days-before-close: 14 # 2 weeks notice
@ -97,26 +91,3 @@ jobs:
echo "2. Click 'Run workflow'"
echo "3. Leave 'Dry run mode' unchecked"
echo "4. Click 'Run workflow'"
lock:
runs-on: ubuntu-latest
needs: stale
# Only run lock job if NOT in dry run mode
if: github.event.inputs.dry_run != 'true'
steps:
# Lock issues/PRs that have been closed for 2 weeks or more
- name: Lock closed issues
uses: dessant/lock-threads@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-inactive-days: 14
issue-lock-reason: 'resolved'
process-only: 'issues'
- name: Lock closed PRs
uses: dessant/lock-threads@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pr-inactive-days: 14
pr-lock-reason: 'resolved'
process-only: 'prs'

View File

@ -655,12 +655,14 @@ database, see `org-roam-db-sync' command."
(add-hook 'kill-emacs-hook #'org-roam-db--close-all)
(advice-add #'rename-file :after #'org-roam-db-autosync--rename-file-a)
(advice-add #'delete-file :before #'org-roam-db-autosync--delete-file-a)
(advice-add #'vc-delete-file :around #'org-roam-db-autosync--vc-delete-file-a)
(org-roam-db-sync))
(t
(remove-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
(remove-hook 'kill-emacs-hook #'org-roam-db--close-all)
(advice-remove #'rename-file #'org-roam-db-autosync--rename-file-a)
(advice-remove #'delete-file #'org-roam-db-autosync--delete-file-a)
(advice-remove #'vc-delete-file #'org-roam-db-autosync--vc-delete-file-a)
(org-roam-db--close-all)
;; Disable local hooks for all org-roam buffers
(dolist (buf (org-roam-buffer-list))
@ -688,6 +690,17 @@ FILE is removed from the database."
(org-roam-file-p file))
(org-roam-db-clear-file (expand-file-name file))))
(defun org-roam-db-autosync--vc-delete-file-a (fun file)
"Maintain cache consistency on file deletion by FUN.
FILE is removed from the database."
(let ((org-roam-file-p (and (not (auto-save-file-name-p file))
(not (backup-file-name-p file))
(org-roam-file-p file))))
(apply fun `(,file))
(when (and org-roam-file-p
(not (file-exists-p file)))
(org-roam-db-clear-file (expand-file-name file)))))
(defun org-roam-db-autosync--rename-file-a (old-file new-file-or-dir &rest _args)
"Maintain cache consistency of file rename.
OLD-FILE is cleared from the database, and NEW-FILE-OR-DIR is added."

View File

@ -167,6 +167,10 @@ This path is relative to `org-roam-directory'."
:group 'org-roam
:type 'string)
(defvar org-roam-link-type "roam"
"Link type for org-roam nodes.
Replaced by `id' automatically when `org-roam-link-auto-replace' is non-nil.")
(defvar org-roam-node-history nil
"Minibuffer history of nodes.")
@ -768,7 +772,7 @@ The INFO, if provided, is passed to the underlying `org-roam-capture-'."
(deactivate-mark)))
;;;;; [roam:] link
(org-link-set-parameters "roam" :follow #'org-roam-link-follow-link)
(org-link-set-parameters org-roam-link-type :follow #'org-roam-link-follow-link)
(defun org-roam-link-follow-link (title-or-alias)
"Navigate \"roam:\" link to find and open the node with TITLE-OR-ALIAS.
Assumes that the cursor was put where the link is."
@ -797,7 +801,7 @@ Assumes that the cursor was put where the link is."
node)
(goto-char (org-element-property :begin link))
(when (and (org-in-regexp org-link-any-re 1)
(string-equal type "roam")
(string-equal type org-roam-link-type)
(setq node (save-match-data (org-roam-node-from-title-or-alias path))))
(replace-match (org-link-make-string
(concat "id:" (org-roam-node-id node))
@ -807,7 +811,7 @@ Assumes that the cursor was put where the link is."
"Replace all \"roam:\" links in buffer with \"id:\" links."
(interactive)
(org-with-point-at 1
(while (re-search-forward org-link-bracket-re nil t)
(while (search-forward (concat "[[" org-roam-link-type ":") nil t)
(org-roam-link-replace-at-point))))
(add-hook 'org-roam-find-file-hook #'org-roam--replace-roam-links-on-save-h)

View File

@ -0,0 +1,56 @@
;;; test-org-roam-link-replace.el --- Tests for Org-roam link replacement -*- lexical-binding: t; -*-
;; Copyright (C) 2025
;; Package-Requires: ((buttercup))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Tests for commits fc86387 and 89dfaef - link replacement optimization
;;; Code:
(require 'buttercup)
(require 'org-roam)
(require 'org-roam-node)
(describe "org-roam-link-replace-all optimization"
(before-all
(setq org-roam-directory (expand-file-name "tests/roam-files")
org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory))
(org-roam-db-sync))
(after-all
(org-roam-db--close)
(delete-file org-roam-db-location))
(it "only processes roam: links, not other bracket links"
(with-temp-buffer
(org-mode)
(insert "[[file:test.org][File]]\n[[roam:Foo]]\n[[https://example.com][Web]]")
(let ((replace-count 0)
(original-fn (symbol-function 'org-roam-link-replace-at-point)))
;; Wrap the original function to count calls
(cl-letf (((symbol-function 'org-roam-link-replace-at-point)
(lambda ()
(cl-incf replace-count)
(funcall original-fn))))
(org-roam-link-replace-all)
;; Should only be called once, for the roam: link
(expect replace-count :to-equal 1)
(expect (buffer-string) :to-match "\\[\\[id:.*\\]\\[Foo\\]\\]"))))))
(provide 'test-org-roam-link-replace)
;;; test-org-roam-link-replace.el ends here

View File

@ -73,14 +73,16 @@
(expect (org-roam-node-title node) :to-equal "Bruce Wayne"))))
(describe "org-roam-demote-entire-buffer"
(after-each
(cd root-directory))
(it "demotes an entire org buffer"
(find-file "tests/roam-files/demoteable.org" nil)
(org-roam-demote-entire-buffer)
(expect (buffer-substring-no-properties (point) (point-max))
:to-equal "* Demoteable\n:PROPERTIES:\n:ID: 97bf31cf-dfee-45d8-87a5-2ae0dabc4734\n:END:\n\n** Demoteable h1\n\n*** Demoteable child\n")))
;; Use a temporary copy to avoid interfering with other tests
(let ((temp-file (make-temp-file "test-demoteable-" nil ".org")))
(copy-file "tests/roam-files/demoteable.org" temp-file t)
(find-file temp-file)
(org-roam-demote-entire-buffer)
(expect (buffer-substring-no-properties (point) (point-max))
:to-equal "* Demoteable\n:PROPERTIES:\n:ID: 97bf31cf-dfee-45d8-87a5-2ae0dabc4734\n:END:\n\n** Demoteable h1\n\n*** Demoteable child\n")
(kill-buffer)
(delete-file temp-file))))
(describe "org-roam--h1-count"
(after-each