Function: projectile-replace--undo-edits
projectile-replace--undo-edits is a byte-compiled function defined in
projectile.el.
Signature
(projectile-replace--undo-edits MATCHES REPLACEMENT LITERAL)
Documentation
Return the undo edits produced by applying MATCHES with REPLACEMENT.
MATCHES all belong to one file or buffer. Each edit records where its
written text ends up once every edit before it in the same file has been
made, so reverting them from the bottom up needs no rescan. LITERAL
selects verbatim vs. capture-group expansion, so the recorded text is
exactly what projectile-replace--do-one writes.
Source Code
;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile-replace--undo-edits (matches replacement literal)
"Return the undo edits produced by applying MATCHES with REPLACEMENT.
MATCHES all belong to one file or buffer. Each edit records where its
written text ends up once every edit before it in the same file has been
made, so reverting them from the bottom up needs no rescan. LITERAL
selects verbatim vs. capture-group expansion, so the recorded text is
exactly what `projectile-replace--do-one' writes."
(let ((ascending (sort (copy-sequence matches)
(lambda (a b)
(< (projectile-replace--match-beg a)
(projectile-replace--match-beg b)))))
(offset 0)
(edits nil))
(dolist (m ascending)
(let ((old (projectile-replace--match-string m))
(new (projectile-replace--expand
replacement (projectile-replace--match-groups m) literal)))
(push (projectile-replace--undo-edit-create
:beg (+ (projectile-replace--match-beg m) offset)
:old old
:new new)
edits)
(setq offset (+ offset (- (length new) (length old))))))
(nreverse edits)))