Function: hsys-consult--grep-paths
hsys-consult--grep-paths is a byte-compiled function defined in
hsys-consult.el.
Signature
(hsys-consult--grep-paths PATHS &optional REGEXP MAX-MATCHES PROMPT)
Documentation
Interactively search PATHS with a consult package grep command.
Use ripgrep (rg) if found, otherwise, plain grep. Interactively
show all matches from PATHS; see the documentation for the dir
argument in consult-grep for valid values of PATHS.
Initialize search with optional REGEXP and interactively prompt
for changes. Limit matches per file to the absolute value of
optional MAX-MATCHES, if given and not 0. If 0, match to the
start of headline text only (lines that start with a '^[*#]+[
]*' regexp).
With optional PROMPT string, use this as the first part of the grep prompt; omit any trailing colon and space in the prompt.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hsys-consult.el
;;; ************************************************************************
;;; Private functions
;;; ************************************************************************
(defun hsys-consult--grep-paths (paths &optional regexp max-matches prompt)
"Interactively search PATHS with a consult package grep command.
Use ripgrep (rg) if found, otherwise, plain grep. Interactively
show all matches from PATHS; see the documentation for the `dir'
argument in `consult-grep' for valid values of PATHS.
Initialize search with optional REGEXP and interactively prompt
for changes. Limit matches per file to the absolute value of
optional MAX-MATCHES, if given and not 0. If 0, match to the
start of headline text only (lines that start with a '^[*#]+[
\t]*' regexp).
With optional PROMPT string, use this as the first part of the
grep prompt; omit any trailing colon and space in the prompt."
(hsys-consult-require-version)
(when max-matches
(setq max-matches (prefix-numeric-value max-matches)))
(when (and (integerp max-matches) (zerop max-matches))
;; Final space in leading regexp in next line makes it work with
;; the Orderless package.
(setq regexp (concat "^[*#]+[ \t]* " (or regexp ""))))
(let ((consult-grep-args (if (and (integerp max-matches) (not (zerop max-matches)))
(if (listp consult-grep-args)
(append consult-grep-args
(list (format "-m %d" (abs max-matches))))
(concat consult-grep-args
(format " -m %d" (abs max-matches))))
consult-grep-args))
(consult-ripgrep-args (if (and (integerp max-matches) (not (zerop max-matches)))
(if (listp consult-ripgrep-args)
(append consult-ripgrep-args
(list (format "-m %d" (abs max-matches))))
(concat consult-ripgrep-args
(format " -m %d" (abs max-matches))))
consult-ripgrep-args)))
;; Ensure any env or lisp variables in paths are replaced so
;; grep does not ignore them.
(setq paths (mapcar #'hpath:expand paths))
;; Consult split style usually uses '#' as a separator char but
;; that interferes with matching to Markdown # chars at the start
;; of a line in the regexp, so disable the separator char as it is
;; not needed for simple regexp searches.
(let ((consult-async-split-style nil))
(if (executable-find "rg")
(consult--grep (or prompt "Ripgrep")
#'consult--ripgrep-make-builder paths regexp)
(consult--grep (or prompt "Grep")
#'consult--grep-make-builder paths regexp)))))