Function: projectile-replace-undo
projectile-replace-undo is an autoloaded, interactive and
byte-compiled function defined in projectile.el.
Signature
(projectile-replace-undo)
Documentation
Revert the last project-wide replace applied from the replace reviewer.
Only replaces applied with ! (projectile-replace--apply) in a
*projectile-replace* buffer are recorded, and only the most recent one:
this is a safety net for the single most destructive thing Projectile
does, not an edit history. The record lives in memory, so it is gone
after restarting Emacs.
Each file is reverted only when the text the replace wrote is still exactly there; a file edited, reverted, deleted or rewritten by a branch switch in the meantime is reported and left alone rather than corrupted. Files that were reverted are dropped from the record, so undoing twice can never apply anything twice, while files that were skipped stay undoable once you have sorted them out.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
;;;###autoload
(defun projectile-replace-undo ()
"Revert the last project-wide replace applied from the replace reviewer.
Only replaces applied with \\<projectile-replace-mode-map>\\[projectile-replace--apply] in a
`*projectile-replace*' buffer are recorded, and only the most recent one:
this is a safety net for the single most destructive thing Projectile
does, not an edit history. The record lives in memory, so it is gone
after restarting Emacs.
Each file is reverted only when the text the replace wrote is still
exactly there; a file edited, reverted, deleted or rewritten by a branch
switch in the meantime is reported and left alone rather than corrupted.
Files that were reverted are dropped from the record, so undoing twice
can never apply anything twice, while files that were skipped stay
undoable once you have sorted them out."
(interactive)
(let ((record projectile-replace--last-apply))
(unless record
(user-error "No applied project-wide replace to undo"))
(let ((nedits 0)
(nfiles 0)
(remaining nil))
(dolist (entry (projectile-replace--undo-record-files record))
(let* ((file (car entry))
(result (condition-case err
(projectile-replace--undo-file file (cdr entry))
(error
(projectile-replace--skip
(file-name-nondirectory file)
(error-message-string err))))))
(if (eq result 'skipped)
(push entry remaining)
(cl-incf nfiles)
(cl-incf nedits result))))
(setq remaining (nreverse remaining))
(setf (projectile-replace--undo-record-files record) remaining)
(unless remaining
(setq projectile-replace--last-apply nil))
(message "%s"
(format "[%s] Reverted %d replacement%s of %s in %d file%s%s"
(projectile-project-name
(projectile-replace--undo-record-root record))
nedits (if (= nedits 1) "" "s")
(projectile-replace--undo-record-term record)
nfiles (if (= nfiles 1) "" "s")
(if remaining
(format " (skipped %d changed file%s)"
(length remaining)
(if (= (length remaining) 1) "" "s"))
""))))))