Function: projectile-replace

projectile-replace is an autoloaded, interactive and byte-compiled function defined in projectile.el.

Signature

(projectile-replace &optional ARG)

Documentation

Replace literal string in project using non-regexp tags-query-replace.

With a prefix argument ARG prompts you for a directory and file name patterns on which to run the replacement.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260310.858/projectile.el
;;;###autoload
(defun projectile-replace (&optional arg)
  "Replace literal string in project using non-regexp `tags-query-replace'.

With a prefix argument ARG prompts you for a directory and file name patterns
on which to run the replacement."
  (interactive "P")
  (let* ((directory (if arg
                        (file-name-as-directory
                         (read-directory-name "Replace in directory: "))
                      (projectile-acquire-root)))
         (file-ext (if arg
                       (if (fboundp #'helm-grep-get-file-extensions)
                           (car (helm-grep-get-file-extensions (list directory)))
                         (read-string
                          (projectile-prepend-project-name
                           "With file extension (empty string means all files): ")))
                     nil))
         (old-text (read-string
                    (projectile-prepend-project-name "Replace: ")
                    (projectile-symbol-or-selection-at-point)))
         (new-text (read-string
                    (projectile-prepend-project-name
                     (format "Replace %s with: " old-text))))
         (files (projectile-files-with-string old-text directory file-ext))
         ;; Filter results through the project's file list so that files
         ;; ignored via .projectile or other ignore rules are excluded.
         (project-files (mapcar (lambda (file) (expand-file-name file directory))
                                (projectile-dir-files directory)))
         (filtered-files (seq-filter (lambda (f) (member f project-files)) files)))
    (fileloop-initialize-replace (regexp-quote old-text) new-text filtered-files 'default)
    (fileloop-continue)))