Function: hyrolo-noninteractive-grep-paths

hyrolo-noninteractive-grep-paths is a byte-compiled function defined in hyrolo.el.

Signature

(hyrolo-noninteractive-grep-paths PATHS REGEXP)

Documentation

Non-interactively search PATHS for any REGEXP match with consult grep.

Return a list of (REGEXP (<paths-with-matches)). PATHS may contain environment and Lisp variable references and wildcards when file-expand-wildcards is non-nil.

Use ripgrep (rg) if available; otherwise, use plain grep.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20261030.2317/hyrolo.el
(defun hyrolo-noninteractive-grep-paths (paths regexp)
  "Non-interactively search PATHS for any REGEXP match with consult grep.
Return a list of (REGEXP (<paths-with-matches)).  PATHS may contain
environment and Lisp variable references and wildcards when
`file-expand-wildcards' is non-nil.

Use ripgrep (rg) if available; otherwise, use plain grep."
  (setq paths (seq-filter #'stringp paths))
  (let* (
         ;; Ensure any env or lisp variables in paths are replaced so
         ;; grep does not ignore them.
         (expanded-paths (mapcar #'expand-file-name
				 (hpath:expand-list
				  paths hyrolo-file-suffix-regexp)))
	 ;; Get a list of the filenames from `expanded-paths' with any
	 ;; `regexp' matches
	 (newline-separated-files (ignore-errors
				    (shell-command-to-string
				     (concat (if (executable-find "rg")
						 "rg" "grep")
					     " -l \'" regexp "\' "
					     (mapconcat (lambda (f)
							  (concat "\"" f "\""))
							;; Use
							;; `copy-list' to
							;; avoid sort
							;; modifying
							;;`expanded-paths'
							(delete-dups (sort (cl-copy-list expanded-paths)
									   #'string-lessp))
							" ")))))
         (matching-files (when newline-separated-files
			   (split-string newline-separated-files "[\n\r]"))))

    ;; Ensure return `matching-files' in the same order as `expanded-paths'
    (list regexp (seq-filter (lambda (p)
                               (member p matching-files))
                             expanded-paths))))