(feat): extract rg-command builder function from unlinked-references (#2449)

* (test): add "org-roam--list-files-search-globs"

* (feat): extract rg-command builder function from unlinked-references

Users can now advice this command to tweak the flag pased to ripgrep.
The current one have been expanded to long-form.

It's a follow up to the fix about shell quoting

* (docs): update CHANGELOG
This commit is contained in:
Bruno Heridet
2024-07-03 19:26:03 +02:00
committed by GitHub
parent edccf9be84
commit 94b826d759
4 changed files with 61 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,39 @@
;;; test-org-roam-mode.el --- Tests for Org-roam -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Jethro Kuan
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
;; 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:
;;; 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

View File

@ -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