Add support for latexindent (#2387)

This commit is contained in:
Riley Martine 2019-04-13 20:21:59 +08:00 committed by w0rp
parent f0f0cc3c18
commit 495bce32e9
6 changed files with 85 additions and 0 deletions

View file

@ -285,6 +285,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['kt'],
\ 'description': 'Fix Kotlin files with ktlint.',
\ },
\ 'latexindent': {
\ 'function': 'ale#fixers#latexindent#Fix',
\ 'suggested_filetypes': ['tex'],
\ 'description' : 'Indent code within environments, commands, after headings and within special code blocks.',
\ },
\}
" Reset the function registry to the default entries.

View file

@ -0,0 +1,18 @@
" Author: riley-martine <riley.martine@protonmail.com>
" Description: Integration of latexindent with ALE.
call ale#Set('tex_latexindent_executable', 'latexindent')
call ale#Set('tex_latexindent_options', '')
function! ale#fixers#latexindent#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'tex_latexindent_executable')
let l:options = ale#Var(a:buffer, 'tex_latexindent_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' -l -w'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View file

@ -32,5 +32,26 @@ g:ale_lacheck_executable *g:ale_lacheck_executable*
This variable can be changed to change the path to lacheck.
===============================================================================
latexindent *ale-tex-latexindent*
g:ale_tex_latexindent_executable *g:ale_tex_latexindent_executable*
*b:ale_tex_latexindent_executable*
Type: |String|
Default: `'latexindent'`
This variable can be changed to change the path to latexindent.
g:ale_tex_latexindent_options *g:ale_tex_latexindent_options*
*b:ale_tex_latexindent_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to latexindent.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -2169,6 +2169,7 @@ documented in additional help files.
tex.....................................|ale-tex-options|
chktex................................|ale-tex-chktex|
lacheck...............................|ale-tex-lacheck|
latexindent...........................|ale-tex-latexindent|
texinfo.................................|ale-texinfo-options|
write-good............................|ale-texinfo-write-good|
text....................................|ale-text-options|

View file

@ -0,0 +1,40 @@
Before:
Save g:ale_tex_latexindent_executable
Save g:ale_tex_latexindent_options
" Use an invalid global executable, so we don't match it.
let g:ale_tex_latexindent_executable = 'xxxinvalid'
let g:ale_tex_latexindent_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The latexindent callback should return the correct default values):
call ale#test#SetFilename('../tex_files/testfile.tex')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -l -w'
\ . ' %t',
\ },
\ ale#fixers#latexindent#Fix(bufnr(''))
Execute(The latexindent callback should include custom gofmt options):
let g:ale_tex_latexindent_options = "-l '~/.indentconfig.yaml'"
call ale#test#SetFilename('../tex_files/testfile.tex')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -l -w'
\ . ' ' . g:ale_tex_latexindent_options
\ . ' %t',
\ },
\ ale#fixers#latexindent#Fix(bufnr(''))

View file