Add erlang-mode fixer for Erlang files (#4848)
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--neovim-06-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled

This fixer performs indentation with the Erlang mode for Emacs.
The Erlang mode is maintained in the Erlang/OTP source tree.  It indents
some things differently than the Vim indent plugin, and provides more
customization options.
This commit is contained in:
Dmitri Vereshchagin
2024-10-31 15:29:59 +03:00
committed by GitHub
parent d82d968f8a
commit 4fca3824cc
7 changed files with 178 additions and 0 deletions

View File

@@ -98,6 +98,12 @@ let s:default_registry = {
\ 'suggested_filetypes': ['dune'],
\ 'description': 'Fix dune files with dune format',
\ },
\ 'erlang_mode': {
\ 'function': 'ale#fixers#erlang_mode#Fix',
\ 'suggested_filetypes': ['erlang'],
\ 'description': 'Indent with the Erlang mode for Emacs',
\ 'aliases': ['erlang-mode'],
\ },
\ 'fecs': {
\ 'function': 'ale#fixers#fecs#Fix',
\ 'suggested_filetypes': ['javascript', 'css', 'html'],

View File

@@ -0,0 +1,49 @@
" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
" Description: Indent with the Erlang mode for Emacs
call ale#Set('erlang_erlang_mode_emacs_executable', 'emacs')
call ale#Set('erlang_erlang_mode_indent_level', 4)
call ale#Set('erlang_erlang_mode_icr_indent', 'nil')
call ale#Set('erlang_erlang_mode_indent_guard', 2)
call ale#Set('erlang_erlang_mode_argument_indent', 2)
call ale#Set('erlang_erlang_mode_indent_tabs_mode', 'nil')
let s:variables = {
\ 'erlang-indent-level': 'erlang_erlang_mode_indent_level',
\ 'erlang-icr-indent': 'erlang_erlang_mode_icr_indent',
\ 'erlang-indent-guard': 'erlang_erlang_mode_indent_guard',
\ 'erlang-argument-indent': 'erlang_erlang_mode_argument_indent',
\ 'indent-tabs-mode': 'erlang_erlang_mode_indent_tabs_mode',
\}
function! ale#fixers#erlang_mode#Fix(buffer) abort
let emacs_executable =
\ ale#Var(a:buffer, 'erlang_erlang_mode_emacs_executable')
let l:exprs = [
\ s:SetqDefault(a:buffer, s:variables),
\ '(erlang-mode)',
\ '(font-lock-fontify-region (point-min) (point-max))',
\ '(indent-region (point-min) (point-max))',
\ '(funcall (if indent-tabs-mode ''tabify ''untabify)'
\ . ' (point-min) (point-max))',
\ '(save-buffer 0)',
\]
let l:command = ale#Escape(l:emacs_executable)
\ . ' --batch'
\ . ' --find-file=%t'
\ . join(map(l:exprs, '" --eval=" . ale#Escape(v:val)'), '')
return {'command': l:command, 'read_temporary_file': 1}
endfunction
function! s:SetqDefault(buffer, variables) abort
let l:args = []
for [l:emacs_name, l:ale_name] in items(a:variables)
let l:args += [l:emacs_name, ale#Var(a:buffer, l:ale_name)]
endfor
return '(setq-default ' . join(l:args) . ')'
endfunction