From 495bce32e957dcf45d6d6acf183599e18c92b09d Mon Sep 17 00:00:00 2001 From: Riley Martine Date: Sat, 13 Apr 2019 20:21:59 +0800 Subject: [PATCH] Add support for latexindent (#2387) --- autoload/ale/fix/registry.vim | 5 +++ autoload/ale/fixers/latexindent.vim | 18 +++++++++ doc/ale-tex.txt | 21 ++++++++++ doc/ale.txt | 1 + .../test_latexindent_fixer_callback.vader | 40 +++++++++++++++++++ test/tex_files/testfile.tex | 0 6 files changed, 85 insertions(+) create mode 100644 autoload/ale/fixers/latexindent.vim create mode 100644 test/fixers/test_latexindent_fixer_callback.vader create mode 100644 test/tex_files/testfile.tex diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 23d32f03..2b43e40a 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -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. diff --git a/autoload/ale/fixers/latexindent.vim b/autoload/ale/fixers/latexindent.vim new file mode 100644 index 00000000..b0a0884a --- /dev/null +++ b/autoload/ale/fixers/latexindent.vim @@ -0,0 +1,18 @@ +" Author: riley-martine +" 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 diff --git a/doc/ale-tex.txt b/doc/ale-tex.txt index 24aa3112..b1b09117 100644 --- a/doc/ale-tex.txt +++ b/doc/ale-tex.txt @@ -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: diff --git a/doc/ale.txt b/doc/ale.txt index 96c3a102..9971d355 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/test/fixers/test_latexindent_fixer_callback.vader b/test/fixers/test_latexindent_fixer_callback.vader new file mode 100644 index 00000000..d0da94a1 --- /dev/null +++ b/test/fixers/test_latexindent_fixer_callback.vader @@ -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('')) diff --git a/test/tex_files/testfile.tex b/test/tex_files/testfile.tex new file mode 100644 index 00000000..e69de29b