Make ripgrep flags customisable for org-roam-search

This commit is contained in:
Chris Barrett
2022-10-12 16:05:28 +13:00
parent 954d7c86b7
commit 9e8c08dac0

View File

@@ -63,6 +63,11 @@
:group 'org-roam-search :group 'org-roam-search
:type 'string) :type 'string)
(defcustom org-roam-search-ripgrep-flags '("--follow" "--smart-case" "--json")
"The flags to apply when searching via ripgrep."
:group 'org-roam-search
:type '(list string))
(defcustom org-roam-search-ignored-tags nil (defcustom org-roam-search-ignored-tags nil
"A list of tags for nodes that should never be included in search results. "A list of tags for nodes that should never be included in search results.
@@ -161,27 +166,26 @@ would be excluded."
(defun org-roam-search--ripgrep-for-nodes (query) (defun org-roam-search--ripgrep-for-nodes (query)
(let ((reporter (make-progress-reporter "Searching nodes")) (let ((reporter (make-progress-reporter "Searching nodes"))
(files (ht-create))) (files (ht-create))
(ripgrep-args (append org-roam-search-ripgrep-flags (list query org-roam-directory))))
(async-wait (async-wait
(async-start-process "ripgrep" org-roam-search-ripgrep-program (apply 'async-start-process "ripgrep" org-roam-search-ripgrep-program
(lambda (_) (lambda (_)
(goto-char (point-min)) (goto-char (point-min))
(while (not (eobp)) (while (not (eobp))
(progress-reporter-update reporter) (progress-reporter-update reporter)
(-when-let* ((line (buffer-substring (line-beginning-position) (line-end-position))) (-when-let* ((line (buffer-substring (line-beginning-position) (line-end-position)))
((parsed &as &plist :type) ((parsed &as &plist :type)
(json-parse-string line :object-type 'plist)) (json-parse-string line :object-type 'plist))
((&plist :data (&plist :path (&plist :text file) :absolute_offset pos)) ((&plist :data (&plist :path (&plist :text file) :absolute_offset pos))
(when (equal "match" type) (when (equal "match" type)
parsed)) parsed))
(file (expand-file-name file org-roam-directory))) (file (expand-file-name file org-roam-directory)))
(puthash file file files)) (puthash file file files))
(forward-line))) (forward-line)))
"--smart-case" ripgrep-args))
"--json"
query org-roam-directory))
(progress-reporter-done reporter) (progress-reporter-done reporter)
(seq-filter (lambda (node) (seq-filter (lambda (node)
(and (ht-get files (org-roam-node-file node)) (and (ht-get files (org-roam-node-file node))