Skip to content

Commit

Permalink
Support for AUCTeX and improved configurability (#15)
Browse files Browse the repository at this point in the history
* Include AUCTeX in mode list, use function eglot definition form

* Mark eglot startup params unused
  • Loading branch information
RomanHargrave authored Oct 14, 2024
1 parent 302720b commit 1ec941d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions eglot-ltex.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ https://github.com/valentjn/ltex-ls"
(bibtex-mode :language-id "bibtex")
(context-mode :language-id "context")
(latex-mode :language-id "latex")
(LaTeX-mode :language-id "latex") ;; AUCTeX
(markdown-mode :language-id "markdown")
(rst-mode :language-id "restructuredtext")
(text-mode :language-id "plaintext"))
Expand All @@ -66,7 +67,7 @@ https://github.com/valentjn/ltex-ls"
:group 'eglot-ltex)

(defcustom eglot-ltex-server-path ""
"The root path of the LTEX language server's folder."
"The root path of the LTEX language server's folder, or path to the executable."
:type 'string
:group 'eglot-ltex)

Expand All @@ -80,19 +81,23 @@ https://github.com/valentjn/ltex-ls"
"Return the server entry file.
This file is use to activate the language server."
(f-join eglot-ltex-server-path "bin" (if (eq system-type 'windows-nt)
"ltex-ls.bat"
"ltex-ls")))

(defun eglot-ltex--server-command ()
"Generate startup command for LTEX language server."
(cl-case eglot-ltex-communication-channel
(`stdio `(,(eglot-ltex--server-entry)))
(`tcp `(,(eglot-ltex--server-entry) "--server-type" "TcpSocket" "--port" :autoport))
(t (user-error "Invalid communication channel type: %s" eglot-ltex-communication-channel))))
(let ((program-basename (if (eq system-type 'windows-nt)
"ltex-ls.bat"
"ltex-ls")))
(pcase eglot-ltex-server-path
((pred f-file?) eglot-ltex-server-path)
((pred f-dir?) (f-join eglot-ltex-server-path "bin" program-basename))
("" (executable-find program-basename))
(_ (user-error "eglot-ltex-server-path is invalid or points to a nonexistant file: " eglot-ltex-server-path)))))

(defun eglot-ltex--server-program (_interactive _project)
(pcase eglot-ltex-communication-channel
('stdio `(,(eglot-ltex--server-entry)))
('tcp `(,(eglot-ltex--server-entry) "--server-type" "TcpSocket" "--port" :autoport))
(_ (user-error "Invalid communication channel type: %s" eglot-ltex-communication-channel))))

(add-to-list 'eglot-server-programs
`(,eglot-ltex-active-modes . ,(eglot-ltex--server-command)))
`(,eglot-ltex-active-modes . eglot-ltex--server-program))

(provide 'eglot-ltex)
;;; eglot-ltex.el ends here

0 comments on commit 1ec941d

Please sign in to comment.