Additional properties in .editorconfig

Tue 22 January 2019

For some inexplicable reasons vim-editorconfig stopped working with my latest build of neovim. I am not sure why and I haven’t have enough time to debug it properly. As a workaround I have temporarily (?) switched to editorconfig-vim. The former plugin is all written in VimL, so it was not problem to extend properties it supports by two more ones spell_enabled and spell_language corresponding to spell and spelllang vim options respectively. The later plugin is in Python and it is a bit more complicated, but fortunately it has an explicit hook for custom plugins. So, I could write this into special plugin/ file (no into ~/.vimrc, because commands from plugins in ~/.vim/pack are not available then yet):

function! FiletypeHook(config)
     if has_key(a:config, 'spell_enabled')
         let spell_enabled = a:config['spell_enabled']
         echom printf("EditorConfig: spell_enabled = %s",
            \ spell_enabled)
         if spell_enabled == "true"
             let &spell = 1
         else
             let &spell = 0
         endif
     endif

     if has_key(a:config, 'spell_language')
        let s:languages = map(filter(globpath(&runtimepath,
          \ 'spell/*', 1, 1),
          \ '!isdirectory(v:val)'), 'fnamemodify(v:val, '':t'')')
        echom printf("EditorConfig: s:languages = %s",
          \ s:languages)

         let spell_language = a:config['spell_language']

         " set bomb if necessary
         if spell_language[-3:] == "BOM"
             let &bomb = 1
             spell_language = spell_language[:-4]
         endif

         echom printf("EditorConfig: spell_language = %s",
           \ spell_language)
        " We need to accept even dialects of languages, e.g., en_gb
         let lang = split(spell_language, '_')[0]
         echom printf("EditorConfig: spell_language = %s",
           \ lang)
         if !empty(filter(copy(s:languages),
           \ 'stridx(v:val, lang) == 0'))
             echom printf("EditorConfig: spell_language = %s",
               \ spell_language)
             let &spelllang = spell_language
         endif
     endif

     return 0   " Return 0 to show no error happened
endfunction
call editorconfig#AddNewHook(function('FiletypeHook'))

Seems to work like charm. Comments on the code are, of course, more than welcome.

Category: computer Tagged: vim authoring

Comments