mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
feat(editorconfig): add support for spelling_language (#28638)
This commit is contained in:
parent
972374f4e9
commit
cb6c0fda71
@ -78,6 +78,10 @@ root *editorconfig.root*
|
||||
directories. This property must be at the top-level of the `.editorconfig`
|
||||
file (i.e. it must not be within a glob section).
|
||||
|
||||
spelling_language *editorconfig.spelling_language*
|
||||
A code of the format ss or ss-TT, where ss is an ISO 639 language code and
|
||||
TT is an ISO 3166 territory identifier. Sets the 'spelllang' option.
|
||||
|
||||
tab_width *editorconfig.tab_width*
|
||||
The display size of a single tab character. Sets the 'tabstop' option.
|
||||
|
||||
|
@ -128,7 +128,8 @@ PERFORMANCE
|
||||
|
||||
PLUGINS
|
||||
|
||||
• TODO
|
||||
• EditorConfig
|
||||
• spelling_language property is now supported.
|
||||
|
||||
STARTUP
|
||||
|
||||
|
@ -190,6 +190,27 @@ function properties.insert_final_newline(bufnr, val)
|
||||
end
|
||||
end
|
||||
|
||||
--- A code of the format ss or ss-TT, where ss is an ISO 639 language code and TT is an ISO 3166 territory identifier.
|
||||
--- Sets the 'spelllang' option.
|
||||
function properties.spelling_language(bufnr, val)
|
||||
local error_msg =
|
||||
'spelling_language must be of the format ss or ss-TT, where ss is an ISO 639 language code and TT is an ISO 3166 territory identifier.'
|
||||
|
||||
assert(val:len() == 2 or val:len() == 5, error_msg)
|
||||
|
||||
local language_code = val:sub(1, 2):lower()
|
||||
assert(language_code:match('%l%l'), error_msg)
|
||||
if val:len() == 2 then
|
||||
vim.bo[bufnr].spelllang = language_code
|
||||
else
|
||||
assert(val:sub(3, 3) == '-', error_msg)
|
||||
|
||||
local territory_code = val:sub(4, 5):lower()
|
||||
assert(territory_code:match('%l%l'), error_msg)
|
||||
vim.bo[bufnr].spelllang = language_code .. '_' .. territory_code
|
||||
end
|
||||
end
|
||||
|
||||
--- @private
|
||||
--- Modified version of [glob2regpat()] that does not match path separators on `*`.
|
||||
---
|
||||
|
@ -16,8 +16,16 @@ local testdir = 'Xtest-editorconfig'
|
||||
local function test_case(name, expected)
|
||||
local filename = testdir .. pathsep .. name
|
||||
command('edit ' .. filename)
|
||||
|
||||
for opt, val in pairs(expected) do
|
||||
eq(val, api.nvim_get_option_value(opt, { buf = 0 }), name)
|
||||
local opt_info = api.nvim_get_option_info2(opt, {})
|
||||
if opt_info.scope == 'win' then
|
||||
eq(val, api.nvim_get_option_value(opt, { win = 0 }), name)
|
||||
elseif opt_info.scope == 'buf' then
|
||||
eq(val, api.nvim_get_option_value(opt, { buf = 0 }), name)
|
||||
else
|
||||
eq(val, api.nvim_get_option_value(opt, {}), name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -93,6 +101,12 @@ setup(function()
|
||||
|
||||
[max_line_length.txt]
|
||||
max_line_length = 42
|
||||
|
||||
[short_spelling_language.txt]
|
||||
spelling_language = de
|
||||
|
||||
[long_spelling_language.txt]
|
||||
spelling_language = en-NZ
|
||||
]]
|
||||
)
|
||||
end)
|
||||
@ -222,4 +236,9 @@ But not this one
|
||||
|
||||
eq(true, ok, err)
|
||||
end)
|
||||
|
||||
it('sets spelllang', function()
|
||||
test_case('short_spelling_language.txt', { spelllang = 'de' })
|
||||
test_case('long_spelling_language.txt', { spelllang = 'en_nz' })
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user