-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add erlang-mode fixer for Erlang files (#4848)
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.
- Loading branch information
1 parent
d82d968
commit 4fca382
Showing
7 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
" Author: Dmitri Vereshchagin <[email protected]> | ||
" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Before: | ||
call ale#assert#SetUpFixerTest('erlang', 'erlang_mode') | ||
|
||
function! Fixer(key, ...) abort | ||
let l:name = get(a:, 1, 'erlang_mode') | ||
|
||
let l:func = ale#fix#registry#GetFunc(l:name) | ||
let l:dict = call(l:func, [bufnr('')]) | ||
|
||
return l:dict[a:key] | ||
endfunction | ||
|
||
After: | ||
delfunction Fixer | ||
call ale#assert#TearDownFixerTest() | ||
|
||
Execute(Emacs should edit temporary file in batch mode): | ||
AssertEqual 0, stridx( | ||
\ Fixer('command'), | ||
\ ale#Escape('emacs') . ' --batch --find-file=%t --eval=', | ||
\) | ||
|
||
Execute(The temporary file should be read): | ||
AssertEqual 1, Fixer('read_temporary_file') | ||
|
||
Execute(Fixer alias erlang-mode should be provided): | ||
AssertEqual 0, stridx( | ||
\ Fixer('command', 'erlang-mode'), | ||
\ ale#Escape('emacs') . ' --batch --find-file=%t --eval=', | ||
\) | ||
|
||
Execute(Emacs executable should be configurable): | ||
let b:ale_erlang_erlang_mode_emacs_executable = '/path/to/emacs' | ||
AssertEqual 0, stridx(Fixer('command'), ale#Escape('/path/to/emacs')) | ||
|
||
Execute(erlang-indent-level should be 4 by default): | ||
Assert Fixer('command') =~# '\m\<erlang-indent-level 4\>' | ||
|
||
Execute(erlang-indent-level should be configurable): | ||
let b:ale_erlang_erlang_mode_indent_level = 2 | ||
Assert Fixer('command') =~# '\m\<erlang-indent-level 2\>' | ||
|
||
Execute(erlang-icr-indent should be nil by default): | ||
Assert Fixer('command') =~# '\m\<erlang-icr-indent nil\>' | ||
|
||
Execute(erlang-icr-indent should be configurable): | ||
let b:ale_erlang_erlang_mode_icr_indent = 0 | ||
Assert Fixer('command') =~# '\m\<erlang-icr-indent 0\>' | ||
|
||
Execute(erlang-indent-guard should be 2 by default): | ||
Assert Fixer('command') =~# '\m\<erlang-indent-guard 2\>' | ||
|
||
Execute(erlang-indent-guard should be configurable): | ||
let b:ale_erlang_erlang_mode_indent_guard = 0 | ||
Assert Fixer('command') =~# '\m\<erlang-indent-guard 0\>' | ||
|
||
Execute(erlang-argument-indent should be 2 by default): | ||
Assert Fixer('command') =~# '\m\<erlang-argument-indent 2\>' | ||
|
||
Execute(erlang-argument-indent should be configurable): | ||
let b:ale_erlang_erlang_mode_argument_indent = 4 | ||
Assert Fixer('command') =~# '\m\<erlang-argument-indent 4\>' | ||
|
||
Execute(indent-tabs-mode should be nil by default): | ||
Assert Fixer('command') =~# '\m\<indent-tabs-mode nil\>' | ||
|
||
Execute(indent-tabs-mode should be configurable): | ||
let b:ale_erlang_erlang_mode_indent_tabs_mode = 't' | ||
Assert Fixer('command') =~# '\m\<indent-tabs-mode t\>' |