-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
eglot-ltex.el
103 lines (83 loc) · 3.84 KB
/
eglot-ltex.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;;; eglot-ltex.el --- Eglot Clients for LTEX -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2024 Shen, Jen-Chieh
;; Created date 2021-04-03 00:40:51
;; Author: Shen, Jen-Chieh <jcs090218@gmail.com>
;; URL: https://github.com/emacs-languagetool/eglot-ltex
;; Version: 0.1.0
;; Package-Requires: ((emacs "24.3") (eglot "1.4") (f "0.20.0"))
;; Keywords: convenience eglot languagetool checker
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Eglot Clients for LTEX.
;;
;;; Code:
(require 'cl-lib)
(require 'eglot)
(require 'f)
(defgroup eglot-ltex nil
"Settings for the LTEX Language Server.
https://github.com/valentjn/ltex-ls"
:prefix "eglot-ltex-"
:group 'eglot
:link '(url-link :tag "Github" "https://github.com/emacs-languagetool/eglot-ltex"))
(defcustom eglot-ltex-active-modes
;; Language ids can be found here:
;; https://github.com/valentjn/ltex-ls/blob/7c031d792110a824951aa003acd3ada158a515b4/src/main/kotlin/org/bsplines/ltexls/parsing/CodeFragmentizer.kt#L46
'((org-mode :language-id "org")
;; Hack for version >=16 of ltex-ls with git commit support. For
;; earlier versions it should just fall back to plaintext. This
;; requires setting git-commit-major-mode to
;; 'git-commit-elisp-text-mode. This is a hack because
;; git-commit-elisp-text-mode isn't a general purpose git commit
;; major mode, but it does the job
(git-commit-elisp-text-mode :language-id "gitcommit")
(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"))
"List of major mode that work with LanguageTool."
:type 'list
:group 'eglot-ltex)
(defcustom eglot-ltex-server-path ""
"The root path of the LTEX language server's folder, or path to the executable."
:type 'string
:group 'eglot-ltex)
(defcustom eglot-ltex-communication-channel 'stdio
"Type of the communication channel."
:type '(choice (const :tag "Standard IO" stdio)
(const :tag "TCP/socket" tcp))
:group 'eglot-ltex)
(defun eglot-ltex--server-entry ()
"Return the server entry file.
This file is use to activate the language server."
(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-program))
(provide 'eglot-ltex)
;;; eglot-ltex.el ends here