Function: projectile--ignore-pattern-to-regexp

projectile--ignore-pattern-to-regexp is a byte-compiled function defined in projectile.el.

Signature

(projectile--ignore-pattern-to-regexp PATTERN)

Documentation

Translate an ignore/ensure PATTERN into a regexp.

The regexp matches root-relative paths using gitignore rules: a pattern without a slash matches the file name or any directory segment anywhere in the tree, while a pattern containing a slash is anchored at the project root (a leading / anchors without naming a directory of its own). A trailing slash restricts the match to directories (and thus everything below them). Directories must be matched with a trailing slash appended.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile--ignore-pattern-to-regexp (pattern)
  "Translate an ignore/ensure PATTERN into a regexp.
The regexp matches root-relative paths using gitignore rules: a
pattern without a slash matches the file name or any directory
segment anywhere in the tree, while a pattern containing a slash is
anchored at the project root (a leading `/' anchors without naming a
directory of its own).  A trailing slash restricts the match to
directories (and thus everything below them).  Directories must be
matched with a trailing slash appended."
  (let* ((dir-only (string-suffix-p "/" pattern))
         (pattern (string-remove-suffix "/" pattern))
         (floating (string-prefix-p "**/" pattern))
         (pattern (if floating (substring pattern 3) pattern))
         (rooted (string-prefix-p "/" pattern))
         (pattern (if rooted (substring pattern 1) pattern))
         (anchored (or rooted (string-search "/" pattern))))
    (concat (cond (floating "\\`\\(?:.*/\\)?")
                  (anchored "\\`")
                  (t "\\(?:\\`\\|/\\)"))
            (projectile--glob-to-regexp pattern)
            (if dir-only "/" "\\(?:/\\|\\'\\)"))))