config formatter when eglot enabled
This commit is contained in:
2 files changed
+17
-8
No files matched your search
+7
-8
@@ -29,12 +29,11 @@
|
||||
(eglot--highlight-piggyback cb)
|
||||
t)))
|
||||
|
||||
(defun creature/eglot-c-mode-keybinding ()
|
||||
(when (derived-mode-p 'c-mode 'c++-mode 'c-ts-mode 'c++-ts-mode)
|
||||
(make-local-variable 'eglot-mode-map)
|
||||
(lazy-load-set-keys
|
||||
'(("C-M-\\" . eglot-format))
|
||||
eglot-mode-map)))
|
||||
(defun creature/eglot-format ()
|
||||
(interactive)
|
||||
(if creature/formatter
|
||||
(funcall creature/formatter)
|
||||
(eglot-format)))
|
||||
|
||||
(with-eval-after-load 'eglot
|
||||
(setq eglot-events-buffer-size 0)
|
||||
@@ -43,7 +42,6 @@
|
||||
(add-to-list 'eglot-ignored-server-capabilities :inlayHintProvider)
|
||||
|
||||
(add-hook 'eglot-managed-mode-hook #'creature/eglot-load-markdown-for-doc)
|
||||
(add-hook 'eglot-managed-mode-hook #'creature/eglot-c-mode-keybinding)
|
||||
|
||||
;; variable `eglot-prefer-plaintext' invoked in eglot-1.14
|
||||
;; and document only show one line by eldoc since eglot-1.14
|
||||
@@ -54,7 +52,8 @@
|
||||
'(("M-." . xref-find-definitions)
|
||||
("M-?" . xref-find-references)
|
||||
("C-c r" . eglot-rename)
|
||||
("C-c o" . eglot-code-actions))
|
||||
("C-c o" . eglot-code-actions)
|
||||
("C-M-\\" . creature/eglot-format))
|
||||
eglot-mode-map))
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
(autoload 'prettier-mode "prettier" "" t)
|
||||
|
||||
(defvar-local creature/formatter nil
|
||||
"Formatter for buffer.")
|
||||
|
||||
(defun creature/prettier-setup ()
|
||||
"Enable `prettier-mode' selectively."
|
||||
(when (and prettier-mode
|
||||
@@ -16,8 +19,15 @@
|
||||
'(json-stringify json json5)
|
||||
'(json json5 json-stringify)))
|
||||
|
||||
(defun creature/prettier-set-formatter ()
|
||||
(setq creature/formatter
|
||||
(if (bound-and-true-p prettier-mode)
|
||||
'creature/indent-region-or-buffer
|
||||
nil)))
|
||||
|
||||
(with-eval-after-load 'prettier
|
||||
(add-hook 'prettier-mode-hook #'creature/prettier-setup)
|
||||
(add-hook 'prettier-mode-hook #'creature/prettier-set-formatter)
|
||||
(add-to-list 'prettier-major-mode-parsers
|
||||
'(js-json-mode . creature/prettier-json-parser)))
|
||||
|
||||
|
||||
Reference in new issue
Block a user