Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Textidote #3066

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions ale_linters/tex/textidote.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
" Author: Jordi Altayo <[email protected]>, Juan Pablo Stumpf
" <[email protected]>
" Description: support for textidote grammar and syntax checker

call ale#Set('tex_textidote_executable', 'textidote')
call ale#Set('tex_textidote_options', '--no-color --output singleline')
" TODO get language from spell spelllang
call ale#Set('tex_textidote_check_lang', '')


function! ale_linters#tex#textidote#GetExecutable(buffer) abort
let l:exe = ale#Var(a:buffer, 'tex_textidote_executable')
let l:exe .= ' ' . ale#Var(a:buffer, 'tex_textidote_options')

let l:check_lang = ale#Var(a:buffer, 'tex_textidote_check_lang')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small attempt to get language from spelllang configuration, may be worth considering:

" Function tries to determine the language to use with textidote from the
" spelllang configuration.
function! ale_linters#tex#textidote#GetSpellLang(buffer) abort

  let l:check_lang = ale#Var(a:buffer, 'tex_textidote_check_lang')

  if !empty(l:check_lang)
    return l:check_lang
  endif

  let l:supported_languages = ['en', 'de', 'es', 'fr', 'nl', 'pt']
  let l:spell_languages = split(&spelllang, ',')

  for spell_lang in l:spell_languages
    for supported_lang in l:supported_languages
      if(spell_lang == supported_lang)
        return spell_lang
      endif
    endfor
  endfor

  return ''
endfunction


if !empty(l:check_lang)
let l:exe .= ' --check ' . l:check_lang
endif

return l:exe . ' ' . expand('#' . a:buffer . ':t')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work when editing files in sub-foders. For example:

main.tex
chapter1/section01.tex

Removing the ':t' would properly show the textidote reported errors on both the main.tex and the chapter1/section01.tex files.

endfunction

function! ale_linters#tex#textidote#Handle(buffer, lines) abort
let l:pattern = '.*' . expand('#' . a:buffer . ':t:r') . '\.tex(L\(\d\+\)C\(\d\+\)-L\d\+C\d\+): \(.*\)".*"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment this breaks for subfolder files. Remove the :t to make it work properly.

let l:output = []

for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col' : l:match[2] + 0,
\ 'text': l:match[3],
\ 'type': 'E',
\})
endfor

return l:output
endfunction

call ale#linter#Define('tex', {
\ 'name': 'textidote',
\ 'output_stream': 'stdout',
\ 'executable': {b -> ale#Var(b, 'tex_textidote_executable')},
\ 'command': function('ale_linters#tex#textidote#GetExecutable'),
\ 'callback': 'ale_linters#tex#textidote#Handle',
\})

27 changes: 27 additions & 0 deletions doc/ale-tex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ g:ale_tex_texlab_options *g:ale_tex_texlab_options*
This variable can be changed to modify flags given to texlab.


===============================================================================
textidote *ale-tex-textidote*

g:ale_tex_textidote_executable *g:tex_textidote_executable*
*b:tex_textidote_executable*
Type: |String|
Default: `'textidote'`

This variable can be changed to change the path to textidote.


g:ale_tex_textidote_options *g:ale_tex_textidote_options*
*b:ale_tex_textidote_options*
Type: |String|
Default: `'--no-color --output singleline'`

This variable can be changed to modify flags given to textidote.


g:ale_tex_textidote_check_lang *g:ale_tex_textidote_check_lang*
*b:ale_tex_textidote_check_lang*
Type: |String|
Default: `''`

If this variable is not empty, the language checker will be used. For
supported languages, please refer to the Language Tool website.


===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,7 @@ documented in additional help files.
lacheck...............................|ale-tex-lacheck|
latexindent...........................|ale-tex-latexindent|
texlab................................|ale-tex-texlab|
textidote.............................|ale-tex-textidote|
texinfo.................................|ale-texinfo-options|
write-good............................|ale-texinfo-write-good|
text....................................|ale-text-options|
Expand Down