Fix #5133: don't kill LSP after reformatting
This happened because LSP hooks on kill-buffer-hook (and possibly others) caused our temporary formatting buffer to talk to LSP as if it were the original buffer. When the temp buffer was cleaned up, LSP assumed the original buffer had been closed. No more! In fact, to avoid similar issues, let's avoid any complex functionality in hooks in this temp buffer.
This commit is contained in:
parent
2d76bdceb8
commit
78dde6efdd
1 changed files with 14 additions and 3 deletions
|
@ -148,7 +148,15 @@ See `+format/buffer' for the interactive version of this function, and
|
||||||
;; `format-all' (and various formatting functions, like `gofmt') widen
|
;; `format-all' (and various formatting functions, like `gofmt') widen
|
||||||
;; the buffer, we must copy the region first.
|
;; the buffer, we must copy the region first.
|
||||||
(let ((output (buffer-substring-no-properties (point-min) (point-max)))
|
(let ((output (buffer-substring-no-properties (point-min) (point-max)))
|
||||||
(origin-buffer (or (buffer-base-buffer) (current-buffer))))
|
(origin-buffer (or (buffer-base-buffer) (current-buffer)))
|
||||||
|
;; Fixes #5133: some packages (like lsp-mode) can do a bunch
|
||||||
|
;; of complicated stuff in these hooks. Better to not have to
|
||||||
|
;; deal with any of them at all.
|
||||||
|
write-file-functions
|
||||||
|
before-save-hook
|
||||||
|
after-save-hook
|
||||||
|
kill-buffer-query-functions
|
||||||
|
kill-buffer-hook)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(with-silent-modifications
|
(with-silent-modifications
|
||||||
(insert output)
|
(insert output)
|
||||||
|
@ -156,10 +164,13 @@ See `+format/buffer' for the interactive version of this function, and
|
||||||
;; buffer as possible, in case the formatter is an elisp
|
;; buffer as possible, in case the formatter is an elisp
|
||||||
;; function, like `gofmt'.
|
;; function, like `gofmt'.
|
||||||
(cl-loop for (var . val)
|
(cl-loop for (var . val)
|
||||||
in (cl-remove-if-not #'listp (buffer-local-variables origin-buffer))
|
in (cl-remove-if-not #'listp (buffer-local-variables (current-buffer)))
|
||||||
;; Making enable-multibyte-characters buffer-local
|
;; Making enable-multibyte-characters buffer-local
|
||||||
;; causes an error.
|
;; causes an error.
|
||||||
unless (eq var 'enable-multibyte-characters)
|
unless (eq var enable-multibyte-characters)
|
||||||
|
;; Fixes #5133: don't deal with complicated hook
|
||||||
|
;; functionality! This isn't a real buffer anyway.
|
||||||
|
unless (string-match-p (symbol-name var) "-\\(hook\\|functions\\)$")
|
||||||
;; Using setq-local would quote var.
|
;; Using setq-local would quote var.
|
||||||
do (set (make-local-variable var) val))
|
do (set (make-local-variable var) val))
|
||||||
;; Since we're piping a region of text to the formatter, remove
|
;; Since we're piping a region of text to the formatter, remove
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue