Skip to content
Ahmed Shariff edited this page May 13, 2024 · 1 revision

Welcome to the org-roam-ql wiki! Recording a few predicates/expansion functions that can be used.

Ripgrep search content

  (defun ripgrep (pattern directory type)
    (-non-nil
     (--map
      (pcase-let ((`(,file ,line ,match) (s-split ":" (f-relative it directory))))
        `(,(expand-file-name file directory), (string-to-number line) ,match))
      (--filter
       (< 0 (length it))
       (s-split "\n"
                (with-temp-buffer
                  (call-process "rg" nil t "--null"
                                "--line-buffered"
                                "--color=never"
                                "--max-columns=10000"
                                "--max-columns-preview"
                                "--path-separator" "/"
                                "--smart-case"
                                "--no-heading"
                                "--with-filename"
                                "--line-number"
                                "--search-zip"
                                "-j5"
                                (format "-t%s" type)
                                pattern
                                directory)
                  (buffer-string)))))))




  (org-roam-ql-defexpansion 'regexp-rg
                            "Regex on all org files."
                            (lambda (regexp)
                              (-map
                               #'org-roam-node-from-id
                               (-non-nil (--map
                                          ;; on windows the path has a colon, hence making it relative then expanding again.
                                          (pcase-let ((`(,file ,line ,match) it))
                                            (org-roam-with-file file nil
                                              (goto-line line)
                                              (or (org-id-get-closest)
                                                  (progn
                                                    (goto-char (point-min))
                                                    (org-id-get)))))
                                          (ripgrep regexp org-roam-directory "org"))))))
Clone this wiki locally