" Load ALE with plugged
call plug#begin('~/.vim/plugged')
 Plug 'dense-analysis/ale'
call plug#end()

" Have to specify paths below
let naev = "/path/to/naev/"
autocmd BufRead,BufNewFile /path/to/naev/* call NaevOptions()
autocmd BufRead,BufNewFile /path/to/naev/*.{c,lua,xml} call NaevALEOptions()
function NaevOptions()
   " Indentation
   set expandtab     " Make sure that every file uses real tabs, not spaces
   set shiftround    " Round indent to multiple of 'shiftwidth'
   set smartindent   " Do smart indenting when starting a new line
   set autoindent    " Copy indent from current line, over to the new line
   set tabstop=3     " indents
   set softtabstop=3 " treat 3 spaces as a single character (when deleting)
   set shiftwidth=3  " more indents
   let s:tabwidth=3  " Set the tab width
   exec 'set tabstop='    .s:tabwidth
   exec 'set shiftwidth=' .s:tabwidth
   exec 'set softtabstop='.s:tabwidth
   autocmd BufNewFile,BufRead *.mvx set syntax=xml
   highlight RedundantSpaces ctermbg=darkred ctermfg=white
   match RedundantSpaces /\s\+$/
   set colorcolumn=85
   highlight ColorColumn ctermbg=darkblue
endfunction
function NaevALEOptions()
   call ale#handlers#languagetool#DefineLinter('xml')
   call ale#handlers#languagetool#DefineLinter('lua')
   let g:ale_languagetool_executable = naev.'utils/gettextlanguagetool.py'
   let g:ale_lua_luacheck_executable = naev.'utils/nluacheck.py'
   let g:ale_lua_luacheck_options = '--config '.naev.'/.luacheckrc'
   let g:ale_c_cppcheck_options = '--enable=style --suppress=objectIndex --suppress=memleakOnRealloc --inline-suppr'
   let g:ale_c_flawfinder_minlevel = 5
   let g:ale_linters = {
   \  'lua':['languagetool', 'cspell', 'lua_language_server', 'luac', 'luacheck', 'selene'],
   \  'xml':['xmllint', 'languagetool'],
   \}

   " Vim defaults to C++ for .h files, so force C
   autocmd! BufNewFile,BufRead *.h,*.c set ft=c
endfunction
