Function: wgrep-apply-change
wgrep-apply-change is a natively compiled function defined in
wgrep.el.
Signature
(wgrep-apply-change MARKER OLD NEW)
Documentation
The changes in the *grep* buffer are applied to the file.
NEW may be nil this means deleting whole line.
Source Code
;; Defined in /nix/store/pbj4kr4ar755h56yscbqpnmv3swf8i1k-emacs-packages-deps/share/emacs/site-lisp/elpa/wgrep-20230203.1214/wgrep.el
(defun wgrep-apply-change (marker old new)
"The changes in the *grep* buffer are applied to the file.
NEW may be nil this means deleting whole line."
(let ((coding buffer-file-coding-system))
(goto-char marker)
;; check BOM
(when (and (= (point-min-marker) marker)
coding
(coding-system-get coding :bom))
(setq old (wgrep-string-replace-bom old coding))
(when new
(setq new (wgrep-string-replace-bom new coding))))
;; Check buffer line was modified after execute grep.
(unless (string= old
(buffer-substring-no-properties
(line-beginning-position) (line-end-position)))
(signal 'wgrep-error (list "Buffer was changed after grep.")))
(cond
(new
(wgrep-replace-to-new-line new))
(t
;; new nil means flush whole line.
(wgrep-flush-whole-line)))))