A *TON* of changes
This commit is contained in:
@ -3,6 +3,14 @@
|
||||
;;; Code:
|
||||
(require 'eglot)
|
||||
|
||||
(defconst ltex-eglot-supported-languages
|
||||
'("ar" "ast-ES" "be-BY" "br-FR" "ca-ES" "ca-ES-valencia" "da-DK" "de" "de-AT"
|
||||
"de-CH" "de-DE" "de-DE-x-simple-language" "el-GR" "en" "en-AU" "en-CA" "en-GB"
|
||||
"en-NZ" "en-US" "en-ZA" "eo" "es" "es-AR" "fa" "fr" "ga-IE" "gl-ES" "it"
|
||||
"ja-JP" "km-KH" "nl" "nl-BE" "pl-PL" "pt" "pt-AO" "pt-BR" "pt-MZ" "pt-PT"
|
||||
"ro-RO" "ru-RU" "sk-SK" "sl-SI" "sv" "ta-IN" "tl-PH" "uk-UA" "zh-CN")
|
||||
"List of languages supportd by LTeX.")
|
||||
|
||||
(defcustom ltex-eglot-server-binary "ltex-ls"
|
||||
"The binary to use for the LTeX LSP server."
|
||||
:group 'ltex-eglot
|
||||
@ -43,6 +51,14 @@
|
||||
(const :tag "Enabled" t)
|
||||
(const :tag "Disabled" nil)))
|
||||
|
||||
(defcustom ltex-eglot-spell-check-rules
|
||||
'(:en-US ["EN_CONTRACTION_SPELLING" "MORFOLOGIK_RULE_EN_US"])
|
||||
"Rules to disable if `ltex-eglot-enable-spell-check' is nil."
|
||||
:group 'ltex-eglot
|
||||
:type '(plist :tag "Entries by language"
|
||||
:key-type (string :tag "Language Code")
|
||||
:value-type (repeat :tag "Rules" string)))
|
||||
|
||||
(defun ltex-eglot--entry-file-p (entry)
|
||||
"Check if ENTRY would be concidered a file by LTex LSP."
|
||||
(when (stringp entry)
|
||||
@ -81,8 +97,8 @@ This is meant to check file-local saftey for the likes of
|
||||
:value-type (repeat :tag "Words" string))
|
||||
:safe 'ltex-eglot--non-file-settings-plist-p)
|
||||
|
||||
(defun ltex-eglot--valid-latex-plist-p (plist)
|
||||
"Return non-nil if PLIST is an OK value for LaTeX options."
|
||||
(defun ltex-eglot--valid-latex-environments-p (plist)
|
||||
"Check if PLIST is an OK value for the `ltex-eglot-latex-environemnts'."
|
||||
(cl-loop for (name handling) on plist by 'cddr
|
||||
unless (and (stringp name)
|
||||
(member handling '("ignore" "default")))
|
||||
@ -100,6 +116,15 @@ This is meant to check file-local saftey for the likes of
|
||||
(const :tag "Check" "default")))
|
||||
:safe 'ltex-eglot--valid-latex-plist-p)
|
||||
|
||||
(defun ltex-eglot--valid-latex-commands-p (plist)
|
||||
"Check if PLIST is an OK value for the `ltex-eglot-latex-commands'."
|
||||
(cl-loop for (name handling) on plist by 'cddr
|
||||
unless (and (stringp name)
|
||||
(member handling '("ignore" "default" "dummy"
|
||||
"pluralDummy" "vowelDummy")))
|
||||
do (cl-return)
|
||||
finally return t))
|
||||
|
||||
(defcustom ltex-eglot-latex-commands ()
|
||||
"Plist controlling the handling of LaTeX commands."
|
||||
:group 'ltex-eglot
|
||||
@ -107,8 +132,13 @@ This is meant to check file-local saftey for the likes of
|
||||
:tag "Commands"
|
||||
:key-type (string :tag "Name")
|
||||
:value-type (choice :tag "Handling"
|
||||
(const :tag "Default" "default")
|
||||
(const :tag "Ignore" "ignore")
|
||||
(const :tag "Check" "default")))
|
||||
(const :tag "Replace with dummy word" "dummy")
|
||||
(const :tag "Replace with dummy plural word"
|
||||
"pluralDummy")
|
||||
(const :tag "Replace with dummy vowel word"
|
||||
"vowelDummy")))
|
||||
:safe 'ltex-eglot--valid-latex-plist-p)
|
||||
|
||||
(defun ltex-eglot--valid-bibtex-plist-p (plist)
|
||||
@ -138,6 +168,19 @@ This is meant to check file-local saftey for the likes of
|
||||
(const :tag "Disabled" nil))
|
||||
:safe 'booleanp)
|
||||
|
||||
(defcustom ltex-eglot-variable-save-method 'dir
|
||||
"How to save variables added by quick fixes.
|
||||
This is one of the following:
|
||||
- \\='dir\tSave in .dir-locals.el
|
||||
- \\='file\tSave as a file local variable
|
||||
- nil\tJust set the buffer local value, don't save the variable"
|
||||
:group 'ltex-eglot
|
||||
:type '(choice :tag "Save method"
|
||||
(const :tag "Directory local (saved)" dir)
|
||||
(const :tag "File local (saved)" file)
|
||||
(const :tag "Buffer local (not saved)" nil))
|
||||
:safe 'symbolp)
|
||||
|
||||
(defvar ltex-eglot-hidden-false-positives nil
|
||||
"List of hidden false positives.
|
||||
This is intented to be set from .dir-locals.el.")
|
||||
@ -203,7 +246,9 @@ well."
|
||||
(dictionary :initform nil
|
||||
:accessor ltex-eglot-server--dictionary)
|
||||
(disabled-rules :initform nil
|
||||
:accessor ltex-eglot-server--disabled-rules))
|
||||
:accessor ltex-eglot-server--disabled-rules)
|
||||
(language :initform nil
|
||||
:accessor ltex-eglot-server--language))
|
||||
"LTeX server class.")
|
||||
|
||||
(cl-defmethod ltex-eglot--disabled-rules-plist ((server ltex-eglot-server))
|
||||
@ -213,7 +258,7 @@ SERVER is the server from which to get the rules."
|
||||
(default-value 'ltex-eglot-disabled-rules)
|
||||
(ltex-eglot-server--disabled-rules server)
|
||||
(and (not ltex-eglot-enable-spell-check)
|
||||
'(:en-US ["EN_CONTRACTION_SPELLING" "MORFOLOGIK_RULE_EN_US"]))))
|
||||
ltex-eglot-spell-check-rules)))
|
||||
|
||||
(cl-defmethod ltex-eglot--setup-server ((server ltex-eglot-server))
|
||||
"Setup up SERVER for the first time."
|
||||
@ -235,6 +280,7 @@ SERVER is the server from which to get the rules."
|
||||
(if (local-variable-p 'ltex-eglot-dictionary)
|
||||
ltex-eglot-dictionary
|
||||
'(t))
|
||||
(ltex-eglot-server--language server) ltex-eglot-language
|
||||
(ltex-eglot-server--setup-done-p server) t)))
|
||||
|
||||
(cl-defmethod ltex-eglot--build-workspace-settings-plist ((server ltex-eglot-server))
|
||||
@ -242,7 +288,7 @@ SERVER is the server from which to get the rules."
|
||||
(unless (ltex-eglot-server--setup-done-p server)
|
||||
(ltex-eglot--setup-server server))
|
||||
(list
|
||||
:language ltex-eglot-language
|
||||
:language (ltex-eglot-server--language server)
|
||||
:dictionary (ltex-eglot--process-and-add-global
|
||||
(default-value 'ltex-eglot-dictionary)
|
||||
(ltex-eglot-server--dictionary server))
|
||||
@ -276,6 +322,16 @@ SERVER is the server from which to get the rules."
|
||||
(cl-callf nconc output (list t)))
|
||||
finally return output))
|
||||
|
||||
(cl-defmethod ltex-eglot--set-variable ((server ltex-eglot-server)
|
||||
variable value)
|
||||
"Set VARIABLE to VALUE in each buffer for SERVER.
|
||||
Also, maybe save VARIABLE in .dir-locals.el or as a file local variable."
|
||||
(cl-case ltex-eglot-variable-save-method
|
||||
(dir (add-dir-local-variable nil variable value))
|
||||
(file (add-file-local-variable variable value)))
|
||||
(dolist (buf (eglot--managed-buffers server))
|
||||
(setf (buffer-local-value variable buf) value)))
|
||||
|
||||
(defun ltex-eglot--handle-client-action (server command slot)
|
||||
"Handle the client side action COMMAND for SERVER.
|
||||
SLOT is a slot in SERVER."
|
||||
@ -291,15 +347,12 @@ SLOT is a slot in SERVER."
|
||||
(newval (ltex-eglot--merge-options-plists
|
||||
'list
|
||||
(slot-value server slot) (plist-get args arg))))
|
||||
(add-dir-local-variable nil local-var
|
||||
(ltex-eglot--cleanup-plist-for-dir-locals newval))
|
||||
(setf (slot-value server slot) newval)
|
||||
(dolist (buf (eglot--managed-buffers server))
|
||||
(setf (buffer-local-value local-var buf) newval))
|
||||
(ltex-eglot--set-variable server local-var newval)
|
||||
(eglot-signal-didChangeConfiguration server)))
|
||||
|
||||
(cl-defmethod eglot-execute ((server ltex-eglot-server) action)
|
||||
"Handelr for LTeX actions.
|
||||
"Handler for LTeX actions.
|
||||
ACTION is the action which to run on SERVER."
|
||||
(let ((kind (plist-get action :kind)))
|
||||
(pcase kind
|
||||
@ -319,7 +372,7 @@ ACTION is the action which to run on SERVER."
|
||||
PATH is the same as for OLDFUN, which is probably
|
||||
`eglot--workspace-configuration-plist'."
|
||||
(let ((conf (funcall oldfun server path)))
|
||||
(when (object-of-class-p server 'ltex-eglot-server)
|
||||
(when (ltex-eglot-server-p server)
|
||||
(let ((ltex-conf (plist-get conf :ltex)))
|
||||
(cl-loop for (prop val) on
|
||||
(ltex-eglot--build-workspace-settings-plist server)
|
||||
@ -329,13 +382,31 @@ PATH is the same as for OLDFUN, which is probably
|
||||
(setf (plist-get conf :ltex) ltex-conf)))
|
||||
conf))
|
||||
|
||||
(defun ltex-eglot-set-language (language server &optional no-save)
|
||||
"Set the SERVER's language to LANGUAGE.
|
||||
When called interactively, prompt for LANGUAGE. With NO-SAVE, don't save the
|
||||
language setting in any file."
|
||||
(interactive (list (completing-read "Language"
|
||||
ltex-eglot-supported-languages)
|
||||
(eglot-current-server)
|
||||
current-prefix-arg))
|
||||
(unless (ltex-eglot-server-p server)
|
||||
(user-error "Current server is not an LTeX server!"))
|
||||
(when-let ((server (eglot-current-server)))
|
||||
(setf (ltex-eglot-server--language server) language)
|
||||
(let ((ltex-eglot-variable-save-method
|
||||
(and (not no-save)
|
||||
ltex-eglot-variable-save-method)))
|
||||
(ltex-eglot--set-variable server 'ltex-eglot-language language))
|
||||
(eglot-signal-didChangeConfiguration server)))
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'eglot-server-programs
|
||||
(cons ltex-eglot-modes
|
||||
(list
|
||||
'ltex-eglot-server
|
||||
ltex-eglot-server-binary "--server-type" "TcpSocket"
|
||||
"--port" :autoport)))
|
||||
"--no-endless" "--port" :autoport)))
|
||||
|
||||
;;;###autoload
|
||||
(advice-add 'eglot--workspace-configuration-plist :around
|
||||
|
Reference in New Issue
Block a user