Function: magit-todos--scan-with-rg

magit-todos--scan-with-rg is a natively compiled function defined in magit-todos.el.

Signature

(magit-todos--scan-with-rg &key MAGIT-STATUS-BUFFER DIRECTORY DEPTH HEADING SYNC CALLBACK)

Documentation

Scan for to-dos with rg.

Then calls CALLBACK. MAGIT-STATUS-BUFFER is what it says. DIRECTORY is the directory in which to run the scan. DEPTH should be an integer, typically the value of magit-todos-depth. HEADING is passed to CALLBACK.

When SYNC is nil, the scanner process is returned, and CALLBACK is a function which is called by the process sentinel with one argument, a list of match items.

When SYNC is non-nil, match items are returned.

Source Code

;; Defined in /nix/store/xy37aj9089qvbs5clw0qszpi3hrh3mxx-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-todos-20250928.1611/magit-todos.el
;; NOTE: These scanners handle the max-depth option differently.  git-grep seems to handle it in the
;; most useful way, with a setting of 0 meaning to look no deeper than the current directory, and a
;; setting of 1 searching directories one level deeper.  In comparison, rg and find effectively
;; subtract one from the value, as a setting of 0 returns no results, and a setting of 1 searches
;; only the current directory (which means that when the max-depth is set to 0, the whole command is
;; essentially a no-op, which is pointless).  Since we want `magit-todos-depth' to behave
;; consistently with all scanners, we will treat it the way git-grep does, and for the other
;; scanners we'll add one to its value.

(magit-todos-defscanner "rg"
  :availablep (lambda ()
                (executable-find "rg"))
  :directory-form (if (equal directory default-directory)
                      ;; Prevent leading "./" in filenames.
                      nil
                    (f-relative directory default-directory))
  :allow-exit-codes (0 1)
  :command (list "rg" "--no-heading" "--line-number"
                 (when depth
                   (list "--maxdepth" (1+ depth)))
                 (when magit-todos-ignore-case
                   "--ignore-case")
                 (when magit-todos-exclude-globs
                   (--map (list "--glob" (concat "!" it))
                          magit-todos-exclude-globs))
                 (unless magit-todos-submodule-list
                   (--map (list "--glob" (concat "!" it))
                          (magit-list-module-paths)))
                 extra-args search-regexp-pcre directory))