diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bc8270..0383b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ ## TBD ### Breaking ### Added +- [#2449](https://github.com/org-roam/org-roam/pull/2449) extract rg-command builder function from unlinked-references ### Removed ### Fixed - [#2264](https://github.com/org-roam/org-roam/pull/2264) Support multi-line org titles - [#2165](https://github.com/org-roam/org-roam/pull/2165) (fix)org-roam-file-p: don't exclude org-roam-directory - [#2168](https://github.com/org-roam/org-roam/pull/2168) (perf)node-read: filter nodes before mapping --to-candidate +- [#2411](https://github.com/org-roam/org-roam/pull/2411) fix for `org-roam-directory` having spaces and Unlinked References not working ### Changed ## 2.2.2 diff --git a/org-roam-mode.el b/org-roam-mode.el index 0bf6278..af9d910 100644 --- a/org-roam-mode.el +++ b/org-roam-mode.el @@ -655,6 +655,18 @@ This is the ROW within FILE." (end-of-line) (point))))) +(defun org-roam-unlinked-references--rg-command (titles) + "Return the ripgrep command searching for TITLES." + (concat "rg --follow --only-matching --vimgrep --pcre2 --ignore-case " + (mapconcat (lambda (glob) (concat "--glob " glob)) + (org-roam--list-files-search-globs org-roam-file-extensions) + " ") + (format " '\\[([^[]]++|(?R))*\\]%s' " + (mapconcat (lambda (title) + (format "|(\\b%s\\b)" (shell-quote-argument title))) + titles "")) + (shell-quote-argument org-roam-directory))) + (defun org-roam-unlinked-references-section (node) "The unlinked references section for NODE. References from FILE are excluded." @@ -664,15 +676,7 @@ References from FILE are excluded." (shell-command-to-string "rg --pcre2-version")))) (let* ((titles (cons (org-roam-node-title node) (org-roam-node-aliases node))) - (rg-command (concat "rg -L -o --vimgrep -P -i " - (mapconcat (lambda (glob) (concat "-g " glob)) - (org-roam--list-files-search-globs org-roam-file-extensions) - " ") - (format " '\\[([^[]]++|(?R))*\\]%s' " - (mapconcat (lambda (title) - (format "|(\\b%s\\b)" (shell-quote-argument title))) - titles "")) - (shell-quote-argument org-roam-directory))) + (rg-command (org-roam-unlinked-references--rg-command titles)) (results (split-string (shell-command-to-string rg-command) "\n")) f row col match) (magit-insert-section (unlinked-references) diff --git a/tests/test-org-roam-mode.el b/tests/test-org-roam-mode.el new file mode 100644 index 0000000..cacfce4 --- /dev/null +++ b/tests/test-org-roam-mode.el @@ -0,0 +1,39 @@ +;;; test-org-roam-mode.el --- Tests for Org-roam -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Jethro Kuan + +;; Author: Jethro Kuan +;; 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 . + +;;; Commentary: +;;; Code: + +(require 'buttercup) +(require 'org-roam) + +(describe "org-roam-unlinked-references--rg-command" + (before-each + ;; the space in the directory is on purpose + (setq org-roam-directory "/tmp/org roam")) + + (it "returns the correct rg command for unlinked references" + (expect (org-roam-unlinked-references--rg-command '("foo" "bar")) + :to-equal + "rg --follow --only-matching --vimgrep --pcre2 --ignore-case --glob \"*.org\" --glob \"*.org.gpg\" --glob \"*.org.age\" '\\[([^[]]++|(?R))*\\]|(\\bfoo\\b)|(\\bbar\\b)' /tmp/org\\ roam"))) + +(provide 'test-org-roam-mode) + +;;; test-org-roam-mode.el ends here diff --git a/tests/test-org-roam.el b/tests/test-org-roam.el index 6430784..6952fec 100644 --- a/tests/test-org-roam.el +++ b/tests/test-org-roam.el @@ -83,6 +83,13 @@ :to-have-same-items-as '("//site.net/docs/01. introduction - hello world.html")))) +(describe "org-roam--list-files-search-globs" + + (it "returns the correct list of globs" + (expect (org-roam--list-files-search-globs org-roam-file-extensions) + :to-have-same-items-as + '("\"*.org\"" "\"*.org.gpg\"" "\"*.org.age\"")))) + (provide 'test-org-roam) ;;; test-org-roam.el ends here