From: Michal Krzywkowski Date: Sat, 28 Jul 2018 17:01:10 +0000 (+0200) Subject: Work around emacs bugs 32237, 32278 () X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~468 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=eb279829cb5c11039abda16b92945a882cfcb39d;p=emacs.git Work around emacs bugs 32237, 32278 () See: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32237 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32278 * eglot.el (eglot--apply-text-edits): Inhibit modification hooks and call them manually for the changed region. GitHub-reference: https://github.com/joaotavora/eglot/issues/53 --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 695db498ff4..1ca7b6d65d1 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1438,7 +1438,23 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (save-excursion (save-restriction (narrow-to-region beg end) - (replace-buffer-contents temp))) + + ;; On emacs versions < 26.2, + ;; `replace-buffer-contents' is buggy - it calls + ;; change functions with invalid arguments - so we + ;; manually call the change functions here. + ;; + ;; See emacs bugs #32237, #32278: + ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32237 + ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32278 + (let ((inhibit-modification-hooks t) + (length (- end beg))) + (run-hook-with-args 'before-change-functions + beg end) + (replace-buffer-contents temp) + (run-hook-with-args 'after-change-functions + beg (+ beg (length newText)) + length)))) (progress-reporter-update reporter (cl-incf done))))))) (mapcar (jsonrpc-lambda (&key range newText) (cons newText (eglot--range-region range 'markers)))