mirror of https://github.com/dense-analysis/ale
Add a function for fixing the alignment of Vim help tags
This commit is contained in:
parent
fd6f05c9ea
commit
160b9548ee
|
@ -7,6 +7,11 @@ let s:default_registry = {
|
||||||
\ 'suggested_filetypes': ['python'],
|
\ 'suggested_filetypes': ['python'],
|
||||||
\ 'description': 'Add blank lines before control statements.',
|
\ 'description': 'Add blank lines before control statements.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'align_help_tags': {
|
||||||
|
\ 'function': 'ale#fixers#help#AlignTags',
|
||||||
|
\ 'suggested_filetypes': ['help'],
|
||||||
|
\ 'description': 'Align help tags to the right margin',
|
||||||
|
\ },
|
||||||
\ 'autopep8': {
|
\ 'autopep8': {
|
||||||
\ 'function': 'ale#fixers#autopep8#Fix',
|
\ 'function': 'ale#fixers#autopep8#Fix',
|
||||||
\ 'suggested_filetypes': ['python'],
|
\ 'suggested_filetypes': ['python'],
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
" Author: w0rp <devw0rp@gmail.com>
|
||||||
|
" Description: Generic fixer functions for Vim help documents.
|
||||||
|
|
||||||
|
function! ale#fixers#help#AlignTags(buffer, lines) abort
|
||||||
|
let l:new_lines = []
|
||||||
|
|
||||||
|
for l:line in a:lines
|
||||||
|
if len(l:line) != 79
|
||||||
|
let l:match = matchlist(l:line, '\v +(\*[^*]+\*)$')
|
||||||
|
|
||||||
|
if !empty(l:match)
|
||||||
|
let l:start = l:line[:-len(l:match[0]) - 1]
|
||||||
|
let l:tag = l:match[1]
|
||||||
|
let l:spaces = repeat(' ', 79 - len(l:start) - len(l:tag))
|
||||||
|
|
||||||
|
let l:line = l:start . l:spaces . l:tag
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
call add(l:new_lines, l:line)
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:new_lines
|
||||||
|
endfunction
|
|
@ -0,0 +1,19 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_fixers
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
Given help(A vim help file with badly aligned tags):
|
||||||
|
foo *foo*
|
||||||
|
bar *bar*
|
||||||
|
baz *bar*
|
||||||
|
|
||||||
|
Execute(Tags should be aligned at the right margin):
|
||||||
|
let g:ale_fixers = {'help': ['align_help_tags']}
|
||||||
|
ALEFix
|
||||||
|
|
||||||
|
Expect help(Tags should be aligned):
|
||||||
|
foo *foo*
|
||||||
|
bar *bar*
|
||||||
|
baz *bar*
|
Loading…
Reference in New Issue