--- Personal lua config files for NeoVim. -- Last Changed: 2022-03-05 -- Author: Federico Igne -- 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