From d4e928f09e5936f7af1ed170ecfda3cc25d874f5 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 5 Apr 2023 08:04:43 -0400 Subject: [PATCH] Use web-mode derived modes for LSP support for JS and HTML --- emacs/.emacs.d/config/init-ide.el | 11 ++++++++++- emacs/.emacs.d/config/init-web.el | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/emacs/.emacs.d/config/init-ide.el b/emacs/.emacs.d/config/init-ide.el index 701cc67..2ec2aa8 100644 --- a/emacs/.emacs.d/config/init-ide.el +++ b/emacs/.emacs.d/config/init-ide.el @@ -40,12 +40,21 @@ (use-package eglot :commands (eglot) + :config + (add-to-list 'eglot-server-programs + '(js-web-mode . ("typescript-language-server" "--stdio"))) + (add-to-list 'eglot-server-programs + `(html-web-mode . ,(eglot-alternatives + '(("vscode-html-language-server" "--stdio") + ("html-languageserver" "--stdio"))))) :hook (java-mode . eglot-ensure) (rust-mode . eglot-ensure) (js-mode . eglot-ensure) (typescript-mode . eglot-ensure) - (python-mode . eglot-ensure)) + (python-mode . eglot-ensure) + (js-web-mode . eglot-ensure) + (html-web-mode . eglot-ensure)) ;; Some compilation-mode conveniences (use-package compile diff --git a/emacs/.emacs.d/config/init-web.el b/emacs/.emacs.d/config/init-web.el index 1cf83b6..afbcc9f 100644 --- a/emacs/.emacs.d/config/init-web.el +++ b/emacs/.emacs.d/config/init-web.el @@ -9,7 +9,6 @@ ("\\.mustache\\'" . web-mode) ("\\.djhtml\\'" . web-mode) ("\\.hbs\\'" . web-mode) - ("\\.html?\\'" . web-mode) ("\\.mako\\'" . web-mode) ("\\.jinja2\\'" . web-mode)) :config @@ -21,4 +20,12 @@ (web-mode-code-indent-offset 2) (web-mode-script-padding 2)) +(define-derived-mode js-web-mode web-mode "JS Web Mode" + "Web mode in JS files.") +(add-to-list 'auto-mode-alist '("\\.jsx?\\'" . js-web-mode)) + +(define-derived-mode html-web-mode web-mode "HTML Web Mode" + "Web mode in HTML files.") +(add-to-list 'auto-mode-alist '("\\.html?\\'" . html-web-mode)) + (provide 'init-web)