From 9989a67672d4a917f8463f2549e0a1e29df1c10c Mon Sep 17 00:00:00 2001 From: David Gustavsson Date: Wed, 25 Jan 2023 09:53:34 +0100 Subject: [PATCH 1/3] Add natural_language --- README.md | 1 + plugin/editorconfig.vim | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index 961c9ae2..14b25f4f 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ The EditorConfig Vim plugin supports the following EditorConfig [properties][]: or [PreserveNoEOL][] is required for this property) * `trim_trailing_whitespace` * `max_line_length` +* `natural_language` * `root` (only used by EditorConfig core) ## Selected Options diff --git a/plugin/editorconfig.vim b/plugin/editorconfig.vim index c489342b..93c7bdc8 100644 --- a/plugin/editorconfig.vim +++ b/plugin/editorconfig.vim @@ -519,6 +519,10 @@ function! s:ApplyConfig(config) abort " Set the buffer options {{{1 endif endif + if s:IsRuleActive('natural_language', a:config) + let &l:spelllang=a:config['natural_language'] + endif + call editorconfig#ApplyHooks(a:config) endfunction From 2c329d9e99bb994ec51947f5eeac92570796c57b Mon Sep 17 00:00:00 2001 From: David Gustavsson Date: Wed, 13 Mar 2024 15:29:45 +0100 Subject: [PATCH 2/3] Implement actual specification --- README.md | 2 +- plugin/editorconfig.vim | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 14b25f4f..12917f42 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The EditorConfig Vim plugin supports the following EditorConfig [properties][]: or [PreserveNoEOL][] is required for this property) * `trim_trailing_whitespace` * `max_line_length` -* `natural_language` +* `spelling_language` * `root` (only used by EditorConfig core) ## Selected Options diff --git a/plugin/editorconfig.vim b/plugin/editorconfig.vim index 93c7bdc8..5703b03f 100644 --- a/plugin/editorconfig.vim +++ b/plugin/editorconfig.vim @@ -519,8 +519,8 @@ function! s:ApplyConfig(config) abort " Set the buffer options {{{1 endif endif - if s:IsRuleActive('natural_language', a:config) - let &l:spelllang=a:config['natural_language'] + if s:IsRuleActive('spelling_language', a:config) + let &l:spelllang=s:ConvertLanguage(a:config['spelling_language']) endif call editorconfig#ApplyHooks(a:config) @@ -548,4 +548,10 @@ endfunction "}}}1 let &cpo = s:saved_cpo unlet! s:saved_cpo +" {{{ +function! s:ConvertLanguage(language) + " Change en-GB (from the editorconfig specification) to en_gb ( + return tolower(substitute(a:language, "-", "_", "")) +endfunction +" }}} " vim: fdm=marker fdc=3 From ec5a0006fdadb2d513b55b269b0d0ba6a91c0fd2 Mon Sep 17 00:00:00 2001 From: David Gustavsson Date: Mon, 8 Apr 2024 17:32:41 +0200 Subject: [PATCH 3/3] Sanity check --- plugin/editorconfig.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin/editorconfig.vim b/plugin/editorconfig.vim index 5703b03f..7dcd23cb 100644 --- a/plugin/editorconfig.vim +++ b/plugin/editorconfig.vim @@ -550,8 +550,14 @@ unlet! s:saved_cpo " {{{ function! s:ConvertLanguage(language) - " Change en-GB (from the editorconfig specification) to en_gb ( - return tolower(substitute(a:language, "-", "_", "")) + " Only accept xx or xx-YY language codes (as per editorconfig specification) + if a:language =~ '^[a-z]\{2}\(-[A-Z]\{2}\)\?$' + " Convert to vim-style xx_yy + return tolower(substitute(a:language, "-", "_", "")) + elseif g:EditorConfig_verbose + echom "'" . a:language . "'' does not match specification for spelling_language. Try 'en' or 'en-GB'" + return "" + endif endfunction " }}} " vim: fdm=marker fdc=3