blob: 9f6106975e8bada9c4701cd8fc14fbabc32e58e1 (
plain) (
blame)
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
|
--- Personal lua config files for NeoVim.
-- Last Changed: 2022-03-05
-- Author: Federico Igne <git@federicoigne.com>
-- License: This file is placed in the public domain.
--- Focus on spelling errors
--
-- "Turn off" colorscheme when checking for spelling errors.
local spell = {}
local lsputil = require 'lspconfig'.util
local lspconfigs = require 'lspconfig.configs'
--- Return true if lTeX LSP is currently active
function spell.with_ltex()
for _,client in pairs(vim.lsp.get_active_clients()) do
if client.config.name == "ltex" then
return true
end
end
end
--- Turn spellchecking ON
--
-- This will set a dull colorscheme and activate the lTeX LSP (if available
-- and compatible with the current filetype), falling back to native
-- spellchecking otherwise.
function spell.on()
vim.cmd('colorscheme off')
if lspconfigs.ltex and vim.tbl_contains(lspconfigs.ltex.filetypes, vim.o.filetype) then
-- Use lTeX if possible
vim.cmd('LspStart ltex')
else
-- Fallback to standard spell checking
vim.opt.spell = true
end
end
--- Turn spellchecking OFF
function spell.off()
vim.cmd('colorscheme gruvbox')
local ltex = lsputil.get_active_client_by_name(0, "ltex")
if ltex then
vim.cmd('LspStop '..ltex.id)
else
vim.opt.spell = false
end
end
--- Toggle spellchecking
function spell.toggle()
if spell.with_ltex() or vim.o.spell then
spell.off()
else
spell.on()
end
end
return spell
|