Fix #5128: No format-on-save by lsp-formatters

A call to `format-all--formatter-executable` with the formatter being
equal to `'lsp` or `'eglot` will return `nil`. Therefore, `funcall` was
never called in those cases.
This commit is contained in:
Ralf Beckmann 2021-06-14 23:52:16 +02:00
parent 2731685095
commit 012b759e98

View file

@ -74,11 +74,13 @@ This is controlled by `+format-on-save-enabled-modes'."
(defadvice! +format--all-buffer-from-hook-a (orig-fn &rest args)
:around #'format-all-buffer--from-hook
(letf! (defun format-all-buffer--with (formatter mode-result)
(and (condition-case-unless-debug e
(format-all--formatter-executable formatter)
(error
(message "Warning: cannot reformat buffer because %S isn't installed"
(gethash formatter format-all--executable-table))
nil))
(funcall format-all-buffer--with formatter mode-result)))
(when (or (eq formatter 'lsp)
(eq formatter 'eglot)
(condition-case-unless-debug e
(format-all--formatter-executable formatter)
(error
(message "Warning: cannot reformat buffer because %S isn't installed"
(gethash formatter format-all--executable-table))
nil)))
(funcall format-all-buffer--with formatter mode-result)))
(apply orig-fn args)))