Skip to content

Commit 4e26194

Browse files
authored
fix: Use replace-region-contents instead (#4780)
1 parent 4498503 commit 4e26194

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lsp-mode.el

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,12 +4563,12 @@ interface TextDocumentEdit {
45634563
(lsp:set-position-line (max 0 line))
45644564
(lsp:set-position-character (max 0 character))))
45654565

4566-
(lsp-defun lsp--apply-text-edit-replace-buffer-contents ((edit &as
4566+
(lsp-defun lsp--apply-text-edit-replace-region-contents ((edit &as
45674567
&TextEdit
45684568
:range (&Range :start :end)
45694569
:new-text))
45704570
"Apply the edits described in the TextEdit object in TEXT-EDIT.
4571-
The method uses `replace-buffer-contents'."
4571+
The method uses `replace-region-contents'."
45724572
(setq new-text (s-replace "\r" "" (or new-text "")))
45734573
(lsp:set-text-edit-new-text edit new-text)
45744574
(-let* ((source (current-buffer))
@@ -4580,21 +4580,12 @@ The method uses `replace-buffer-contents'."
45804580
(with-current-buffer source
45814581
(save-excursion
45824582
(save-restriction
4583-
(narrow-to-region beg end)
4584-
4585-
;; On emacs versions < 26.2,
4586-
;; `replace-buffer-contents' is buggy - it calls
4587-
;; change functions with invalid arguments - so we
4588-
;; manually call the change functions here.
4589-
;;
4590-
;; See emacs bugs #32237, #32278:
4591-
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32237
4592-
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32278
45934583
(let ((inhibit-modification-hooks t)
45944584
(length (- end beg)))
45954585
(run-hook-with-args 'before-change-functions
45964586
beg end)
4597-
(replace-buffer-contents temp)
4587+
(replace-region-contents beg end
4588+
(lambda (&rest _) temp))
45984589
(run-hook-with-args 'after-change-functions
45994590
beg (+ beg (length new-text))
46004591
length)))))))))
@@ -4670,7 +4661,7 @@ OPERATION is symbol representing the source of this text edit."
46704661
(reporter (make-progress-reporter message 0 howmany))
46714662
(done 0)
46724663
(apply-edit (if (not lsp--virtual-buffer)
4673-
#'lsp--apply-text-edit-replace-buffer-contents
4664+
#'lsp--apply-text-edit-replace-region-contents
46744665
#'lsp--apply-text-edit)))
46754666
(unwind-protect
46764667
(->> edits

0 commit comments

Comments
 (0)